From d43045438e43926569f3f9b95196e97610f6988e 2012-06-20 09:30:31 From: Tero Ahola Date: 2012-06-20 09:30:31 Subject: [PATCH] QML xy-series data manipulation --- diff --git a/plugins/declarative/declarativelineseries.h b/plugins/declarative/declarativelineseries.h index 860fa5a..53932ce 100644 --- a/plugins/declarative/declarativelineseries.h +++ b/plugins/declarative/declarativelineseries.h @@ -49,7 +49,9 @@ public: // from QDeclarativeParserStatus public: // from QLineSeries Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); } + Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QLineSeries::replace(oldX, oldY, newX, newY); } Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); } + Q_INVOKABLE void insert(int index, qreal x, qreal y) { QLineSeries::insert(index, QPointF(x, y)); } Q_INVOKABLE void clear() { QLineSeries::clear(); } Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } diff --git a/plugins/declarative/declarativescatterseries.h b/plugins/declarative/declarativescatterseries.h index 11930cc..5450882 100644 --- a/plugins/declarative/declarativescatterseries.h +++ b/plugins/declarative/declarativescatterseries.h @@ -48,8 +48,10 @@ public: // from QDeclarativeParserStatus public: // from QScatterSeries Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); } + Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QScatterSeries::replace(oldX, oldY, newX, newY); } Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); } Q_INVOKABLE void clear() { QScatterSeries::clear(); } + Q_INVOKABLE void insert(int index, qreal x, qreal y) { QScatterSeries::insert(index, QPointF(x, y)); } Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } Q_SIGNALS: diff --git a/plugins/declarative/declarativesplineseries.h b/plugins/declarative/declarativesplineseries.h index bb5bb52..e9ee4ee 100644 --- a/plugins/declarative/declarativesplineseries.h +++ b/plugins/declarative/declarativesplineseries.h @@ -34,6 +34,7 @@ class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) Q_CLASSINFO("DefaultProperty", "declarativeChildren") @@ -48,8 +49,10 @@ public: // from QDeclarativeParserStatus public: // from QSplineSeries Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); } + Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { QSplineSeries::replace(oldX, oldY, newX, newY); } Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); } Q_INVOKABLE void clear() { QSplineSeries::clear(); } + Q_INVOKABLE void insert(int index, qreal x, qreal y) { QSplineSeries::insert(index, QPointF(x, y)); } Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } Q_SIGNALS: diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml index 92a4031..7190af7 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/LineChart.qml @@ -43,7 +43,7 @@ ChartView { onClicked: console.log("lineSeries.onClicked: " + point.x + ", " + point.y); onPointReplaced: console.log("lineSeries.onPointReplaced: " + index); onPointRemoved: console.log("lineSeries.onPointRemoved: " + index); - onPointAdded: console.log("lineSeries.onPointAdded: " + index); + onPointAdded: console.log("lineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); onColorChanged: console.log("lineSeries.onColorChanged: " + color); onCountChanged: console.log("lineSeries.onCountChanged: " + count); } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml index f4243f4..37cd1de 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/LineEditor.qml @@ -38,6 +38,29 @@ Flow { } Button { text: "points visible" - onClicked: series.pointsVisible = !series.pointsVisible + onClicked: series.pointsVisible = !series.pointsVisible; + } + Button { + text: "append point" + onClicked: series.append(series.count - 1, series.count - 1); + } + Button { + text: "replace point" + onClicked: { + var xyPoint = series.at(series.count - 1); + series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1); + } + } + Button { + text: "remove point" + onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y); + } + Button { + text: "insert point" + onClicked: series.insert(0, series.count - 1, series.count - 1); + } + Button { + text: "clear" + onClicked: series.clear(); } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml index 8fb58e4..434e7f8 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterChart.qml @@ -40,6 +40,9 @@ ChartView { onNameChanged: console.log("scatterSeries.onNameChanged: " + name); onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible); + onPointReplaced: console.log("scatterSeries.onPointReplaced: " + index); + onPointRemoved: console.log("scatterSeries.onPointRemoved: " + index); + onPointAdded: console.log("scatterSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); onColorChanged: console.log("scatterSeries.onColorChanged: " + color); onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor); onCountChanged: console.log("scatterSeries.onCountChanged: " + count); diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml index 05d8341..fefa6b1 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/ScatterEditor.qml @@ -52,4 +52,27 @@ Flow { text: "markerShape" onClicked: series.markerShape = ((series.markerShape + 1) % 2); } + Button { + text: "append point" + onClicked: series.append(series.count - 1, series.count - 1); + } + Button { + text: "replace point" + onClicked: { + var xyPoint = series.at(series.count - 1); + series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1); + } + } + Button { + text: "remove point" + onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y); + } + Button { + text: "insert point" + onClicked: series.insert(0, series.count - 1, series.count - 1); + } + Button { + text: "clear" + onClicked: series.clear(); + } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml index 7c9ced9..9f8a3e8 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/SplineChart.qml @@ -42,7 +42,7 @@ ChartView { onClicked: console.log("splineSeries.onClicked: " + point.x + ", " + point.y); onPointReplaced: console.log("splineSeries.onPointReplaced: " + index); onPointRemoved: console.log("splineSeries.onPointRemoved: " + index); - onPointAdded: console.log("splineSeries.onPointAdded: " + index); + onPointAdded: console.log("splineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); onColorChanged: console.log("splineSeries.onColorChanged: " + color); onCountChanged: console.log("splineSeries.onCountChanged: " + count); }