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

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