##// 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 // Fail if set is already in list or set is null.
677 // Fail if set is already in list or set is null.
678 return false;
678 return false;
679 }
679 }
680
680 m_barSets.append(set);
681 m_barSets.append(set);
681 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
682 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
682 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
683 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
683 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
684 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
684 emit restructuredBars(); // this notifies barchartitem
685
685 if (m_dataset) {
686 emit restructuredBars(); // this notifies barchartitem
686 m_dataset->updateSeries(q); // this notifies legend
687 emit legendPropertiesUpdated(q); // this notifies legend
687 }
688 return true;
688 return true;
689 }
689 }
690
690
@@ -695,14 +695,14 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
695 // Fail if set is not in list
695 // Fail if set is not in list
696 return false;
696 return false;
697 }
697 }
698
698 m_barSets.removeOne(set);
699 m_barSets.removeOne(set);
699 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
702 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
703
702 emit restructuredBars(); // this notifies barchartitem
704 emit restructuredBars(); // this notifies barchartitem
703 if (m_dataset) {
705 emit legendPropertiesUpdated(q);
704 m_dataset->updateSeries(q); // this notifies legend
705 }
706 return true;
706 return true;
707 }
707 }
708
708
@@ -726,10 +726,9 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 }
728 }
729
729 emit restructuredBars(); // this notifies barchartitem
730 emit restructuredBars(); // this notifies barchartitem
730 if (m_dataset) {
731 emit legendPropertiesUpdated(q); // this notifies legend
731 m_dataset->updateSeries(q); // this notifies legend
732 }
733 return true;
732 return true;
734 }
733 }
735
734
@@ -758,9 +757,7 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
758 }
757 }
759
758
760 emit restructuredBars(); // this notifies barchartitem
759 emit restructuredBars(); // this notifies barchartitem
761 if (m_dataset) {
760 emit legendPropertiesUpdated(q);
762 m_dataset->updateSeries(q); // this notifies legend
763 }
764 return true;
761 return true;
765 }
762 }
766
763
@@ -771,14 +768,14 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
771 // Fail if set is already in list or set is null.
768 // Fail if set is already in list or set is null.
772 return false;
769 return false;
773 }
770 }
771
774 m_barSets.insert(index, set);
772 m_barSets.insert(index, set);
775 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
773 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
776 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
774 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
777 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
775 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
776
778 emit restructuredBars(); // this notifies barchartitem
777 emit restructuredBars(); // this notifies barchartitem
779 if (m_dataset) {
778 emit legendPropertiesUpdated(q);
780 m_dataset->updateSeries(q); // this notifies legend
781 }
782 return true;
779 return true;
783 }
780 }
784
781
@@ -485,12 +485,12 QList<QAbstractSeries*> ChartDataSet::series() const
485 {
485 {
486 return m_seriesDomainMap.keys();
486 return m_seriesDomainMap.keys();
487 }
487 }
488
488 /*
489 void ChartDataSet::updateSeries(QAbstractSeries *series)
489 void ChartDataSet::updateSeries(QAbstractSeries *series)
490 {
490 {
491 emit seriesUpdated(series);
491 emit seriesUpdated(series);
492 }
492 }
493
493 */
494 #include "moc_chartdataset_p.cpp"
494 #include "moc_chartdataset_p.cpp"
495
495
496 QTCOMMERCIALCHART_END_NAMESPACE
496 QTCOMMERCIALCHART_END_NAMESPACE
@@ -49,7 +49,7 public:
49 void addSeries(QAbstractSeries* series);
49 void addSeries(QAbstractSeries* series);
50 void removeSeries(QAbstractSeries* series);
50 void removeSeries(QAbstractSeries* series);
51 void removeAllSeries();
51 void removeAllSeries();
52 void updateSeries(QAbstractSeries* series);
52 // void updateSeries(QAbstractSeries* series);
53
53
54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
@@ -72,7 +72,7 public:
72 Q_SIGNALS:
72 Q_SIGNALS:
73 void seriesAdded(QAbstractSeries* series, Domain* domain);
73 void seriesAdded(QAbstractSeries* series, Domain* domain);
74 void seriesRemoved(QAbstractSeries* series);
74 void seriesRemoved(QAbstractSeries* series);
75 void seriesUpdated(QAbstractSeries* series);
75 // void seriesUpdated(QAbstractSeries* series);
76 void axisAdded(QAbstractAxis* axis,Domain* domain);
76 void axisAdded(QAbstractAxis* axis,Domain* domain);
77 void axisRemoved(QAbstractAxis* axis);
77 void axisRemoved(QAbstractAxis* axis);
78
78
@@ -174,7 +174,7 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
174 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
174 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
175 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
175 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
176 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
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 setLayout(d_ptr->m_layout);
178 setLayout(d_ptr->m_layout);
179 }
179 }
180
180
@@ -464,7 +464,7 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
464
464
465 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
465 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
466
466
467 foreach(LegendMarker* marker, markers) {
467 foreach (LegendMarker* marker, markers) {
468 marker->setFont(m_font);
468 marker->setFont(m_font);
469 marker->setLabelBrush(m_labelBrush);
469 marker->setLabelBrush(m_labelBrush);
470 marker->setVisible(series->isVisible());
470 marker->setVisible(series->isVisible());
@@ -473,12 +473,7 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
473 }
473 }
474
474
475 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
475 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
476
476 QObject::connect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
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 }
482
477
483 q_ptr->layout()->invalidate();
478 q_ptr->layout()->invalidate();
484 q_ptr->layout()->activate();
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)
491 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
497 {
492 QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
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 }
502
493
503 q_ptr->layout()->invalidate();
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 void QLegendPrivate::handleSeriesVisibleChanged()
497 void QLegendPrivate::handleSeriesVisibleChanged()
525 {
498 {
526 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
499 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
@@ -534,6 +507,15 void QLegendPrivate::handleSeriesVisibleChanged()
534 q_ptr->layout()->invalidate();
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 #include "moc_qlegend.cpp"
519 #include "moc_qlegend.cpp"
538 #include "moc_qlegend_p.cpp"
520 #include "moc_qlegend_p.cpp"
539
521
@@ -58,9 +58,8 public:
58 public Q_SLOTS:
58 public Q_SLOTS:
59 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
59 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
60 void handleSeriesRemoved(QAbstractSeries *series);
60 void handleSeriesRemoved(QAbstractSeries *series);
61 void handleSeriesUpdated(QAbstractSeries *series);
62 void handleUpdatePieSeries(); //TODO remove this function
63 void handleSeriesVisibleChanged();
61 void handleSeriesVisibleChanged();
62 void handleLegendPropertiesUpdated(QAbstractSeries *series);
64
63
65 private:
64 private:
66 QLegend *q_ptr;
65 QLegend *q_ptr;
@@ -412,6 +412,13 bool QPieSeries::append(QList<QPieSlice*> slices)
412 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
412 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
413 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
413 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
414 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
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 emit added(slices);
424 emit added(slices);
@@ -471,6 +478,13 bool QPieSeries::insert(int index, QPieSlice* slice)
471 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
478 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
472 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
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 emit added(QList<QPieSlice*>() << slice);
488 emit added(QList<QPieSlice*>() << slice);
475 emit countChanged();
489 emit countChanged();
476
490
@@ -830,6 +844,13 void QPieSeriesPrivate::sliceHovered(bool state)
830 emit q->hovered(slice, state);
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 void QPieSeriesPrivate::scaleDomain(Domain& domain)
854 void QPieSeriesPrivate::scaleDomain(Domain& domain)
834 {
855 {
835 Q_UNUSED(domain);
856 Q_UNUSED(domain);
@@ -67,6 +67,7 public Q_SLOTS:
67 void sliceValueChanged();
67 void sliceValueChanged();
68 void sliceClicked();
68 void sliceClicked();
69 void sliceHovered(bool state);
69 void sliceHovered(bool state);
70 void updateLegendProperties();
70
71
71 private:
72 private:
72 QList<QPieSlice*> m_slices;
73 QList<QPieSlice*> m_slices;
@@ -55,6 +55,9 public:
55 virtual void initializeAxis(QAbstractAxis* axis) = 0;
55 virtual void initializeAxis(QAbstractAxis* axis) = 0;
56 virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0;
56 virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0;
57
57
58 Q_SIGNALS:
59 void legendPropertiesUpdated(QAbstractSeries* series);
60
58 protected:
61 protected:
59 QAbstractSeries *q_ptr;
62 QAbstractSeries *q_ptr;
60 QChart *m_chart;
63 QChart *m_chart;
General Comments 0
You need to be logged in to leave comments. Login now