##// END OF EJS Templates
Color and border color properties of XYSeries
Tero Ahola -
r1537:7402b18c3d59
parent child
Show More
@@ -145,13 +145,36 QAbstractSeries::SeriesType QScatterSeries::type() const
145 return QAbstractSeries::SeriesTypeScatter;
145 return QAbstractSeries::SeriesTypeScatter;
146 }
146 }
147
147
148 void QScatterSeries::setPen(const QPen &pen)
149 {
150 Q_D(QXYSeries);
151 if (d->m_pen != pen) {
152 bool emitColorChanged = d->m_pen.color() != pen.color();
153 d->m_pen = pen;
154 emit d->updated();
155 if (emitColorChanged)
156 emit borderColorChanged(pen.color());
157 }
158 }
159
160 void QScatterSeries::setBrush(const QBrush &brush)
161 {
162 Q_D(QScatterSeries);
163 if (d->m_brush != brush) {
164 bool emitColorChanged = d->m_brush.color() != brush.color();
165 d->m_brush = brush;
166 emit d->updated();
167 if (emitColorChanged)
168 emit colorChanged(brush.color());
169 }
170 }
171
148 void QScatterSeries::setColor(const QColor &color)
172 void QScatterSeries::setColor(const QColor &color)
149 {
173 {
150 QBrush b = brush();
174 QBrush b = brush();
151 if (b.color() != color) {
175 if (b.color() != color) {
152 b.setColor(color);
176 b.setColor(color);
153 setBrush(b);
177 setBrush(b);
154 emit colorChanged(color);
155 }
178 }
156 }
179 }
157
180
@@ -166,7 +189,6 void QScatterSeries::setBorderColor(const QColor &color)
166 if (p.color() != color) {
189 if (p.color() != color) {
167 p.setColor(color);
190 p.setColor(color);
168 setPen(p);
191 setPen(p);
169 emit borderColorChanged(color);
170 }
192 }
171 }
193 }
172
194
@@ -208,12 +230,12 void QScatterSeries::setMarkerSize(qreal size)
208
230
209 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
210
232
211 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q),
233 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) :
234 QXYSeriesPrivate(q),
212 m_shape(QScatterSeries::MarkerShapeCircle),
235 m_shape(QScatterSeries::MarkerShapeCircle),
213 m_size(15.0)
236 m_size(15.0)
214 {
237 {
215
238 }
216 };
217
239
218 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
240 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
219 {
241 {
@@ -47,6 +47,8 public:
47 explicit QScatterSeries(QObject *parent = 0);
47 explicit QScatterSeries(QObject *parent = 0);
48 ~QScatterSeries();
48 ~QScatterSeries();
49 QAbstractSeries::SeriesType type() const;
49 QAbstractSeries::SeriesType type() const;
50 void setPen(const QPen &pen);
51 void setBrush(const QBrush &brush);
50 void setColor(const QColor &color);
52 void setColor(const QColor &color);
51 QColor color() const;
53 QColor color() const;
52 void setBorderColor(const QColor &color);
54 void setBorderColor(const QColor &color);
@@ -43,8 +43,7 public:
43 private:
43 private:
44 QScatterSeries::MarkerShape m_shape;
44 QScatterSeries::MarkerShape m_shape;
45 qreal m_size;
45 qreal m_size;
46 Q_DECLARE_PUBLIC(QScatterSeries);
46 Q_DECLARE_PUBLIC(QScatterSeries)
47
48 };
47 };
49
48
50 QTCOMMERCIALCHART_END_NAMESPACE
49 QTCOMMERCIALCHART_END_NAMESPACE
@@ -299,8 +299,11 void QXYSeries::setPen(const QPen &pen)
299 {
299 {
300 Q_D(QXYSeries);
300 Q_D(QXYSeries);
301 if (d->m_pen!=pen) {
301 if (d->m_pen != pen) {
302 bool emitColorChanged = d->m_pen.color() != pen.color();
302 d->m_pen = pen;
303 d->m_pen = pen;
303 emit d->updated();
304 emit d->updated();
305 if (emitColorChanged)
306 emit colorChanged(pen.color());
304 }
307 }
305 }
308 }
306
309
@@ -336,7 +339,6 void QXYSeries::setColor(const QColor &color)
336 if (p.color() != color) {
339 if (p.color() != color) {
337 p.setColor(color);
340 p.setColor(color);
338 setPen(p);
341 setPen(p);
339 emit colorChanged(color);
340 }
342 }
341 }
343 }
342
344
@@ -60,10 +60,10 public:
60 QXYSeries& operator << (const QPointF &point);
60 QXYSeries& operator << (const QPointF &point);
61 QXYSeries& operator << (const QList<QPointF> &points);
61 QXYSeries& operator << (const QList<QPointF> &points);
62
62
63 void setPen(const QPen &pen);
63 virtual void setPen(const QPen &pen);
64 QPen pen() const;
64 QPen pen() const;
65
65
66 void setBrush(const QBrush &brush);
66 virtual void setBrush(const QBrush &brush);
67 QBrush brush() const;
67 QBrush brush() const;
68
68
69 virtual void setColor(const QColor &color);
69 virtual void setColor(const QColor &color);
@@ -59,9 +59,8 protected:
59 bool m_pointsVisible;
59 bool m_pointsVisible;
60
60
61 private:
61 private:
62 Q_DECLARE_PUBLIC(QXYSeries);
62 Q_DECLARE_PUBLIC(QXYSeries)
63 friend class QScatterSeries;
63 friend class QScatterSeries;
64
65 };
64 };
66
65
67 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
@@ -35,6 +35,8 public slots:
35 private slots:
35 private slots:
36 void qscatterseries_data();
36 void qscatterseries_data();
37 void qscatterseries();
37 void qscatterseries();
38 void scatterChangedSignals();
39
38 protected:
40 protected:
39 void pointsVisible_data();
41 void pointsVisible_data();
40 };
42 };
@@ -94,6 +96,35 void tst_QScatterSeries::qscatterseries()
94 QTest::qWaitForWindowShown(m_view);
96 QTest::qWaitForWindowShown(m_view);
95 }
97 }
96
98
99 void tst_QScatterSeries::scatterChangedSignals()
100 {
101 QScatterSeries *series = qobject_cast<QScatterSeries *>(m_series);
102 QVERIFY(series);
103
104 QSignalSpy colorSpy(series, SIGNAL(colorChanged(QColor)));
105 QSignalSpy borderColorSpy(series, SIGNAL(borderColorChanged(QColor)));
106
107 // Color
108 series->setColor(QColor("blueviolet"));
109 TRY_COMPARE(colorSpy.count(), 1);
110
111 // Border color
112 series->setBorderColor(QColor("burlywood"));
113 TRY_COMPARE(borderColorSpy.count(), 1);
114
115 // Pen
116 QPen p = series->pen();
117 p.setColor("lightpink");
118 series->setPen(p);
119 TRY_COMPARE(borderColorSpy.count(), 2);
120
121 // Brush
122 QBrush b = series->brush();
123 b.setColor("lime");
124 series->setBrush(b);
125 TRY_COMPARE(colorSpy.count(), 2);
126 }
127
97 QTEST_MAIN(tst_QScatterSeries)
128 QTEST_MAIN(tst_QScatterSeries)
98
129
99 #include "tst_qscatterseries.moc"
130 #include "tst_qscatterseries.moc"
@@ -399,11 +399,31 void tst_QXYSeries::pointsVisible_raw()
399 void tst_QXYSeries::changedSignals()
399 void tst_QXYSeries::changedSignals()
400 {
400 {
401 QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged()));
401 QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged()));
402 QSignalSpy nameSpy(m_series, SIGNAL(nameChanged()));
403 QSignalSpy colorSpy(m_series, SIGNAL(colorChanged(QColor)));
402
404
405 // Visibility
403 m_series->setVisible(false);
406 m_series->setVisible(false);
404 m_series->setVisible(false);
407 m_series->setVisible(false);
405 TRY_COMPARE(visibleSpy.count(), 1);
408 TRY_COMPARE(visibleSpy.count(), 1);
406 m_series->setVisible(true);
409 m_series->setVisible(true);
407 TRY_COMPARE(visibleSpy.count(), 2);
410 TRY_COMPARE(visibleSpy.count(), 2);
408 }
409
411
412 // Color
413 m_series->setColor(QColor("aliceblue"));
414 TRY_COMPARE(colorSpy.count(), 1);
415
416 // Pen and Brush
417 QPen p = m_series->pen();
418 p.setColor("aquamarine");
419 m_series->setPen(p);
420 QBrush b = m_series->brush();
421 b.setColor("beige");
422 m_series->setBrush(b);
423 TRY_COMPARE(colorSpy.count(), 2);
424
425 // Verify all the signals again, to make sure no extra signals were emitted
426 TRY_COMPARE(visibleSpy.count(), 2);
427 TRY_COMPARE(nameSpy.count(), 0);
428 TRY_COMPARE(colorSpy.count(), 2);
429 }
General Comments 0
You need to be logged in to leave comments. Login now