From f9a49067ae3bd3493531935c7e00e7862fef6828 2012-06-20 12:18:21 From: Tero Ahola Date: 2012-06-20 12:18:21 Subject: [PATCH] QML BarSet data manipulation --- diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index 4dbb5e3..2b36a4a 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -44,7 +44,7 @@ QVariantList DeclarativeBarSet::values() { QVariantList values; for (int i(0); i < count(); i++) - values.append(QVariant(at(i))); + values.append(QVariant(QBarSet::at(i))); return values; } @@ -55,7 +55,9 @@ void DeclarativeBarSet::setValues(QVariantList values) for (int i(0); i < values.count(); i++) { if (values.at(i).canConvert(QVariant::Double)) - append(values[i].toDouble()); + QBarSet::append(values[i].toDouble()); + else if (values.at(i).canConvert(QVariant::PointF)) + QBarSet::append(values[i].toPointF()); } } diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index 9638270..eff8639 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -47,6 +47,10 @@ public: public: // From QBarSet Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } Q_INVOKABLE void append(qreal x, qreal y) { QBarSet::append(QPointF(x, y)); } + Q_INVOKABLE bool remove(const int index, const int count = 1) { return QBarSet::remove(index, count); } + Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); } + Q_INVOKABLE void replace(int index, qreal x, qreal y) { QBarSet::replace(index, QPointF(x, y)); } + Q_INVOKABLE QPointF at(int index) { return QBarSet::at(index); } Q_SIGNALS: void countChanged(int count); diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml index 62882db..6c23f80 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml @@ -36,10 +36,18 @@ ChartView { BarSet { label: "Bob"; values: [4, 7, 3, 10, 5, 6] onClicked: console.log("barset.onClicked: " + index); onHovered: console.log("barset.onHovered: " + status); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); onColorChanged: console.log("barset.onColorChanged: " + color); onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 8] } BarSet { label: "James"; values: [3, 5, 8, 5, 4, 7] } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml index 1539cb0..8308ae7 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml @@ -65,6 +65,20 @@ Flow { text: "clear sets" onClicked: series.clear(); } + + Button { + text: "set 1 append" + onClicked: series.at(0).append(series.at(0).count + 1); + } + Button { + text: "set 1 replace" + onClicked: series.at(0).replace(series.at(0).count - 1, series.at(0).at(series.at(0).count - 1).y + 0.5); + } + Button { + text: "set 1 remove" + onClicked: series.at(0).remove(series.at(0).count - 1); + } + Button { text: "set 1 color" onClicked: series.at(0).color = main.nextColor(); diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/GroupedBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/GroupedBarChart.qml index c34cd8d..657fb40 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/GroupedBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/GroupedBarChart.qml @@ -36,10 +36,18 @@ ChartView { BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); onHovered: console.log("barset.onHovered: " + status); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); onColorChanged: console.log("barset.onColorChanged: " + color); onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml index 6f27e97..8a2a827 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/PercentBarChart.qml @@ -36,10 +36,18 @@ ChartView { BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); onHovered: console.log("barset.onHovered: " + status); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); onColorChanged: console.log("barset.onColorChanged: " + color); onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml index 6738a04..a87a119 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/StackedBarChart.qml @@ -36,10 +36,18 @@ ChartView { BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] onClicked: console.log("barset.onClicked: " + index); onHovered: console.log("barset.onHovered: " + status); + onPenChanged: console.log("barset.onPenChanged: " + pen); + onBrushChanged: console.log("barset.onBrushChanged: " + brush); + onLabelChanged: console.log("barset.onLabelChanged: " + label); + onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); + onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); onColorChanged: console.log("barset.onColorChanged: " + color); onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); onCountChanged: console.log("barset.onCountChanged: " + count); + onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); + onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); + onValueChanged: console.log("barset.onValuesChanged: " + index); } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }