diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-05-05 16:17:43 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-05-05 16:17:43 (GMT) |
commit | 2e0430832d3656753f73b09765769d10aa51add3 (patch) | |
tree | 04c9fa068c57b90de15ebd01831a0e140b2b8e6c /examples/statemachine | |
parent | 6eae8aedd14acbc4ea73f336124b0243e9ebb9c0 (diff) | |
download | Qt-2e0430832d3656753f73b09765769d10aa51add3.zip Qt-2e0430832d3656753f73b09765769d10aa51add3.tar.gz Qt-2e0430832d3656753f73b09765769d10aa51add3.tar.bz2 |
add event as argument to onEntry(), onExit() and onTransition()
Accessing the event can be useful. E.g., onEntry() can do some
common event processing regardless of which transition caused the
state to be entered; onTransition() can be used in combination
with eventTest(), where eventTest() would first check that the
input matches some criteria, and then the actual processing of that
input would be done in onTransition.
Diffstat (limited to 'examples/statemachine')
8 files changed, 16 insertions, 16 deletions
diff --git a/examples/statemachine/clockticking/main.cpp b/examples/statemachine/clockticking/main.cpp index 9b54f29..ea8e692 100644 --- a/examples/statemachine/clockticking/main.cpp +++ b/examples/statemachine/clockticking/main.cpp @@ -61,7 +61,7 @@ public: : QState(parent) {} protected: - virtual void onEntry() + virtual void onEntry(QEvent *) { fprintf(stdout, "ClockState entered; posting the initial tick\n"); machine()->postEvent(new ClockEvent()); @@ -77,7 +77,7 @@ protected: virtual bool eventTest(QEvent *e) const { return (e->type() == QEvent::User+2); } - virtual void onTransition() + virtual void onTransition(QEvent *) { fprintf(stdout, "ClockTransition triggered; posting another tick with a delay of 1 second\n"); machine()->postEvent(new ClockEvent(), 1000); @@ -93,7 +93,7 @@ protected: virtual bool eventTest(QEvent *e) const { return (e->type() == QEvent::User+2); } - virtual void onTransition() + virtual void onTransition(QEvent *) { fprintf(stdout, "ClockListener heard a tick!\n"); } diff --git a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h index d3670bd..3db464b 100644 --- a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h +++ b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h @@ -21,7 +21,7 @@ signals: void turnSelected(); protected: - void onEntry() + void onEntry(QEvent *) { int rand = qrand() % 4; switch (rand) { @@ -45,7 +45,7 @@ signals: void distanceComputed(qreal distance); protected: - void onEntry() + void onEntry(QEvent *) { emit distanceComputed(qreal(qrand() % 180)); } diff --git a/examples/statemachine/errorstateplugins/seek_ai/seek_ai.h b/examples/statemachine/errorstateplugins/seek_ai/seek_ai.h index 83f50a7..7d8aa68 100644 --- a/examples/statemachine/errorstateplugins/seek_ai/seek_ai.h +++ b/examples/statemachine/errorstateplugins/seek_ai/seek_ai.h @@ -48,13 +48,13 @@ signals: void nearestObstacleStraightAhead(); protected: - void onEntry() + void onEntry(QEvent *) { connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle())); turnAlittle(); } - void onExit() + void onExit(QEvent *) { disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(turnAlittle())); disconnect(m_tank, SIGNAL(actionCompleted()), this, SLOT(nearestObstacleStraightAhead())); @@ -89,7 +89,7 @@ protected: return QSignalTransition::eventTest(event); } - void onTransition() + void onTransition(QEvent *) { qreal currentDirection = m_tank->property("direction").toDouble(); qreal angleOfWall = m_lastLine.angle(); diff --git a/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h b/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h index 309ba14..4b4629c 100644 --- a/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h +++ b/examples/statemachine/errorstateplugins/spin_ai/spin_ai.h @@ -22,7 +22,7 @@ public slots: } protected: - void onEntry() + void onEntry(QEvent *) { connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); spin(); diff --git a/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h b/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h index fa06d10..9a96a8b 100644 --- a/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h +++ b/examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h @@ -22,7 +22,7 @@ public slots: } protected: - void onEntry() + void onEntry(QEvent *) { connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin())); spin(); diff --git a/examples/statemachine/factorial/main.cpp b/examples/statemachine/factorial/main.cpp index 9e39ced..2b63690 100644 --- a/examples/statemachine/factorial/main.cpp +++ b/examples/statemachine/factorial/main.cpp @@ -104,7 +104,7 @@ public: return m_fact->property("x").toInt() > 1; } - virtual void onTransition() + virtual void onTransition(QEvent *) { int x = m_fact->property("x").toInt(); int fac = m_fact->property("fac").toInt(); @@ -128,7 +128,7 @@ public: return m_fact->property("x").toInt() <= 1; } - virtual void onTransition() + virtual void onTransition(QEvent *) { fprintf(stdout, "%d\n", m_fact->property("fac").toInt()); } diff --git a/examples/statemachine/helloworld/main.cpp b/examples/statemachine/helloworld/main.cpp index 13486d4..fbe34b5 100644 --- a/examples/statemachine/helloworld/main.cpp +++ b/examples/statemachine/helloworld/main.cpp @@ -52,7 +52,7 @@ public: S0(QState *parent = 0) : QState(parent) {} - virtual void onEntry() + virtual void onEntry(QEvent *) { fprintf(stdout, "Hello world!\n"); } diff --git a/examples/statemachine/pingpong/main.cpp b/examples/statemachine/pingpong/main.cpp index 68f7115..eb8fd5d 100644 --- a/examples/statemachine/pingpong/main.cpp +++ b/examples/statemachine/pingpong/main.cpp @@ -68,7 +68,7 @@ public: : QState(parent) {} protected: - virtual void onEntry() + virtual void onEntry(QEvent *) { machine()->postEvent(new PingEvent()); fprintf(stdout, "ping?\n"); @@ -84,7 +84,7 @@ protected: virtual bool eventTest(QEvent *e) const { return (e->type() == QEvent::User+3); } - virtual void onTransition() + virtual void onTransition(QEvent *) { machine()->postEvent(new PingEvent(), 500); fprintf(stdout, "ping?\n"); @@ -100,7 +100,7 @@ protected: virtual bool eventTest(QEvent *e) const { return (e->type() == QEvent::User+2); } - virtual void onTransition() + virtual void onTransition(QEvent *) { machine()->postEvent(new PongEvent(), 500); fprintf(stdout, "pong!\n"); |