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 | |
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.
-rw-r--r-- | src/corelib/statemachine/qeventtransition.cpp | 29 | ||||
-rw-r--r-- | src/corelib/statemachine/qeventtransition_p.h | 3 | ||||
-rw-r--r-- | tests/auto/qstatemachine/tst_qstatemachine.cpp | 13 |
3 files changed, 31 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; diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 8354d03..a5070cb 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1836,6 +1836,19 @@ void tst_QStateMachine::eventTransitions() QCoreApplication::processEvents(); QTest::mouseRelease(&button, Qt::LeftButton); QTRY_COMPARE(finishedSpy.count(), 2); + + machine.start(); + QCoreApplication::processEvents(); + trans->setEventType(QEvent::MouseButtonPress); + QTest::mousePress(&button, Qt::LeftButton); + QTRY_COMPARE(finishedSpy.count(), 3); + + QPushButton button2; + machine.start(); + QCoreApplication::processEvents(); + trans->setEventObject(&button2); + QTest::mousePress(&button2, Qt::LeftButton); + QTRY_COMPARE(finishedSpy.count(), 4); } for (int x = 0; x < 3; ++x) { QStateMachine machine; |