KD Chart API Documentation 3.1
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 for (CartesianAxis *axis : qAsConst(d->axesList)) {
50 axis->deleteObserver(this);
51 }
52 d->axesList.clear();
53}
54
55void AbstractCartesianDiagram::init()
56{
57 d->compressor.setModel(attributesModel());
59 &d->compressor, &CartesianDiagramDataCompressor::slotDiagramLayoutChanged);
62
63 if (d->plane) {
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(), &AttributesModel::rowsRemoved,
105 coordinatePlane(), &AbstractCoordinatePlane::relayout);
106 disconnect(attributesModel(), &AttributesModel::rowsInserted,
107 coordinatePlane(), &AbstractCoordinatePlane::relayout);
108 disconnect(attributesModel(), &AttributesModel::columnsRemoved,
109 coordinatePlane(), &AbstractCoordinatePlane::relayout);
110 disconnect(attributesModel(), &AttributesModel::columnsInserted,
111 coordinatePlane(), &AbstractCoordinatePlane::relayout);
112 disconnect(coordinatePlane());
113 }
114
116 if (plane) {
117 // Readjust the layout when the dataset count changes
118 connect(attributesModel(), &AttributesModel::rowsRemoved,
120 connect(attributesModel(), &AttributesModel::rowsInserted,
122 connect(attributesModel(), &AttributesModel::columnsRemoved,
124 connect(attributesModel(), &AttributesModel::columnsInserted,
130 }
131}
132
134{
135 d->referenceDiagram = diagram;
136 d->referenceDiagramOffset = offset;
137}
138
143
145{
146 return d->referenceDiagramOffset;
147}
148
150{
151 d->compressor.setRootIndex(attributesModel()->mapFromSource(index));
153}
154
156{
157 if (m == model()) {
158 return;
159 }
161}
162
170
172{
173 // The compressor must receive model signals before the diagram because the diagram will ask the
174 // compressor for data upon receiving dataChanged() et al. from the model, at which point the
175 // compressor must be up to date already.
176 // Starting from Qt 4.6, the invocation order of slots is guaranteed to be equal to connection
177 // order (and probably was before).
178 // This is our opportunity to connect to the AttributesModel before the AbstractDiagram does.
179
180 // ### A better design would be to properly recognize that the compressor is the real data interface
181 // for Cartesian diagrams and make diagrams listen to updates from the *compressor*, not the model.
182 // However, this would change the outside interface of AbstractCartesianDiagram which would be bad.
183 // So we're stuck with the complication of this slot and the corresponding signal.
184 d->compressor.setModel(newModel);
185}
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.
void columnsInserted(const QModelIndex &parent, int first, int last)
void columnsRemoved(const QModelIndex &parent, int first, int last)
void rowsInserted(const QModelIndex &parent, int first, int last)
void rowsRemoved(const QModelIndex &parent, int first, int last)
QAbstractItemModel * model() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void update()

© 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