@@ -145,13 +145,36 QAbstractSeries::SeriesType QScatterSeries::type() const | |||
|
145 | 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 | 172 | void QScatterSeries::setColor(const QColor &color) |
|
149 | 173 | { |
|
150 | 174 | QBrush b = brush(); |
|
151 | 175 | if (b.color() != color) { |
|
152 | 176 | b.setColor(color); |
|
153 | 177 | setBrush(b); |
|
154 | emit colorChanged(color); | |
|
155 | 178 | } |
|
156 | 179 | } |
|
157 | 180 | |
@@ -166,7 +189,6 void QScatterSeries::setBorderColor(const QColor &color) | |||
|
166 | 189 | if (p.color() != color) { |
|
167 | 190 | p.setColor(color); |
|
168 | 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): |
|
|
212 | m_shape(QScatterSeries::MarkerShapeCircle), | |
|
213 | m_size(15.0) | |
|
233 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) : | |
|
234 | QXYSeriesPrivate(q), | |
|
235 | m_shape(QScatterSeries::MarkerShapeCircle), | |
|
236 | m_size(15.0) | |
|
214 | 237 | { |
|
215 | ||
|
216 | }; | |
|
238 | } | |
|
217 | 239 | |
|
218 | 240 | Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
219 | 241 | { |
@@ -47,6 +47,8 public: | |||
|
47 | 47 | explicit QScatterSeries(QObject *parent = 0); |
|
48 | 48 | ~QScatterSeries(); |
|
49 | 49 | QAbstractSeries::SeriesType type() const; |
|
50 | void setPen(const QPen &pen); | |
|
51 | void setBrush(const QBrush &brush); | |
|
50 | 52 | void setColor(const QColor &color); |
|
51 | 53 | QColor color() const; |
|
52 | 54 | void setBorderColor(const QColor &color); |
@@ -43,8 +43,7 public: | |||
|
43 | 43 | private: |
|
44 | 44 | QScatterSeries::MarkerShape m_shape; |
|
45 | 45 | qreal m_size; |
|
46 |
Q_DECLARE_PUBLIC(QScatterSeries) |
|
|
47 | ||
|
46 | Q_DECLARE_PUBLIC(QScatterSeries) | |
|
48 | 47 | }; |
|
49 | 48 | |
|
50 | 49 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -298,9 +298,12 int QXYSeries::count() const | |||
|
298 | 298 | void QXYSeries::setPen(const QPen &pen) |
|
299 | 299 | { |
|
300 | 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 | 303 | d->m_pen = pen; |
|
303 | 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 | 339 | if (p.color() != color) { |
|
337 | 340 | p.setColor(color); |
|
338 | 341 | setPen(p); |
|
339 | emit colorChanged(color); | |
|
340 | 342 | } |
|
341 | 343 | } |
|
342 | 344 |
@@ -60,10 +60,10 public: | |||
|
60 | 60 | QXYSeries& operator << (const QPointF &point); |
|
61 | 61 | QXYSeries& operator << (const QList<QPointF> &points); |
|
62 | 62 | |
|
63 | void setPen(const QPen &pen); | |
|
63 | virtual void setPen(const QPen &pen); | |
|
64 | 64 | QPen pen() const; |
|
65 | 65 | |
|
66 | void setBrush(const QBrush &brush); | |
|
66 | virtual void setBrush(const QBrush &brush); | |
|
67 | 67 | QBrush brush() const; |
|
68 | 68 | |
|
69 | 69 | virtual void setColor(const QColor &color); |
@@ -59,9 +59,8 protected: | |||
|
59 | 59 | bool m_pointsVisible; |
|
60 | 60 | |
|
61 | 61 | private: |
|
62 |
Q_DECLARE_PUBLIC(QXYSeries) |
|
|
62 | Q_DECLARE_PUBLIC(QXYSeries) | |
|
63 | 63 | friend class QScatterSeries; |
|
64 | ||
|
65 | 64 | }; |
|
66 | 65 | |
|
67 | 66 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -35,6 +35,8 public slots: | |||
|
35 | 35 | private slots: |
|
36 | 36 | void qscatterseries_data(); |
|
37 | 37 | void qscatterseries(); |
|
38 | void scatterChangedSignals(); | |
|
39 | ||
|
38 | 40 | protected: |
|
39 | 41 | void pointsVisible_data(); |
|
40 | 42 | }; |
@@ -94,6 +96,35 void tst_QScatterSeries::qscatterseries() | |||
|
94 | 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 | 128 | QTEST_MAIN(tst_QScatterSeries) |
|
98 | 129 | |
|
99 | 130 | #include "tst_qscatterseries.moc" |
@@ -399,11 +399,31 void tst_QXYSeries::pointsVisible_raw() | |||
|
399 | 399 | void tst_QXYSeries::changedSignals() |
|
400 | 400 | { |
|
401 | 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 | 406 | m_series->setVisible(false); |
|
404 | 407 | m_series->setVisible(false); |
|
405 | 408 | TRY_COMPARE(visibleSpy.count(), 1); |
|
406 | 409 | m_series->setVisible(true); |
|
407 | 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