diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-04-27 15:38:01 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-04-27 15:38:01 (GMT) |
commit | 53e8c64d0ed050bc195bb4851da2f6d65b5c8ca5 (patch) | |
tree | 54dcb7def96e89ab788d565dcf9d2df07196747b /src/corelib/statemachine/qstatemachine.cpp | |
parent | af4f0170810efeb071e6e9dac0df6a84962e9806 (diff) | |
download | Qt-53e8c64d0ed050bc195bb4851da2f6d65b5c8ca5.zip Qt-53e8c64d0ed050bc195bb4851da2f6d65b5c8ca5.tar.gz Qt-53e8c64d0ed050bc195bb4851da2f6d65b5c8ca5.tar.bz2 |
make the entry/exit order well-defined for all combinations of states
Comparing pointers meant that the order could be different each run.
Now the entry/exit order will be consistent, even for states that are
in disjoint parts of the hierarchy.
Diffstat (limited to 'src/corelib/statemachine/qstatemachine.cpp')
-rw-r--r-- | src/corelib/statemachine/qstatemachine.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 2d3eea1..8cee1fc 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -234,6 +234,18 @@ Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler() return &qt_kernel_statemachine_handler; } +static int indexOfDescendant(QState *s, QAbstractState *desc) +{ + QList<QAbstractState*> childStates = QStatePrivate::get(s)->childStates(); + for (int i = 0; i < childStates.size(); ++i) { + QAbstractState *c = childStates.at(i); + if ((c == desc) || QStateMachinePrivate::isDescendantOf(desc, c)) { + return i; + } + } + return -1; +} + bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState *s2) { if (s1->parent() == s2->parent()) { @@ -244,8 +256,9 @@ bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState } else if (isDescendantOf(s2, s1)) { return true; } else { - // ### fixme - return s1 < s2; + QState *lca = findLCA(QList<QAbstractState*>() << s1 << s2); + Q_ASSERT(lca != 0); + return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2)); } } @@ -259,8 +272,9 @@ bool QStateMachinePrivate::stateExitLessThan(QAbstractState *s1, QAbstractState } else if (isDescendantOf(s2, s1)) { return false; } else { - // ### fixme - return s2 < s1; + QState *lca = findLCA(QList<QAbstractState*>() << s1 << s2); + Q_ASSERT(lca != 0); + return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2)); } } |