From 381e67f03155167cd9c1c0c3c4c3905196f287df Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Tue, 21 Apr 2009 14:53:34 +0200
Subject: compile.
---
tests/auto/qstate/tst_qstate.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp
index f28c3fa..f79fcd4 100644
--- a/tests/auto/qstate/tst_qstate.cpp
+++ b/tests/auto/qstate/tst_qstate.cpp
@@ -9,7 +9,7 @@
#include "qstate.h"
#include "qstatemachine.h"
-#include "qtransition.h"
+#include "qactiontransition.h"
#include "qsignaltransition.h"
#include "qstateaction.h"
@@ -265,11 +265,11 @@ void tst_QState::assignPropertyTwice()
QCOMPARE(object->property("fooBar").toInt(), 30);
}
-class EventTestTransition: public QTransition
+class EventTestTransition: public QActionTransition
{
public:
EventTestTransition(QEvent::Type type, QState *targetState)
- : QTransition(QList() << targetState), m_type(type)
+ : QActionTransition(QList() << targetState), m_type(type)
{
}
--
cgit v0.12
From ae6ab698ea739ac82cc6245742b58c7265ee82f8 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Tue, 21 Apr 2009 15:55:35 +0200
Subject: Have QState::addTransition(QAbstractTransition*) return the
transition object when it is added. Reduces the number of temporary variables
you have to declare in your code since you can do things like:
state->addTransition(new Transition())->addAnimation(new Animation());
Could also be used for error checking.
---
src/corelib/statemachine/qstate.cpp | 9 +++++----
src/corelib/statemachine/qstate.h | 2 +-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index e3da1c5..abd7379 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -247,28 +247,29 @@ void QState::setErrorState(QAbstractState *state)
Adds the given \a transition. The transition has this state as the source.
This state takes ownership of the transition.
*/
-void QState::addTransition(QAbstractTransition *transition)
+QAbstractTransition *QState::addTransition(QAbstractTransition *transition)
{
Q_D(QState);
if (!transition) {
qWarning("QState::addTransition: cannot add null transition");
- return;
+ return 0;
}
const QList &targets = QAbstractTransitionPrivate::get(transition)->targetStates;
for (int i = 0; i < targets.size(); ++i) {
QAbstractState *t = targets.at(i);
if (!t) {
qWarning("QState::addTransition: cannot add transition to null state");
- return;
+ return 0;
}
if ((QAbstractStatePrivate::get(t)->machine() != d->machine())
&& QAbstractStatePrivate::get(t)->machine() && d->machine()) {
qWarning("QState::addTransition: cannot add transition "
"to a state in a different state machine");
- return;
+ return 0;
}
}
transition->setParent(this);
+ return transition;
}
/*!
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
index 4c86e02..1ec0896 100644
--- a/src/corelib/statemachine/qstate.h
+++ b/src/corelib/statemachine/qstate.h
@@ -81,7 +81,7 @@ public:
QAbstractState *errorState() const;
void setErrorState(QAbstractState *state);
- void addTransition(QAbstractTransition *transition);
+ QAbstractTransition *addTransition(QAbstractTransition *transition);
QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target);
QAbstractTransition *addTransition(QAbstractState *target);
QStateFinishedTransition *addFinishedTransition(QAbstractState *target);
--
cgit v0.12
From 750cea0a42bc969913547a7266e8ae16936a7a8c Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Tue, 21 Apr 2009 15:59:21 +0200
Subject: doc: Document return value of
QState::addTransition(QAbstractTransition*)
---
src/corelib/statemachine/qstate.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index abd7379..28c84d5 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -245,7 +245,8 @@ void QState::setErrorState(QAbstractState *state)
/*!
Adds the given \a transition. The transition has this state as the source.
- This state takes ownership of the transition.
+ This state takes ownership of the transition. If the transition is successfully
+ added, the function will return the \a transition pointer. Otherwise it will return null.
*/
QAbstractTransition *QState::addTransition(QAbstractTransition *transition)
{
--
cgit v0.12
From c912281e63b2883e481050f1e246d36e6026100e Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Tue, 21 Apr 2009 17:09:58 +0200
Subject: QAnimationState is no more, so we remove the test for it. The
relevant tests have been ported to the new API and added to the QStateMachine
autotest instead.
---
tests/auto/qanimationstate/qanimationstate.pro | 5 -
tests/auto/qanimationstate/tst_qanimationstate.cpp | 625 ---------------------
tests/auto/qstatemachine/tst_qstatemachine.cpp | 327 +++++++++++
3 files changed, 327 insertions(+), 630 deletions(-)
delete mode 100644 tests/auto/qanimationstate/qanimationstate.pro
delete mode 100644 tests/auto/qanimationstate/tst_qanimationstate.cpp
diff --git a/tests/auto/qanimationstate/qanimationstate.pro b/tests/auto/qanimationstate/qanimationstate.pro
deleted file mode 100644
index 8862c27..0000000
--- a/tests/auto/qanimationstate/qanimationstate.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-load(qttest_p4)
-QT = core
-SOURCES += tst_qanimationstate.cpp
-
-
diff --git a/tests/auto/qanimationstate/tst_qanimationstate.cpp b/tests/auto/qanimationstate/tst_qanimationstate.cpp
deleted file mode 100644
index 085db24..0000000
--- a/tests/auto/qanimationstate/tst_qanimationstate.cpp
+++ /dev/null
@@ -1,625 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-****************************************************************************/
-
-#include
-#include
-#include
-#include
-
-//TESTED_CLASS=QAnimationState
-//TESTED_FILES=
-
-#define QTRY_COMPARE(__expr, __expected) \
- do { \
- const int __step = 50; \
- const int __timeout = 5000; \
- if ((__expr) != (__expected)) { \
- QTest::qWait(0); \
- } \
- for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
- QTest::qWait(__step); \
- } \
- QCOMPARE(__expr, __expected); \
- } while(0)
-
-
-class tst_QAnimationState : public QObject
-{
- Q_OBJECT
-public:
- tst_QAnimationState();
- virtual ~tst_QAnimationState();
-
-private slots:
- void init();
- void cleanup();
- void construction();
- void noAnimation();
- void simpleAnimation();
- void twoAnimations();
- void reuseAnimation();
- void nestedTargetState();
- void parallelTargetState();
- void playTwice();
- void twoAnimatedTransitions();
- void globalRestoreProperty();
- void specificRestoreProperty();
- void someAnimationsNotSpecified();
- void someActionsNotAnimated();
- void specificTargetValueOfAnimation();
- void persistentTargetValueOfAnimation();
-};
-
-tst_QAnimationState::tst_QAnimationState()
-{
-}
-
-tst_QAnimationState::~tst_QAnimationState()
-{
-}
-
-void tst_QAnimationState::init()
-{
-}
-
-void tst_QAnimationState::cleanup()
-{
-}
-
-void tst_QAnimationState::construction()
-{
- QAnimationState as;
-}
-
-class EventTransition : public QTransition
-{
-public:
- EventTransition(QEvent::Type type, QAbstractState *target)
- : QTransition(), m_type(type) {
- setTargetState(target);
- }
-protected:
- virtual bool eventTest(QEvent *e) const {
- return (e->type() == m_type);
- }
-private:
- QEvent::Type m_type;
-};
-
-void tst_QAnimationState::noAnimation()
-{
- QStateMachine machine;
-
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(machine.rootState());
- s2->setProperty("entered", false);
- s2->setPropertyOnEntry(s2, "entered", true);
-
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- s2->addTransition(new EventTransition(QEvent::User, s1));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- QVERIFY(machine.configuration().contains(s1));
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->property("entered").toBool(), true);
- QVERIFY(machine.configuration().contains(s2));
-
- machine.postEvent(new QEvent(QEvent::User));
- QCoreApplication::processEvents();
-
- QVERIFY(machine.configuration().contains(s1));
-
- s2->setProperty("entered", false);
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->property("entered").toBool(), true);
- QVERIFY(machine.configuration().contains(s2));
-}
-
-class ValueCheckerState: public QState
-{
-public:
- ValueCheckerState(QState *parent)
- : QState(parent)
- {
- }
-
- void addPropertyToCheck(const QObject *object, const char *propertyName)
- {
- m_objects.append(object);
- m_propertyNames.append(propertyName);
- valueOnEntry.append(QVariant());
- }
-
- QVariantList valueOnEntry;
-
-protected:
- virtual void onEntry()
- {
- for (int i=0; iproperty(m_propertyNames.at(i));
-
- QState::onEntry();
- }
-
- QList m_objects;
- QList m_propertyNames;
-
-};
-
-void tst_QAnimationState::simpleAnimation()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("fooBar", 1.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "fooBar");
- s2->setPropertyOnEntry(object, "fooBar", 2.0);
-
- QPropertyAnimation *animation = new QPropertyAnimation(object, "fooBar", s2);
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2), animation);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
-
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
-}
-
-void tst_QAnimationState::twoAnimations()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
- s2->setPropertyOnEntry(object, "bar", 10.0);
-
- QPropertyAnimation *animationFoo = new QPropertyAnimation(object, "foo", s2);
- QPropertyAnimation *animationBar = new QPropertyAnimation(object, "bar", s2);
- animationBar->setDuration(900);
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(animationFoo);
- as->addAnimation(animationBar);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
-
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 10.0);
-}
-
-void tst_QAnimationState::parallelTargetState()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(QState::ParallelGroup, machine.rootState());
-
- ValueCheckerState *c1 = new ValueCheckerState(s2);
- c1->setPropertyOnEntry(object, "foo", 2.0);
- c1->addPropertyToCheck(object, "foo");
- c1->addPropertyToCheck(object, "bar");
-
- QState *c2 = new QState(s2);
- c2->setPropertyOnEntry(object, "bar", 10.0);
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(c1->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(c1->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(c1->valueOnEntry.at(1).toDouble(), 10.0);
-}
-
-
-void tst_QAnimationState::twoAnimatedTransitions()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 5.0);
- ValueCheckerState *s3 = new ValueCheckerState(machine.rootState());
- s3->setPropertyOnEntry(object, "foo", 2.0);
- s3->addPropertyToCheck(object, "foo");
-
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2),
- new QPropertyAnimation(object, "foo", s2));
- s2->addAnimatedTransition(new EventTransition(QEvent::User, s3),
- new QPropertyAnimation(object, "foo", s2));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s3->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s3->valueOnEntry.at(0).toDouble(), 2.0);
-}
-
-void tst_QAnimationState::playTwice()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 5.0);
- QState *s3 = new QState(machine.rootState());
- s3->setPropertyOnEntry(object, "foo", 2.0);
-
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2),
- new QPropertyAnimation(object, "foo", s2));
- s2->addTransition(new EventTransition(QEvent::User, s3));
- s3->addTransition(s1);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QCoreApplication::processEvents();
- QVERIFY(machine.configuration().contains(s1));
- QCOMPARE(object->property("foo").toDouble(), 2.0);
-
- s2->valueOnEntry[0] = QVariant();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(object->property("foo").toDouble(), 5.0);
-}
-
-void tst_QAnimationState::nestedTargetState()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- QState *s2Child = new QState(s2);
- s2Child->setPropertyOnEntry(object, "bar", 10.0);
- s2->setInitialState(s2Child);
-
- QState *s2Child2 = new QState(s2);
- s2Child2->setPropertyOnEntry(object, "bar", 11.0);
- s2Child->addTransition(s2Child2); // should *not* be considered by QAnimationState as part of target
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
-
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
-
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 10.0);
- QCOMPARE(object->property("bar").toDouble(), 11.0);
-}
-
-void tst_QAnimationState::reuseAnimation()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 5.0);
- ValueCheckerState *s3 = new ValueCheckerState(machine.rootState());
- s3->setPropertyOnEntry(object, "foo", 2.0);
- s3->addPropertyToCheck(object, "foo");
-
- QPropertyAnimation *anim = new QPropertyAnimation(object, "foo", s2);
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2), anim);
- s2->addAnimatedTransition(new EventTransition(QEvent::User, s3), anim);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s3->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s3->valueOnEntry.at(0).toDouble(), 2.0);
-}
-
-void tst_QAnimationState::globalRestoreProperty()
-{
- QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- ValueCheckerState *s3 = new ValueCheckerState(machine.rootState());
- s3->addPropertyToCheck(object, "foo");
- s3->addPropertyToCheck(object, "bar");
- s3->setPropertyOnEntry(object, "bar", 5.0);
-
- ValueCheckerState *s4 = new ValueCheckerState(machine.rootState());
- s4->addPropertyToCheck(object, "foo");
- s4->addPropertyToCheck(object, "bar");
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- as = s2->addAnimatedTransition(new EventTransition(QEvent::User, s3));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- as = s3->addAnimatedTransition(new EventTransition(QEvent::User, s4));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 3.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s3->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s3->valueOnEntry.at(0).toDouble(), 1.0);
- QCOMPARE(s3->valueOnEntry.at(1).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s4->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s4->valueOnEntry.at(0).toDouble(), 1.0);
- QCOMPARE(s4->valueOnEntry.at(1).toDouble(), 3.0);
-
-}
-
-void tst_QAnimationState::specificRestoreProperty()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->setRestorePolicy(QState::RestoreProperties);
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- ValueCheckerState *s3 = new ValueCheckerState(machine.rootState());
- s3->setRestorePolicy(QState::RestoreProperties);
- s3->addPropertyToCheck(object, "foo");
- s3->addPropertyToCheck(object, "bar");
- s3->setPropertyOnEntry(object, "bar", 5.0);
-
- ValueCheckerState *s4 = new ValueCheckerState(machine.rootState());
- s4->setRestorePolicy(QState::RestoreProperties);
- s4->addPropertyToCheck(object, "foo");
- s4->addPropertyToCheck(object, "bar");
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
-
- as = s2->addAnimatedTransition(new EventTransition(QEvent::User, s3));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- as = s3->addAnimatedTransition(new EventTransition(QEvent::User, s4));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 3.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s3->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s3->valueOnEntry.at(0).toDouble(), 1.0);
- QCOMPARE(s3->valueOnEntry.at(1).toDouble(), 5.0);
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s4->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s4->valueOnEntry.at(0).toDouble(), 1.0);
- QCOMPARE(s4->valueOnEntry.at(1).toDouble(), 3.0);
-}
-
-void tst_QAnimationState::someAnimationsNotSpecified()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- QAnimationState *as = s1->addAnimatedTransition(new EventTransition(QEvent::User, s2));
- as->addAnimation(new QPropertyAnimation(object, "foo", as));
- as->addAnimation(new QPropertyAnimation(object, "bar", as));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 3.0);
-}
-
-void tst_QAnimationState::someActionsNotAnimated()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
- object->setProperty("bar", 3.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->addPropertyToCheck(object, "bar");
- s2->setPropertyOnEntry(object, "foo", 2.0);
- s2->setPropertyOnEntry(object, "bar", 5.0);
-
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2),
- new QPropertyAnimation(object, "foo", s1));
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(s2->valueOnEntry.at(1).toDouble(), 3.0);
- QCOMPARE(object->property("foo").toDouble(), 2.0);
- QCOMPARE(object->property("bar").toDouble(), 5.0);
-}
-
-void tst_QAnimationState::specificTargetValueOfAnimation()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
- anim->setEndValue(10.0);
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2), anim);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 10.0);
- QCOMPARE(object->property("foo").toDouble(), 2.0);
-}
-
-void tst_QAnimationState::persistentTargetValueOfAnimation()
-{
- QStateMachine machine;
-
- QObject *object = new QObject();
- object->setProperty("foo", 1.0);
-
- QState *s1 = new QState(machine.rootState());
-
- ValueCheckerState *s2 = new ValueCheckerState(machine.rootState());
- s2->addPropertyToCheck(object, "foo");
- s2->setPropertyOnEntry(object, "foo", 2.0);
-
- QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
- s1->addAnimatedTransition(new EventTransition(QEvent::User, s2), anim);
-
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QTRY_COMPARE(s2->valueOnEntry.at(0).isValid(), true);
- QCOMPARE(s2->valueOnEntry.at(0).toDouble(), 2.0);
- QCOMPARE(anim->endValue().isValid(), false);
-}
-
-
-QTEST_MAIN(tst_QAnimationState)
-#include "tst_qanimationstate.moc"
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 085d16b..be80bed 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -70,6 +70,17 @@
static int globalTick;
+// Run exec for a maximum of TIMEOUT msecs
+#define QCOREAPPLICATION_EXEC(TIMEOUT) \
+{ \
+ QTimer timer; \
+ timer.setSingleShot(true); \
+ timer.setInterval(TIMEOUT); \
+ timer.start(); \
+ connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit())); \
+ QCoreApplication::exec(); \
+}
+
class tst_QStateMachine : public QObject
{
Q_OBJECT
@@ -122,6 +133,14 @@ private slots:
void setGlobalRestorePolicyToGlobalRestore();
void restorePolicyOnChildState();
void transitionWithParent();
+
+ void simpleAnimation();
+ void twoAnimations();
+ void twoAnimatedTransitions();
+ void playAnimationTwice();
+ void nestedTargetStateForAnimation();
+ void animatedGlobalRestoreProperty();
+ void specificTargetValueOfAnimation();
};
tst_QStateMachine::tst_QStateMachine()
@@ -2111,5 +2130,313 @@ void tst_QStateMachine::transitionWithParent()
QCOMPARE(trans->targetStates().at(0), (QAbstractState*)s2);
}
+void tst_QStateMachine::simpleAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("fooBar", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "fooBar", 2.0);
+
+ EventTransition *et = new EventTransition(QEvent::User, s2);
+ QPropertyAnimation *animation = new QPropertyAnimation(object, "fooBar", s2);
+ et->addAnimation(animation);
+ s1->addTransition(et);
+
+ QState *s3 = new QState(machine.rootState());
+ s2->addTransition(animation, SIGNAL(finished()), s3);
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("fooBar").toDouble(), 2.0);
+}
+
+class SlotCalledCounter: public QObject
+{
+ Q_OBJECT
+public:
+ SlotCalledCounter() : counter(0) {}
+
+ int counter;
+
+public slots:
+ void slot() { counter++; }
+};
+
+void tst_QStateMachine::twoAnimations()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 3.0);
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+ s2->assignProperty(object, "bar", 10.0);
+
+ QPropertyAnimation *animationFoo = new QPropertyAnimation(object, "foo", s2);
+ QPropertyAnimation *animationBar = new QPropertyAnimation(object, "bar", s2);
+ animationBar->setDuration(900);
+
+ SlotCalledCounter counter;
+ connect(animationFoo, SIGNAL(finished()), &counter, SLOT(slot()));
+ connect(animationBar, SIGNAL(finished()), &counter, SLOT(slot()));
+
+ EventTransition *et = new EventTransition(QEvent::User, s2);
+ et->addAnimation(animationFoo);
+ et->addAnimation(animationBar);
+ s1->addTransition(et);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ s2->addTransition(&machine, SIGNAL(animationsFinished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(object->property("bar").toDouble(), 10.0);
+
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::twoAnimatedTransitions()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 5.0);
+ QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(object, "foo", 2.0);
+ QPropertyAnimation *fooAnimation2 = new QPropertyAnimation(object, "foo", s4);
+ s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation2);
+
+ QState *s5 = new QState(machine.rootState());
+ s5->invokeMethodOnEntry(QApplication::instance(), "quit");
+ s4->addTransition(fooAnimation2, SIGNAL(finished()), s5);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 5.0);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s5));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::playAnimationTwice()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 5.0);
+ QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(object, "foo", 2.0);
+ s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation);
+
+ QState *s5 = new QState(machine.rootState());
+ s5->invokeMethodOnEntry(QApplication::instance(), "quit");
+ s4->addTransition(fooAnimation, SIGNAL(finished()), s5);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 5.0);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s5));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::nestedTargetStateForAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 3.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s2Child = new QState(s2);
+ s2Child->assignProperty(object, "bar", 10.0);
+ s2->setInitialState(s2Child);
+
+ QState *s2Child2 = new QState(s2);
+ s2Child2->assignProperty(object, "bar", 11.0);
+ QAbstractTransition *at = s2Child->addTransition(new EventTransition(QEvent::User, s2Child2));
+
+ QPropertyAnimation *animation = new QPropertyAnimation(object, "bar", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ animation = new QPropertyAnimation(object, "foo", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ animation = new QPropertyAnimation(object, "bar", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ s2->addTransition(&machine, SIGNAL(animationsFinished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(object->property("bar").toDouble(), 10.0);
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::animatedGlobalRestoreProperty()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QState::RestoreProperties);
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+
+ QState *s4 = new QState(machine.rootState());
+ s4->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", s2);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ at = s2->addTransition(pa, SIGNAL(finished()), s3);
+ pa = new QPropertyAnimation(object, "foo", s3);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ at = s3->addTransition(pa, SIGNAL(finished()), s4);
+ pa = new QPropertyAnimation(object, "foo", s4);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s4));
+ QCOMPARE(object->property("foo").toDouble(), 1.0);
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::specificTargetValueOfAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
+ anim->setEndValue(10.0);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(anim);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ s2->addTransition(anim, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(anim->endValue().toDouble(), 10.0);
+}
+
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"
--
cgit v0.12
From e339b7568774e0b26d3f57a7f4b791d39b44b450 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Tue, 21 Apr 2009 17:26:36 +0200
Subject: Add API for adding default animations to the state machine. This is
especially useful when using the RestoreProperties policy, because this is
intended to allow you to build a state machine without having each state
consider all the possible properties that may be set by some state at some
point. Default animations provide the same convenience for animated
properties.
---
src/corelib/statemachine/qstatemachine.cpp | 111 +++++++++++++++++++-
src/corelib/statemachine/qstatemachine.h | 16 +++
src/corelib/statemachine/qstatemachine_p.h | 9 +-
tests/auto/qstatemachine/tst_qstatemachine.cpp | 140 +++++++++++++++++++++++++
4 files changed, 272 insertions(+), 4 deletions(-)
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 0a1d248..1f8d8a8 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -612,8 +612,17 @@ void QStateMachinePrivate::applyProperties(const QList &tr
// Find the animations to use for the state change.
QList selectedAnimations;
- for (int i = 0; i < transitionList.size(); ++i)
- selectedAnimations << transitionList.at(i)->animations();
+ for (int i = 0; i < transitionList.size(); ++i) {
+ QAbstractTransition *transition = transitionList.at(i);
+
+ selectedAnimations << transition->animations();
+ selectedAnimations << defaultAnimationsForSource.values(transition->sourceState());
+
+ QList targetStates = transition->targetStates();
+ for (int j=0; jdefaultAnimations.append(animation);
+}
+
+/*!
+ Returns the list of default animations that will be considered for any transition.
+*/
+QList QStateMachine::defaultAnimations() const
+{
+ Q_D(const QStateMachine);
+ return d->defaultAnimations;
+}
+
+/*!
+ Removes \a animation from the list of default animations.
+*/
+void QStateMachine::removeDefaultAnimation(QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimations.removeAll(animation);
+}
+
+
+/*!
+ Adds a default \a animation to be considered for any transition with the source state
+ \a sourceState.
+*/
+void QStateMachine::addDefaultAnimationForSourceState(QAbstractState *sourceState,
+ QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimationsForSource.insert(sourceState, animation);
+}
+
+
+/*!
+ Returns the list of default animations that will be considered for any transition with
+ the source state \a sourceState.
+*/
+QList QStateMachine::defaultAnimationsForSourceState(QAbstractState *sourceState) const
+{
+ Q_D(const QStateMachine);
+ return d->defaultAnimationsForSource.values(sourceState);
+}
+
+/*!
+ Removes \a animation from the list of default animations for the source state
+ \a sourceState.
+*/
+void QStateMachine::removeDefaultAnimationForSourceState(QAbstractState *sourceState,
+ QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimationsForSource.remove(sourceState, animation);
+}
+
+/*!
+ Adds a default \a animation to be considered for any transition with the target state
+ \a targetState.
+*/
+void QStateMachine::addDefaultAnimationForTargetState(QAbstractState *targetState,
+ QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimationsForTarget.insert(targetState, animation);
+}
+
+/*!
+ Returns the list of default animations that will be considered for any transition with
+ the target state \a targetState.
+*/
+QList QStateMachine::defaultAnimationsForTargetState(QAbstractState *targetState) const
+{
+ Q_D(const QStateMachine);
+ return d->defaultAnimationsForTarget.values(targetState);
+}
+
+/*!
+ Removes \a animation from the list of default animations for the target state
+ \a targetState.
+*/
+void QStateMachine::removeDefaultAnimationForTargetState(QAbstractState *targetState,
+ QAbstractAnimation *animation)
+{
+ Q_D(QStateMachine);
+ d->defaultAnimationsForTarget.remove(targetState, animation);
+}
+
+#endif // QT_NO_ANIMATION
+
+
static const uint qt_meta_data_QSignalEventGenerator[] = {
// content:
diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h
index c7de171..f39efc7 100644
--- a/src/corelib/statemachine/qstatemachine.h
+++ b/src/corelib/statemachine/qstatemachine.h
@@ -63,6 +63,8 @@ class QAbstractState;
class QState;
class QStateMachinePrivate;
+class QAbstractAnimation;
+class QAbstractState;
class Q_CORE_EXPORT QStateMachine : public QObject
{
Q_OBJECT
@@ -96,6 +98,20 @@ public:
QString errorString() const;
void clearError();
+#ifndef QT_NO_ANIMATION
+ void addDefaultAnimation(QAbstractAnimation *animation);
+ QList defaultAnimations() const;
+ void removeDefaultAnimation(QAbstractAnimation *animation);
+
+ void addDefaultAnimationForSourceState(QAbstractState *sourceState, QAbstractAnimation *animation);
+ QList defaultAnimationsForSourceState(QAbstractState *sourceState) const;
+ void removeDefaultAnimationForSourceState(QAbstractState *sourceState, QAbstractAnimation *animation);
+
+ void addDefaultAnimationForTargetState(QAbstractState *targetState, QAbstractAnimation *animation);
+ QList defaultAnimationsForTargetState(QAbstractState *targetState) const;
+ void removeDefaultAnimationForTargetState(QAbstractState *targetState, QAbstractAnimation *animation);
+#endif // QT_NO_ANIMATION
+
QAbstractState::RestorePolicy globalRestorePolicy() const;
void setGlobalRestorePolicy(QAbstractState::RestorePolicy restorePolicy);
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 04dc71e..a9fd2de 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -169,7 +169,7 @@ public:
QSet configuration;
QList internalEventQueue;
QList externalEventQueue;
-
+
QStateMachine::Error error;
QActionState::RestorePolicy globalRestorePolicy;
@@ -186,7 +186,12 @@ public:
QList > propertiesForAnimations;
QList playingAnimations;
QList resetEndValues;
-#endif
+
+ QList defaultAnimations;
+ QMultiHash defaultAnimationsForSource;
+ QMultiHash defaultAnimationsForTarget;
+
+#endif // QT_NO_ANIMATION
#ifndef QT_STATEMACHINE_SOLUTION
QSignalEventGenerator *signalEventGenerator;
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index be80bed..5796161 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -141,6 +141,10 @@ private slots:
void nestedTargetStateForAnimation();
void animatedGlobalRestoreProperty();
void specificTargetValueOfAnimation();
+ void addDefaultAnimation();
+ void addDefaultAnimationWithUnusedAnimation();
+ void addDefaultAnimationForSource();
+ void addDefaultAnimationForTarget();
};
tst_QStateMachine::tst_QStateMachine()
@@ -2437,6 +2441,142 @@ void tst_QStateMachine::specificTargetValueOfAnimation()
QCOMPARE(anim->endValue().toDouble(), 10.0);
}
+void tst_QStateMachine::addDefaultAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimation(pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 2.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ machine.addDefaultAnimation(pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ pa = new QPropertyAnimation(object, "bar", &machine);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ machine.addDefaultAnimation(pa);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(counter.counter, 1);
+}
+
+void tst_QStateMachine::addDefaultAnimationForSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimationForSourceState(s1, pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::addDefaultAnimationForTarget()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimationForTargetState(s2, pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"
--
cgit v0.12
From a81e1a625d25db862fe02bfa484a6216ff06bcf8 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Wed, 22 Apr 2009 11:17:14 +0200
Subject: Add tests for the removeDefaultAnimation* API
---
tests/auto/qstatemachine/tst_qstatemachine.cpp | 127 +++++++++++++++++++++++++
1 file changed, 127 insertions(+)
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 5796161..33239b8 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -145,6 +145,9 @@ private slots:
void addDefaultAnimationWithUnusedAnimation();
void addDefaultAnimationForSource();
void addDefaultAnimationForTarget();
+ void removeDefaultAnimation();
+ void removeDefaultAnimationForSource();
+ void removeDefaultAnimationForTarget();
};
tst_QStateMachine::tst_QStateMachine()
@@ -2578,5 +2581,129 @@ void tst_QStateMachine::addDefaultAnimationForTarget()
QCOMPARE(object->property("foo").toDouble(), 2.0);
}
+void tst_QStateMachine::removeDefaultAnimation()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 1);
+ QVERIFY(machine.defaultAnimations().contains(anim));
+
+ machine.removeDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+
+ machine.addDefaultAnimation(anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimation(anim2);
+
+ QCOMPARE(machine.defaultAnimations().size(), 2);
+ QVERIFY(machine.defaultAnimations().contains(anim));
+ QVERIFY(machine.defaultAnimations().contains(anim2));
+
+ machine.removeDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 1);
+ QVERIFY(machine.defaultAnimations().contains(anim2));
+
+ machine.removeDefaultAnimation(anim2);
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+}
+
+void tst_QStateMachine::removeDefaultAnimationForSource()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim2);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 2);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim2);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+}
+
+void tst_QStateMachine::removeDefaultAnimationForTarget()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim2);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 2);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim2);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+}
+
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"
--
cgit v0.12
From 31f5348ea1691a7664b6abc04cf425dd02637b33 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Wed, 22 Apr 2009 13:28:21 +0200
Subject: Test for overriding default animations. This test defines the order
of precedence:
1. Specific animation for transition
2. Default animation for source state
3. Default animation for target state
4. Default animation
---
tests/auto/qstatemachine/tst_qstatemachine.cpp | 247 +++++++++++++++++++++++++
1 file changed, 247 insertions(+)
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 33239b8..b82055b 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -148,6 +148,12 @@ private slots:
void removeDefaultAnimation();
void removeDefaultAnimationForSource();
void removeDefaultAnimationForTarget();
+ void overrideDefaultAnimationWithSource();
+ void overrideDefaultAnimationWithTarget();
+ void overrideDefaultAnimationWithSpecific();
+ void overrideDefaultSourceAnimationWithSpecific();
+ void overrideDefaultTargetAnimationWithSpecific();
+ void overrideDefaultTargetAnimationWithSource();
};
tst_QStateMachine::tst_QStateMachine()
@@ -2704,6 +2710,247 @@ void tst_QStateMachine::removeDefaultAnimationForTarget()
QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
}
+void tst_QStateMachine::overrideDefaultAnimationWithSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ machine.addDefaultAnimationForSourceState(s1, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithTarget()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ machine.addDefaultAnimationForTargetState(s2, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultSourceAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForSourceState(s1, defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultTargetAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForTargetState(s2, defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultTargetAnimationWithSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForTargetState(s2, defaultAnimation);
+ machine.addDefaultAnimationForSourceState(s1, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"
--
cgit v0.12
From f87641584424deed25e2abdadea08c3be94b9ce1 Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Wed, 22 Apr 2009 17:20:19 +0200
Subject: kill the stateactions api
It just didn't give us that much.
Typically you just reimplement onEntry/onExit/onTransition
when you want to do something.
We go back to the signals-and-slots approach: states have
entered() and exited() signals that you can connect to.
It's still possible to have an action-based API, but then
you build it on top of the core API, which is OK.
Replacing 4 public classes (and one layer in the hierarchy)
with 2 signals feels good.
---
doc/src/statemachine.qdoc | 7 +-
examples/animation/example/mainwindow.cpp | 6 +-
examples/animation/moveblocks/main.cpp | 2 +-
examples/animation/stickman/lifecycle.cpp | 4 +-
examples/statemachine/composition/main.cpp | 4 +-
examples/statemachine/trafficlight/main.cpp | 6 +-
src/corelib/statemachine/qabstractstate.cpp | 29 ++
src/corelib/statemachine/qabstractstate.h | 4 +
src/corelib/statemachine/qabstractstate_p.h | 3 +
src/corelib/statemachine/qactionstate.cpp | 293 -----------------
src/corelib/statemachine/qactionstate.h | 102 ------
src/corelib/statemachine/qactionstate_p.h | 83 -----
src/corelib/statemachine/qactiontransition.cpp | 230 -------------
src/corelib/statemachine/qactiontransition.h | 96 ------
src/corelib/statemachine/qactiontransition_p.h | 80 -----
src/corelib/statemachine/qeventtransition.cpp | 21 +-
src/corelib/statemachine/qeventtransition.h | 7 +-
src/corelib/statemachine/qeventtransition_p.h | 4 +-
src/corelib/statemachine/qfinalstate.cpp | 10 +-
src/corelib/statemachine/qfinalstate.h | 6 +-
src/corelib/statemachine/qsignaltransition.cpp | 15 +-
src/corelib/statemachine/qsignaltransition.h | 7 +-
src/corelib/statemachine/qsignaltransition_p.h | 4 +-
src/corelib/statemachine/qstate.cpp | 10 +-
src/corelib/statemachine/qstate.h | 6 +-
src/corelib/statemachine/qstate_p.h | 4 +-
src/corelib/statemachine/qstateaction.cpp | 356 ---------------------
src/corelib/statemachine/qstateaction.h | 119 -------
src/corelib/statemachine/qstateaction_p.h | 107 -------
.../statemachine/qstatefinishedtransition.cpp | 17 +-
.../statemachine/qstatefinishedtransition.h | 7 +-
src/corelib/statemachine/qstatemachine.cpp | 10 +-
src/corelib/statemachine/qstatemachine.h | 4 +-
src/corelib/statemachine/qstatemachine_p.h | 2 +-
src/corelib/statemachine/statemachine.pri | 9 -
tests/auto/qstatemachine/tst_qstatemachine.cpp | 194 ++---------
36 files changed, 148 insertions(+), 1720 deletions(-)
delete mode 100644 src/corelib/statemachine/qactionstate.cpp
delete mode 100644 src/corelib/statemachine/qactionstate.h
delete mode 100644 src/corelib/statemachine/qactionstate_p.h
delete mode 100644 src/corelib/statemachine/qactiontransition.cpp
delete mode 100644 src/corelib/statemachine/qactiontransition.h
delete mode 100644 src/corelib/statemachine/qactiontransition_p.h
delete mode 100644 src/corelib/statemachine/qstateaction.cpp
delete mode 100644 src/corelib/statemachine/qstateaction.h
delete mode 100644 src/corelib/statemachine/qstateaction_p.h
diff --git a/doc/src/statemachine.qdoc b/doc/src/statemachine.qdoc
index 3051d19..97c09b9 100644
--- a/doc/src/statemachine.qdoc
+++ b/doc/src/statemachine.qdoc
@@ -91,13 +91,12 @@
When any of the states is entered, the label's text will be changed
accordingly.
- The QActionState::invokeMethodOnEntry() function can be used to have a state
- invoke a method (a slot) of a QObject when the state is entered. In the
+ The QActionState::entered() signal is emitted when the state is entered. In the
following snippet, the button's showMaximized() slot will be called when
state \c s3 is entered:
\code
- s2->invokeMethodOnEntry(button, "showMaximized");
+ QObject::connect(s3, SIGNAL(entered()), button, SLOT(showMaximized()));
\endcode
\section1 Sharing Transitions By Grouping States
@@ -209,7 +208,7 @@
mbox.addButton(QMessageBox::Ok);
mbox.setText("Interrupted!");
mbox.setIcon(QMessageBox::Information);
- s3->invokeMethodOnEntry(&mbox, "exec");
+ QObject::connect(s3, SIGNAL(entered()), &mbox, SLOT(exec()));
s3->addTransition(s1h);
machine.addState(s3);
diff --git a/examples/animation/example/mainwindow.cpp b/examples/animation/example/mainwindow.cpp
index 2b0e035..bec755c 100644
--- a/examples/animation/example/mainwindow.cpp
+++ b/examples/animation/example/mainwindow.cpp
@@ -173,9 +173,9 @@ MainWindow::MainWindow() : QMainWindow(0)
setCentralWidget(view);
- state3->invokeMethodOnEntry(this, "onEnterState3");
- state2->invokeMethodOnEntry(this, "onEnterState2");
- state1->invokeMethodOnEntry(this, "onEnterState1");
+ QObject::connect(state3, SIGNAL(entered()), this, SLOT(onEnterState3()));
+ QObject::connect(state2, SIGNAL(entered()), this, SLOT(onEnterState2()));
+ QObject::connect(state1, SIGNAL(entered()), this, SLOT(onEnterState1()));
connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onItemClicked(QListWidgetItem*)));
connect(button3, SIGNAL(clicked()), this, SLOT(onRemoveClicked()));
diff --git a/examples/animation/moveblocks/main.cpp b/examples/animation/moveblocks/main.cpp
index 1f253f3..639fff3 100644
--- a/examples/animation/moveblocks/main.cpp
+++ b/examples/animation/moveblocks/main.cpp
@@ -172,7 +172,7 @@ int main(int argc, char **argv)
QTimer timer;
timer.setInterval(1250);
timer.setSingleShot(true);
- group->invokeMethodOnEntry(&timer, "start");
+ QObject::connect(group, SIGNAL(entered()), &timer, SLOT(start()));
QState *state1;
QState *state2;
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
index 9233760..e67b32d 100644
--- a/examples/animation/stickman/lifecycle.cpp
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -86,8 +86,8 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
QTimer *timer = new QTimer(lightningBlink);
timer->setSingleShot(true);
timer->setInterval(100);
- lightningBlink->invokeMethodOnEntry(timer, "start");
- lightningBlink->invokeMethodOnExit(timer, "stop");
+ QObject::connect(lightningBlink, SIGNAL(entered()), timer, SLOT(start()));
+ QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop()));
m_dead = new QState(m_machine->rootState());
m_dead->setRestorePolicy(QState::DoNotRestoreProperties);
diff --git a/examples/statemachine/composition/main.cpp b/examples/statemachine/composition/main.cpp
index 24b823c..927fc62 100644
--- a/examples/statemachine/composition/main.cpp
+++ b/examples/statemachine/composition/main.cpp
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
s1_timer->setObjectName("s1_timer");
QTimer t1;
t1.setInterval(2000);
- s1_timer->invokeMethodOnEntry(&t1, "start");
+ QObject::connect(s1_timer, SIGNAL(entered()), &t1, SLOT(start()));
QFinalState *s1_done = new QFinalState(s1);
s1_done->setObjectName("s1_done");
s1_timer->addTransition(&t1, SIGNAL(timeout()), s1_done);
@@ -80,7 +80,7 @@ int main(int argc, char **argv)
s2_timer->setObjectName("s2_timer");
QTimer t2;
t2.setInterval(2000);
- s2_timer->invokeMethodOnEntry(&t2, "start");
+ QObject::connect(s2_timer, SIGNAL(entered()), &t2, SLOT(start()));
QFinalState *s2_done = new QFinalState(s2);
s2_done->setObjectName("s2_done");
s2_timer->addTransition(&t2, SIGNAL(timeout()), s2_done);
diff --git a/examples/statemachine/trafficlight/main.cpp b/examples/statemachine/trafficlight/main.cpp
index 528ed00..115ecad 100644
--- a/examples/statemachine/trafficlight/main.cpp
+++ b/examples/statemachine/trafficlight/main.cpp
@@ -97,9 +97,9 @@ public:
timer->setInterval(duration);
timer->setSingleShot(true);
QState *timing = new QState(this);
- timing->invokeMethodOnEntry(light, "turnOn");
- timing->invokeMethodOnEntry(timer, "start");
- timing->invokeMethodOnExit(light, "turnOff");
+ QObject::connect(timing, SIGNAL(entered()), light, SLOT(turnOn()));
+ QObject::connect(timing, SIGNAL(entered()), timer, SLOT(start()));
+ QObject::connect(timing, SIGNAL(exited()), light, SLOT(turnOff()));
QFinalState *done = new QFinalState(this);
timing->addTransition(timer, SIGNAL(timeout()), done);
setInitialState(timing);
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index 89dcff9..030c63c 100644
--- a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -62,6 +62,9 @@ QT_BEGIN_NAMESPACE
The assignProperty() function is used for defining property assignments that
should be performed when a state is entered.
+ The entered() signal is emitted when the state has been entered. The
+ exited() signal is emitted when the state has been exited.
+
The parentState() function returns the state's parent state.
\section1 Subclassing
@@ -149,6 +152,18 @@ void QAbstractStatePrivate::callOnExit()
q->onExit();
}
+void QAbstractStatePrivate::emitEntered()
+{
+ Q_Q(QAbstractState);
+ emit q->entered();
+}
+
+void QAbstractStatePrivate::emitExited()
+{
+ Q_Q(QAbstractState);
+ emit q->exited();
+}
+
/*!
Constructs a new state with the given \a parent state.
*/
@@ -256,6 +271,20 @@ QAbstractState::RestorePolicy QAbstractState::restorePolicy() const
*/
/*!
+ \fn QAbstractState::entered()
+
+ This signal is emitted when the state has been entered (after onEntry() has
+ been called).
+*/
+
+/*!
+ \fn QAbstractState::exited()
+
+ This signal is emitted when the state has been exited (after onExit() has
+ been called).
+*/
+
+/*!
\reimp
*/
bool QAbstractState::event(QEvent *e)
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index b788a88..55e9a62 100644
--- a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -75,6 +75,10 @@ public:
void setRestorePolicy(RestorePolicy restorePolicy);
RestorePolicy restorePolicy() const;
+Q_SIGNALS:
+ void entered();
+ void exited();
+
protected:
QAbstractState(QState *parent = 0);
diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h
index 7c565f0..e47fbd2 100644
--- a/src/corelib/statemachine/qabstractstate_p.h
+++ b/src/corelib/statemachine/qabstractstate_p.h
@@ -98,6 +98,9 @@ public:
void callOnEntry();
void callOnExit();
+ void emitEntered();
+ void emitExited();
+
QAbstractState::RestorePolicy restorePolicy;
QList propertyAssignments;
diff --git a/src/corelib/statemachine/qactionstate.cpp b/src/corelib/statemachine/qactionstate.cpp
deleted file mode 100644
index 1da0350..0000000
--- a/src/corelib/statemachine/qactionstate.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qactionstate.h"
-#include "qactionstate_p.h"
-#include "qstateaction.h"
-#include "qstateaction_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QActionState
-
- \brief The QActionState class provides an action-based state.
-
- \since 4.6
- \ingroup statemachine
-
- QActionState executes \l{QStateAction}{state actions} when the state is
- entered and exited. QActionState is part of \l{The State Machine Framework}.
-
- You can add actions to a state with the addEntryAction() and addExitAction()
- functions. The state executes the actions when the state is entered and
- exited, respectively.
-
- The invokeMethodOnEntry() and invokeMethodOnExit() functions are used for
- defining method invocations that should be performed when a state is entered
- and exited, respectively.
-
- \code
- QState *s2 = new QState();
- s2->invokeMethodOnEntry(&label, "showMaximized");
- machine.addState(s2);
- \endcode
-
- \sa QStateAction
-*/
-
-QActionStatePrivate::QActionStatePrivate()
-{
-}
-
-QActionStatePrivate::~QActionStatePrivate()
-{
-}
-
-QActionStatePrivate *QActionStatePrivate::get(QActionState *q)
-{
- return q->d_func();
-}
-
-const QActionStatePrivate *QActionStatePrivate::get(const QActionState *q)
-{
- return q->d_func();
-}
-
-QList QActionStatePrivate::entryActions() const
-{
- QList result;
- QList::const_iterator it;
-#ifdef QT_STATEMACHINE_SOLUTION
- const QObjectList &children = q_func()->children();
-#endif
- for (it = children.constBegin(); it != children.constEnd(); ++it) {
- QStateAction *act = qobject_cast(*it);
- if (act && (QStateActionPrivate::get(act)->when == QStateActionPrivate::ExecuteOnEntry))
- result.append(act);
- }
- return result;
-}
-
-QList QActionStatePrivate::exitActions() const
-{
- QList result;
- QList::const_iterator it;
-#ifdef QT_STATEMACHINE_SOLUTION
- const QObjectList &children = q_func()->children();
-#endif
- for (it = children.constBegin(); it != children.constEnd(); ++it) {
- QStateAction *act = qobject_cast(*it);
- if (act && (QStateActionPrivate::get(act)->when == QStateActionPrivate::ExecuteOnExit))
- result.append(act);
- }
- return result;
-}
-
-/*!
- Constructs a new action state with the given \a parent state.
-*/
-QActionState::QActionState(QState *parent)
- : QAbstractState(*new QActionStatePrivate, parent)
-{
-}
-
-/*!
- \internal
-*/
-QActionState::QActionState(QActionStatePrivate &dd,
- QState *parent)
- : QAbstractState(dd, parent)
-{
-}
-
-/*!
- Destroys this action state.
-*/
-QActionState::~QActionState()
-{
-}
-
-/*!
- Instructs this state to invoke the given \a method of the given \a object
- with the given \a arguments when the state is entered. This function will
- create a QStateInvokeMethodAction object and add it to the entry actions of
- the state.
-
- \sa invokeMethodOnExit(), addEntryAction()
-*/
-void QActionState::invokeMethodOnEntry(QObject *object, const char *method,
- const QList &arguments)
-{
- addEntryAction(new QStateInvokeMethodAction(object, method, arguments));
-}
-
-/*!
- Instructs this state to invoke the given \a method of the given \a object
- with the given \a arguments when the state is exited. This function will
- create a QStateInvokeMethodAction object and add it to the exit actions of
- the state.
-
- \sa invokeMethodOnEntry(), addExitAction()
-*/
-void QActionState::invokeMethodOnExit(QObject *object, const char *method,
- const QList &arguments)
-{
- addExitAction(new QStateInvokeMethodAction(object, method, arguments));
-}
-
-/*!
- Adds the given \a action to this state. The action will be executed when
- this state is entered. The state takes ownership of the action.
-
- \sa addExitAction(), removeEntryAction()
-*/
-void QActionState::addEntryAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionState::addEntryAction: cannot add null action");
- return;
- }
- action->setParent(this);
- QStateActionPrivate::get(action)->when = QStateActionPrivate::ExecuteOnEntry;
-}
-
-/*!
- Adds the given \a action to this state. The action will be executed when
- this state is exited. The state takes ownership of the action.
-
- \sa addEntryAction(), removeExitAction()
-*/
-void QActionState::addExitAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionState::addExitAction: cannot add null action");
- return;
- }
- action->setParent(this);
- QStateActionPrivate::get(action)->when = QStateActionPrivate::ExecuteOnExit;
-}
-
-/*!
- Removes the given entry \a action from this state. The state releases
- ownership of the action.
-
- \sa addEntryAction()
-*/
-void QActionState::removeEntryAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionState::removeEntryAction: cannot remove null action");
- return;
- }
- if (action->parent() == this)
- action->setParent(0);
-}
-
-/*!
- Removes the given exit \a action from this state. The state releases
- ownership of the action.
-
- \sa addExitAction()
-*/
-void QActionState::removeExitAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionState::removeExitAction: cannot remove null action");
- return;
- }
- if (action->parent() == this)
- action->setParent(0);
-}
-
-/*!
- Returns this state's entry actions.
-
- \sa addEntryAction(), exitActions()
-*/
-QList QActionState::entryActions() const
-{
- Q_D(const QActionState);
- return d->entryActions();
-}
-
-/*!
- Returns this state's exit actions.
-
- \sa addExitAction(), entryActions()
-*/
-QList QActionState::exitActions() const
-{
- Q_D(const QActionState);
- return d->exitActions();
-}
-
-/*!
- \reimp
-*/
-void QActionState::onEntry()
-{
- Q_D(QActionState);
- QList actions = d->entryActions();
- for (int i = 0; i < actions.size(); ++i)
- QStateActionPrivate::get(actions.at(i))->callExecute();
-}
-
-/*!
- \reimp
-*/
-void QActionState::onExit()
-{
- Q_D(QActionState);
- QList actions = d->exitActions();
- for (int i = 0; i < actions.size(); ++i)
- QStateActionPrivate::get(actions.at(i))->callExecute();
-}
-
-/*!
- \reimp
-*/
-bool QActionState::event(QEvent *e)
-{
- return QAbstractState::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qactionstate.h b/src/corelib/statemachine/qactionstate.h
deleted file mode 100644
index 517b4b2..0000000
--- a/src/corelib/statemachine/qactionstate.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QACTIONSTATE_H
-#define QACTIONSTATE_H
-
-#ifndef QT_STATEMACHINE_SOLUTION
-#include
-#else
-#include "qabstractstate.h"
-#endif
-
-#include
-#include
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QStateAction;
-
-class QActionStatePrivate;
-class Q_CORE_EXPORT QActionState : public QAbstractState
-{
- Q_OBJECT
-public:
- QActionState(QState *parent = 0);
- ~QActionState();
-
- void invokeMethodOnEntry(QObject *object, const char *method,
- const QList &args = QList());
- void invokeMethodOnExit(QObject *object, const char *method,
- const QList &args = QList());
-
- void addEntryAction(QStateAction *action);
- void addExitAction(QStateAction *action);
-
- void removeEntryAction(QStateAction *action);
- void removeExitAction(QStateAction *action);
-
- QList entryActions() const;
- QList exitActions() const;
-
-protected:
- void onEntry();
- void onExit();
-
- bool event(QEvent *e);
-
-protected:
- QActionState(QActionStatePrivate &dd, QState *parent);
-
-private:
- Q_DISABLE_COPY(QActionState)
- Q_DECLARE_PRIVATE(QActionState)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/corelib/statemachine/qactionstate_p.h b/src/corelib/statemachine/qactionstate_p.h
deleted file mode 100644
index a06dde2..0000000
--- a/src/corelib/statemachine/qactionstate_p.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QACTIONSTATE_P_H
-#define QACTIONSTATE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qabstractstate_p.h"
-#include "qactionstate.h"
-
-#include
-
-QT_BEGIN_NAMESPACE
-
-class QStateAction;
-
-class QActionState;
-class Q_CORE_EXPORT QActionStatePrivate : public QAbstractStatePrivate
-{
- Q_DECLARE_PUBLIC(QActionState)
-
-public:
- QActionStatePrivate();
- ~QActionStatePrivate();
-
- static QActionStatePrivate *get(QActionState *q);
- static const QActionStatePrivate *get(const QActionState *q);
-
- QList entryActions() const;
- QList exitActions() const;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/statemachine/qactiontransition.cpp b/src/corelib/statemachine/qactiontransition.cpp
deleted file mode 100644
index 7c53e15..0000000
--- a/src/corelib/statemachine/qactiontransition.cpp
+++ /dev/null
@@ -1,230 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qactiontransition.h"
-#include "qactiontransition_p.h"
-#include "qstateaction.h"
-#include "qstateaction_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QActionTransition
-
- \brief The QActionTransition class provides an action-based transition.
-
- \since 4.6
- \ingroup statemachine
-
- QActionTransition provides an action-based transition; you add actions with
- the addAction() function. The transition executes the actions when the
- transition is triggered. QActionTransition is part of \l{The State Machine
- Framework}.
-
- The invokeMethodOnTransition() function is used for defining method
- invocations that should be performed when a transition is taken.
-
- \code
- QStateMachine machine;
- QState *s1 = new QState();
- machine.addState(s1);
- QActionTransition *t1 = new QActionTransition();
- QLabel label;
- t1->invokeMethodOnTransition(&label, "clear");
- QState *s2 = new QState();
- machine.addState(s2);
- t1->setTargetState(s2);
- s1->addTransition(t1);
- \endcode
-
- Actions are executed in the order in which they were added.
-
- \sa QState::addTransition(), QStateAction
-*/
-
-QActionTransitionPrivate::QActionTransitionPrivate()
-{
-}
-
-QActionTransitionPrivate::~QActionTransitionPrivate()
-{
-}
-
-QActionTransitionPrivate *QActionTransitionPrivate::get(QActionTransition *q)
-{
- return q->d_func();
-}
-
-const QActionTransitionPrivate *QActionTransitionPrivate::get(const QActionTransition *q)
-{
- return q->d_func();
-}
-
-QList QActionTransitionPrivate::actions() const
-{
- QList result;
- QList::const_iterator it;
-#ifdef QT_STATEMACHINE_SOLUTION
- const QObjectList &children = q_func()->children();
-#endif
- for (it = children.constBegin(); it != children.constEnd(); ++it) {
- QStateAction *s = qobject_cast(*it);
- if (s)
- result.append(s);
- }
- return result;
-}
-
-/*!
- Constructs a new QActionTransition object with the given \a sourceState.
-*/
-QActionTransition::QActionTransition(QState *sourceState)
- : QAbstractTransition(*new QActionTransitionPrivate, sourceState)
-{
-}
-
-/*!
- Constructs a new QActionTransition object with the given \a targets and \a
- sourceState.
-*/
-QActionTransition::QActionTransition(const QList &targets, QState *sourceState)
- : QAbstractTransition(*new QActionTransitionPrivate, targets, sourceState)
-{
-}
-
-/*!
- \internal
-*/
-QActionTransition::QActionTransition(QActionTransitionPrivate &dd, QState *parent)
- : QAbstractTransition(dd, parent)
-{
-}
-
-/*!
- \internal
-*/
-QActionTransition::QActionTransition(QActionTransitionPrivate &dd, const QList &targets, QState *parent)
- : QAbstractTransition(dd, targets, parent)
-{
-}
-
-/*!
- Destroys this transition.
-*/
-QActionTransition::~QActionTransition()
-{
-}
-
-/*!
- Instructs this QActionTransition to invoke the given \a method of the given \a
- object with the given \a arguments when the transition is taken. This
- function will create a QStateInvokeMethodAction object and add it to the
- actions of the transition.
-*/
-void QActionTransition::invokeMethodOnTransition(QObject *object, const char *method,
- const QList &arguments)
-{
- addAction(new QStateInvokeMethodAction(object, method, arguments));
-}
-
-/*!
- Adds the given \a action to this transition.
- The action will be executed when the transition is triggered.
- The transition takes ownership of the action.
-
- \sa removeAction()
-*/
-void QActionTransition::addAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionTransition::addAction: cannot add null action");
- return;
- }
- action->setParent(this);
-}
-
-/*!
- Removes the given \a action from this transition.
- The transition releases ownership of the action.
-
- \sa addAction()
-*/
-void QActionTransition::removeAction(QStateAction *action)
-{
- if (!action) {
- qWarning("QActionTransition::removeAction: cannot remove null action");
- return;
- }
- action->setParent(0);
-}
-
-/*!
- Returns this transitions's actions, or an empty list if the transition has
- no actions.
-
- \sa addAction()
-*/
-QList QActionTransition::actions() const
-{
- Q_D(const QActionTransition);
- return d->actions();
-}
-
-/*!
- \reimp
-*/
-void QActionTransition::onTransition()
-{
- Q_D(QActionTransition);
- QList actions = d->actions();
- for (int i = 0; i < actions.size(); ++i)
- QStateActionPrivate::get(actions.at(i))->callExecute();
-}
-
-/*!
- \reimp
-*/
-bool QActionTransition::event(QEvent *e)
-{
- return QAbstractTransition::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qactiontransition.h b/src/corelib/statemachine/qactiontransition.h
deleted file mode 100644
index 1a779fa..0000000
--- a/src/corelib/statemachine/qactiontransition.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QACTIONTRANSITION_H
-#define QACTIONTRANSITION_H
-
-#ifndef QT_STATEMACHINE_SOLUTION
-#include
-#else
-#include "qabstracttransition.h"
-#endif
-
-#include
-#include
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QStateAction;
-
-class QActionTransitionPrivate;
-class Q_CORE_EXPORT QActionTransition : public QAbstractTransition
-{
- Q_OBJECT
-public:
- QActionTransition(QState *sourceState = 0);
- QActionTransition(const QList &targets, QState *sourceState = 0);
- ~QActionTransition();
-
- void invokeMethodOnTransition(QObject *object, const char *method,
- const QList &args = QList());
-
- void addAction(QStateAction *action);
- void removeAction(QStateAction *action);
- QList actions() const;
-
-protected:
- virtual void onTransition();
-
- bool event(QEvent *e);
-
-protected:
- QActionTransition(QActionTransitionPrivate &dd, QState *parent);
- QActionTransition(QActionTransitionPrivate &dd, const QList &targets, QState *parent);
-
-private:
- Q_DISABLE_COPY(QActionTransition)
- Q_DECLARE_PRIVATE(QActionTransition)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/corelib/statemachine/qactiontransition_p.h b/src/corelib/statemachine/qactiontransition_p.h
deleted file mode 100644
index 34f80d1..0000000
--- a/src/corelib/statemachine/qactiontransition_p.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QACTIONTRANSITION_P_H
-#define QACTIONTRANSITION_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qabstracttransition_p.h"
-
-#include
-
-QT_BEGIN_NAMESPACE
-
-class QStateAction;
-
-class QActionTransition;
-class Q_CORE_EXPORT QActionTransitionPrivate : public QAbstractTransitionPrivate
-{
- Q_DECLARE_PUBLIC(QActionTransition)
-public:
- QActionTransitionPrivate();
- ~QActionTransitionPrivate();
-
- static QActionTransitionPrivate *get(QActionTransition *q);
- static const QActionTransitionPrivate *get(const QActionTransition *q);
-
- QList actions() const;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/statemachine/qeventtransition.cpp b/src/corelib/statemachine/qeventtransition.cpp
index 87ed77a..09b89f3 100644
--- a/src/corelib/statemachine/qeventtransition.cpp
+++ b/src/corelib/statemachine/qeventtransition.cpp
@@ -129,7 +129,7 @@ void QEventTransitionPrivate::invalidate()
Constructs a new QEventTransition object with the given \a sourceState.
*/
QEventTransition::QEventTransition(QState *sourceState)
- : QActionTransition(*new QEventTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, sourceState)
{
}
@@ -139,7 +139,7 @@ QEventTransition::QEventTransition(QState *sourceState)
*/
QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
QState *sourceState)
- : QActionTransition(*new QEventTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, sourceState)
{
Q_D(QEventTransition);
d->registered = false;
@@ -155,7 +155,7 @@ QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
const QList &targets,
QState *sourceState)
- : QActionTransition(*new QEventTransitionPrivate, targets, sourceState)
+ : QAbstractTransition(*new QEventTransitionPrivate, targets, sourceState)
{
Q_D(QEventTransition);
d->registered = false;
@@ -167,7 +167,7 @@ QEventTransition::QEventTransition(QObject *object, QEvent::Type type,
\internal
*/
QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QState *parent)
- : QActionTransition(dd, parent)
+ : QAbstractTransition(dd, parent)
{
}
@@ -176,7 +176,7 @@ QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QState *parent)
*/
QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,
QEvent::Type type, QState *parent)
- : QActionTransition(dd, parent)
+ : QAbstractTransition(dd, parent)
{
Q_D(QEventTransition);
d->registered = false;
@@ -190,7 +190,7 @@ QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,
QEventTransition::QEventTransition(QEventTransitionPrivate &dd, QObject *object,
QEvent::Type type, const QList &targets,
QState *parent)
- : QActionTransition(dd, targets, parent)
+ : QAbstractTransition(dd, targets, parent)
{
Q_D(QEventTransition);
d->registered = false;
@@ -268,6 +268,13 @@ bool QEventTransition::eventTest(QEvent *event) const
}
/*!
+ \reimp
+*/
+void QEventTransition::onTransition()
+{
+}
+
+/*!
Tests an instance of an event associated with this event transition and
returns true if the transition should be taken, otherwise returns false.
The type of the given \a event will be eventType().
@@ -286,7 +293,7 @@ bool QEventTransition::testEventCondition(QEvent *event) const
*/
bool QEventTransition::event(QEvent *e)
{
- return QActionTransition::event(e);
+ return QAbstractTransition::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qeventtransition.h b/src/corelib/statemachine/qeventtransition.h
index 21a696c..e19b5af 100644
--- a/src/corelib/statemachine/qeventtransition.h
+++ b/src/corelib/statemachine/qeventtransition.h
@@ -43,9 +43,9 @@
#define QEVENTTRANSITION_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include
+#include
#else
-#include "qactiontransition.h"
+#include "qabstracttransition.h"
#endif
#include
@@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
class QEventTransitionPrivate;
-class Q_CORE_EXPORT QEventTransition : public QActionTransition
+class Q_CORE_EXPORT QEventTransition : public QAbstractTransition
{
Q_OBJECT
Q_PROPERTY(QObject* object READ eventSource WRITE setEventSource)
@@ -80,6 +80,7 @@ protected:
virtual bool testEventCondition(QEvent *event) const; // ### name
bool eventTest(QEvent *event) const;
+ void onTransition();
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qeventtransition_p.h b/src/corelib/statemachine/qeventtransition_p.h
index 2bb5aaa..fca8c0d 100644
--- a/src/corelib/statemachine/qeventtransition_p.h
+++ b/src/corelib/statemachine/qeventtransition_p.h
@@ -53,12 +53,12 @@
// We mean it.
//
-#include "qactiontransition_p.h"
+#include "qabstracttransition_p.h"
QT_BEGIN_NAMESPACE
class QEventTransition;
-class Q_CORE_EXPORT QEventTransitionPrivate : public QActionTransitionPrivate
+class Q_CORE_EXPORT QEventTransitionPrivate : public QAbstractTransitionPrivate
{
Q_DECLARE_PUBLIC(QEventTransition)
public:
diff --git a/src/corelib/statemachine/qfinalstate.cpp b/src/corelib/statemachine/qfinalstate.cpp
index abf9d2e..16e080e 100644
--- a/src/corelib/statemachine/qfinalstate.cpp
+++ b/src/corelib/statemachine/qfinalstate.cpp
@@ -40,7 +40,7 @@
****************************************************************************/
#include "qfinalstate.h"
-#include "qactionstate_p.h"
+#include "qabstractstate_p.h"
QT_BEGIN_NAMESPACE
@@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE
\sa QStateFinishedTransition
*/
-class QFinalStatePrivate : public QActionStatePrivate
+class QFinalStatePrivate : public QAbstractStatePrivate
{
Q_DECLARE_PUBLIC(QFinalState)
@@ -96,7 +96,7 @@ QFinalStatePrivate::QFinalStatePrivate()
Constructs a new QFinalState object with the given \a parent state.
*/
QFinalState::QFinalState(QState *parent)
- : QActionState(*new QFinalStatePrivate, parent)
+ : QAbstractState(*new QFinalStatePrivate, parent)
{
}
@@ -112,7 +112,6 @@ QFinalState::~QFinalState()
*/
void QFinalState::onEntry()
{
- QActionState::onEntry();
}
/*!
@@ -120,7 +119,6 @@ void QFinalState::onEntry()
*/
void QFinalState::onExit()
{
- QActionState::onExit();
}
/*!
@@ -128,7 +126,7 @@ void QFinalState::onExit()
*/
bool QFinalState::event(QEvent *e)
{
- return QActionState::event(e);
+ return QAbstractState::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qfinalstate.h b/src/corelib/statemachine/qfinalstate.h
index 36813f5..726a399 100644
--- a/src/corelib/statemachine/qfinalstate.h
+++ b/src/corelib/statemachine/qfinalstate.h
@@ -43,9 +43,9 @@
#define QFINALSTATE_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include
+#include
#else
-#include "qactionstate.h"
+#include "qabstractstate.h"
#endif
QT_BEGIN_HEADER
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
class QFinalStatePrivate;
-class Q_CORE_EXPORT QFinalState : public QActionState
+class Q_CORE_EXPORT QFinalState : public QAbstractState
{
Q_OBJECT
public:
diff --git a/src/corelib/statemachine/qsignaltransition.cpp b/src/corelib/statemachine/qsignaltransition.cpp
index 32f2d02..064ac6e 100644
--- a/src/corelib/statemachine/qsignaltransition.cpp
+++ b/src/corelib/statemachine/qsignaltransition.cpp
@@ -137,7 +137,7 @@ void QSignalTransitionPrivate::invalidate()
Constructs a new signal transition with the given \a sourceState.
*/
QSignalTransition::QSignalTransition(QState *sourceState)
- : QActionTransition(*new QSignalTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
{
}
@@ -147,7 +147,7 @@ QSignalTransition::QSignalTransition(QState *sourceState)
*/
QSignalTransition::QSignalTransition(QObject *sender, const char *signal,
QState *sourceState)
- : QActionTransition(*new QSignalTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
{
Q_D(QSignalTransition);
d->sender = sender;
@@ -162,7 +162,7 @@ QSignalTransition::QSignalTransition(QObject *sender, const char *signal,
QSignalTransition::QSignalTransition(QObject *sender, const char *signal,
const QList &targets,
QState *sourceState)
- : QActionTransition(*new QSignalTransitionPrivate, targets, sourceState)
+ : QAbstractTransition(*new QSignalTransitionPrivate, targets, sourceState)
{
Q_D(QSignalTransition);
d->sender = sender;
@@ -245,9 +245,16 @@ bool QSignalTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
+void QSignalTransition::onTransition()
+{
+}
+
+/*!
+ \reimp
+*/
bool QSignalTransition::event(QEvent *e)
{
- return QActionTransition::event(e);
+ return QAbstractTransition::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qsignaltransition.h b/src/corelib/statemachine/qsignaltransition.h
index c1a41ae..4df97cf 100644
--- a/src/corelib/statemachine/qsignaltransition.h
+++ b/src/corelib/statemachine/qsignaltransition.h
@@ -43,9 +43,9 @@
#define QSIGNALTRANSITION_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include
+#include
#else
-#include "qactiontransition.h"
+#include "qabstracttransition.h"
#endif
QT_BEGIN_HEADER
@@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
class QSignalTransitionPrivate;
-class Q_CORE_EXPORT QSignalTransition : public QActionTransition
+class Q_CORE_EXPORT QSignalTransition : public QAbstractTransition
{
Q_OBJECT
Q_PROPERTY(QObject* object READ senderObject WRITE setSenderObject)
@@ -77,6 +77,7 @@ public:
protected:
bool eventTest(QEvent *event) const;
+ void onTransition();
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qsignaltransition_p.h b/src/corelib/statemachine/qsignaltransition_p.h
index bd815d9..a23e58c 100644
--- a/src/corelib/statemachine/qsignaltransition_p.h
+++ b/src/corelib/statemachine/qsignaltransition_p.h
@@ -53,12 +53,12 @@
// We mean it.
//
-#include "qactiontransition_p.h"
+#include "qabstracttransition_p.h"
QT_BEGIN_NAMESPACE
class QSignalTransition;
-class QSignalTransitionPrivate : public QActionTransitionPrivate
+class QSignalTransitionPrivate : public QAbstractTransitionPrivate
{
Q_DECLARE_PUBLIC(QSignalTransition)
public:
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index 28c84d5..56a855e 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -138,7 +138,7 @@ const QStatePrivate *QStatePrivate::get(const QState *q)
Constructs a new state with the given \a parent state.
*/
QState::QState(QState *parent)
- : QActionState(*new QStatePrivate, parent)
+ : QAbstractState(*new QStatePrivate, parent)
{
}
@@ -146,7 +146,7 @@ QState::QState(QState *parent)
Constructs a new state of the given \a type with the given \a parent state.
*/
QState::QState(Type type, QState *parent)
- : QActionState(*new QStatePrivate, parent)
+ : QAbstractState(*new QStatePrivate, parent)
{
Q_D(QState);
d->isParallelGroup = (type == ParallelGroup);
@@ -156,7 +156,7 @@ QState::QState(Type type, QState *parent)
\internal
*/
QState::QState(QStatePrivate &dd, QState *parent)
- : QActionState(dd, parent)
+ : QAbstractState(dd, parent)
{
}
@@ -385,7 +385,6 @@ QHistoryState *QState::addHistoryState(HistoryType type)
*/
void QState::onEntry()
{
- QActionState::onEntry();
}
/*!
@@ -393,7 +392,6 @@ void QState::onEntry()
*/
void QState::onExit()
{
- QActionState::onExit();
}
/*!
@@ -430,7 +428,7 @@ void QState::setInitialState(QAbstractState *state)
*/
bool QState::event(QEvent *e)
{
- return QActionState::event(e);
+ return QAbstractState::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
index 1ec0896..7c64c80 100644
--- a/src/corelib/statemachine/qstate.h
+++ b/src/corelib/statemachine/qstate.h
@@ -43,9 +43,9 @@
#define QSTATE_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include
+#include
#else
-#include "qactionstate.h"
+#include "qabstractstate.h"
#endif
QT_BEGIN_HEADER
@@ -60,7 +60,7 @@ class QSignalTransition;
class QStateFinishedTransition;
class QStatePrivate;
-class Q_CORE_EXPORT QState : public QActionState
+class Q_CORE_EXPORT QState : public QAbstractState
{
Q_OBJECT
public:
diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h
index 17b312a..8d040d0 100644
--- a/src/corelib/statemachine/qstate_p.h
+++ b/src/corelib/statemachine/qstate_p.h
@@ -53,14 +53,14 @@
// We mean it.
//
-#include "qactionstate_p.h"
+#include "qabstractstate_p.h"
#include
QT_BEGIN_NAMESPACE
class QState;
-class Q_CORE_EXPORT QStatePrivate : public QActionStatePrivate
+class Q_CORE_EXPORT QStatePrivate : public QAbstractStatePrivate
{
Q_DECLARE_PUBLIC(QState)
public:
diff --git a/src/corelib/statemachine/qstateaction.cpp b/src/corelib/statemachine/qstateaction.cpp
deleted file mode 100644
index 569d5d5..0000000
--- a/src/corelib/statemachine/qstateaction.cpp
+++ /dev/null
@@ -1,356 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qstateaction.h"
-#include "qstateaction_p.h"
-#include
-#include
-
-QT_BEGIN_NAMESPACE
-
-QStateActionPrivate::QStateActionPrivate()
-{
- when = ExecuteOnEntry;
-}
-
-QStateActionPrivate::~QStateActionPrivate()
-{
-}
-
-QStateActionPrivate *QStateActionPrivate::get(QStateAction *q)
-{
- return q->d_func();
-}
-
-void QStateActionPrivate::callExecute()
-{
- Q_Q(QStateAction);
- q->execute();
-}
-
-/*!
- \class QStateAction
-
- \brief The QStateAction class is the base class of QState actions.
-
- \since 4.6
- \ingroup statemachine
-
- A state action is added to a state by calling QActionState::addEntryAction()
- or QActionState::addExitAction(). QStateAction is part of \l{The State
- Machine Framework}.
-
- \section1 Subclassing
-
- Subclasses must implement the execute() function.
-*/
-
-/*!
- Constructs a new QStateAction object with the given \a parent.
-*/
-QStateAction::QStateAction(QObject *parent)
- : QObject(
-#ifndef QT_STATEMACHINE_SOLUTION
- *new QStateActionPrivate,
-#endif
- parent)
-#ifdef QT_STATEMACHINE_SOLUTION
- , d_ptr(new QStateActionPrivate)
-#endif
-{
-#ifdef QT_STATEMACHINE_SOLUTION
- d_ptr->q_ptr = this;
-#endif
-}
-
-/*!
- \internal
-*/
-QStateAction::QStateAction(QStateActionPrivate &dd, QObject *parent)
- : QObject(
-#ifndef QT_STATEMACHINE_SOLUTION
- dd,
-#endif
- parent)
-#ifdef QT_STATEMACHINE_SOLUTION
- , d_ptr(&dd)
-#endif
-{
-#ifdef QT_STATEMACHINE_SOLUTION
- d_ptr->q_ptr = this;
-#endif
-}
-
-/*!
- Destroys this QStateAction object.
-*/
-QStateAction::~QStateAction()
-{
-#ifdef QT_STATEMACHINE_SOLUTION
- delete d_ptr;
-#endif
-}
-
-/*!
- \fn QStateAction::execute()
-
- Executes this action.
-*/
-
-/*!
- \reimp
-*/
-bool QStateAction::event(QEvent *e)
-{
- return QObject::event(e);
-}
-
-QStateInvokeMethodActionPrivate *QStateInvokeMethodActionPrivate::get(QStateInvokeMethodAction *q)
-{
- return q->d_func();
-}
-
-/*!
- \class QStateInvokeMethodAction
-
- \brief The QStateInvokeMethodAction class provides an invoke method action for QObjects.
-
- \since 4.6
- \ingroup statemachine
-
- The QStateInvokeMethodAction class provides an action that calls a method of
- a QObject when a QState is entered or exited. QStateInvokeMethodAction is
- part of \l{The State Machine Framework}.
-
- Typically you don't construct QStateInvokeMethodAction objects directly, but
- rather call the QState::invokeMethodOnEntry() function or the
- QState::invokeMethodOnExit() function.
-*/
-
-/*!
- \property QStateInvokeMethodAction::arguments
-
- \brief the arguments to the method this action invokes
-*/
-
-/*!
- \property QStateInvokeMethodAction::methodName
-
- \brief the name of the method this action invokes
-*/
-
-/*!
- \property QStateInvokeMethodAction::target
-
- \brief the object on which this action invokes a method
-*/
-
-/*!
- Constructs a new QStateInvokeMethodAction object for the method named \a
- methodName of the given \a target object, with the given \a parent.
-*/
-QStateInvokeMethodAction::QStateInvokeMethodAction(
- QObject *target, const QByteArray &methodName, QObject *parent)
- : QStateAction(*new QStateInvokeMethodActionPrivate, parent)
-{
- Q_D(QStateInvokeMethodAction);
- d->target = target;
- d->methodName = methodName;
- d->methodIndex = -1;
-}
-
-/*!
- Constructs a new QStateInvokeMethodAction object for the method named \a
- methodName of the given \a target object, with the given arguments, \a args,
- and with the given \a parent.
-*/
-QStateInvokeMethodAction::QStateInvokeMethodAction(
- QObject *target, const QByteArray &methodName,
- const QList &args, QObject *parent)
- : QStateAction(*new QStateInvokeMethodActionPrivate, parent)
-{
- Q_D(QStateInvokeMethodAction);
- d->target = target;
- d->methodName = methodName;
- d->methodIndex = -1;
- d->args = args;
-}
-
-/*!
- Constructs a new QStateInvokeMethodAction object with the given \a parent.
-*/
-QStateInvokeMethodAction::QStateInvokeMethodAction(QObject *parent)
- : QStateAction(*new QStateInvokeMethodActionPrivate, parent)
-{
- Q_D(QStateInvokeMethodAction);
- d->target = 0;
- d->methodIndex = -1;
-}
-
-/*!
- Destroys this QStateInvokeMethodAction object.
-*/
-QStateInvokeMethodAction::~QStateInvokeMethodAction()
-{
-}
-
-/*!
- \reimp
-*/
-void QStateInvokeMethodAction::execute()
-{
- Q_D(QStateInvokeMethodAction);
- if (!d->target)
- return;
-
- if (d->methodIndex == -1) {
- QVarLengthArray sig;
- int len = d->methodName.length();
- if (len <= 0)
- return;
- sig.append(d->methodName, len);
- sig.append('(');
-
- int paramCount;
- for (paramCount = 0; paramCount < d->args.size() && paramCount < 10; ++paramCount) {
- const char *tn = d->args.at(paramCount).typeName();
- len = qstrlen(tn);
- if (len <= 0)
- break;
- sig.append(tn, len);
- sig.append(',');
- }
- if (paramCount == 0)
- sig.append(')'); // no parameters
- else
- sig[sig.size() - 1] = ')';
- sig.append('\0');
-
- const QMetaObject *meta = d->target->metaObject();
- int idx = meta->indexOfMethod(sig.constData());
- if (idx < 0) {
- QByteArray norm = QMetaObject::normalizedSignature(sig.constData());
- idx = meta->indexOfMethod(norm.constData());
- if ((idx < 0) || (idx >= meta->methodCount())) {
- qWarning("InvokeMethodAction: unable to find method '%s' of %s(%p)",
- sig.constData(), meta->className(), d->target);
- return;
- }
- }
- d->methodIndex = idx;
- }
-
- void *param[11];
- param[0] = 0; // return value
- for (int i = 0; i < 10; ++i)
- param[i+1] = (i < d->args.size()) ? const_cast(d->args.at(i).constData()) : (void*)0;
- (void)d->target->qt_metacall(QMetaObject::InvokeMetaMethod, d->methodIndex, param);
-}
-
-/*!
- Returns the object on which this action invokes a method.
-*/
-QObject *QStateInvokeMethodAction::targetObject() const
-{
- Q_D(const QStateInvokeMethodAction);
- return d->target;
-}
-
-/*!
- Sets the object on which this action invokes a method.
-*/
-void QStateInvokeMethodAction::setTargetObject(QObject *target)
-{
- Q_D(QStateInvokeMethodAction);
- d->target = target;
-}
-
-/*!
- Returns the name of the method this action will invoke.
-*/
-QByteArray QStateInvokeMethodAction::methodName() const
-{
- Q_D(const QStateInvokeMethodAction);
- return d->methodName;
-}
-
-/*!
- Sets the name of the method this action will invoke.
-*/
-void QStateInvokeMethodAction::setMethodName(const QByteArray &methodName)
-{
- Q_D(QStateInvokeMethodAction);
- if (methodName != d->methodName) {
- d->methodName = methodName;
- d->methodIndex = -1;
- }
-}
-
-/*!
- Returns the arguments to the method this action will invoke.
-*/
-QVariantList QStateInvokeMethodAction::arguments() const
-{
- Q_D(const QStateInvokeMethodAction);
- return d->args;
-}
-
-/*!
- Sets the arguments to the method this action will invoke.
-*/
-void QStateInvokeMethodAction::setArguments(const QVariantList &arguments)
-{
- Q_D(QStateInvokeMethodAction);
- if (d->args != arguments) {
- d->args = arguments;
- d->methodIndex = -1;
- }
-}
-
-/*!
- \reimp
-*/
-bool QStateInvokeMethodAction::event(QEvent *e)
-{
- return QStateAction::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstateaction.h b/src/corelib/statemachine/qstateaction.h
deleted file mode 100644
index 6843080..0000000
--- a/src/corelib/statemachine/qstateaction.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSTATEACTION_H
-#define QSTATEACTION_H
-
-#include
-
-#include
-#include
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QStateActionPrivate;
-class Q_CORE_EXPORT QStateAction : public QObject
-{
- Q_OBJECT
-public:
- ~QStateAction();
-
-protected:
- QStateAction(QObject *parent = 0);
-
- virtual void execute() = 0;
-
- bool event(QEvent *e);
-
-protected:
-#ifdef QT_STATEMACHINE_SOLUTION
- QStateActionPrivate *d_ptr;
-#endif
- QStateAction(QStateActionPrivate &dd, QObject *parent);
-
-private:
- Q_DISABLE_COPY(QStateAction)
- Q_DECLARE_PRIVATE(QStateAction)
-};
-
-class QStateInvokeMethodActionPrivate;
-class Q_CORE_EXPORT QStateInvokeMethodAction : public QStateAction
-{
- Q_OBJECT
- Q_PROPERTY(QObject* target READ targetObject WRITE setTargetObject)
- Q_PROPERTY(QByteArray methodName READ methodName WRITE setMethodName)
- Q_PROPERTY(QVariantList arguments READ arguments WRITE setArguments)
-public:
- QStateInvokeMethodAction(QObject *target, const QByteArray &methodName,
- QObject *parent = 0);
- QStateInvokeMethodAction(QObject *target, const QByteArray &methodName,
- const QList &args, QObject *parent = 0);
- QStateInvokeMethodAction(QObject *parent = 0);
- ~QStateInvokeMethodAction();
-
- QObject *targetObject() const;
- void setTargetObject(QObject *target);
-
- QByteArray methodName() const;
- void setMethodName(const QByteArray &methodName);
-
- QVariantList arguments() const;
- void setArguments(const QVariantList &arguments);
-
-protected:
- void execute();
-
- bool event(QEvent *e);
-
-private:
- Q_DISABLE_COPY(QStateInvokeMethodAction)
- Q_DECLARE_PRIVATE(QStateInvokeMethodAction)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/corelib/statemachine/qstateaction_p.h b/src/corelib/statemachine/qstateaction_p.h
deleted file mode 100644
index 4016b74..0000000
--- a/src/corelib/statemachine/qstateaction_p.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSTATEACTION_P_H
-#define QSTATEACTION_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QT_STATEMACHINE_SOLUTION
-#include
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class QStateAction;
-class QStateActionPrivate
-#ifndef QT_STATEMACHINE_SOLUTION
- : public QObjectPrivate
-#endif
-{
- Q_DECLARE_PUBLIC(QStateAction)
-public:
- QStateActionPrivate();
- ~QStateActionPrivate();
-
- static QStateActionPrivate *get(QStateAction *q);
-
- void callExecute();
-
- enum When {
- ExecuteOnEntry,
- ExecuteOnExit
- };
-
- When when;
-
-#ifdef QT_STATEMACHINE_SOLUTION
- QStateAction *q_ptr;
-#endif
-};
-
-class QStateInvokeMethodAction;
-class QStateInvokeMethodActionPrivate : public QStateActionPrivate
-{
- Q_DECLARE_PUBLIC(QStateInvokeMethodAction)
-public:
- QStateInvokeMethodActionPrivate() {}
- ~QStateInvokeMethodActionPrivate() {}
-
- static QStateInvokeMethodActionPrivate *get(QStateInvokeMethodAction *q);
-
- QObject *target;
- QByteArray methodName;
- int methodIndex;
- QList args;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/statemachine/qstatefinishedtransition.cpp b/src/corelib/statemachine/qstatefinishedtransition.cpp
index 33c3d22..151a274 100644
--- a/src/corelib/statemachine/qstatefinishedtransition.cpp
+++ b/src/corelib/statemachine/qstatefinishedtransition.cpp
@@ -41,7 +41,7 @@
#include "qstatefinishedtransition.h"
#include "qstatefinishedevent.h"
-#include "qactiontransition_p.h"
+#include "qabstracttransition_p.h"
QT_BEGIN_NAMESPACE
@@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE
\brief the state whose QStateFinishedEvent this transition is associated with
*/
-class QStateFinishedTransitionPrivate : public QActionTransitionPrivate
+class QStateFinishedTransitionPrivate : public QAbstractTransitionPrivate
{
Q_DECLARE_PUBLIC(QStateFinishedTransition)
public:
@@ -106,7 +106,7 @@ QStateFinishedTransitionPrivate *QStateFinishedTransitionPrivate::get(QStateFini
sourceState.
*/
QStateFinishedTransition::QStateFinishedTransition(QState *sourceState)
- : QActionTransition(*new QStateFinishedTransitionPrivate, sourceState)
+ : QAbstractTransition(*new QStateFinishedTransitionPrivate, sourceState)
{
}
@@ -116,7 +116,7 @@ QStateFinishedTransition::QStateFinishedTransition(QState *sourceState)
*/
QStateFinishedTransition::QStateFinishedTransition(
QState *state, const QList &targets, QState *sourceState)
- : QActionTransition(*new QStateFinishedTransitionPrivate, targets, sourceState)
+ : QAbstractTransition(*new QStateFinishedTransitionPrivate, targets, sourceState)
{
Q_D(QStateFinishedTransition);
d->state = state;
@@ -167,9 +167,16 @@ bool QStateFinishedTransition::eventTest(QEvent *event) const
/*!
\reimp
*/
+void QStateFinishedTransition::onTransition()
+{
+}
+
+/*!
+ \reimp
+*/
bool QStateFinishedTransition::event(QEvent *e)
{
- return QActionTransition::event(e);
+ return QAbstractTransition::event(e);
}
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstatefinishedtransition.h b/src/corelib/statemachine/qstatefinishedtransition.h
index f9320f5..ed86288 100644
--- a/src/corelib/statemachine/qstatefinishedtransition.h
+++ b/src/corelib/statemachine/qstatefinishedtransition.h
@@ -43,9 +43,9 @@
#define QSTATEFINISHEDTRANSITION_H
#ifndef QT_STATEMACHINE_SOLUTION
-#include
+#include
#else
-#include "qactiontransition.h"
+#include "qabstracttransition.h"
#endif
QT_BEGIN_HEADER
@@ -57,7 +57,7 @@ QT_MODULE(Core)
class QState;
class QStateFinishedTransitionPrivate;
-class Q_CORE_EXPORT QStateFinishedTransition : public QActionTransition
+class Q_CORE_EXPORT QStateFinishedTransition : public QAbstractTransition
{
Q_OBJECT
Q_PROPERTY(QState* state READ state WRITE setState)
@@ -72,6 +72,7 @@ public:
protected:
bool eventTest(QEvent *event) const;
+ void onTransition();
bool event(QEvent *e);
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 1f8d8a8..b6ab205 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -49,8 +49,6 @@
#include "qsignaleventgenerator_p.h"
#include "qabstractstate.h"
#include "qabstractstate_p.h"
-#include "qactionstate.h"
-#include "qactionstate_p.h"
#include "qfinalstate.h"
#include "qhistorystate.h"
#include "qhistorystate_p.h"
@@ -58,8 +56,6 @@
#include "qstatefinishedtransition.h"
#include "qstate.h"
#include "qstate_p.h"
-#include "qstateaction.h"
-#include "qstateaction_p.h"
#ifndef QT_STATEMACHINE_SOLUTION
#include "private/qobject_p.h"
#include "private/qthread_p.h"
@@ -417,6 +413,7 @@ QList QStateMachinePrivate::exitStates(const QListcallOnExit();
configuration.remove(s);
+ QAbstractStatePrivate::get(s)->emitExited();
}
return statesToExit_sorted;
}
@@ -504,6 +501,7 @@ QList QStateMachinePrivate::enterStates(const QListcallOnEntry();
+ QAbstractStatePrivate::get(s)->emitEntered();
if (statesForDefaultEntry.contains(s)) {
// ### executeContent(s.initial.transition.children())
}
@@ -1490,9 +1488,9 @@ void QStateMachine::clearError()
/*!
Returns the global restore policy of the state machine.
- \sa QActionState::restorePolicy()
+ \sa QAbstractState::restorePolicy()
*/
-QActionState::RestorePolicy QStateMachine::globalRestorePolicy() const
+QAbstractState::RestorePolicy QStateMachine::globalRestorePolicy() const
{
Q_D(const QStateMachine);
return d->globalRestorePolicy;
diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h
index f39efc7..901d160 100644
--- a/src/corelib/statemachine/qstatemachine.h
+++ b/src/corelib/statemachine/qstatemachine.h
@@ -43,9 +43,9 @@
#define QSTATEMACHINE_H
#ifndef QT_STATEMACHINE_SOLUTION
-# include
+# include
#else
-# include "qactionstate.h"
+# include "qabstractstate.h"
#endif
#include
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index a9fd2de..910b751 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -171,7 +171,7 @@ public:
QList externalEventQueue;
QStateMachine::Error error;
- QActionState::RestorePolicy globalRestorePolicy;
+ QAbstractState::RestorePolicy globalRestorePolicy;
QString errorString;
QSet pendingErrorStates;
diff --git a/src/corelib/statemachine/statemachine.pri b/src/corelib/statemachine/statemachine.pri
index 4179e45..620c7a0 100644
--- a/src/corelib/statemachine/statemachine.pri
+++ b/src/corelib/statemachine/statemachine.pri
@@ -1,12 +1,8 @@
HEADERS += $$PWD/qstatemachine.h \
$$PWD/qstatemachine_p.h \
- $$PWD/qstateaction.h \
- $$PWD/qstateaction_p.h \
$$PWD/qsignaleventgenerator_p.h \
$$PWD/qabstractstate.h \
$$PWD/qabstractstate_p.h \
- $$PWD/qactionstate.h \
- $$PWD/qactionstate_p.h \
$$PWD/qstate.h \
$$PWD/qstate_p.h \
$$PWD/qfinalstate.h \
@@ -14,8 +10,6 @@ HEADERS += $$PWD/qstatemachine.h \
$$PWD/qhistorystate_p.h \
$$PWD/qabstracttransition.h \
$$PWD/qabstracttransition_p.h \
- $$PWD/qactiontransition.h \
- $$PWD/qactiontransition_p.h \
$$PWD/qstatefinishedevent.h \
$$PWD/qstatefinishedtransition.h \
$$PWD/qsignalevent.h \
@@ -23,14 +17,11 @@ HEADERS += $$PWD/qstatemachine.h \
$$PWD/qsignaltransition_p.h
SOURCES += $$PWD/qstatemachine.cpp \
- $$PWD/qstateaction.cpp \
$$PWD/qabstractstate.cpp \
- $$PWD/qactionstate.cpp \
$$PWD/qstate.cpp \
$$PWD/qfinalstate.cpp \
$$PWD/qhistorystate.cpp \
$$PWD/qabstracttransition.cpp \
- $$PWD/qactiontransition.cpp \
$$PWD/qstatefinishedtransition.cpp \
$$PWD/qsignaltransition.cpp
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index b82055b..bf3ff71 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -45,7 +45,6 @@
#include "qstatemachine.h"
#include "qstate.h"
-#include "qactiontransition.h"
#include "qhistorystate.h"
#include "qkeyeventtransition.h"
#include "qmouseeventtransition.h"
@@ -102,8 +101,6 @@ private slots:
void signalTransitions();
void eventTransitions();
void historyStates();
- void stateActions();
- void transitionActions();
void transitionToRootState();
void transitionEntersParent();
@@ -226,15 +223,16 @@ void tst_QStateMachine::cleanup()
qInstallMsgHandler(s_oldHandler);
}
-class EventTransition : public QActionTransition
+class EventTransition : public QAbstractTransition
{
public:
EventTransition(QEvent::Type type, QAbstractState *target, QState *parent = 0)
- : QActionTransition(QList() << target, parent), m_type(type) {}
+ : QAbstractTransition(QList() << target, parent), m_type(type) {}
protected:
virtual bool eventTest(QEvent *e) const {
return (e->type() == m_type);
}
+ virtual void onTransition() {}
private:
QEvent::Type m_type;
};
@@ -1631,154 +1629,6 @@ void tst_QStateMachine::historyStates()
QTRY_COMPARE(finishedSpy.count(), 1);
}
-class TestStateAction : public QStateAction
-{
-public:
- TestStateAction() : m_didExecute(false)
- {}
- bool didExecute() const {
- return m_didExecute;
- }
-protected:
- void execute() {
- m_didExecute = true;
- }
-private:
- bool m_didExecute;
-};
-
-void tst_QStateMachine::stateActions()
-{
- QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
-
- QVERIFY(s1->entryActions().isEmpty());
- QVERIFY(s1->exitActions().isEmpty());
-
- QTest::ignoreMessage(QtWarningMsg, "QActionState::addEntryAction: cannot add null action");
- s1->addEntryAction(0);
- QTest::ignoreMessage(QtWarningMsg, "QActionState::addExitAction: cannot add null action");
- s1->addExitAction(0);
- QTest::ignoreMessage(QtWarningMsg, "QActionState::removeEntryAction: cannot remove null action");
- s1->removeEntryAction(0);
- QTest::ignoreMessage(QtWarningMsg, "QActionState::removeExitAction: cannot remove null action");
- s1->removeExitAction(0);
-
- QFinalState *s2 = new QFinalState(machine.rootState());
- s1->addTransition(s2);
-
- machine.setInitialState(s1);
- QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
-
- QObject *obj = new QObject();
- QStateInvokeMethodAction *ima = new QStateInvokeMethodAction(obj, "deleteLater");
- QPointer ptr(obj);
- QVERIFY(ptr != 0);
- s1->addEntryAction(ima);
- finishedSpy.clear();
- machine.start();
- QTRY_COMPARE(finishedSpy.count(), 1);
- QCoreApplication::processEvents();
- QVERIFY(ptr == 0);
-
- s1->removeEntryAction(ima);
-
- s1->invokeMethodOnEntry(ima, "deleteLater");
- QCOMPARE(s1->entryActions().size(), 1);
-
- ptr = ima;
- QVERIFY(ptr != 0);
- finishedSpy.clear();
- machine.start();
- QTRY_COMPARE(finishedSpy.count(), 1);
- QCoreApplication::processEvents();
- QVERIFY(ptr == 0);
-
- while (!s1->entryActions().isEmpty()) {
- QStateAction *act = s1->entryActions().first();
- s1->removeEntryAction(act);
- delete act;
- }
-
- TestStateAction *act1 = new TestStateAction();
- s1->addEntryAction(act1);
- TestStateAction *act2 = new TestStateAction();
- s1->addExitAction(act2);
- QVERIFY(!act1->didExecute());
- QVERIFY(!act2->didExecute());
-
- finishedSpy.clear();
- machine.start();
- QTRY_COMPARE(finishedSpy.count(), 1);
-
- QVERIFY(act1->didExecute());
- QVERIFY(act2->didExecute());
-
- QCOMPARE(s1->entryActions().size(), 1);
- QCOMPARE(s2->entryActions().size(), 0);
- s2->addEntryAction(act1); // should remove it from s1
- QCOMPARE(s1->entryActions().size(), 0);
- QCOMPARE(s2->entryActions().size(), 1);
- QCOMPARE(act1->parent(), (QObject*)s2);
-
- QCOMPARE(s2->exitActions().size(), 0);
- s2->addExitAction(act1); // should remove entry action
- QCOMPARE(s2->exitActions().size(), 1);
- QCOMPARE(s2->entryActions().size(), 0);
- QCOMPARE(act1->parent(), (QObject*)s2);
-}
-
-void tst_QStateMachine::transitionActions()
-{
- QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
-
- QFinalState *s2 = new QFinalState(machine.rootState());
- EventTransition *trans = new EventTransition(QEvent::User, s2);
- s1->addTransition(trans);
- QVERIFY(trans->actions().isEmpty());
- QTest::ignoreMessage(QtWarningMsg, "QActionTransition::addAction: cannot add null action");
- trans->addAction(0);
- QVERIFY(trans->actions().isEmpty());
-
- TestStateAction *act = new TestStateAction();
- trans->addAction(act);
- QCOMPARE(trans->actions().size(), 1);
- QCOMPARE(trans->actions().at(0), (QStateAction*)act);
- QCOMPARE(act->parent(), (QObject*)trans);
- QVERIFY(!act->didExecute());
-
- trans->removeAction(act);
- QVERIFY(trans->actions().isEmpty());
- QCOMPARE(act->parent(), (QObject*)0);
-
- trans->addAction(act);
-
- QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
- machine.setInitialState(s1);
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QCoreApplication::processEvents();
- QTRY_COMPARE(finishedSpy.count(), 1);
- QVERIFY(act->didExecute());
-
- trans->invokeMethodOnTransition(act, "deleteLater");
-
- QPointer ptr(act);
- QVERIFY(ptr != 0);
- finishedSpy.clear();
- machine.start();
- QCoreApplication::processEvents();
-
- machine.postEvent(new QEvent(QEvent::User));
- QCoreApplication::processEvents();
- QTRY_COMPARE(finishedSpy.count(), 1);
- QCoreApplication::processEvents();
- QVERIFY(ptr == 0);
-}
-
void tst_QStateMachine::defaultGlobalRestorePolicy()
{
QStateMachine machine;
@@ -2161,7 +2011,7 @@ void tst_QStateMachine::simpleAnimation()
QState *s3 = new QState(machine.rootState());
s2->addTransition(animation, SIGNAL(finished()), s3);
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
machine.setInitialState(s1);
machine.start();
@@ -2213,7 +2063,7 @@ void tst_QStateMachine::twoAnimations()
s1->addTransition(et);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(&machine, SIGNAL(animationsFinished()), s3);
machine.setInitialState(s1);
@@ -2245,7 +2095,7 @@ void tst_QStateMachine::twoAnimatedTransitions()
s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
QState *s4 = new QState(machine.rootState());
@@ -2254,7 +2104,7 @@ void tst_QStateMachine::twoAnimatedTransitions()
s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation2);
QState *s5 = new QState(machine.rootState());
- s5->invokeMethodOnEntry(QApplication::instance(), "quit");
+ QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
s4->addTransition(fooAnimation2, SIGNAL(finished()), s5);
machine.setInitialState(s1);
@@ -2289,7 +2139,7 @@ void tst_QStateMachine::playAnimationTwice()
s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
QState *s4 = new QState(machine.rootState());
@@ -2297,7 +2147,7 @@ void tst_QStateMachine::playAnimationTwice()
s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation);
QState *s5 = new QState(machine.rootState());
- s5->invokeMethodOnEntry(QApplication::instance(), "quit");
+ QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
s4->addTransition(fooAnimation, SIGNAL(finished()), s5);
machine.setInitialState(s1);
@@ -2355,7 +2205,7 @@ void tst_QStateMachine::nestedTargetStateForAnimation()
at->addAnimation(animation);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(&machine, SIGNAL(animationsFinished()), s3);
machine.setInitialState(s1);
@@ -2388,7 +2238,7 @@ void tst_QStateMachine::animatedGlobalRestoreProperty()
QState *s3 = new QState(machine.rootState());
QState *s4 = new QState(machine.rootState());
- s4->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s4, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", s2);
@@ -2435,7 +2285,7 @@ void tst_QStateMachine::specificTargetValueOfAnimation()
s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(anim);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(anim, SIGNAL(finished()), s3);
machine.setInitialState(s1);
@@ -2463,7 +2313,7 @@ void tst_QStateMachine::addDefaultAnimation()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2498,7 +2348,7 @@ void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2536,7 +2386,7 @@ void tst_QStateMachine::addDefaultAnimationForSource()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2568,7 +2418,7 @@ void tst_QStateMachine::addDefaultAnimationForTarget()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2726,7 +2576,7 @@ void tst_QStateMachine::overrideDefaultAnimationWithSource()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2766,7 +2616,7 @@ void tst_QStateMachine::overrideDefaultAnimationWithTarget()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2807,7 +2657,7 @@ void tst_QStateMachine::overrideDefaultAnimationWithSpecific()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2847,7 +2697,7 @@ void tst_QStateMachine::overrideDefaultSourceAnimationWithSpecific()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2887,7 +2737,7 @@ void tst_QStateMachine::overrideDefaultTargetAnimationWithSpecific()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -2927,7 +2777,7 @@ void tst_QStateMachine::overrideDefaultTargetAnimationWithSource()
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(machine.rootState());
- s3->invokeMethodOnEntry(QCoreApplication::instance(), "quit");
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
--
cgit v0.12
From 44548c4e02061ec14ba126a857665593e1aca642 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Thu, 23 Apr 2009 09:33:52 +0200
Subject: Remove specific RestorePolicy per state from example. The semantics
for this have changed to something which is more intuitive, so it is no
longer useful for this case.
---
examples/animation/stickman/lifecycle.cpp | 12 ------------
examples/animation/stickman/lifecycle.h | 1 -
examples/animation/stickman/main.cpp | 2 --
3 files changed, 15 deletions(-)
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
index e67b32d..67dd209 100644
--- a/examples/animation/stickman/lifecycle.cpp
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -70,14 +70,12 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
// Set up intial state graph
m_machine = new QStateMachine();
- m_machine->setGlobalRestorePolicy(QState::RestoreProperties);
m_alive = new QState(m_machine->rootState());
m_alive->setObjectName("alive");
// Make it blink when lightning strikes before entering dead animation
QState *lightningBlink = new QState(m_machine->rootState());
- lightningBlink->setRestorePolicy(QState::DoNotRestoreProperties);
lightningBlink->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::white);
lightningBlink->assignProperty(m_stickMan, "penColor", Qt::black);
lightningBlink->assignProperty(m_stickMan, "fillColor", Qt::white);
@@ -90,7 +88,6 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
QObject::connect(lightningBlink, SIGNAL(exited()), timer, SLOT(stop()));
m_dead = new QState(m_machine->rootState());
- m_dead->setRestorePolicy(QState::DoNotRestoreProperties);
m_dead->assignProperty(m_stickMan->scene(), "backgroundBrush", Qt::black);
m_dead->assignProperty(m_stickMan, "penColor", Qt::white);
m_dead->assignProperty(m_stickMan, "fillColor", Qt::black);
@@ -110,15 +107,6 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
m_machine->setInitialState(m_alive);
}
-void LifeCycle::setResetKey(Qt::Key resetKey)
-{
- // When resetKey is pressed, enter the idle state and do a restoration animation
- // (requires no animation pointer, since no property is being set in the idle state)
- KeyPressTransition *trans = new KeyPressTransition(m_keyReceiver, resetKey, m_idle);
- trans->addAnimation(m_animationGroup);
- m_alive->addTransition(trans);
-}
-
void LifeCycle::setDeathAnimation(const QString &fileName)
{
QState *deathAnimation = makeState(m_dead, fileName);
diff --git a/examples/animation/stickman/lifecycle.h b/examples/animation/stickman/lifecycle.h
index 437e935..58372f4 100644
--- a/examples/animation/stickman/lifecycle.h
+++ b/examples/animation/stickman/lifecycle.h
@@ -17,7 +17,6 @@ public:
~LifeCycle();
void setDeathAnimation(const QString &fileName);
- void setResetKey(Qt::Key key);
void addActivity(const QString &fileName, Qt::Key key);
void start();
diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp
index 62860ec..8fc0077 100644
--- a/examples/animation/stickman/main.cpp
+++ b/examples/animation/stickman/main.cpp
@@ -23,7 +23,6 @@ int main(int argc, char **argv)
"Press J to make the stickman jump."
"Press D to make the stickman dance."
"Press C to make him chill out."
- "Press Return to make him return to his original position."
"When you are done, press Escape."
"
"
"If he is unlucky, the stickman will get struck by lightning, and never jump, dance or chill out again."
@@ -46,7 +45,6 @@ int main(int argc, char **argv)
view->setSceneRect(scene->sceneRect());
LifeCycle *cycle = new LifeCycle(stickMan, view);
- cycle->setResetKey(Qt::Key_Return);
cycle->setDeathAnimation("animations/dead");
cycle->addActivity("animations/jumping", Qt::Key_J);
--
cgit v0.12
From 404db2ceac0ad4770c77f42e8f8a9cd003b151a1 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Thu, 23 Apr 2009 11:22:07 +0200
Subject: Compile.
---
examples/animation/piemenu/qgraphicspiemenu_p.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/examples/animation/piemenu/qgraphicspiemenu_p.h b/examples/animation/piemenu/qgraphicspiemenu_p.h
index 87a749c..93b0079 100644
--- a/examples/animation/piemenu/qgraphicspiemenu_p.h
+++ b/examples/animation/piemenu/qgraphicspiemenu_p.h
@@ -17,7 +17,6 @@
#include
#include
-#include
#include
class QAction;
@@ -34,7 +33,6 @@ public:
QString title;
QStateMachine *machine;
QState *popupState;
- //QTransition *transition;
QList sections;
QEventLoop *eventLoop;
--
cgit v0.12
From ad1441fcb1c66ddafd890c1aa22a631d12c4ee0d Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Thu, 23 Apr 2009 11:46:02 +0200
Subject: Remove API for setting specific restore policies on states. We have
no clear use case for this, so it has been removed. If the requirement arises
we can add it back in later. Since it no longer makes sense to have it in
QAbstractState, the RestorePolicy enum has been moved to QStateMachine.
---
examples/animation/appchooser/main.cpp | 2 +-
src/corelib/statemachine/qabstractstate.cpp | 60 +-------------------------
src/corelib/statemachine/qabstractstate.h | 11 -----
src/corelib/statemachine/qabstractstate_p.h | 1 -
src/corelib/statemachine/qstatemachine.cpp | 54 ++++++++++++++---------
src/corelib/statemachine/qstatemachine.h | 10 ++++-
src/corelib/statemachine/qstatemachine_p.h | 2 +-
tests/auto/qstate/tst_qstate.cpp | 25 ++---------
tests/auto/qstatemachine/tst_qstatemachine.cpp | 41 ++++++++++--------
9 files changed, 73 insertions(+), 133 deletions(-)
diff --git a/examples/animation/appchooser/main.cpp b/examples/animation/appchooser/main.cpp
index 1a43ed7..6735012 100644
--- a/examples/animation/appchooser/main.cpp
+++ b/examples/animation/appchooser/main.cpp
@@ -104,7 +104,7 @@ int main(int argc, char **argv)
window.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QState *group = new QState(machine.rootState());
group->setObjectName("group");
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index 030c63c..396063a 100644
--- a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -76,45 +76,7 @@ QT_BEGIN_NAMESPACE
function to perform custom processing when the state is exited.
*/
-/*!
- \enum QAbstractState::RestorePolicy
-
- This enum specifies the restore policy type for a state. The restore policy
- takes effect when the machine enters a state which sets one or more
- properties. If the restore policy of the state is set to RestoreProperties,
- the state machine will save the original value of the property before the
- new value is set.
-
- Later, when the machine either enters a state which has its restore policy
- set to DoNotRestoreProperties or when it enters a state which does not set
- a value for the given property, the property will automatically be restored
- to its initial value.
-
- Only one initial value will be saved for any given property. If a value for a property has
- already been saved by the state machine, it will not be overwritten until the property has been
- successfully restored. Once the property has been restored, the state machine will clear the
- initial value until it enters a new state which sets the property and which has RestoreProperties
- as its restore policy.
-
- \value GlobalRestorePolicy The restore policy for the state should be retrieved using
- QStateMachine::globalRestorePolicy()
- \value DoNotRestoreProperties The state machine should not save the initial values of properties
- set in the state and restore them later.
- \value RestoreProperties The state machine should save the initial values of properties
- set in the state and restore them later.
-
-
- \sa setRestorePolicy(), restorePolicy(), QAbstractState::assignProperty()
-*/
-
-/*!
- \property QAbstractState::restorePolicy
-
- \brief the restore policy of this state
-*/
-
-QAbstractStatePrivate::QAbstractStatePrivate()
- : restorePolicy(QAbstractState::GlobalRestorePolicy)
+QAbstractStatePrivate::QAbstractStatePrivate()
{
}
@@ -237,26 +199,6 @@ void QAbstractState::assignProperty(QObject *object, const char *name,
}
/*!
- Sets the restore policy of this state to \a restorePolicy.
-
- The default restore policy is QAbstractState::GlobalRestorePolicy.
-*/
-void QAbstractState::setRestorePolicy(RestorePolicy restorePolicy)
-{
- Q_D(QAbstractState);
- d->restorePolicy = restorePolicy;
-}
-
-/*!
- Returns the restore policy for this state.
-*/
-QAbstractState::RestorePolicy QAbstractState::restorePolicy() const
-{
- Q_D(const QAbstractState);
- return d->restorePolicy;
-}
-
-/*!
\fn QAbstractState::onExit()
This function is called when the state is exited. Reimplement this function
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index 55e9a62..69e6bf1 100644
--- a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -56,15 +56,7 @@ class QAbstractStatePrivate;
class Q_CORE_EXPORT QAbstractState : public QObject
{
Q_OBJECT
- Q_ENUMS(RestorePolicy)
- Q_PROPERTY(RestorePolicy restorePolicy READ restorePolicy WRITE setRestorePolicy)
public:
- enum RestorePolicy {
- GlobalRestorePolicy,
- DoNotRestoreProperties,
- RestoreProperties
- };
-
~QAbstractState();
QState *parentState() const;
@@ -72,9 +64,6 @@ public:
void assignProperty(QObject *object, const char *name,
const QVariant &value);
- void setRestorePolicy(RestorePolicy restorePolicy);
- RestorePolicy restorePolicy() const;
-
Q_SIGNALS:
void entered();
void exited();
diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h
index e47fbd2..8c8f436 100644
--- a/src/corelib/statemachine/qabstractstate_p.h
+++ b/src/corelib/statemachine/qabstractstate_p.h
@@ -101,7 +101,6 @@ public:
void emitEntered();
void emitExited();
- QAbstractState::RestorePolicy restorePolicy;
QList propertyAssignments;
#ifdef QT_STATEMACHINE_SOLUTION
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index b6ab205..2d3eea1 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -188,7 +188,7 @@ QStateMachinePrivate::QStateMachinePrivate()
processingScheduled = false;
stop = false;
error = QStateMachine::NoError;
- globalRestorePolicy = QAbstractState::DoNotRestoreProperties;
+ globalRestorePolicy = QStateMachine::DoNotRestoreProperties;
rootState = 0;
initialErrorStateForRoot = 0;
#ifndef QT_STATEMACHINE_SOLUTION
@@ -631,14 +631,10 @@ void QStateMachinePrivate::applyProperties(const QList &tr
for (int i = 0; i < enteredStates.size(); ++i) {
QAbstractState *s = enteredStates.at(i);
- QAbstractState::RestorePolicy restorePolicy = s->restorePolicy();
- if (restorePolicy == QAbstractState::GlobalRestorePolicy)
- restorePolicy = globalRestorePolicy;
-
QList assignments = QAbstractStatePrivate::get(s)->propertyAssignments;
for (int j = 0; j < assignments.size(); ++j) {
const QPropertyAssignment &assn = assignments.at(j);
- if (restorePolicy == QAbstractState::RestoreProperties) {
+ if (globalRestorePolicy == QStateMachine::RestoreProperties) {
registerRestorable(assn.object, assn.propertyName);
}
pendingRestorables.remove(RestorableId(assn.object, assn.propertyName));
@@ -1458,6 +1454,32 @@ void QStateMachine::setErrorState(QAbstractState *state)
*/
/*!
+ \enum QStateMachine::RestorePolicy
+
+ This enum specifies the restore policy type. The restore policy
+ takes effect when the machine enters a state which sets one or more
+ properties. If the restore policy is set to RestoreProperties,
+ the state machine will save the original value of the property before the
+ new value is set.
+
+ Later, when the machine either enters a state which does not set
+ a value for the given property, the property will automatically be restored
+ to its initial value.
+
+ Only one initial value will be saved for any given property. If a value for a property has
+ already been saved by the state machine, it will not be overwritten until the property has been
+ successfully restored.
+
+ \value DoNotRestoreProperties The state machine should not save the initial values of properties
+ and restore them later.
+ \value RestoreProperties The state machine should save the initial values of properties
+ and restore them later.
+
+ \sa setRestorePolicy(), restorePolicy(), QAbstractState::assignProperty()
+*/
+
+
+/*!
Returns the error code of the last error that occurred in the state machine.
*/
QStateMachine::Error QStateMachine::error() const
@@ -1486,33 +1508,25 @@ void QStateMachine::clearError()
}
/*!
- Returns the global restore policy of the state machine.
+ Returns the restore policy of the state machine.
- \sa QAbstractState::restorePolicy()
+ \sa setGlobalRestorePolicy()
*/
-QAbstractState::RestorePolicy QStateMachine::globalRestorePolicy() const
+QStateMachine::RestorePolicy QStateMachine::globalRestorePolicy() const
{
Q_D(const QStateMachine);
return d->globalRestorePolicy;
}
/*!
- Sets the global restore policy of the state machine to \a restorePolicy. The default global
+ Sets the restore policy of the state machine to \a restorePolicy. The default
restore policy is QAbstractState::DoNotRestoreProperties.
- The global restore policy cannot be set to QAbstractState::GlobalRestorePolicy.
-
- \sa QAbstractState::setRestorePolicy()
+ \sa globalRestorePolicy()
*/
-void QStateMachine::setGlobalRestorePolicy(QAbstractState::RestorePolicy restorePolicy)
+void QStateMachine::setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy)
{
Q_D(QStateMachine);
- if (restorePolicy == QState::GlobalRestorePolicy) {
- qWarning("QStateMachine::setGlobalRestorePolicy: Cannot set global restore policy to "
- "GlobalRestorePolicy");
- return;
- }
-
d->globalRestorePolicy = restorePolicy;
}
diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h
index 901d160..9a7a6fc 100644
--- a/src/corelib/statemachine/qstatemachine.h
+++ b/src/corelib/statemachine/qstatemachine.h
@@ -72,7 +72,13 @@ class Q_CORE_EXPORT QStateMachine : public QObject
Q_PROPERTY(QAbstractState* initialState READ initialState WRITE setInitialState)
Q_PROPERTY(QAbstractState* errorState READ errorState WRITE setErrorState)
Q_PROPERTY(QString errorString READ errorString)
+ Q_PROPERTY(RestorePolicy globalRestorePolicy READ globalRestorePolicy WRITE setGlobalRestorePolicy)
+ Q_ENUMS(RestorePolicy)
public:
+ enum RestorePolicy {
+ DoNotRestoreProperties,
+ RestoreProperties
+ };
enum Error {
NoError,
@@ -112,8 +118,8 @@ public:
void removeDefaultAnimationForTargetState(QAbstractState *targetState, QAbstractAnimation *animation);
#endif // QT_NO_ANIMATION
- QAbstractState::RestorePolicy globalRestorePolicy() const;
- void setGlobalRestorePolicy(QAbstractState::RestorePolicy restorePolicy);
+ QStateMachine::RestorePolicy globalRestorePolicy() const;
+ void setGlobalRestorePolicy(QStateMachine::RestorePolicy restorePolicy);
void postEvent(QEvent *event, int delay = 0);
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 910b751..9f93217 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -171,7 +171,7 @@ public:
QList externalEventQueue;
QStateMachine::Error error;
- QAbstractState::RestorePolicy globalRestorePolicy;
+ QStateMachine::RestorePolicy globalRestorePolicy;
QString errorString;
QSet pendingErrorStates;
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp
index f79fcd4..f082caf 100644
--- a/tests/auto/qstate/tst_qstate.cpp
+++ b/tests/auto/qstate/tst_qstate.cpp
@@ -9,9 +9,7 @@
#include "qstate.h"
#include "qstatemachine.h"
-#include "qactiontransition.h"
#include "qsignaltransition.h"
-#include "qstateaction.h"
// Will try to wait for the condition while allowing event processing
#define QTRY_COMPARE(__expr, __expected) \
@@ -45,7 +43,6 @@ private slots:
void assignProperty();
void assignPropertyTwice();
void historyInitialState();
- void addEntryAction();
private:
bool functionCalled;
@@ -214,22 +211,6 @@ public slots:
};
-void tst_QState::addEntryAction()
-{
- QStateMachine sm;
-
- TestClass testObject;
-
- QState *s0 = new QState(sm.rootState());
- s0->addEntryAction(new QStateInvokeMethodAction(&testObject, "slot"));
- sm.setInitialState(s0);
-
- sm.start();
- QCoreApplication::processEvents();
-
- QCOMPARE(testObject.called, true);
-}
-
void tst_QState::assignProperty()
{
QStateMachine machine;
@@ -265,11 +246,11 @@ void tst_QState::assignPropertyTwice()
QCOMPARE(object->property("fooBar").toInt(), 30);
}
-class EventTestTransition: public QActionTransition
+class EventTestTransition: public QAbstractTransition
{
public:
EventTestTransition(QEvent::Type type, QState *targetState)
- : QActionTransition(QList() << targetState), m_type(type)
+ : QAbstractTransition(QList() << targetState), m_type(type)
{
}
@@ -279,6 +260,8 @@ protected:
return e->type() == m_type;
}
+ void onTransition() {}
+
private:
QEvent::Type m_type;
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index bf3ff71..2fa9b1a 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -121,14 +121,17 @@ private slots:
void customErrorStateNotInGraph();
void transitionToStateNotInGraph();
void restoreProperties();
+
void defaultGlobalRestorePolicy();
void globalRestorePolicySetToRestore();
void globalRestorePolicySetToDoNotRestore();
- void restorePolicyNotInherited();
- void mixedRestoreProperties();
- void setRestorePolicyToDoNotRestore();
- void setGlobalRestorePolicyToGlobalRestore();
- void restorePolicyOnChildState();
+
+ //void restorePolicyNotInherited();
+ //void mixedRestoreProperties();
+ //void setRestorePolicyToDoNotRestore();
+ //void setGlobalRestorePolicyToGlobalRestore();
+ //void restorePolicyOnChildState();
+
void transitionWithParent();
void simpleAnimation();
@@ -923,22 +926,20 @@ void tst_QStateMachine::restoreProperties()
object->setProperty("b", 2);
QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QState *S1 = new QState();
S1->setObjectName("S1");
S1->assignProperty(object, "a", 3);
- S1->setRestorePolicy(QState::RestoreProperties);
machine.addState(S1);
QState *S2 = new QState();
S2->setObjectName("S2");
S2->assignProperty(object, "b", 5);
- S2->setRestorePolicy(QState::RestoreProperties);
machine.addState(S2);
QState *S3 = new QState();
S3->setObjectName("S3");
- S3->setRestorePolicy(QState::RestoreProperties);
machine.addState(S3);
QFinalState *S4 = new QFinalState();
@@ -1668,6 +1669,7 @@ void tst_QStateMachine::defaultGlobalRestorePolicy()
QCOMPARE(propertyHolder->property("b").toInt(), 4);
}
+/*
void tst_QStateMachine::restorePolicyNotInherited()
{
QStateMachine machine;
@@ -1714,12 +1716,12 @@ void tst_QStateMachine::restorePolicyNotInherited()
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 4);
-}
+}*/
void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
{
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::DoNotRestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::DoNotRestoreProperties);
QObject *propertyHolder = new QObject();
propertyHolder->setProperty("a", 1);
@@ -1756,6 +1758,7 @@ void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
QCOMPARE(propertyHolder->property("b").toInt(), 4);
}
+/*
void tst_QStateMachine::setRestorePolicyToDoNotRestore()
{
QObject *object = new QObject();
@@ -1812,19 +1815,20 @@ void tst_QStateMachine::setGlobalRestorePolicyToGlobalRestore()
{
s_countWarnings = false;
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::GlobalRestorePolicy);
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
- QCOMPARE(machine.globalRestorePolicy(), QState::DoNotRestoreProperties);
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties);
QCOMPARE(s_msgType, QtWarningMsg);
s_msgType = QtDebugMsg;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
- machine.setGlobalRestorePolicy(QState::GlobalRestorePolicy);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
- QCOMPARE(machine.globalRestorePolicy(), QState::RestoreProperties);
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::RestoreProperties);
QCOMPARE(s_msgType, QtWarningMsg);
}
+
void tst_QStateMachine::restorePolicyOnChildState()
{
QStateMachine machine;
@@ -1873,11 +1877,12 @@ void tst_QStateMachine::restorePolicyOnChildState()
QCOMPARE(propertyHolder->property("a").toInt(), 1);
QCOMPARE(propertyHolder->property("b").toInt(), 2);
}
+*/
void tst_QStateMachine::globalRestorePolicySetToRestore()
{
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QObject *propertyHolder = new QObject();
propertyHolder->setProperty("a", 1);
@@ -1914,6 +1919,7 @@ void tst_QStateMachine::globalRestorePolicySetToRestore()
QCOMPARE(propertyHolder->property("b").toInt(), 2);
}
+/*
void tst_QStateMachine::mixedRestoreProperties()
{
QStateMachine machine;
@@ -1980,6 +1986,7 @@ void tst_QStateMachine::mixedRestoreProperties()
// Enter s3, restore
QCOMPARE(propertyHolder->property("a").toInt(), 5);
}
+*/
void tst_QStateMachine::transitionWithParent()
{
@@ -2224,7 +2231,7 @@ void tst_QStateMachine::nestedTargetStateForAnimation()
void tst_QStateMachine::animatedGlobalRestoreProperty()
{
QStateMachine machine;
- machine.setGlobalRestorePolicy(QState::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
QObject *object = new QObject();
object->setProperty("foo", 1.0);
--
cgit v0.12
From a8cce89940e42fb05efef049122286652bae61e3 Mon Sep 17 00:00:00 2001
From: Alexis Menard
Date: Fri, 24 Apr 2009 17:04:19 +0200
Subject: Add an OSD to display game progress in the scene
---
examples/animation/sub-attaq/boat.cpp | 79 ++++++++++++++++-------
examples/animation/sub-attaq/boat.h | 6 ++
examples/animation/sub-attaq/boat_p.h | 6 +-
examples/animation/sub-attaq/graphicsscene.cpp | 22 +++++--
examples/animation/sub-attaq/graphicsscene.h | 5 ++
examples/animation/sub-attaq/progressitem.cpp | 67 +++++++++++++++++++
examples/animation/sub-attaq/progressitem.h | 61 ++++++++++++++++++
examples/animation/sub-attaq/states.cpp | 89 +++++++++++++++++++-------
examples/animation/sub-attaq/states.h | 31 ++++++++-
examples/animation/sub-attaq/sub-attaq.pro | 11 ++--
examples/animation/sub-attaq/submarine.cpp | 8 +--
11 files changed, 320 insertions(+), 65 deletions(-)
create mode 100644 examples/animation/sub-attaq/progressitem.cpp
create mode 100644 examples/animation/sub-attaq/progressitem.h
diff --git a/examples/animation/sub-attaq/boat.cpp b/examples/animation/sub-attaq/boat.cpp
index 5721485..5b270c0 100644
--- a/examples/animation/sub-attaq/boat.cpp
+++ b/examples/animation/sub-attaq/boat.cpp
@@ -99,10 +99,30 @@ static QAbstractAnimation *setupDestroyAnimation(Boat *boat)
anim4->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
anim4->setDuration(100);
anim4->setEndValue(1);
+ CustomPropertyAnimation *anim5 = new CustomPropertyAnimation(boat);
+ anim5->setMemberFunctions((QGraphicsItem*)step1, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim5->setDuration(100);
+ anim5->setEndValue(0);
+ CustomPropertyAnimation *anim6 = new CustomPropertyAnimation(boat);
+ anim6->setMemberFunctions((QGraphicsItem*)step2, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim6->setDuration(100);
+ anim6->setEndValue(0);
+ CustomPropertyAnimation *anim7 = new CustomPropertyAnimation(boat);
+ anim7->setMemberFunctions((QGraphicsItem*)step3, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim7->setDuration(100);
+ anim7->setEndValue(0);
+ CustomPropertyAnimation *anim8 = new CustomPropertyAnimation(boat);
+ anim8->setMemberFunctions((QGraphicsItem*)step4, &QGraphicsItem::opacity, &QGraphicsItem::setOpacity);
+ anim8->setDuration(100);
+ anim8->setEndValue(0);
group->addAnimation(anim1);
group->addAnimation(anim2);
group->addAnimation(anim3);
group->addAnimation(anim4);
+ group->addAnimation(anim5);
+ group->addAnimation(anim6);
+ group->addAnimation(anim7);
+ group->addAnimation(anim8);
#else
// work around for a bug where we don't transition if the duration is zero.
QtPauseAnimation *anim = new QtPauseAnimation(group);
@@ -126,37 +146,39 @@ Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags)
//The movement animation used to animate the boat
movementAnimation = new QPropertyAnimation(this, "pos");
- AnimationManager::self()->registerAnimation(movementAnimation);
+
+ //The movement animation used to animate the boat
+ destroyAnimation = setupDestroyAnimation(this);
//We setup the state machien of the boat
- QStateMachine *machine = new QStateMachine(this);
+ machine = new QStateMachine(this);
QState *moving = new QState(machine->rootState());
- StopState *stopState = new StopState(this,moving);
+ StopState *stopState = new StopState(this, moving);
machine->setInitialState(moving);
moving->setInitialState(stopState);
- MoveStateRight *moveStateRight = new MoveStateRight(this,moving);
- MoveStateLeft *moveStateLeft = new MoveStateLeft(this,moving);
- LaunchStateRight *launchStateRight = new LaunchStateRight(this,machine->rootState());
- LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this,machine->rootState());
+ MoveStateRight *moveStateRight = new MoveStateRight(this, moving);
+ MoveStateLeft *moveStateLeft = new MoveStateLeft(this, moving);
+ LaunchStateRight *launchStateRight = new LaunchStateRight(this, machine->rootState());
+ LaunchStateLeft *launchStateLeft = new LaunchStateLeft(this, machine->rootState());
//then setup the transitions for the rightMove state
- KeyStopTransition *leftStopRight = new KeyStopTransition(this,QEvent::KeyPress,Qt::Key_Left);
+ KeyStopTransition *leftStopRight = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Left);
leftStopRight->setTargetState(stopState);
- KeyMoveTransition *leftMoveRight = new KeyMoveTransition(this,QEvent::KeyPress,Qt::Key_Left);
+ KeyMoveTransition *leftMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Left);
leftMoveRight->setTargetState(moveStateRight);
- KeyMoveTransition *rightMoveRight = new KeyMoveTransition(this,QEvent::KeyPress,Qt::Key_Right);
+ KeyMoveTransition *rightMoveRight = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right);
rightMoveRight->setTargetState(moveStateRight);
- KeyMoveTransition *rightMoveStop = new KeyMoveTransition(this,QEvent::KeyPress,Qt::Key_Right);
+ KeyMoveTransition *rightMoveStop = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right);
rightMoveStop->setTargetState(moveStateRight);
//then setup the transitions for the leftMove state
- KeyStopTransition *rightStopLeft = new KeyStopTransition(this,QEvent::KeyPress,Qt::Key_Right);
+ KeyStopTransition *rightStopLeft = new KeyStopTransition(this, QEvent::KeyPress, Qt::Key_Right);
rightStopLeft->setTargetState(stopState);
- KeyMoveTransition *rightMoveLeft = new KeyMoveTransition(this,QEvent::KeyPress,Qt::Key_Right);
+ KeyMoveTransition *rightMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress, Qt::Key_Right);
rightMoveLeft->setTargetState(moveStateLeft);
- KeyMoveTransition *leftMoveLeft = new KeyMoveTransition(this,QEvent::KeyPress,Qt::Key_Left);
+ KeyMoveTransition *leftMoveLeft = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left);
leftMoveLeft->setTargetState(moveStateLeft);
- KeyMoveTransition *leftMoveStop = new KeyMoveTransition(this,QEvent::KeyPress,Qt::Key_Left);
+ KeyMoveTransition *leftMoveStop = new KeyMoveTransition(this, QEvent::KeyPress,Qt::Key_Left);
leftMoveStop->setTargetState(moveStateLeft);
//We set up the right move state
@@ -176,17 +198,17 @@ Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags)
moveStateRight->addTransition(movementAnimation, SIGNAL(finished()), stopState);
//We set up the keys for dropping bombs
- KeyLaunchTransition *upFireLeft = new KeyLaunchTransition(this,QEvent::KeyPress,Qt::Key_Up);
+ KeyLaunchTransition *upFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up);
upFireLeft->setTargetState(launchStateRight);
- KeyLaunchTransition *upFireRight = new KeyLaunchTransition(this,QEvent::KeyPress,Qt::Key_Up);
+ KeyLaunchTransition *upFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up);
upFireRight->setTargetState(launchStateRight);
- KeyLaunchTransition *upFireStop = new KeyLaunchTransition(this,QEvent::KeyPress,Qt::Key_Up);
+ KeyLaunchTransition *upFireStop = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Up);
upFireStop->setTargetState(launchStateRight);
- KeyLaunchTransition *downFireLeft = new KeyLaunchTransition(this,QEvent::KeyPress,Qt::Key_Down);
+ KeyLaunchTransition *downFireLeft = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down);
downFireLeft->setTargetState(launchStateLeft);
- KeyLaunchTransition *downFireRight = new KeyLaunchTransition(this,QEvent::KeyPress,Qt::Key_Down);
+ KeyLaunchTransition *downFireRight = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down);
downFireRight->setTargetState(launchStateLeft);
- KeyLaunchTransition *downFireMove = new KeyLaunchTransition(this,QEvent::KeyPress,Qt::Key_Down);
+ KeyLaunchTransition *downFireMove = new KeyLaunchTransition(this, QEvent::KeyPress, Qt::Key_Down);
downFireMove->setTargetState(launchStateLeft);
//We set up transitions for fire up
@@ -208,7 +230,7 @@ Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags)
//This state play the destroyed animation
QAnimationState *destroyedState = new QAnimationState(machine->rootState());
- destroyedState->setAnimation(setupDestroyAnimation(this));
+ destroyedState->setAnimation(destroyAnimation);
//Play a nice animation when the boat is destroyed
moving->addTransition(this, SIGNAL(boatDestroyed()),destroyedState);
@@ -219,9 +241,22 @@ Boat::Boat(QGraphicsItem * parent, Qt::WindowFlags wFlags)
//The machine has finished to be executed, then the boat is dead
connect(machine,SIGNAL(finished()),this, SIGNAL(boatExecutionFinished()));
+}
+
+void Boat::run()
+{
+ //We register animations
+ AnimationManager::self()->registerAnimation(movementAnimation);
+ AnimationManager::self()->registerAnimation(destroyAnimation);
machine->start();
}
+void Boat::stop()
+{
+ movementAnimation->stop();
+ machine->stop();
+}
+
void Boat::updateBoatMovement()
{
if (speed == 0 || direction == Boat::None) {
diff --git a/examples/animation/sub-attaq/boat.h b/examples/animation/sub-attaq/boat.h
index b8d5772..44de367 100644
--- a/examples/animation/sub-attaq/boat.h
+++ b/examples/animation/sub-attaq/boat.h
@@ -57,6 +57,8 @@
class PixmapItem;
class Bomb;
class QVariantAnimation;
+class QAbstractAnimation;
+class QStateMachine;
class Boat : public QGraphicsWidget
{
@@ -71,6 +73,8 @@ public:
enum { Type = UserType + 2 };
Boat(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
void destroy();
+ void run();
+ void stop();
int bombsLaunched() const;
void setBombsLaunched(int number);
@@ -94,6 +98,8 @@ private:
int bombsAlreadyLaunched;
Movement direction;
QVariantAnimation *movementAnimation;
+ QAbstractAnimation *destroyAnimation;
+ QStateMachine *machine;
PixmapItem *pixmapItem;
};
diff --git a/examples/animation/sub-attaq/boat_p.h b/examples/animation/sub-attaq/boat_p.h
index 8dacaba..3c466b3 100644
--- a/examples/animation/sub-attaq/boat_p.h
+++ b/examples/animation/sub-attaq/boat_p.h
@@ -61,7 +61,7 @@ class KeyStopTransition : public QKeyEventTransition
{
public:
KeyStopTransition(Boat *boat, QEvent::Type type, int key)
- : QKeyEventTransition(boat,type, key)
+ : QKeyEventTransition(boat, type, key)
{
this->boat = boat;
this->key = key;
@@ -90,7 +90,7 @@ private:
{
public:
KeyMoveTransition(Boat *boat, QEvent::Type type, int key)
- : QKeyEventTransition(boat,type, key)
+ : QKeyEventTransition(boat, type, key)
{
this->boat = boat;
this->key = key;
@@ -131,7 +131,7 @@ private:
{
public:
KeyLaunchTransition(Boat *boat, QEvent::Type type, int key)
- : QKeyEventTransition(boat,type, key)
+ : QKeyEventTransition(boat, type, key)
{
this->boat = boat;
this->key = key;
diff --git a/examples/animation/sub-attaq/graphicsscene.cpp b/examples/animation/sub-attaq/graphicsscene.cpp
index 5dcc034..a66925c 100644
--- a/examples/animation/sub-attaq/graphicsscene.cpp
+++ b/examples/animation/sub-attaq/graphicsscene.cpp
@@ -50,6 +50,7 @@
#include "custompropertyanimation.h"
#include "animationmanager.h"
#include "qanimationstate.h"
+#include "progressitem.h"
//Qt
#if defined(QT_EXPERIMENTAL_SOLUTION)
@@ -117,6 +118,15 @@ GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode)
surfaceItem->setPos(0,sealLevel() - surfaceItem->boundingRect().height()/2);
addItem(surfaceItem);
+ //The item that display score and level
+ progressItem = new ProgressItem(backgroundItem);
+
+ //We create the boat
+ boat = new Boat();
+ addItem(boat);
+ boat->setPos(this->width()/2, sealLevel() - boat->size().height());
+ boat->hide();
+
//parse the xml that contain all data of the game
QXmlStreamReader reader;
QFile file(QDir::currentPath() + "/data.xml");
@@ -335,17 +345,17 @@ void GraphicsScene::clearScene()
{
foreach (SubMarine *sub,submarines) {
sub->destroy();
- delete sub;
+ sub->deleteLater();
}
foreach (Torpedo *torpedo,torpedos) {
torpedo->destroy();
- delete torpedo;
+ torpedo->deleteLater();
}
foreach (Bomb *bomb,bombs) {
bomb->destroy();
- delete bomb;
+ bomb->deleteLater();
}
submarines.clear();
@@ -354,10 +364,8 @@ void GraphicsScene::clearScene()
AnimationManager::self()->unregisterAllAnimations();
- if (boat) {
- delete boat;
- boat = 0;
- }
+ boat->stop();
+ boat->hide();
}
QGraphicsPixmapItem *GraphicsScene::addWelcomeItem(const QPixmap &pm)
diff --git a/examples/animation/sub-attaq/graphicsscene.h b/examples/animation/sub-attaq/graphicsscene.h
index 875f59f..bc9734c 100644
--- a/examples/animation/sub-attaq/graphicsscene.h
+++ b/examples/animation/sub-attaq/graphicsscene.h
@@ -58,6 +58,7 @@ class SubMarine;
class Torpedo;
class Bomb;
class PixmapItem;
+class ProgressItem;
class QAction;
class GraphicsScene : public QGraphicsScene
@@ -109,6 +110,7 @@ private slots:
private:
Mode mode;
PixmapItem *backgroundItem;
+ ProgressItem *progressItem;
QAction * newAction;
QAction * quitAction;
Boat *boat;
@@ -121,8 +123,11 @@ private:
friend class PauseState;
friend class PlayState;
+ friend class LevelState;
friend class LostState;
friend class WinState;
+ friend class WinTransition;
+ friend class UpdateScoreTransition;
};
#endif //__GRAPHICSSCENE__H__
diff --git a/examples/animation/sub-attaq/progressitem.cpp b/examples/animation/sub-attaq/progressitem.cpp
new file mode 100644
index 0000000..59ccb9a
--- /dev/null
+++ b/examples/animation/sub-attaq/progressitem.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "progressitem.h"
+#include "pixmapitem.h"
+
+ProgressItem::ProgressItem (QGraphicsItem * parent)
+ : QGraphicsTextItem(parent), currentLevel(1), currentScore(0)
+{
+ setFont(QFont("Comic Sans MS"));
+ setPos(parentItem()->boundingRect().topRight() - QPointF(180, -5));
+}
+
+void ProgressItem::setLevel(int level)
+{
+ currentLevel = level;
+ updateProgress();
+}
+
+void ProgressItem::setScore(int score)
+{
+ currentScore = score;
+ updateProgress();
+}
+
+void ProgressItem::updateProgress()
+{
+ setHtml(QString("Level : %1 Score : %2").arg(currentLevel).arg(currentScore));
+}
diff --git a/examples/animation/sub-attaq/progressitem.h b/examples/animation/sub-attaq/progressitem.h
new file mode 100644
index 0000000..006cc6d
--- /dev/null
+++ b/examples/animation/sub-attaq/progressitem.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PROGRESSITEM_H
+#define PROGRESSITEM_H
+
+//Qt
+#include
+
+class ProgressItem : public QGraphicsTextItem
+{
+public:
+ ProgressItem(QGraphicsItem * parent = 0);
+ void setLevel(int level);
+ void setScore(int score);
+
+private:
+ void updateProgress();
+ int currentLevel;
+ int currentScore;
+};
+
+#endif // PROGRESSITEM_H
diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp
index f476f55..5dce445 100644
--- a/examples/animation/sub-attaq/states.cpp
+++ b/examples/animation/sub-attaq/states.cpp
@@ -46,6 +46,7 @@
#include "submarine.h"
#include "torpedo.h"
#include "animationmanager.h"
+#include "progressitem.h"
//Qt
#include
@@ -81,27 +82,31 @@ void PlayState::onEntry()
if (machine) {
machine->stop();
scene->clearScene();
+ currentLevel = 0;
+ score = 0;
delete machine;
}
machine = new QStateMachine(this);
//This state is when player is playing
- QState *playState = new QState(machine->rootState());
+ LevelState *levelState = new LevelState(scene, this, machine->rootState());
- initializeLevel();
+ //This state is when the player is actually playing but the game is not paused
+ QState *playingState = new QState(levelState);
+ levelState->setInitialState(playingState);
//This state is when the game is paused
- PauseState *pauseState = new PauseState(scene, machine->rootState());
+ PauseState *pauseState = new PauseState(scene, levelState);
//We have one view, it receive the key press event
QKeyEventTransition *pressPplay = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P);
pressPplay->setTargetState(pauseState);
QKeyEventTransition *pressPpause = new QKeyEventTransition(scene->views().at(0), QEvent::KeyPress, Qt::Key_P);
- pressPpause->setTargetState(playState);
+ pressPpause->setTargetState(playingState);
//Pause "P" is triggered, the player pause the game
- playState->addTransition(pressPplay);
+ playingState->addTransition(pressPplay);
//To get back playing when the game has been paused
pauseState->addTransition(pressPpause);
@@ -113,34 +118,37 @@ void PlayState::onEntry()
WinState *winState = new WinState(scene, this, machine->rootState());
//The boat has been destroyed then the game is finished
- playState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState);
+ levelState->addTransition(scene->boat, SIGNAL(boatExecutionFinished()),lostState);
//This transition check if we won or not
WinTransition *winTransition = new WinTransition(scene, this, winState);
//The boat has been destroyed then the game is finished
- playState->addTransition(winTransition);
+ levelState->addTransition(winTransition);
//This state is an animation when the score changed
- UpdateScoreState *scoreState = new UpdateScoreState(this, machine->rootState());
+ UpdateScoreState *scoreState = new UpdateScoreState(this, levelState);
//This transition update the score when a submarine die
- UpdateScoreTransition *scoreTransition = new UpdateScoreTransition(scene, this, scoreState);
+ UpdateScoreTransition *scoreTransition = new UpdateScoreTransition(scene, this, levelState);
+ scoreTransition->setTargetState(scoreState);
//The boat has been destroyed then the game is finished
- playState->addTransition(scoreTransition);
+ playingState->addTransition(scoreTransition);
//We go back to play state
- scoreState->addTransition(playState);
+ scoreState->addTransition(playingState);
//We start playing!!!
- machine->setInitialState(playState);
+ machine->setInitialState(levelState);
//Final state
QFinalState *final = new QFinalState(machine->rootState());
- //We win we should reach the final state
- winState->addFinishedTransition(final);
+ //This transition is triggered when the player press space after completing a level
+ CustomSpaceTransition *spaceTransition = new CustomSpaceTransition(scene->views().at(0), this, QEvent::KeyPress, Qt::Key_Space);
+ spaceTransition->setTargetState(levelState);
+ winState->addTransition(spaceTransition);
//We lost we should reach the final state
lostState->addFinishedTransition(final);
@@ -148,14 +156,29 @@ void PlayState::onEntry()
machine->start();
}
-void PlayState::initializeLevel()
+LevelState::LevelState(GraphicsScene *scene, PlayState *game, QState *parent) : QState(parent), scene(scene), game(game)
{
- scene->boat = new Boat();
- scene->addItem(scene->boat);
- scene->setFocusItem(scene->boat,Qt::OtherFocusReason);
+}
+void LevelState::onEntry()
+{
+ initializeLevel();
+}
+
+void LevelState::initializeLevel()
+{
+ //we re-init the boat
scene->boat->setPos(scene->width()/2, scene->sealLevel() - scene->boat->size().height());
+ scene->boat->setCurrentSpeed(0);
+ scene->boat->setCurrentDirection(Boat::None);
+ scene->boat->setBombsLaunched(0);
+ scene->boat->show();
+ scene->setFocusItem(scene->boat,Qt::OtherFocusReason);
+ scene->boat->run();
+
+ scene->progressItem->setScore(game->score);
+ scene->progressItem->setLevel(game->currentLevel + 1);
- GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(currentLevel);
+ GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel);
for (int i = 0; i < currentLevelDescription.submarines.size(); ++i ) {
@@ -226,7 +249,7 @@ void WinState::onEntry()
QString message;
if (scene->levelsData.size() - 1 != game->currentLevel) {
- message = QString("You win the level %1. Your score is %2.").arg(game->currentLevel+1).arg(game->score);
+ message = QString("You win the level %1. Your score is %2.\nPress Space to continue after closing this dialog.").arg(game->currentLevel+1).arg(game->score);
//We increment the level number
game->currentLevel++;
} else {
@@ -248,14 +271,13 @@ UpdateScoreState::UpdateScoreState(PlayState *game, QState *parent) : QState(par
}
void UpdateScoreState::onEntry()
{
- //### Make a nice anim to update the score in the scene
QState::onEntry();
}
/** Win transition */
UpdateScoreTransition::UpdateScoreTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target)
: QSignalTransition(scene,SIGNAL(subMarineDestroyed(int)), QList() << target),
- game(game)
+ game(game), scene(scene)
{
}
@@ -266,6 +288,7 @@ bool UpdateScoreTransition::eventTest(QEvent *event) const
else {
QSignalEvent *se = static_cast(event);
game->score += se->arguments().at(0).toInt();
+ scene->progressItem->setScore(game->score);
return true;
}
}
@@ -273,7 +296,7 @@ bool UpdateScoreTransition::eventTest(QEvent *event) const
/** Win transition */
WinTransition::WinTransition(GraphicsScene *scene, PlayState *game, QAbstractState *target)
: QSignalTransition(scene,SIGNAL(allSubMarineDestroyed(int)), QList() << target),
- game(game)
+ game(game), scene(scene)
{
}
@@ -284,6 +307,26 @@ bool WinTransition::eventTest(QEvent *event) const
else {
QSignalEvent *se = static_cast(event);
game->score += se->arguments().at(0).toInt();
+ scene->progressItem->setScore(game->score);
return true;
}
}
+
+/** Space transition */
+CustomSpaceTransition::CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key)
+ : QKeyEventTransition(widget, type, key),
+ game(game)
+{
+}
+
+bool CustomSpaceTransition::eventTest(QEvent *event) const
+{
+ Q_UNUSED(event);
+ if (!QKeyEventTransition::eventTest(event))
+ return false;
+ if (game->currentLevel != 0)
+ return true;
+ else
+ return false;
+
+}
diff --git a/examples/animation/sub-attaq/states.h b/examples/animation/sub-attaq/states.h
index 52d4ffa..8dbdf86 100644
--- a/examples/animation/sub-attaq/states.h
+++ b/examples/animation/sub-attaq/states.h
@@ -47,10 +47,12 @@
#include "qstate.h"
#include "qsignaltransition.h"
#include "qpropertyanimation.h"
+#include "qkeyeventtransition.h"
#else
#include
#include
#include
+# include
#endif
#include
@@ -64,7 +66,6 @@ class PlayState : public QState
public:
PlayState(GraphicsScene *scene, QState *parent = 0);
~PlayState();
- void initializeLevel();
protected:
void onEntry();
@@ -79,8 +80,22 @@ private :
friend class UpdateScoreState;
friend class UpdateScoreTransition;
friend class WinTransition;
+ friend class CustomSpaceTransition;
friend class WinState;
friend class LostState;
+ friend class LevelState;
+};
+
+class LevelState : public QState
+{
+public:
+ LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+protected:
+ void onEntry();
+private :
+ void initializeLevel();
+ GraphicsScene *scene;
+ PlayState *game;
};
class PauseState : public QState
@@ -140,6 +155,7 @@ protected:
virtual bool eventTest(QEvent *event) const;
private:
PlayState * game;
+ GraphicsScene *scene;
};
//These transtion test if we have won the game
@@ -151,6 +167,19 @@ protected:
virtual bool eventTest(QEvent *event) const;
private:
PlayState * game;
+ GraphicsScene *scene;
+};
+
+//These transtion is true if one level has been completed and the player want to continue
+ class CustomSpaceTransition : public QKeyEventTransition
+{
+public:
+ CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key);
+protected:
+ virtual bool eventTest(QEvent *event) const;
+private:
+ PlayState *game;
+ int key;
};
#endif // STATES_H
diff --git a/examples/animation/sub-attaq/sub-attaq.pro b/examples/animation/sub-attaq/sub-attaq.pro
index 1456d0e..961a9b5 100644
--- a/examples/animation/sub-attaq/sub-attaq.pro
+++ b/examples/animation/sub-attaq/sub-attaq.pro
@@ -2,10 +2,10 @@
# Automatically generated by qmake (2.01a) Thu Oct 9 10:53:30 2008
# #####################################################################
TEMPLATE = app
-TARGET =
+TARGET =
DEPENDPATH += .
INCLUDEPATH += .
-QT+= xml
+QT += xml
contains(QT_CONFIG, opengl):QT += opengl
# Input
@@ -21,7 +21,8 @@ HEADERS += boat.h \
boat_p.h \
submarine_p.h \
custompropertyanimation.h \
- qanimationstate.h
+ qanimationstate.h \
+ progressitem.h
SOURCES += boat.cpp \
bomb.cpp \
main.cpp \
@@ -33,6 +34,6 @@ SOURCES += boat.cpp \
animationmanager.cpp \
states.cpp \
custompropertyanimation.cpp \
- qanimationstate.cpp
-
+ qanimationstate.cpp \
+ progressitem.cpp
RESOURCES += subattaq.qrc
diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp
index 555617c..b8a476e 100644
--- a/examples/animation/sub-attaq/submarine.cpp
+++ b/examples/animation/sub-attaq/submarine.cpp
@@ -126,15 +126,15 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem *
QState *moving = new QState(machine->rootState());
//This state is when the boat is moving from left to right
- MovementState *movement = new MovementState(this,moving);
+ MovementState *movement = new MovementState(this, moving);
//This state is when the boat is moving from left to right
- ReturnState *rotation = new ReturnState(this,moving);
+ ReturnState *rotation = new ReturnState(this, moving);
//This is the initial state of the moving root state
moving->setInitialState(movement);
- movement->addTransition(this, SIGNAL(subMarineStateChanged()),moving);
+ movement->addTransition(this, SIGNAL(subMarineStateChanged()), moving);
//This is the initial state of the machine
machine->setInitialState(moving);
@@ -153,7 +153,7 @@ SubMarine::SubMarine(int type, const QString &name, int points, QGraphicsItem *
destroyedState->setAnimation(setupDestroyAnimation(this));
//Play a nice animation when the submarine is destroyed
- moving->addTransition(this, SIGNAL(subMarineDestroyed()),destroyedState);
+ moving->addTransition(this, SIGNAL(subMarineDestroyed()), destroyedState);
//Transition to final state when the destroyed animation is finished
destroyedState->addTransition(destroyedState, SIGNAL(animationFinished()), final);
--
cgit v0.12
From c3290381a1dba7971dd70b7220a71e6feceb3f4c Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Fri, 24 Apr 2009 17:35:35 +0200
Subject: Unfinished tank AI game. The idea is that you plug in AIs for the
tanks, and one such plugin will have a run time error, so the game server
needs to use errorState for handling errors.
---
examples/statemachine/errorstate/errorstate.pro | 13 ++
examples/statemachine/errorstate/main.cpp | 12 ++
examples/statemachine/errorstate/mainwindow.cpp | 184 ++++++++++++++++
examples/statemachine/errorstate/mainwindow.h | 41 ++++
examples/statemachine/errorstate/plugin.h | 16 ++
examples/statemachine/errorstate/tank.h | 31 +++
examples/statemachine/errorstate/tankitem.cpp | 274 ++++++++++++++++++++++++
examples/statemachine/errorstate/tankitem.h | 48 +++++
8 files changed, 619 insertions(+)
create mode 100644 examples/statemachine/errorstate/errorstate.pro
create mode 100644 examples/statemachine/errorstate/main.cpp
create mode 100644 examples/statemachine/errorstate/mainwindow.cpp
create mode 100644 examples/statemachine/errorstate/mainwindow.h
create mode 100644 examples/statemachine/errorstate/plugin.h
create mode 100644 examples/statemachine/errorstate/tank.h
create mode 100644 examples/statemachine/errorstate/tankitem.cpp
create mode 100644 examples/statemachine/errorstate/tankitem.h
diff --git a/examples/statemachine/errorstate/errorstate.pro b/examples/statemachine/errorstate/errorstate.pro
new file mode 100644
index 0000000..d937b02
--- /dev/null
+++ b/examples/statemachine/errorstate/errorstate.pro
@@ -0,0 +1,13 @@
+######################################################################
+# Automatically generated by qmake (2.01a) on 22. apr 14:11:33 2009
+######################################################################
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += C:/dev/kinetic/examples/statemachine/errorstate/. .
+
+# Input
+HEADERS += mainwindow.h plugin.h tank.h tankitem.h
+SOURCES += main.cpp mainwindow.cpp tankitem.cpp
+CONFIG += console
diff --git a/examples/statemachine/errorstate/main.cpp b/examples/statemachine/errorstate/main.cpp
new file mode 100644
index 0000000..26fc1bb
--- /dev/null
+++ b/examples/statemachine/errorstate/main.cpp
@@ -0,0 +1,12 @@
+#include
+#include "mainwindow.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ MainWindow mainWindow;
+ mainWindow.show();
+
+ return app.exec();
+}
diff --git a/examples/statemachine/errorstate/mainwindow.cpp b/examples/statemachine/errorstate/mainwindow.cpp
new file mode 100644
index 0000000..598756f
--- /dev/null
+++ b/examples/statemachine/errorstate/mainwindow.cpp
@@ -0,0 +1,184 @@
+#include "mainwindow.h"
+#include "tankitem.h"
+#include "plugin.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ init();
+}
+
+MainWindow::~MainWindow()
+{
+}
+
+void MainWindow::addWall(const QRectF &wall)
+{
+ QGraphicsRectItem *item = new QGraphicsRectItem;
+ item->setRect(wall);
+ item->setBrush(Qt::darkGreen);
+ item->setPen(QPen(Qt::black, 0));
+
+ m_scene->addItem(item);
+}
+
+void MainWindow::init()
+{
+ setWindowTitle("Pluggable Tank Game");
+
+ QGraphicsView *view = new QGraphicsView(this);
+ setCentralWidget(view);
+
+ m_scene = new QGraphicsScene(this);
+ view->setScene(m_scene);
+
+ QRectF sceneRect = QRectF(-200.0, -200.0, 400.0, 400.0);
+ m_scene->setSceneRect(sceneRect);
+
+ {
+ TankItem *item = new TankItem(this);
+
+ item->setPos(m_scene->sceneRect().topLeft() + QPointF(15.0, 15.0));
+ item->setDirection(45.0);
+ item->setColor(Qt::red);
+
+ m_spawns.append(item);
+ }
+
+ {
+ TankItem *item = new TankItem(this);
+
+ item->setPos(m_scene->sceneRect().topRight() + QPointF(-15.0, 15.0));
+ item->setDirection(135.0);
+ item->setColor(Qt::green);
+
+ m_spawns.append(item);
+ }
+
+ {
+ TankItem *item = new TankItem(this);
+
+ item->setPos(m_scene->sceneRect().bottomRight() + QPointF(-15.0, -15.0));
+ item->setDirection(225.0);
+ item->setColor(Qt::blue);
+
+ m_spawns.append(item);
+ }
+
+ {
+ TankItem *item = new TankItem(this);
+
+ item->setPos(m_scene->sceneRect().bottomLeft() + QPointF(15.0, -15.0));
+ item->setDirection(315.0);
+ item->setColor(Qt::yellow);
+
+ m_spawns.append(item);
+ }
+
+ QPointF centerOfMap = sceneRect.center();
+ addWall(QRectF(centerOfMap + QPointF(-50.0, -60.0), centerOfMap + QPointF(50.0, -50.0)));
+ addWall(QRectF(centerOfMap - QPointF(-50.0, -60.0), centerOfMap - QPointF(50.0, -50.0)));
+ addWall(QRectF(centerOfMap + QPointF(-50.0, -50.0), centerOfMap + QPointF(-40.0, 50.0)));
+ addWall(QRectF(centerOfMap - QPointF(-50.0, -50.0), centerOfMap - QPointF(-40.0, 50.0)));
+
+ addWall(QRectF(sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, 0.0),
+ sceneRect.topLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, 100.0)));
+ addWall(QRectF(sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 - 5.0, 0.0),
+ sceneRect.bottomLeft() + QPointF(sceneRect.width() / 2.0 + 5.0, -100.0)));
+ addWall(QRectF(sceneRect.topLeft() + QPointF(0.0, sceneRect.height() / 2.0 - 5.0),
+ sceneRect.topLeft() + QPointF(100.0, sceneRect.height() / 2.0 + 5.0)));
+ addWall(QRectF(sceneRect.topRight() + QPointF(0.0, sceneRect.height() / 2.0 - 5.0),
+ sceneRect.topRight() + QPointF(-100.0, sceneRect.height() / 2.0 + 5.0)));
+
+
+ QAction *addTankAction = menuBar()->addAction("&Add tank");
+ QAction *runGameAction = menuBar()->addAction("&Run game");
+ QAction *stopGameAction = menuBar()->addAction("&Stop game");
+ menuBar()->addSeparator();
+ QAction *quitAction = menuBar()->addAction("&Quit");
+
+ connect(addTankAction, SIGNAL(triggered()), this, SLOT(addTank()));
+ connect(stopGameAction, SIGNAL(triggered()), this, SIGNAL(gameOver()));
+ connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
+
+ m_machine = new QStateMachine(this);
+ m_machine->setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QState *stoppedState = new QState(m_machine->rootState());
+
+ stoppedState->assignProperty(runGameAction, "enabled", true);
+ stoppedState->assignProperty(stopGameAction, "enabled", false);
+ m_machine->setInitialState(stoppedState);
+
+ QState *spawnsAvailable = new QState(stoppedState);
+ spawnsAvailable->assignProperty(addTankAction, "enabled", true);
+
+ QState *noSpawnsAvailable = new QState(stoppedState);
+ noSpawnsAvailable->assignProperty(addTankAction, "enabled", false);
+
+ spawnsAvailable->addTransition(this, SIGNAL(mapFull()), noSpawnsAvailable);
+
+ QHistoryState *hs = stoppedState->addHistoryState();
+ hs->setDefaultState(spawnsAvailable);
+ stoppedState->setInitialState(spawnsAvailable);
+
+ m_runningState = new QState(QState::ParallelGroup, m_machine->rootState());
+ m_runningState->assignProperty(addTankAction, "enabled", false);
+ m_runningState->assignProperty(runGameAction, "enabled", false);
+ m_runningState->assignProperty(stopGameAction, "enabled", true);
+
+ stoppedState->addTransition(runGameAction, SIGNAL(triggered()), m_runningState);
+ m_runningState->addTransition(this, SIGNAL(gameOver()), stoppedState);
+
+ m_machine->start();
+
+ QTimer *timer = new QTimer(this);
+ timer->setInterval(100);
+ connect(timer, SIGNAL(timeout()), this, SLOT(runStep()));
+ connect(m_runningState, SIGNAL(entered()), timer, SLOT(start()));
+ connect(m_runningState, SIGNAL(exited()), timer, SLOT(stop()));
+
+ m_time.start();
+}
+
+void MainWindow::runStep()
+{
+ int elapsed = m_time.elapsed();
+ if (elapsed > 0) {
+ m_time.restart();
+ qreal elapsedSecs = elapsed / 1000.0;
+ QList tankItems = qFindChildren(this);
+ foreach (TankItem *tankItem, tankItems)
+ tankItem->idle(elapsedSecs);
+ }
+}
+
+void MainWindow::addTank()
+{
+ Q_ASSERT(!m_spawns.isEmpty());
+
+ QString fileName = QFileDialog::getOpenFileName(this, "Select plugin file",
+ "plugins/", "*.dll");
+ QPluginLoader loader(fileName);
+
+ Plugin *plugin = qobject_cast(loader.instance());
+ if (plugin != 0) {
+ TankItem *tankItem = m_spawns.takeLast();
+ m_scene->addItem(tankItem);
+ if (m_spawns.isEmpty())
+ emit mapFull();
+
+ plugin->create(m_runningState, tankItem);
+ }
+}
+
diff --git a/examples/statemachine/errorstate/mainwindow.h b/examples/statemachine/errorstate/mainwindow.h
new file mode 100644
index 0000000..2bd574d
--- /dev/null
+++ b/examples/statemachine/errorstate/mainwindow.h
@@ -0,0 +1,41 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include
+#include
+
+class QGraphicsScene;
+class QStateMachine;
+class QState;
+class TankItem;
+class MainWindow: public QMainWindow
+{
+ Q_OBJECT
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+public slots:
+ void addTank();
+ void runStep();
+
+signals:
+ void gameOver();
+ void mapFull();
+
+private:
+ void init();
+ void addWall(const QRectF &wall);
+
+ QGraphicsScene *m_scene;
+
+ QStateMachine *m_machine;
+ QState *m_runningState;
+
+ QList m_spawns;
+ QTime m_time;
+
+};
+
+#endif
+
diff --git a/examples/statemachine/errorstate/plugin.h b/examples/statemachine/errorstate/plugin.h
new file mode 100644
index 0000000..1ac7e0f
--- /dev/null
+++ b/examples/statemachine/errorstate/plugin.h
@@ -0,0 +1,16 @@
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+class QState;
+class Tank;
+class Plugin
+{
+public:
+ virtual ~Plugin() {}
+
+ virtual QState *create(QState *parentState, Tank *tank) = 0;
+};
+
+Q_DECLARE_INTERFACE(Plugin, "TankPlugin")
+
+#endif
diff --git a/examples/statemachine/errorstate/tank.h b/examples/statemachine/errorstate/tank.h
new file mode 100644
index 0000000..9def6df
--- /dev/null
+++ b/examples/statemachine/errorstate/tank.h
@@ -0,0 +1,31 @@
+#ifndef TANK_H
+#define TANK_H
+
+#include
+#include
+
+class Tank: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal direction READ direction)
+ Q_PROPERTY(qreal distanceToObstacle READ distanceToObstacle)
+public:
+ Tank(QObject *parent = 0) : QObject(parent) {}
+
+ virtual qreal direction() const = 0;
+ virtual qreal distanceToObstacle() const = 0;
+
+signals:
+ void collision(const QLineF &collidedLine) const;
+ void actionCompleted();
+ void tankSpotted(qreal otherTankDirection, qreal distance);
+
+public slots:
+ virtual void moveForwards(qreal length) = 0;
+ virtual void moveBackwards(qreal length) = 0;
+ virtual void turn(qreal newDirection) = 0;
+ virtual void stop() = 0;
+ virtual void fireCannon(qreal distance) = 0;
+};
+
+#endif
diff --git a/examples/statemachine/errorstate/tankitem.cpp b/examples/statemachine/errorstate/tankitem.cpp
new file mode 100644
index 0000000..21d4a25
--- /dev/null
+++ b/examples/statemachine/errorstate/tankitem.cpp
@@ -0,0 +1,274 @@
+#include "tankitem.h"
+
+#include
+#include
+
+#include
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+class Action
+{
+public:
+ Action(TankItem *item) : m_item(item)
+ {
+ }
+
+ TankItem *item() const { return m_item; }
+ void setItem(TankItem *item) { m_item = item; }
+
+ virtual bool apply(qreal timeDelta) = 0;
+
+private:
+ TankItem *m_item;
+};
+
+class MoveAction: public Action
+{
+public:
+ MoveAction(TankItem *item, qreal distance)
+ : Action(item), m_distance(distance)
+ {
+ }
+
+ bool apply(qreal timeDelta)
+ {
+ qreal dist = timeDelta * item()->speed();
+ m_distance -= dist;
+ if (qFuzzyCompare(m_distance, 0.0))
+ return false;
+
+ qreal a = item()->direction() * M_PI / 180.0;
+
+ qreal yd = dist * sin(a);
+ qreal xd = dist * sin(M_PI / 2.0 - a);
+
+ item()->setPos(item()->pos() + QPointF(xd, yd));
+ return true;
+ }
+
+private:
+ qreal m_distance;
+};
+
+class TurnAction: public Action
+{
+public:
+ TurnAction(TankItem *item, qreal distance)
+ : Action(item), m_distance(distance)
+ {
+ }
+
+ bool apply(qreal timeDelta)
+ {
+ qreal dist = timeDelta * item()->angularSpeed();
+ m_distance -= dist;
+ if (qFuzzyCompare(m_distance, 0.0))
+ return false;
+
+ item()->setDirection(item()->direction() + dist);
+ return true;
+ }
+
+private:
+ qreal m_distance;
+};
+
+class FireCannonAction: public Action
+{
+public:
+ FireCannonAction(TankItem *item, qreal distance)
+ : Action(item), m_distance(distance)
+ {
+ }
+
+ bool apply(qreal )
+ {
+ return false;
+ }
+
+private:
+ qreal m_distance;
+};
+
+TankItem::TankItem(QObject *parent) : Tank(parent), m_currentAction(0), m_currentDirection(0.0)
+{
+}
+
+void TankItem::idle(qreal elapsed)
+{
+ if (m_currentAction != 0) {
+ if (!m_currentAction->apply(elapsed)) {
+ setAction(0);
+ emit actionCompleted();
+ }
+ }
+}
+
+void TankItem::setAction(Action *newAction)
+{
+ if (m_currentAction != 0)
+ delete m_currentAction;
+
+ m_currentAction = newAction;
+}
+
+void TankItem::moveForwards(qreal length)
+{
+ setAction(new MoveAction(this, length));
+}
+
+void TankItem::moveBackwards(qreal length)
+{
+ setAction(new MoveAction(this, -length));
+}
+
+void TankItem::turn(qreal newDirection)
+{
+ setAction(new TurnAction(this, m_currentDirection - newDirection));
+}
+
+void TankItem::stop()
+{
+ setAction(0);
+}
+
+void TankItem::fireCannon(qreal distance)
+{
+ setAction(new FireCannonAction(this, distance));
+}
+
+QPointF TankItem::tryMove(const QPointF &requestedPosition) const
+{
+ QLineF movementPath(pos(), requestedPosition);
+
+ qreal cannonLength = 0.0;
+ {
+ QPointF p1 = boundingRect().center();
+ QPointF p2 = QPointF(boundingRect().right() + 10.0, p1.y());
+
+ cannonLength = QLineF(mapToScene(p1), mapToScene(p2)).length();
+ }
+
+ movementPath.setLength(movementPath.length() + cannonLength);
+
+ QRectF boundingRectPath(QPointF(qMin(movementPath.x1(), movementPath.x2()), qMin(movementPath.y1(), movementPath.y2())),
+ QPointF(qMax(movementPath.x1(), movementPath.x2()), qMax(movementPath.y1(), movementPath.y2())));
+
+ m_brp = mapFromScene(boundingRectPath);
+
+ QList itemsInRect = scene()->items(boundingRectPath, Qt::IntersectsItemBoundingRect);
+
+ QPointF nextPoint = requestedPosition;
+ QRectF sceneRect = scene()->sceneRect();
+
+ QLineF collidedLine;
+ foreach (QGraphicsItem *item, itemsInRect) {
+ if (item == static_cast(this))
+ continue;
+
+ QPolygonF mappedBoundingRect = item->mapToScene(item->boundingRect());
+ for (int i=0; i sceneRect.right())
+ nextPoint.rx() = sceneRect.right();
+ if (nextPoint.y() < sceneRect.top())
+ nextPoint.ry() = sceneRect.top();
+ if (nextPoint.y() > sceneRect.bottom())
+ nextPoint.ry() = sceneRect.bottom();
+
+ if (nextPoint != requestedPosition) {
+ emit collision(collidedLine);
+ }
+
+ return nextPoint;
+}
+
+QVariant TankItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
+{
+ if (change == ItemPositionChange && scene())
+ return tryMove(value.toPointF());
+ else
+ return QGraphicsItem::itemChange(change, value);
+}
+
+
+void TankItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ QRectF brect = boundingRect();
+
+ painter->setBrush(m_color);
+ painter->setPen(Qt::black);
+
+ // body
+ painter->drawRect(brect.adjusted(0.0, 4.0, -2.0, -4.0));
+
+ // cannon
+ QRectF cannonBase = brect.adjusted(10.0, 6.0, -12.0, -6.0);
+ painter->drawEllipse(cannonBase);
+
+ painter->drawRect(QRectF(QPointF(cannonBase.center().x(), cannonBase.center().y() - 2.0),
+ QPointF(brect.right(), cannonBase.center().y() + 2.0)));
+
+ // left track
+ painter->setBrush(QBrush(Qt::black, Qt::VerPattern));
+ QRectF leftTrackRect = QRectF(brect.topLeft(), QPointF(brect.right() - 2.0, brect.top() + 4.0));
+ painter->fillRect(leftTrackRect, Qt::darkYellow);
+ painter->drawRect(leftTrackRect);
+
+ // right track
+ QRectF rightTrackRect = QRectF(QPointF(brect.left(), brect.bottom() - 4.0),
+ QPointF(brect.right() - 2.0, brect.bottom()));
+ painter->fillRect(rightTrackRect, Qt::darkYellow);
+ painter->drawRect(rightTrackRect);
+
+ painter->setBrush(QColor::fromRgb(255, 0, 0, 128));
+ painter->drawPolygon(m_brp);
+
+}
+
+QRectF TankItem::boundingRect() const
+{
+ return QRectF(-20.0, -10.0, 40.0, 20.0);
+}
+
+qreal TankItem::direction() const
+{
+ return m_currentDirection;
+}
+
+void TankItem::setDirection(qreal newDirection)
+{
+ m_currentDirection = newDirection;
+ rotate(newDirection);
+}
+
+qreal TankItem::distanceToObstacle() const
+{
+ // ###
+
+ return 0.0;
+}
+
+
+
diff --git a/examples/statemachine/errorstate/tankitem.h b/examples/statemachine/errorstate/tankitem.h
new file mode 100644
index 0000000..df13689
--- /dev/null
+++ b/examples/statemachine/errorstate/tankitem.h
@@ -0,0 +1,48 @@
+#ifndef TANKITEM_H
+#define TANKITEM_H
+
+#include "tank.h"
+
+#include
+#include
+
+class Action;
+class TankItem: public Tank, public QGraphicsItem
+{
+ Q_OBJECT
+public:
+ TankItem(QObject *parent = 0);
+
+ virtual void moveForwards(qreal length);
+ virtual void moveBackwards(qreal length);
+ virtual void turn(qreal newDirection);
+ virtual void stop();
+ virtual void fireCannon(qreal distance);
+ virtual qreal direction() const;
+ virtual qreal distanceToObstacle() const;
+
+ void setColor(const QColor &color) { m_color = color; }
+ QColor color() const { return m_color; }
+
+ void idle(qreal elapsed);
+ void setDirection(qreal newDirection);
+
+ qreal speed() const { return 20.0; }
+ qreal angularSpeed() const { return 1.0; }
+
+protected:
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QRectF boundingRect() const;
+ QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
+
+private:
+ QPointF tryMove(const QPointF &requestedPosition) const;
+ void setAction(Action *newAction);
+
+ Action *m_currentAction;
+ qreal m_currentDirection;
+ QColor m_color;
+ mutable QPolygonF m_brp;
+};
+
+#endif
--
cgit v0.12
From af4f0170810efeb071e6e9dac0df6a84962e9806 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Fri, 24 Apr 2009 17:36:48 +0200
Subject: Really broken plugin for errorState. Don't try to use this yet, it
doesn't work at all.
---
.../errorstateplugins/random_ai/random_ai.pro | 13 +++++
.../random_ai/random_ai_plugin.cpp | 40 ++++++++++++++
.../errorstateplugins/random_ai/random_ai_plugin.h | 62 ++++++++++++++++++++++
3 files changed, 115 insertions(+)
create mode 100644 examples/statemachine/errorstateplugins/random_ai/random_ai.pro
create mode 100644 examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.cpp
create mode 100644 examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
diff --git a/examples/statemachine/errorstateplugins/random_ai/random_ai.pro b/examples/statemachine/errorstateplugins/random_ai/random_ai.pro
new file mode 100644
index 0000000..f290250
--- /dev/null
+++ b/examples/statemachine/errorstateplugins/random_ai/random_ai.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += plugin
+INCLUDEPATH += ../..
+HEADERS = random_ai_plugin.h
+SOURCES = random_ai_plugin.cpp
+TARGET = $$qtLibraryTarget(random_ai)
+DESTDIR = ../../errorstate/plugins
+
+#! [0]
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/statemachine/errorstate/plugins
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS random_ai.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/statemachine/errorstateplugins/random_ai
\ No newline at end of file
diff --git a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.cpp b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.cpp
new file mode 100644
index 0000000..429e3ca
--- /dev/null
+++ b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.cpp
@@ -0,0 +1,40 @@
+#include "random_ai_plugin.h"
+
+#include
+
+#include
+#include
+
+#include
+
+QState *RandomAiPlugin::create(QState *parentState, Tank *tank)
+{
+ qsrand(uint(time(NULL)));
+
+ QState *topLevel = new QState(parentState);
+
+ QState *selectNextActionState = new SelectActionState(topLevel);
+ topLevel->setInitialState(selectNextActionState);
+
+ QState *fireState = new RandomDistanceState(topLevel);
+ connect(fireState, SIGNAL(distanceComputed(qreal)), tank, SLOT(fireCannon(qreal)));
+ selectNextActionState->addTransition(selectNextActionState, SIGNAL(fireSelected()), fireState);
+
+ QState *moveForwardsState = new RandomDistanceState(topLevel);
+ connect(moveForwardsState, SIGNAL(distanceComputed(qreal)), tank, SLOT(moveForwards(qreal)));
+ selectNextActionState->addTransition(selectNextActionState, SIGNAL(moveForwardsSelected()), moveForwardsState);
+
+ QState *moveBackwardsState = new RandomDistanceState(topLevel);
+ connect(moveBackwardsState, SIGNAL(distanceComputed(qreal)), tank, SLOT(moveBackwards(qreal)));
+ selectNextActionState->addTransition(selectNextActionState, SIGNAL(moveBackwardsSelected()), moveBackwardsState);
+
+ QState *turnState = new RandomDistanceState(topLevel);
+ connect(turnState, SIGNAL(distanceComputed(qreal)), tank, SLOT(turn(qreal)));
+ selectNextActionState->addTransition(selectNextActionState, SIGNAL(turnSelected()), turnState);
+
+ topLevel->addTransition(tank, SIGNAL(actionCompleted()), selectNextActionState);
+
+ return topLevel;
+}
+
+Q_EXPORT_PLUGIN2(random_ai, RandomAiPlugin)
diff --git a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
new file mode 100644
index 0000000..27c9b92
--- /dev/null
+++ b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
@@ -0,0 +1,62 @@
+#ifndef RANDOM_AI_PLUGIN_H
+#define RANDOM_AI_PLUGIN_H
+
+#include
+#include
+
+#include
+
+class SelectActionState: public QState
+{
+ Q_OBJECT
+public:
+ SelectActionState(QState *parent = 0) : QState(parent)
+ {
+ }
+
+signals:
+ void fireSelected();
+ void moveForwardsSelected();
+ void moveBackwardsSelected();
+ void turnSelected();
+
+protected:
+ void onEntry()
+ {
+ int rand = qrand() % 4;
+ switch (rand) {
+ case 0: emit fireSelected(); break;
+ case 1: emit moveForwardsSelected(); break;
+ case 2: emit moveBackwardsSelected(); break;
+ case 3: emit turnSelected(); break;
+ };
+ }
+};
+
+class RandomDistanceState: public QState
+{
+ Q_OBJECT
+public:
+ RandomDistanceState(QState *parent = 0) : QState(parent)
+ {
+ }
+
+signals:
+ void distanceComputed(qreal distance);
+
+protected:
+ void onEntry()
+ {
+ emit distanceComputed(qreal(qrand() % 10));
+ }
+};
+
+class RandomAiPlugin: public QObject, public Plugin
+{
+ Q_OBJECT
+ Q_INTERFACES(Plugin)
+public:
+ virtual QState *create(QState *parentState, Tank *tank);
+};
+
+#endif // RANDOM_AI_PLUGIN_H
--
cgit v0.12
From 6f955aedcdb6c2b1de04d1cd7e959e284581b3b3 Mon Sep 17 00:00:00 2001
From: Thierry Bastian
Date: Mon, 27 Apr 2009 16:41:25 +0200
Subject: Build fix for mingw
---
examples/animation/sub-attaq/animationmanager.cpp | 2 +-
examples/animation/sub-attaq/animationmanager.h | 2 +-
examples/animation/sub-attaq/boat.cpp | 12 +++++------
examples/animation/sub-attaq/boat.h | 6 ++----
examples/animation/sub-attaq/graphicsscene.cpp | 26 +++++++++++------------
examples/animation/sub-attaq/graphicsscene.h | 6 +++---
examples/animation/sub-attaq/mainwindow.cpp | 2 +-
examples/animation/sub-attaq/mainwindow.h | 2 +-
examples/animation/sub-attaq/pixmapitem.cpp | 2 +-
examples/animation/sub-attaq/pixmapitem.h | 2 +-
examples/animation/sub-attaq/progressitem.h | 2 +-
examples/animation/sub-attaq/states.cpp | 6 +++---
examples/animation/sub-attaq/states.h | 10 ++++-----
examples/animation/sub-attaq/submarine.cpp | 8 +++----
examples/animation/sub-attaq/submarine.h | 4 ++--
examples/animation/sub-attaq/submarine_p.h | 4 ++--
examples/animation/sub-attaq/torpedo.cpp | 6 +++---
examples/animation/sub-attaq/torpedo.h | 4 ++--
18 files changed, 52 insertions(+), 54 deletions(-)
diff --git a/examples/animation/sub-attaq/animationmanager.cpp b/examples/animation/sub-attaq/animationmanager.cpp
index 9f99426..5b9282a 100644
--- a/examples/animation/sub-attaq/animationmanager.cpp
+++ b/examples/animation/sub-attaq/animationmanager.cpp
@@ -48,7 +48,7 @@
#else
# include
#endif
-#include
+#include
// the universe's only animation manager
AnimationManager *AnimationManager::instance = 0;
diff --git a/examples/animation/sub-attaq/animationmanager.h b/examples/animation/sub-attaq/animationmanager.h
index fe92680..69ec3d7 100644
--- a/examples/animation/sub-attaq/animationmanager.h
+++ b/examples/animation/sub-attaq/animationmanager.h
@@ -42,7 +42,7 @@
#ifndef ANIMATIONMANAGER_H
#define ANIMATIONMANAGER_H
-#include
+#include
class QAbstractAnimation;
diff --git a/examples/animation/sub-attaq/boat.cpp b/examples/animation/sub-attaq/boat.cpp
index 5b270c0..b1995dd 100644
--- a/examples/animation/sub-attaq/boat.cpp
+++ b/examples/animation/sub-attaq/boat.cpp
@@ -59,12 +59,12 @@
# include "qpauseanimation.h"
#include "qsequentialanimationgroup.h"
#else
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
#endif
static QAbstractAnimation *setupDestroyAnimation(Boat *boat)
diff --git a/examples/animation/sub-attaq/boat.h b/examples/animation/sub-attaq/boat.h
index 44de367..b28cf20 100644
--- a/examples/animation/sub-attaq/boat.h
+++ b/examples/animation/sub-attaq/boat.h
@@ -43,10 +43,8 @@
#define __BOAT__H__
//Qt
-#include
-#include
-
-#include
+#include
+#include
#if defined(QT_EXPERIMENTAL_SOLUTION)
# include "qtgraphicswidget.h"
diff --git a/examples/animation/sub-attaq/graphicsscene.cpp b/examples/animation/sub-attaq/graphicsscene.cpp
index a66925c..2a6f83c 100644
--- a/examples/animation/sub-attaq/graphicsscene.cpp
+++ b/examples/animation/sub-attaq/graphicsscene.cpp
@@ -61,20 +61,20 @@
#include "qfinalstate.h"
#include "qpauseanimation.h"
#else
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
#endif
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
//helper function that creates an animation for position and inserts it into group
static CustomPropertyAnimation *addGraphicsItemPosAnimation(QSequentialAnimationGroup *group,
diff --git a/examples/animation/sub-attaq/graphicsscene.h b/examples/animation/sub-attaq/graphicsscene.h
index bc9734c..0840564 100644
--- a/examples/animation/sub-attaq/graphicsscene.h
+++ b/examples/animation/sub-attaq/graphicsscene.h
@@ -43,13 +43,13 @@
#define __GRAPHICSSCENE__H__
//Qt
-#include
-#include
+#include
+#include
#if defined(QT_EXPERIMENTAL_SOLUTION)
# include "qstate.h"
#else
-# include
+# include
#endif
diff --git a/examples/animation/sub-attaq/mainwindow.cpp b/examples/animation/sub-attaq/mainwindow.cpp
index c25b9ef..a166241 100644
--- a/examples/animation/sub-attaq/mainwindow.cpp
+++ b/examples/animation/sub-attaq/mainwindow.cpp
@@ -47,7 +47,7 @@
#include
#endif
//Qt
-#include
+#include
MainWindow::MainWindow() : QMainWindow(0)
{
diff --git a/examples/animation/sub-attaq/mainwindow.h b/examples/animation/sub-attaq/mainwindow.h
index 6289b3f..72d1324 100644
--- a/examples/animation/sub-attaq/mainwindow.h
+++ b/examples/animation/sub-attaq/mainwindow.h
@@ -43,7 +43,7 @@
#define __MAINWINDOW__H__
//Qt
-#include
+#include
class GraphicsScene;
class QGraphicsView;
diff --git a/examples/animation/sub-attaq/pixmapitem.cpp b/examples/animation/sub-attaq/pixmapitem.cpp
index aa8b552..22a363f 100644
--- a/examples/animation/sub-attaq/pixmapitem.cpp
+++ b/examples/animation/sub-attaq/pixmapitem.cpp
@@ -43,7 +43,7 @@
#include "pixmapitem.h"
//Qt
-#include
+#include
PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent) : QGraphicsPixmapItem(parent),name(fileName)
{
diff --git a/examples/animation/sub-attaq/pixmapitem.h b/examples/animation/sub-attaq/pixmapitem.h
index f3c1a41..31022c1 100644
--- a/examples/animation/sub-attaq/pixmapitem.h
+++ b/examples/animation/sub-attaq/pixmapitem.h
@@ -46,7 +46,7 @@
#include "graphicsscene.h"
//Qt
-#include
+#include
class PixmapItem : public QGraphicsPixmapItem
{
diff --git a/examples/animation/sub-attaq/progressitem.h b/examples/animation/sub-attaq/progressitem.h
index 006cc6d..7b8db4d 100644
--- a/examples/animation/sub-attaq/progressitem.h
+++ b/examples/animation/sub-attaq/progressitem.h
@@ -43,7 +43,7 @@
#define PROGRESSITEM_H
//Qt
-#include
+#include
class ProgressItem : public QGraphicsTextItem
{
diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp
index 5dce445..1036fdf 100644
--- a/examples/animation/sub-attaq/states.cpp
+++ b/examples/animation/sub-attaq/states.cpp
@@ -49,8 +49,8 @@
#include "progressitem.h"
//Qt
-#include
-#include
+#include
+#include
#if defined(QT_EXPERIMENTAL_SOLUTION)
#include "qstatemachine.h"
#include "qkeyeventtransition.h"
@@ -60,7 +60,7 @@
#include
#include
#include
-#include
+#include
#endif
PlayState::PlayState(GraphicsScene *scene, QState *parent)
diff --git a/examples/animation/sub-attaq/states.h b/examples/animation/sub-attaq/states.h
index 8dbdf86..ec69ae7 100644
--- a/examples/animation/sub-attaq/states.h
+++ b/examples/animation/sub-attaq/states.h
@@ -49,12 +49,12 @@
#include "qpropertyanimation.h"
#include "qkeyeventtransition.h"
#else
-#include
-#include
-#include
-# include
+#include
+#include
+#include
+# include
#endif
-#include
+#include
class GraphicsScene;
class Boat;
diff --git a/examples/animation/sub-attaq/submarine.cpp b/examples/animation/sub-attaq/submarine.cpp
index b8a476e..0f03efc 100644
--- a/examples/animation/sub-attaq/submarine.cpp
+++ b/examples/animation/sub-attaq/submarine.cpp
@@ -56,10 +56,10 @@
# include "qsequentialanimationgroup.h"
# include "qpauseanimation.h"
#else
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
#endif
static QAbstractAnimation *setupDestroyAnimation(SubMarine *sub)
diff --git a/examples/animation/sub-attaq/submarine.h b/examples/animation/sub-attaq/submarine.h
index 562b4cf..7ee587d 100644
--- a/examples/animation/sub-attaq/submarine.h
+++ b/examples/animation/sub-attaq/submarine.h
@@ -47,8 +47,8 @@
#include "qvariantanimation.h"
#include "qgraphicswidget.h"
#else
-#include
-#include
+#include
+#include
#endif
class PixmapItem;
diff --git a/examples/animation/sub-attaq/submarine_p.h b/examples/animation/sub-attaq/submarine_p.h
index 354a406..918e7f5 100644
--- a/examples/animation/sub-attaq/submarine_p.h
+++ b/examples/animation/sub-attaq/submarine_p.h
@@ -51,9 +51,9 @@
#if defined(QT_EXPERIMENTAL_SOLUTION)
#include "qpropertyanimation.h"
#else
-#include
+#include
#endif
-#include
+#include
//This state is describing when the boat is moving right
class MovementState : public QAnimationState
diff --git a/examples/animation/sub-attaq/torpedo.cpp b/examples/animation/sub-attaq/torpedo.cpp
index b24948d..88f1112 100644
--- a/examples/animation/sub-attaq/torpedo.cpp
+++ b/examples/animation/sub-attaq/torpedo.cpp
@@ -52,9 +52,9 @@
#include "qstatemachine.h"
#include "qfinalstate.h"
#else
-#include
-#include
-#include
+#include
+#include
+#include
#endif
Torpedo::Torpedo(QGraphicsItem * parent, Qt::WindowFlags wFlags)
diff --git a/examples/animation/sub-attaq/torpedo.h b/examples/animation/sub-attaq/torpedo.h
index 33bbc04..2e44e41 100644
--- a/examples/animation/sub-attaq/torpedo.h
+++ b/examples/animation/sub-attaq/torpedo.h
@@ -43,13 +43,13 @@
#define __TORPEDO__H__
//Qt
-#include
+#include
#if defined(QT_EXPERIMENTAL_SOLUTION)
# include "qvariantanimation.h"
# include "qgraphicswidget.h"
#else
-# include
+# include
# include
#endif
--
cgit v0.12
From 53e8c64d0ed050bc195bb4851da2f6d65b5c8ca5 Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Mon, 27 Apr 2009 17:38:01 +0200
Subject: make the entry/exit order well-defined for all combinations of states
Comparing pointers meant that the order could be different each run.
Now the entry/exit order will be consistent, even for states that are
in disjoint parts of the hierarchy.
---
src/corelib/statemachine/qstatemachine.cpp | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 2d3eea1..8cee1fc 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -234,6 +234,18 @@ Q_CORE_EXPORT const QStateMachinePrivate::Handler *qcoreStateMachineHandler()
return &qt_kernel_statemachine_handler;
}
+static int indexOfDescendant(QState *s, QAbstractState *desc)
+{
+ QList childStates = QStatePrivate::get(s)->childStates();
+ for (int i = 0; i < childStates.size(); ++i) {
+ QAbstractState *c = childStates.at(i);
+ if ((c == desc) || QStateMachinePrivate::isDescendantOf(desc, c)) {
+ return i;
+ }
+ }
+ return -1;
+}
+
bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState *s2)
{
if (s1->parent() == s2->parent()) {
@@ -244,8 +256,9 @@ bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState
} else if (isDescendantOf(s2, s1)) {
return true;
} else {
- // ### fixme
- return s1 < s2;
+ QState *lca = findLCA(QList() << s1 << s2);
+ Q_ASSERT(lca != 0);
+ return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));
}
}
@@ -259,8 +272,9 @@ bool QStateMachinePrivate::stateExitLessThan(QAbstractState *s1, QAbstractState
} else if (isDescendantOf(s2, s1)) {
return false;
} else {
- // ### fixme
- return s2 < s1;
+ QState *lca = findLCA(QList() << s1 << s2);
+ Q_ASSERT(lca != 0);
+ return (indexOfDescendant(lca, s1) < indexOfDescendant(lca, s2));
}
}
--
cgit v0.12
From a460bee2b3051bf6a5176b5c620f81ff962a7f53 Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Mon, 27 Apr 2009 18:07:03 +0200
Subject: replace QStateFinished{Event,Transition} by QState::finished() signal
Not worth it having two public classes when the same can be achieved
by having a signal.
---
src/corelib/statemachine/qfinalstate.cpp | 2 -
src/corelib/statemachine/qstate.cpp | 30 ++--
src/corelib/statemachine/qstate.h | 5 +-
src/corelib/statemachine/qstate_p.h | 2 +
src/corelib/statemachine/qstatefinishedevent.h | 70 --------
.../statemachine/qstatefinishedtransition.cpp | 182 ---------------------
.../statemachine/qstatefinishedtransition.h | 88 ----------
src/corelib/statemachine/qstatemachine.cpp | 60 +------
src/corelib/statemachine/statemachine.pri | 3 -
tests/auto/qstatemachine/tst_qstatemachine.cpp | 4 +-
10 files changed, 23 insertions(+), 423 deletions(-)
delete mode 100644 src/corelib/statemachine/qstatefinishedevent.h
delete mode 100644 src/corelib/statemachine/qstatefinishedtransition.cpp
delete mode 100644 src/corelib/statemachine/qstatefinishedtransition.h
diff --git a/src/corelib/statemachine/qfinalstate.cpp b/src/corelib/statemachine/qfinalstate.cpp
index 16e080e..6a1b608 100644
--- a/src/corelib/statemachine/qfinalstate.cpp
+++ b/src/corelib/statemachine/qfinalstate.cpp
@@ -76,8 +76,6 @@ QT_BEGIN_NAMESPACE
machine.setInitialState(s1);
machine.start();
\endcode
-
- \sa QStateFinishedTransition
*/
class QFinalStatePrivate : public QAbstractStatePrivate
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index 56a855e..9bda250 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -46,7 +46,6 @@
#include "qabstracttransition.h"
#include "qabstracttransition_p.h"
#include "qsignaltransition.h"
-#include "qstatefinishedtransition.h"
#include "qstatemachine.h"
#include "qstatemachine_p.h"
@@ -75,9 +74,6 @@ QT_BEGIN_NAMESPACE
The addHistoryState() function adds a history state.
- The addFinishedTransition() function creates and adds a transition that's
- triggered when a final child state is entered.
-
The setErrorState() sets the state's error state. The error state is the
state that the state machine will transition to if an error is detected when
attempting to enter the state (e.g. because no initial state has been set).
@@ -134,6 +130,12 @@ const QStatePrivate *QStatePrivate::get(const QState *q)
return q->d_func();
}
+void QStatePrivate::emitFinished()
+{
+ Q_Q(QState);
+ emit q->finished();
+}
+
/*!
Constructs a new state with the given \a parent state.
*/
@@ -294,20 +296,6 @@ QSignalTransition *QState::addTransition(QObject *sender, const char *signal,
return trans;
}
-/*!
- Adds a transition that's triggered by the finished event of this state, and
- returns the new QStateFinishedTransition object. The transition has the
- given \a target state.
-
- \sa QStateFinishedEvent
-*/
-QStateFinishedTransition *QState::addFinishedTransition(QAbstractState *target)
-{
- QStateFinishedTransition *trans = new QStateFinishedTransition(this, QList() << target);
- addTransition(trans);
- return trans;
-}
-
namespace {
// ### Make public?
@@ -431,4 +419,10 @@ bool QState::event(QEvent *e)
return QAbstractState::event(e);
}
+/*!
+ \fn QState::finished()
+
+ This signal is emitted when a final child state of this state is entered.
+*/
+
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
index 7c64c80..70211c1 100644
--- a/src/corelib/statemachine/qstate.h
+++ b/src/corelib/statemachine/qstate.h
@@ -57,7 +57,6 @@ QT_MODULE(Core)
class QAbstractTransition;
class QHistoryState;
class QSignalTransition;
-class QStateFinishedTransition;
class QStatePrivate;
class Q_CORE_EXPORT QState : public QAbstractState
@@ -84,7 +83,6 @@ public:
QAbstractTransition *addTransition(QAbstractTransition *transition);
QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target);
QAbstractTransition *addTransition(QAbstractState *target);
- QStateFinishedTransition *addFinishedTransition(QAbstractState *target);
void removeTransition(QAbstractTransition *transition);
QList transitions() const;
@@ -93,6 +91,9 @@ public:
QAbstractState *initialState() const;
void setInitialState(QAbstractState *state);
+Q_SIGNALS:
+ void finished();
+
protected:
void onEntry();
void onExit();
diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h
index 8d040d0..2df6823 100644
--- a/src/corelib/statemachine/qstate_p.h
+++ b/src/corelib/statemachine/qstate_p.h
@@ -74,6 +74,8 @@ public:
QList historyStates() const;
QList transitions() const;
+ void emitFinished();
+
QAbstractState *errorState;
bool isParallelGroup;
QAbstractState *initialState;
diff --git a/src/corelib/statemachine/qstatefinishedevent.h b/src/corelib/statemachine/qstatefinishedevent.h
deleted file mode 100644
index c2f81f7..0000000
--- a/src/corelib/statemachine/qstatefinishedevent.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSTATEFINISHEDEVENT_H
-#define QSTATEFINISHEDEVENT_H
-
-#include
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QState;
-
-class Q_CORE_EXPORT QStateFinishedEvent : public QEvent
-{
-public:
- QStateFinishedEvent(QState *state);
- ~QStateFinishedEvent();
-
- QState *state() const;
-
-private:
- QState *m_state;
- void *d;
-};
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/corelib/statemachine/qstatefinishedtransition.cpp b/src/corelib/statemachine/qstatefinishedtransition.cpp
deleted file mode 100644
index 151a274..0000000
--- a/src/corelib/statemachine/qstatefinishedtransition.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qstatefinishedtransition.h"
-#include "qstatefinishedevent.h"
-#include "qabstracttransition_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QStateFinishedTransition
-
- \brief The QStateFinishedTransition class provides a transition that triggers when a state is finished.
-
- \ingroup statemachine
-
- A state is finished when one of its final child states (a QFinalState) is
- entered; this will cause a QStateFinishedEvent to be generated. The
- QStateFinishedTransition class provides a way of associating a transition
- with such an event. QStateFinishedTransition is part of \l{The State Machine
- Framework}.
-
- \code
- QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
- QState *s11 = new QState(s1);
- QFinalState *s12 = new QFinalState(s1);
- s11->addTransition(s12);
-
- QState *s2 = new QState(machine.rootState());
- QStateFinishedTransition *finishedTransition = new QStateFinishedTransition(s1);
- finishedTransition->setTargetState(s2);
- s1->addTransition(finishedTransition);
- \endcode
-
- \sa QState::addFinishedTransition(), QStateFinishedEvent
-*/
-
-/*!
- \property QStateFinishedTransition::state
-
- \brief the state whose QStateFinishedEvent this transition is associated with
-*/
-
-class QStateFinishedTransitionPrivate : public QAbstractTransitionPrivate
-{
- Q_DECLARE_PUBLIC(QStateFinishedTransition)
-public:
- QStateFinishedTransitionPrivate();
-
- static QStateFinishedTransitionPrivate *get(QStateFinishedTransition *q);
-
- QState *state;
-};
-
-QStateFinishedTransitionPrivate::QStateFinishedTransitionPrivate()
-{
- state = 0;
-}
-
-QStateFinishedTransitionPrivate *QStateFinishedTransitionPrivate::get(QStateFinishedTransition *q)
-{
- return q->d_func();
-}
-
-/*!
- Constructs a new QStateFinishedTransition object that has the given \a
- sourceState.
-*/
-QStateFinishedTransition::QStateFinishedTransition(QState *sourceState)
- : QAbstractTransition(*new QStateFinishedTransitionPrivate, sourceState)
-{
-}
-
-/*!
- Constructs a new QStateFinishedTransition object associated with the given
- \a state, and that has the given \a targets and \a sourceState.
-*/
-QStateFinishedTransition::QStateFinishedTransition(
- QState *state, const QList &targets, QState *sourceState)
- : QAbstractTransition(*new QStateFinishedTransitionPrivate, targets, sourceState)
-{
- Q_D(QStateFinishedTransition);
- d->state = state;
-}
-
-/*!
- Destroys this QStateFinishedTransition.
-*/
-QStateFinishedTransition::~QStateFinishedTransition()
-{
-}
-
-/*!
- Returns the state associated with this QStateFinishedTransition.
-*/
-QState *QStateFinishedTransition::state() const
-{
- Q_D(const QStateFinishedTransition);
- return d->state;
-}
-
-/*!
- Sets the \a state associated with this QStateFinishedTransition.
-*/
-void QStateFinishedTransition::setState(QState *state)
-{
- Q_D(QStateFinishedTransition);
- d->state = state;
-}
-
-/*!
- \reimp
-*/
-bool QStateFinishedTransition::eventTest(QEvent *event) const
-{
- Q_D(const QStateFinishedTransition);
-#ifndef QT_STATEMACHINE_SOLUTION
- if (event->type() == QEvent::StateFinished) {
-#else
- if (event->type() == QEvent::Type(QEvent::User-2)) {
-#endif
- QStateFinishedEvent *sfe = static_cast(event);
- return (sfe->state() == d->state);
- }
- return false;
-}
-
-/*!
- \reimp
-*/
-void QStateFinishedTransition::onTransition()
-{
-}
-
-/*!
- \reimp
-*/
-bool QStateFinishedTransition::event(QEvent *e)
-{
- return QAbstractTransition::event(e);
-}
-
-QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstatefinishedtransition.h b/src/corelib/statemachine/qstatefinishedtransition.h
deleted file mode 100644
index ed86288..0000000
--- a/src/corelib/statemachine/qstatefinishedtransition.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Qt Software Information (qt-info@nokia.com)
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at qt-sales@nokia.com.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QSTATEFINISHEDTRANSITION_H
-#define QSTATEFINISHEDTRANSITION_H
-
-#ifndef QT_STATEMACHINE_SOLUTION
-#include
-#else
-#include "qabstracttransition.h"
-#endif
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Core)
-
-class QState;
-
-class QStateFinishedTransitionPrivate;
-class Q_CORE_EXPORT QStateFinishedTransition : public QAbstractTransition
-{
- Q_OBJECT
- Q_PROPERTY(QState* state READ state WRITE setState)
-public:
- QStateFinishedTransition(QState *sourceState = 0);
- QStateFinishedTransition(QState *state, const QList &targets,
- QState *sourceState = 0);
- ~QStateFinishedTransition();
-
- QState *state() const; // ### name
- void setState(QState *state);
-
-protected:
- bool eventTest(QEvent *event) const;
- void onTransition();
-
- bool event(QEvent *e);
-
-private:
- Q_DISABLE_COPY(QStateFinishedTransition)
- Q_DECLARE_PRIVATE(QStateFinishedTransition)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 8cee1fc..632390f 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -52,8 +52,6 @@
#include "qfinalstate.h"
#include "qhistorystate.h"
#include "qhistorystate_p.h"
-#include "qstatefinishedevent.h"
-#include "qstatefinishedtransition.h"
#include "qstate.h"
#include "qstate_p.h"
#ifndef QT_STATEMACHINE_SOLUTION
@@ -524,9 +522,9 @@ QList QStateMachinePrivate::enterStates(const QListparentState();
#ifdef QSTATEMACHINE_DEBUG
- qDebug() << q << ": posting finished event for" << parent;
+ qDebug() << q << ": emitting finished signal for" << parent;
#endif
- internalEventQueue.append(new QStateFinishedEvent(parent));
+ QStatePrivate::get(parent)->emitFinished();
if (grandparent && isParallel(grandparent)) {
bool allChildStatesFinal = true;
QList childStates = QStatePrivate::get(grandparent)->childStates();
@@ -539,9 +537,9 @@ QList QStateMachinePrivate::enterStates(const QListemitFinished();
}
}
}
@@ -2102,56 +2100,6 @@ QSignalEvent::~QSignalEvent()
Returns the arguments of the signal.
*/
-/*!
- \class QStateFinishedEvent
-
- \brief The QStateFinishedEvent class contains parameters that describe a state that has finished.
-
- \since 4.6
- \ingroup statemachine
-
- A state is finished when one of its final child states (a QFinalState) is
- entered; this will cause a QStateFinishedEvent to be generated by the state
- machine. QStateFinishedEvent is part of \l{The State Machine Framework}.
-
- Typically you do not create QStateFinishedEvent objects yourself, but rather
- use QStateFinishedTransition to create a transition that's triggered by a
- state's finished event.
-
- \sa QStateFinishedTransition
-*/
-
-/*!
- \internal
-
- Constructs a new QStateFinishedEvent object associated with the given \a state.
-*/
-QStateFinishedEvent::QStateFinishedEvent(QState *state)
- :
-#ifndef QT_STATEMACHINE_SOLUTION
- QEvent(StateFinished)
-#else
- QEvent(QEvent::Type(QEvent::User-2))
-#endif
- , m_state(state), d(0)
-{
-}
-
-/*!
- Destroys this QStateFinishedEvent.
-*/
-QStateFinishedEvent::~QStateFinishedEvent()
-{
-}
-
-/*!
- Returns the state associated with this QStateFinishedEvent.
-*/
-QState *QStateFinishedEvent::state() const
-{
- return m_state;
-}
-
QT_END_NAMESPACE
#include "moc_qstatemachine.cpp"
diff --git a/src/corelib/statemachine/statemachine.pri b/src/corelib/statemachine/statemachine.pri
index 620c7a0..69f887c 100644
--- a/src/corelib/statemachine/statemachine.pri
+++ b/src/corelib/statemachine/statemachine.pri
@@ -10,8 +10,6 @@ HEADERS += $$PWD/qstatemachine.h \
$$PWD/qhistorystate_p.h \
$$PWD/qabstracttransition.h \
$$PWD/qabstracttransition_p.h \
- $$PWD/qstatefinishedevent.h \
- $$PWD/qstatefinishedtransition.h \
$$PWD/qsignalevent.h \
$$PWD/qsignaltransition.h \
$$PWD/qsignaltransition_p.h
@@ -22,7 +20,6 @@ SOURCES += $$PWD/qstatemachine.cpp \
$$PWD/qfinalstate.cpp \
$$PWD/qhistorystate.cpp \
$$PWD/qabstracttransition.cpp \
- $$PWD/qstatefinishedtransition.cpp \
$$PWD/qsignaltransition.cpp
!contains(DEFINES, QT_NO_STATEMACHINE_EVENTFILTER) {
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 2fa9b1a..54446a6 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -1231,7 +1231,7 @@ void tst_QStateMachine::stateFinished()
s1_1->addTransition(s1_2);
s1->setInitialState(s1_1);
QFinalState *s2 = new QFinalState(machine.rootState());
- s1->addTransition(new QStateFinishedTransition(s1, QList() << s2));
+ s1->addTransition(s1, SIGNAL(finished()), s2);
machine.setInitialState(s1);
QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
machine.start();
@@ -1260,7 +1260,7 @@ void tst_QStateMachine::parallelStates()
QFinalState *s2 = new QFinalState();
machine.addState(s2);
- s1->addFinishedTransition(s2);
+ s1->addTransition(s1, SIGNAL(finished()), s2);
machine.setInitialState(s1);
QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
--
cgit v0.12
From 77abdfda731e010f8f93eb083478d10c7fd860fb Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Tue, 28 Apr 2009 13:10:35 +0200
Subject: compile after api changes
---
examples/animation/sub-attaq/states.cpp | 4 ++--
examples/statemachine/composition/main.cpp | 4 ++--
examples/statemachine/trafficlight/main.cpp | 8 ++++----
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/examples/animation/sub-attaq/states.cpp b/examples/animation/sub-attaq/states.cpp
index f476f55..b381db7 100644
--- a/examples/animation/sub-attaq/states.cpp
+++ b/examples/animation/sub-attaq/states.cpp
@@ -140,10 +140,10 @@ void PlayState::onEntry()
QFinalState *final = new QFinalState(machine->rootState());
//We win we should reach the final state
- winState->addFinishedTransition(final);
+ winState->addTransition(winState, SIGNAL(finished()), final);
//We lost we should reach the final state
- lostState->addFinishedTransition(final);
+ lostState->addTransition(lostState, SIGNAL(finished()), final);
machine->start();
}
diff --git a/examples/statemachine/composition/main.cpp b/examples/statemachine/composition/main.cpp
index 927fc62..0afff66 100644
--- a/examples/statemachine/composition/main.cpp
+++ b/examples/statemachine/composition/main.cpp
@@ -86,11 +86,11 @@ int main(int argc, char **argv)
s2_timer->addTransition(&t2, SIGNAL(timeout()), s2_done);
s2->setInitialState(s2_timer);
- s1->addFinishedTransition(s2);
+ s1->addTransition(s1, SIGNAL(finished()), s2);
QFinalState *s3 = new QFinalState();
s3->setObjectName("s3");
- s2->addFinishedTransition(s3);
+ s2->addTransition(s2, SIGNAL(finished()), s3);
machine.addState(s1);
machine.addState(s2);
diff --git a/examples/statemachine/trafficlight/main.cpp b/examples/statemachine/trafficlight/main.cpp
index 115ecad..ed0eeea 100644
--- a/examples/statemachine/trafficlight/main.cpp
+++ b/examples/statemachine/trafficlight/main.cpp
@@ -157,14 +157,14 @@ public:
redGoingYellow->setObjectName("redGoingYellow");
LightState *yellowGoingGreen = new LightState(widget->yellowLight(), 1000);
yellowGoingGreen->setObjectName("yellowGoingGreen");
- redGoingYellow->addFinishedTransition(yellowGoingGreen);
+ redGoingYellow->addTransition(redGoingYellow, SIGNAL(finished()), yellowGoingGreen);
LightState *greenGoingYellow = new LightState(widget->greenLight(), 3000);
greenGoingYellow->setObjectName("greenGoingYellow");
- yellowGoingGreen->addFinishedTransition(greenGoingYellow);
+ yellowGoingGreen->addTransition(yellowGoingGreen, SIGNAL(finished()), greenGoingYellow);
LightState *yellowGoingRed = new LightState(widget->yellowLight(), 1000);
yellowGoingRed->setObjectName("yellowGoingRed");
- greenGoingYellow->addFinishedTransition(yellowGoingRed);
- yellowGoingRed->addFinishedTransition(redGoingYellow);
+ greenGoingYellow->addTransition(greenGoingYellow, SIGNAL(finished()), yellowGoingRed);
+ yellowGoingRed->addTransition(yellowGoingRed, SIGNAL(finished()), redGoingYellow);
machine->addState(redGoingYellow);
machine->addState(yellowGoingGreen);
--
cgit v0.12
From 77ed0fdc4a74113982dbcd70b689b2addf30516c Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Tue, 28 Apr 2009 13:13:56 +0200
Subject: kill StateFinished event type since it doesn't exist anymore
---
src/corelib/kernel/qcoreevent.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h
index 5e76976..674b5b0 100644
--- a/src/corelib/kernel/qcoreevent.h
+++ b/src/corelib/kernel/qcoreevent.h
@@ -269,8 +269,7 @@ public:
CocoaRequestModal = 190, // Internal for requesting an application modal Cocoa Window
MacGLClearDrawable = 191, // Internal Cocoa, the window has changed, so we must clear
- Signal = 191,
- StateFinished = 192,
+ Signal = 192,
Bound = 193,
// 512 reserved for Qt Jambi's MetaCall event
--
cgit v0.12
From a3e862a07bd724c02d1860eb106dfb245659775b Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Mon, 27 Apr 2009 15:24:41 +0200
Subject: Some updates to the errorstate example.
Added cannon firing. There are some problems left: For some reason the parallel
state group does not work properly, so only one tank moves even if you add more.
There also seems to be something wrong with historyState->setDefaultState().
---
examples/statemachine/errorstate/errorstate.pro | 4 +-
examples/statemachine/errorstate/gameitem.cpp | 67 ++++++++++
examples/statemachine/errorstate/gameitem.h | 22 ++++
examples/statemachine/errorstate/mainwindow.cpp | 42 +++++--
examples/statemachine/errorstate/mainwindow.h | 8 +-
examples/statemachine/errorstate/rocketitem.cpp | 60 +++++++++
examples/statemachine/errorstate/rocketitem.h | 28 +++++
examples/statemachine/errorstate/tank.h | 4 +-
examples/statemachine/errorstate/tankitem.cpp | 136 ++++++---------------
examples/statemachine/errorstate/tankitem.h | 21 ++--
.../random_ai/random_ai_plugin.cpp | 2 +-
.../errorstateplugins/random_ai/random_ai_plugin.h | 2 +-
12 files changed, 270 insertions(+), 126 deletions(-)
create mode 100644 examples/statemachine/errorstate/gameitem.cpp
create mode 100644 examples/statemachine/errorstate/gameitem.h
create mode 100644 examples/statemachine/errorstate/rocketitem.cpp
create mode 100644 examples/statemachine/errorstate/rocketitem.h
diff --git a/examples/statemachine/errorstate/errorstate.pro b/examples/statemachine/errorstate/errorstate.pro
index d937b02..c159f94 100644
--- a/examples/statemachine/errorstate/errorstate.pro
+++ b/examples/statemachine/errorstate/errorstate.pro
@@ -8,6 +8,6 @@ DEPENDPATH += .
INCLUDEPATH += C:/dev/kinetic/examples/statemachine/errorstate/. .
# Input
-HEADERS += mainwindow.h plugin.h tank.h tankitem.h
-SOURCES += main.cpp mainwindow.cpp tankitem.cpp
+HEADERS += mainwindow.h plugin.h tank.h tankitem.h rocketitem.h gameitem.h
+SOURCES += main.cpp mainwindow.cpp tankitem.cpp rocketitem.cpp gameitem.cpp
CONFIG += console
diff --git a/examples/statemachine/errorstate/gameitem.cpp b/examples/statemachine/errorstate/gameitem.cpp
new file mode 100644
index 0000000..786cf51
--- /dev/null
+++ b/examples/statemachine/errorstate/gameitem.cpp
@@ -0,0 +1,67 @@
+#include "gameitem.h"
+
+#include
+
+QPointF GameItem::tryMove(const QPointF &requestedPosition, QLineF *collidedLine,
+ QGraphicsItem **collidedItem) const
+{
+ QLineF movementPath(pos(), requestedPosition);
+
+ qreal cannonLength = 0.0;
+ {
+ QPointF p1 = boundingRect().center();
+ QPointF p2 = QPointF(boundingRect().right() + 10.0, p1.y());
+
+ cannonLength = QLineF(mapToScene(p1), mapToScene(p2)).length();
+ }
+
+ movementPath.setLength(movementPath.length() + cannonLength);
+
+ QRectF boundingRectPath(QPointF(qMin(movementPath.x1(), movementPath.x2()), qMin(movementPath.y1(), movementPath.y2())),
+ QPointF(qMax(movementPath.x1(), movementPath.x2()), qMax(movementPath.y1(), movementPath.y2())));
+
+ QList itemsInRect = scene()->items(boundingRectPath, Qt::IntersectsItemBoundingRect);
+
+ QPointF nextPoint = requestedPosition;
+ QRectF sceneRect = scene()->sceneRect();
+
+ foreach (QGraphicsItem *item, itemsInRect) {
+ if (item == static_cast(this))
+ continue;
+
+ QPolygonF mappedBoundingRect = item->mapToScene(item->boundingRect());
+ for (int i=0; i sceneRect.right())
+ nextPoint.rx() = sceneRect.right();
+ if (nextPoint.y() < sceneRect.top())
+ nextPoint.ry() = sceneRect.top();
+ if (nextPoint.y() > sceneRect.bottom())
+ nextPoint.ry() = sceneRect.bottom();
+
+ return nextPoint;
+}
+
diff --git a/examples/statemachine/errorstate/gameitem.h b/examples/statemachine/errorstate/gameitem.h
new file mode 100644
index 0000000..6ca32b7
--- /dev/null
+++ b/examples/statemachine/errorstate/gameitem.h
@@ -0,0 +1,22 @@
+#ifndef GAMEITEM_H
+#define GAMEITEM_H
+
+#include
+
+class QLineF;
+class GameItem: public QGraphicsItem
+{
+public:
+ enum { Type = UserType + 1 };
+
+ int type() const { return Type; }
+ virtual void idle(qreal elapsed) = 0;
+
+ virtual void hitByRocket() = 0;
+
+protected:
+ QPointF tryMove(const QPointF &requestedPosition, QLineF *collidedLine = 0,
+ QGraphicsItem **collidedItem = 0) const;
+};
+
+#endif
diff --git a/examples/statemachine/errorstate/mainwindow.cpp b/examples/statemachine/errorstate/mainwindow.cpp
index 598756f..c0af62d 100644
--- a/examples/statemachine/errorstate/mainwindow.cpp
+++ b/examples/statemachine/errorstate/mainwindow.cpp
@@ -1,5 +1,6 @@
#include "mainwindow.h"
#include "tankitem.h"
+#include "rocketitem.h"
#include "plugin.h"
#include
@@ -13,7 +14,7 @@
#include
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
+ : QMainWindow(parent), m_scene(0), m_machine(0), m_runningState(0), m_started(false)
{
init();
}
@@ -37,6 +38,7 @@ void MainWindow::init()
setWindowTitle("Pluggable Tank Game");
QGraphicsView *view = new QGraphicsView(this);
+ view->setRenderHints(QPainter::Antialiasing);
setCentralWidget(view);
m_scene = new QGraphicsScene(this);
@@ -118,6 +120,7 @@ void MainWindow::init()
stoppedState->assignProperty(runGameAction, "enabled", true);
stoppedState->assignProperty(stopGameAction, "enabled", false);
+ stoppedState->assignProperty(this, "started", false);
m_machine->setInitialState(stoppedState);
QState *spawnsAvailable = new QState(stoppedState);
@@ -146,20 +149,42 @@ void MainWindow::init()
timer->setInterval(100);
connect(timer, SIGNAL(timeout()), this, SLOT(runStep()));
connect(m_runningState, SIGNAL(entered()), timer, SLOT(start()));
- connect(m_runningState, SIGNAL(exited()), timer, SLOT(stop()));
+ connect(m_runningState, SIGNAL(exited()), timer, SLOT(stop()));
m_time.start();
}
void MainWindow::runStep()
{
- int elapsed = m_time.elapsed();
- if (elapsed > 0) {
+ if (!m_started) {
m_time.restart();
- qreal elapsedSecs = elapsed / 1000.0;
- QList tankItems = qFindChildren(this);
- foreach (TankItem *tankItem, tankItems)
- tankItem->idle(elapsedSecs);
+ m_started = true;
+ } else {
+ int elapsed = m_time.elapsed();
+ if (elapsed > 0) {
+ m_time.restart();
+ qreal elapsedSecs = elapsed / 1000.0;
+ QList items = m_scene->items();
+ foreach (QGraphicsItem *item, items) {
+ GameItem *gameItem = qgraphicsitem_cast(item);
+ if (gameItem != 0)
+ gameItem->idle(elapsedSecs);
+ }
+ }
+ }
+}
+
+void MainWindow::addRocket()
+{
+ TankItem *tankItem = qobject_cast(sender());
+ if (tankItem != 0) {
+ RocketItem *rocketItem = new RocketItem;
+
+ QPointF s = tankItem->mapToScene(QPointF(tankItem->boundingRect().right() + 10.0,
+ tankItem->boundingRect().center().y()));
+ rocketItem->setPos(s);
+ rocketItem->setDirection(tankItem->direction());
+ m_scene->addItem(rocketItem);
}
}
@@ -175,6 +200,7 @@ void MainWindow::addTank()
if (plugin != 0) {
TankItem *tankItem = m_spawns.takeLast();
m_scene->addItem(tankItem);
+ connect(tankItem, SIGNAL(fireCannon()), this, SLOT(addRocket()));
if (m_spawns.isEmpty())
emit mapFull();
diff --git a/examples/statemachine/errorstate/mainwindow.h b/examples/statemachine/errorstate/mainwindow.h
index 2bd574d..33122eb 100644
--- a/examples/statemachine/errorstate/mainwindow.h
+++ b/examples/statemachine/errorstate/mainwindow.h
@@ -11,12 +11,17 @@ class TankItem;
class MainWindow: public QMainWindow
{
Q_OBJECT
+ Q_PROPERTY(bool started READ started WRITE setStarted)
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
+ void setStarted(bool b) { m_started = b; }
+ bool started() const { return m_started; }
+
public slots:
void addTank();
+ void addRocket();
void runStep();
signals:
@@ -34,7 +39,8 @@ private:
QList m_spawns;
QTime m_time;
-
+
+ bool m_started : 1;
};
#endif
diff --git a/examples/statemachine/errorstate/rocketitem.cpp b/examples/statemachine/errorstate/rocketitem.cpp
new file mode 100644
index 0000000..de9eef7
--- /dev/null
+++ b/examples/statemachine/errorstate/rocketitem.cpp
@@ -0,0 +1,60 @@
+#include "rocketitem.h"
+
+#include
+#include
+
+#include
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+RocketItem::RocketItem()
+ : m_direction(0.0), m_distance(300.0)
+{
+}
+
+QRectF RocketItem::boundingRect() const
+{
+ return QRectF(-1.0, -1.0, 2.0, 2.0);
+}
+
+void RocketItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ painter->setBrush(Qt::black);
+ painter->drawEllipse(boundingRect());
+}
+
+void RocketItem::hitByRocket()
+{
+}
+
+void RocketItem::idle(qreal elapsed)
+{
+ qreal dist = elapsed * speed();
+
+ m_distance -= dist;
+ if (m_distance < 0.0) {
+ scene()->removeItem(this);
+ delete this;
+ return;
+ }
+
+ qreal a = m_direction * M_PI / 180.0;
+
+ qreal yd = dist * sin(a);
+ qreal xd = dist * sin(M_PI / 2.0 - a);
+
+ QPointF requestedPosition = pos() + QPointF(xd, yd);
+ QGraphicsItem *collidedItem = 0;
+ QPointF nextPosition = tryMove(requestedPosition, 0, &collidedItem);
+ if (requestedPosition == nextPosition) {
+ setPos(nextPosition);
+ } else {
+ if (GameItem *gameItem = qgraphicsitem_cast(collidedItem))
+ gameItem->hitByRocket();
+
+ scene()->removeItem(this);
+ delete this;
+ }
+}
diff --git a/examples/statemachine/errorstate/rocketitem.h b/examples/statemachine/errorstate/rocketitem.h
new file mode 100644
index 0000000..9805a8a
--- /dev/null
+++ b/examples/statemachine/errorstate/rocketitem.h
@@ -0,0 +1,28 @@
+#ifndef ROCKETITEM_H
+#define ROCKETITEM_H
+
+#include "gameitem.h"
+
+class RocketItem: public GameItem
+{
+public:
+ RocketItem();
+
+ virtual void idle(qreal elapsed);
+ qreal speed() const { return 100.0; }
+ void setDirection(qreal direction) { m_direction = direction; }
+
+ void hitByRocket();
+
+protected:
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QRectF boundingRect() const;
+
+
+private:
+ qreal m_direction;
+ qreal m_distance;
+};
+
+
+#endif
diff --git a/examples/statemachine/errorstate/tank.h b/examples/statemachine/errorstate/tank.h
index 9def6df..49c5daf 100644
--- a/examples/statemachine/errorstate/tank.h
+++ b/examples/statemachine/errorstate/tank.h
@@ -23,9 +23,9 @@ signals:
public slots:
virtual void moveForwards(qreal length) = 0;
virtual void moveBackwards(qreal length) = 0;
- virtual void turn(qreal newDirection) = 0;
+ virtual void turn(qreal degrees) = 0;
virtual void stop() = 0;
- virtual void fireCannon(qreal distance) = 0;
+ virtual void fireCannon() = 0;
};
#endif
diff --git a/examples/statemachine/errorstate/tankitem.cpp b/examples/statemachine/errorstate/tankitem.cpp
index 21d4a25..814de2b 100644
--- a/examples/statemachine/errorstate/tankitem.cpp
+++ b/examples/statemachine/errorstate/tankitem.cpp
@@ -31,14 +31,18 @@ public:
MoveAction(TankItem *item, qreal distance)
: Action(item), m_distance(distance)
{
+ m_reverse = m_distance < 0.0;
}
bool apply(qreal timeDelta)
{
- qreal dist = timeDelta * item()->speed();
+ qreal dist = timeDelta * item()->speed() * (m_reverse ? -1.0 : 1.0);
+
m_distance -= dist;
- if (qFuzzyCompare(m_distance, 0.0))
- return false;
+ if (m_reverse && m_distance > 0.0)
+ return false;
+ else if (m_distance < 0.0)
+ return false;
qreal a = item()->direction() * M_PI / 180.0;
@@ -51,6 +55,7 @@ public:
private:
qreal m_distance;
+ bool m_reverse;
};
class TurnAction: public Action
@@ -59,14 +64,17 @@ public:
TurnAction(TankItem *item, qreal distance)
: Action(item), m_distance(distance)
{
+ m_reverse = m_distance < 0.0;
}
bool apply(qreal timeDelta)
{
- qreal dist = timeDelta * item()->angularSpeed();
+ qreal dist = timeDelta * item()->angularSpeed() * (m_reverse ? -1.0 : 1.0);
m_distance -= dist;
- if (qFuzzyCompare(m_distance, 0.0))
- return false;
+ if (m_reverse && m_distance > 0.0)
+ return false;
+ else if (m_distance < 0.0)
+ return false;
item()->setDirection(item()->direction() + dist);
return true;
@@ -74,27 +82,12 @@ public:
private:
qreal m_distance;
-};
-
-class FireCannonAction: public Action
-{
-public:
- FireCannonAction(TankItem *item, qreal distance)
- : Action(item), m_distance(distance)
- {
- }
-
- bool apply(qreal )
- {
- return false;
- }
-
-private:
- qreal m_distance;
+ bool m_reverse;
};
TankItem::TankItem(QObject *parent) : Tank(parent), m_currentAction(0), m_currentDirection(0.0)
{
+ connect(this, SIGNAL(fireCannon()), this, SIGNAL(actionCompleted()));
}
void TankItem::idle(qreal elapsed)
@@ -107,6 +100,11 @@ void TankItem::idle(qreal elapsed)
}
}
+void TankItem::hitByRocket()
+{
+ deleteLater();
+}
+
void TankItem::setAction(Action *newAction)
{
if (m_currentAction != 0)
@@ -125,9 +123,9 @@ void TankItem::moveBackwards(qreal length)
setAction(new MoveAction(this, -length));
}
-void TankItem::turn(qreal newDirection)
+void TankItem::turn(qreal degrees)
{
- setAction(new TurnAction(this, m_currentDirection - newDirection));
+ setAction(new TurnAction(this, degrees));
}
void TankItem::stop()
@@ -135,81 +133,18 @@ void TankItem::stop()
setAction(0);
}
-void TankItem::fireCannon(qreal distance)
-{
- setAction(new FireCannonAction(this, distance));
-}
-
-QPointF TankItem::tryMove(const QPointF &requestedPosition) const
-{
- QLineF movementPath(pos(), requestedPosition);
-
- qreal cannonLength = 0.0;
- {
- QPointF p1 = boundingRect().center();
- QPointF p2 = QPointF(boundingRect().right() + 10.0, p1.y());
-
- cannonLength = QLineF(mapToScene(p1), mapToScene(p2)).length();
- }
-
- movementPath.setLength(movementPath.length() + cannonLength);
-
- QRectF boundingRectPath(QPointF(qMin(movementPath.x1(), movementPath.x2()), qMin(movementPath.y1(), movementPath.y2())),
- QPointF(qMax(movementPath.x1(), movementPath.x2()), qMax(movementPath.y1(), movementPath.y2())));
-
- m_brp = mapFromScene(boundingRectPath);
-
- QList itemsInRect = scene()->items(boundingRectPath, Qt::IntersectsItemBoundingRect);
-
- QPointF nextPoint = requestedPosition;
- QRectF sceneRect = scene()->sceneRect();
-
- QLineF collidedLine;
- foreach (QGraphicsItem *item, itemsInRect) {
- if (item == static_cast(this))
- continue;
-
- QPolygonF mappedBoundingRect = item->mapToScene(item->boundingRect());
- for (int i=0; i sceneRect.right())
- nextPoint.rx() = sceneRect.right();
- if (nextPoint.y() < sceneRect.top())
- nextPoint.ry() = sceneRect.top();
- if (nextPoint.y() > sceneRect.bottom())
- nextPoint.ry() = sceneRect.bottom();
-
- if (nextPoint != requestedPosition) {
- emit collision(collidedLine);
- }
-
- return nextPoint;
-}
-
QVariant TankItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
- if (change == ItemPositionChange && scene())
- return tryMove(value.toPointF());
- else
+ if (change == ItemPositionChange && scene()) {
+ QPointF requestedPosition = value.toPointF();
+ QLineF collidedLine;
+ QPointF nextPoint = tryMove(requestedPosition, &collidedLine);
+ if (nextPoint != requestedPosition)
+ emit collision(collidedLine);
+ return nextPoint;
+ } else {
return QGraphicsItem::itemChange(change, value);
+ }
}
@@ -241,10 +176,6 @@ void TankItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
QPointF(brect.right() - 2.0, brect.bottom()));
painter->fillRect(rightTrackRect, Qt::darkYellow);
painter->drawRect(rightTrackRect);
-
- painter->setBrush(QColor::fromRgb(255, 0, 0, 128));
- painter->drawPolygon(m_brp);
-
}
QRectF TankItem::boundingRect() const
@@ -259,8 +190,9 @@ qreal TankItem::direction() const
void TankItem::setDirection(qreal newDirection)
{
+ qreal diff = newDirection - m_currentDirection;
m_currentDirection = newDirection;
- rotate(newDirection);
+ rotate(diff);
}
qreal TankItem::distanceToObstacle() const
diff --git a/examples/statemachine/errorstate/tankitem.h b/examples/statemachine/errorstate/tankitem.h
index df13689..c9e0d22 100644
--- a/examples/statemachine/errorstate/tankitem.h
+++ b/examples/statemachine/errorstate/tankitem.h
@@ -2,12 +2,12 @@
#define TANKITEM_H
#include "tank.h"
+#include "gameitem.h"
-#include
#include
class Action;
-class TankItem: public Tank, public QGraphicsItem
+class TankItem: public Tank, public GameItem
{
Q_OBJECT
public:
@@ -17,7 +17,6 @@ public:
virtual void moveBackwards(qreal length);
virtual void turn(qreal newDirection);
virtual void stop();
- virtual void fireCannon(qreal distance);
virtual qreal direction() const;
virtual qreal distanceToObstacle() const;
@@ -27,22 +26,26 @@ public:
void idle(qreal elapsed);
void setDirection(qreal newDirection);
- qreal speed() const { return 20.0; }
- qreal angularSpeed() const { return 1.0; }
+ qreal speed() const { return 90.0; }
+ qreal angularSpeed() const { return 90.0; }
-protected:
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;
+
+ void hitByRocket();
+
+signals:
+ virtual void fireCannon();
+
+protected:
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
private:
- QPointF tryMove(const QPointF &requestedPosition) const;
void setAction(Action *newAction);
Action *m_currentAction;
qreal m_currentDirection;
QColor m_color;
- mutable QPolygonF m_brp;
};
#endif
diff --git a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.cpp b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.cpp
index 429e3ca..135c7b6 100644
--- a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.cpp
+++ b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.cpp
@@ -17,7 +17,7 @@ QState *RandomAiPlugin::create(QState *parentState, Tank *tank)
topLevel->setInitialState(selectNextActionState);
QState *fireState = new RandomDistanceState(topLevel);
- connect(fireState, SIGNAL(distanceComputed(qreal)), tank, SLOT(fireCannon(qreal)));
+ connect(fireState, SIGNAL(distanceComputed(qreal)), tank, SLOT(fireCannon()));
selectNextActionState->addTransition(selectNextActionState, SIGNAL(fireSelected()), fireState);
QState *moveForwardsState = new RandomDistanceState(topLevel);
diff --git a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
index 27c9b92..758b3e8 100644
--- a/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
+++ b/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
@@ -47,7 +47,7 @@ signals:
protected:
void onEntry()
{
- emit distanceComputed(qreal(qrand() % 10));
+ emit distanceComputed(qreal(qrand() % 180));
}
};
--
cgit v0.12
From 772cb8c46b96e850b391f157e4870895e53748d4 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Tue, 28 Apr 2009 13:47:00 +0200
Subject: Add a test for the semantics of transitions from a region in parallel
states. This test checks for the behavior I expected, but that's apparently
not how it's defined in the SCXML algorithm. Currently it XFAILs, and we'll
either have to fix the algorithm or the test when we get word back on what
the correct semantics are.
---
tests/auto/qstatemachine/tst_qstatemachine.cpp | 47 ++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 54446a6..db25ad5 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -133,6 +133,7 @@ private slots:
//void restorePolicyOnChildState();
void transitionWithParent();
+ void parallelStateTransition();
void simpleAnimation();
void twoAnimations();
@@ -2808,6 +2809,52 @@ void tst_QStateMachine::overrideDefaultTargetAnimationWithSource()
QCOMPARE(counter.counter, 2); // specific animation started and stopped
}
+void tst_QStateMachine::parallelStateTransition()
+{
+ QStateMachine machine;
+
+ QState *parallelState = new QState(QState::ParallelGroup, machine.rootState());
+ machine.setInitialState(parallelState);
+
+ QState *s1 = new QState(parallelState);
+ QState *s2 = new QState(parallelState);
+
+ QState *s1InitialChild = new QState(s1);
+ s1->setInitialState(s1InitialChild);
+
+ QState *s2InitialChild = new QState(s2);
+ s2->setInitialState(s2InitialChild);
+
+ QState *s1OtherChild = new QState(s1);
+ QState *s2OtherChild = new QState(s2);
+
+ s1->addTransition(new EventTransition(QEvent::User, s1OtherChild));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QVERIFY(machine.configuration().contains(parallelState));
+ QVERIFY(machine.configuration().contains(s1));
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s1InitialChild));
+ QVERIFY(machine.configuration().contains(s2InitialChild));
+ QCOMPARE(machine.configuration().size(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QVERIFY(machine.configuration().contains(parallelState));
+
+ QVERIFY(machine.configuration().contains(s1));
+
+ QEXPECT_FAIL("", "This failure is defined in the algorithm. We need to find out what behavior is correct.", Abort);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s1OtherChild));
+ QVERIFY(machine.configuration().contains(s2InitialChild));
+ QCOMPARE(machine.configuration().size(), 5);
+
+}
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"
--
cgit v0.12
From 6cb8adb930926511777f8e97bc45683ecbbf5b36 Mon Sep 17 00:00:00 2001
From: Eskil Abrahamsen Blomfeldt
Date: Tue, 28 Apr 2009 15:47:02 +0200
Subject: Work around an oddity in parallel states that causes all regions to
exit if there is a transition from one of them (even if the target state of
the transition is inside the region.)
---
examples/statemachine/errorstate/mainwindow.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/examples/statemachine/errorstate/mainwindow.cpp b/examples/statemachine/errorstate/mainwindow.cpp
index c0af62d..9281298 100644
--- a/examples/statemachine/errorstate/mainwindow.cpp
+++ b/examples/statemachine/errorstate/mainwindow.cpp
@@ -192,8 +192,7 @@ void MainWindow::addTank()
{
Q_ASSERT(!m_spawns.isEmpty());
- QString fileName = QFileDialog::getOpenFileName(this, "Select plugin file",
- "plugins/", "*.dll");
+ QString fileName = QFileDialog::getOpenFileName(this, "Select plugin file", "plugins/", "*.dll");
QPluginLoader loader(fileName);
Plugin *plugin = qobject_cast(loader.instance());
@@ -203,8 +202,9 @@ void MainWindow::addTank()
connect(tankItem, SIGNAL(fireCannon()), this, SLOT(addRocket()));
if (m_spawns.isEmpty())
emit mapFull();
-
- plugin->create(m_runningState, tankItem);
+
+ QState *region = new QState(m_runningState);
+ region->setInitialState(plugin->create(region, tankItem));
}
}
--
cgit v0.12
From 9c28c75052a38eb3b317c2ac7ad2a26c73deeb2d Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Tue, 28 Apr 2009 13:26:09 +0200
Subject: kill StateFinished from docs
---
src/corelib/kernel/qcoreevent.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp
index fc1cefb..f98ef8b 100644
--- a/src/corelib/kernel/qcoreevent.cpp
+++ b/src/corelib/kernel/qcoreevent.cpp
@@ -265,7 +265,6 @@ QT_BEGIN_NAMESPACE
\omitvalue CocoaRequestModal
\omitvalue Bound
\omitvalue Signal
- \omitvalue StateFinished
*/
/*!
--
cgit v0.12
From 4f6b9b1779fe33f876f96c196c3feef7e72992a0 Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Tue, 28 Apr 2009 13:29:37 +0200
Subject: move assignProperty() to QState
Doesn't belong in the abstract base class.
---
doc/src/statemachine.qdoc | 9 ++++-----
src/corelib/statemachine/qabstractstate.cpp | 24 ++----------------------
src/corelib/statemachine/qabstractstate.h | 3 ---
src/corelib/statemachine/qabstractstate_p.h | 20 --------------------
src/corelib/statemachine/qstate.cpp | 21 +++++++++++++++++++++
src/corelib/statemachine/qstate.h | 4 ++++
src/corelib/statemachine/qstate_p.h | 19 +++++++++++++++++++
src/corelib/statemachine/qstatemachine.cpp | 12 +++++++-----
src/corelib/statemachine/qstatemachine_p.h | 2 +-
9 files changed, 58 insertions(+), 56 deletions(-)
diff --git a/doc/src/statemachine.qdoc b/doc/src/statemachine.qdoc
index 97c09b9..1462ec1 100644
--- a/doc/src/statemachine.qdoc
+++ b/doc/src/statemachine.qdoc
@@ -76,11 +76,10 @@
becomes part of your application's event loop.
The above state machine is perfectly fine, but it doesn't \e do anything; it
- merely transitions from one state to another. The
- QAbstractState::assignProperty() function can be used to have a state set a
- property of a QObject when the state is entered. In the following snippet,
- the value that should be assigned to a QLabel's text property is specified
- for each state:
+ merely transitions from one state to another. The QState::assignProperty()
+ function can be used to have a state set a property of a QObject when the
+ state is entered. In the following snippet, the value that should be
+ assigned to a QLabel's text property is specified for each state:
\code
s1->assignProperty(label, "text", "In state s1");
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index 396063a..12f14d7 100644
--- a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -41,9 +41,10 @@
#include "qabstractstate.h"
#include "qabstractstate_p.h"
+#include "qstate.h"
+#include "qstate_p.h"
#include "qstatemachine.h"
#include "qstatemachine_p.h"
-#include "qstate.h"
QT_BEGIN_NAMESPACE
@@ -59,9 +60,6 @@ QT_BEGIN_NAMESPACE
of a QStateMachine. It defines the interface that all state objects have in
common. QAbstractState is part of \l{The State Machine Framework}.
- The assignProperty() function is used for defining property assignments that
- should be performed when a state is entered.
-
The entered() signal is emitted when the state has been entered. The
exited() signal is emitted when the state has been exited.
@@ -181,24 +179,6 @@ QState *QAbstractState::parentState() const
}
/*!
- Instructs this state to set the property with the given \a name of the given
- \a object to the given \a value when the state is entered.
-*/
-void QAbstractState::assignProperty(QObject *object, const char *name,
- const QVariant &value)
-{
- Q_D(QAbstractState);
- for (int i = 0; i < d->propertyAssignments.size(); ++i) {
- QPropertyAssignment &assn = d->propertyAssignments[i];
- if ((assn.object == object) && (assn.propertyName == name)) {
- assn.value = value;
- return;
- }
- }
- d->propertyAssignments.append(QPropertyAssignment(object, name, value));
-}
-
-/*!
\fn QAbstractState::onExit()
This function is called when the state is exited. Reimplement this function
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index 69e6bf1..a5f1440 100644
--- a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -61,9 +61,6 @@ public:
QState *parentState() const;
- void assignProperty(QObject *object, const char *name,
- const QVariant &value);
-
Q_SIGNALS:
void entered();
void exited();
diff --git a/src/corelib/statemachine/qabstractstate_p.h b/src/corelib/statemachine/qabstractstate_p.h
index 8c8f436..bbe12d6 100644
--- a/src/corelib/statemachine/qabstractstate_p.h
+++ b/src/corelib/statemachine/qabstractstate_p.h
@@ -57,28 +57,10 @@
#include
#endif
-#include
-#include
-#include
-
QT_BEGIN_NAMESPACE
-class QAbstractTransition;
-class QHistoryState;
class QStateMachine;
-struct QPropertyAssignment
-{
- QPropertyAssignment(QObject *o, const QByteArray &n,
- const QVariant &v, bool es = true)
- : object(o), propertyName(n), value(v), explicitlySet(es)
- {}
- QObject *object;
- QByteArray propertyName;
- QVariant value;
- bool explicitlySet;
-};
-
class QAbstractState;
class Q_CORE_EXPORT QAbstractStatePrivate
#ifndef QT_STATEMACHINE_SOLUTION
@@ -101,8 +83,6 @@ public:
void emitEntered();
void emitExited();
- QList propertyAssignments;
-
#ifdef QT_STATEMACHINE_SOLUTION
QAbstractState *q_ptr;
#endif
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index 9bda250..5c3418b 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -65,6 +65,9 @@ QT_BEGIN_NAMESPACE
The addTransition() function adds a transition. The removeTransition()
function removes a transition.
+ The assignProperty() function is used for defining property assignments that
+ should be performed when a state is entered.
+
\section1 States with Child States
For non-parallel state groups, the setInitialState() function must be called
@@ -216,6 +219,24 @@ QList QStatePrivate::transitions() const
}
/*!
+ Instructs this state to set the property with the given \a name of the given
+ \a object to the given \a value when the state is entered.
+*/
+void QState::assignProperty(QObject *object, const char *name,
+ const QVariant &value)
+{
+ Q_D(QState);
+ for (int i = 0; i < d->propertyAssignments.size(); ++i) {
+ QPropertyAssignment &assn = d->propertyAssignments[i];
+ if ((assn.object == object) && (assn.propertyName == name)) {
+ assn.value = value;
+ return;
+ }
+ }
+ d->propertyAssignments.append(QPropertyAssignment(object, name, value));
+}
+
+/*!
Returns this state group's error state.
\sa QStateMachine::errorState(), QStateMachine::setErrorState()
diff --git a/src/corelib/statemachine/qstate.h b/src/corelib/statemachine/qstate.h
index 70211c1..0dd99dc 100644
--- a/src/corelib/statemachine/qstate.h
+++ b/src/corelib/statemachine/qstate.h
@@ -91,8 +91,12 @@ public:
QAbstractState *initialState() const;
void setInitialState(QAbstractState *state);
+ void assignProperty(QObject *object, const char *name,
+ const QVariant &value);
+
Q_SIGNALS:
void finished();
+ void polished();
protected:
void onEntry();
diff --git a/src/corelib/statemachine/qstate_p.h b/src/corelib/statemachine/qstate_p.h
index 2df6823..603bc18 100644
--- a/src/corelib/statemachine/qstate_p.h
+++ b/src/corelib/statemachine/qstate_p.h
@@ -56,9 +56,26 @@
#include "qabstractstate_p.h"
#include
+#include
+#include
QT_BEGIN_NAMESPACE
+struct QPropertyAssignment
+{
+ QPropertyAssignment(QObject *o, const QByteArray &n,
+ const QVariant &v, bool es = true)
+ : object(o), propertyName(n), value(v), explicitlySet(es)
+ {}
+ QObject *object;
+ QByteArray propertyName;
+ QVariant value;
+ bool explicitlySet;
+};
+
+class QAbstractTransition;
+class QHistoryState;
+
class QState;
class Q_CORE_EXPORT QStatePrivate : public QAbstractStatePrivate
{
@@ -79,6 +96,8 @@ public:
QAbstractState *errorState;
bool isParallelGroup;
QAbstractState *initialState;
+
+ QList propertyAssignments;
};
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 632390f..1434bc0 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -40,6 +40,8 @@
****************************************************************************/
#include "qstatemachine.h"
+#include "qstate.h"
+#include "qstate_p.h"
#include "qstatemachine_p.h"
#include "qabstracttransition.h"
#include "qabstracttransition_p.h"
@@ -52,8 +54,6 @@
#include "qfinalstate.h"
#include "qhistorystate.h"
#include "qhistorystate_p.h"
-#include "qstate.h"
-#include "qstate_p.h"
#ifndef QT_STATEMACHINE_SOLUTION
#include "private/qobject_p.h"
#include "private/qthread_p.h"
@@ -641,9 +641,11 @@ void QStateMachinePrivate::applyProperties(const QList &tr
QList propertyAssignments;
QHash pendingRestorables = registeredRestorables;
for (int i = 0; i < enteredStates.size(); ++i) {
- QAbstractState *s = enteredStates.at(i);
+ QState *s = qobject_cast(enteredStates.at(i));
+ if (!s)
+ continue;
- QList assignments = QAbstractStatePrivate::get(s)->propertyAssignments;
+ QList assignments = QStatePrivate::get(s)->propertyAssignments;
for (int j = 0; j < assignments.size(); ++j) {
const QPropertyAssignment &assn = assignments.at(j);
if (globalRestorePolicy == QStateMachine::RestoreProperties) {
@@ -1487,7 +1489,7 @@ void QStateMachine::setErrorState(QAbstractState *state)
\value RestoreProperties The state machine should save the initial values of properties
and restore them later.
- \sa setRestorePolicy(), restorePolicy(), QAbstractState::assignProperty()
+ \sa setRestorePolicy(), restorePolicy(), QState::assignProperty()
*/
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 9f93217..323473d 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -62,7 +62,7 @@
#include
#include
-#include "qabstractstate_p.h"
+#include "qstate_p.h"
QT_BEGIN_NAMESPACE
--
cgit v0.12
From 6293521a6e5ee0ce010180a40e6fda3ef3a8b245 Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Tue, 28 Apr 2009 13:45:23 +0200
Subject: add animationsEnabled property
---
src/corelib/statemachine/qstatemachine.cpp | 47 +++++++++++++++++++++++++-----
src/corelib/statemachine/qstatemachine.h | 6 ++++
src/corelib/statemachine/qstatemachine_p.h | 2 ++
3 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 1434bc0..8d5317a 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -177,6 +177,14 @@ QT_BEGIN_NAMESPACE
\brief the error string of this state machine
*/
+#ifndef QT_NO_ANIMATION
+/*!
+ \property QStateMachine::animationsEnabled
+
+ \brief whether animations are enabled
+*/
+#endif
+
// #define QSTATEMACHINE_DEBUG
QStateMachinePrivate::QStateMachinePrivate()
@@ -192,6 +200,9 @@ QStateMachinePrivate::QStateMachinePrivate()
#ifndef QT_STATEMACHINE_SOLUTION
signalEventGenerator = 0;
#endif
+#ifndef QT_NO_ANIMATION
+ animationsEnabled = true;
+#endif
}
QStateMachinePrivate::~QStateMachinePrivate()
@@ -622,17 +633,19 @@ void QStateMachinePrivate::applyProperties(const QList &tr
// Find the animations to use for the state change.
QList selectedAnimations;
- for (int i = 0; i < transitionList.size(); ++i) {
- QAbstractTransition *transition = transitionList.at(i);
+ if (animationsEnabled) {
+ for (int i = 0; i < transitionList.size(); ++i) {
+ QAbstractTransition *transition = transitionList.at(i);
- selectedAnimations << transition->animations();
- selectedAnimations << defaultAnimationsForSource.values(transition->sourceState());
+ selectedAnimations << transition->animations();
+ selectedAnimations << defaultAnimationsForSource.values(transition->sourceState());
- QList targetStates = transition->targetStates();
- for (int j=0; j targetStates = transition->targetStates();
+ for (int j=0; janimationsEnabled;
+}
+
+/*!
+ Sets whether animations are \a enabled for this state machine.
+*/
+void QStateMachine::setAnimationsEnabled(bool enabled)
+{
+ Q_D(QStateMachine);
+ d->animationsEnabled = enabled;
+}
+
+/*!
Adds a default \a animation to be considered for any transition.
*/
void QStateMachine::addDefaultAnimation(QAbstractAnimation *animation)
diff --git a/src/corelib/statemachine/qstatemachine.h b/src/corelib/statemachine/qstatemachine.h
index 9a7a6fc..3ad215b 100644
--- a/src/corelib/statemachine/qstatemachine.h
+++ b/src/corelib/statemachine/qstatemachine.h
@@ -74,6 +74,9 @@ class Q_CORE_EXPORT QStateMachine : public QObject
Q_PROPERTY(QString errorString READ errorString)
Q_PROPERTY(RestorePolicy globalRestorePolicy READ globalRestorePolicy WRITE setGlobalRestorePolicy)
Q_ENUMS(RestorePolicy)
+#ifndef QT_NO_ANIMATION
+ Q_PROPERTY(bool animationsEnabled READ animationsEnabled WRITE setAnimationsEnabled)
+#endif
public:
enum RestorePolicy {
DoNotRestoreProperties,
@@ -105,6 +108,9 @@ public:
void clearError();
#ifndef QT_NO_ANIMATION
+ bool animationsEnabled() const;
+ void setAnimationsEnabled(bool enabled);
+
void addDefaultAnimation(QAbstractAnimation *animation);
QList defaultAnimations() const;
void removeDefaultAnimation(QAbstractAnimation *animation);
diff --git a/src/corelib/statemachine/qstatemachine_p.h b/src/corelib/statemachine/qstatemachine_p.h
index 323473d..bb58edc 100644
--- a/src/corelib/statemachine/qstatemachine_p.h
+++ b/src/corelib/statemachine/qstatemachine_p.h
@@ -179,6 +179,8 @@ public:
QAbstractState *initialErrorStateForRoot;
#ifndef QT_NO_ANIMATION
+ bool animationsEnabled;
+
QPair, QList >
initializeAnimation(QAbstractAnimation *abstractAnimation,
const QPropertyAssignment &prop);
--
cgit v0.12
From 2c22f8748f62db3cd4c2782abcd19c273f4a4426 Mon Sep 17 00:00:00 2001
From: Kent Hansen
Date: Tue, 28 Apr 2009 14:05:15 +0200
Subject: say hello (again) to QAbstract{State,Transition}::machine()
It's useful and it's simple for us to expose, so let's.
---
examples/statemachine/clockticking/main.cpp | 24 ++++++------------
examples/statemachine/pingpong/main.cpp | 31 ++++++++----------------
src/corelib/statemachine/qabstractstate.cpp | 13 +++++++++-
src/corelib/statemachine/qabstractstate.h | 2 ++
src/corelib/statemachine/qabstracttransition.cpp | 13 +++++++++-
src/corelib/statemachine/qabstracttransition.h | 3 +++
6 files changed, 47 insertions(+), 39 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);
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index 12f14d7..cc6f0f9 100644
--- a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -63,7 +63,8 @@ QT_BEGIN_NAMESPACE
The entered() signal is emitted when the state has been entered. The
exited() signal is emitted when the state has been exited.
- The parentState() function returns the state's parent state.
+ The parentState() function returns the state's parent state. The machine()
+ function returns the state machine that the state is part of.
\section1 Subclassing
@@ -179,6 +180,16 @@ QState *QAbstractState::parentState() const
}
/*!
+ Returns the state machine that this state is part of, or 0 if the state is
+ not part of a state machine.
+*/
+QStateMachine *QAbstractState::machine() const
+{
+ Q_D(const QAbstractState);
+ return d->machine();
+}
+
+/*!
\fn QAbstractState::onExit()
This function is called when the state is exited. Reimplement this function
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index a5f1440..30a68ff 100644
--- a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Core)
class QState;
+class QStateMachine;
class QAbstractStatePrivate;
class Q_CORE_EXPORT QAbstractState : public QObject
@@ -60,6 +61,7 @@ public:
~QAbstractState();
QState *parentState() const;
+ QStateMachine *machine() const;
Q_SIGNALS:
void entered();
diff --git a/src/corelib/statemachine/qabstracttransition.cpp b/src/corelib/statemachine/qabstracttransition.cpp
index dfce310..731871c 100644
--- a/src/corelib/statemachine/qabstracttransition.cpp
+++ b/src/corelib/statemachine/qabstracttransition.cpp
@@ -61,7 +61,8 @@ QT_BEGIN_NAMESPACE
Framework}.
The sourceState() function returns the source of the transition. The
- targetStates() function returns the targets of the transition.
+ targetStates() function returns the targets of the transition. The machine()
+ function returns the state machine that the transition is part of.
Transitions can cause animations to be played. Use the addAnimation()
function to add an animation to the transition.
@@ -286,6 +287,16 @@ void QAbstractTransition::setTargetStates(const QList &targets)
d->targetStates = targets;
}
+/*!
+ Returns the state machine that this transition is part of, or 0 if the
+ transition is not part of a state machine.
+*/
+QStateMachine *QAbstractTransition::machine() const
+{
+ Q_D(const QAbstractTransition);
+ return d->machine();
+}
+
#ifndef QT_NO_ANIMATION
/*!
diff --git a/src/corelib/statemachine/qabstracttransition.h b/src/corelib/statemachine/qabstracttransition.h
index c49731f..37365c5 100644
--- a/src/corelib/statemachine/qabstracttransition.h
+++ b/src/corelib/statemachine/qabstracttransition.h
@@ -55,6 +55,7 @@ QT_MODULE(Core)
class QEvent;
class QAbstractState;
class QState;
+class QStateMachine;
#ifndef QT_NO_ANIMATION
class QAbstractAnimation;
@@ -78,6 +79,8 @@ public:
QList