From a034773ce0e9d3fe3e7768da248d8c2e99cf132d Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 26 Mar 2010 08:38:43 +0100 Subject: Adds a way to clear the state list property in QDeclarativeStateGroup Needed by QmlDesigner, which needs to be able to remove states at runtime. Done my Marco Bubke Reviewed-by: Michael Brasser --- src/declarative/util/qdeclarativestategroup.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/declarative/util/qdeclarativestategroup.cpp b/src/declarative/util/qdeclarativestategroup.cpp index bc4582c..258a9e9 100644 --- a/src/declarative/util/qdeclarativestategroup.cpp +++ b/src/declarative/util/qdeclarativestategroup.cpp @@ -69,6 +69,7 @@ public: static void append_state(QDeclarativeListProperty *list, QDeclarativeState *state); static int count_state(QDeclarativeListProperty *list); static QDeclarativeState *at_state(QDeclarativeListProperty *list, int index); + static void clear_states(QDeclarativeListProperty *list); QList states; QList transitions; @@ -150,7 +151,8 @@ QDeclarativeListProperty QDeclarativeStateGroup::statesProper Q_D(QDeclarativeStateGroup); return QDeclarativeListProperty(this, &d->states, &QDeclarativeStateGroupPrivate::append_state, &QDeclarativeStateGroupPrivate::count_state, - &QDeclarativeStateGroupPrivate::at_state); + &QDeclarativeStateGroupPrivate::at_state, + &QDeclarativeStateGroupPrivate::clear_states); } void QDeclarativeStateGroupPrivate::append_state(QDeclarativeListProperty *list, QDeclarativeState *state) @@ -175,6 +177,16 @@ QDeclarativeState *QDeclarativeStateGroupPrivate::at_state(QDeclarativeListPrope return _this->d_func()->states.at(index); } +void QDeclarativeStateGroupPrivate::clear_states(QDeclarativeListProperty *list) +{ + QDeclarativeStateGroup *_this = static_cast(list->object); + _this->d_func()->setCurrentStateInternal(QString(), true); + for (int i = 0; i < _this->d_func()->states.count(); ++i) { + _this->d_func()->states.at(i)->setStateGroup(0); + } + _this->d_func()->states.clear(); +} + /*! \qmlproperty list StateGroup::transitions This property holds a list of transitions defined by the state group. -- cgit v0.12