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 | |
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')
-rw-r--r-- | examples/animation/moveblocks/main.cpp | 6 | ||||
-rw-r--r-- | examples/animation/sub-attaq/boat_p.h | 12 | ||||
-rw-r--r-- | examples/animation/sub-attaq/qanimationstate.cpp | 4 | ||||
-rw-r--r-- | examples/animation/sub-attaq/qanimationstate.h | 4 | ||||
-rw-r--r-- | examples/animation/sub-attaq/states.cpp | 16 | ||||
-rw-r--r-- | examples/animation/sub-attaq/states.h | 14 | ||||
-rw-r--r-- | examples/animation/sub-attaq/submarine_p.h | 12 | ||||
-rw-r--r-- | examples/statemachine/clockticking/main.cpp | 6 | ||||
-rw-r--r-- | examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h | 4 | ||||
-rw-r--r-- | examples/statemachine/errorstateplugins/seek_ai/seek_ai.h | 6 | ||||
-rw-r--r-- | examples/statemachine/errorstateplugins/spin_ai/spin_ai.h | 2 | ||||
-rw-r--r-- | examples/statemachine/errorstateplugins/spin_ai_with_error/spin_ai_with_error.h | 2 | ||||
-rw-r--r-- | examples/statemachine/factorial/main.cpp | 4 | ||||
-rw-r--r-- | examples/statemachine/helloworld/main.cpp | 2 | ||||
-rw-r--r-- | examples/statemachine/pingpong/main.cpp | 6 |
15 files changed, 50 insertions, 50 deletions
diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp index eb23bd5..06ed3dd 100644 --- a/examples/animation/moveblocks/main.cpp +++ b/examples/animation/moveblocks/main.cpp @@ -101,7 +101,7 @@ protected: && (static_cast<StateSwitchEvent *>(event)->rand() == m_rand); } - virtual void onTransition() {} + virtual void onTransition(QEvent *) {} private: int m_rand; @@ -116,7 +116,7 @@ public: m_stateCount(0), m_lastIndex(0) { } - virtual void onEntry() + virtual void onEntry(QEvent *) { int n; while ((n = (qrand() % m_stateCount + 1)) == m_lastIndex) @@ -124,7 +124,7 @@ public: m_lastIndex = n; m_machine->postEvent(new StateSwitchEvent(n)); } - virtual void onExit() {} + virtual void onExit(QEvent *) {} void addState(QState *state, QAbstractAnimation *animation) { StateSwitchTransition *trans = new StateSwitchTransition(++m_stateCount); diff --git a/examples/animation/sub-attaq/boat_p.h b/examples/animation/sub-attaq/boat_p.h index 855b10f..17fbe5c 100644 --- a/examples/animation/sub-attaq/boat_p.h +++ b/examples/animation/sub-attaq/boat_p.h @@ -104,7 +104,7 @@ protected: return false; } - void onTransition() + void onTransition(QEvent *) { //We decrease the speed if needed if (key == Qt::Key_Left && boat->currentDirection() == Boat::Right) @@ -156,7 +156,7 @@ public: this->boat = boat; } protected: - void onEntry() + void onEntry(QEvent *) { boat->setCurrentDirection(Boat::Right); boat->updateBoatMovement(); @@ -174,7 +174,7 @@ public: this->boat = boat; } protected: - void onEntry() + void onEntry(QEvent *) { boat->setCurrentDirection(Boat::Left); boat->updateBoatMovement(); @@ -192,7 +192,7 @@ public: this->boat = boat; } protected: - void onEntry() + void onEntry(QEvent *) { boat->setCurrentSpeed(0); boat->setCurrentDirection(Boat::None); @@ -211,7 +211,7 @@ public: this->boat = boat; } protected: - void onEntry() + void onEntry(QEvent *) { Bomb *b = new Bomb(); b->setPos(boat->x()+boat->size().width(),boat->y()); @@ -233,7 +233,7 @@ public: this->boat = boat; } protected: - void onEntry() + void onEntry(QEvent *) { Bomb *b = new Bomb(); b->setPos(boat->x() - b->size().width(), boat->y()); diff --git a/examples/animation/sub-attaq/qanimationstate.cpp b/examples/animation/sub-attaq/qanimationstate.cpp index 3659657..0f30ac2 100644 --- a/examples/animation/sub-attaq/qanimationstate.cpp +++ b/examples/animation/sub-attaq/qanimationstate.cpp @@ -146,7 +146,7 @@ QAbstractAnimation* QAnimationState::animation() const /*! \reimp */ -void QAnimationState::onEntry() +void QAnimationState::onEntry(QEvent *) { Q_D(QAnimationState); if (d->animation) @@ -156,7 +156,7 @@ void QAnimationState::onEntry() /*! \reimp */ -void QAnimationState::onExit() +void QAnimationState::onExit(QEvent *) { Q_D(QAnimationState); if (d->animation) diff --git a/examples/animation/sub-attaq/qanimationstate.h b/examples/animation/sub-attaq/qanimationstate.h index ddf5681..88c0a6d 100644 --- a/examples/animation/sub-attaq/qanimationstate.h +++ b/examples/animation/sub-attaq/qanimationstate.h @@ -74,8 +74,8 @@ Q_SIGNALS: void animationFinished(); protected: - void onEntry(); - void onExit(); + void onEntry(QEvent *); + void onExit(QEvent *); bool event(QEvent *e); private: diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp index 0b98016..c6af924 100644 --- a/examples/animation/sub-attaq/states.cpp +++ b/examples/animation/sub-attaq/states.cpp @@ -76,7 +76,7 @@ PlayState::~PlayState() { } -void PlayState::onEntry() +void PlayState::onEntry(QEvent *) { //We are now playing? if (machine) { @@ -159,7 +159,7 @@ void PlayState::onEntry() LevelState::LevelState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game) { } -void LevelState::onEntry() +void LevelState::onEntry(QEvent *) { initializeLevel(); } @@ -202,12 +202,12 @@ void LevelState::initializeLevel() PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent),scene(scene) { } -void PauseState::onEntry() +void PauseState::onEntry(QEvent *) { AnimationManager::self()->pauseAll(); scene->boat->setEnabled(false); } -void PauseState::onExit() +void PauseState::onExit(QEvent *) { AnimationManager::self()->resumeAll(); scene->boat->setEnabled(true); @@ -219,7 +219,7 @@ LostState::LostState(GraphicsScene *scene, PlayState *game, QState *parent) : QS { } -void LostState::onEntry() +void LostState::onEntry(QEvent *) { //The message to display QString message = QString("You lose on level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score); @@ -242,7 +242,7 @@ WinState::WinState(GraphicsScene *scene, PlayState *game, QState *parent) : QSta { } -void WinState::onEntry() +void WinState::onEntry(QEvent *) { //We clear the scene scene->clearScene(); @@ -269,9 +269,9 @@ UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(par { this->game = game; } -void UpdateScoreState::onEntry() +void UpdateScoreState::onEntry(QEvent *e) { - QState::onEntry(); + QState::onEntry(e); } /** Win transition */ diff --git a/examples/animation/sub-attaq/states.h b/examples/animation/sub-attaq/states.h index ec69ae7..27beb71 100644 --- a/examples/animation/sub-attaq/states.h +++ b/examples/animation/sub-attaq/states.h @@ -68,7 +68,7 @@ public: ~PlayState(); protected: - void onEntry(); + void onEntry(QEvent *); private : GraphicsScene *scene; @@ -91,7 +91,7 @@ class LevelState : public QState public: LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0); protected: - void onEntry(); + void onEntry(QEvent *); private : void initializeLevel(); GraphicsScene *scene; @@ -104,8 +104,8 @@ public: PauseState(GraphicsScene *scene, QState *parent = 0); protected: - void onEntry(); - void onExit(); + void onEntry(QEvent *); + void onExit(QEvent *); private : GraphicsScene *scene; Boat *boat; @@ -117,7 +117,7 @@ public: LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0); protected: - void onEntry(); + void onEntry(QEvent *); private : GraphicsScene *scene; PlayState *game; @@ -129,7 +129,7 @@ public: WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0); protected: - void onEntry(); + void onEntry(QEvent *); private : GraphicsScene *scene; PlayState *game; @@ -140,7 +140,7 @@ class UpdateScoreState : public QState public: UpdateScoreState(PlayState *game, QState *parent); protected: - void onEntry(); + void onEntry(QEvent *); private: QPropertyAnimation *scoreAnimation; PlayState *game; diff --git a/examples/animation/sub-attaq/submarine_p.h b/examples/animation/sub-attaq/submarine_p.h index 918e7f5..c76d991 100644 --- a/examples/animation/sub-attaq/submarine_p.h +++ b/examples/animation/sub-attaq/submarine_p.h @@ -77,7 +77,7 @@ protected slots: } protected: - void onEntry() + void onEntry(QEvent *e) { if (submarine->currentDirection() == SubMarine::Left) { movementAnimation->setEndValue(QPointF(0,submarine->y())); @@ -88,7 +88,7 @@ protected: movementAnimation->setDuration((submarine->scene()->width()-submarine->size().width()-submarine->x())/submarine->currentSpeed()*12); } movementAnimation->setStartValue(submarine->pos()); - QAnimationState::onEntry(); + QAnimationState::onEntry(e); } private: @@ -109,19 +109,19 @@ public: } protected: - void onEntry() + void onEntry(QEvent *e) { returnAnimation->stop(); returnAnimation->setStartValue(submarine->yRotation()); returnAnimation->setEndValue(submarine->currentDirection() == SubMarine::Right ? 360. : 180.); returnAnimation->setDuration(500); - QAnimationState::onEntry(); + QAnimationState::onEntry(e); } - void onExit() + void onExit(QEvent *e) { submarine->currentDirection() == SubMarine::Right ? submarine->setCurrentDirection(SubMarine::Left) : submarine->setCurrentDirection(SubMarine::Right); - QAnimationState::onExit(); + QAnimationState::onExit(e); } private: 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"); |