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