File indexing completed on 2024-05-12 04:20:36
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KCHARTRELATIVEPOSITION_H 0010 #define KCHARTRELATIVEPOSITION_H 0011 0012 #include <QDebug> 0013 #include <QMetaType> 0014 #include <Qt> 0015 #include <QPointF> 0016 #include <QSizeF> 0017 #include "KChartGlobal.h" 0018 0019 namespace KChart { 0020 0021 class Position; 0022 class PositionPoints; 0023 class Measure; 0024 0025 /** 0026 \class RelativePosition KChartRelativePosition.h 0027 \brief Defines relative position information: reference area, position 0028 in this area (reference position), horizontal / vertical padding, and rotation. 0029 0030 See detailed description of \a KChart::Position for an illustration of the 0031 different possible reference positions. 0032 0033 Using RelativePosition you can specify the relative parts 0034 of some position information, and you can specify the absolute parts: 0035 the reference area, and the position in this area. 0036 0037 \note To get an absolute position, you have three options: 0038 \li either you declare both, the relative and the absolute parts, 0039 using setReferenceArea for the latter, 0040 \li or you specify a set of points, using setReferencePoints, 0041 \li or you don't use either, leaving it to KChart to find a suitable reference area. 0042 */ 0043 class KCHART_EXPORT RelativePosition 0044 { 0045 public: 0046 RelativePosition(); 0047 RelativePosition( const RelativePosition& ); 0048 0049 RelativePosition & operator=( const RelativePosition & other ); 0050 0051 ~RelativePosition(); 0052 0053 /** 0054 * \brief Set the reference area to be used to find the anchor point. 0055 * 0056 * The reference area's type can be either a QWidget subclass or a KChart::AbstractArea subclass. 0057 * 0058 * \note Usage of reference area and reference points is mutually exclusive: 0059 * Only one can be used, so any previously set reference points are cleared 0060 * when you call setReferenceArea. 0061 * 0062 * Also note: In a few cases KChart will ignore your area (or points, resp.) settings! 0063 * Relative positioning of data value texts is an example: For these 0064 * the reference area is always taken to be the data area. 0065 * 0066 * \sa setReferencePosition, setAlignment, setHorizontalPadding, setVerticalPadding 0067 */ 0068 void setReferenceArea( QObject* area ); 0069 QObject* referenceArea() const; 0070 0071 /** 0072 * \brief Set a set of points from which the anchor point will be selected. 0073 * 0074 * \note Usage of reference area and reference points is mutually exclusive: 0075 * Only one can be used, so any previously set reference area is cleared 0076 * when you call setReferencePoints. 0077 * 0078 * Also note: In a few cases KChart will ignore your points (or area, resp.) settings! 0079 * Relative positioning of data value texts is an example: For these 0080 * the reference area is always taken to be the data area. 0081 * 0082 * \sa setReferenceArea, setReferencePosition, setAlignment, setHorizontalPadding, setVerticalPadding 0083 */ 0084 void setReferencePoints( const PositionPoints& points ); 0085 const PositionPoints referencePoints() const; 0086 0087 /** 0088 * \brief Set the position of the anchor point. 0089 * 0090 * The anchor point of a RelativePosition may be one of the pre-defined 0091 * points of it's reference area - for details see KChart::Position. 0092 * 0093 * See detailed description of \a KChart::Position for an illustration of the 0094 * different possible reference positions. 0095 * 0096 * \sa resetReferencePosition, setReferenceArea, setAlignment, setHorizontalPadding, setVerticalPadding, KChart::Position 0097 */ 0098 void setReferencePosition( Position position ); 0099 0100 /** 0101 * \brief Resets the position of the anchor point to the built-in default. 0102 * 0103 * If the anchor point of a RelativePosition is reset (or never changed from the 0104 * default setting) KChart will choose an appropriate Position at run-time. 0105 * 0106 * e.g. BarDiagrams will use Position::North / Position::South for positive / negative values. 0107 * 0108 * \sa setReferencePosition, setReferenceArea, setAlignment, setHorizontalPadding, setVerticalPadding, KChart::Position 0109 */ 0110 void resetReferencePosition(); 0111 Position referencePosition() const; 0112 0113 /** 0114 * Set the alignment of the content placed by this RelativePosition. 0115 * 0116 * Padding is applied first to obtain the final reference point 0117 * for the content's alignment 0118 * 0119 * \note To print centered content, besides calling setAlignment( Qt::AlignCenter ) 0120 * you might also want to set zero padding to have your text centered more precisely. 0121 * 0122 * \sa setReferencePosition, setReferenceArea, setHorizontalPadding, setVerticalPadding 0123 */ 0124 void setAlignment( Qt::Alignment flags ); 0125 Qt::Alignment alignment() const; 0126 0127 /** 0128 * Set the width of the horizontal padding between the anchor point and the content 0129 * placed by this RelativePosition. 0130 * 0131 * \note When printing data value texts this Measure is used to find the alignment 0132 * point for this text, then alignment() is use to determine how to align the text 0133 * relative to that point. 0134 * The font height is used as reference size for both horizontal and vertical padding 0135 * if the respective padding's Measure is using automatic reference area detection. 0136 * 0137 * \sa setVerticalPadding, setReferencePosition, setReferenceArea 0138 */ 0139 void setHorizontalPadding( const Measure& padding ); 0140 Measure horizontalPadding() const; 0141 0142 /** 0143 * Set the height of the vertical padding between the anchor point and the content 0144 * placed by this RelativePosition. 0145 * 0146 * \note When printing data value texts this Measure is used to find the alignment 0147 * point for this text, then alignment() is use to determine how to align the text 0148 * relative to that point. 0149 * The font height is used as reference size for both horizontal and vertical padding 0150 * if the respective padding's Measure is using automatic reference area detection. 0151 * 0152 * \sa setHorizontalPadding, setReferencePosition, setReferenceArea 0153 */ 0154 void setVerticalPadding( const Measure& padding ); 0155 Measure verticalPadding() const; 0156 0157 void setRotation( qreal rot ); 0158 qreal rotation() const; 0159 0160 /** 0161 * \brief Return the reference point, according to the reference area/position, and ignoring padding. 0162 * 0163 * This method is called at drawing time. 0164 * The returned point is used to test if the label of a data value is to be printed: a label 0165 * is printed only if its reference point is inside or touching the coordinate plane. 0166 * 0167 * If polarDegrees is set, the degree information will be returned that was stored for the 0168 * respective point. This is used by the PieDiagram class to determine how vertical/horizontal 0169 * padding settings should affect the position of the data value texts' reference points. 0170 * \sa calculatedPoint, setReferenceArea, setReferencePosition, setHorizontalPadding, setVerticalPadding 0171 */ 0172 const QPointF referencePoint(qreal* polarDegrees = nullptr) const; 0173 0174 /** 0175 * \brief Calculate a point, accordin to the reference area/position and the padding. 0176 * 0177 * This method is called at drawing time: The returned point is used as anchor point. 0178 * Note that it is the task of the calling code to place the content, taking the alignment 0179 * property into account. This class does not know the size of the content so it 0180 * cannot place it. 0181 * 0182 * \sa referencePoint, setReferenceArea, setReferencePosition, setHorizontalPadding, setVerticalPadding 0183 */ 0184 const QPointF calculatedPoint( const QSizeF& autoSize ) const; 0185 0186 bool operator==( const RelativePosition& ) const; 0187 bool operator!=( const RelativePosition & other ) const; 0188 0189 private: 0190 KCHART_DECLARE_PRIVATE_BASE_VALUE( RelativePosition ) 0191 }; 0192 0193 inline bool RelativePosition::operator!=( const RelativePosition & other ) const { return !operator==( other ); } 0194 } 0195 0196 #if !defined(QT_NO_DEBUG_STREAM) 0197 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::RelativePosition& ); 0198 #endif /* QT_NO_DEBUG_STREAM */ 0199 0200 KCHART_DECLARE_SWAP_SPECIALISATION( KChart::RelativePosition ) 0201 0202 QT_BEGIN_NAMESPACE 0203 Q_DECLARE_TYPEINFO( KChart::RelativePosition, Q_MOVABLE_TYPE ); 0204 QT_END_NAMESPACE 0205 0206 Q_DECLARE_METATYPE( KChart::RelativePosition ) 0207 0208 #endif // KCHARTRELATIVEPOSITION_H