for (int ii = 0; ii < reverting.count(); ++ii) {
for (int jj = 0; jj < revertList.count(); ++jj) {
- if (revertList.at(jj).property() == reverting.at(ii)) {
+ const QDeclarativeRevertAction &revert = reverting.at(ii);
+ const QDeclarativeSimpleAction &simple = revertList.at(jj);
+ if ((revert.event && simple.event() == revert.event) ||
+ simple.property() == revert.property) {
revertList.removeAt(jj);
break;
}
a.event->saveCurrentValues();
applyList << a;
// Store these special reverts in the reverting list
- d->reverting << d->revertList.at(ii).property();
+ if (a.event)
+ d->reverting << a.event;
+ else
+ d->reverting << a.property;
}
}
// All the local reverts now become part of the ongoing revertList
bool m_reverseEvent;
};
+class QDeclarativeRevertAction
+{
+public:
+ QDeclarativeRevertAction() : event(0) {}
+ QDeclarativeRevertAction(const QDeclarativeProperty &prop) : property(prop), event(0) {}
+ QDeclarativeRevertAction(QDeclarativeActionEvent *e) : event(e) {}
+ QDeclarativeProperty property;
+ QDeclarativeActionEvent *event;
+};
+
class QDeclarativeStateOperationPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeStateOperation)
QDeclarativeTransitionManager transitionManager;
SimpleActionList revertList;
- QList<QDeclarativeProperty> reverting;
+ QList<QDeclarativeRevertAction> reverting;
QString extends;
mutable bool inState;
QDeclarativeStateGroup *group;
--- /dev/null
+import QtQuick 2.0
+
+Rectangle {
+ width: 400; height: 400
+
+ property Item targetItem: rect1
+
+ function switchTargetItem() {
+ if (targetItem === rect1)
+ targetItem = rect2;
+ else
+ targetItem = rect1;
+ }
+
+ states: State {
+ name: "reparented"
+ ParentChange {
+ target: targetItem
+ parent: newParent
+ x: 0; y: 0
+ }
+ }
+
+ Item {
+ objectName: "originalParent1"
+ Rectangle {
+ id: rect1; objectName: "rect1"
+ width: 50; height: 50
+ color: "green"
+ }
+ }
+
+ Item {
+ objectName: "originalParent2"
+ Rectangle {
+ id: rect2; objectName: "rect2"
+ x: 50; y: 50
+ width: 50; height: 50
+ color: "green"
+ }
+ }
+
+ Item {
+ id: newParent; objectName: "newParent"
+ x: 200; y: 100
+ }
+}
void editProperties();
void QTBUG_14830();
void avoidFastForward();
+ void revertListBug();
};
void tst_qdeclarativestates::initTestCase()
QCOMPARE(rect->property("updateCount").toInt(), 1);
}
+//QTBUG-22583
+void tst_qdeclarativestates::revertListBug()
+{
+ QDeclarativeEngine engine;
+
+ QDeclarativeComponent c(&engine, TESTDATA("revertListBug.qml"));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(c.create());
+ QVERIFY(rect != 0);
+
+ QQuickRectangle *rect1 = rect->findChild<QQuickRectangle*>("rect1");
+ QQuickRectangle *rect2 = rect->findChild<QQuickRectangle*>("rect2");
+ QQuickItem *origParent1 = rect->findChild<QQuickItem*>("originalParent1");
+ QQuickItem *origParent2 = rect->findChild<QQuickItem*>("originalParent2");
+ QQuickItem *newParent = rect->findChild<QQuickItem*>("newParent");
+
+ QCOMPARE(rect1->parentItem(), origParent1);
+ QCOMPARE(rect2->parentItem(), origParent2);
+
+ QQuickItemPrivate *rectPrivate = QQuickItemPrivate::get(rect);
+ rectPrivate->setState("reparented");
+
+ QCOMPARE(rect1->parentItem(), newParent);
+ QCOMPARE(rect2->parentItem(), origParent2);
+
+ rectPrivate->setState("");
+
+ QCOMPARE(rect1->parentItem(), origParent1);
+ QCOMPARE(rect2->parentItem(), origParent2);
+
+ QMetaObject::invokeMethod(rect, "switchTargetItem");
+
+ rectPrivate->setState("reparented");
+
+ QCOMPARE(rect1->parentItem(), origParent1);
+ QCOMPARE(rect2->parentItem(), newParent);
+
+ rectPrivate->setState("");
+
+ QCOMPARE(rect1->parentItem(), origParent1);
+ QCOMPARE(rect2->parentItem(), origParent2); //QTBUG-22583 causes rect2's parent item to be origParent1
+}
+
QTEST_MAIN(tst_qdeclarativestates)
#include "tst_qdeclarativestates.moc"