##// END OF EJS Templates
Fixed a bug with legend not updating series labels
Tero Ahola -
r1328:a05051bade54
parent child
Show More
@@ -36,13 +36,14
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : QGraphicsObject(legend),
39 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) :
40 m_series(series),
40 QGraphicsObject(legend),
41 m_markerRect(0,0,10.0,10.0),
41 m_series(series),
42 m_boundingRect(0,0,0,0),
42 m_markerRect(0,0,10.0,10.0),
43 m_legend(legend),
43 m_boundingRect(0,0,0,0),
44 m_textItem(new QGraphicsSimpleTextItem(this)),
44 m_legend(legend),
45 m_rectItem(new QGraphicsRectItem(this))
45 m_textItem(new QGraphicsSimpleTextItem(this)),
46 m_rectItem(new QGraphicsRectItem(this))
46 {
47 {
47 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
48 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
48 m_rectItem->setRect(m_markerRect);
49 m_rectItem->setRect(m_markerRect);
@@ -125,6 +126,7 m_series(series)
125 {
126 {
126 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
127 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
127 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
128 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
129 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
128 updated();
130 updated();
129 }
131 }
130
132
@@ -173,6 +175,7 m_series(series)
173 {
175 {
174 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
176 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
175 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
177 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
178 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
176 updated();
179 updated();
177 }
180 }
178
181
@@ -419,11 +419,10 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
419 Q_UNUSED(domain)
419 Q_UNUSED(domain)
420
420
421 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
421 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
422 foreach(LegendMarker* marker , markers)
422 foreach(LegendMarker* marker, markers)
423 m_markers->addToGroup(marker);
423 m_markers->addToGroup(marker);
424
424
425 if(series->type() == QAbstractSeries::SeriesTypePie)
425 if(series->type() == QAbstractSeries::SeriesTypePie) {
426 {
427 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
426 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
428 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
427 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
429 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
428 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
@@ -434,7 +433,6 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
434
433
435 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
434 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
436 {
435 {
437
438 QList<QGraphicsItem *> items = m_markers->childItems();
436 QList<QGraphicsItem *> items = m_markers->childItems();
439
437
440 foreach (QGraphicsItem *markers, items) {
438 foreach (QGraphicsItem *markers, items) {
@@ -90,7 +90,10 QAbstractSeries::~QAbstractSeries()
90
90
91 void QAbstractSeries::setName(const QString& name)
91 void QAbstractSeries::setName(const QString& name)
92 {
92 {
93 d_ptr->m_name = name;
93 if (name != d_ptr->m_name) {
94 d_ptr->m_name = name;
95 nameChanged();
96 }
94 }
97 }
95
98
96 /*!
99 /*!
@@ -33,7 +33,7 class QChart;
33 class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(QString name READ name WRITE setName)
36 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
37 Q_ENUMS(SeriesType)
37 Q_ENUMS(SeriesType)
38
38
39 public:
39 public:
@@ -59,6 +59,9 public:
59 QString name() const;
59 QString name() const;
60 QChart* chart() const;
60 QChart* chart() const;
61
61
62 Q_SIGNALS:
63 void nameChanged();
64
62 protected:
65 protected:
63 QScopedPointer<QAbstractSeriesPrivate> d_ptr;
66 QScopedPointer<QAbstractSeriesPrivate> d_ptr;
64 friend class ChartDataSet;
67 friend class ChartDataSet;
General Comments 0
You need to be logged in to leave comments. Login now