From 1adeb672d1e021b224c0b00d8fc7b226447437d7 2012-06-20 09:33:31 From: Tero Ahola Date: 2012-06-20 09:33:31 Subject: [PATCH] QML BarSeries added/removed signals --- diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index ca43528..b1069a4 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -62,6 +62,24 @@ void DeclarativeBarSet::setValues(QVariantList values) DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : QBarSeries(parent) { + connect(this, SIGNAL(barsetsAdded(QList)), this, SLOT(handleAdded(QList))); + connect(this, SIGNAL(barsetsRemoved(QList)), this, SLOT(handleRemoved(QList))); +} + +void DeclarativeBarSeries::handleAdded(QList barsets) +{ + foreach(QBarSet *b, barsets) { + DeclarativeBarSet *barset = qobject_cast(b); + emit added(barset); + } +} + +void DeclarativeBarSeries::handleRemoved(QList barsets) +{ + foreach(QBarSet *b, barsets) { + DeclarativeBarSet *barset = qobject_cast(b); + emit removed(barset); + } } void DeclarativeBarSeries::classBegin() diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index 169432a..c28092d 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -71,8 +71,14 @@ public: // from QDeclarativeParserStatus void classBegin(); void componentComplete(); +Q_SIGNALS: + void added(DeclarativeBarSet *barset); + void removed(DeclarativeBarSet *barset); + public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); + void handleAdded(QList barsets); + void handleRemoved(QList barsets); }; class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 46b8032..20b33dc 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -139,12 +139,20 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE This signal is emitted when \a sets have been added to the series. \sa append(), insert() */ +/*! + \qmlsignal BarSeries::added(BarSet barset) + Emitted when \a barset has been added to the series. +*/ /*! \fn void QBarSeries::barsetsRemoved(QList sets) This signal is emitted when \a sets have been removed from the series. \sa remove() */ +/*! + \qmlsignal BarSeries::removed(BarSet barset) + Emitted when \a barset has been removed from the series. +*/ /*! Constructs empty QBarSeries. diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml index 6d6a42d..62882db 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarChart.qml @@ -50,5 +50,9 @@ ChartView { onHovered: console.log("barSeries.onHovered: " + barset + " " + status); onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible); onCountChanged: console.log("barSeries.onCountChanged: " + count); + onBarsetsAdded: console.log("barSeries.onBarsetsAdded: " + sets); // There is no point in this signal on QML side + onAdded: console.log("barSeries.onBarsetAdded: " + barset); + onBarsetsRemoved: console.log("barSeries.onBarsetsRemoved: " + sets); // There is no point in this signal on QML side + onRemoved: console.log("barSeries.onBarsetRemoved: " + barset); } } diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml index 7f08fe2..15da8b3 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/BarEditor.qml @@ -44,6 +44,10 @@ Flow { onClicked: series.barWidth -= 0.1; } Button { + text: "remove set" + onClicked: series.remove(series.count - 1); + } + Button { text: "set 1 color" onClicked: series.at(0).color = main.nextColor(); }