KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
KDChartAbstractAxis.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
11#include "KDChartAbstractAxis.h"
12#include "KDChartAbstractAxis_p.h"
15#include "KDChartEnums.h"
16#include "KDChartMeasure.h"
17
18#include <KDABLibFakes>
19
20using namespace KDChart;
21
22#define d d_func()
23
24AbstractAxis::Private::Private(AbstractDiagram *diagram, AbstractAxis *axis)
25 : observer(nullptr)
26 , mDiagram(diagram)
27 , mAxis(axis)
28{
29 // Note: We do NOT call setDiagram( diagram, axis );
30 // but it is called in AbstractAxis::delayedInit() instead!
31}
32
33AbstractAxis::Private::~Private()
34{
35 delete observer;
36 observer = nullptr;
37}
38
39bool AbstractAxis::Private::setDiagram(AbstractDiagram *diagram_, bool delayedInit)
40{
41 AbstractDiagram *diagram = delayedInit ? mDiagram : diagram_;
42 if (delayedInit) {
43 mDiagram = nullptr;
44 }
45
46 // do not set a diagram again that was already set
47 if (diagram && ((diagram == mDiagram) || secondaryDiagrams.contains(diagram)))
48 return false;
49
50 bool bNewDiagramStored = false;
51 if (!mDiagram) {
52 mDiagram = diagram;
53 delete observer;
54 if (mDiagram) {
55 observer = new DiagramObserver(mDiagram, mAxis);
56 const bool con = connect(observer, &DiagramObserver::diagramDataChanged,
58 Q_UNUSED(con)
59 Q_ASSERT(con);
60 bNewDiagramStored = true;
61 } else {
62 observer = nullptr;
63 }
64 } else {
65 if (diagram)
66 secondaryDiagrams.enqueue(diagram);
67 }
68 return bNewDiagramStored;
69}
70
71void AbstractAxis::Private::unsetDiagram(AbstractDiagram *diagram)
72{
73 if (diagram == mDiagram) {
74 mDiagram = nullptr;
75 delete observer;
76 observer = nullptr;
77 } else {
78 secondaryDiagrams.removeAll(diagram);
79 }
80 if (!secondaryDiagrams.isEmpty()) {
81 AbstractDiagram *nextDiagram = secondaryDiagrams.dequeue();
82 setDiagram(nextDiagram);
83 }
84}
85
86bool AbstractAxis::Private::hasDiagram(AbstractDiagram *diagram) const
87{
88 return diagram == mDiagram || secondaryDiagrams.contains(diagram);
89}
90
91void AbstractAxis::Private::updateLayouts()
92{
93 if (auto *cartesianAxis = qobject_cast<CartesianAxis *>(mAxis)) {
94 cartesianAxis->layoutPlanes();
95 } else {
96 mAxis->update();
97 }
98}
99
101 : AbstractArea(new Private(diagram, this))
102{
103 init();
105}
106
108{
109 d->mDiagram = nullptr;
110 d->secondaryDiagrams.clear();
111}
112
113void AbstractAxis::init()
114{
116 d->textAttributes.setFontSize(m);
117 m.setValue(6);
119 d->textAttributes.setMinimalFontSize(m);
120 if (d->diagram())
121 createObserver(d->diagram());
122}
123
125{
126 // We call setDiagram() here, because the c'tor of Private
127 // only has stored the pointers, but it did not call setDiagram().
128 if (d)
129 d->setDiagram(nullptr, true /* delayedInit */);
130}
131
132bool AbstractAxis::compare(const AbstractAxis *other) const
133{
134 if (other == this) {
135 return true;
136 }
137 if (!other) {
138 return false;
139 }
140
141 return (static_cast<const AbstractAreaBase *>(this)->compare(other)) && (textAttributes() == other->textAttributes()) && (labels() == other->labels()) && (shortLabels() == other->shortLabels());
142}
143
145{
146 return label;
147}
148
150{
151 d->setDiagram(diagram);
152}
153
155{
156 d->unsetDiagram(diagram);
157}
158
160{
161 if (d->observer) {
162 const bool con = connect(d->observer, &DiagramObserver::diagramDataChanged,
164 Q_UNUSED(con);
165 Q_ASSERT(con);
166 }
167}
168
170{
171 if (d->textAttributes == a)
172 return;
173
174 d->textAttributes = a;
175 d->updateLayouts();
176}
177
179{
180 return d->textAttributes;
181}
182
184{
185 d->rulerAttributes = a;
186 d->updateLayouts();
187}
188
190{
191 return d->rulerAttributes;
192}
193
195{
196 if (d->hardLabels == list)
197 return;
198
199 d->hardLabels = list;
200 d->updateLayouts();
201}
202
204{
205 return d->hardLabels;
206}
207
209{
210 if (d->hardShortLabels == list)
211 return;
212
213 d->hardShortLabels = list;
214 d->updateLayouts();
215}
216
218{
219 return d->hardShortLabels;
220}
221
223{
224 if (d->diagram())
225 return d->diagram()->coordinatePlane();
226 return nullptr;
227}
228
230{
231 return d->diagram();
232}
233
235{
236 return d->hasDiagram(diagram);
237}
238
240{
241 if (d->diagram())
242 d->diagram()->update();
243}
Definition of global enums.
Declaring the class KDChart::Measure.
@ MeasureCalculationModeAbsolute
@ MeasureCalculationModeAuto
Base class for AbstractArea and AbstractAreaWidget: An area in the chart with a background,...
An area in the chart with a background, a frame, etc.
RulerAttributes rulerAttributes() const
Returns the attributes to be used for painting the rulers.
virtual const QString customizedLabel(const QString &label) const
Reimplement this method if you want to adjust axis labels before they are printed.
const AbstractDiagram * diagram() const
bool observedBy(AbstractDiagram *diagram) const
void setLabels(const QStringList &list)
Use this to specify your own set of strings, to be used as axis labels.
void deleteObserver(AbstractDiagram *diagram)
void createObserver(AbstractDiagram *diagram)
void setShortLabels(const QStringList &list)
Use this to specify your own set of strings, to be used as axis labels, in case the normal labels are...
void setRulerAttributes(const RulerAttributes &a)
Use this to specify the attributes used to paint the axis ruler.
void setTextAttributes(const TextAttributes &a)
Use this to specify the text attributes to be used for axis labels.
bool compare(const AbstractAxis *other) const
TextAttributes textAttributes() const
Returns the text attributes to be used for axis labels.
QStringList shortLabels() const
const AbstractCoordinatePlane * coordinatePlane() const
Convenience function, returns the coordinate plane, in which this axis is used.
AbstractAxis(AbstractDiagram *diagram=nullptr)
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane,...
AbstractDiagram defines the interface for diagram classes.
AbstractCoordinatePlane * coordinatePlane() const
A DiagramObserver watches the associated diagram for changes and deletion and emits corresponding sig...
void diagramDataChanged(AbstractDiagram *diagram)
Measure is used to specify relative and absolute sizes in KDChart, e.g. font sizes.
A set of attributes controlling the appearance of axis rulers.
A set of text attributes.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)

© 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 Fri Apr 26 2024 00:04:56 for KD Chart API Documentation by doxygen 1.9.8