diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-22 13:10:35 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-22 13:23:06 (GMT) |
commit | 1a55f40b6223511d0eb388064597ab38a0d37627 (patch) | |
tree | 522d9fafe3bef5049b75471b266ab2f614dfa412 /examples/animation/moveblocks/main.cpp | |
parent | df2a1de1720476d096ad9be0a8cf5a0410206d82 (diff) | |
download | Qt-1a55f40b6223511d0eb388064597ab38a0d37627.zip Qt-1a55f40b6223511d0eb388064597ab38a0d37627.tar.gz Qt-1a55f40b6223511d0eb388064597ab38a0d37627.tar.bz2 |
Make QStateMachine inherit QState
This removes the need for a "root state" in the machine; or rather,
the machine _is_ the root state.
User code can now pass in a QStateMachine directly to the QState
constructor, instead of machine->rootState().
This also means we could get rid of the "proxying" from the machine
to the root state for things like properties (initialState et al),
finished() signal and auto-reparenting of states (the ChildAdded
event hack).
A fun little side-effect of this change is that it's now possible
to embed state machines within state machines. We can't think of
a good use case yet where you would rather embed a stand-alone
state machine (with its own event processing etc.) rather than
having just a regular nested state, but it's neat and it works.
Reviewed-by: Eskil Abrahamsen Blomfeldt
Diffstat (limited to 'examples/animation/moveblocks/main.cpp')
-rw-r--r-- | examples/animation/moveblocks/main.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp index c43e841..97d3f81 100644 --- a/examples/animation/moveblocks/main.cpp +++ b/examples/animation/moveblocks/main.cpp @@ -108,8 +108,7 @@ class StateSwitcher : public QState Q_OBJECT public: StateSwitcher(QStateMachine *machine) - : QState(machine->rootState()), m_machine(machine), - m_stateCount(0), m_lastIndex(0) + : QState(machine), m_stateCount(0), m_lastIndex(0) { } //![10] @@ -120,7 +119,7 @@ public: while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex) { } m_lastIndex = n; - m_machine->postEvent(new StateSwitchEvent(n)); + machine()->postEvent(new StateSwitchEvent(n)); } virtual void onExit(QEvent *) {} //![11] @@ -135,7 +134,6 @@ public: //![12] private: - QStateMachine *m_machine; int m_stateCount; int m_lastIndex; }; |