diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index b1069a4..4dbb5e3 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -116,12 +116,23 @@ void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty setList = barSets(); - if (index < setList.count()) + if (index >= 0 && index < setList.count()) return qobject_cast(setList[index]); return 0; } +DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) +{ + DeclarativeBarSet *barset = new DeclarativeBarSet(this); + barset->setLabel(label); + barset->setValues(values); + if (QBarSeries::insert(index, barset)) + return barset; + delete barset; + return 0; +} + DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) : QGroupedBarSeries(parent) { @@ -161,12 +172,23 @@ void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty< DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index) { QList setList = barSets(); - if (index < setList.count()) + if (index >= 0 && index < setList.count()) return qobject_cast(setList[index]); return 0; } +DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values) +{ + DeclarativeBarSet *barset = new DeclarativeBarSet(this); + barset->setLabel(label); + barset->setValues(values); + if (QGroupedBarSeries::insert(index, barset)) + return barset; + delete barset; + return 0; +} + DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : QStackedBarSeries(parent) { @@ -206,12 +228,23 @@ void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty< DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) { QList setList = barSets(); - if (index < setList.count()) + if (index >= 0 && index < setList.count()) return qobject_cast(setList[index]); return 0; } +DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) +{ + DeclarativeBarSet *barset = new DeclarativeBarSet(this); + barset->setLabel(label); + barset->setValues(values); + if (QStackedBarSeries::insert(index, barset)) + return barset; + delete barset; + return 0; +} + DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : QPercentBarSeries(parent) { @@ -251,12 +284,23 @@ void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty< DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) { QList setList = barSets(); - if (index < setList.count()) + if (index >= 0 && index < setList.count()) return qobject_cast(setList[index]); return 0; } +DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) +{ + DeclarativeBarSet *barset = new DeclarativeBarSet(this); + barset->setLabel(label); + barset->setValues(values); + if (QPercentBarSeries::insert(index, barset)) + return barset; + delete barset; + return 0; +} + #include "moc_declarativebarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index c28092d..9638270 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -66,6 +66,10 @@ public: explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); QDeclarativeListProperty seriesChildren(); Q_INVOKABLE DeclarativeBarSet *at(int index); + Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } + Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); + Q_INVOKABLE bool remove(QBarSet *barset) { return QBarSeries::remove(barset); } + Q_INVOKABLE void clear() { return QBarSeries::clear(); } public: // from QDeclarativeParserStatus void classBegin(); @@ -92,6 +96,10 @@ public: explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0); QDeclarativeListProperty seriesChildren(); Q_INVOKABLE DeclarativeBarSet *at(int index); + Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } + Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); + Q_INVOKABLE bool remove(QBarSet *barset) { return QGroupedBarSeries::remove(barset); } + Q_INVOKABLE void clear() { return QGroupedBarSeries::clear(); } public: // from QDeclarativeParserStatus void classBegin(); @@ -112,6 +120,10 @@ public: explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); QDeclarativeListProperty seriesChildren(); Q_INVOKABLE DeclarativeBarSet *at(int index); + Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } + Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); + Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); } + Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); } public: // from QDeclarativeParserStatus void classBegin(); @@ -132,6 +144,10 @@ public: explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); QDeclarativeListProperty seriesChildren(); Q_INVOKABLE DeclarativeBarSet *at(int index); + Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } + Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); + Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); } + Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); } public: // from QDeclarativeParserStatus void classBegin(); diff --git a/plugins/declarative/declarativepieseries.cpp b/plugins/declarative/declarativepieseries.cpp index 10b1008..7d9c79f 100644 --- a/plugins/declarative/declarativepieseries.cpp +++ b/plugins/declarative/declarativepieseries.cpp @@ -93,12 +93,9 @@ QPieSlice* DeclarativePieSeries::append(QString label, qreal value) return slice; } -bool DeclarativePieSeries::remove(int index) +bool DeclarativePieSeries::remove(QPieSlice *slice) { - QPieSlice *slice = at(index); - if (slice) - return QPieSeries::remove(slice); - return false; + return QPieSeries::remove(slice); } void DeclarativePieSeries::clear() diff --git a/plugins/declarative/declarativepieseries.h b/plugins/declarative/declarativepieseries.h index eae14a5..fb9fdf5 100644 --- a/plugins/declarative/declarativepieseries.h +++ b/plugins/declarative/declarativepieseries.h @@ -45,7 +45,7 @@ public: Q_INVOKABLE QPieSlice *at(int index); Q_INVOKABLE QPieSlice *find(QString label); Q_INVOKABLE QPieSlice *append(QString label, qreal value); - Q_INVOKABLE bool remove(int index); + Q_INVOKABLE bool remove(QPieSlice *slice); Q_INVOKABLE void clear(); public: diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml index 15da8b3..1539cb0 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml @@ -44,8 +44,26 @@ Flow { onClicked: series.barWidth -= 0.1; } Button { + text: "append set" + onClicked: { + var count = series.count; + series.append("set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]); + } + } + Button { + text: "insert set" + onClicked: { + var count = series.count; + series.insert(count - 1, "set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]); + } + } + Button { text: "remove set" - onClicked: series.remove(series.count - 1); + onClicked: series.remove(series.at(series.count - 1)); + } + Button { + text: "clear sets" + onClicked: series.clear(); } Button { text: "set 1 color" diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml index a75dd12..0748e81 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/PieEditor.qml @@ -73,7 +73,7 @@ Flow { } Button { text: "remove slice" - onClicked: series.remove(series.count - 1); + onClicked: series.remove(series.at(series.count - 1)); } Button { text: "slice color"