##// END OF EJS Templates
BarSeries API can now be used when the series is used with BarModelMapper
Marek Rosa -
r1435:5560f4cf8e35
parent child
Show More
@@ -122,7 +122,8 void QBarModelMapper::setSeries(QBarSeries *series)
122 d->m_series = series;
122 d->m_series = series;
123 d->initializeBarFromModel();
123 d->initializeBarFromModel();
124 // connect the signals from the series
124 // connect the signals from the series
125 // TODO: TO be implemented
125 connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>)));
126 connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>)));
126 }
127 }
127
128
128 int QBarModelMapper::first() const
129 int QBarModelMapper::first() const
@@ -416,6 +417,145 void QBarModelMapperPrivate::removeData(int start, int end)
416 // To be implemented
417 // To be implemented
417 }
418 }
418
419
420 void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets)
421 {
422 if (m_seriesSignalsBlock)
423 return;
424
425 if (sets.count() == 0)
426 return;
427
428 int firstIndex = m_series->barSets().indexOf(sets.at(0));
429 if (firstIndex == -1)
430 return;
431
432 int maxCount = 0;
433 for(int i = 0; i < sets.count(); i++)
434 if (sets.at(i)->count() > m_count)
435 maxCount = sets.at(i)->count();
436
437 if (m_count != -1 && m_count < maxCount)
438 m_count = maxCount;
439
440 m_lastBarSetSection += sets.count();
441
442 blockModelSignals();
443 int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
444 if (maxCount > modelCapacity) {
445 if (m_orientation == Qt::Vertical)
446 m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
447 else
448 m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
449 }
450
451 if (m_orientation == Qt::Vertical)
452 m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count());
453 else
454 m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count());
455
456
457 for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) {
458 m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label());
459 for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++)
460 m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j).y());
461 }
462 blockModelSignals(false);
463 initializeBarFromModel();
464 }
465
466 void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets)
467 {
468 if (m_seriesSignalsBlock)
469 return;
470
471 if (sets.count() == 0)
472 return;
473
474 int firstIndex = m_barSets.indexOf(sets.at(0));
475 if (firstIndex == -1)
476 return;
477
478 m_lastBarSetSection -= sets.count();
479
480 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
481 m_barSets.removeAt(i);
482
483 blockModelSignals();
484 if (m_orientation == Qt::Vertical)
485 m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count());
486 else
487 m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count());
488 blockModelSignals(false);
489 initializeBarFromModel();
490 }
491
492 void QBarModelMapperPrivate::valuesAdded(int index, int count)
493 {
494 if (m_seriesSignalsBlock)
495 return;
496
497 if (m_count != -1)
498 m_count += count;
499
500 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
501
502 blockModelSignals();
503 if (m_orientation == Qt::Vertical)
504 m_model->insertRows(index + m_first, count);
505 else
506 m_model->insertColumns(index + m_first, count);
507
508 for (int j = index; j < index + count; j++)
509 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j).y());
510
511 blockModelSignals(false);
512 initializeBarFromModel();
513 }
514
515 void QBarModelMapperPrivate::valuesRemoved(int index, int count)
516 {
517 if (m_seriesSignalsBlock)
518 return;
519
520 if (m_count != -1)
521 m_count -= count;
522
523 blockModelSignals();
524 if (m_orientation == Qt::Vertical)
525 m_model->removeRows(index + m_first, count);
526 else
527 m_model->removeColumns(index + m_first, count);
528
529 blockModelSignals(false);
530 initializeBarFromModel();
531 }
532
533 void QBarModelMapperPrivate::barLabelChanged()
534 {
535 if (m_seriesSignalsBlock)
536 return;
537
538 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
539
540 blockModelSignals();
541 m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label());
542 blockModelSignals(false);
543 initializeBarFromModel();
544 }
545
546 void QBarModelMapperPrivate::barValueChanged(int index)
547 {
548 if (m_seriesSignalsBlock)
549 return;
550
551 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
552
553 blockModelSignals();
554 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index).y());
555 blockModelSignals(false);
556 initializeBarFromModel();
557 }
558
419 void QBarModelMapperPrivate::initializeBarFromModel()
559 void QBarModelMapperPrivate::initializeBarFromModel()
420 {
560 {
421 if (m_model == 0 || m_series == 0)
561 if (m_model == 0 || m_series == 0)
@@ -424,6 +564,7 void QBarModelMapperPrivate::initializeBarFromModel()
424 blockSeriesSignals();
564 blockSeriesSignals();
425 // clear current content
565 // clear current content
426 m_series->clear();
566 m_series->clear();
567 m_barSets.clear();
427
568
428 // create the initial bar sets
569 // create the initial bar sets
429 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
570 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
@@ -437,7 +578,12 void QBarModelMapperPrivate::initializeBarFromModel()
437 posInBar++;
578 posInBar++;
438 barIndex = barModelIndex(i, posInBar);
579 barIndex = barModelIndex(i, posInBar);
439 }
580 }
581 connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int)));
582 connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int)));
583 connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int)));
584 connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged()));
440 m_series->append(barSet);
585 m_series->append(barSet);
586 m_barSets.append(barSet);
441 } else {
587 } else {
442 break;
588 break;
443 }
589 }
@@ -55,6 +55,14 public Q_SLOTS:
55 void modelColumnsAdded(QModelIndex parent, int start, int end);
55 void modelColumnsAdded(QModelIndex parent, int start, int end);
56 void modelColumnsRemoved(QModelIndex parent, int start, int end);
56 void modelColumnsRemoved(QModelIndex parent, int start, int end);
57
57
58 // for the series
59 void barSetsAdded(QList<QBarSet*> sets);
60 void barSetsRemoved(QList<QBarSet*> sets);
61 void valuesAdded(int index, int count);
62 void valuesRemoved(int index, int count);
63 void barLabelChanged();
64 void barValueChanged(int index);
65
58 void initializeBarFromModel();
66 void initializeBarFromModel();
59
67
60 private:
68 private:
@@ -66,7 +74,8 private:
66 void blockSeriesSignals(bool block = true);
74 void blockSeriesSignals(bool block = true);
67
75
68 private:
76 private:
69 QBarSeries *m_series;
77 QBarSeries *m_series;
78 QList<QBarSet*> m_barSets;
70 QAbstractItemModel *m_model;
79 QAbstractItemModel *m_model;
71 int m_first;
80 int m_first;
72 int m_count;
81 int m_count;
General Comments 0
You need to be logged in to leave comments. Login now