This diff has been collapsed as it changes many lines, (538 lines changed) Show them Hide them | |||||
@@ -0,0 +1,538 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "qboxplotmodelmapper.h" | |||
|
22 | #include "qboxplotmodelmapper_p.h" | |||
|
23 | #include "qboxplotseries.h" | |||
|
24 | #include "qboxset.h" | |||
|
25 | #include "qchart.h" | |||
|
26 | #include <QAbstractItemModel> | |||
|
27 | ||||
|
28 | #include <QDebug> | |||
|
29 | ||||
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
31 | ||||
|
32 | QBoxPlotModelMapper::QBoxPlotModelMapper(QObject *parent) : | |||
|
33 | QObject(parent), | |||
|
34 | d_ptr(new QBoxPlotModelMapperPrivate(this)) | |||
|
35 | { | |||
|
36 | } | |||
|
37 | ||||
|
38 | QAbstractItemModel *QBoxPlotModelMapper::model() const | |||
|
39 | { | |||
|
40 | Q_D(const QBoxPlotModelMapper); | |||
|
41 | return d->m_model; | |||
|
42 | } | |||
|
43 | ||||
|
44 | void QBoxPlotModelMapper::setModel(QAbstractItemModel *model) | |||
|
45 | { | |||
|
46 | if (model == 0) | |||
|
47 | return; | |||
|
48 | ||||
|
49 | Q_D(QBoxPlotModelMapper); | |||
|
50 | if (d->m_model) | |||
|
51 | disconnect(d->m_model, 0, d, 0); | |||
|
52 | ||||
|
53 | d->m_model = model; | |||
|
54 | d->initializeBoxFromModel(); | |||
|
55 | // connect signals from the model | |||
|
56 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |||
|
57 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); | |||
|
58 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |||
|
59 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |||
|
60 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |||
|
61 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |||
|
62 | connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed())); | |||
|
63 | } | |||
|
64 | ||||
|
65 | QBoxPlotSeries *QBoxPlotModelMapper::series() const | |||
|
66 | { | |||
|
67 | Q_D(const QBoxPlotModelMapper); | |||
|
68 | return d->m_series; | |||
|
69 | } | |||
|
70 | ||||
|
71 | void QBoxPlotModelMapper::setSeries(QBoxPlotSeries *series) | |||
|
72 | { | |||
|
73 | Q_D(QBoxPlotModelMapper); | |||
|
74 | if (d->m_series) | |||
|
75 | disconnect(d->m_series, 0, d, 0); | |||
|
76 | ||||
|
77 | if (series == 0) | |||
|
78 | return; | |||
|
79 | ||||
|
80 | d->m_series = series; | |||
|
81 | d->initializeBoxFromModel(); | |||
|
82 | // connect the signals from the series | |||
|
83 | connect(d->m_series, SIGNAL(boxsetsAdded(QList<QBoxSet*>)), d, SLOT(boxSetsAdded(QList<QBoxSet*>))); | |||
|
84 | connect(d->m_series, SIGNAL(boxsetsRemoved(QList<QBoxSet*>)), d, SLOT(boxSetsRemoved(QList<QBoxSet*>))); | |||
|
85 | connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed())); | |||
|
86 | } | |||
|
87 | ||||
|
88 | /*! | |||
|
89 | Returns which row/column of the model contains the first values of the QBoxSets in the series. | |||
|
90 | The default value is 0. | |||
|
91 | */ | |||
|
92 | int QBoxPlotModelMapper::first() const | |||
|
93 | { | |||
|
94 | Q_D(const QBoxPlotModelMapper); | |||
|
95 | return d->m_first; | |||
|
96 | } | |||
|
97 | ||||
|
98 | /*! | |||
|
99 | Sets which row of the model contains the \a first values of the QBoxSets in the series. | |||
|
100 | The default value is 0. | |||
|
101 | */ | |||
|
102 | void QBoxPlotModelMapper::setFirst(int first) | |||
|
103 | { | |||
|
104 | Q_D(QBoxPlotModelMapper); | |||
|
105 | d->m_first = qMax(first, 0); | |||
|
106 | d->initializeBoxFromModel(); | |||
|
107 | } | |||
|
108 | ||||
|
109 | /*! | |||
|
110 | Returns the number of rows/columns of the model that are mapped as the data for QBoxPlotSeries | |||
|
111 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |||
|
112 | */ | |||
|
113 | int QBoxPlotModelMapper::count() const | |||
|
114 | { | |||
|
115 | Q_D(const QBoxPlotModelMapper); | |||
|
116 | return d->m_count; | |||
|
117 | } | |||
|
118 | ||||
|
119 | /*! | |||
|
120 | Sets the \a count of rows/columns of the model that are mapped as the data for QBoxPlotSeries | |||
|
121 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |||
|
122 | */ | |||
|
123 | void QBoxPlotModelMapper::setCount(int count) | |||
|
124 | { | |||
|
125 | Q_D(QBoxPlotModelMapper); | |||
|
126 | d->m_count = qMax(count, -1); | |||
|
127 | d->initializeBoxFromModel(); | |||
|
128 | } | |||
|
129 | ||||
|
130 | /*! | |||
|
131 | Returns the orientation that is used when QBoxPlotModelMapper accesses the model. | |||
|
132 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) | |||
|
133 | or from columns (Qt::Vertical) | |||
|
134 | */ | |||
|
135 | Qt::Orientation QBoxPlotModelMapper::orientation() const | |||
|
136 | { | |||
|
137 | Q_D(const QBoxPlotModelMapper); | |||
|
138 | return d->m_orientation; | |||
|
139 | } | |||
|
140 | ||||
|
141 | /*! | |||
|
142 | Returns the \a orientation that is used when QBoxPlotModelMapper accesses the model. | |||
|
143 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) | |||
|
144 | or from columns (Qt::Vertical) | |||
|
145 | */ | |||
|
146 | void QBoxPlotModelMapper::setOrientation(Qt::Orientation orientation) | |||
|
147 | { | |||
|
148 | Q_D(QBoxPlotModelMapper); | |||
|
149 | d->m_orientation = orientation; | |||
|
150 | d->initializeBoxFromModel(); | |||
|
151 | } | |||
|
152 | ||||
|
153 | /*! | |||
|
154 | Returns which section of the model is used as the data source for the first box set | |||
|
155 | */ | |||
|
156 | int QBoxPlotModelMapper::firstBoxSetSection() const | |||
|
157 | { | |||
|
158 | Q_D(const QBoxPlotModelMapper); | |||
|
159 | return d->m_firstBoxSetSection; | |||
|
160 | } | |||
|
161 | ||||
|
162 | /*! | |||
|
163 | Sets the model section that is used as the data source for the first box set | |||
|
164 | Parameter \a firstBoxSetSection specifies the section of the model. | |||
|
165 | */ | |||
|
166 | void QBoxPlotModelMapper::setFirstBoxSetSection(int firstBoxSetSection) | |||
|
167 | { | |||
|
168 | Q_D(QBoxPlotModelMapper); | |||
|
169 | d->m_firstBoxSetSection = qMax(-1, firstBoxSetSection); | |||
|
170 | d->initializeBoxFromModel(); | |||
|
171 | } | |||
|
172 | ||||
|
173 | /*! | |||
|
174 | Returns which section of the model is used as the data source for the last box set | |||
|
175 | */ | |||
|
176 | int QBoxPlotModelMapper::lastBoxSetSection() const | |||
|
177 | { | |||
|
178 | Q_D(const QBoxPlotModelMapper); | |||
|
179 | return d->m_lastBoxSetSection; | |||
|
180 | } | |||
|
181 | ||||
|
182 | /*! | |||
|
183 | Sets the model section that is used as the data source for the last box set | |||
|
184 | Parameter \a lastBoxSetSection specifies the section of the model. | |||
|
185 | */ | |||
|
186 | void QBoxPlotModelMapper::setLastBoxSetSection(int lastBoxSetSection) | |||
|
187 | { | |||
|
188 | Q_D(QBoxPlotModelMapper); | |||
|
189 | d->m_lastBoxSetSection = qMax(-1, lastBoxSetSection); | |||
|
190 | d->initializeBoxFromModel(); | |||
|
191 | } | |||
|
192 | ||||
|
193 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
194 | ||||
|
195 | QBoxPlotModelMapperPrivate::QBoxPlotModelMapperPrivate(QBoxPlotModelMapper *q) : | |||
|
196 | QObject(q), | |||
|
197 | m_series(0), | |||
|
198 | m_model(0), | |||
|
199 | m_first(0), | |||
|
200 | m_count(-1), | |||
|
201 | m_orientation(Qt::Vertical), | |||
|
202 | m_firstBoxSetSection(-1), | |||
|
203 | m_lastBoxSetSection(-1), | |||
|
204 | m_seriesSignalsBlock(false), | |||
|
205 | m_modelSignalsBlock(false), | |||
|
206 | q_ptr(q) | |||
|
207 | { | |||
|
208 | } | |||
|
209 | ||||
|
210 | void QBoxPlotModelMapperPrivate::blockModelSignals(bool block) | |||
|
211 | { | |||
|
212 | m_modelSignalsBlock = block; | |||
|
213 | } | |||
|
214 | ||||
|
215 | void QBoxPlotModelMapperPrivate::blockSeriesSignals(bool block) | |||
|
216 | { | |||
|
217 | m_seriesSignalsBlock = block; | |||
|
218 | } | |||
|
219 | ||||
|
220 | QBoxSet *QBoxPlotModelMapperPrivate::boxSet(QModelIndex index) | |||
|
221 | { | |||
|
222 | if (!index.isValid()) | |||
|
223 | return 0; | |||
|
224 | ||||
|
225 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBoxSetSection && index.column() <= m_lastBoxSetSection) { | |||
|
226 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |||
|
227 | return m_series->boxSets().at(index.column() - m_firstBoxSetSection); | |||
|
228 | } | |||
|
229 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBoxSetSection && index.row() <= m_lastBoxSetSection) { | |||
|
230 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |||
|
231 | return m_series->boxSets().at(index.row() - m_firstBoxSetSection); | |||
|
232 | } | |||
|
233 | return 0; // This part of model has not been mapped to any slice | |||
|
234 | } | |||
|
235 | ||||
|
236 | QModelIndex QBoxPlotModelMapperPrivate::boxModelIndex(int boxSection, int posInBar) | |||
|
237 | { | |||
|
238 | if (m_count != -1 && posInBar >= m_count) | |||
|
239 | return QModelIndex(); // invalid | |||
|
240 | ||||
|
241 | if (boxSection < m_firstBoxSetSection || boxSection > m_lastBoxSetSection) | |||
|
242 | return QModelIndex(); // invalid | |||
|
243 | ||||
|
244 | if (m_orientation == Qt::Vertical) | |||
|
245 | return m_model->index(posInBar + m_first, boxSection); | |||
|
246 | else | |||
|
247 | return m_model->index(boxSection, posInBar + m_first); | |||
|
248 | } | |||
|
249 | ||||
|
250 | void QBoxPlotModelMapperPrivate::handleSeriesDestroyed() | |||
|
251 | { | |||
|
252 | m_series = 0; | |||
|
253 | } | |||
|
254 | ||||
|
255 | void QBoxPlotModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |||
|
256 | { | |||
|
257 | Q_UNUSED(topLeft) | |||
|
258 | Q_UNUSED(bottomRight) | |||
|
259 | ||||
|
260 | if (m_model == 0 || m_series == 0) | |||
|
261 | return; | |||
|
262 | ||||
|
263 | if (m_modelSignalsBlock) | |||
|
264 | return; | |||
|
265 | ||||
|
266 | blockSeriesSignals(); | |||
|
267 | QModelIndex index; | |||
|
268 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |||
|
269 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |||
|
270 | index = topLeft.sibling(row, column); | |||
|
271 | QBoxSet *box = boxSet(index); | |||
|
272 | if (box) { | |||
|
273 | if (m_orientation == Qt::Vertical) | |||
|
274 | box->replace(row - m_first, m_model->data(index).toReal()); | |||
|
275 | else | |||
|
276 | box->replace(column - m_first, m_model->data(index).toReal()); | |||
|
277 | } | |||
|
278 | } | |||
|
279 | } | |||
|
280 | blockSeriesSignals(false); | |||
|
281 | } | |||
|
282 | ||||
|
283 | void QBoxPlotModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) | |||
|
284 | { | |||
|
285 | Q_UNUSED(orientation); | |||
|
286 | Q_UNUSED(first); | |||
|
287 | Q_UNUSED(last); | |||
|
288 | ||||
|
289 | qDebug() << "ALERT: QBoxPlotModelMapperPrivate::modelHeaderDataUpdated implement"; | |||
|
290 | } | |||
|
291 | ||||
|
292 | void QBoxPlotModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |||
|
293 | { | |||
|
294 | Q_UNUSED(parent) | |||
|
295 | if (m_modelSignalsBlock) | |||
|
296 | return; | |||
|
297 | ||||
|
298 | blockSeriesSignals(); | |||
|
299 | if (m_orientation == Qt::Vertical) | |||
|
300 | insertData(start, end); | |||
|
301 | else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize | |||
|
302 | initializeBoxFromModel(); | |||
|
303 | blockSeriesSignals(false); | |||
|
304 | } | |||
|
305 | ||||
|
306 | void QBoxPlotModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |||
|
307 | { | |||
|
308 | Q_UNUSED(parent) | |||
|
309 | if (m_modelSignalsBlock) | |||
|
310 | return; | |||
|
311 | ||||
|
312 | blockSeriesSignals(); | |||
|
313 | if (m_orientation == Qt::Vertical) | |||
|
314 | removeData(start, end); | |||
|
315 | else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize | |||
|
316 | initializeBoxFromModel(); | |||
|
317 | blockSeriesSignals(false); | |||
|
318 | } | |||
|
319 | ||||
|
320 | void QBoxPlotModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |||
|
321 | { | |||
|
322 | Q_UNUSED(parent) | |||
|
323 | if (m_modelSignalsBlock) | |||
|
324 | return; | |||
|
325 | ||||
|
326 | blockSeriesSignals(); | |||
|
327 | if (m_orientation == Qt::Horizontal) | |||
|
328 | insertData(start, end); | |||
|
329 | else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize | |||
|
330 | initializeBoxFromModel(); | |||
|
331 | blockSeriesSignals(false); | |||
|
332 | } | |||
|
333 | ||||
|
334 | void QBoxPlotModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |||
|
335 | { | |||
|
336 | Q_UNUSED(parent) | |||
|
337 | if (m_modelSignalsBlock) | |||
|
338 | return; | |||
|
339 | ||||
|
340 | blockSeriesSignals(); | |||
|
341 | if (m_orientation == Qt::Horizontal) | |||
|
342 | removeData(start, end); | |||
|
343 | else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize | |||
|
344 | initializeBoxFromModel(); | |||
|
345 | blockSeriesSignals(false); | |||
|
346 | } | |||
|
347 | ||||
|
348 | void QBoxPlotModelMapperPrivate::handleModelDestroyed() | |||
|
349 | { | |||
|
350 | m_model = 0; | |||
|
351 | } | |||
|
352 | ||||
|
353 | void QBoxPlotModelMapperPrivate::insertData(int start, int end) | |||
|
354 | { | |||
|
355 | Q_UNUSED(end) | |||
|
356 | Q_UNUSED(start) | |||
|
357 | Q_UNUSED(end) | |||
|
358 | // Currently barchart needs to be fully recalculated when change is made. | |||
|
359 | // Re-initialize | |||
|
360 | initializeBoxFromModel(); | |||
|
361 | } | |||
|
362 | ||||
|
363 | void QBoxPlotModelMapperPrivate::removeData(int start, int end) | |||
|
364 | { | |||
|
365 | Q_UNUSED(end) | |||
|
366 | Q_UNUSED(start) | |||
|
367 | Q_UNUSED(end) | |||
|
368 | // Currently barchart needs to be fully recalculated when change is made. | |||
|
369 | // Re-initialize | |||
|
370 | initializeBoxFromModel(); | |||
|
371 | } | |||
|
372 | ||||
|
373 | void QBoxPlotModelMapperPrivate::boxSetsAdded(QList<QBoxSet *> sets) | |||
|
374 | { | |||
|
375 | if (m_seriesSignalsBlock) | |||
|
376 | return; | |||
|
377 | ||||
|
378 | if (sets.count() == 0) | |||
|
379 | return; | |||
|
380 | ||||
|
381 | int firstIndex = m_series->boxSets().indexOf(sets.at(0)); | |||
|
382 | if (firstIndex == -1) | |||
|
383 | return; | |||
|
384 | ||||
|
385 | int maxCount = 0; | |||
|
386 | for (int i = 0; i < sets.count(); i++) { | |||
|
387 | if (sets.at(i)->count() > m_count) | |||
|
388 | maxCount = sets.at(i)->count(); | |||
|
389 | } | |||
|
390 | ||||
|
391 | if (m_count != -1 && m_count < maxCount) | |||
|
392 | m_count = maxCount; | |||
|
393 | ||||
|
394 | m_lastBoxSetSection += sets.count(); | |||
|
395 | ||||
|
396 | blockModelSignals(); | |||
|
397 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; | |||
|
398 | if (maxCount > modelCapacity) { | |||
|
399 | if (m_orientation == Qt::Vertical) | |||
|
400 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); | |||
|
401 | else | |||
|
402 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); | |||
|
403 | } | |||
|
404 | ||||
|
405 | if (m_orientation == Qt::Vertical) | |||
|
406 | m_model->insertColumns(firstIndex + m_firstBoxSetSection, sets.count()); | |||
|
407 | else | |||
|
408 | m_model->insertRows(firstIndex + m_firstBoxSetSection, sets.count()); | |||
|
409 | ||||
|
410 | ||||
|
411 | for (int i = firstIndex + m_firstBoxSetSection; i < firstIndex + m_firstBoxSetSection + sets.count(); i++) { | |||
|
412 | //m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBoxSetSection)->label()); | |||
|
413 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBoxSetSection)->count(); j++) | |||
|
414 | m_model->setData(boxModelIndex(i, j), sets.at(i - firstIndex - m_firstBoxSetSection)->at(j)); | |||
|
415 | } | |||
|
416 | blockModelSignals(false); | |||
|
417 | initializeBoxFromModel(); | |||
|
418 | } | |||
|
419 | ||||
|
420 | void QBoxPlotModelMapperPrivate::boxSetsRemoved(QList<QBoxSet *> sets) | |||
|
421 | { | |||
|
422 | if (m_seriesSignalsBlock) | |||
|
423 | return; | |||
|
424 | ||||
|
425 | if (sets.count() == 0) | |||
|
426 | return; | |||
|
427 | ||||
|
428 | int firstIndex = m_boxSets.indexOf(sets.at(0)); | |||
|
429 | if (firstIndex == -1) | |||
|
430 | return; | |||
|
431 | ||||
|
432 | m_lastBoxSetSection -= sets.count(); | |||
|
433 | ||||
|
434 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) | |||
|
435 | m_boxSets.removeAt(i); | |||
|
436 | ||||
|
437 | blockModelSignals(); | |||
|
438 | if (m_orientation == Qt::Vertical) | |||
|
439 | m_model->removeColumns(firstIndex + m_firstBoxSetSection, sets.count()); | |||
|
440 | else | |||
|
441 | m_model->removeRows(firstIndex + m_firstBoxSetSection, sets.count()); | |||
|
442 | blockModelSignals(false); | |||
|
443 | initializeBoxFromModel(); | |||
|
444 | } | |||
|
445 | ||||
|
446 | void QBoxPlotModelMapperPrivate::valuesAdded(int index, int count) | |||
|
447 | { | |||
|
448 | if (m_seriesSignalsBlock) | |||
|
449 | return; | |||
|
450 | ||||
|
451 | if (m_count != -1) | |||
|
452 | m_count += count; | |||
|
453 | ||||
|
454 | int boxSetIndex = m_boxSets.indexOf(qobject_cast<QBoxSet *>(QObject::sender())); | |||
|
455 | ||||
|
456 | blockModelSignals(); | |||
|
457 | if (m_orientation == Qt::Vertical) | |||
|
458 | m_model->insertRows(index + m_first, count); | |||
|
459 | else | |||
|
460 | m_model->insertColumns(index + m_first, count); | |||
|
461 | ||||
|
462 | for (int j = index; j < index + count; j++) | |||
|
463 | m_model->setData(boxModelIndex(boxSetIndex + m_firstBoxSetSection, j), m_boxSets.at(boxSetIndex)->at(j)); | |||
|
464 | ||||
|
465 | blockModelSignals(false); | |||
|
466 | initializeBoxFromModel(); | |||
|
467 | } | |||
|
468 | ||||
|
469 | void QBoxPlotModelMapperPrivate::valuesRemoved(int index, int count) | |||
|
470 | { | |||
|
471 | if (m_seriesSignalsBlock) | |||
|
472 | return; | |||
|
473 | ||||
|
474 | if (m_count != -1) | |||
|
475 | m_count -= count; | |||
|
476 | ||||
|
477 | blockModelSignals(); | |||
|
478 | if (m_orientation == Qt::Vertical) | |||
|
479 | m_model->removeRows(index + m_first, count); | |||
|
480 | else | |||
|
481 | m_model->removeColumns(index + m_first, count); | |||
|
482 | ||||
|
483 | blockModelSignals(false); | |||
|
484 | initializeBoxFromModel(); | |||
|
485 | } | |||
|
486 | ||||
|
487 | void QBoxPlotModelMapperPrivate::boxValueChanged(int index) | |||
|
488 | { | |||
|
489 | if (m_seriesSignalsBlock) | |||
|
490 | return; | |||
|
491 | ||||
|
492 | int boxSetIndex = m_boxSets.indexOf(qobject_cast<QBoxSet *>(QObject::sender())); | |||
|
493 | ||||
|
494 | blockModelSignals(); | |||
|
495 | m_model->setData(boxModelIndex(boxSetIndex + m_firstBoxSetSection, index), m_boxSets.at(boxSetIndex)->at(index)); | |||
|
496 | blockModelSignals(false); | |||
|
497 | initializeBoxFromModel(); | |||
|
498 | } | |||
|
499 | ||||
|
500 | void QBoxPlotModelMapperPrivate::initializeBoxFromModel() | |||
|
501 | { | |||
|
502 | if (m_model == 0 || m_series == 0) | |||
|
503 | return; | |||
|
504 | ||||
|
505 | blockSeriesSignals(); | |||
|
506 | // clear current content | |||
|
507 | m_series->clear(); | |||
|
508 | m_boxSets.clear(); | |||
|
509 | ||||
|
510 | // create the initial bar sets | |||
|
511 | for (int i = m_firstBoxSetSection; i <= m_lastBoxSetSection; i++) { | |||
|
512 | int posInBar = 0; | |||
|
513 | QModelIndex boxIndex = boxModelIndex(i, posInBar); | |||
|
514 | // check if there is such model index | |||
|
515 | if (boxIndex.isValid()) { | |||
|
516 | QBoxSet *boxSet = new QBoxSet(); | |||
|
517 | while (boxIndex.isValid()) { | |||
|
518 | boxSet->append(m_model->data(boxIndex, Qt::DisplayRole).toDouble()); | |||
|
519 | posInBar++; | |||
|
520 | boxIndex = boxModelIndex(i, posInBar); | |||
|
521 | } | |||
|
522 | connect(boxSet, SIGNAL(valuesAdded(int,int)), this, SLOT(valuesAdded(int,int))); | |||
|
523 | connect(boxSet, SIGNAL(valuesRemoved(int,int)), this, SLOT(valuesRemoved(int,int))); | |||
|
524 | connect(boxSet, SIGNAL(valueChanged(int)), this, SLOT(boxValueChanged(int))); | |||
|
525 | m_series->append(boxSet); | |||
|
526 | m_boxSets.append(boxSet); | |||
|
527 | } else { | |||
|
528 | break; | |||
|
529 | } | |||
|
530 | } | |||
|
531 | blockSeriesSignals(false); | |||
|
532 | } | |||
|
533 | ||||
|
534 | #include "moc_qboxplotmodelmapper.cpp" | |||
|
535 | #include "moc_qboxplotmodelmapper_p.cpp" | |||
|
536 | ||||
|
537 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
538 |
@@ -0,0 +1,69 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #ifndef QBOXPLOTMODELMAPPER_H | |||
|
22 | #define QBOXPLOTMODELMAPPER_H | |||
|
23 | ||||
|
24 | #include "qchartglobal.h" | |||
|
25 | #include <QObject> | |||
|
26 | ||||
|
27 | class QAbstractItemModel; | |||
|
28 | ||||
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
30 | ||||
|
31 | class QBoxPlotModelMapperPrivate; | |||
|
32 | class QBoxPlotSeries; | |||
|
33 | ||||
|
34 | class QTCOMMERCIALCHART_EXPORT QBoxPlotModelMapper : public QObject | |||
|
35 | { | |||
|
36 | Q_OBJECT | |||
|
37 | ||||
|
38 | protected: | |||
|
39 | explicit QBoxPlotModelMapper(QObject *parent = 0); | |||
|
40 | ||||
|
41 | QAbstractItemModel *model() const; | |||
|
42 | void setModel(QAbstractItemModel *model); | |||
|
43 | ||||
|
44 | QBoxPlotSeries *series() const; | |||
|
45 | void setSeries(QBoxPlotSeries *series); | |||
|
46 | ||||
|
47 | int first() const; | |||
|
48 | void setFirst(int first); | |||
|
49 | ||||
|
50 | int count() const; | |||
|
51 | void setCount(int count); | |||
|
52 | ||||
|
53 | int firstBoxSetSection() const; | |||
|
54 | void setFirstBoxSetSection(int firstBoxSetSection); | |||
|
55 | ||||
|
56 | int lastBoxSetSection() const; | |||
|
57 | void setLastBoxSetSection(int lastBoxSetSection); | |||
|
58 | ||||
|
59 | Qt::Orientation orientation() const; | |||
|
60 | void setOrientation(Qt::Orientation orientation); | |||
|
61 | ||||
|
62 | protected: | |||
|
63 | QBoxPlotModelMapperPrivate * const d_ptr; | |||
|
64 | Q_DECLARE_PRIVATE(QBoxPlotModelMapper) | |||
|
65 | }; | |||
|
66 | ||||
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
68 | ||||
|
69 | #endif // QBOXPLOTMODELMAPPER_H |
@@ -0,0 +1,95 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | #ifndef QBOXPLOTMODELMAPPER_P_H | |||
|
31 | #define QBOXPLOTMODELMAPPER_P_H | |||
|
32 | ||||
|
33 | #include <QObject> | |||
|
34 | #include "qboxplotmodelmapper.h" | |||
|
35 | ||||
|
36 | class QModelIndex; | |||
|
37 | ||||
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
39 | ||||
|
40 | class QBoxSet; | |||
|
41 | ||||
|
42 | class QBoxPlotModelMapperPrivate : public QObject | |||
|
43 | { | |||
|
44 | Q_OBJECT | |||
|
45 | public: | |||
|
46 | explicit QBoxPlotModelMapperPrivate(QBoxPlotModelMapper *q); | |||
|
47 | ||||
|
48 | public Q_SLOTS: | |||
|
49 | // for the model | |||
|
50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |||
|
51 | void modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last); | |||
|
52 | void modelRowsAdded(QModelIndex parent, int start, int end); | |||
|
53 | void modelRowsRemoved(QModelIndex parent, int start, int end); | |||
|
54 | void modelColumnsAdded(QModelIndex parent, int start, int end); | |||
|
55 | void modelColumnsRemoved(QModelIndex parent, int start, int end); | |||
|
56 | void handleModelDestroyed(); | |||
|
57 | ||||
|
58 | // for the series | |||
|
59 | void boxSetsAdded(QList<QBoxSet *> sets); | |||
|
60 | void boxSetsRemoved(QList<QBoxSet *> sets); | |||
|
61 | void valuesAdded(int index, int count); | |||
|
62 | void valuesRemoved(int index, int count); | |||
|
63 | void boxValueChanged(int index); | |||
|
64 | void handleSeriesDestroyed(); | |||
|
65 | ||||
|
66 | void initializeBoxFromModel(); | |||
|
67 | ||||
|
68 | private: | |||
|
69 | QBoxSet *boxSet(QModelIndex index); | |||
|
70 | QModelIndex boxModelIndex(int boxSection, int posInBox); | |||
|
71 | void insertData(int start, int end); | |||
|
72 | void removeData(int start, int end); | |||
|
73 | void blockModelSignals(bool block = true); | |||
|
74 | void blockSeriesSignals(bool block = true); | |||
|
75 | ||||
|
76 | private: | |||
|
77 | QBoxPlotSeries *m_series; | |||
|
78 | QList<QBoxSet *> m_boxSets; | |||
|
79 | QAbstractItemModel *m_model; | |||
|
80 | int m_first; | |||
|
81 | int m_count; | |||
|
82 | Qt::Orientation m_orientation; | |||
|
83 | int m_firstBoxSetSection; | |||
|
84 | int m_lastBoxSetSection; | |||
|
85 | bool m_seriesSignalsBlock; | |||
|
86 | bool m_modelSignalsBlock; | |||
|
87 | ||||
|
88 | private: | |||
|
89 | QBoxPlotModelMapper *q_ptr; | |||
|
90 | Q_DECLARE_PUBLIC(QBoxPlotModelMapper) | |||
|
91 | }; | |||
|
92 | ||||
|
93 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
94 | ||||
|
95 | #endif // QBOXPLOTMODELMAPPER_P_H |
@@ -0,0 +1,249 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "qvboxplotmodelmapper.h" | |||
|
22 | ||||
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
24 | ||||
|
25 | /*! | |||
|
26 | \class QVBoxPlotModelMapper | |||
|
27 | \brief Vertical model mapper for bar series | |||
|
28 | \mainclass | |||
|
29 | ||||
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |||
|
31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. | |||
|
32 | Model mapper maintains equal size of all the BarSets. | |||
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |||
|
34 | Note: used model has to support adding/removing rows/columns and modifying the data of the cells. | |||
|
35 | */ | |||
|
36 | /*! | |||
|
37 | \qmlclass VBarModelMapper | |||
|
38 | \mainclass | |||
|
39 | ||||
|
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |||
|
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. | |||
|
42 | VBarModelMapper keeps the series and the model in sync. | |||
|
43 | ||||
|
44 | The following QML example would create a bar series with three bar sets (assuming the | |||
|
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be | |||
|
46 | defined by the horizontal header (of the column). | |||
|
47 | \code | |||
|
48 | BarSeries { | |||
|
49 | VBarModelMapper { | |||
|
50 | model: myCustomModel // QAbstractItemModel derived implementation | |||
|
51 | firstBarSetColumn: 1 | |||
|
52 | lastBarSetColumn: 3 | |||
|
53 | firstRow: 1 | |||
|
54 | } | |||
|
55 | } | |||
|
56 | \endcode | |||
|
57 | */ | |||
|
58 | ||||
|
59 | /*! | |||
|
60 | \property QVBoxPlotModelMapper::series | |||
|
61 | \brief Defines the QPieSeries object that is used by the mapper. | |||
|
62 | ||||
|
63 | All the data in the series is discarded when it is set to the mapper. | |||
|
64 | When new series is specified the old series is disconnected (it preserves its data) | |||
|
65 | */ | |||
|
66 | /*! | |||
|
67 | \qmlproperty AbstractBarSeries VBarModelMapper::series | |||
|
68 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |||
|
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |||
|
70 | */ | |||
|
71 | ||||
|
72 | /*! | |||
|
73 | \property QVBoxPlotModelMapper::model | |||
|
74 | \brief Defines the model that is used by the mapper. | |||
|
75 | */ | |||
|
76 | /*! | |||
|
77 | \qmlproperty SomeModel VBarModelMapper::model | |||
|
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |||
|
79 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns | |||
|
80 | and modifying the data of the cells. | |||
|
81 | */ | |||
|
82 | ||||
|
83 | /*! | |||
|
84 | \property QVBoxPlotModelMapper::firstBarSetColumn | |||
|
85 | \brief Defines which column of the model is used as the data source for the first bar set | |||
|
86 | Default value is: -1 (invalid mapping) | |||
|
87 | */ | |||
|
88 | /*! | |||
|
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn | |||
|
90 | Defines which column of the model is used as the data source for the first bar set. Default value | |||
|
91 | is: -1 (invalid mapping). | |||
|
92 | */ | |||
|
93 | ||||
|
94 | /*! | |||
|
95 | \property QVBoxPlotModelMapper::lastBarSetColumn | |||
|
96 | \brief Defines which column of the model is used as the data source for the last bar set | |||
|
97 | Default value is: -1 (invalid mapping) | |||
|
98 | */ | |||
|
99 | /*! | |||
|
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn | |||
|
101 | Defines which column of the model is used as the data source for the last bar set. Default | |||
|
102 | value is: -1 (invalid mapping). | |||
|
103 | */ | |||
|
104 | ||||
|
105 | /*! | |||
|
106 | \property QVBoxPlotModelMapper::firstRow | |||
|
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. | |||
|
108 | Minimal and default value is: 0 | |||
|
109 | */ | |||
|
110 | /*! | |||
|
111 | \qmlproperty int VBarModelMapper::firstRow | |||
|
112 | Defines which row of the model contains the first values of the QBarSets in the series. | |||
|
113 | The default value is 0. | |||
|
114 | */ | |||
|
115 | ||||
|
116 | /*! | |||
|
117 | \property QVBoxPlotModelMapper::rowCount | |||
|
118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries | |||
|
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |||
|
120 | */ | |||
|
121 | /*! | |||
|
122 | \qmlproperty int VBarModelMapper::rowCount | |||
|
123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is | |||
|
124 | -1 (count limited by the number of rows in the model) | |||
|
125 | */ | |||
|
126 | ||||
|
127 | /*! | |||
|
128 | \fn void QVBoxPlotModelMapper::seriesReplaced() | |||
|
129 | ||||
|
130 | Emitted when the series to which mapper is connected to has changed. | |||
|
131 | */ | |||
|
132 | ||||
|
133 | /*! | |||
|
134 | \fn void QVBoxPlotModelMapper::modelReplaced() | |||
|
135 | ||||
|
136 | Emitted when the model to which mapper is connected to has changed. | |||
|
137 | */ | |||
|
138 | ||||
|
139 | /*! | |||
|
140 | \fn void QVBoxPlotModelMapper::firstBarSetColumnChanged() | |||
|
141 | Emitted when the firstBarSetColumn has changed. | |||
|
142 | */ | |||
|
143 | ||||
|
144 | /*! | |||
|
145 | \fn void QVBoxPlotModelMapper::lastBarSetColumnChanged() | |||
|
146 | Emitted when the lastBarSetColumn has changed. | |||
|
147 | */ | |||
|
148 | ||||
|
149 | /*! | |||
|
150 | \fn void QVBoxPlotModelMapper::firstRowChanged() | |||
|
151 | Emitted when the firstRow has changed. | |||
|
152 | */ | |||
|
153 | ||||
|
154 | /*! | |||
|
155 | \fn void QVBoxPlotModelMapper::rowCountChanged() | |||
|
156 | Emitted when the rowCount has changed. | |||
|
157 | */ | |||
|
158 | ||||
|
159 | /*! | |||
|
160 | Constructs a mapper object which is a child of \a parent. | |||
|
161 | */ | |||
|
162 | QVBoxPlotModelMapper::QVBoxPlotModelMapper(QObject *parent) : | |||
|
163 | QBoxPlotModelMapper(parent) | |||
|
164 | { | |||
|
165 | QBoxPlotModelMapper::setOrientation(Qt::Vertical); | |||
|
166 | } | |||
|
167 | ||||
|
168 | QAbstractItemModel *QVBoxPlotModelMapper::model() const | |||
|
169 | { | |||
|
170 | return QBoxPlotModelMapper::model(); | |||
|
171 | } | |||
|
172 | ||||
|
173 | void QVBoxPlotModelMapper::setModel(QAbstractItemModel *model) | |||
|
174 | { | |||
|
175 | if (model != QBoxPlotModelMapper::model()) { | |||
|
176 | QBoxPlotModelMapper::setModel(model); | |||
|
177 | emit modelReplaced(); | |||
|
178 | } | |||
|
179 | } | |||
|
180 | ||||
|
181 | QBoxPlotSeries *QVBoxPlotModelMapper::series() const | |||
|
182 | { | |||
|
183 | return QBoxPlotModelMapper::series(); | |||
|
184 | } | |||
|
185 | ||||
|
186 | void QVBoxPlotModelMapper::setSeries(QBoxPlotSeries *series) | |||
|
187 | { | |||
|
188 | if (series != QBoxPlotModelMapper::series()) { | |||
|
189 | QBoxPlotModelMapper::setSeries(series); | |||
|
190 | emit seriesReplaced(); | |||
|
191 | } | |||
|
192 | } | |||
|
193 | ||||
|
194 | int QVBoxPlotModelMapper::firstBoxSetColumn() const | |||
|
195 | { | |||
|
196 | return QBoxPlotModelMapper::firstBoxSetSection(); | |||
|
197 | } | |||
|
198 | ||||
|
199 | void QVBoxPlotModelMapper::setFirstBoxSetColumn(int firstBoxSetColumn) | |||
|
200 | { | |||
|
201 | if (firstBoxSetColumn != firstBoxSetSection()) { | |||
|
202 | QBoxPlotModelMapper::setFirstBoxSetSection(firstBoxSetColumn); | |||
|
203 | emit firstBoxSetColumnChanged(); | |||
|
204 | } | |||
|
205 | } | |||
|
206 | ||||
|
207 | int QVBoxPlotModelMapper::lastBoxSetColumn() const | |||
|
208 | { | |||
|
209 | return QBoxPlotModelMapper::lastBoxSetSection(); | |||
|
210 | } | |||
|
211 | ||||
|
212 | void QVBoxPlotModelMapper::setLastBoxSetColumn(int lastBoxSetColumn) | |||
|
213 | { | |||
|
214 | if (lastBoxSetColumn != lastBoxSetSection()) { | |||
|
215 | QBoxPlotModelMapper::setLastBoxSetSection(lastBoxSetColumn); | |||
|
216 | emit lastBoxSetColumnChanged(); | |||
|
217 | } | |||
|
218 | } | |||
|
219 | ||||
|
220 | int QVBoxPlotModelMapper::firstRow() const | |||
|
221 | { | |||
|
222 | return QBoxPlotModelMapper::first(); | |||
|
223 | } | |||
|
224 | ||||
|
225 | void QVBoxPlotModelMapper::setFirstRow(int firstRow) | |||
|
226 | { | |||
|
227 | if (firstRow != first()) { | |||
|
228 | QBoxPlotModelMapper::setFirst(firstRow); | |||
|
229 | emit firstRowChanged(); | |||
|
230 | } | |||
|
231 | } | |||
|
232 | ||||
|
233 | int QVBoxPlotModelMapper::rowCount() const | |||
|
234 | { | |||
|
235 | return QBoxPlotModelMapper::count(); | |||
|
236 | } | |||
|
237 | ||||
|
238 | void QVBoxPlotModelMapper::setRowCount(int rowCount) | |||
|
239 | { | |||
|
240 | if (rowCount != count()) { | |||
|
241 | QBoxPlotModelMapper::setCount(rowCount); | |||
|
242 | emit rowCountChanged(); | |||
|
243 | } | |||
|
244 | } | |||
|
245 | ||||
|
246 | #include "moc_qvboxplotmodelmapper.cpp" | |||
|
247 | ||||
|
248 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
249 |
@@ -0,0 +1,70 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2013 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #ifndef QVBOXPLOTMODELMAPPER_H | |||
|
22 | #define QVBOXPLOTMODELMAPPER_H | |||
|
23 | ||||
|
24 | #include <QBoxPlotModelMapper> | |||
|
25 | ||||
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
27 | ||||
|
28 | class QTCOMMERCIALCHART_EXPORT QVBoxPlotModelMapper : public QBoxPlotModelMapper | |||
|
29 | { | |||
|
30 | Q_OBJECT | |||
|
31 | Q_PROPERTY(QBoxPlotSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |||
|
32 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) | |||
|
33 | Q_PROPERTY(int firstBoxSetColumn READ firstBoxSetColumn WRITE setFirstBoxSetColumn NOTIFY firstBoxSetColumnChanged) | |||
|
34 | Q_PROPERTY(int lastBoxSetColumn READ lastBoxSetColumn WRITE setLastBoxSetColumn NOTIFY lastBoxSetColumnChanged) | |||
|
35 | Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged) | |||
|
36 | Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged) | |||
|
37 | ||||
|
38 | public: | |||
|
39 | explicit QVBoxPlotModelMapper(QObject *parent = 0); | |||
|
40 | ||||
|
41 | QAbstractItemModel *model() const; | |||
|
42 | void setModel(QAbstractItemModel *model); | |||
|
43 | ||||
|
44 | QBoxPlotSeries *series() const; | |||
|
45 | void setSeries(QBoxPlotSeries *series); | |||
|
46 | ||||
|
47 | int firstBoxSetColumn() const; | |||
|
48 | void setFirstBoxSetColumn(int firstBoxSetColumn); | |||
|
49 | ||||
|
50 | int lastBoxSetColumn() const; | |||
|
51 | void setLastBoxSetColumn(int lastBoxSetColumn); | |||
|
52 | ||||
|
53 | int firstRow() const; | |||
|
54 | void setFirstRow(int firstRow); | |||
|
55 | ||||
|
56 | int rowCount() const; | |||
|
57 | void setRowCount(int rowCount); | |||
|
58 | ||||
|
59 | Q_SIGNALS: | |||
|
60 | void seriesReplaced(); | |||
|
61 | void modelReplaced(); | |||
|
62 | void firstBoxSetColumnChanged(); | |||
|
63 | void lastBoxSetColumnChanged(); | |||
|
64 | void firstRowChanged(); | |||
|
65 | void rowCountChanged(); | |||
|
66 | }; | |||
|
67 | ||||
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
69 | ||||
|
70 | #endif // QVBOXPLOTMODELMAPPER_H |
@@ -5,15 +5,21 SOURCES += \ | |||||
5 | $$PWD/boxplotchartitem.cpp \ |
|
5 | $$PWD/boxplotchartitem.cpp \ | |
6 | $$PWD/qboxplotseries.cpp \ |
|
6 | $$PWD/qboxplotseries.cpp \ | |
7 | $$PWD/boxwhiskers.cpp \ |
|
7 | $$PWD/boxwhiskers.cpp \ | |
8 | $$PWD/qboxset.cpp |
|
8 | $$PWD/qboxset.cpp \ | |
|
9 | $$PWD/qboxplotmodelmapper.cpp \ | |||
|
10 | $$PWD/qvboxplotmodelmapper.cpp | |||
9 |
|
11 | |||
10 | PRIVATE_HEADERS += \ |
|
12 | PRIVATE_HEADERS += \ | |
11 | $$PWD/boxplotchartitem_p.h \ |
|
13 | $$PWD/boxplotchartitem_p.h \ | |
12 | $$PWD/qboxplotseries_p.h \ |
|
14 | $$PWD/qboxplotseries_p.h \ | |
13 | $$PWD/boxwhiskers_p.h \ |
|
15 | $$PWD/boxwhiskers_p.h \ | |
14 | $$PWD/boxwhiskersdata_p.h \ |
|
16 | $$PWD/boxwhiskersdata_p.h \ | |
15 | $$PWD/qboxset_p.h |
|
17 | $$PWD/qboxset_p.h \ | |
|
18 | $$PWD/qboxplotmodelmapper_p.h | |||
16 |
|
19 | |||
17 | PUBLIC_HEADERS += \ |
|
20 | PUBLIC_HEADERS += \ | |
18 | $$PWD/qboxplotseries.h \ |
|
21 | $$PWD/qboxplotseries.h \ | |
19 | $$PWD/qboxset.h |
|
22 | $$PWD/qboxset.h \ | |
|
23 | $$PWD/qboxplotmodelmapper.h \ | |||
|
24 | $$PWD/qvboxplotmodelmapper.h | |||
|
25 |
@@ -20,7 +20,7 | |||||
20 |
|
20 | |||
21 | #include "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "customtablemodel.h" |
|
22 | #include "customtablemodel.h" | |
23 |
#include <QVB |
|
23 | #include <QVBoxPlotModelMapper> | |
24 | #include <QTableView> |
|
24 | #include <QTableView> | |
25 | #include <QHeaderView> |
|
25 | #include <QHeaderView> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
@@ -214,7 +214,7 void MainWidget::addSeries() | |||||
214 | m_axis = new QBarCategoryAxis(); |
|
214 | m_axis = new QBarCategoryAxis(); | |
215 | m_axis->append(categories); |
|
215 | m_axis->append(categories); | |
216 | m_chart->createDefaultAxes(); |
|
216 | m_chart->createDefaultAxes(); | |
217 |
|
|
217 | m_chart->setAxisX(m_axis, m_series[nSeries]); | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | nSeries++; |
|
220 | nSeries++; | |
@@ -333,12 +333,12 void MainWidget::modelMapperToggled(bool enabled) | |||||
333 |
|
333 | |||
334 | int first = 0; |
|
334 | int first = 0; | |
335 | int count = 5; |
|
335 | int count = 5; | |
336 |
QVB |
|
336 | QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this); | |
337 |
mapper->setFirstB |
|
337 | mapper->setFirstBoxSetColumn(0); | |
338 |
mapper->setLastB |
|
338 | mapper->setLastBoxSetColumn(5); | |
339 | mapper->setFirstRow(first); |
|
339 | mapper->setFirstRow(first); | |
340 | mapper->setRowCount(count); |
|
340 | mapper->setRowCount(count); | |
341 |
|
|
341 | mapper->setSeries(m_series[nSeries]); | |
342 | mapper->setModel(m_model); |
|
342 | mapper->setModel(m_model); | |
343 | m_chart->addSeries(m_series[nSeries]); |
|
343 | m_chart->addSeries(m_series[nSeries]); | |
344 |
|
344 |
General Comments 0
You need to be logged in to leave comments.
Login now