From 7402b18c3d5987647357ee31389ee3a28da02968 2012-06-26 12:56:46 From: Tero Ahola Date: 2012-06-26 12:56:46 Subject: [PATCH] Color and border color properties of XYSeries --- diff --git a/src/scatterchart/qscatterseries.cpp b/src/scatterchart/qscatterseries.cpp index 31c3071..e03776b 100644 --- a/src/scatterchart/qscatterseries.cpp +++ b/src/scatterchart/qscatterseries.cpp @@ -145,13 +145,36 @@ QAbstractSeries::SeriesType QScatterSeries::type() const return QAbstractSeries::SeriesTypeScatter; } +void QScatterSeries::setPen(const QPen &pen) +{ + Q_D(QXYSeries); + if (d->m_pen != pen) { + bool emitColorChanged = d->m_pen.color() != pen.color(); + d->m_pen = pen; + emit d->updated(); + if (emitColorChanged) + emit borderColorChanged(pen.color()); + } +} + +void QScatterSeries::setBrush(const QBrush &brush) +{ + Q_D(QScatterSeries); + if (d->m_brush != brush) { + bool emitColorChanged = d->m_brush.color() != brush.color(); + d->m_brush = brush; + emit d->updated(); + if (emitColorChanged) + emit colorChanged(brush.color()); + } +} + void QScatterSeries::setColor(const QColor &color) { QBrush b = brush(); if (b.color() != color) { b.setColor(color); setBrush(b); - emit colorChanged(color); } } @@ -166,7 +189,6 @@ void QScatterSeries::setBorderColor(const QColor &color) if (p.color() != color) { p.setColor(color); setPen(p); - emit borderColorChanged(color); } } @@ -208,12 +230,12 @@ void QScatterSeries::setMarkerSize(qreal size) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q), - m_shape(QScatterSeries::MarkerShapeCircle), - m_size(15.0) +QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) : + QXYSeriesPrivate(q), + m_shape(QScatterSeries::MarkerShapeCircle), + m_size(15.0) { - -}; +} Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) { diff --git a/src/scatterchart/qscatterseries.h b/src/scatterchart/qscatterseries.h index 9780da9..ad6894d 100644 --- a/src/scatterchart/qscatterseries.h +++ b/src/scatterchart/qscatterseries.h @@ -47,6 +47,8 @@ public: explicit QScatterSeries(QObject *parent = 0); ~QScatterSeries(); QAbstractSeries::SeriesType type() const; + void setPen(const QPen &pen); + void setBrush(const QBrush &brush); void setColor(const QColor &color); QColor color() const; void setBorderColor(const QColor &color); diff --git a/src/scatterchart/qscatterseries_p.h b/src/scatterchart/qscatterseries_p.h index 3c79d44..6dba063 100644 --- a/src/scatterchart/qscatterseries_p.h +++ b/src/scatterchart/qscatterseries_p.h @@ -43,8 +43,7 @@ public: private: QScatterSeries::MarkerShape m_shape; qreal m_size; - Q_DECLARE_PUBLIC(QScatterSeries); - + Q_DECLARE_PUBLIC(QScatterSeries) }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index 1299776..a24f065 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -298,9 +298,12 @@ int QXYSeries::count() const void QXYSeries::setPen(const QPen &pen) { Q_D(QXYSeries); - if (d->m_pen!=pen) { + if (d->m_pen != pen) { + bool emitColorChanged = d->m_pen.color() != pen.color(); d->m_pen = pen; emit d->updated(); + if (emitColorChanged) + emit colorChanged(pen.color()); } } @@ -336,7 +339,6 @@ void QXYSeries::setColor(const QColor &color) if (p.color() != color) { p.setColor(color); setPen(p); - emit colorChanged(color); } } diff --git a/src/xychart/qxyseries.h b/src/xychart/qxyseries.h index e1dce66..1257240 100644 --- a/src/xychart/qxyseries.h +++ b/src/xychart/qxyseries.h @@ -60,10 +60,10 @@ public: QXYSeries& operator << (const QPointF &point); QXYSeries& operator << (const QList &points); - void setPen(const QPen &pen); + virtual void setPen(const QPen &pen); QPen pen() const; - void setBrush(const QBrush &brush); + virtual void setBrush(const QBrush &brush); QBrush brush() const; virtual void setColor(const QColor &color); diff --git a/src/xychart/qxyseries_p.h b/src/xychart/qxyseries_p.h index 54c63c0..245c2f6 100644 --- a/src/xychart/qxyseries_p.h +++ b/src/xychart/qxyseries_p.h @@ -59,9 +59,8 @@ protected: bool m_pointsVisible; private: - Q_DECLARE_PUBLIC(QXYSeries); + Q_DECLARE_PUBLIC(QXYSeries) friend class QScatterSeries; - }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/tests/auto/qscatterseries/tst_qscatterseries.cpp b/tests/auto/qscatterseries/tst_qscatterseries.cpp index dc7da6e..acdc9d5 100644 --- a/tests/auto/qscatterseries/tst_qscatterseries.cpp +++ b/tests/auto/qscatterseries/tst_qscatterseries.cpp @@ -35,6 +35,8 @@ public slots: private slots: void qscatterseries_data(); void qscatterseries(); + void scatterChangedSignals(); + protected: void pointsVisible_data(); }; @@ -94,6 +96,35 @@ void tst_QScatterSeries::qscatterseries() QTest::qWaitForWindowShown(m_view); } +void tst_QScatterSeries::scatterChangedSignals() +{ + QScatterSeries *series = qobject_cast(m_series); + QVERIFY(series); + + QSignalSpy colorSpy(series, SIGNAL(colorChanged(QColor))); + QSignalSpy borderColorSpy(series, SIGNAL(borderColorChanged(QColor))); + + // Color + series->setColor(QColor("blueviolet")); + TRY_COMPARE(colorSpy.count(), 1); + + // Border color + series->setBorderColor(QColor("burlywood")); + TRY_COMPARE(borderColorSpy.count(), 1); + + // Pen + QPen p = series->pen(); + p.setColor("lightpink"); + series->setPen(p); + TRY_COMPARE(borderColorSpy.count(), 2); + + // Brush + QBrush b = series->brush(); + b.setColor("lime"); + series->setBrush(b); + TRY_COMPARE(colorSpy.count(), 2); +} + QTEST_MAIN(tst_QScatterSeries) #include "tst_qscatterseries.moc" diff --git a/tests/auto/qxyseries/tst_qxyseries.cpp b/tests/auto/qxyseries/tst_qxyseries.cpp index 21d8264..63e5223 100644 --- a/tests/auto/qxyseries/tst_qxyseries.cpp +++ b/tests/auto/qxyseries/tst_qxyseries.cpp @@ -399,11 +399,31 @@ void tst_QXYSeries::pointsVisible_raw() void tst_QXYSeries::changedSignals() { QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged())); + QSignalSpy nameSpy(m_series, SIGNAL(nameChanged())); + QSignalSpy colorSpy(m_series, SIGNAL(colorChanged(QColor))); + // Visibility m_series->setVisible(false); m_series->setVisible(false); TRY_COMPARE(visibleSpy.count(), 1); m_series->setVisible(true); TRY_COMPARE(visibleSpy.count(), 2); -} + // Color + m_series->setColor(QColor("aliceblue")); + TRY_COMPARE(colorSpy.count(), 1); + + // Pen and Brush + QPen p = m_series->pen(); + p.setColor("aquamarine"); + m_series->setPen(p); + QBrush b = m_series->brush(); + b.setColor("beige"); + m_series->setBrush(b); + TRY_COMPARE(colorSpy.count(), 2); + + // Verify all the signals again, to make sure no extra signals were emitted + TRY_COMPARE(visibleSpy.count(), 2); + TRY_COMPARE(nameSpy.count(), 0); + TRY_COMPARE(colorSpy.count(), 2); +}