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
33QT_CHARTS_BEGIN_NAMESPACE
34
35/*!
36 \class QHBoxPlotModelMapper
37 \inmodule QtCharts
38 \brief The QHBoxPlotModelMapper class is a horizontal model mapper for box
39 plot series.
40
41 Model mappers enable using a data model derived from the QAbstractItemModel
42 class as a data source for a chart. A horizontal model mapper is used to
43 create a connection between a data model and QBoxPlotSeries object, so that
44 each row in the data model defines a box-and-whiskers item and each column
45 maps to the range and three median values of the box-and-whiskers item.
46
47 Both model and series properties can be used to manipulate the
48 data. The model mapper keeps the series and the data model in sync.
49
50 The model mapper ensures that all the box-and-whiskers items in the box plot
51 series have equal sizes. Therefore, adding or removing a value from a
52 box-and-whiskers item causes the same change to be made in all the
53 box-and-whiskers items in the box plot series.
54
55 \sa QVBoxPlotModelMapper
56*/
57/*!
58 \qmltype HBoxPlotModelMapper
59 \instantiates QHBoxPlotModelMapper
60 \inqmlmodule QtCharts
61
62 \brief Horizontal model mapper for box plot series.
63
64 The HBoxPlotModelMapper type enables using a data model derived from the
65 QAbstractItemModel class as a data source for a chart. A horizontal model
66 mapper is used to create a connection between a data model and a
67 BoxPlotSeries type, so that each row in the data model defines a
68 box-and-whiskers item and each column maps to the range and three median
69 values of the box-and-whiskers item.
70
71 Both model and series properties can be used to manipulate the data. The
72 model mapper keeps the series and the data model in sync.
73
74 The model mapper ensures that all the box-and-whiskers items in the box plot
75 series have equal sizes. Therefore, adding or removing a value from a
76 box-and-whiskers item causes the same change to be made in all the
77 box-and-whiskers items in the box plot series.
78
79 The following QML code snippet creates a box plot series with three
80 box-and-whiskers items (assuming the model has at least four rows). Each
81 box-and-whiskers item contains data starting from column 1. The name of an
82 item is defined by the row header.
83 \code
84 BoxPlotSeries {
85 HBoxPlotModelMapper {
86 model: myCustomModel // QAbstractItemModel derived implementation
87 firstBoxSetRow: 1
88 lastBoxSetRow: 3
89 firstColumn: 1
90 }
91 }
92 \endcode
93
94 \sa VBoxPlotModelMapper
95*/
96
97/*!
98 \property QHBoxPlotModelMapper::series
99 \brief The box plot series that is used by the mapper.
100
101 All the data in the series is discarded when it is set to the mapper.
102 When a new series is specified, the old series is disconnected (but it
103 preserves its data).
104*/
105/*!
106 \qmlproperty AbstractBarSeries HBoxPlotModelMapper::series
107 The box plot series that is used by the mapper. All the data in the series
108 is discarded when it is set to the mapper. When the new series is specified,
109 the old series is disconnected (but it preserves its data).
110*/
111
112/*!
113 \property QHBoxPlotModelMapper::model
114 \brief The model that is used by the mapper.
115*/
116/*!
117 \qmlproperty SomeModel HBoxPlotModelMapper::model
118 The data model that is used by the mapper. You need to implement the model
119 and expose it to QML.
120
121 \note The model has to support adding and removing rows or columns and
122 modifying the data in the cells.
123*/
124
125/*!
126 \property QHBoxPlotModelMapper::firstBoxSetRow
127 \brief The row of the model that is used as the data source for the first
128 box-and-whiskers item.
129
130 The default value is -1 (invalid mapping).
131*/
132/*!
133 \qmlproperty int HBoxPlotModelMapper::firstBoxSetRow
134 The row of the model is used as the data source for the first
135 box-and-whiskers item. The default value is -1 (invalid mapping).
136*/
137
138/*!
139 \property QHBoxPlotModelMapper::lastBoxSetRow
140 \brief The row of the model that is used as the data source for the last
141 box-and-whiskers item.
142
143 The default value is -1 (invalid mapping).
144*/
145/*!
146 \qmlproperty int HBoxPlotModelMapper::lastBoxSetRow
147 The row of the model is used as the data source for the last
148 box-and-whiskers item. The default value is -1 (invalid mapping).
149*/
150
151/*!
152 \property QHBoxPlotModelMapper::firstColumn
153 \brief The column of the model that contains the first values of the
154 box-and-whiskers items in the box plot series.
155
156 The minimum and default value is 0.
157*/
158/*!
159 \qmlproperty int HBoxPlotModelMapper::firstColumn
160 The column of the model that contains the first values of the
161 box-and-whiskers items in the box plot series.
162 The default value is 0.
163*/
164
165/*!
166 \property QHBoxPlotModelMapper::columnCount
167 \brief The number of columns of the model that are mapped as the data for
168 the box plot series.
169
170 The minimum and default value is -1 (number limited to the number of
171 columns in the model).
172*/
173/*!
174 \qmlproperty int HBoxPlotModelMapper::columnCount
175 The number of columns of the model that are mapped as the data for
176 the box plot series. The minimum and default value is -1 (number limited to
177 the number of columns in the model).
178*/
179
180/*!
181 \fn void QHBoxPlotModelMapper::seriesReplaced()
182
183 This signal is emitted when the series that the mapper is connected to
184 changes.
185*/
186
187/*!
188 \fn void QHBoxPlotModelMapper::modelReplaced()
189
190 This signal is emitted when the model that the mapper is connected to
191 changes.
192*/
193
194/*!
195 \fn void QHBoxPlotModelMapper::firstBoxSetRowChanged()
196 This signal is emitted when the first box-and-whiskers item row changes.
197*/
198
199/*!
200 \fn void QHBoxPlotModelMapper::lastBoxSetRowChanged()
201 This signal is emitted when the last box-and-whiskers item row changes.
202*/
203
204/*!
205 \fn void QHBoxPlotModelMapper::firstColumnChanged()
206 This signal is emitted when the first column changes.
207*/
208
209/*!
210 \fn void QHBoxPlotModelMapper::columnCountChanged()
211 This signal is emitted when the number of columns changes.
212*/
213
214/*!
215 Constructs a mapper object that is a child of \a parent.
216*/
217QHBoxPlotModelMapper::QHBoxPlotModelMapper(QObject *parent) :
218 QBoxPlotModelMapper(parent)
219{
220 QBoxPlotModelMapper::setOrientation(Qt::Horizontal);
221}
222
223QAbstractItemModel *QHBoxPlotModelMapper::model() const
224{
225 return QBoxPlotModelMapper::model();
226}
227
228void QHBoxPlotModelMapper::setModel(QAbstractItemModel *model)
229{
230 if (model != QBoxPlotModelMapper::model()) {
231 QBoxPlotModelMapper::setModel(model);
232 emit modelReplaced();
233 }
234}
235
236QBoxPlotSeries *QHBoxPlotModelMapper::series() const
237{
238 return QBoxPlotModelMapper::series();
239}
240
241void QHBoxPlotModelMapper::setSeries(QBoxPlotSeries *series)
242{
243 if (series != QBoxPlotModelMapper::series()) {
244 QBoxPlotModelMapper::setSeries(series);
245 emit seriesReplaced();
246 }
247}
248
249int QHBoxPlotModelMapper::firstBoxSetRow() const
250{
251 return QBoxPlotModelMapper::firstBoxSetSection();
252}
253
254void QHBoxPlotModelMapper::setFirstBoxSetRow(int firstBoxSetRow)
255{
256 if (firstBoxSetRow != firstBoxSetSection()) {
257 QBoxPlotModelMapper::setFirstBoxSetSection(firstBoxSetRow);
258 emit firstBoxSetRowChanged();
259 }
260}
261
262int QHBoxPlotModelMapper::lastBoxSetRow() const
263{
264 return QBoxPlotModelMapper::lastBoxSetSection();
265}
266
267void QHBoxPlotModelMapper::setLastBoxSetRow(int lastBoxSetRow)
268{
269 if (lastBoxSetRow != lastBoxSetSection()) {
270 QBoxPlotModelMapper::setLastBoxSetSection(lastBoxSetRow);
271 emit lastBoxSetRowChanged();
272 }
273}
274
275int QHBoxPlotModelMapper::firstColumn() const
276{
277 return QBoxPlotModelMapper::first();
278}
279
280void QHBoxPlotModelMapper::setFirstColumn(int firstColumn)
281{
282 if (firstColumn != first()) {
283 QBoxPlotModelMapper::setFirst(firstColumn);
284 emit firstColumnChanged();
285 }
286}
287
288int QHBoxPlotModelMapper::columnCount() const
289{
290 return QBoxPlotModelMapper::count();
291}
292
293void QHBoxPlotModelMapper::setColumnCount(int columnCount)
294{
295 if (columnCount != count()) {
296 QBoxPlotModelMapper::setCount(columnCount);
297 emit columnCountChanged();
298 }
299}
300
301QT_CHARTS_END_NAMESPACE
302
303#include "moc_qhboxplotmodelmapper.cpp"
304

source code of qtcharts/src/charts/boxplotchart/qhboxplotmodelmapper.cpp