diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-05-13 11:56:44 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-05-13 11:56:44 (GMT) |
commit | 3cd4b6e00e3448d880ae2335bd50f70d9a5d0fca (patch) | |
tree | 019c7150eb761c0f3463734a4ccdef1147fd8feb /src | |
parent | b75c6210c7fa225e86d2c4bff239bb050321998d (diff) | |
download | Qt-3cd4b6e00e3448d880ae2335bd50f70d9a5d0fca.zip Qt-3cd4b6e00e3448d880ae2335bd50f70d9a5d0fca.tar.gz Qt-3cd4b6e00e3448d880ae2335bd50f70d9a5d0fca.tar.bz2 |
correctly handle multiple event transitions for same (object,event)
The event filter was not removed at the right time. We now store the
number of active event transitions for a particular (object,event)
and only remove the filtering when the count drops to zero.
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 19 | ||||
-rw-r--r-- | src/corelib/statemachine/qstatemachine_p.h | 2 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 2f620c7..046fbb4 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1407,7 +1407,7 @@ void QStateMachinePrivate::registerEventTransition(QEventTransition *transition) QObjectPrivate *od = QObjectPrivate::get(object); if (!od->eventFilters.contains(q)) object->installEventFilter(q); - qobjectEvents[object].insert(transition->eventType()); + ++qobjectEvents[object][transition->eventType()]; QEventTransitionPrivate::get(transition)->registered = true; #ifdef QSTATEMACHINE_DEBUG qDebug() << q << ": added event transition from" << transition->sourceState() @@ -1422,11 +1422,18 @@ void QStateMachinePrivate::unregisterEventTransition(QEventTransition *transitio if (!QEventTransitionPrivate::get(transition)->registered) return; QObject *object = QEventTransitionPrivate::get(transition)->object; - QSet<QEvent::Type> &events = qobjectEvents[object]; - events.remove(transition->eventType()); - if (events.isEmpty()) { - qobjectEvents.remove(object); - object->removeEventFilter(q); + QHash<QEvent::Type, int> &events = qobjectEvents[object]; + Q_ASSERT(events.value(transition->eventType()) > 0); + if (--events[transition->eventType()] == 0) { + events.remove(transition->eventType()); + int sum = 0; + QHash<QEvent::Type, int>::const_iterator it; + for (it = events.constBegin(); it != events.constEnd(); ++it) + sum += it.value(); + if (sum == 0) { + qobjectEvents.remove(object); + object->removeEventFilter(q); + } } QEventTransitionPrivate::get(transition)->registered = false; } diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h index 9b4b861..dfa5575 100644 --- a/src/corelib/statemachine/qstatemachine_p.h +++ b/src/corelib/statemachine/qstatemachine_p.h @@ -200,7 +200,7 @@ public: QHash<const QObject*, QVector<int> > connections; #ifndef QT_NO_STATEMACHINE_EVENTFILTER - QHash<QObject*, QSet<QEvent::Type> > qobjectEvents; + QHash<QObject*, QHash<QEvent::Type, int> > qobjectEvents; #endif QHash<int, QEvent*> delayedEvents; |