diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-11-22 23:56:08 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-11-22 23:57:58 (GMT) |
commit | 5f0a3cd6dbae87b5944c3cb31fdc294fc0ac1163 (patch) | |
tree | 2d44116fd8f982cc5ae6a57b49abc15d8eb87404 | |
parent | 055e1008ca5a49f1653db2ff5d5de51d584922b7 (diff) | |
download | Qt-5f0a3cd6dbae87b5944c3cb31fdc294fc0ac1163.zip Qt-5f0a3cd6dbae87b5944c3cb31fdc294fc0ac1163.tar.gz Qt-5f0a3cd6dbae87b5944c3cb31fdc294fc0ac1163.tar.bz2 |
Remove deleted state operations from the state.
-rw-r--r-- | src/declarative/util/qmlstate_p_p.h | 25 | ||||
-rw-r--r-- | tests/auto/declarative/states/data/deleting.qml | 11 | ||||
-rw-r--r-- | tests/auto/declarative/states/data/deletingState.qml | 13 | ||||
-rw-r--r-- | tests/auto/declarative/states/tst_states.cpp | 65 |
4 files changed, 113 insertions, 1 deletions
diff --git a/src/declarative/util/qmlstate_p_p.h b/src/declarative/util/qmlstate_p_p.h index 095a7d2..75eb3fd 100644 --- a/src/declarative/util/qmlstate_p_p.h +++ b/src/declarative/util/qmlstate_p_p.h @@ -102,7 +102,30 @@ public: QString name; QmlBinding *when; - QmlConcreteList<QmlStateOperation *> operations; + + class OperationList; + struct OperationGuard : public QGuard<QmlStateOperation> + { + OperationGuard(QObject *obj, OperationList *l) : list(l) { (QGuard<QObject>&)*this = obj; } + OperationList *list; + void objectDestroyed(QmlStateOperation *) { + // we assume priv will always be destroyed after objectDestroyed calls + list->removeOne(*this); + } + }; + + typedef QList<OperationGuard> GuardedOpList; + class OperationList : public GuardedOpList, public QmlList<QmlStateOperation*> + { + public: + virtual void append(QmlStateOperation* v) { GuardedOpList::append(OperationGuard(v, this)); } + virtual void insert(int i, QmlStateOperation* v) { GuardedOpList::insert(i, OperationGuard(v, this)); } + virtual void clear() { GuardedOpList::clear(); } + virtual QmlStateOperation* at(int i) const { return GuardedOpList::at(i); } + virtual void removeAt(int i) { GuardedOpList::removeAt(i); } + virtual int count() const { return GuardedOpList::count(); } + }; + OperationList operations; QmlTransitionManager transitionManager; diff --git a/tests/auto/declarative/states/data/deleting.qml b/tests/auto/declarative/states/data/deleting.qml new file mode 100644 index 0000000..0c512dd --- /dev/null +++ b/tests/auto/declarative/states/data/deleting.qml @@ -0,0 +1,11 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue"; objectName: "pc1" } + PropertyChanges { target: MyRectangle; radius: 5; objectName: "pc2" } + } +} diff --git a/tests/auto/declarative/states/data/deletingState.qml b/tests/auto/declarative/states/data/deletingState.qml new file mode 100644 index 0000000..9dc46a6 --- /dev/null +++ b/tests/auto/declarative/states/data/deletingState.qml @@ -0,0 +1,13 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + StateGroup { + id: stateGroup + states: State { + name: "blue" + PropertyChanges { target: MyRectangle; color: "blue" } + } + } +} diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index a4da1f1..4847535 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -44,6 +44,7 @@ #include <private/qmlgraphicsanchors_p_p.h> #include <private/qmlgraphicsrectangle_p.h> #include <private/qmlpropertychanges_p.h> +#include <private/qmlstategroup_p.h> class tst_states : public QObject { @@ -69,6 +70,8 @@ private slots: void explicitChanges(); void propertyErrors(); void incorrectRestoreBug(); + void deletingChange(); + void deletingState(); }; void tst_states::basicChanges() @@ -738,6 +741,68 @@ void tst_states::incorrectRestoreBug() QCOMPARE(rect->color(),QColor("green")); } +void tst_states::deletingChange() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/deleting.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + QCOMPARE(rect->radius(),qreal(5)); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->radius(),qreal(0)); + + QmlPropertyChanges *pc = rect->findChild<QmlPropertyChanges*>("pc1"); + QVERIFY(pc != 0); + delete pc; + + QmlState *state = rect->findChild<QmlState*>(); + QVERIFY(state != 0); + QCOMPARE(state->changes()->count(), 1); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("red")); + QCOMPARE(rect->radius(),qreal(5)); + + delete rect; +} + +void tst_states::deletingState() +{ + QmlEngine engine; + + QmlComponent rectComponent(&engine, SRCDIR "/data/deletingState.qml"); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(rectComponent.create()); + QVERIFY(rect != 0); + + QmlStateGroup *sg = rect->findChild<QmlStateGroup*>(); + QVERIFY(sg != 0); + QVERIFY(sg->findState("blue") != 0); + + sg->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + sg->setState(""); + QCOMPARE(rect->color(),QColor("red")); + + QmlState *state = rect->findChild<QmlState*>(); + QVERIFY(state != 0); + delete state; + + QVERIFY(sg->findState("blue") == 0); + + //### should we warn that state doesn't exist + sg->setState("blue"); + QCOMPARE(rect->color(),QColor("red")); + + delete rect; +} + QTEST_MAIN(tst_states) #include "tst_states.moc" |