##// END OF EJS Templates
Removed unnecessary model related function from xyseries and pieseries
Marek Rosa -
r1166:740d4c3988ce
parent child
Show More
@@ -439,8 +439,15 void QPieSeries::setModel(QAbstractItemModel* model)
439 if(model)
439 if(model)
440 {
440 {
441 d->m_model = model;
441 d->m_model = model;
442 // connect signals from the model
443 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
444 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
445 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
446 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
447 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
448
442 if (d->m_mapper)
449 if (d->m_mapper)
443 d->setMapping();
450 d->initializePieFromModel();
444 }
451 }
445 else
452 else
446 {
453 {
@@ -458,8 +465,11 void QPieSeries::setModelMapper(QPieModelMapper *mapper)
458
465
459 if (mapper) {
466 if (mapper) {
460 d->m_mapper = mapper;
467 d->m_mapper = mapper;
468 // connect the signal from the mapper
469 connect(d->m_mapper, SIGNAL(updated()), d, SLOT(initializePieFromModel()));
470
461 if (d->m_model)
471 if (d->m_model)
462 d->setMapping();
472 d->initializePieFromModel();
463 } else {
473 } else {
464 d->m_mapper = 0;
474 d->m_mapper = 0;
465 }
475 }
@@ -560,6 +570,7 void QPieSeriesPrivate::sliceHovered(bool state)
560
570
561 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
571 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
562 {
572 {
573 if (m_mapper) {
563 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
574 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
564 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
575 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
565 if (m_mapper->orientation() == Qt::Vertical)
576 if (m_mapper->orientation() == Qt::Vertical)
@@ -583,47 +594,57 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRigh
583 }
594 }
584 }
595 }
585 }
596 }
597 }
586
598
587
599
588 void QPieSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
600 void QPieSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
589 {
601 {
590 Q_UNUSED(parent);
602 Q_UNUSED(parent);
603 if (m_mapper) {
591 if (m_mapper->orientation() == Qt::Vertical)
604 if (m_mapper->orientation() == Qt::Vertical)
592 insertData(start, end);
605 insertData(start, end);
593 else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
606 else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
594 initializePieFromModel();
607 initializePieFromModel();
595 }
608 }
609 }
596
610
597 void QPieSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
611 void QPieSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
598 {
612 {
599 Q_UNUSED(parent);
613 Q_UNUSED(parent);
614 if (m_mapper) {
600 if (m_mapper->orientation() == Qt::Vertical)
615 if (m_mapper->orientation() == Qt::Vertical)
601 removeData(start, end);
616 removeData(start, end);
602 else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
617 else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
603 initializePieFromModel();
618 initializePieFromModel();
604 }
619 }
620 }
605
621
606 void QPieSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
622 void QPieSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
607 {
623 {
608 Q_UNUSED(parent);
624 Q_UNUSED(parent);
625 if (m_mapper) {
609 if (m_mapper->orientation() == Qt::Horizontal)
626 if (m_mapper->orientation() == Qt::Horizontal)
610 insertData(start, end);
627 insertData(start, end);
611 else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
628 else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
612 initializePieFromModel();
629 initializePieFromModel();
613 }
630 }
631 }
614
632
615 void QPieSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
633 void QPieSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
616 {
634 {
617 Q_UNUSED(parent);
635 Q_UNUSED(parent);
636 if (m_mapper) {
618 if (m_mapper->orientation() == Qt::Horizontal)
637 if (m_mapper->orientation() == Qt::Horizontal)
619 removeData(start, end);
638 removeData(start, end);
620 else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
639 else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
621 initializePieFromModel();
640 initializePieFromModel();
622 }
641 }
642 }
623
643
624 void QPieSeriesPrivate::insertData(int start, int end)
644 void QPieSeriesPrivate::insertData(int start, int end)
625 {
645 {
626 Q_Q(QPieSeries);
646 Q_Q(QPieSeries);
647 if (m_mapper) {
627 if (m_mapper->count() != -1 && start >= m_mapper->first() + m_mapper->count()) {
648 if (m_mapper->count() != -1 && start >= m_mapper->first() + m_mapper->count()) {
628 return;
649 return;
629 } else {
650 } else {
@@ -649,10 +670,12 void QPieSeriesPrivate::insertData(int start, int end)
649 q->remove(q->slices().at(i));
670 q->remove(q->slices().at(i));
650 }
671 }
651 }
672 }
673 }
652
674
653 void QPieSeriesPrivate::removeData(int start, int end)
675 void QPieSeriesPrivate::removeData(int start, int end)
654 {
676 {
655 Q_Q(QPieSeries);
677 Q_Q(QPieSeries);
678 if (m_mapper) {
656 int removedCount = end - start + 1;
679 int removedCount = end - start + 1;
657 if (m_mapper->count() != -1 && start >= m_mapper->first() + m_mapper->count()) {
680 if (m_mapper->count() != -1 && start >= m_mapper->first() + m_mapper->count()) {
658 return;
681 return;
@@ -687,20 +710,6 void QPieSeriesPrivate::removeData(int start, int end)
687 }
710 }
688 }
711 }
689 }
712 }
690
691 void QPieSeriesPrivate::setMapping()
692 {
693 initializePieFromModel();
694
695 // connect signals from the model
696 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
697 connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelRowsAdded(QModelIndex,int,int)));
698 connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelRowsRemoved(QModelIndex,int,int)));
699 connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelColumnsAdded(QModelIndex,int,int)));
700 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
701
702 // connect the signal from the mapper
703 connect(m_mapper, SIGNAL(updated()), this, SLOT(initializePieFromModel()));
704 }
713 }
705
714
706 void QPieSeriesPrivate::initializePieFromModel()
715 void QPieSeriesPrivate::initializePieFromModel()
@@ -65,7 +65,6 public Q_SLOTS:
65 bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0);
65 bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0);
66
66
67 private:
67 private:
68 void setMapping();
69 void insertData(int start, int end);
68 void insertData(int start, int end);
70 void removeData(int start, int end);
69 void removeData(int start, int end);
71
70
@@ -339,8 +339,14 void QXYSeries::setModel(QAbstractItemModel *model)
339 // set new model
339 // set new model
340 if (model) {
340 if (model) {
341 d->m_model = model;
341 d->m_model = model;
342 if (d->m_mapper)
342 emit d->reinitialized();
343 d->setMapping();
343
344 // connect signals from the model
345 connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
346 connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
347 connect(d->m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
348 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
349 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
344 } else {
350 } else {
345 d->m_model = 0;
351 d->m_model = 0;
346 }
352 }
@@ -356,8 +362,10 void QXYSeries::setModelMapper(QXYModelMapper *mapper)
356
362
357 if (mapper) {
363 if (mapper) {
358 d->m_mapper = mapper;
364 d->m_mapper = mapper;
359 if (d->m_model)
365 emit d->reinitialized();
360 d->setMapping();
366
367 // connect the signal from the mapper
368 connect(d->m_mapper, SIGNAL(updated()), d, SLOT(mappingUpdated()));
361 } else {
369 } else {
362 d->m_mapper = 0;
370 d->m_mapper = 0;
363 }
371 }
@@ -438,26 +446,15 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
438 return list << new XYLegendMarker(q,legend);
446 return list << new XYLegendMarker(q,legend);
439 }
447 }
440
448
441 void QXYSeriesPrivate::setMapping()
442 {
443 // connect signals from the model
444 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
445 connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelRowsAdded(QModelIndex,int,int)));
446 connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelRowsRemoved(QModelIndex,int,int)));
447 connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelColumnsAdded(QModelIndex,int,int)));
448 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
449
450 // connect the signal from the mapper
451 connect(m_mapper, SIGNAL(updated()), this, SLOT(mappingUpdated()));
452 }
453
454 void QXYSeriesPrivate::mappingUpdated()
449 void QXYSeriesPrivate::mappingUpdated()
455 {
450 {
451 if (m_model)
456 emit reinitialized();
452 emit reinitialized();
457 }
453 }
458
454
459 void QXYSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
455 void QXYSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
460 {
456 {
457 if (m_mapper) {
461 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
458 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
462 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
459 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
463 if (m_mapper->orientation() == Qt::Vertical) {
460 if (m_mapper->orientation() == Qt::Vertical) {
@@ -474,43 +471,52 void QXYSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight
474 }
471 }
475 }
472 }
476 }
473 }
474 }
477
475
478
476
479 void QXYSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
477 void QXYSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
480 {
478 {
481 Q_UNUSED(parent);
479 Q_UNUSED(parent);
480 if (m_mapper) {
482 if (m_mapper->orientation() == Qt::Vertical)
481 if (m_mapper->orientation() == Qt::Vertical)
483 emit pointsAdded(start, end);
482 emit pointsAdded(start, end);
484 else if (start <= m_mapper->mapX() || start <= m_mapper->mapY())
483 else if (start <= m_mapper->mapX() || start <= m_mapper->mapY())
485 emit reinitialized();
484 emit reinitialized();
486 }
485 }
486 }
487
487
488 void QXYSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
488 void QXYSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
489 {
489 {
490 Q_UNUSED(parent);
490 Q_UNUSED(parent);
491 if (m_mapper) {
491 if (m_mapper->orientation() == Qt::Vertical)
492 if (m_mapper->orientation() == Qt::Vertical)
492 emit pointsRemoved(start, end);
493 emit pointsRemoved(start, end);
493 else if (start <= m_mapper->mapX() || start <= m_mapper->mapY())
494 else if (start <= m_mapper->mapX() || start <= m_mapper->mapY())
494 emit reinitialized();
495 emit reinitialized();
495 }
496 }
497 }
496
498
497 void QXYSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
499 void QXYSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
498 {
500 {
499 Q_UNUSED(parent);
501 Q_UNUSED(parent);
502 if (m_mapper) {
500 if (m_mapper->orientation() == Qt::Horizontal)
503 if (m_mapper->orientation() == Qt::Horizontal)
501 emit pointsAdded(start, end);
504 emit pointsAdded(start, end);
502 else if (start <= m_mapper->mapX() || start <= m_mapper->mapY())
505 else if (start <= m_mapper->mapX() || start <= m_mapper->mapY())
503 emit reinitialized();
506 emit reinitialized();
504 }
507 }
508 }
505
509
506 void QXYSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
510 void QXYSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
507 {
511 {
508 Q_UNUSED(parent);
512 Q_UNUSED(parent);
513 if (m_mapper) {
509 if (m_mapper->orientation() == Qt::Horizontal)
514 if (m_mapper->orientation() == Qt::Horizontal)
510 emit pointsRemoved(start, end);
515 emit pointsRemoved(start, end);
511 else if (start <= m_mapper->mapX() || start <= m_mapper->mapY())
516 else if (start <= m_mapper->mapX() || start <= m_mapper->mapY())
512 emit reinitialized();
517 emit reinitialized();
513 }
518 }
519 }
514
520
515 #include "moc_qxyseries.cpp"
521 #include "moc_qxyseries.cpp"
516 #include "moc_qxyseries_p.cpp"
522 #include "moc_qxyseries_p.cpp"
@@ -56,7 +56,6 protected Q_SLOTS:
56 virtual void mappingUpdated();
56 virtual void mappingUpdated();
57
57
58 private:
58 private:
59 void setMapping();
60 void insertData(int start, int end);
59 void insertData(int start, int end);
61 void removeData(int start, int end);
60 void removeData(int start, int end);
62
61
General Comments 0
You need to be logged in to leave comments. Login now