diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-04-28 12:05:15 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-04-29 06:29:47 (GMT) |
commit | 2c22f8748f62db3cd4c2782abcd19c273f4a4426 (patch) | |
tree | 7042ed9d22fc694aca7651d938496a16c369a58e /examples | |
parent | 6293521a6e5ee0ce010180a40e6fda3ef3a8b245 (diff) | |
download | Qt-2c22f8748f62db3cd4c2782abcd19c273f4a4426.zip Qt-2c22f8748f62db3cd4c2782abcd19c273f4a4426.tar.gz Qt-2c22f8748f62db3cd4c2782abcd19c273f4a4426.tar.bz2 |
say hello (again) to QAbstract{State,Transition}::machine()
It's useful and it's simple for us to expose, so let's.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/statemachine/clockticking/main.cpp | 24 | ||||
-rw-r--r-- | examples/statemachine/pingpong/main.cpp | 31 |
2 files changed, 18 insertions, 37 deletions
diff --git a/examples/statemachine/clockticking/main.cpp b/examples/statemachine/clockticking/main.cpp index 5501e2c..301060b 100644 --- a/examples/statemachine/clockticking/main.cpp +++ b/examples/statemachine/clockticking/main.cpp @@ -57,25 +57,21 @@ public: class ClockState : public QState { public: - ClockState(QStateMachine *machine, QState *parent) - : QState(parent), m_machine(machine) {} + ClockState(QState *parent) + : QState(parent) {} protected: virtual void onEntry() { fprintf(stdout, "ClockState entered; posting the initial tick\n"); - m_machine->postEvent(new ClockEvent()); + machine()->postEvent(new ClockEvent()); } - -private: - QStateMachine *m_machine; }; class ClockTransition : public QAbstractTransition { public: - ClockTransition(QStateMachine *machine) - : QAbstractTransition(), m_machine(machine) { } + ClockTransition() {} protected: virtual bool eventTest(QEvent *e) const { @@ -84,18 +80,14 @@ protected: virtual void onTransition() { fprintf(stdout, "ClockTransition triggered; posting another tick with a delay of 1 second\n"); - m_machine->postEvent(new ClockEvent(), 1000); + machine()->postEvent(new ClockEvent(), 1000); } - -private: - QStateMachine *m_machine; }; class ClockListener : public QAbstractTransition { public: - ClockListener() - : QAbstractTransition() {} + ClockListener() {} protected: virtual bool eventTest(QEvent *e) const { @@ -115,9 +107,9 @@ int main(int argc, char **argv) QState *group = new QState(QState::ParallelGroup); group->setObjectName("group"); - ClockState *clock = new ClockState(&machine, group); + ClockState *clock = new ClockState(group); clock->setObjectName("clock"); - clock->addTransition(new ClockTransition(&machine)); + clock->addTransition(new ClockTransition()); QState *listener = new QState(group); listener->setObjectName("listener"); diff --git a/examples/statemachine/pingpong/main.cpp b/examples/statemachine/pingpong/main.cpp index 00ff643..ec1ebf2 100644 --- a/examples/statemachine/pingpong/main.cpp +++ b/examples/statemachine/pingpong/main.cpp @@ -64,25 +64,21 @@ public: class Pinger : public QState { public: - Pinger(QStateMachine *machine, QState *parent) - : QState(parent), m_machine(machine) {} + Pinger(QState *parent) + : QState(parent) {} protected: virtual void onEntry() { - m_machine->postEvent(new PingEvent()); + machine()->postEvent(new PingEvent()); fprintf(stdout, "ping?\n"); } - -private: - QStateMachine *m_machine; }; class PongTransition : public QAbstractTransition { public: - PongTransition(QStateMachine *machine) - : QAbstractTransition(), m_machine(machine) {} + PongTransition() {} protected: virtual bool eventTest(QEvent *e) const { @@ -90,19 +86,15 @@ protected: } virtual void onTransition() { - m_machine->postEvent(new PingEvent(), 500); + machine()->postEvent(new PingEvent(), 500); fprintf(stdout, "ping?\n"); } - -private: - QStateMachine *m_machine; }; class PingTransition : public QAbstractTransition { public: - PingTransition(QStateMachine *machine) - : QAbstractTransition(), m_machine(machine) {} + PingTransition() {} protected: virtual bool eventTest(QEvent *e) const { @@ -110,12 +102,9 @@ protected: } virtual void onTransition() { - m_machine->postEvent(new PongEvent(), 500); + machine()->postEvent(new PongEvent(), 500); fprintf(stdout, "pong!\n"); } - -private: - QStateMachine *m_machine; }; int main(int argc, char **argv) @@ -126,13 +115,13 @@ int main(int argc, char **argv) QState *group = new QState(QState::ParallelGroup); group->setObjectName("group"); - Pinger *pinger = new Pinger(&machine, group); + Pinger *pinger = new Pinger(group); pinger->setObjectName("pinger"); - pinger->addTransition(new PongTransition(&machine)); + pinger->addTransition(new PongTransition()); QState *ponger = new QState(group); ponger->setObjectName("ponger"); - ponger->addTransition(new PingTransition(&machine)); + ponger->addTransition(new PingTransition()); machine.addState(group); machine.setInitialState(group); |