##// END OF EJS Templates
Add a method to remove more than one point to QXYSeries...
Miikka Heikkinen -
r2805:42870bd3de5c
parent child
Show More
@@ -0,0 +1,260
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
7 ** This file is part of the Qt Charts module.
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
13 **
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
16 **
17 ****************************************************************************/
18
19 import QtQuick 2.0
20 import QtTest 1.0
21 import QtCharts 2.0
22
23 Rectangle {
24 width: 400
25 height: 300
26
27 TestCase {
28 id: tc1
29 name: "tst_qml-qtquicktest XY Series"
30 when: windowShown
31
32 function test_properties() {
33 verify(lineSeries.color != undefined);
34 compare(lineSeries.pointsVisible, false);
35 compare(lineSeries.capStyle, Qt.SquareCap);
36 compare(lineSeries.style, Qt.SolidLine);
37 compare(lineSeries.width, 2.0);
38
39 verify(splineSeries.color != undefined);
40 compare(splineSeries.pointsVisible, false);
41 compare(splineSeries.capStyle, Qt.SquareCap);
42 compare(splineSeries.style, Qt.SolidLine);
43 compare(splineSeries.width, 2.0);
44
45 verify(scatterSeries.color != undefined);
46 verify(scatterSeries.borderColor != undefined);
47 compare(scatterSeries.borderWidth, 2.0);
48 compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle);
49 compare(scatterSeries.markerSize, 15.0);
50 compare(scatterSeries.brushFilename, "");
51
52 verify(areaSeries.color != undefined);
53 verify(areaSeries.borderColor != undefined);
54 compare(areaSeries.borderWidth, 2.0);
55 compare(areaSeries.brushFilename, "");
56 }
57
58 function test_axes() {
59 // Axis initialization
60 compare(chartView.axisX(), lineSeries.axisX);
61 compare(chartView.axisY(), lineSeries.axisY);
62 compare(lineSeries.axisX, splineSeries.axisX);
63 compare(lineSeries.axisY, splineSeries.axisY);
64 compare(lineSeries.axisX, areaSeries.axisX);
65 compare(lineSeries.axisY, areaSeries.axisY);
66 }
67
68 function test_append() {
69 lineSeriesPointAddedSpy.clear();
70 splineSeriesPointAddedSpy.clear();
71 scatterSeriesPointAddedSpy.clear();
72 var count = append();
73 compare(lineSeries.count, count);
74 compare(splineSeries.count, count);
75 compare(scatterSeries.count, count);
76 compare(lineSeriesPointAddedSpy.count, count);
77 compare(splineSeriesPointAddedSpy.count, count);
78 compare(scatterSeriesPointAddedSpy.count, count);
79 clear();
80 compare(lineSeries.count, 0);
81 compare(splineSeries.count, 0);
82 compare(scatterSeries.count, 0);
83 }
84
85 function test_replace() {
86 var count = append();
87 for (var i = 0; i < count; i++) {
88 lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random());
89 splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random());
90 scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random());
91 }
92 compare(lineSeries.count, count);
93 compare(splineSeries.count, count);
94 compare(scatterSeries.count, count);
95 compare(lineSeriesPointReplacedSpy.count, count);
96 compare(splineSeriesPointReplacedSpy.count, count);
97 compare(scatterSeriesPointReplacedSpy.count, count);
98 clear();
99 }
100
101 function test_insert() {
102 var count = append();
103 lineSeriesPointAddedSpy.clear();
104 splineSeriesPointAddedSpy.clear();
105 scatterSeriesPointAddedSpy.clear();
106 for (var i = 0; i < count; i++) {
107 lineSeries.insert(i * 2, i, Math.random());
108 splineSeries.insert(i * 2, i, Math.random());
109 scatterSeries.insert(i * 2, i, Math.random());
110 }
111 compare(lineSeries.count, count * 2);
112 compare(splineSeries.count, count * 2);
113 compare(scatterSeries.count, count * 2);
114 compare(lineSeriesPointAddedSpy.count, count);
115 compare(splineSeriesPointAddedSpy.count, count);
116 compare(scatterSeriesPointAddedSpy.count, count);
117 clear();
118 }
119
120 function test_remove() {
121 lineSeriesPointRemovedSpy.clear();
122 splineSeriesPointRemovedSpy.clear();
123 scatterSeriesPointRemovedSpy.clear();
124 var count = append();
125 for (var i = 0; i < count; i++) {
126 lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y);
127 splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y);
128 scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y);
129 }
130 compare(lineSeries.count, 0);
131 compare(splineSeries.count, 0);
132 compare(scatterSeries.count, 0);
133 compare(lineSeriesPointRemovedSpy.count, count);
134 compare(splineSeriesPointRemovedSpy.count, count);
135 compare(scatterSeriesPointRemovedSpy.count, count);
136 }
137
138 // Not a test function, called from test functions
139 function append() {
140 var count = 100;
141 chartView.axisX().min = 0;
142 chartView.axisX().max = 100;
143 chartView.axisY().min = 0;
144 chartView.axisY().max = 1;
145
146 for (var i = 0; i < count; i++) {
147 lineSeries.append(i, Math.random());
148 splineSeries.append(i, Math.random());
149 scatterSeries.append(i, Math.random());
150 }
151
152 return count;
153 }
154
155 // Not a test function, called from test functions
156 function clear() {
157 lineSeries.clear();
158 splineSeries.clear();
159 scatterSeries.clear();
160 }
161 }
162
163 ChartView {
164 id: chartView
165 anchors.fill: parent
166
167 LineSeries {
168 id: lineSeries
169 name: "line"
170
171 SignalSpy {
172 id: lineSeriesPointAddedSpy
173 target: lineSeries
174 signalName: "pointAdded"
175 }
176
177 SignalSpy {
178 id: lineSeriesPointReplacedSpy
179 target: lineSeries
180 signalName: "pointReplaced"
181 }
182
183 SignalSpy {
184 id: lineSeriesPointsReplacedSpy
185 target: lineSeries
186 signalName: "pointsReplaced"
187 }
188
189 SignalSpy {
190 id: lineSeriesPointRemovedSpy
191 target: lineSeries
192 signalName: "pointRemoved"
193 }
194 }
195
196 AreaSeries {
197 id: areaSeries
198 name: "area"
199 upperSeries: lineSeries
200 }
201
202 SplineSeries {
203 id: splineSeries
204 name: "spline"
205
206 SignalSpy {
207 id: splineSeriesPointAddedSpy
208 target: splineSeries
209 signalName: "pointAdded"
210 }
211
212 SignalSpy {
213 id: splineSeriesPointReplacedSpy
214 target: splineSeries
215 signalName: "pointReplaced"
216 }
217
218 SignalSpy {
219 id: splineSeriesPointsReplacedSpy
220 target: splineSeries
221 signalName: "pointsReplaced"
222 }
223
224 SignalSpy {
225 id: splineSeriesPointRemovedSpy
226 target: splineSeries
227 signalName: "pointRemoved"
228 }
229 }
230
231 ScatterSeries {
232 id: scatterSeries
233 name: "scatter"
234
235 SignalSpy {
236 id: scatterSeriesPointAddedSpy
237 target: scatterSeries
238 signalName: "pointAdded"
239 }
240
241 SignalSpy {
242 id: scatterSeriesPointReplacedSpy
243 target: scatterSeries
244 signalName: "pointReplaced"
245 }
246
247 SignalSpy {
248 id: scatterSeriesPointsReplacedSpy
249 target: scatterSeries
250 signalName: "pointsReplaced"
251 }
252
253 SignalSpy {
254 id: scatterSeriesPointRemovedSpy
255 target: scatterSeries
256 signalName: "pointRemoved"
257 }
258 }
259 }
260 }
@@ -94,6 +94,7 void QXYModelMapper::setSeries(QXYSeries *series)
94 94 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
95 95 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
96 96 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
97 connect(d->m_series, SIGNAL(pointsRemoved(int,int)), d, SLOT(handlePointsRemoved(int,int)));
97 98 }
98 99
99 100 /*!
@@ -309,6 +310,24 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
309 310 blockModelSignals(false);
310 311 }
311 312
313 void QXYModelMapperPrivate::handlePointsRemoved(int pointPos, int count)
314 {
315 if (m_seriesSignalsBlock)
316 return;
317
318 m_count -= count;
319
320 if (m_count < -1)
321 m_count = -1;
322
323 blockModelSignals();
324 if (m_orientation == Qt::Vertical)
325 m_model->removeRows(pointPos + m_first, count);
326 else
327 m_model->removeColumns(pointPos + m_first, count);
328 blockModelSignals(false);
329 }
330
312 331 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
313 332 {
314 333 if (m_seriesSignalsBlock)
@@ -61,6 +61,7 public Q_SLOTS:
61 61 // for the series
62 62 void handlePointAdded(int pointPos);
63 63 void handlePointRemoved(int pointPos);
64 void handlePointsRemoved(int pointPos, int count);
64 65 void handlePointReplaced(int pointPos);
65 66 void handleSeriesDestroyed();
66 67
@@ -111,7 +111,7 QT_CHARTS_BEGIN_NAMESPACE
111 111 \property QXYSeries::color
112 112 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
113 113 fill (brush) color in case of QScatterSeries or QAreaSeries.
114 \sa QXYSeries::pen(), QXYSeries::brush()
114 \sa pen(), brush()
115 115 */
116 116 /*!
117 117 \qmlproperty color XYSeries::color
@@ -141,13 +141,13 QT_CHARTS_BEGIN_NAMESPACE
141 141 area, labels on the edge of the plot area are cut. If the points are close to each other the
142 142 labels may overlap.
143 143
144 \sa QXYSeries::pointLabelsVisible, QXYSeries::pointLabelsFont, QXYSeries::pointLabelsColor
144 \sa pointLabelsVisible, pointLabelsFont, pointLabelsColor
145 145 */
146 146 /*!
147 147 \qmlproperty string XYSeries::pointLabelsFormat
148 148 The \a format used for showing labels with series points.
149 149
150 \sa QXYSeries::pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor
150 \sa pointLabelsFormat, pointLabelsVisible, pointLabelsFont, pointLabelsColor
151 151 */
152 152 /*!
153 153 \fn void QXYSeries::pointLabelsFormatChanged(const QString &format)
@@ -162,7 +162,7 QT_CHARTS_BEGIN_NAMESPACE
162 162 \property QXYSeries::pointLabelsVisible
163 163 Defines the visibility for data point labels. False by default.
164 164
165 \sa QXYSeries::pointLabelsFormat
165 \sa pointLabelsFormat
166 166 */
167 167 /*!
168 168 \qmlproperty bool XYSeries::pointLabelsVisible
@@ -183,7 +183,7 QT_CHARTS_BEGIN_NAMESPACE
183 183 \property QXYSeries::pointLabelsFont
184 184 Defines the font used for data point labels.
185 185
186 \sa QXYSeries::pointLabelsFormat
186 \sa pointLabelsFormat
187 187 */
188 188 /*!
189 189 \qmlproperty font XYSeries::pointLabelsFont
@@ -205,7 +205,7 QT_CHARTS_BEGIN_NAMESPACE
205 205 Defines the color used for data point labels. By default, the color is the color of the brush
206 206 defined in theme for labels.
207 207
208 \sa QXYSeries::pointLabelsFormat
208 \sa pointLabelsFormat
209 209 */
210 210 /*!
211 211 \qmlproperty font XYSeries::pointLabelsColor
@@ -355,6 +355,17 QT_CHARTS_BEGIN_NAMESPACE
355 355 */
356 356
357 357 /*!
358 \fn void QXYSeries::pointsRemoved(int index, int count)
359 Signal is emitted when a \a count of points has been removed starting at \a index.
360 \sa removePoints(), clear()
361 */
362
363 /*!
364 \qmlsignal XYSeries::onPointsRemoved(int index, int count)
365 Signal is emitted when a \a count of points has been removed starting at \a index.
366 */
367
368 /*!
358 369 \fn void QXYSeries::colorChanged(QColor color)
359 370 \brief Signal is emitted when the line (pen) color has changed to \a color.
360 371 */
@@ -385,6 +396,16 QT_CHARTS_BEGIN_NAMESPACE
385 396 */
386 397
387 398 /*!
399 \qmlmethod XYSeries::remove(int index)
400 Removes a point from the series at \a index.
401 */
402
403 /*!
404 \qmlmethod XYSeries::removePoints(int index, int count)
405 Removes \a count points from the series starting at \a index.
406 */
407
408 /*!
388 409 \qmlmethod XYSeries::insert(int index, real x, real y)
389 410 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
390 411 points. If index is the same as or bigger than count, the point is appended to the list of points.
@@ -448,7 +469,7 void QXYSeries::append(const QList<QPointF> &points)
448 469
449 470 /*!
450 471 Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY).
451 \sa QXYSeries::pointReplaced()
472 \sa pointReplaced()
452 473 */
453 474 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
454 475 {
@@ -457,7 +478,7 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
457 478
458 479 /*!
459 480 Replaces \a oldPoint with \a newPoint.
460 \sa QXYSeries::pointReplaced()
481 \sa pointReplaced()
461 482 */
462 483 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
463 484 {
@@ -470,7 +491,7 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
470 491
471 492 /*!
472 493 Replaces the point at \a index with data point (\a newX, \a newY).
473 \sa QXYSeries::pointReplaced()
494 \sa pointReplaced()
474 495 */
475 496 void QXYSeries::replace(int index, qreal newX, qreal newY)
476 497 {
@@ -479,7 +500,7 void QXYSeries::replace(int index, qreal newX, qreal newY)
479 500
480 501 /*!
481 502 Replaces the point at \a index with \a newPoint.
482 \sa QXYSeries::pointReplaced()
503 \sa pointReplaced()
483 504 */
484 505 void QXYSeries::replace(int index, const QPointF &newPoint)
485 506 {
@@ -496,7 +517,7 void QXYSeries::replace(int index, const QPointF &newPoint)
496 517 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
497 518 when the points have been replaced. However, note that using the overload that takes
498 519 \c{QVector<QPointF>} as parameter is slightly faster than using this overload.
499 \sa QXYSeries::pointsReplaced()
520 \sa pointsReplaced()
500 521 */
501 522 void QXYSeries::replace(QList<QPointF> points)
502 523 {
@@ -508,7 +529,7 void QXYSeries::replace(QList<QPointF> points)
508 529 \note This is much faster than replacing data points one by one,
509 530 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
510 531 when the points have been replaced.
511 \sa QXYSeries::pointsReplaced()
532 \sa pointsReplaced()
512 533 */
513 534 void QXYSeries::replace(QVector<QPointF> points)
514 535 {
@@ -519,6 +540,7 void QXYSeries::replace(QVector<QPointF> points)
519 540
520 541 /*!
521 542 Removes the point (\a x, \a y) from the series.
543 \sa pointRemoved()
522 544 */
523 545 void QXYSeries::remove(qreal x, qreal y)
524 546 {
@@ -527,6 +549,7 void QXYSeries::remove(qreal x, qreal y)
527 549
528 550 /*!
529 551 Removes the \a point from the series.
552 \sa pointRemoved()
530 553 */
531 554 void QXYSeries::remove(const QPointF &point)
532 555 {
@@ -539,6 +562,7 void QXYSeries::remove(const QPointF &point)
539 562
540 563 /*!
541 564 Removes the point at \a index from the series.
565 \sa pointRemoved()
542 566 */
543 567 void QXYSeries::remove(int index)
544 568 {
@@ -548,7 +572,23 void QXYSeries::remove(int index)
548 572 }
549 573
550 574 /*!
575 Removes \a count number of points from the series starting at \a index.
576 \sa pointsRemoved()
577 */
578 void QXYSeries::removePoints(int index, int count)
579 {
580 // This function doesn't overload remove as there is chance for it to get mixed up with
581 // remove(qreal, qreal) overload in some implicit casting cases.
582 Q_D(QXYSeries);
583 if (count > 0) {
584 d->m_points.remove(index, count);
585 emit pointsRemoved(index, count);
586 }
587 }
588
589 /*!
551 590 Inserts a \a point in the series at \a index position.
591 \sa pointAdded()
552 592 */
553 593 void QXYSeries::insert(int index, const QPointF &point)
554 594 {
@@ -561,13 +601,13 void QXYSeries::insert(int index, const QPointF &point)
561 601 }
562 602
563 603 /*!
564 Removes all points from the series.
604 Removes all points from the series.
605 \sa pointsRemoved()
565 606 */
566 607 void QXYSeries::clear()
567 608 {
568 609 Q_D(QXYSeries);
569 for (int i = d->m_points.size() - 1; i >= 0; i--)
570 remove(d->m_points.at(i));
610 removePoints(0, d->m_points.size());
571 611 }
572 612
573 613 /*!
@@ -58,6 +58,7 public:
58 58 void remove(qreal x, qreal y);
59 59 void remove(const QPointF &point);
60 60 void remove(int index);
61 void removePoints(int index, int count);
61 62 void insert(int index, const QPointF &point);
62 63 void clear();
63 64
@@ -110,6 +111,7 Q_SIGNALS:
110 111 void pointLabelsVisibilityChanged(bool visible);
111 112 void pointLabelsFontChanged(const QFont &font);
112 113 void pointLabelsColorChanged(const QColor &color);
114 void pointsRemoved(int index, int count);
113 115
114 116 private:
115 117 Q_DECLARE_PRIVATE(QXYSeries)
@@ -39,6 +39,7 XYChart::XYChart(QXYSeries *series, QGraphicsItem *item):
39 39 QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
40 40 QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
41 41 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
42 QObject::connect(series, SIGNAL(pointsRemoved(int, int)), this, SLOT(handlePointsRemoved(int, int)));
42 43 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
43 44 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool)));
44 45 QObject::connect(this, SIGNAL(pressed(QPointF)), series, SIGNAL(pressed(QPointF)));
@@ -145,6 +146,23 void XYChart::handlePointRemoved(int index)
145 146 updateChart(m_points, points, index);
146 147 }
147 148
149 void XYChart::handlePointsRemoved(int index, int count)
150 {
151 Q_ASSERT(index <= m_series->count());
152 Q_ASSERT(index >= 0);
153
154 QVector<QPointF> points;
155
156 if (m_dirty || m_points.isEmpty()) {
157 points = domain()->calculateGeometryPoints(m_series->points());
158 } else {
159 points = m_points;
160 points.remove(index, count);
161 }
162
163 updateChart(m_points, points, index);
164 }
165
148 166 void XYChart::handlePointReplaced(int index)
149 167 {
150 168 Q_ASSERT(index < m_series->count());
@@ -62,6 +62,7 public:
62 62 public Q_SLOTS:
63 63 void handlePointAdded(int index);
64 64 void handlePointRemoved(int index);
65 void handlePointsRemoved(int index, int count);
65 66 void handlePointReplaced(int index);
66 67 void handlePointsReplaced();
67 68 void handleDomainUpdated();
@@ -306,6 +306,9 public:
306 306 qmlRegisterUncreatableType<QAbstractAxis>(uri, 2, 1, "AbstractAxis",
307 307 QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead."));
308 308 qmlRegisterType<DeclarativeChart, 5>(uri, 2, 1, "ChartView");
309 qmlRegisterType<DeclarativeScatterSeries, 5>(uri, 2, 1, "ScatterSeries");
310 qmlRegisterType<DeclarativeLineSeries, 4>(uri, 2, 1, "LineSeries");
311 qmlRegisterType<DeclarativeSplineSeries, 4>(uri, 2, 1, "SplineSeries");
309 312 }
310 313
311 314 };
@@ -32,6 +32,7 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
32 32 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*)));
33 33 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
34 34 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
35 connect(this, SIGNAL(pointsRemoved(int, int)), this, SLOT(handleCountChanged(int)));
35 36 }
36 37
37 38 void DeclarativeLineSeries::handleCountChanged(int index)
@@ -78,6 +78,7 public:
78 78 Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); }
79 79 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
80 80 Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); }
81 Q_REVISION(4) Q_INVOKABLE void removePoints(int index, int count) { DeclarativeXySeries::removePoints(index, count); }
81 82 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
82 83 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
83 84 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
@@ -32,6 +32,7 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
32 32 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*)));
33 33 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
34 34 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
35 connect(this, SIGNAL(pointsRemoved(int, int)), this, SLOT(handleCountChanged(int)));
35 36 connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged()));
36 37 }
37 38
@@ -78,6 +78,7 public:
78 78 Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); }
79 79 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
80 80 Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); }
81 Q_REVISION(5) Q_INVOKABLE void removePoints(int index, int count) { DeclarativeXySeries::removePoints(index, count); }
81 82 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
82 83 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
83 84 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
@@ -32,6 +32,7 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
32 32 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*)));
33 33 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
34 34 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
35 connect(this, SIGNAL(pointsRemoved(int, int)), this, SLOT(handleCountChanged(int)));
35 36 }
36 37
37 38 void DeclarativeSplineSeries::handleCountChanged(int index)
@@ -78,6 +78,7 public:
78 78 Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); }
79 79 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
80 80 Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); }
81 Q_REVISION(4) Q_INVOKABLE void removePoints(int index, int count) { DeclarativeXySeries::removePoints(index, count); }
81 82 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
82 83 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
83 84 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
@@ -90,6 +90,13 void DeclarativeXySeries::remove(int index)
90 90 series->remove(index);
91 91 }
92 92
93 void DeclarativeXySeries::removePoints(int index, int count)
94 {
95 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
96 Q_ASSERT(series);
97 series->removePoints(index, count);
98 }
99
93 100 void DeclarativeXySeries::insert(int index, qreal x, qreal y)
94 101 {
95 102 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
@@ -42,6 +42,7 public:
42 42 void replace(int index, qreal newX, qreal newY);
43 43 void remove(qreal x, qreal y);
44 44 void remove(int index);
45 void removePoints(int index, int count);
45 46 void insert(int index, qreal x, qreal y);
46 47 void clear();
47 48 QPointF at(int index);
@@ -18,7 +18,7
18 18
19 19 import QtQuick 2.0
20 20 import QtTest 1.0
21 import QtCharts 2.0
21 import QtCharts 2.1
22 22
23 23 Rectangle {
24 24 width: 400
@@ -133,6 +133,36 Rectangle {
133 133 compare(lineSeriesPointRemovedSpy.count, count);
134 134 compare(splineSeriesPointRemovedSpy.count, count);
135 135 compare(scatterSeriesPointRemovedSpy.count, count);
136
137 lineSeriesPointRemovedSpy.clear();
138 splineSeriesPointRemovedSpy.clear();
139 scatterSeriesPointRemovedSpy.clear();
140 lineSeriesPointsRemovedSpy.clear();
141 splineSeriesPointsRemovedSpy.clear();
142 scatterSeriesPointsRemovedSpy.clear();
143
144 count = append();
145 lineSeries.removePoints(2, count - 2);
146 splineSeries.removePoints(2, count - 2);
147 scatterSeries.removePoints(2, count - 2);
148
149 compare(lineSeries.count, 2);
150 compare(splineSeries.count, 2);
151 compare(scatterSeries.count, 2);
152
153 lineSeries.removePoints(0, 2);
154 splineSeries.removePoints(0, 2);
155 scatterSeries.removePoints(0, 2);
156
157 compare(lineSeries.count, 0);
158 compare(splineSeries.count, 0);
159 compare(scatterSeries.count, 0);
160 compare(lineSeriesPointRemovedSpy.count, 0);
161 compare(splineSeriesPointRemovedSpy.count, 0);
162 compare(scatterSeriesPointRemovedSpy.count, 0);
163 compare(lineSeriesPointsRemovedSpy.count, 2);
164 compare(splineSeriesPointsRemovedSpy.count, 2);
165 compare(scatterSeriesPointsRemovedSpy.count, 2);
136 166 }
137 167
138 168 // Not a test function, called from test functions
@@ -191,6 +221,12 Rectangle {
191 221 target: lineSeries
192 222 signalName: "pointRemoved"
193 223 }
224
225 SignalSpy {
226 id: lineSeriesPointsRemovedSpy
227 target: lineSeries
228 signalName: "pointsRemoved"
229 }
194 230 }
195 231
196 232 AreaSeries {
@@ -226,6 +262,12 Rectangle {
226 262 target: splineSeries
227 263 signalName: "pointRemoved"
228 264 }
265
266 SignalSpy {
267 id: splineSeriesPointsRemovedSpy
268 target: splineSeries
269 signalName: "pointsRemoved"
270 }
229 271 }
230 272
231 273 ScatterSeries {
@@ -255,6 +297,12 Rectangle {
255 297 target: scatterSeries
256 298 signalName: "pointRemoved"
257 299 }
300
301 SignalSpy {
302 id: scatterSeriesPointsRemovedSpy
303 target: scatterSeries
304 signalName: "pointsRemoved"
305 }
258 306 }
259 307 }
260 308 }
@@ -176,7 +176,10 void tst_qml::checkPlugin_data()
176 176 QTest::newRow("BoxPlotSeries_2_0") << imports_2_0() + "BoxPlotSeries{}";
177 177 QTest::newRow("BoxSet_2_0") << imports_2_0() + "BoxSet{}";
178 178
179 QTest::newRow("CategoryAxis") << imports_2_1() + "CategoryAxis{}";
179 QTest::newRow("CategoryAxis_2_1") << imports_2_1() + "CategoryAxis{}";
180 QTest::newRow("ScatterSeries_2_1") << imports_2_1() + "ScatterSeries{}";
181 QTest::newRow("LineSeries_2_1") << imports_2_1() + "LineSeries{}";
182 QTest::newRow("SplineSeries_2_1") << imports_2_1() + "SplineSeries{}";
180 183 }
181 184
182 185 void tst_qml::checkPlugin()
@@ -329,6 +329,10 void tst_qxymodelmapper::seriesUpdated()
329 329 QCOMPARE(m_series->count(), m_modelRowCount);
330 330 QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model
331 331
332 m_series->removePoints(1, m_modelRowCount - 4);
333 QCOMPARE(m_series->count(), 4);
334 QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model
335
332 336 m_series->replace(m_series->points().first(), QPointF(25.0, 75.0));
333 337 QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0);
334 338 QCOMPARE(m_model->data(m_model->index(0, 1)).toReal(), 75.0);
@@ -316,6 +316,16 void tst_QXYSeries::remove_raw()
316 316 QCOMPARE(m_series->points().count(), i);
317 317 }
318 318 QCOMPARE(m_series->points().count(), 0);
319
320 // Multiple removal using index
321 for (int i = 0; i < 10; i++)
322 bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX));
323 m_series->replace(bunchOfPoints);
324 m_series->removePoints(5, 2);
325 m_series->removePoints(0, 3);
326 QCOMPARE(m_series->points().count(), (bunchOfPoints.count() - 5));
327 m_series->removePoints(0, (bunchOfPoints.count() - 5));
328 QCOMPARE(m_series->points().count(), 0);
319 329 }
320 330
321 331 void tst_QXYSeries::remove_chart_data()
@@ -111,6 +111,16 Flow {
111 111 onClicked: series.remove(series.count - 1);
112 112 }
113 113 Button {
114 text: "remove points"
115 onClicked: {
116 var count = 3;
117 if (series.count < 3)
118 count = series.count
119 var index = series.count - count;
120 series.removePoints(index, count);
121 }
122 }
123 Button {
114 124 text: "insert point"
115 125 onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2);
116 126 }
@@ -106,6 +106,16 Flow {
106 106 onClicked: series.remove(series.count - 1);
107 107 }
108 108 Button {
109 text: "remove points"
110 onClicked: {
111 var count = 3;
112 if (series.count < 3)
113 count = series.count
114 var index = series.count - count;
115 series.removePoints(index, count);
116 }
117 }
118 Button {
109 119 text: "insert point"
110 120 onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2);
111 121 }
General Comments 0
You need to be logged in to leave comments. Login now