#include <KDChartRelativePosition.h>
Using RelativePosition you can specify the relative parts of some position information, and you can specify the absolute parts: the reference area, and the position in this area.
To get an absolute position, you have three options:
Definition at line 62 of file KDChartRelativePosition.h.
Public Member Functions | |
Qt::Alignment | alignment () const |
const QPointF | calculatedPoint (const QSizeF &autoSize) const |
Calculate a point, according to the reference area/position and horiz/vert padding. | |
Measure | horizontalPadding () const |
bool | operator!= (const RelativePosition &other) const |
RelativePosition & | operator= (const RelativePosition &other) |
bool | operator== (const RelativePosition &) const |
QObject * | referenceArea () const |
const QPointF | referencePoint (qreal *polarDegrees=0) const |
Return the reference point, according to the reference area/position, but ignoring horiz/vert padding. | |
const PositionPoints | referencePoints () const |
Position | referencePosition () const |
RelativePosition (const RelativePosition &) | |
RelativePosition () | |
void | resetReferencePosition () |
Resets the position of the anchor point to the built-in default. | |
qreal | rotation () const |
void | setAlignment (Qt::Alignment flags) |
Specifies the location of the content, that is to be positioned by this RelativePosition. | |
void | setHorizontalPadding (const Measure &padding) |
Specifies the horizontal width of the gap between the anchor point and the content, that is to be positioned by this RelativePosition. | |
void | setReferenceArea (QObject *area) |
Specifies the reference area to be used to find the anchor point. | |
void | setReferencePoints (const PositionPoints &points) |
Specifies a set of points from which the anchor point will be selected. | |
void | setReferencePosition (Position position) |
Specifies the position of the anchor point. | |
void | setRotation (qreal rot) |
void | setVerticalPadding (const Measure &padding) |
Specifies the vertical width of the gap between the anchor point and the content, that is to be positioned by this RelativePosition. | |
Measure | verticalPadding () const |
~RelativePosition () |
RelativePosition::RelativePosition | ( | ) |
Definition at line 70 of file KDChartRelativePosition.cpp.
00071 : _d( new Private ) 00072 { 00073 00074 }
RelativePosition::RelativePosition | ( | const RelativePosition & | r | ) |
Definition at line 76 of file KDChartRelativePosition.cpp.
00077 : _d( new Private( *r._d ) ) 00078 { 00079 00080 }
RelativePosition::~RelativePosition | ( | ) |
Qt::Alignment RelativePosition::alignment | ( | ) | const |
Definition at line 130 of file KDChartRelativePosition.cpp.
References d.
Referenced by operator<<(), and operator==().
00130 { 00131 return d->alignment; 00132 }
const QPointF RelativePosition::calculatedPoint | ( | const QSizeF & | autoSize | ) | const |
Calculate a point, according to the reference area/position and horiz/vert padding.
This method is called at drawing time: The returned point is used as anchor point. Note that calculatedPoint ignores the alignment setting, it just returns the point, so the calling code needs to take alignment into account explicitly.
Definition at line 190 of file KDChartRelativePosition.cpp.
References KDChart::Measure::calculatedValue(), horizontalPadding(), KDChartEnums::MeasureOrientationHorizontal, KDChartEnums::MeasureOrientationVertical, referencePoint(), and verticalPadding().
00191 { 00192 const qreal dx = horizontalPadding().calculatedValue( autoSize, KDChartEnums::MeasureOrientationHorizontal ); 00193 const qreal dy = verticalPadding() .calculatedValue( autoSize, KDChartEnums::MeasureOrientationVertical ); 00194 qreal polarDegrees; 00195 QPointF pt( referencePoint( &polarDegrees ) ); 00196 if( polarDegrees == 0.0 ){ 00197 pt += QPointF(dx, dy); 00198 }else{ 00199 const qreal rad = DEGTORAD( polarDegrees); 00200 const qreal sinDeg = sin(rad); 00201 const qreal cosDeg = cos(rad); 00202 pt.setX( pt.x() + dx * cosDeg + dy * sinDeg ); 00203 pt.setY( pt.y() - dx * sinDeg + dy * cosDeg ); 00204 } 00205 return pt; 00206 }
Measure RelativePosition::horizontalPadding | ( | ) | const |
Definition at line 138 of file KDChartRelativePosition.cpp.
References d.
Referenced by calculatedPoint(), operator<<(), and operator==().
00138 { 00139 return d->horizontalPadding; 00140 }
bool KDChart::RelativePosition::operator!= | ( | const RelativePosition & | other | ) | const |
Definition at line 210 of file KDChartRelativePosition.h.
References operator==().
00210 { return !operator==( other ); }
RelativePosition & RelativePosition::operator= | ( | const RelativePosition & | other | ) |
Definition at line 82 of file KDChartRelativePosition.cpp.
00082 { 00083 RelativePosition copy( other ); 00084 copy.swap( *this ); 00085 return *this; 00086 }
bool RelativePosition::operator== | ( | const RelativePosition & | r | ) | const |
Definition at line 209 of file KDChartRelativePosition.cpp.
References alignment(), d, horizontalPadding(), referenceArea(), referencePosition(), rotation(), and verticalPadding().
Referenced by operator!=().
00210 { 00211 return d->area == r.referenceArea() && 00212 d->position == r.referencePosition() && 00213 d->alignment == r.alignment() && 00214 d->horizontalPadding == r.horizontalPadding() && 00215 d->verticalPadding == r.verticalPadding() && 00216 d->rotation == r.rotation() ; 00217 }
QObject * RelativePosition::referenceArea | ( | ) | const |
Definition at line 101 of file KDChartRelativePosition.cpp.
References d.
Referenced by operator<<(), and operator==().
00101 { 00102 return d->area; 00103 }
const QPointF RelativePosition::referencePoint | ( | qreal * | polarDegrees = 0 |
) | const |
Return the reference point, according to the reference area/position, but ignoring horiz/vert padding.
This method is called at drawing time. The returned point is used to test if the label of a data value is to be printed: labels are printed only, if their reference points are either inside or touching the coordinate plane.
If polarDegrees is set, the degree information will be returned that was stored for the respective point. This is used by the PieDiagram class to determin how vertical/horizontal padding settings should affect the position of the data value texts' reference points.
Definition at line 159 of file KDChartRelativePosition.cpp.
References d.
Referenced by calculatedPoint().
00160 { 00161 bool useRect = (d->area != 0); 00162 QRect rect; 00163 if( useRect ){ 00164 const QWidget* widget = dynamic_cast<const QWidget*>(d->area); 00165 if( widget ){ 00166 const QLayout * layout = widget->layout(); 00167 rect = layout ? layout->geometry() : widget->geometry(); 00168 }else{ 00169 const AbstractArea* kdcArea = dynamic_cast<const AbstractArea*>(d->area); 00170 if( kdcArea ) 00171 rect = kdcArea->geometry(); 00172 else 00173 useRect = false; 00174 } 00175 } 00176 QPointF pt; 00177 if ( useRect ){ 00178 pt = PositionPoints( rect ).point( d->position ); 00179 if( polarDegrees ) 00180 *polarDegrees = 0.0; 00181 }else{ 00182 pt = d->points.point( d->position ); 00183 if( polarDegrees ) 00184 *polarDegrees = d->points.degrees( d->position.value() ); 00185 } 00186 return pt; 00187 }
const PositionPoints RelativePosition::referencePoints | ( | ) | const |
Definition at line 110 of file KDChartRelativePosition.cpp.
References d.
00110 { 00111 return d->points; 00112 }
Position RelativePosition::referencePosition | ( | ) | const |
Definition at line 122 of file KDChartRelativePosition.cpp.
References d.
Referenced by operator<<(), and operator==().
00122 { 00123 return d->position; 00124 }
void RelativePosition::resetReferencePosition | ( | ) |
Resets the position of the anchor point to the built-in default.
If the anchor point of a RelativePosition is reset (or never changed from the default setting, resp.) KD Chart will choose an appropriate Position at run-time.
e.g. BarDiagrams will use Position::NorthWest / Position::SouthEast for positive / negative values.
Definition at line 118 of file KDChartRelativePosition.cpp.
References d, and KDChart::Position::Unknown.
00118 { 00119 d->position = Position::Unknown; 00120 }
qreal RelativePosition::rotation | ( | ) | const |
Definition at line 154 of file KDChartRelativePosition.cpp.
References d.
Referenced by operator<<(), and operator==().
00154 { 00155 return d->rotation; 00156 }
void RelativePosition::setAlignment | ( | Qt::Alignment | flags | ) |
Specifies the location of the content, that is to be positioned by this RelativePosition.
Aligning is applied, after horiz./vert. padding was retrieved to calculate the real reference point, so aligning is seen as relative to that point.
Definition at line 126 of file KDChartRelativePosition.cpp.
References d.
00126 { 00127 d->alignment = align; 00128 }
void RelativePosition::setHorizontalPadding | ( | const Measure & | padding | ) |
Specifies the horizontal width of the gap between the anchor point and the content, that is to be positioned by this RelativePosition.
Definition at line 134 of file KDChartRelativePosition.cpp.
References d.
00134 { 00135 d->horizontalPadding = pad; 00136 }
void RelativePosition::setReferenceArea | ( | QObject * | area | ) |
Specifies the reference area to be used to find the anchor point.
The reference area's type can be either QWidget, or be derived from KDChart::AbstractArea.
Definition at line 95 of file KDChartRelativePosition.cpp.
References d, and setReferencePoints().
Referenced by setReferencePoints().
00095 { 00096 d->area = area; 00097 if( area ) 00098 setReferencePoints( PositionPoints() ); 00099 }
void RelativePosition::setReferencePoints | ( | const PositionPoints & | points | ) |
Specifies a set of points from which the anchor point will be selected.
Definition at line 105 of file KDChartRelativePosition.cpp.
References d, KDChart::PositionPoints::isNull(), and setReferenceArea().
Referenced by setReferenceArea().
00105 { 00106 d->points = points; 00107 if( !points.isNull() ) 00108 setReferenceArea( 0 ); 00109 }
void RelativePosition::setReferencePosition | ( | Position | position | ) |
Specifies the position of the anchor point.
The anchor point of a RelativePosition may be one of the pre-defined points of it's reference area - for details see KDChart::Position.
Definition at line 114 of file KDChartRelativePosition.cpp.
References d.
00114 { 00115 d->position = pos; 00116 }
void RelativePosition::setRotation | ( | qreal | rot | ) |
Definition at line 150 of file KDChartRelativePosition.cpp.
References d.
00150 { 00151 d->rotation = rot; 00152 }
void RelativePosition::setVerticalPadding | ( | const Measure & | padding | ) |
Specifies the vertical width of the gap between the anchor point and the content, that is to be positioned by this RelativePosition.
Definition at line 142 of file KDChartRelativePosition.cpp.
References d.
00142 { 00143 d->verticalPadding = pad; 00144 }
Measure RelativePosition::verticalPadding | ( | ) | const |
Definition at line 146 of file KDChartRelativePosition.cpp.
References d.
Referenced by calculatedPoint(), operator<<(), and operator==().
00146 { 00147 return d->verticalPadding; 00148 }