diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-05-22 14:19:21 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-05-22 14:19:21 (GMT) |
commit | 24d798694b794732240e85fa65b958b8c97cbef5 (patch) | |
tree | 050fba2c7812e0721c7628c75ee11bc16dd8232b /src/corelib | |
parent | 74d54eeabcd648ee5100853299de8af5ac4b36f2 (diff) | |
download | Qt-24d798694b794732240e85fa65b958b8c97cbef5.zip Qt-24d798694b794732240e85fa65b958b8c97cbef5.tar.gz Qt-24d798694b794732240e85fa65b958b8c97cbef5.tar.bz2 |
make sure event transition is correctly unregistered/re-registered
When the eventType or eventObject is changed while the state is active,
the transition needs to be unregistered _before_ either property is
changed, only _then_ can it be re-registered.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/statemachine/qeventtransition.cpp | 29 | ||||
-rw-r--r-- | src/corelib/statemachine/qeventtransition_p.h | 3 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/corelib/statemachine/qeventtransition.cpp b/src/corelib/statemachine/qeventtransition.cpp index 74eb577..f25d821 100644 --- a/src/corelib/statemachine/qeventtransition.cpp +++ b/src/corelib/statemachine/qeventtransition.cpp @@ -111,19 +111,20 @@ QEventTransitionPrivate *QEventTransitionPrivate::get(QEventTransition *q) return q->d_func(); } -void QEventTransitionPrivate::invalidate() +void QEventTransitionPrivate::unregister() { Q_Q(QEventTransition); - if (registered) { - QState *source = sourceState(); - QStatePrivate *source_d = QStatePrivate::get(source); - QStateMachinePrivate *mach = QStateMachinePrivate::get(source_d->machine()); - if (mach) { - mach->unregisterEventTransition(q); - if (mach->configuration.contains(source)) - mach->registerEventTransition(q); - } - } + if (!registered || !machine()) + return; + QStateMachinePrivate::get(machine())->unregisterEventTransition(q); +} + +void QEventTransitionPrivate::maybeRegister() +{ + Q_Q(QEventTransition); + if (!machine() || !machine()->configuration().contains(sourceState())) + return; + QStateMachinePrivate::get(machine())->registerEventTransition(q); } /*! @@ -223,8 +224,9 @@ void QEventTransition::setEventType(QEvent::Type type) Q_D(QEventTransition); if (d->eventType == type) return; + d->unregister(); d->eventType = type; - d->invalidate(); + d->maybeRegister(); } /*! @@ -245,8 +247,9 @@ void QEventTransition::setEventObject(QObject *object) Q_D(QEventTransition); if (d->object == object) return; + d->unregister(); d->object = object; - d->invalidate(); + d->maybeRegister(); } /*! diff --git a/src/corelib/statemachine/qeventtransition_p.h b/src/corelib/statemachine/qeventtransition_p.h index fca8c0d..600cec0 100644 --- a/src/corelib/statemachine/qeventtransition_p.h +++ b/src/corelib/statemachine/qeventtransition_p.h @@ -66,7 +66,8 @@ public: static QEventTransitionPrivate *get(QEventTransition *q); - void invalidate(); + void unregister(); + void maybeRegister(); bool registered; QObject *object; |