1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include <QtCharts/QHBarModelMapper> |
31 | |
32 | QT_CHARTS_BEGIN_NAMESPACE |
33 | |
34 | /*! |
35 | \class QHBarModelMapper |
36 | \inmodule QtCharts |
37 | \brief The QHBarModelMapper class is a horizontal model mapper for bar series. |
38 | |
39 | Model mappers enable using a data model derived from the QAbstractItemModel class |
40 | as a data source for a chart. A horizontal model mapper is used to create a connection |
41 | between a data model and QAbstractBarSeries, so that each row in the data model |
42 | defines a bar set and each column maps to a category in a bar series. |
43 | |
44 | Both model and bar series properties can be used to manipulate the data. The model mapper |
45 | keeps the bar series and the data model in sync. |
46 | |
47 | The model mapper ensures that all the bar sets in the bar series have equal sizes. |
48 | Therefore, adding or removing a value from a bar set causes the same change to be |
49 | made in all the bar sets in the bar series. |
50 | |
51 | \sa QVBarModelMapper |
52 | */ |
53 | /*! |
54 | \qmltype HBarModelMapper |
55 | \instantiates QHBarModelMapper |
56 | \inqmlmodule QtCharts |
57 | |
58 | \brief Horizontal model mapper for bar series. |
59 | |
60 | The HBarModelMapper type enables using a data model derived from the QAbstractItemModel |
61 | class as a data source for a chart. A horizontal model mapper is used to create a connection |
62 | between a data model and AbstractBarSeries, so that each row in the data model |
63 | defines a bar set and each column maps to a category in a bar series. You need to implement |
64 | the data model and expose it to QML. |
65 | |
66 | Both model and bar series properties can be used to manipulate the data. The model mapper |
67 | keeps the bar series and the data model in sync. |
68 | |
69 | The model mapper ensures that all the bar sets in the bar series have equal sizes. |
70 | Therefore, adding or removing a value from a bar set causes the same change to be |
71 | made in all the bar sets in the bar series. |
72 | |
73 | The following QML code snippet creates a bar series with three bar sets (assuming the model |
74 | has at least four rows). Each bar set contains data starting from column 1. The name |
75 | of a bar set is defined by the row header. |
76 | \code |
77 | BarSeries { |
78 | HBarModelMapper { |
79 | model: myCustomModel // QAbstractItemModel derived implementation |
80 | firstBarSetRow: 1 |
81 | lastBarSetRow: 3 |
82 | firstColumn: 1 |
83 | } |
84 | } |
85 | \endcode |
86 | |
87 | \sa VBarModelMapper |
88 | */ |
89 | |
90 | /*! |
91 | \property QHBarModelMapper::series |
92 | \brief The bar series that is used by the mapper. |
93 | |
94 | All the data in the series is discarded when it is set to the mapper. |
95 | When a new series is specified, the old series is disconnected (but it preserves its data). |
96 | */ |
97 | /*! |
98 | \qmlproperty AbstractBarSeries HBarModelMapper::series |
99 | The bar series that is used by the mapper. All the data in the series is discarded when it is |
100 | set to the mapper. When the new series is specified, the old series is disconnected (but it |
101 | preserves its data). |
102 | */ |
103 | |
104 | /*! |
105 | \property QHBarModelMapper::model |
106 | \brief Defines the model that is used by the mapper. |
107 | */ |
108 | /*! |
109 | \qmlproperty SomeModel HBarModelMapper::model |
110 | The data model that is used by the mapper. You need to implement the model and expose it to QML. |
111 | |
112 | \note The model has to support adding and removing rows or columns and modifying |
113 | the data in the cells. |
114 | */ |
115 | |
116 | /*! |
117 | \property QHBarModelMapper::firstBarSetRow |
118 | \brief The row of the model that is used as the data source for the first bar set. |
119 | |
120 | The default value is -1 (invalid mapping). |
121 | */ |
122 | /*! |
123 | \qmlproperty int HBarModelMapper::firstBarSetRow |
124 | Defines which row of the model is used as the data source for the first bar set. The default value is -1 |
125 | (invalid mapping). |
126 | */ |
127 | |
128 | /*! |
129 | \property QHBarModelMapper::lastBarSetRow |
130 | \brief The row of the model that is used as the data source for the last bar set. |
131 | |
132 | The default value is -1 (invalid mapping). |
133 | */ |
134 | /*! |
135 | \qmlproperty int HBarModelMapper::lastBarSetRow |
136 | The row of the model that is used as the data source for the last bar set. The default |
137 | value is -1 (invalid mapping). |
138 | */ |
139 | |
140 | /*! |
141 | \property QHBarModelMapper::firstColumn |
142 | \brief The column of the model that contains the first values of the bar sets in the bar series. |
143 | |
144 | The minimum and default value is 0. |
145 | */ |
146 | /*! |
147 | \qmlproperty int HBarModelMapper::firstColumn |
148 | The column of the model that contains the first values of the bar sets in the bar series. |
149 | The default value is 0. |
150 | */ |
151 | |
152 | /*! |
153 | \property QHBarModelMapper::columnCount |
154 | \brief The number of columns of the model that are mapped as the data for the bar series. |
155 | |
156 | The minimum and default value is -1 (number limited to the number of columns in the model). |
157 | */ |
158 | /*! |
159 | \qmlproperty int HBarModelMapper::columnCount |
160 | The number of columns of the model that are mapped as the data for the bar series. The default |
161 | value is -1 (number limited to the number of columns in the model). |
162 | */ |
163 | |
164 | /*! |
165 | \fn void QHBarModelMapper::seriesReplaced() |
166 | |
167 | This signal is emitted when the series that the mapper is connected to changes. |
168 | */ |
169 | |
170 | /*! |
171 | \fn void QHBarModelMapper::modelReplaced() |
172 | |
173 | This signal is emitted when the model that the mapper is connected to changes. |
174 | */ |
175 | |
176 | /*! |
177 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
178 | |
179 | This signal is emitted when the first bar set row changes. |
180 | */ |
181 | |
182 | /*! |
183 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
184 | |
185 | This signal is emitted when the last bar set row changes. |
186 | */ |
187 | |
188 | /*! |
189 | \fn void QHBarModelMapper::firstColumnChanged() |
190 | This signal is emitted when the first column changes. |
191 | */ |
192 | |
193 | /*! |
194 | \fn void QHBarModelMapper::columnCountChanged() |
195 | This signal is emitted when the number of columns changes. |
196 | */ |
197 | |
198 | /*! |
199 | Constructs a mapper object that is a child of \a parent. |
200 | */ |
201 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
202 | QBarModelMapper(parent) |
203 | { |
204 | QBarModelMapper::setOrientation(Qt::Horizontal); |
205 | } |
206 | |
207 | QAbstractItemModel *QHBarModelMapper::model() const |
208 | { |
209 | return QBarModelMapper::model(); |
210 | } |
211 | |
212 | void QHBarModelMapper::setModel(QAbstractItemModel *model) |
213 | { |
214 | if (model != QBarModelMapper::model()) { |
215 | QBarModelMapper::setModel(model); |
216 | emit modelReplaced(); |
217 | } |
218 | } |
219 | |
220 | QAbstractBarSeries *QHBarModelMapper::series() const |
221 | { |
222 | return QBarModelMapper::series(); |
223 | } |
224 | |
225 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) |
226 | { |
227 | if (series != QBarModelMapper::series()) { |
228 | QBarModelMapper::setSeries(series); |
229 | emit seriesReplaced(); |
230 | } |
231 | } |
232 | |
233 | int QHBarModelMapper::firstBarSetRow() const |
234 | { |
235 | return QBarModelMapper::firstBarSetSection(); |
236 | } |
237 | |
238 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
239 | { |
240 | if (firstBarSetRow != firstBarSetSection()) { |
241 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
242 | emit firstBarSetRowChanged(); |
243 | } |
244 | } |
245 | |
246 | int QHBarModelMapper::lastBarSetRow() const |
247 | { |
248 | return QBarModelMapper::lastBarSetSection(); |
249 | } |
250 | |
251 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
252 | { |
253 | if (lastBarSetRow != lastBarSetSection()) { |
254 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
255 | emit lastBarSetRowChanged(); |
256 | } |
257 | } |
258 | |
259 | int QHBarModelMapper::firstColumn() const |
260 | { |
261 | return QBarModelMapper::first(); |
262 | } |
263 | |
264 | void QHBarModelMapper::setFirstColumn(int firstColumn) |
265 | { |
266 | if (firstColumn != first()) { |
267 | QBarModelMapper::setFirst(firstColumn); |
268 | emit firstColumnChanged(); |
269 | } |
270 | } |
271 | |
272 | int QHBarModelMapper::columnCount() const |
273 | { |
274 | return QBarModelMapper::count(); |
275 | } |
276 | |
277 | void QHBarModelMapper::setColumnCount(int columnCount) |
278 | { |
279 | if (columnCount != count()) { |
280 | QBarModelMapper::setCount(columnCount); |
281 | emit columnCountChanged(); |
282 | } |
283 | } |
284 | |
285 | QT_CHARTS_END_NAMESPACE |
286 | |
287 | #include "moc_qhbarmodelmapper.cpp" |
288 | |