From 224fca6f49675e04aa383543e21a235347aba3e2 2012-09-21 15:26:26 From: Michal Klocek Date: 2012-09-21 15:26:26 Subject: [PATCH] Fixes legend markers updates --- diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp index 1c4150a..346b149 100644 --- a/src/barchart/qabstractbarseries.cpp +++ b/src/barchart/qabstractbarseries.cpp @@ -198,9 +198,11 @@ QAbstractBarSeries::~QAbstractBarSeries() /*! \internal */ -QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : - QAbstractSeries(d,parent) +QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) : + QAbstractSeries(o,parent) { + Q_D(QAbstractSeries); + QObject::connect(this,SIGNAL(countChanged()),d,SIGNAL(countChanged())); } /*! @@ -672,7 +674,6 @@ QList QAbstractBarSeriesPrivate::createLegendMarker(QLegend* lege bool QAbstractBarSeriesPrivate::append(QBarSet *set) { - Q_Q(QAbstractBarSeries); if ((m_barSets.contains(set)) || (set == 0)) { // Fail if set is already in list or set is null. return false; @@ -684,13 +685,11 @@ bool QAbstractBarSeriesPrivate::append(QBarSet *set) QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); emit restructuredBars(); // this notifies barchartitem - emit legendPropertiesUpdated(q); // this notifies legend return true; } bool QAbstractBarSeriesPrivate::remove(QBarSet *set) { - Q_Q(QAbstractBarSeries); if (!m_barSets.contains(set)) { // Fail if set is not in list return false; @@ -702,13 +701,11 @@ bool QAbstractBarSeriesPrivate::remove(QBarSet *set) QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); emit restructuredBars(); // this notifies barchartitem - emit legendPropertiesUpdated(q); return true; } bool QAbstractBarSeriesPrivate::append(QList sets) { - Q_Q(QAbstractBarSeries); foreach (QBarSet* set, sets) { if ((set == 0) || (m_barSets.contains(set))) { // Fail if any of the sets is null or is already appended. @@ -728,13 +725,11 @@ bool QAbstractBarSeriesPrivate::append(QList sets) } emit restructuredBars(); // this notifies barchartitem - emit legendPropertiesUpdated(q); // this notifies legend return true; } bool QAbstractBarSeriesPrivate::remove(QList sets) { - Q_Q(QAbstractBarSeries); if (sets.count() == 0) { return false; } @@ -757,13 +752,11 @@ bool QAbstractBarSeriesPrivate::remove(QList sets) } emit restructuredBars(); // this notifies barchartitem - emit legendPropertiesUpdated(q); return true; } bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) { - Q_Q(QAbstractBarSeries); if ((m_barSets.contains(set)) || (set == 0)) { // Fail if set is already in list or set is null. return false; @@ -775,7 +768,6 @@ bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); emit restructuredBars(); // this notifies barchartitem - emit legendPropertiesUpdated(q); return true; } diff --git a/src/barchart/vertical/bar/qbarseries.cpp b/src/barchart/vertical/bar/qbarseries.cpp index 42685c6..41b2115 100644 --- a/src/barchart/vertical/bar/qbarseries.cpp +++ b/src/barchart/vertical/bar/qbarseries.cpp @@ -62,6 +62,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QBarSeries::QBarSeries(QObject *parent) : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) { + } /*! diff --git a/src/legend/legendlayout.cpp b/src/legend/legendlayout.cpp index db8c05f..921921a 100644 --- a/src/legend/legendlayout.cpp +++ b/src/legend/legendlayout.cpp @@ -104,7 +104,6 @@ void LegendLayout::setGeometry(const QRectF& rect) void LegendLayout::setAttachedGeometry(const QRectF& rect) { if (!rect.isValid()) return; - m_offsetX=0; m_offsetY=0; diff --git a/src/legend/legendmarker.cpp b/src/legend/legendmarker.cpp index 6857a20..3a8c5c3 100644 --- a/src/legend/legendmarker.cpp +++ b/src/legend/legendmarker.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -88,6 +88,7 @@ void LegendMarker::setLabel(const QString label) { m_text = label; updateGeometry(); + m_legend->layout()->invalidate(); } QString LegendMarker::label() const diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index 67c795d..d6bbb2b 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -475,10 +475,11 @@ void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) } QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); - QObject::connect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*))); + QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); + m_items->setVisible(false); q_ptr->layout()->invalidate(); - q_ptr->layout()->activate(); + m_presenter->layout()->invalidate(); } void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) @@ -491,7 +492,7 @@ void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) } QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); - QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*))); + QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); q_ptr->layout()->invalidate(); } @@ -499,6 +500,7 @@ void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) void QLegendPrivate::handleSeriesVisibleChanged() { QAbstractSeries* series = qobject_cast (sender()); + Q_ASSERT(series); foreach (LegendMarker* marker, m_markers) { if (marker->series() == series) { @@ -509,13 +511,12 @@ void QLegendPrivate::handleSeriesVisibleChanged() q_ptr->layout()->invalidate(); } -void QLegendPrivate::handleLegendPropertiesUpdated(QAbstractSeries *series) +void QLegendPrivate::handleCountChanged() { - // Handle new or removed markers - // Handle changes of marker pen/brush/label. every property that legend is interested - handleSeriesRemoved(series); - Domain domain; - handleSeriesAdded(series, &domain); + QAbstractSeriesPrivate* series = qobject_cast (sender()); + Q_ASSERT(series); + handleSeriesRemoved(series->q_ptr); + handleSeriesAdded(series->q_ptr, 0); } #include "moc_qlegend.cpp" diff --git a/src/legend/qlegend_p.h b/src/legend/qlegend_p.h index 667734a..41e58e0 100644 --- a/src/legend/qlegend_p.h +++ b/src/legend/qlegend_p.h @@ -59,7 +59,7 @@ public Q_SLOTS: void handleSeriesAdded(QAbstractSeries *series, Domain *domain); void handleSeriesRemoved(QAbstractSeries *series); void handleSeriesVisibleChanged(); - void handleLegendPropertiesUpdated(QAbstractSeries *series); + void handleCountChanged(); private: QLegend *q_ptr; diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index f25c77a..7ce5730 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -350,7 +350,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QPieSeries::QPieSeries(QObject *parent) : QAbstractSeries(*new QPieSeriesPrivate(this),parent) { - + Q_D(QPieSeries); + QObject::connect(this,SIGNAL(countChanged()),d,SIGNAL(countChanged())); } /*! @@ -412,13 +413,6 @@ bool QPieSeries::append(QList slices) connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); - - connect(s, SIGNAL(labelChanged()), d, SLOT(updateLegendProperties())); - connect(s, SIGNAL(penChanged()), d, SLOT(updateLegendProperties())); - connect(s, SIGNAL(brushChanged()), d, SLOT(updateLegendProperties())); - connect(s, SIGNAL(labelBrushChanged()), d, SLOT(updateLegendProperties())); - connect(s, SIGNAL(labelFontChanged()), d, SLOT(updateLegendProperties())); - connect(s, SIGNAL(labelFontChanged()), d, SLOT(updateLegendProperties())); } emit added(slices); @@ -478,12 +472,6 @@ bool QPieSeries::insert(int index, QPieSlice* slice) connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); - connect(slice, SIGNAL(labelChanged()), d, SLOT(updateLegendProperties())); - connect(slice, SIGNAL(penChanged()), d, SLOT(updateLegendProperties())); - connect(slice, SIGNAL(brushChanged()), d, SLOT(updateLegendProperties())); - connect(slice, SIGNAL(labelBrushChanged()), d, SLOT(updateLegendProperties())); - connect(slice, SIGNAL(labelFontChanged()), d, SLOT(updateLegendProperties())); - connect(slice, SIGNAL(labelFontChanged()), d, SLOT(updateLegendProperties())); emit added(QList() << slice); emit countChanged(); @@ -846,13 +834,6 @@ void QPieSeriesPrivate::sliceHovered(bool state) emit q->hovered(slice, state); } -void QPieSeriesPrivate::updateLegendProperties() -{ - // This slot listens to all properties of slices, which may interest legend and signals it. - Q_Q(QPieSeries); - emit legendPropertiesUpdated(q); -} - void QPieSeriesPrivate::scaleDomain(Domain& domain) { Q_UNUSED(domain); diff --git a/src/piechart/qpieseries_p.h b/src/piechart/qpieseries_p.h index 68fb5ce..163d335 100644 --- a/src/piechart/qpieseries_p.h +++ b/src/piechart/qpieseries_p.h @@ -67,7 +67,6 @@ public Q_SLOTS: void sliceValueChanged(); void sliceClicked(); void sliceHovered(bool state); - void updateLegendProperties(); private: QList m_slices; diff --git a/src/qabstractseries_p.h b/src/qabstractseries_p.h index ac7da48..5018aa0 100644 --- a/src/qabstractseries_p.h +++ b/src/qabstractseries_p.h @@ -56,7 +56,7 @@ public: virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; Q_SIGNALS: - void legendPropertiesUpdated(QAbstractSeries* series); + void countChanged(); protected: QAbstractSeries *q_ptr; @@ -68,6 +68,7 @@ protected: friend class QAbstractSeries; friend class ChartDataSet; + friend class QLegendPrivate; }; QTCOMMERCIALCHART_END_NAMESPACE