KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
KDChartRelativePosition.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Chart library.
4**
5** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10
12
13#include "KDChartAbstractArea.h"
14#include "KDChartEnums.h"
15#include "KDChartMeasure.h"
16#include "KDChartPosition.h"
17
18#include <QLayout>
19#include <QWidget>
20
21#include <KDABLibFakes>
22
23using namespace KDChart;
24
25class RelativePosition::Private
26{
27 friend class ::KDChart::RelativePosition;
28
29public:
30 Private();
31 ~Private();
32
33private:
34 QObject *area = nullptr;
35 PositionPoints points;
36 Position position;
37 Qt::Alignment alignment;
38 Measure horizontalPadding;
39 Measure verticalPadding;
40 qreal rotation = 0;
41};
42
43RelativePosition::Private::Private()
44 : alignment(Qt::AlignCenter)
45{
46}
47
48RelativePosition::Private::~Private()
49{
50}
51
53 : _d(new Private)
54{
55}
56
58 : _d(new Private(*r._d))
59{
60}
61
63{
64 RelativePosition copy(other);
65 copy.swap(*this);
66 return *this;
67}
68
73
74#define d d_func()
75
77{
78 d->area = area;
79 if (area)
81}
82
84{
85 return d->area;
86}
87
89{
90 d->points = points;
91 if (!points.isNull())
92 setReferenceArea(nullptr);
93}
95{
96 return d->points;
97}
98
100{
101 d->position = pos;
102}
103
108
110{
111 return d->position;
112}
113
115{
116 d->alignment = align;
117}
118
120{
121 return d->alignment;
122}
123
125{
126 d->horizontalPadding = pad;
127}
128
130{
131 return d->horizontalPadding;
132}
133
135{
136 d->verticalPadding = pad;
137}
138
140{
141 return d->verticalPadding;
142}
143
145{
146 d->rotation = rot;
147}
148
150{
151 return d->rotation;
152}
153
154const QPointF RelativePosition::referencePoint(qreal *polarDegrees) const
155{
156 bool useRect = (d->area != nullptr);
157 QRect rect;
158 if (useRect) {
159 if (const auto *widget = qobject_cast<const QWidget *>(d->area)) {
160 const QLayout *layout = widget->layout();
161 rect = layout ? layout->geometry() : widget->geometry();
162 } else if (const auto *kdcArea = qobject_cast<const AbstractArea *>(d->area)) {
163 rect = kdcArea->geometry();
164 } else {
165 useRect = false;
166 }
167 }
168
169 QPointF pt;
170 qreal angle = 0.0;
171 if (useRect) {
172 pt = PositionPoints(rect).point(d->position);
173 } else {
174 pt = d->points.point(d->position);
175 angle = d->points.degrees(d->position.value());
176 }
177
178 if (polarDegrees) {
179 *polarDegrees = angle;
180 }
181 return pt;
182}
183
185{
188
189 qreal polarDegrees;
190 QPointF pt(referencePoint(&polarDegrees));
191 if (polarDegrees == 0.0) {
192 pt += QPointF(dx, dy);
193 } else {
194 const qreal rad = DEGTORAD(polarDegrees);
195 const qreal sinDeg = sin(rad);
196 const qreal cosDeg = cos(rad);
197 pt.setX(pt.x() + dx * cosDeg + dy * sinDeg);
198 pt.setY(pt.y() - dx * sinDeg + dy * cosDeg);
199 }
200 return pt;
201}
202
204{
205 return d->area == r.referenceArea() && d->position == r.referencePosition() && d->alignment == r.alignment() && d->horizontalPadding == r.horizontalPadding() && d->verticalPadding == r.verticalPadding() && d->rotation == r.rotation();
206}
207
208#undef d
209
210#if !defined(QT_NO_DEBUG_STREAM)
212{
213 dbg << "KDChart::RelativePosition("
214 << "referencearea=" << rp.referenceArea()
215 << "referenceposition=" << rp.referencePosition()
216 << "alignment=" << rp.alignment()
217 << "horizontalpadding=" << rp.horizontalPadding()
218 << "verticalpadding=" << rp.verticalPadding()
219 << "rotation=" << rp.rotation()
220 << ")";
221 return dbg;
222}
223#endif /* QT_NO_DEBUG_STREAM */
Definition of global enums.
Declaring the class KDChart::Measure.
@ MeasureOrientationVertical
@ MeasureOrientationHorizontal
Measure is used to specify relative and absolute sizes in KDChart, e.g. font sizes.
qreal calculatedValue(const QObject *autoArea, KDChartEnums::MeasureOrientation autoOrientation) const
Stores the absolute target points of a Position.
QPointF point(Position position) const
Defines a position, using compass terminology.
static const Position & Unknown
Defines relative position information: reference area, position in this area (reference position),...
void setReferencePoints(const PositionPoints &points)
Set a set of points from which the anchor point will be selected.
void setReferenceArea(QObject *area)
Set the reference area to be used to find the anchor point.
void resetReferencePosition()
Resets the position of the anchor point to the built-in default.
const PositionPoints referencePoints() const
void setAlignment(Qt::Alignment flags)
void setReferencePosition(Position position)
Set the position of the anchor point.
bool operator==(const RelativePosition &) const
RelativePosition & operator=(const RelativePosition &other)
void setVerticalPadding(const Measure &padding)
const QPointF calculatedPoint(const QSizeF &autoSize) const
Calculate a point, according to the reference area/position and the padding.
const QPointF referencePoint(qreal *polarDegrees=nullptr) const
Return the reference point, according to the reference area/position, and ignoring padding.
void setHorizontalPadding(const Measure &padding)
QDebug operator<<(QDebug stream, const DataDimension &r)
virtual QRect geometry() const const override
virtual QLayout * layout() override
void setX(qreal x)
void setY(qreal y)
qreal x() const const
qreal y() const const
typedef Alignment

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Wed May 1 2024 00:01:10 for KD Chart API Documentation by doxygen 1.9.8