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/statemachine/pingpong | |
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/statemachine/pingpong')
-rw-r--r-- | examples/statemachine/pingpong/main.cpp | 31 |
1 files changed, 10 insertions, 21 deletions
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); |