diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-05-22 14:31:40 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-05-22 14:31:40 (GMT) |
commit | 1602820bb4d2b13f843594194ace2186f4f72806 (patch) | |
tree | b00d38441edb1029b6e9f59f298c24785519c7ba /src | |
parent | 24d798694b794732240e85fa65b958b8c97cbef5 (diff) | |
download | Qt-1602820bb4d2b13f843594194ace2186f4f72806.zip Qt-1602820bb4d2b13f843594194ace2186f4f72806.tar.gz Qt-1602820bb4d2b13f843594194ace2186f4f72806.tar.bz2 |
make sure signal transition is correctly unregistered/re-registered
When the signal or senderObject 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')
-rw-r--r-- | src/corelib/statemachine/qsignaltransition.cpp | 29 | ||||
-rw-r--r-- | src/corelib/statemachine/qsignaltransition_p.h | 3 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/corelib/statemachine/qsignaltransition.cpp b/src/corelib/statemachine/qsignaltransition.cpp index 4caa917..9ffcb9c 100644 --- a/src/corelib/statemachine/qsignaltransition.cpp +++ b/src/corelib/statemachine/qsignaltransition.cpp @@ -118,19 +118,20 @@ QSignalTransitionPrivate *QSignalTransitionPrivate::get(QSignalTransition *q) return q->d_func(); } -void QSignalTransitionPrivate::invalidate() +void QSignalTransitionPrivate::unregister() { Q_Q(QSignalTransition); - if (signalIndex != -1) { - QState *source = sourceState(); - QStatePrivate *source_d = QStatePrivate::get(source); - QStateMachinePrivate *mach = QStateMachinePrivate::get(source_d->machine()); - if (mach) { - mach->unregisterSignalTransition(q); - if (mach->configuration.contains(source)) - mach->registerSignalTransition(q); - } - } + if ((signalIndex == -1) || !machine()) + return; + QStateMachinePrivate::get(machine())->unregisterSignalTransition(q); +} + +void QSignalTransitionPrivate::maybeRegister() +{ + Q_Q(QSignalTransition); + if (!machine() || !machine()->configuration().contains(sourceState())) + return; + QStateMachinePrivate::get(machine())->registerSignalTransition(q); } /*! @@ -193,8 +194,9 @@ void QSignalTransition::setSenderObject(QObject *sender) Q_D(QSignalTransition); if (sender == d->sender) return; + d->unregister(); d->sender = sender; - d->invalidate(); + d->maybeRegister(); } /*! @@ -214,8 +216,9 @@ void QSignalTransition::setSignal(const QByteArray &signal) Q_D(QSignalTransition); if (signal == d->signal) return; + d->unregister(); d->signal = signal; - d->invalidate(); + d->maybeRegister(); } /*! diff --git a/src/corelib/statemachine/qsignaltransition_p.h b/src/corelib/statemachine/qsignaltransition_p.h index a23e58c..339de63 100644 --- a/src/corelib/statemachine/qsignaltransition_p.h +++ b/src/corelib/statemachine/qsignaltransition_p.h @@ -66,7 +66,8 @@ public: static QSignalTransitionPrivate *get(QSignalTransition *q); - void invalidate(); + void unregister(); + void maybeRegister(); QObject *sender; QByteArray signal; |