From 9816567056c93f193c8d86d8e3cc8e22695b6642 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 28 Jul 2009 13:25:11 +1000 Subject: Fix ParentChange in states. Make sure we can override when necessary. --- src/declarative/util/qmlstate.cpp | 28 +++++++++++++++++++++++----- src/declarative/util/qmlstate.h | 1 + src/declarative/util/qmlstateoperations.cpp | 10 ++++++++++ src/declarative/util/qmlstateoperations.h | 1 + 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/declarative/util/qmlstate.cpp b/src/declarative/util/qmlstate.cpp index c41c31a..af60a6f 100644 --- a/src/declarative/util/qmlstate.cpp +++ b/src/declarative/util/qmlstate.cpp @@ -110,6 +110,11 @@ void ActionEvent::clearReverseBindings() { } +bool ActionEvent::override(ActionEvent *other) +{ + return false; +} + /*! \internal */ @@ -378,13 +383,15 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever if (action.event) { if (!action.event->isReversable()) continue; - /*for (jj = 0; jj < d->revertList.count(); ++jj) { + for (jj = 0; jj < d->revertList.count(); ++jj) { ActionEvent *event = d->revertList.at(jj).event; if (event && event->typeName() == action.event->typeName()) { - found = true; - break; + if (action.event->override(event)) { + found = true; + break; + } } - }*/ //### not a close enough match + } } else { action.fromBinding = action.property.binding(); @@ -417,7 +424,18 @@ void QmlState::apply(QmlStateGroup *group, QmlTransition *trans, QmlState *rever // into this state need to be translated into apply actions for (int ii = 0; ii < d->revertList.count(); ++ii) { bool found = false; - if (!d->revertList.at(ii).event) { //### corresponding test for events? + if (d->revertList.at(ii).event) { + ActionEvent *event = d->revertList.at(ii).event; + if (!event->isReversable()) + continue; + for (int jj = 0; !found && jj < applyList.count(); ++jj) { + const Action &action = applyList.at(jj); + if (action.event && action.event->typeName() == event->typeName()) { + if (action.event->override(event)) + found = true; + } + } + } else { for (int jj = 0; !found && jj < applyList.count(); ++jj) { const Action &action = applyList.at(jj); if (action.property == d->revertList.at(ii).property) diff --git a/src/declarative/util/qmlstate.h b/src/declarative/util/qmlstate.h index 7b3021b..7c62768 100644 --- a/src/declarative/util/qmlstate.h +++ b/src/declarative/util/qmlstate.h @@ -96,6 +96,7 @@ public: virtual bool changesBindings(); virtual void clearForwardBindings(); virtual void clearReverseBindings(); + virtual bool override(ActionEvent*other); }; class QmlStateGroup; diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index e2cbae4..3d03c34 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -202,6 +202,16 @@ QString QmlParentChange::typeName() const return QLatin1String("ParentChange"); } +bool QmlParentChange::override(ActionEvent*other) +{ + Q_D(QmlParentChange); + if (other->typeName() != QLatin1String("ParentChange")) + return false; + if (QmlParentChange *otherPC = static_cast(other)) + return (d->target == otherPC->object()); + return false; +} + class QmlRunScriptPrivate : public QObjectPrivate { public: diff --git a/src/declarative/util/qmlstateoperations.h b/src/declarative/util/qmlstateoperations.h index f595e16..4bd17a0 100644 --- a/src/declarative/util/qmlstateoperations.h +++ b/src/declarative/util/qmlstateoperations.h @@ -76,6 +76,7 @@ public: virtual bool isReversable(); virtual void reverse(); virtual QString typeName() const; + virtual bool override(ActionEvent*other); }; class QmlRunScriptPrivate; -- cgit v0.12