##// END OF EJS Templates
legend private implemantation modified.
sauimone -
r2081:b2efc1272dac
parent child
Show More
@@ -677,14 +677,14 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
677 677 // Fail if set is already in list or set is null.
678 678 return false;
679 679 }
680
680 681 m_barSets.append(set);
681 682 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
682 683 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
683 684 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
685
684 686 emit restructuredBars(); // this notifies barchartitem
685 if (m_dataset) {
686 m_dataset->updateSeries(q); // this notifies legend
687 }
687 emit legendPropertiesUpdated(q); // this notifies legend
688 688 return true;
689 689 }
690 690
@@ -695,14 +695,14 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
695 695 // Fail if set is not in list
696 696 return false;
697 697 }
698
698 699 m_barSets.removeOne(set);
699 700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
700 701 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
701 702 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
703
702 704 emit restructuredBars(); // this notifies barchartitem
703 if (m_dataset) {
704 m_dataset->updateSeries(q); // this notifies legend
705 }
705 emit legendPropertiesUpdated(q);
706 706 return true;
707 707 }
708 708
@@ -726,10 +726,9 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
726 726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 727 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 728 }
729
729 730 emit restructuredBars(); // this notifies barchartitem
730 if (m_dataset) {
731 m_dataset->updateSeries(q); // this notifies legend
732 }
731 emit legendPropertiesUpdated(q); // this notifies legend
733 732 return true;
734 733 }
735 734
@@ -758,9 +757,7 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
758 757 }
759 758
760 759 emit restructuredBars(); // this notifies barchartitem
761 if (m_dataset) {
762 m_dataset->updateSeries(q); // this notifies legend
763 }
760 emit legendPropertiesUpdated(q);
764 761 return true;
765 762 }
766 763
@@ -771,14 +768,14 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
771 768 // Fail if set is already in list or set is null.
772 769 return false;
773 770 }
771
774 772 m_barSets.insert(index, set);
775 773 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
776 774 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
777 775 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
776
778 777 emit restructuredBars(); // this notifies barchartitem
779 if (m_dataset) {
780 m_dataset->updateSeries(q); // this notifies legend
781 }
778 emit legendPropertiesUpdated(q);
782 779 return true;
783 780 }
784 781
@@ -485,12 +485,12 QList<QAbstractSeries*> ChartDataSet::series() const
485 485 {
486 486 return m_seriesDomainMap.keys();
487 487 }
488
488 /*
489 489 void ChartDataSet::updateSeries(QAbstractSeries *series)
490 490 {
491 491 emit seriesUpdated(series);
492 492 }
493
493 */
494 494 #include "moc_chartdataset_p.cpp"
495 495
496 496 QTCOMMERCIALCHART_END_NAMESPACE
@@ -49,7 +49,7 public:
49 49 void addSeries(QAbstractSeries* series);
50 50 void removeSeries(QAbstractSeries* series);
51 51 void removeAllSeries();
52 void updateSeries(QAbstractSeries* series);
52 // void updateSeries(QAbstractSeries* series);
53 53
54 54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
55 55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
@@ -72,7 +72,7 public:
72 72 Q_SIGNALS:
73 73 void seriesAdded(QAbstractSeries* series, Domain* domain);
74 74 void seriesRemoved(QAbstractSeries* series);
75 void seriesUpdated(QAbstractSeries* series);
75 // void seriesUpdated(QAbstractSeries* series);
76 76 void axisAdded(QAbstractAxis* axis,Domain* domain);
77 77 void axisRemoved(QAbstractAxis* axis);
78 78
@@ -174,7 +174,7 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
174 174 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
175 175 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
176 176 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
177 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
177 // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
178 178 setLayout(d_ptr->m_layout);
179 179 }
180 180
@@ -473,12 +473,7 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
473 473 }
474 474
475 475 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
476
477 if(series->type() == QAbstractSeries::SeriesTypePie) {
478 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
479 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
480 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
481 }
476 QObject::connect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
482 477
483 478 q_ptr->layout()->invalidate();
484 479 q_ptr->layout()->activate();
@@ -493,34 +488,12 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
493 488 }
494 489 }
495 490
496 if(series->type() == QAbstractSeries::SeriesTypePie)
497 {
498 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
499 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
500 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
501 }
491 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
492 QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
502 493
503 494 q_ptr->layout()->invalidate();
504 495 }
505 496
506 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
507 {
508 // TODO: find out which markers are are added or removed. Update them
509 // TODO: better implementation
510 handleSeriesRemoved(series);
511 Domain domain;
512 handleSeriesAdded(series, &domain);
513 }
514
515 void QLegendPrivate::handleUpdatePieSeries()
516 {
517 //TODO: reimplement to be optimal
518 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
519 Q_ASSERT(series);
520 handleSeriesRemoved(series);
521 handleSeriesAdded(series, 0);
522 }
523
524 497 void QLegendPrivate::handleSeriesVisibleChanged()
525 498 {
526 499 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
@@ -534,6 +507,15 void QLegendPrivate::handleSeriesVisibleChanged()
534 507 q_ptr->layout()->invalidate();
535 508 }
536 509
510 void QLegendPrivate::handleLegendPropertiesUpdated(QAbstractSeries *series)
511 {
512 // Handle new or removed markers
513 // Handle changes of marker pen/brush/label. every property that legend is interested
514 handleSeriesRemoved(series);
515 Domain domain;
516 handleSeriesAdded(series, &domain);
517 }
518
537 519 #include "moc_qlegend.cpp"
538 520 #include "moc_qlegend_p.cpp"
539 521
@@ -58,9 +58,8 public:
58 58 public Q_SLOTS:
59 59 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
60 60 void handleSeriesRemoved(QAbstractSeries *series);
61 void handleSeriesUpdated(QAbstractSeries *series);
62 void handleUpdatePieSeries(); //TODO remove this function
63 61 void handleSeriesVisibleChanged();
62 void handleLegendPropertiesUpdated(QAbstractSeries *series);
64 63
65 64 private:
66 65 QLegend *q_ptr;
@@ -412,6 +412,13 bool QPieSeries::append(QList<QPieSlice*> slices)
412 412 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
413 413 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
414 414 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
415
416 connect(s, SIGNAL(labelChanged()), d, SLOT(updateLegendProperties()));
417 connect(s, SIGNAL(penChanged()), d, SLOT(updateLegendProperties()));
418 connect(s, SIGNAL(brushChanged()), d, SLOT(updateLegendProperties()));
419 connect(s, SIGNAL(labelBrushChanged()), d, SLOT(updateLegendProperties()));
420 connect(s, SIGNAL(labelFontChanged()), d, SLOT(updateLegendProperties()));
421 connect(s, SIGNAL(labelFontChanged()), d, SLOT(updateLegendProperties()));
415 422 }
416 423
417 424 emit added(slices);
@@ -471,6 +478,13 bool QPieSeries::insert(int index, QPieSlice* slice)
471 478 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
472 479 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
473 480
481 connect(slice, SIGNAL(labelChanged()), d, SLOT(updateLegendProperties()));
482 connect(slice, SIGNAL(penChanged()), d, SLOT(updateLegendProperties()));
483 connect(slice, SIGNAL(brushChanged()), d, SLOT(updateLegendProperties()));
484 connect(slice, SIGNAL(labelBrushChanged()), d, SLOT(updateLegendProperties()));
485 connect(slice, SIGNAL(labelFontChanged()), d, SLOT(updateLegendProperties()));
486 connect(slice, SIGNAL(labelFontChanged()), d, SLOT(updateLegendProperties()));
487
474 488 emit added(QList<QPieSlice*>() << slice);
475 489 emit countChanged();
476 490
@@ -830,6 +844,13 void QPieSeriesPrivate::sliceHovered(bool state)
830 844 emit q->hovered(slice, state);
831 845 }
832 846
847 void QPieSeriesPrivate::updateLegendProperties()
848 {
849 // This slot listens to all properties of slices, which may interest legend and signals it.
850 Q_Q(QPieSeries);
851 emit legendPropertiesUpdated(q);
852 }
853
833 854 void QPieSeriesPrivate::scaleDomain(Domain& domain)
834 855 {
835 856 Q_UNUSED(domain);
@@ -67,6 +67,7 public Q_SLOTS:
67 67 void sliceValueChanged();
68 68 void sliceClicked();
69 69 void sliceHovered(bool state);
70 void updateLegendProperties();
70 71
71 72 private:
72 73 QList<QPieSlice*> m_slices;
@@ -55,6 +55,9 public:
55 55 virtual void initializeAxis(QAbstractAxis* axis) = 0;
56 56 virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0;
57 57
58 Q_SIGNALS:
59 void legendPropertiesUpdated(QAbstractSeries* series);
60
58 61 protected:
59 62 QAbstractSeries *q_ptr;
60 63 QChart *m_chart;
General Comments 0
You need to be logged in to leave comments. Login now