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/sub-attaq/submarine.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/sub-attaq/submarine.cpp')
-rw-r--r-- | examples/animation/sub-attaq/submarine.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp index 04b7916..78a9539 100644 --- a/examples/animation/sub-attaq/submarine.cpp +++ b/examples/animation/sub-attaq/submarine.cpp @@ -115,7 +115,7 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * QStateMachine *machine = new QStateMachine(this); //This state is when the boat is moving/rotating - QState *moving = new QState(machine->rootState()); + QState *moving = new QState(machine); //This state is when the boat is moving from left to right MovementState *movement = new MovementState(this, moving); @@ -132,7 +132,7 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * machine->setInitialState(moving); //End - QFinalState *final = new QFinalState(machine->rootState()); + QFinalState *final = new QFinalState(machine); //If the moving animation is finished we move to the return state movement->addTransition(movement, SIGNAL(animationFinished()), rotation); @@ -141,7 +141,7 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem * rotation->addTransition(rotation, SIGNAL(animationFinished()), movement); //This state play the destroyed animation - QAnimationState *destroyedState = new QAnimationState(machine->rootState()); + QAnimationState *destroyedState = new QAnimationState(machine); destroyedState->setAnimation(setupDestroyAnimation(this)); //Play a nice animation when the submarine is destroyed |