summaryrefslogtreecommitdiffstats
path: root/examples/statemachine
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-07-22 13:10:35 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-07-22 13:23:06 (GMT)
commit1a55f40b6223511d0eb388064597ab38a0d37627 (patch)
tree522d9fafe3bef5049b75471b266ab2f614dfa412 /examples/statemachine
parentdf2a1de1720476d096ad9be0a8cf5a0410206d82 (diff)
downloadQt-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/statemachine')
-rw-r--r--examples/statemachine/factorial/main.cpp4
-rw-r--r--examples/statemachine/tankgame/mainwindow.cpp6
2 files changed, 5 insertions, 5 deletions
diff --git a/examples/statemachine/factorial/main.cpp b/examples/statemachine/factorial/main.cpp
index 18a9521..5050347 100644
--- a/examples/statemachine/factorial/main.cpp
+++ b/examples/statemachine/factorial/main.cpp
@@ -151,14 +151,14 @@ int main(int argc, char **argv)
//! [3]
//! [4]
- QState *compute = new QState(machine.rootState());
+ QState *compute = new QState(&machine);
compute->assignProperty(&factorial, "fac", 1);
compute->assignProperty(&factorial, "x", 6);
compute->addTransition(new FactorialLoopTransition(&factorial));
//! [4]
//! [5]
- QFinalState *done = new QFinalState(machine.rootState());
+ QFinalState *done = new QFinalState(&machine);
FactorialDoneTransition *doneTransition = new FactorialDoneTransition(&factorial);
doneTransition->setTargetState(done);
compute->addTransition(doneTransition);
diff --git a/examples/statemachine/tankgame/mainwindow.cpp b/examples/statemachine/tankgame/mainwindow.cpp
index 68a8d68..596cdfe 100644
--- a/examples/statemachine/tankgame/mainwindow.cpp
+++ b/examples/statemachine/tankgame/mainwindow.cpp
@@ -160,7 +160,7 @@ void MainWindow::init()
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
m_machine = new QStateMachine(this);
- QState *stoppedState = new QState(m_machine->rootState());
+ QState *stoppedState = new QState(m_machine);
stoppedState->setObjectName("stoppedState");
stoppedState->assignProperty(runGameAction, "enabled", true);
stoppedState->assignProperty(stopGameAction, "enabled", false);
@@ -188,14 +188,14 @@ void MainWindow::init()
stoppedState->setInitialState(hs);
//! [0]
- m_runningState = new QState(QState::ParallelStates, m_machine->rootState());
+ m_runningState = new QState(QState::ParallelStates, m_machine);
//! [0]
m_runningState->setObjectName("runningState");
m_runningState->assignProperty(addTankAction, "enabled", false);
m_runningState->assignProperty(runGameAction, "enabled", false);
m_runningState->assignProperty(stopGameAction, "enabled", true);
- QState *gameOverState = new QState(m_machine->rootState());
+ QState *gameOverState = new QState(m_machine);
gameOverState->setObjectName("gameOverState");
gameOverState->assignProperty(stopGameAction, "enabled", false);
connect(gameOverState, SIGNAL(entered()), this, SLOT(gameOver()));