##// END OF EJS Templates
Add horizontal box plot model mapper....
Volker Krause -
r2873:4cbd063d2219
parent child
Show More
@@ -0,0 +1,266
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the Qt Charts module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:GPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU
20 ** General Public License version 3 or (at your option) any later version
21 ** approved by the KDE Free Qt Foundation. The licenses are as published by
22 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
23 ** included in the packaging of this file. Please review the following
24 ** information to ensure the GNU General Public License requirements will
25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
26 **
27 ** $QT_END_LICENSE$
28 **
29 ****************************************************************************/
30
31 #include <QtCharts/QHBoxPlotModelMapper>
32
33 QT_CHARTS_BEGIN_NAMESPACE
34
35 /*!
36 \class QHBoxPlotModelMapper
37 \inmodule Qt Charts
38 \brief Horizontal model mapper for box plot series.
39
40 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
41 Horizontal model mapper is used to create a connection between QBoxPlotSeries and QAbstractItemModel derived model object.
42 Model mapper maintains equal size of all the QBoxSets.
43 \note used model has to support adding/removing rows/columns and modifying the data of the cells.
44 */
45 /*!
46 \qmltype HBoxPlotModelMapper
47 \instantiates QHBoxPlotModelMapper
48 \inqmlmodule QtCharts
49
50 \brief Horizontal model mapper for box plot series.
51
52 HBoxPlotModelMapper allows you to use your own QAbstractItemModel derived model with data in
53 rows as a data source for any box-and-whiskers series. It is possible to use both
54 QAbstractItemModel and box-and-whiskers series data API to manipulate data. HBoxPlotModelMapper
55 keeps the series and the model in sync.
56
57 The following QML example would create a box-and-whiskers series with three box sets (assuming
58 the model has at least four rows). Each box set would contain data starting from column 1. The
59 name of a set would be defined by the vertical header (of the row).
60 \code
61 BoxPlotSeries {
62 HBoxPlotModelMapper {
63 model: myCustomModel // QAbstractItemModel derived implementation
64 firstBoxSetRow: 1
65 lastBoxSetRow: 3
66 firstColumn: 1
67 }
68 }
69 \endcode
70 */
71
72 /*!
73 \property QHBoxPlotModelMapper::series
74 \brief Defines the QBoxPlotSeries object that is used by the mapper.
75
76 All the data in the series is discarded when it is set to the mapper.
77 When new series is specified the old series is disconnected (it preserves its data)
78 */
79 /*!
80 \qmlproperty AbstractBarSeries HBoxPlotModelMapper::series
81 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
82 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
83 */
84
85 /*!
86 \property QHBoxPlotModelMapper::model
87 \brief Defines the model that is used by the mapper.
88 */
89 /*!
90 \qmlproperty SomeModel HBoxPlotModelMapper::model
91 The QAbstractItemModel based model that is used by the mapper. You need to implement the model
92 and expose it to QML. \note the model has to support adding/removing rows/columns and modifying
93 the data of the cells.
94 */
95
96 /*!
97 \property QHBoxPlotModelMapper::firstBoxSetRow
98 \brief Defines which row of the model is used as the data source for the first box-and-whiskers set.
99
100 Default value is: -1 (invalid mapping)
101 */
102 /*!
103 \qmlproperty int HBoxPlotModelMapper::firstBoxSetRow
104 Defines which row of the model is used as the data source for the first box-and-whiskers set. Default value
105 is: -1 (invalid mapping).
106 */
107
108 /*!
109 \property QHBoxPlotModelMapper::lastBoxSetRow
110 \brief Defines which row of the model is used as the data source for the last box-and-whiskers set.
111
112 Default value is: -1 (invalid mapping)
113 */
114 /*!
115 \qmlproperty int HBoxPlotModelMapper::lastBoxSetRow
116 Defines which row of the model is used as the data source for the last box-and-whiskers set. Default
117 value is: -1 (invalid mapping).
118 */
119
120 /*!
121 \property QHBoxPlotModelMapper::firstColumn
122 \brief Defines which column of the model contains the first values of the QBoxSets in the series.
123
124 Minimal and default value is: 0
125 */
126 /*!
127 \qmlproperty int HBoxPlotModelMapper::firstColumn
128 Defines which column of the model contains the first values of the QBoxSets in the series.
129 The default value is 0.
130 */
131
132 /*!
133 \property QHBoxPlotModelMapper::columnCount
134 \brief Defines the number of column of the model that are mapped as the data for QBoxPlotSeries
135
136 Minimal and default value is: -1 (count limited by the number of columns in the model)
137 */
138 /*!
139 \qmlproperty int HBoxPlotModelMapper::columnCount
140 Defines the number of columns of the model that are mapped as the data for QBoxPlotSeries. The default value is
141 -1 (count limited by the number of columns in the model)
142 */
143
144 /*!
145 \fn void QHBoxPlotModelMapper::seriesReplaced()
146
147 Emitted when the series to which mapper is connected to has changed.
148 */
149
150 /*!
151 \fn void QHBoxPlotModelMapper::modelReplaced()
152
153 Emitted when the model to which mapper is connected to has changed.
154 */
155
156 /*!
157 \fn void QHBoxPlotModelMapper::firstBoxSetRowChanged()
158 Emitted when the firstBoxSetRow has changed.
159 */
160
161 /*!
162 \fn void QHBoxPlotModelMapper::lastBoxSetRowChanged()
163 Emitted when the lastBoxSetRow has changed.
164 */
165
166 /*!
167 \fn void QHBoxPlotModelMapper::firstColumnChanged()
168 Emitted when the firstColumn has changed.
169 */
170
171 /*!
172 \fn void QHBoxPlotModelMapper::columnCountChanged()
173 Emitted when the columnCount has changed.
174 */
175
176 /*!
177 Constructs a mapper object which is a child of \a parent.
178 */
179 QHBoxPlotModelMapper::QHBoxPlotModelMapper(QObject *parent) :
180 QBoxPlotModelMapper(parent)
181 {
182 QBoxPlotModelMapper::setOrientation(Qt::Horizontal);
183 }
184
185 QAbstractItemModel *QHBoxPlotModelMapper::model() const
186 {
187 return QBoxPlotModelMapper::model();
188 }
189
190 void QHBoxPlotModelMapper::setModel(QAbstractItemModel *model)
191 {
192 if (model != QBoxPlotModelMapper::model()) {
193 QBoxPlotModelMapper::setModel(model);
194 emit modelReplaced();
195 }
196 }
197
198 QBoxPlotSeries *QHBoxPlotModelMapper::series() const
199 {
200 return QBoxPlotModelMapper::series();
201 }
202
203 void QHBoxPlotModelMapper::setSeries(QBoxPlotSeries *series)
204 {
205 if (series != QBoxPlotModelMapper::series()) {
206 QBoxPlotModelMapper::setSeries(series);
207 emit seriesReplaced();
208 }
209 }
210
211 int QHBoxPlotModelMapper::firstBoxSetRow() const
212 {
213 return QBoxPlotModelMapper::firstBoxSetSection();
214 }
215
216 void QHBoxPlotModelMapper::setFirstBoxSetRow(int firstBoxSetRow)
217 {
218 if (firstBoxSetRow != firstBoxSetSection()) {
219 QBoxPlotModelMapper::setFirstBoxSetSection(firstBoxSetRow);
220 emit firstBoxSetRowChanged();
221 }
222 }
223
224 int QHBoxPlotModelMapper::lastBoxSetRow() const
225 {
226 return QBoxPlotModelMapper::lastBoxSetSection();
227 }
228
229 void QHBoxPlotModelMapper::setLastBoxSetRow(int lastBoxSetRow)
230 {
231 if (lastBoxSetRow != lastBoxSetSection()) {
232 QBoxPlotModelMapper::setLastBoxSetSection(lastBoxSetRow);
233 emit lastBoxSetRowChanged();
234 }
235 }
236
237 int QHBoxPlotModelMapper::firstColumn() const
238 {
239 return QBoxPlotModelMapper::first();
240 }
241
242 void QHBoxPlotModelMapper::setFirstColumn(int firstColumn)
243 {
244 if (firstColumn != first()) {
245 QBoxPlotModelMapper::setFirst(firstColumn);
246 emit firstColumnChanged();
247 }
248 }
249
250 int QHBoxPlotModelMapper::columnCount() const
251 {
252 return QBoxPlotModelMapper::count();
253 }
254
255 void QHBoxPlotModelMapper::setColumnCount(int columnCount)
256 {
257 if (columnCount != count()) {
258 QBoxPlotModelMapper::setCount(columnCount);
259 emit columnCountChanged();
260 }
261 }
262
263 #include "moc_qhboxplotmodelmapper.cpp"
264
265 QT_CHARTS_END_NAMESPACE
266
@@ -0,0 +1,80
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the Qt Charts module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:GPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU
20 ** General Public License version 3 or (at your option) any later version
21 ** approved by the KDE Free Qt Foundation. The licenses are as published by
22 ** the Free Software Foundation and appearing in the file LICENSE.GPL3
23 ** included in the packaging of this file. Please review the following
24 ** information to ensure the GNU General Public License requirements will
25 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
26 **
27 ** $QT_END_LICENSE$
28 **
29 ****************************************************************************/
30
31 #ifndef QHBOXPLOTMODELMAPPER_H
32 #define QHBOXPLOTMODELMAPPER_H
33
34 #include <QtCharts/QBoxPlotModelMapper>
35
36 QT_CHARTS_BEGIN_NAMESPACE
37 /* Comment line for syncqt to generate the fwd-include correctly, due to QTBUG-22432 */
38 class QT_CHARTS_EXPORT QHBoxPlotModelMapper : public QBoxPlotModelMapper
39 {
40 Q_OBJECT
41 Q_PROPERTY(QBoxPlotSeries *series READ series WRITE setSeries NOTIFY seriesReplaced)
42 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced)
43 Q_PROPERTY(int firstBoxSetRow READ firstBoxSetRow WRITE setFirstBoxSetRow NOTIFY firstBoxSetRowChanged)
44 Q_PROPERTY(int lastBoxSetRow READ lastBoxSetRow WRITE setLastBoxSetRow NOTIFY lastBoxSetRowChanged)
45 Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged)
46 Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged)
47
48 public:
49 explicit QHBoxPlotModelMapper(QObject *parent = nullptr);
50
51 QAbstractItemModel *model() const;
52 void setModel(QAbstractItemModel *model);
53
54 QBoxPlotSeries *series() const;
55 void setSeries(QBoxPlotSeries *series);
56
57 int firstBoxSetRow() const;
58 void setFirstBoxSetRow(int firstBoxSetRow);
59
60 int lastBoxSetRow() const;
61 void setLastBoxSetRow(int lastBoxSetRow);
62
63 int firstColumn() const;
64 void setFirstColumn(int firstColumn);
65
66 int columnCount() const;
67 void setColumnCount(int rowCount);
68
69 Q_SIGNALS:
70 void seriesReplaced();
71 void modelReplaced();
72 void firstBoxSetRowChanged();
73 void lastBoxSetRowChanged();
74 void firstColumnChanged();
75 void columnCountChanged();
76 };
77
78 QT_CHARTS_END_NAMESPACE
79
80 #endif // QHBOXPLOTMODELMAPPER_H
@@ -7,6 +7,7 SOURCES += \
7 $$PWD/boxwhiskers.cpp \
7 $$PWD/boxwhiskers.cpp \
8 $$PWD/qboxset.cpp \
8 $$PWD/qboxset.cpp \
9 $$PWD/qboxplotmodelmapper.cpp \
9 $$PWD/qboxplotmodelmapper.cpp \
10 $$PWD/qhboxplotmodelmapper.cpp \
10 $$PWD/qvboxplotmodelmapper.cpp
11 $$PWD/qvboxplotmodelmapper.cpp
11
12
12 PRIVATE_HEADERS += \
13 PRIVATE_HEADERS += \
@@ -21,5 +22,6 PUBLIC_HEADERS += \
21 $$PWD/qboxplotseries.h \
22 $$PWD/qboxplotseries.h \
22 $$PWD/qboxset.h \
23 $$PWD/qboxset.h \
23 $$PWD/qboxplotmodelmapper.h \
24 $$PWD/qboxplotmodelmapper.h \
25 $$PWD/qhboxplotmodelmapper.h \
24 $$PWD/qvboxplotmodelmapper.h
26 $$PWD/qvboxplotmodelmapper.h
25
27
@@ -99,7 +99,7 QT_CHARTS_BEGIN_NAMESPACE
99 Default value is: -1 (invalid mapping)
99 Default value is: -1 (invalid mapping)
100 */
100 */
101 /*!
101 /*!
102 \qmlproperty int VBarModelMapper::firstBoxSetColumn
102 \qmlproperty int VBoxPlotModelMapper::firstBoxSetColumn
103 Defines which column of the model is used as the data source for the first box-and-whiskers set. Default value
103 Defines which column of the model is used as the data source for the first box-and-whiskers set. Default value
104 is: -1 (invalid mapping).
104 is: -1 (invalid mapping).
105 */
105 */
@@ -111,7 +111,7 QT_CHARTS_BEGIN_NAMESPACE
111 Default value is: -1 (invalid mapping)
111 Default value is: -1 (invalid mapping)
112 */
112 */
113 /*!
113 /*!
114 \qmlproperty int VBarModelMapper::lastBoxSetColumn
114 \qmlproperty int VBoxPlotModelMapper::lastBoxSetColumn
115 Defines which column of the model is used as the data source for the last box-and-whiskers set. Default
115 Defines which column of the model is used as the data source for the last box-and-whiskers set. Default
116 value is: -1 (invalid mapping).
116 value is: -1 (invalid mapping).
117 */
117 */
@@ -135,7 +135,7 QT_CHARTS_BEGIN_NAMESPACE
135 Minimal and default value is: -1 (count limited by the number of rows in the model)
135 Minimal and default value is: -1 (count limited by the number of rows in the model)
136 */
136 */
137 /*!
137 /*!
138 \qmlproperty int VBoxModelMapper::rowCount
138 \qmlproperty int VBoxPlotModelMapper::rowCount
139 Defines the number of rows of the model that are mapped as the data for QBoxPlotSeries. The default value is
139 Defines the number of rows of the model that are mapped as the data for QBoxPlotSeries. The default value is
140 -1 (count limited by the number of rows in the model)
140 -1 (count limited by the number of rows in the model)
141 */
141 */
@@ -56,6 +56,7
56 #include <QtCharts/QPieLegendMarker>
56 #include <QtCharts/QPieLegendMarker>
57 #include <QtCharts/QXYLegendMarker>
57 #include <QtCharts/QXYLegendMarker>
58 #include <QtCharts/QBoxPlotModelMapper>
58 #include <QtCharts/QBoxPlotModelMapper>
59 #include <QtCharts/QHBoxPlotModelMapper>
59 #include <QtCharts/QVBoxPlotModelMapper>
60 #include <QtCharts/QVBoxPlotModelMapper>
60 #ifndef QT_QREAL_IS_FLOAT
61 #ifndef QT_QREAL_IS_FLOAT
61 #include <QtCharts/QDateTimeAxis>
62 #include <QtCharts/QDateTimeAxis>
@@ -109,6 +110,7 QML_DECLARE_TYPE(QVXYModelMapper)
109 QML_DECLARE_TYPE(QXYLegendMarker)
110 QML_DECLARE_TYPE(QXYLegendMarker)
110 QML_DECLARE_TYPE(QXYModelMapper)
111 QML_DECLARE_TYPE(QXYModelMapper)
111 QML_DECLARE_TYPE(QBoxPlotModelMapper)
112 QML_DECLARE_TYPE(QBoxPlotModelMapper)
113 QML_DECLARE_TYPE(QHBoxPlotModelMapper)
112 QML_DECLARE_TYPE(QVBoxPlotModelMapper)
114 QML_DECLARE_TYPE(QVBoxPlotModelMapper)
113
115
114 QML_DECLARE_TYPE(QAbstractSeries)
116 QML_DECLARE_TYPE(QAbstractSeries)
@@ -251,6 +253,7 public:
251 qmlRegisterType<DeclarativeScatterSeries, 4>(uri, 1, 4, "ScatterSeries");
253 qmlRegisterType<DeclarativeScatterSeries, 4>(uri, 1, 4, "ScatterSeries");
252
254
253 // QtCharts 2.0
255 // QtCharts 2.0
256 qmlRegisterType<QHBoxPlotModelMapper>(uri, 2, 0, "HBoxPlotModelMapper");
254 qmlRegisterType<QVBoxPlotModelMapper>(uri, 2, 0, "VBoxPlotModelMapper");
257 qmlRegisterType<QVBoxPlotModelMapper>(uri, 2, 0, "VBoxPlotModelMapper");
255 qmlRegisterUncreatableType<QBoxPlotModelMapper>(uri, 2, 0, "BoxPlotModelMapper",
258 qmlRegisterUncreatableType<QBoxPlotModelMapper>(uri, 2, 0, "BoxPlotModelMapper",
256 QLatin1String("Trying to create uncreatable: BoxPlotModelMapper."));
259 QLatin1String("Trying to create uncreatable: BoxPlotModelMapper."));
General Comments 0
You need to be logged in to leave comments. Login now