##// END OF EJS Templates
Implement index based removing/replacing points in series...
Miikka Heikkinen -
r2496:764230e0c100
parent child
Show More
@@ -91,7 +91,9 public: // from QDeclarativeParserStatus
91 public:
91 public:
92 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
92 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
93 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
93 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
94 Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); }
94 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
95 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
96 Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); }
95 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
97 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
96 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
98 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
97 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
99 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
@@ -85,7 +85,9 public: // from QDeclarativeParserStatus
85 public:
85 public:
86 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
86 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
87 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
87 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
88 Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); }
88 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
89 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
90 Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); }
89 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
91 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
90 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
92 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
91 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
93 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
@@ -91,7 +91,9 public: // from QDeclarativeParserStatus
91 public:
91 public:
92 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
92 Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); }
93 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
93 Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); }
94 Q_REVISION(3) Q_INVOKABLE void replace(int index, qreal newX, qreal newY) { DeclarativeXySeries::replace(index, newX, newY); }
94 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
95 Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); }
96 Q_REVISION(3) Q_INVOKABLE void remove(int index) { DeclarativeXySeries::remove(index); }
95 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
97 Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); }
96 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
98 Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); }
97 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
99 Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); }
@@ -71,6 +71,13 void DeclarativeXySeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY
71 series->replace(oldX, oldY, newX, newY);
71 series->replace(oldX, oldY, newX, newY);
72 }
72 }
73
73
74 void DeclarativeXySeries::replace(int index, qreal newX, qreal newY)
75 {
76 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
77 Q_ASSERT(series);
78 series->replace(index, newX, newY);
79 }
80
74 void DeclarativeXySeries::remove(qreal x, qreal y)
81 void DeclarativeXySeries::remove(qreal x, qreal y)
75 {
82 {
76 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
83 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
@@ -78,6 +85,13 void DeclarativeXySeries::remove(qreal x, qreal y)
78 series->remove(x, y);
85 series->remove(x, y);
79 }
86 }
80
87
88 void DeclarativeXySeries::remove(int index)
89 {
90 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
91 Q_ASSERT(series);
92 series->remove(index);
93 }
94
81 void DeclarativeXySeries::insert(int index, qreal x, qreal y)
95 void DeclarativeXySeries::insert(int index, qreal x, qreal y)
82 {
96 {
83 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
97 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
@@ -41,7 +41,9 public:
41
41
42 void append(qreal x, qreal y);
42 void append(qreal x, qreal y);
43 void replace(qreal oldX, qreal oldY, qreal newX, qreal newY);
43 void replace(qreal oldX, qreal oldY, qreal newX, qreal newY);
44 void replace(int index, qreal newX, qreal newY);
44 void remove(qreal x, qreal y);
45 void remove(qreal x, qreal y);
46 void remove(int index);
45 void insert(int index, qreal x, qreal y);
47 void insert(int index, qreal x, qreal y);
46 void clear();
48 void clear();
47 QPointF at(int index);
49 QPointF at(int index);
@@ -292,6 +292,17 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
292 int index = d->m_points.indexOf(oldPoint);
292 int index = d->m_points.indexOf(oldPoint);
293 if (index == -1)
293 if (index == -1)
294 return;
294 return;
295 replace(index, newPoint);
296 }
297
298 void QXYSeries::replace(int index, qreal newX, qreal newY)
299 {
300 replace(index, QPointF(newX, newY));
301 }
302
303 void QXYSeries::replace(int index, const QPointF &newPoint)
304 {
305 Q_D(QXYSeries);
295 if (isValidValue(newPoint)) {
306 if (isValidValue(newPoint)) {
296 d->m_points[index] = newPoint;
307 d->m_points[index] = newPoint;
297 emit pointReplaced(index);
308 emit pointReplaced(index);
@@ -329,6 +340,12 void QXYSeries::remove(const QPointF &point)
329 int index = d->m_points.indexOf(point);
340 int index = d->m_points.indexOf(point);
330 if (index == -1)
341 if (index == -1)
331 return;
342 return;
343 remove(index);
344 }
345
346 void QXYSeries::remove(int index)
347 {
348 Q_D(QXYSeries);
332 d->m_points.remove(index);
349 d->m_points.remove(index);
333 emit pointRemoved(index);
350 emit pointRemoved(index);
334 }
351 }
@@ -49,8 +49,11 public:
49 void append(const QList<QPointF> &points);
49 void append(const QList<QPointF> &points);
50 void replace(qreal oldX, qreal oldY, qreal newX, qreal newY);
50 void replace(qreal oldX, qreal oldY, qreal newX, qreal newY);
51 void replace(const QPointF &oldPoint, const QPointF &newPoint);
51 void replace(const QPointF &oldPoint, const QPointF &newPoint);
52 void replace(int index, qreal newX, qreal newY);
53 void replace(int index, const QPointF &newPoint);
52 void remove(qreal x, qreal y);
54 void remove(qreal x, qreal y);
53 void remove(const QPointF &point);
55 void remove(const QPointF &point);
56 void remove(int index);
54 void insert(int index, const QPointF &point);
57 void insert(int index, const QPointF &point);
55 void clear();
58 void clear();
56
59
@@ -231,6 +231,20 void tst_QXYSeries::remove_raw()
231 m_series->remove(bunchOfPoints.at(i));
231 m_series->remove(bunchOfPoints.at(i));
232 QTest::qWait(50);
232 QTest::qWait(50);
233 }
233 }
234 QCOMPARE(m_series->points().count(), 0);
235
236 // Removal using index
237 for (int i = 0; i < 10; i++)
238 bunchOfPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX));
239 m_series->replace(bunchOfPoints);
240 m_series->remove(5);
241 m_series->remove(0);
242 QCOMPARE(m_series->points().count(), (bunchOfPoints.count() - 2));
243 for (int i = bunchOfPoints.count() - 3; i >= 0; i--) {
244 m_series->remove(i);
245 QCOMPARE(m_series->points().count(), i);
246 }
247 QCOMPARE(m_series->points().count(), 0);
234 }
248 }
235
249
236 void tst_QXYSeries::remove_chart_data()
250 void tst_QXYSeries::remove_chart_data()
@@ -366,6 +380,15 void tst_QXYSeries::replace_raw()
366 m_series->replace(QPointF(23,23), otherPoints.at(1));
380 m_series->replace(QPointF(23,23), otherPoints.at(1));
367 QCOMPARE(m_series->points().at(1).x(), otherPoints.at(1).x());
381 QCOMPARE(m_series->points().at(1).x(), otherPoints.at(1).x());
368 QCOMPARE(m_series->points().at(1).y(), otherPoints.at(1).y());
382 QCOMPARE(m_series->points().at(1).y(), otherPoints.at(1).y());
383
384 // Replace using index
385 m_series->append(otherPoints);
386 m_series->replace(0, QPointF(333, 333));
387 m_series->replace(3, 444, 444);
388 m_series->replace(m_series->count() - 1, QPointF(555, 555));
389 QCOMPARE(m_series->points().at(0), QPointF(333, 333));
390 QCOMPARE(m_series->points().at(3), QPointF(444, 444));
391 QCOMPARE(m_series->points().at(m_series->count() - 1), QPointF(555, 555));
369 }
392 }
370
393
371
394
@@ -79,12 +79,12 Flow {
79 text: "replace point"
79 text: "replace point"
80 onClicked: {
80 onClicked: {
81 var xyPoint = series.at(series.count - 1);
81 var xyPoint = series.at(series.count - 1);
82 series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1);
82 series.replace(series.count - 1, xyPoint.x, xyPoint.y + 0.1);
83 }
83 }
84 }
84 }
85 Button {
85 Button {
86 text: "remove point"
86 text: "remove point"
87 onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y);
87 onClicked: series.remove(series.count - 1);
88 }
88 }
89 Button {
89 Button {
90 text: "insert point"
90 text: "insert point"
@@ -74,12 +74,12 Flow {
74 text: "replace point"
74 text: "replace point"
75 onClicked: {
75 onClicked: {
76 var xyPoint = series.at(series.count - 1);
76 var xyPoint = series.at(series.count - 1);
77 series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1);
77 series.replace(series.count - 1, xyPoint.x, xyPoint.y + 0.1);
78 }
78 }
79 }
79 }
80 Button {
80 Button {
81 text: "remove point"
81 text: "remove point"
82 onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y);
82 onClicked: series.remove(series.count - 1);
83 }
83 }
84 Button {
84 Button {
85 text: "insert point"
85 text: "insert point"
@@ -79,12 +79,12 Flow {
79 text: "replace point"
79 text: "replace point"
80 onClicked: {
80 onClicked: {
81 var xyPoint = series.at(series.count - 1);
81 var xyPoint = series.at(series.count - 1);
82 series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1);
82 series.replace(series.count - 1, xyPoint.x, xyPoint.y + 0.1);
83 }
83 }
84 }
84 }
85 Button {
85 Button {
86 text: "remove point"
86 text: "remove point"
87 onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y);
87 onClicked: series.remove(series.count - 1);
88 }
88 }
89 Button {
89 Button {
90 text: "insert point"
90 text: "insert point"
@@ -74,12 +74,12 Flow {
74 text: "replace point"
74 text: "replace point"
75 onClicked: {
75 onClicked: {
76 var xyPoint = series.at(series.count - 1);
76 var xyPoint = series.at(series.count - 1);
77 series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1);
77 series.replace(series.count - 1, xyPoint.x, xyPoint.y + 0.1);
78 }
78 }
79 }
79 }
80 Button {
80 Button {
81 text: "remove point"
81 text: "remove point"
82 onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y);
82 onClicked: series.remove(series.count - 1);
83 }
83 }
84 Button {
84 Button {
85 text: "insert point"
85 text: "insert point"
General Comments 0
You need to be logged in to leave comments. Login now