KD Chart API Documentation 3.0
Loading...
Searching...
No Matches
KDChartAbstractCartesianDiagram.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#include "KDChartAbstractCartesianDiagram_p.h"
13
14#include <KDABLibFakes>
15
16using namespace KDChart;
17
18AbstractCartesianDiagram::Private::Private()
19{
20}
21
22AbstractCartesianDiagram::Private::~Private()
23{
24}
25
27{
28 if (other == this)
29 return true;
30 if (!other) {
31 return false;
32 }
33 return // compare the base class
34 (static_cast<const AbstractDiagram *>(this)->compare(other)) &&
35 // compare own properties
37}
38
39#define d d_func()
40
42 : AbstractDiagram(new Private(), parent, plane)
43{
44 init();
45}
46
48{
49 Q_FOREACH (CartesianAxis *axis, d->axesList) {
50 axis->deleteObserver(this);
51 }
52 d->axesList.clear();
53}
54
55void AbstractCartesianDiagram::init()
56{
57 d->compressor.setModel(attributesModel());
58 connect(this, SIGNAL(layoutChanged(AbstractDiagram *)),
59 &d->compressor, SLOT(slotDiagramLayoutChanged(AbstractDiagram *)));
62
63 if (d->plane) {
65 this, SIGNAL(viewportCoordinateSystemChanged()));
66 }
67}
68
70{
71 if (!d->axesList.contains(axis)) {
72 d->axesList.append(axis);
73 axis->createObserver(this);
75 }
76}
77
79{
80 const int idx = d->axesList.indexOf(axis);
81 if (idx != -1)
82 d->axesList.takeAt(idx);
83 axis->deleteObserver(this);
84 axis->setParentWidget(nullptr);
86}
87
89{
90 return d->axesList;
91}
92
94{
95 AbstractCoordinatePlane *plane = coordinatePlane();
96 if (plane) {
97 plane->layoutPlanes();
98 }
99}
100
102{
103 if (coordinatePlane()) {
104 disconnect(attributesModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
105 coordinatePlane(), SLOT(relayout()));
106 disconnect(attributesModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
107 coordinatePlane(), SLOT(relayout()));
108 disconnect(attributesModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
109 coordinatePlane(), SLOT(relayout()));
110 disconnect(attributesModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)),
111 coordinatePlane(), SLOT(relayout()));
112 disconnect(coordinatePlane());
113 }
114
116 if (plane) {
117 // Readjust the layout when the dataset count changes
118 connect(attributesModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
119 plane, SLOT(relayout()));
120 connect(attributesModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
121 plane, SLOT(relayout()));
122 connect(attributesModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)),
123 plane, SLOT(relayout()));
124 connect(attributesModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)),
125 plane, SLOT(relayout()));
126 connect(plane, SIGNAL(viewportCoordinateSystemChanged()),
127 this, SIGNAL(viewportCoordinateSystemChanged()));
128 connect(plane, SIGNAL(viewportCoordinateSystemChanged()), this, SLOT(update()));
129 }
130}
131
133{
134 d->referenceDiagram = diagram;
135 d->referenceDiagramOffset = offset;
136}
137
142
144{
145 return d->referenceDiagramOffset;
146}
147
149{
150 d->compressor.setRootIndex(attributesModel()->mapFromSource(index));
152}
153
155{
156 if (m == model()) {
157 return;
158 }
160}
161
169
171{
172 // The compressor must receive model signals before the diagram because the diagram will ask the
173 // compressor for data upon receiving dataChanged() et al. from the model, at which point the
174 // compressor must be up to date already.
175 // Starting from Qt 4.6, the invocation order of slots is guaranteed to be equal to connection
176 // order (and probably was before).
177 // This is our opportunity to connect to the AttributesModel before the AbstractDiagram does.
178
179 // ### A better design would be to properly recognize that the compressor is the real data interface
180 // for Cartesian diagrams and make diagrams listen to updates from the *compressor*, not the model.
181 // However, this would change the outside interface of AbstractCartesianDiagram which would be bad.
182 // So we're stuck with the complication of this slot and the corresponding signal.
183 d->compressor.setModel(newModel);
184}
void deleteObserver(AbstractDiagram *diagram)
void createObserver(AbstractDiagram *diagram)
Base class for diagrams based on a cartesian coordianate system.
AbstractCartesianDiagram(QWidget *parent=nullptr, CartesianCoordinatePlane *plane=nullptr)
void setAttributesModel(AttributesModel *amodel) override
Sets an external AttributesModel on this diagram.
void setRootIndex(const QModelIndex &index) override
virtual void setReferenceDiagram(AbstractCartesianDiagram *diagram, const QPointF &offset=QPointF())
virtual AbstractCartesianDiagram * referenceDiagram() const
void setModel(QAbstractItemModel *model) override
bool compare(const AbstractCartesianDiagram *other) const
virtual KDChart::CartesianAxisList axes() const
void setCoordinatePlane(AbstractCoordinatePlane *plane) override
Base class common for all coordinate planes, CartesianCoordinatePlane, PolarCoordinatePlane,...
AbstractDiagram defines the interface for diagram classes.
void setModel(QAbstractItemModel *model) override
virtual AttributesModel * attributesModel() const
void layoutChanged(AbstractDiagram *)
void viewportCoordinateSystemChanged()
virtual void setAttributesModel(AttributesModel *model)
Sets an external AttributesModel on this diagram.
virtual void setCoordinatePlane(AbstractCoordinatePlane *plane)
void setRootIndex(const QModelIndex &idx) override
Reimplemented for internal purposes.
void attributesModelAboutToChange(AttributesModel *newModel, AttributesModel *oldModel)
virtual void setParentWidget(QWidget *widget)
A proxy model used for decorating data with attributes.
QAbstractItemModel * model() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)

© 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 Feb 23 2024 00:02:57 for KD Chart API Documentation by doxygen 1.9.8