@@ -1,597 +1,633 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarmodelmapper.h" |
|
22 | 22 | #include "qbarmodelmapper_p.h" |
|
23 | 23 | #include "qbarseries.h" |
|
24 | 24 | #include "qbarset.h" |
|
25 | 25 | #include "qchart.h" |
|
26 | 26 | #include <QAbstractItemModel> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \class QBarModelMapper |
|
32 | 32 | \brief part of QtCommercial chart API. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
36 | 36 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
37 | 37 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. |
|
38 | 38 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. |
|
39 | 39 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. |
|
40 | 40 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
41 | 41 | */ |
|
42 | 42 | |
|
43 | 43 | /*! |
|
44 | 44 | \property QBarModelMapper::series |
|
45 | 45 | \brief Defines the QPieSeries object that is used by the mapper. |
|
46 | 46 | |
|
47 | 47 | All the data in the series is discarded when it is set to the mapper. |
|
48 | 48 | When new series is specified the old series is disconnected (it preserves its data) |
|
49 | 49 | */ |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | \property QBarModelMapper::model |
|
53 | 53 | \brief Defines the model that is used by the mapper. |
|
54 | 54 | */ |
|
55 | 55 | |
|
56 | 56 | /*! |
|
57 | 57 | \property QBarModelMapper::first |
|
58 | 58 | \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. |
|
59 | 59 | |
|
60 | 60 | Minimal and default value is: 0 |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QBarModelMapper::count |
|
65 | 65 | \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries |
|
66 | 66 | |
|
67 | 67 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
68 | 68 | */ |
|
69 | 69 | |
|
70 | 70 | /*! |
|
71 | \fn void QBarModelMapper::seriesReplaced() | |
|
72 | ||
|
73 | Emitted when the series to which mapper is connected to has changed. | |
|
74 | */ | |
|
75 | ||
|
76 | /*! | |
|
77 | \fn void QBarModelMapper::modelReplaced() | |
|
78 | ||
|
79 | Emitted when the model to which mapper is connected to has changed. | |
|
80 | */ | |
|
81 | ||
|
82 | /*! | |
|
83 | \fn void QBarModelMapper::firstChanged() | |
|
84 | ||
|
85 | Emitted when the value for the first has changed. | |
|
86 | */ | |
|
87 | ||
|
88 | /*! | |
|
89 | \fn void QBarModelMapper::countChanged() | |
|
90 | ||
|
91 | Emitted when the value for the count has changed. | |
|
92 | */ | |
|
93 | ||
|
94 | /*! | |
|
71 | 95 | Constructs a mapper object which is a child of \a parent. |
|
72 | 96 | */ |
|
73 | 97 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
74 | 98 | QObject(parent), |
|
75 | 99 | d_ptr(new QBarModelMapperPrivate(this)) |
|
76 | 100 | { |
|
77 | 101 | } |
|
78 | 102 | |
|
79 | 103 | QAbstractItemModel* QBarModelMapper::model() const |
|
80 | 104 | { |
|
81 | 105 | Q_D(const QBarModelMapper); |
|
82 | 106 | return d->m_model; |
|
83 | 107 | } |
|
84 | 108 | |
|
85 | 109 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
86 | 110 | { |
|
87 | 111 | if (model == 0) |
|
88 | 112 | return; |
|
89 | 113 | |
|
90 | 114 | Q_D(QBarModelMapper); |
|
91 | 115 | if (d->m_model) { |
|
92 | 116 | disconnect(d->m_model, 0, d, 0); |
|
93 | 117 | } |
|
94 | 118 | |
|
95 | 119 | d->m_model = model; |
|
96 | 120 | d->initializeBarFromModel(); |
|
97 | 121 | // connect signals from the model |
|
98 | 122 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
99 | 123 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); |
|
100 | 124 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
101 | 125 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
102 | 126 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
103 | 127 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
128 | ||
|
129 | emit modelReplaced(); | |
|
104 | 130 | } |
|
105 | 131 | |
|
106 | 132 | QBarSeries* QBarModelMapper::series() const |
|
107 | 133 | { |
|
108 | 134 | Q_D(const QBarModelMapper); |
|
109 | 135 | return d->m_series; |
|
110 | 136 | } |
|
111 | 137 | |
|
112 | 138 | void QBarModelMapper::setSeries(QBarSeries *series) |
|
113 | 139 | { |
|
114 | 140 | Q_D(QBarModelMapper); |
|
115 | 141 | if (d->m_series) { |
|
116 | 142 | disconnect(d->m_series, 0, d, 0); |
|
117 | 143 | } |
|
118 | 144 | |
|
119 | 145 | if (series == 0) |
|
120 | 146 | return; |
|
121 | 147 | |
|
122 | 148 | d->m_series = series; |
|
123 | 149 | d->initializeBarFromModel(); |
|
124 | 150 | // connect the signals from the series |
|
125 | 151 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); |
|
126 | 152 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); |
|
153 | ||
|
154 | emit seriesReplaced(); | |
|
127 | 155 | } |
|
128 | 156 | |
|
129 | 157 | int QBarModelMapper::first() const |
|
130 | 158 | { |
|
131 | 159 | Q_D(const QBarModelMapper); |
|
132 | 160 | return d->m_first; |
|
133 | 161 | } |
|
134 | 162 | |
|
135 | 163 | void QBarModelMapper::setFirst(int first) |
|
136 | 164 | { |
|
137 | 165 | Q_D(QBarModelMapper); |
|
166 | if (first != d->m_first) { | |
|
138 | 167 | d->m_first = qMax(first, 0); |
|
139 | 168 | d->initializeBarFromModel(); |
|
169 | ||
|
170 | emit firstChanged(); | |
|
171 | } | |
|
140 | 172 | } |
|
141 | 173 | |
|
142 | 174 | int QBarModelMapper::count() const |
|
143 | 175 | { |
|
144 | 176 | Q_D(const QBarModelMapper); |
|
145 | 177 | return d->m_count; |
|
146 | 178 | } |
|
147 | 179 | |
|
148 | 180 | void QBarModelMapper::setCount(int count) |
|
149 | 181 | { |
|
150 | 182 | Q_D(QBarModelMapper); |
|
183 | if (count != d->m_count) { | |
|
151 | 184 | d->m_count = qMax(count, -1); |
|
152 | 185 | d->initializeBarFromModel(); |
|
186 | ||
|
187 | emit countChanged(); | |
|
188 | } | |
|
153 | 189 | } |
|
154 | 190 | |
|
155 | 191 | /*! |
|
156 | 192 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
157 | 193 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
158 | 194 | or from columns (Qt::Vertical) |
|
159 | 195 | */ |
|
160 | 196 | Qt::Orientation QBarModelMapper::orientation() const |
|
161 | 197 | { |
|
162 | 198 | Q_D(const QBarModelMapper); |
|
163 | 199 | return d->m_orientation; |
|
164 | 200 | } |
|
165 | 201 | |
|
166 | 202 | /*! |
|
167 | 203 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
168 | 204 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
169 | 205 | or from columns (Qt::Vertical) |
|
170 | 206 | */ |
|
171 | 207 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
172 | 208 | { |
|
173 | 209 | Q_D(QBarModelMapper); |
|
174 | 210 | d->m_orientation = orientation; |
|
175 | 211 | d->initializeBarFromModel(); |
|
176 | 212 | } |
|
177 | 213 | |
|
178 | 214 | /*! |
|
179 | 215 | Returns which section of the model is used as the data source for the first bar set |
|
180 | 216 | */ |
|
181 | 217 | int QBarModelMapper::firstBarSetSection() const |
|
182 | 218 | { |
|
183 | 219 | Q_D(const QBarModelMapper); |
|
184 | 220 | return d->m_firstBarSetSection; |
|
185 | 221 | } |
|
186 | 222 | |
|
187 | 223 | /*! |
|
188 | 224 | Sets the model section that is used as the data source for the first bar set |
|
189 | 225 | Parameter \a firstBarSetSection specifies the section of the model. |
|
190 | 226 | */ |
|
191 | 227 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
192 | 228 | { |
|
193 | 229 | Q_D(QBarModelMapper); |
|
194 | 230 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); |
|
195 | 231 | d->initializeBarFromModel(); |
|
196 | 232 | } |
|
197 | 233 | |
|
198 | 234 | /*! |
|
199 | 235 | Returns which section of the model is used as the data source for the last bar set |
|
200 | 236 | */ |
|
201 | 237 | int QBarModelMapper::lastBarSetSection() const |
|
202 | 238 | { |
|
203 | 239 | Q_D(const QBarModelMapper); |
|
204 | 240 | return d->m_lastBarSetSection; |
|
205 | 241 | } |
|
206 | 242 | |
|
207 | 243 | /*! |
|
208 | 244 | Sets the model section that is used as the data source for the last bar set |
|
209 | 245 | Parameter \a lastBarSetSection specifies the section of the model. |
|
210 | 246 | */ |
|
211 | 247 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
212 | 248 | { |
|
213 | 249 | Q_D(QBarModelMapper); |
|
214 | 250 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); |
|
215 | 251 | d->initializeBarFromModel(); |
|
216 | 252 | } |
|
217 | 253 | |
|
218 | 254 | /*! |
|
219 | 255 | Resets the QBarModelMapper to the default state. |
|
220 | 256 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 |
|
221 | 257 | */ |
|
222 | 258 | void QBarModelMapper::reset() |
|
223 | 259 | { |
|
224 | 260 | Q_D(QBarModelMapper); |
|
225 | 261 | d->m_first = 0; |
|
226 | 262 | d->m_count = -1; |
|
227 | 263 | d->m_firstBarSetSection = -1; |
|
228 | 264 | d->m_lastBarSetSection = -1; |
|
229 | 265 | d->initializeBarFromModel(); |
|
230 | 266 | } |
|
231 | 267 | |
|
232 | 268 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
233 | 269 | |
|
234 | 270 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
235 | 271 | m_series(0), |
|
236 | 272 | m_model(0), |
|
237 | 273 | m_first(0), |
|
238 | 274 | m_count(-1), |
|
239 | 275 | m_orientation(Qt::Vertical), |
|
240 | 276 | m_firstBarSetSection(-1), |
|
241 | 277 | m_lastBarSetSection(-1), |
|
242 | 278 | m_seriesSignalsBlock(false), |
|
243 | 279 | m_modelSignalsBlock(false), |
|
244 | 280 | q_ptr(q) |
|
245 | 281 | { |
|
246 | 282 | } |
|
247 | 283 | |
|
248 | 284 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
249 | 285 | { |
|
250 | 286 | m_modelSignalsBlock = block; |
|
251 | 287 | } |
|
252 | 288 | |
|
253 | 289 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
254 | 290 | { |
|
255 | 291 | m_seriesSignalsBlock = block; |
|
256 | 292 | } |
|
257 | 293 | |
|
258 | 294 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
259 | 295 | { |
|
260 | 296 | if (!index.isValid()) |
|
261 | 297 | return 0; |
|
262 | 298 | |
|
263 | 299 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
264 | 300 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
265 | 301 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
266 | 302 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
267 | 303 | // else |
|
268 | 304 | // return 0; |
|
269 | 305 | } |
|
270 | 306 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
271 | 307 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
272 | 308 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
273 | 309 | } |
|
274 | 310 | return 0; // This part of model has not been mapped to any slice |
|
275 | 311 | } |
|
276 | 312 | |
|
277 | 313 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
278 | 314 | { |
|
279 | 315 | if (m_count != -1 && posInBar >= m_count) |
|
280 | 316 | return QModelIndex(); // invalid |
|
281 | 317 | |
|
282 | 318 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
283 | 319 | return QModelIndex(); // invalid |
|
284 | 320 | |
|
285 | 321 | if (m_orientation == Qt::Vertical) |
|
286 | 322 | return m_model->index(posInBar + m_first, barSection); |
|
287 | 323 | else |
|
288 | 324 | return m_model->index(barSection, posInBar + m_first); |
|
289 | 325 | } |
|
290 | 326 | |
|
291 | 327 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
292 | 328 | { |
|
293 | 329 | Q_UNUSED(topLeft) |
|
294 | 330 | Q_UNUSED(bottomRight) |
|
295 | 331 | |
|
296 | 332 | if (m_model == 0 || m_series == 0) |
|
297 | 333 | return; |
|
298 | 334 | |
|
299 | 335 | if (m_modelSignalsBlock) |
|
300 | 336 | return; |
|
301 | 337 | |
|
302 | 338 | blockSeriesSignals(); |
|
303 | 339 | QModelIndex index; |
|
304 | 340 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
305 | 341 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
306 | 342 | index = topLeft.sibling(row, column); |
|
307 | 343 | QBarSet* bar = barSet(index); |
|
308 | 344 | if (bar) { |
|
309 | 345 | if (m_orientation == Qt::Vertical) |
|
310 | 346 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
311 | 347 | else |
|
312 | 348 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
313 | 349 | } |
|
314 | 350 | } |
|
315 | 351 | } |
|
316 | 352 | blockSeriesSignals(false); |
|
317 | 353 | } |
|
318 | 354 | |
|
319 | 355 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) |
|
320 | 356 | { |
|
321 | 357 | if (m_model == 0 || m_series == 0) |
|
322 | 358 | return; |
|
323 | 359 | |
|
324 | 360 | if (m_modelSignalsBlock) |
|
325 | 361 | return; |
|
326 | 362 | |
|
327 | 363 | blockSeriesSignals(); |
|
328 | 364 | if (orientation != m_orientation) { |
|
329 | 365 | for (int section = first; section <= last; section++) { |
|
330 | 366 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { |
|
331 | 367 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); |
|
332 | 368 | if (bar) |
|
333 | 369 | bar->setLabel(m_model->headerData(section, orientation).toString()); |
|
334 | 370 | } |
|
335 | 371 | } |
|
336 | 372 | } |
|
337 | 373 | blockSeriesSignals(false); |
|
338 | 374 | } |
|
339 | 375 | |
|
340 | 376 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
341 | 377 | { |
|
342 | 378 | Q_UNUSED(parent); |
|
343 | 379 | Q_UNUSED(end) |
|
344 | 380 | if (m_modelSignalsBlock) |
|
345 | 381 | return; |
|
346 | 382 | |
|
347 | 383 | blockSeriesSignals(); |
|
348 | 384 | if (m_orientation == Qt::Vertical) |
|
349 | 385 | // insertData(start, end); |
|
350 | 386 | initializeBarFromModel(); |
|
351 | 387 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
352 | 388 | initializeBarFromModel(); |
|
353 | 389 | blockSeriesSignals(false); |
|
354 | 390 | } |
|
355 | 391 | |
|
356 | 392 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
357 | 393 | { |
|
358 | 394 | Q_UNUSED(parent); |
|
359 | 395 | Q_UNUSED(end) |
|
360 | 396 | if (m_modelSignalsBlock) |
|
361 | 397 | return; |
|
362 | 398 | |
|
363 | 399 | blockSeriesSignals(); |
|
364 | 400 | if (m_orientation == Qt::Vertical) |
|
365 | 401 | // removeData(start, end); |
|
366 | 402 | initializeBarFromModel(); |
|
367 | 403 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
368 | 404 | initializeBarFromModel(); |
|
369 | 405 | blockSeriesSignals(false); |
|
370 | 406 | } |
|
371 | 407 | |
|
372 | 408 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
373 | 409 | { |
|
374 | 410 | Q_UNUSED(parent); |
|
375 | 411 | Q_UNUSED(end) |
|
376 | 412 | if (m_modelSignalsBlock) |
|
377 | 413 | return; |
|
378 | 414 | |
|
379 | 415 | blockSeriesSignals(); |
|
380 | 416 | if (m_orientation == Qt::Horizontal) |
|
381 | 417 | // insertData(start, end); |
|
382 | 418 | initializeBarFromModel(); |
|
383 | 419 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
384 | 420 | initializeBarFromModel(); |
|
385 | 421 | blockSeriesSignals(false); |
|
386 | 422 | } |
|
387 | 423 | |
|
388 | 424 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
389 | 425 | { |
|
390 | 426 | Q_UNUSED(parent); |
|
391 | 427 | Q_UNUSED(end) |
|
392 | 428 | if (m_modelSignalsBlock) |
|
393 | 429 | return; |
|
394 | 430 | |
|
395 | 431 | blockSeriesSignals(); |
|
396 | 432 | if (m_orientation == Qt::Horizontal) |
|
397 | 433 | // removeData(start, end); |
|
398 | 434 | initializeBarFromModel(); |
|
399 | 435 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
400 | 436 | initializeBarFromModel(); |
|
401 | 437 | blockSeriesSignals(false); |
|
402 | 438 | } |
|
403 | 439 | |
|
404 | 440 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
405 | 441 | { |
|
406 | 442 | Q_UNUSED(end) |
|
407 | 443 | Q_UNUSED(start) |
|
408 | 444 | Q_UNUSED(end) |
|
409 | 445 | // To be implemented |
|
410 | 446 | } |
|
411 | 447 | |
|
412 | 448 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
413 | 449 | { |
|
414 | 450 | Q_UNUSED(end) |
|
415 | 451 | Q_UNUSED(start) |
|
416 | 452 | Q_UNUSED(end) |
|
417 | 453 | // To be implemented |
|
418 | 454 | } |
|
419 | 455 | |
|
420 | 456 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) |
|
421 | 457 | { |
|
422 | 458 | if (m_seriesSignalsBlock) |
|
423 | 459 | return; |
|
424 | 460 | |
|
425 | 461 | if (sets.count() == 0) |
|
426 | 462 | return; |
|
427 | 463 | |
|
428 | 464 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); |
|
429 | 465 | if (firstIndex == -1) |
|
430 | 466 | return; |
|
431 | 467 | |
|
432 | 468 | int maxCount = 0; |
|
433 | 469 | for(int i = 0; i < sets.count(); i++) |
|
434 | 470 | if (sets.at(i)->count() > m_count) |
|
435 | 471 | maxCount = sets.at(i)->count(); |
|
436 | 472 | |
|
437 | 473 | if (m_count != -1 && m_count < maxCount) |
|
438 | 474 | m_count = maxCount; |
|
439 | 475 | |
|
440 | 476 | m_lastBarSetSection += sets.count(); |
|
441 | 477 | |
|
442 | 478 | blockModelSignals(); |
|
443 | 479 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; |
|
444 | 480 | if (maxCount > modelCapacity) { |
|
445 | 481 | if (m_orientation == Qt::Vertical) |
|
446 | 482 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); |
|
447 | 483 | else |
|
448 | 484 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); |
|
449 | 485 | } |
|
450 | 486 | |
|
451 | 487 | if (m_orientation == Qt::Vertical) |
|
452 | 488 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
453 | 489 | else |
|
454 | 490 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
455 | 491 | |
|
456 | 492 | |
|
457 | 493 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { |
|
458 | 494 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); |
|
459 | 495 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) |
|
460 | 496 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y()); |
|
461 | 497 | } |
|
462 | 498 | blockModelSignals(false); |
|
463 | 499 | initializeBarFromModel(); |
|
464 | 500 | } |
|
465 | 501 | |
|
466 | 502 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) |
|
467 | 503 | { |
|
468 | 504 | if (m_seriesSignalsBlock) |
|
469 | 505 | return; |
|
470 | 506 | |
|
471 | 507 | if (sets.count() == 0) |
|
472 | 508 | return; |
|
473 | 509 | |
|
474 | 510 | int firstIndex = m_barSets.indexOf(sets.at(0)); |
|
475 | 511 | if (firstIndex == -1) |
|
476 | 512 | return; |
|
477 | 513 | |
|
478 | 514 | m_lastBarSetSection -= sets.count(); |
|
479 | 515 | |
|
480 | 516 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) |
|
481 | 517 | m_barSets.removeAt(i); |
|
482 | 518 | |
|
483 | 519 | blockModelSignals(); |
|
484 | 520 | if (m_orientation == Qt::Vertical) |
|
485 | 521 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
486 | 522 | else |
|
487 | 523 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
488 | 524 | blockModelSignals(false); |
|
489 | 525 | initializeBarFromModel(); |
|
490 | 526 | } |
|
491 | 527 | |
|
492 | 528 | void QBarModelMapperPrivate::valuesAdded(int index, int count) |
|
493 | 529 | { |
|
494 | 530 | if (m_seriesSignalsBlock) |
|
495 | 531 | return; |
|
496 | 532 | |
|
497 | 533 | if (m_count != -1) |
|
498 | 534 | m_count += count; |
|
499 | 535 | |
|
500 | 536 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
501 | 537 | |
|
502 | 538 | blockModelSignals(); |
|
503 | 539 | if (m_orientation == Qt::Vertical) |
|
504 | 540 | m_model->insertRows(index + m_first, count); |
|
505 | 541 | else |
|
506 | 542 | m_model->insertColumns(index + m_first, count); |
|
507 | 543 | |
|
508 | 544 | for (int j = index; j < index + count; j++) |
|
509 | 545 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y()); |
|
510 | 546 | |
|
511 | 547 | blockModelSignals(false); |
|
512 | 548 | initializeBarFromModel(); |
|
513 | 549 | } |
|
514 | 550 | |
|
515 | 551 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) |
|
516 | 552 | { |
|
517 | 553 | if (m_seriesSignalsBlock) |
|
518 | 554 | return; |
|
519 | 555 | |
|
520 | 556 | if (m_count != -1) |
|
521 | 557 | m_count -= count; |
|
522 | 558 | |
|
523 | 559 | blockModelSignals(); |
|
524 | 560 | if (m_orientation == Qt::Vertical) |
|
525 | 561 | m_model->removeRows(index + m_first, count); |
|
526 | 562 | else |
|
527 | 563 | m_model->removeColumns(index + m_first, count); |
|
528 | 564 | |
|
529 | 565 | blockModelSignals(false); |
|
530 | 566 | initializeBarFromModel(); |
|
531 | 567 | } |
|
532 | 568 | |
|
533 | 569 | void QBarModelMapperPrivate::barLabelChanged() |
|
534 | 570 | { |
|
535 | 571 | if (m_seriesSignalsBlock) |
|
536 | 572 | return; |
|
537 | 573 | |
|
538 | 574 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
539 | 575 | |
|
540 | 576 | blockModelSignals(); |
|
541 | 577 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); |
|
542 | 578 | blockModelSignals(false); |
|
543 | 579 | initializeBarFromModel(); |
|
544 | 580 | } |
|
545 | 581 | |
|
546 | 582 | void QBarModelMapperPrivate::barValueChanged(int index) |
|
547 | 583 | { |
|
548 | 584 | if (m_seriesSignalsBlock) |
|
549 | 585 | return; |
|
550 | 586 | |
|
551 | 587 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
552 | 588 | |
|
553 | 589 | blockModelSignals(); |
|
554 | 590 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y()); |
|
555 | 591 | blockModelSignals(false); |
|
556 | 592 | initializeBarFromModel(); |
|
557 | 593 | } |
|
558 | 594 | |
|
559 | 595 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
560 | 596 | { |
|
561 | 597 | if (m_model == 0 || m_series == 0) |
|
562 | 598 | return; |
|
563 | 599 | |
|
564 | 600 | blockSeriesSignals(); |
|
565 | 601 | // clear current content |
|
566 | 602 | m_series->clear(); |
|
567 | 603 | m_barSets.clear(); |
|
568 | 604 | |
|
569 | 605 | // create the initial bar sets |
|
570 | 606 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
571 | 607 | int posInBar = 0; |
|
572 | 608 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
573 | 609 | // check if there is such model index |
|
574 | 610 | if (barIndex.isValid()) { |
|
575 | 611 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); |
|
576 | 612 | while (barIndex.isValid()) { |
|
577 | 613 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
578 | 614 | posInBar++; |
|
579 | 615 | barIndex = barModelIndex(i, posInBar); |
|
580 | 616 | } |
|
581 | 617 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); |
|
582 | 618 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); |
|
583 | 619 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); |
|
584 | 620 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); |
|
585 | 621 | m_series->append(barSet); |
|
586 | 622 | m_barSets.append(barSet); |
|
587 | 623 | } else { |
|
588 | 624 | break; |
|
589 | 625 | } |
|
590 | 626 | } |
|
591 | 627 | blockSeriesSignals(false); |
|
592 | 628 | } |
|
593 | 629 | |
|
594 | 630 | #include "moc_qbarmodelmapper.cpp" |
|
595 | 631 | #include "moc_qbarmodelmapper_p.cpp" |
|
596 | 632 | |
|
597 | 633 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,79 +1,85 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QBARMODELMAPPER_H |
|
22 | 22 | #define QBARMODELMAPPER_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include <QObject> |
|
26 | 26 | |
|
27 | 27 | class QAbstractItemModel; |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QBarModelMapperPrivate; |
|
32 | 32 | class QBarSeries; |
|
33 | 33 | class QChart; |
|
34 | 34 | |
|
35 | 35 | class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject |
|
36 | 36 | { |
|
37 | 37 | Q_OBJECT |
|
38 | Q_PROPERTY(QBarSeries *series READ series WRITE setSeries) | |
|
39 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel) | |
|
40 | Q_PROPERTY(int first READ first WRITE setFirst) | |
|
41 | Q_PROPERTY(int count READ count WRITE setCount) | |
|
38 | Q_PROPERTY(QBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |
|
39 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) | |
|
40 | Q_PROPERTY(int first READ first WRITE setFirst NOTIFY firstChanged) | |
|
41 | Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) | |
|
42 | 42 | Q_ENUMS(Qt::Orientation) |
|
43 | 43 | |
|
44 | 44 | protected: |
|
45 | 45 | explicit QBarModelMapper(QObject *parent = 0); |
|
46 | 46 | |
|
47 | 47 | public: |
|
48 | 48 | QAbstractItemModel* model() const; |
|
49 | 49 | void setModel(QAbstractItemModel *model); |
|
50 | 50 | |
|
51 | 51 | QBarSeries* series() const; |
|
52 | 52 | void setSeries(QBarSeries *series); |
|
53 | 53 | |
|
54 | 54 | int first() const; |
|
55 | 55 | void setFirst(int first); |
|
56 | 56 | |
|
57 | 57 | int count() const; |
|
58 | 58 | void setCount(int count); |
|
59 | 59 | |
|
60 | 60 | void reset(); |
|
61 | 61 | |
|
62 | 62 | protected: |
|
63 | 63 | int firstBarSetSection() const; |
|
64 | 64 | void setFirstBarSetSection(int firstBarSetSection); |
|
65 | 65 | |
|
66 | 66 | int lastBarSetSection() const; |
|
67 | 67 | void setLastBarSetSection(int lastBarSetSection); |
|
68 | 68 | |
|
69 | 69 | Qt::Orientation orientation() const; |
|
70 | 70 | void setOrientation(Qt::Orientation orientation); |
|
71 | 71 | |
|
72 | Q_SIGNALS: | |
|
73 | void seriesReplaced(); | |
|
74 | void modelReplaced(); | |
|
75 | void firstChanged(); | |
|
76 | void countChanged(); | |
|
77 | ||
|
72 | 78 | protected: |
|
73 | 79 | QBarModelMapperPrivate * const d_ptr; |
|
74 | 80 | Q_DECLARE_PRIVATE(QBarModelMapper) |
|
75 | 81 | }; |
|
76 | 82 | |
|
77 | 83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | 84 | |
|
79 | 85 | #endif // QBARMODELMAPPER_H |
@@ -1,83 +1,101 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qhbarmodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QHBarModelMapper |
|
27 | 27 | \brief part of QtCommercial chart API. |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
32 | 32 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. |
|
33 | 33 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. |
|
34 | 34 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. |
|
35 | 35 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
36 | 36 | */ |
|
37 | 37 | |
|
38 | 38 | /*! |
|
39 | 39 | \property QHBarModelMapper::firstBarSetRow |
|
40 | 40 | \brief Defines which column of the model is used as the data source for the first bar set |
|
41 | 41 | |
|
42 | 42 | Default value is: -1 (invalid mapping) |
|
43 | 43 | */ |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 | 46 | \property QHBarModelMapper::lastBarSetRow |
|
47 | 47 | \brief Defines which column of the model is used as the data source for the last bar set |
|
48 | 48 | |
|
49 | 49 | Default value is: -1 (invalid mapping) |
|
50 | 50 | */ |
|
51 | 51 | |
|
52 | 52 | /*! |
|
53 | \fn void QHBarModelMapper::firstBarSetRowChanged() | |
|
54 | ||
|
55 | Emitted when the firstBarSetRow has changed. | |
|
56 | */ | |
|
57 | ||
|
58 | /*! | |
|
59 | \fn void QHBarModelMapper::lastBarSetRowChanged() | |
|
60 | ||
|
61 | Emitted when the lastBarSetRow has changed. | |
|
62 | */ | |
|
63 | ||
|
64 | /*! | |
|
53 | 65 | Constructs a mapper object which is a child of \a parent. |
|
54 | 66 | */ |
|
55 | 67 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
56 | 68 | QBarModelMapper(parent) |
|
57 | 69 | { |
|
58 | 70 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
59 | 71 | } |
|
60 | 72 | |
|
61 | 73 | int QHBarModelMapper::firstBarSetRow() const |
|
62 | 74 | { |
|
63 | 75 | return QBarModelMapper::firstBarSetSection(); |
|
64 | 76 | } |
|
65 | 77 | |
|
66 | 78 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
67 | 79 | { |
|
80 | if (firstBarSetRow != firstBarSetSection()) { | |
|
68 | 81 | return QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
82 | emit firstBarSetRowChanged(); | |
|
83 | } | |
|
69 | 84 | } |
|
70 | 85 | |
|
71 | 86 | int QHBarModelMapper::lastBarSetRow() const |
|
72 | 87 | { |
|
73 | 88 | return QBarModelMapper::lastBarSetSection(); |
|
74 | 89 | } |
|
75 | 90 | |
|
76 | 91 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
77 | 92 | { |
|
93 | if (lastBarSetRow != lastBarSetSection()) { | |
|
78 | 94 | return QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
95 | emit lastBarSetRowChanged(); | |
|
96 | } | |
|
79 | 97 | } |
|
80 | 98 | |
|
81 | 99 | #include "moc_qhbarmodelmapper.cpp" |
|
82 | 100 | |
|
83 | 101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,50 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QHBARMODELMAPPER_H |
|
22 | 22 | #define QHBARMODELMAPPER_H |
|
23 | 23 | |
|
24 | 24 | #include <QBarModelMapper> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper |
|
29 | 29 | { |
|
30 | 30 | Q_OBJECT |
|
31 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow) | |
|
32 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow) | |
|
31 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow NOTIFY firstBarSetRowChanged) | |
|
32 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow NOTIFY lastBarSetRowChanged) | |
|
33 | 33 | |
|
34 | 34 | public: |
|
35 | 35 | explicit QHBarModelMapper(QObject *parent = 0); |
|
36 | 36 | |
|
37 | 37 | int firstBarSetRow() const; |
|
38 | 38 | void setFirstBarSetRow(int firstBarSetRow); |
|
39 | 39 | |
|
40 | 40 | int lastBarSetRow() const; |
|
41 | 41 | void setLastBarSetRow(int lastBarSetRow); |
|
42 | ||
|
43 | Q_SIGNALS: | |
|
44 | void firstBarSetRowChanged(); | |
|
45 | void lastBarSetRowChanged(); | |
|
42 | 46 | }; |
|
43 | 47 | |
|
44 | 48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | 49 | |
|
46 | 50 | #endif // QHBARMODELMAPPER_H |
@@ -1,83 +1,101 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qvbarmodelmapper.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | /*! |
|
26 | 26 | \class QVBarModelMapper |
|
27 | 27 | \brief part of QtCommercial chart API. |
|
28 | 28 | \mainclass |
|
29 | 29 | |
|
30 | 30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
31 | 31 | Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
32 | 32 | Curently it is NOT possible to use both QAbstractItemModel and QBarSeries model API. |
|
33 | 33 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. |
|
34 | 34 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. |
|
35 | 35 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
36 | 36 | */ |
|
37 | 37 | |
|
38 | 38 | /*! |
|
39 | 39 | \property QVBarModelMapper::firstBarSetColumn |
|
40 | 40 | \brief Defines which column of the model is used as the data source for the first bar set |
|
41 | 41 | |
|
42 | 42 | Default value is: -1 (invalid mapping) |
|
43 | 43 | */ |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 | 46 | \property QVBarModelMapper::lastBarSetColumn |
|
47 | 47 | \brief Defines which column of the model is used as the data source for the last bar set |
|
48 | 48 | |
|
49 | 49 | Default value is: -1 (invalid mapping) |
|
50 | 50 | */ |
|
51 | 51 | |
|
52 | 52 | /*! |
|
53 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |
|
54 | ||
|
55 | Emitted when the firstBarSetColumn has changed. | |
|
56 | */ | |
|
57 | ||
|
58 | /*! | |
|
59 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |
|
60 | ||
|
61 | Emitted when the lastBarSetColumn has changed. | |
|
62 | */ | |
|
63 | ||
|
64 | /*! | |
|
53 | 65 | Constructs a mapper object which is a child of \a parent. |
|
54 | 66 | */ |
|
55 | 67 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
56 | 68 | QBarModelMapper(parent) |
|
57 | 69 | { |
|
58 | 70 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
59 | 71 | } |
|
60 | 72 | |
|
61 | 73 | int QVBarModelMapper::firstBarSetColumn() const |
|
62 | 74 | { |
|
63 | 75 | return QBarModelMapper::firstBarSetSection(); |
|
64 | 76 | } |
|
65 | 77 | |
|
66 | 78 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
67 | 79 | { |
|
80 | if (firstBarSetColumn != firstBarSetSection()) { | |
|
68 | 81 | return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
82 | emit firstBarSetColumnChanged(); | |
|
83 | } | |
|
69 | 84 | } |
|
70 | 85 | |
|
71 | 86 | int QVBarModelMapper::lastBarSetColumn() const |
|
72 | 87 | { |
|
73 | 88 | return QBarModelMapper::lastBarSetSection(); |
|
74 | 89 | } |
|
75 | 90 | |
|
76 | 91 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
77 | 92 | { |
|
93 | if (lastBarSetColumn != lastBarSetSection()) { | |
|
78 | 94 | return QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
95 | emit lastBarSetColumnChanged(); | |
|
96 | } | |
|
79 | 97 | } |
|
80 | 98 | |
|
81 | 99 | #include "moc_qvbarmodelmapper.cpp" |
|
82 | 100 | |
|
83 | 101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,50 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QVBARMODELMAPPER_H |
|
22 | 22 | #define QVBARMODELMAPPER_H |
|
23 | 23 | |
|
24 | 24 | #include <QBarModelMapper> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper |
|
29 | 29 | { |
|
30 | 30 | Q_OBJECT |
|
31 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn) | |
|
32 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn) | |
|
31 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn NOTIFY firstBarSetColumnChanged) | |
|
32 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn NOTIFY lastBarSetColumnChanged) | |
|
33 | 33 | |
|
34 | 34 | public: |
|
35 | 35 | explicit QVBarModelMapper(QObject *parent = 0); |
|
36 | 36 | |
|
37 | 37 | int firstBarSetColumn() const; |
|
38 | 38 | void setFirstBarSetColumn(int firstBarSetColumn); |
|
39 | 39 | |
|
40 | 40 | int lastBarSetColumn() const; |
|
41 | 41 | void setLastBarSetColumn(int lastBarSetColumn); |
|
42 | ||
|
43 | Q_SIGNALS: | |
|
44 | void firstBarSetColumnChanged(); | |
|
45 | void lastBarSetColumnChanged(); | |
|
42 | 46 | }; |
|
43 | 47 | |
|
44 | 48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | 49 | |
|
46 | 50 | #endif // QVBARMODELMAPPER_H |
General Comments 0
You need to be logged in to leave comments.
Login now