##// END OF EJS Templates
Fixes legend markers updates
Michal Klocek -
r2085:224fca6f4967
parent child
Show More
@@ -198,9 +198,11 QAbstractBarSeries::~QAbstractBarSeries()
198 198 /*!
199 199 \internal
200 200 */
201 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
202 QAbstractSeries(d,parent)
201 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) :
202 QAbstractSeries(o,parent)
203 203 {
204 Q_D(QAbstractSeries);
205 QObject::connect(this,SIGNAL(countChanged()),d,SIGNAL(countChanged()));
204 206 }
205 207
206 208 /*!
@@ -672,7 +674,6 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* lege
672 674
673 675 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
674 676 {
675 Q_Q(QAbstractBarSeries);
676 677 if ((m_barSets.contains(set)) || (set == 0)) {
677 678 // Fail if set is already in list or set is null.
678 679 return false;
@@ -684,13 +685,11 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
684 685 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
685 686
686 687 emit restructuredBars(); // this notifies barchartitem
687 emit legendPropertiesUpdated(q); // this notifies legend
688 688 return true;
689 689 }
690 690
691 691 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
692 692 {
693 Q_Q(QAbstractBarSeries);
694 693 if (!m_barSets.contains(set)) {
695 694 // Fail if set is not in list
696 695 return false;
@@ -702,13 +701,11 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
702 701 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
703 702
704 703 emit restructuredBars(); // this notifies barchartitem
705 emit legendPropertiesUpdated(q);
706 704 return true;
707 705 }
708 706
709 707 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
710 708 {
711 Q_Q(QAbstractBarSeries);
712 709 foreach (QBarSet* set, sets) {
713 710 if ((set == 0) || (m_barSets.contains(set))) {
714 711 // Fail if any of the sets is null or is already appended.
@@ -728,13 +725,11 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
728 725 }
729 726
730 727 emit restructuredBars(); // this notifies barchartitem
731 emit legendPropertiesUpdated(q); // this notifies legend
732 728 return true;
733 729 }
734 730
735 731 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
736 732 {
737 Q_Q(QAbstractBarSeries);
738 733 if (sets.count() == 0) {
739 734 return false;
740 735 }
@@ -757,13 +752,11 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
757 752 }
758 753
759 754 emit restructuredBars(); // this notifies barchartitem
760 emit legendPropertiesUpdated(q);
761 755 return true;
762 756 }
763 757
764 758 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
765 759 {
766 Q_Q(QAbstractBarSeries);
767 760 if ((m_barSets.contains(set)) || (set == 0)) {
768 761 // Fail if set is already in list or set is null.
769 762 return false;
@@ -775,7 +768,6 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
775 768 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
776 769
777 770 emit restructuredBars(); // this notifies barchartitem
778 emit legendPropertiesUpdated(q);
779 771 return true;
780 772 }
781 773
@@ -62,6 +62,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
62 62 QBarSeries::QBarSeries(QObject *parent)
63 63 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
64 64 {
65
65 66 }
66 67
67 68 /*!
@@ -104,7 +104,6 void LegendLayout::setGeometry(const QRectF& rect)
104 104 void LegendLayout::setAttachedGeometry(const QRectF& rect)
105 105 {
106 106 if (!rect.isValid()) return;
107
108 107 m_offsetX=0;
109 108 m_offsetY=0;
110 109
@@ -32,7 +32,7
32 32 #include <QPainter>
33 33 #include <QGraphicsSceneEvent>
34 34 #include <QGraphicsSimpleTextItem>
35 #include <QDebug>
35 #include <QGraphicsLayout>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
@@ -88,6 +88,7 void LegendMarker::setLabel(const QString label)
88 88 {
89 89 m_text = label;
90 90 updateGeometry();
91 m_legend->layout()->invalidate();
91 92 }
92 93
93 94 QString LegendMarker::label() const
@@ -475,10 +475,11 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
475 475 }
476 476
477 477 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
478 QObject::connect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
478 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
479 479
480 m_items->setVisible(false);
480 481 q_ptr->layout()->invalidate();
481 q_ptr->layout()->activate();
482 m_presenter->layout()->invalidate();
482 483 }
483 484
484 485 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
@@ -491,7 +492,7 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
491 492 }
492 493
493 494 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
494 QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
495 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
495 496
496 497 q_ptr->layout()->invalidate();
497 498 }
@@ -499,6 +500,7 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
499 500 void QLegendPrivate::handleSeriesVisibleChanged()
500 501 {
501 502 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
503 Q_ASSERT(series);
502 504
503 505 foreach (LegendMarker* marker, m_markers) {
504 506 if (marker->series() == series) {
@@ -509,13 +511,12 void QLegendPrivate::handleSeriesVisibleChanged()
509 511 q_ptr->layout()->invalidate();
510 512 }
511 513
512 void QLegendPrivate::handleLegendPropertiesUpdated(QAbstractSeries *series)
514 void QLegendPrivate::handleCountChanged()
513 515 {
514 // Handle new or removed markers
515 // Handle changes of marker pen/brush/label. every property that legend is interested
516 handleSeriesRemoved(series);
517 Domain domain;
518 handleSeriesAdded(series, &domain);
516 QAbstractSeriesPrivate* series = qobject_cast<QAbstractSeriesPrivate *> (sender());
517 Q_ASSERT(series);
518 handleSeriesRemoved(series->q_ptr);
519 handleSeriesAdded(series->q_ptr, 0);
519 520 }
520 521
521 522 #include "moc_qlegend.cpp"
@@ -59,7 +59,7 public Q_SLOTS:
59 59 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
60 60 void handleSeriesRemoved(QAbstractSeries *series);
61 61 void handleSeriesVisibleChanged();
62 void handleLegendPropertiesUpdated(QAbstractSeries *series);
62 void handleCountChanged();
63 63
64 64 private:
65 65 QLegend *q_ptr;
@@ -350,7 +350,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
350 350 QPieSeries::QPieSeries(QObject *parent) :
351 351 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
352 352 {
353
353 Q_D(QPieSeries);
354 QObject::connect(this,SIGNAL(countChanged()),d,SIGNAL(countChanged()));
354 355 }
355 356
356 357 /*!
@@ -412,13 +413,6 bool QPieSeries::append(QList<QPieSlice*> slices)
412 413 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
413 414 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
414 415 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()));
422 416 }
423 417
424 418 emit added(slices);
@@ -478,12 +472,6 bool QPieSeries::insert(int index, QPieSlice* slice)
478 472 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
479 473 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
480 474
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 475
488 476 emit added(QList<QPieSlice*>() << slice);
489 477 emit countChanged();
@@ -846,13 +834,6 void QPieSeriesPrivate::sliceHovered(bool state)
846 834 emit q->hovered(slice, state);
847 835 }
848 836
849 void QPieSeriesPrivate::updateLegendProperties()
850 {
851 // This slot listens to all properties of slices, which may interest legend and signals it.
852 Q_Q(QPieSeries);
853 emit legendPropertiesUpdated(q);
854 }
855
856 837 void QPieSeriesPrivate::scaleDomain(Domain& domain)
857 838 {
858 839 Q_UNUSED(domain);
@@ -67,7 +67,6 public Q_SLOTS:
67 67 void sliceValueChanged();
68 68 void sliceClicked();
69 69 void sliceHovered(bool state);
70 void updateLegendProperties();
71 70
72 71 private:
73 72 QList<QPieSlice*> m_slices;
@@ -56,7 +56,7 public:
56 56 virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0;
57 57
58 58 Q_SIGNALS:
59 void legendPropertiesUpdated(QAbstractSeries* series);
59 void countChanged();
60 60
61 61 protected:
62 62 QAbstractSeries *q_ptr;
@@ -68,6 +68,7 protected:
68 68
69 69 friend class QAbstractSeries;
70 70 friend class ChartDataSet;
71 friend class QLegendPrivate;
71 72 };
72 73
73 74 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now