diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index a105cd4..ad5d86e 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -127,6 +127,7 @@ qreal QBarSet::total() void QBarSet::setPen(const QPen pen) { mPen = pen; + emit changed(); } /*! @@ -143,6 +144,7 @@ QPen QBarSet::pen() const void QBarSet::setBrush(const QBrush brush) { mBrush = brush; + emit changed(); } /*! diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index c4246e5..9ea805b 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -43,6 +43,7 @@ Q_SIGNALS: // TODO: Expose this to user or not? // TODO: TO PIMPL ---> + void changed(); void hoverEnter(QPoint pos); void hoverLeave(); void showToolTip(QPoint pos, QString tip); // Private signal diff --git a/src/legendmarker.cpp b/src/legendmarker.cpp index 786b38b..55cb977 100644 --- a/src/legendmarker.cpp +++ b/src/legendmarker.cpp @@ -1,5 +1,7 @@ #include "qchartglobal.h" #include "legendmarker_p.h" +#include +#include #include #include @@ -116,6 +118,27 @@ void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) } } +void LegendMarker::changed() +{ + switch (mType) + { + case LegendMarkerTypeSeries: { + // TODO: + break; + } + case LegendMarkerTypeBarset: { + setBrush(mBarset->brush()); + setName(mBarset->name()); + break; + } + case LegendMarkerTypePieslice: { + setBrush(mPieslice->sliceBrush()); + setName(mPieslice->label()); + break; + } + } +} + #include "moc_legendmarker_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/legendmarker_p.h b/src/legendmarker_p.h index b39dc5a..915f8ef 100644 --- a/src/legendmarker_p.h +++ b/src/legendmarker_p.h @@ -49,6 +49,9 @@ Q_SIGNALS: void clicked(QBarSet* barset, Qt::MouseButton button); void clicked(QPieSlice* pieslice, Qt::MouseButton button); +public Q_SLOTS: + void changed(); + private: QRectF mBoundingRect; QRectF mMarkerBoundingRect; diff --git a/src/qlegend.cpp b/src/qlegend.cpp index cec9892..fb2d0a6 100644 --- a/src/qlegend.cpp +++ b/src/qlegend.cpp @@ -88,16 +88,6 @@ void QLegend::handleGeometryChanged(const QRectF& size) layoutChanged(); } -void QLegend::handleThemeChanged() -{ - foreach(QSeries *s, mSeriesList) { - deleteMarkers(s); - } - foreach(QSeries *s, mSeriesList) { - createMarkers(s); - } -} - void QLegend::createMarkers(QSeries *series) { switch (series->type()) @@ -174,6 +164,7 @@ void QLegend::appendMarkers(QBarSeries *series) marker->setName(s->name()); marker->setBrush(s->brush()); connect(marker,SIGNAL(clicked(QBarSet*,Qt::MouseButton)),this,SIGNAL(clicked(QBarSet*,Qt::MouseButton))); + connect(s,SIGNAL(changed()),marker,SLOT(changed())); mMarkers.append(marker); childItems().append(marker); } @@ -186,6 +177,7 @@ void QLegend::appendMarkers(QPieSeries *series) marker->setName(s->label()); marker->setBrush(s->sliceBrush()); connect(marker,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)),this,SIGNAL(clicked(QPieSlice*,Qt::MouseButton))); + connect(s,SIGNAL(changed()),marker,SLOT(changed())); mMarkers.append(marker); childItems().append(marker); } diff --git a/src/qlegend.h b/src/qlegend.h index 7dfc9cd..ef54ef2 100644 --- a/src/qlegend.h +++ b/src/qlegend.h @@ -42,11 +42,6 @@ public slots: void handleSeriesRemoved(QSeries* series); void handleGeometryChanged(const QRectF& size); - // PIMPL ---> - // Internal slot. Legend needs to know when theme has changed (or color of some series, if user changes it) - void handleThemeChanged(); - // <--- PIMPL - private: // PIMPL ---> void createMarkers(QSeries* series);