summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-07-22 15:10:35 +0200
committerKent Hansen <khansen@trolltech.com>2009-07-22 15:23:06 +0200
commit1a55f40b6223511d0eb388064597ab38a0d37627 (patch)
tree522d9fafe3bef5049b75471b266ab2f614dfa412 /tests
parentdf2a1de1720476d096ad9be0a8cf5a0410206d82 (diff)
downloadqt4-tools-1a55f40b6223511d0eb388064597ab38a0d37627.tar.gz
Make QStateMachine inherit QState
This removes the need for a "root state" in the machine; or rather, the machine _is_ the root state. User code can now pass in a QStateMachine directly to the QState constructor, instead of machine->rootState(). This also means we could get rid of the "proxying" from the machine to the root state for things like properties (initialState et al), finished() signal and auto-reparenting of states (the ChildAdded event hack). A fun little side-effect of this change is that it's now possible to embed state machines within state machines. We can't think of a good use case yet where you would rather embed a stand-alone state machine (with its own event processing etc.) rather than having just a regular nested state, but it's neat and it works. Reviewed-by: Eskil Abrahamsen Blomfeldt
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qstate/tst_qstate.cpp12
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp511
2 files changed, 283 insertions, 240 deletions
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp
index ab87767592..78b98530d2 100644
--- a/tests/auto/qstate/tst_qstate.cpp
+++ b/tests/auto/qstate/tst_qstate.cpp
@@ -60,10 +60,10 @@ tst_QState::~tst_QState()
void tst_QState::test()
{
QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
QCOMPARE(s1->machine(), &machine);
- QCOMPARE(s1->parentState(), machine.rootState());
+ QCOMPARE(s1->parentState(), &machine);
QCOMPARE(s1->initialState(), (QState*)0);
QVERIFY(s1->childStates().isEmpty());
QVERIFY(s1->transitions().isEmpty());
@@ -218,7 +218,7 @@ void tst_QState::assignProperty()
QObject *object = new QObject();
object->setProperty("fooBar", 10);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->assignProperty(object, "fooBar", 20);
machine.setInitialState(s1);
@@ -235,7 +235,7 @@ void tst_QState::assignPropertyTwice()
QObject *object = new QObject();
object->setProperty("fooBar", 10);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->assignProperty(object, "fooBar", 20);
s1->assignProperty(object, "fooBar", 30);
@@ -271,9 +271,9 @@ void tst_QState::historyInitialState()
{
QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
QHistoryState *h1 = new QHistoryState(s2);
s2->setInitialState(h1);
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 44fc9986ae..7f4d9f55c6 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -190,6 +190,8 @@ private slots:
// void overrideDefaultSourceAnimationWithSpecific();
// void overrideDefaultTargetAnimationWithSpecific();
// void overrideDefaultTargetAnimationWithSource();
+
+ void nestedStateMachines();
};
tst_QStateMachine::tst_QStateMachine()
@@ -259,13 +261,17 @@ private:
void tst_QStateMachine::transitionToRootState()
{
QStateMachine machine;
+ machine.setObjectName("machine");
QState *initialState = new QState();
+ initialState->setObjectName("initial");
machine.addState(initialState);
machine.setInitialState(initialState);
- QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::setTargetStates: root state cannot be target of transition");
- initialState->addTransition(new EventTransition(QEvent::User, machine.rootState()));
+ QAbstractTransition *trans = initialState->addTransition(new EventTransition(QEvent::User, &machine));
+ QVERIFY(trans != 0);
+ QCOMPARE(trans->sourceState(), initialState);
+ QCOMPARE(trans->targetState(), &machine);
machine.start();
QCoreApplication::processEvents();
@@ -274,22 +280,21 @@ void tst_QStateMachine::transitionToRootState()
QVERIFY(machine.configuration().contains(initialState));
machine.postEvent(new QEvent(QEvent::User));
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 'initial'");
QCoreApplication::processEvents();
-
- QCOMPARE(machine.configuration().count(), 1);
- QVERIFY(machine.configuration().contains(initialState));
+ QVERIFY(machine.configuration().isEmpty());
+ QVERIFY(!machine.isRunning());
}
void tst_QStateMachine::transitionFromRootState()
{
QStateMachine machine;
- QState *root = machine.rootState();
+ QState *root = &machine;
QState *s1 = new QState(root);
EventTransition *trans = new EventTransition(QEvent::User, s1);
- QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add transition from root state");
- root->addTransition(trans);
- QCOMPARE(trans->sourceState(), (QState*)0);
- delete trans;
+ QCOMPARE(root->addTransition(trans), trans);
+ QCOMPARE(trans->sourceState(), root);
+ QCOMPARE(trans->targetState(), s1);
}
void tst_QStateMachine::transitionEntersParent()
@@ -671,7 +676,7 @@ void tst_QStateMachine::errorStateIsRootState()
{
QStateMachine machine;
QTest::ignoreMessage(QtWarningMsg, "QStateMachine::setErrorState: root state cannot be error state");
- machine.setErrorState(machine.rootState());
+ machine.setErrorState(&machine);
QState *initialState = new QState();
initialState->setObjectName("initialState");
@@ -772,7 +777,7 @@ void tst_QStateMachine::errorStateEntersParentFirst()
void tst_QStateMachine::customErrorStateIsNull()
{
QStateMachine machine;
- machine.rootState()->setErrorState(0);
+ machine.setErrorState(0);
QState *initialState = new QState();
machine.addState(initialState);
@@ -798,9 +803,9 @@ void tst_QStateMachine::customErrorStateIsNull()
void tst_QStateMachine::clearError()
{
QStateMachine machine;
- machine.setErrorState(new QState(machine.rootState())); // avoid warnings
+ machine.setErrorState(new QState(&machine)); // avoid warnings
- QState *brokenState = new QState(machine.rootState());
+ QState *brokenState = new QState(&machine);
brokenState->setObjectName("brokenState");
machine.setInitialState(brokenState);
new QState(brokenState);
@@ -822,13 +827,13 @@ void tst_QStateMachine::historyStateAsInitialState()
{
QStateMachine machine;
- QHistoryState *hs = new QHistoryState(machine.rootState());
+ QHistoryState *hs = new QHistoryState(&machine);
machine.setInitialState(hs);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
hs->setDefaultState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
QHistoryState *s2h = new QHistoryState(s2);
s2->setInitialState(s2h);
@@ -856,11 +861,11 @@ void tst_QStateMachine::historyStateHasNowhereToGo()
{
QStateMachine machine;
- QState *initialState = new QState(machine.rootState());
+ QState *initialState = new QState(&machine);
machine.setInitialState(initialState);
- machine.setErrorState(new QState(machine.rootState())); // avoid warnings
+ machine.setErrorState(new QState(&machine)); // avoid warnings
- QState *brokenState = new QState(machine.rootState());
+ QState *brokenState = new QState(&machine);
brokenState->setObjectName("brokenState");
brokenState->setInitialState(new QState(brokenState));
@@ -890,14 +895,14 @@ void tst_QStateMachine::brokenStateIsNeverEntered()
entryController->setProperty("childStateEntered", false);
entryController->setProperty("errorStateEntered", false);
- QState *initialState = new QState(machine.rootState());
+ QState *initialState = new QState(&machine);
machine.setInitialState(initialState);
- QState *errorState = new QState(machine.rootState());
+ QState *errorState = new QState(&machine);
errorState->assignProperty(entryController, "errorStateEntered", true);
machine.setErrorState(errorState);
- QState *brokenState = new QState(machine.rootState());
+ QState *brokenState = new QState(&machine);
brokenState->assignProperty(entryController, "brokenStateEntered", true);
brokenState->setObjectName("brokenState");
@@ -921,7 +926,7 @@ void tst_QStateMachine::transitionToStateNotInGraph()
{
QStateMachine machine;
- QState *initialState = new QState(machine.rootState());
+ QState *initialState = new QState(&machine);
initialState->setObjectName("initialState");
machine.setInitialState(initialState);
@@ -946,7 +951,7 @@ void tst_QStateMachine::customErrorStateNotInGraph()
machine.setErrorState(&errorState);
QCOMPARE(machine.errorState(), reinterpret_cast<QAbstractState *>(0));
- QState *initialBrokenState = new QState(machine.rootState());
+ QState *initialBrokenState = new QState(&machine);
initialBrokenState->setObjectName("initialBrokenState");
machine.setInitialState(initialBrokenState);
new QState(initialBrokenState);
@@ -1012,25 +1017,22 @@ void tst_QStateMachine::restoreProperties()
void tst_QStateMachine::rootState()
{
QStateMachine machine;
- QVERIFY(machine.rootState() != 0);
- QVERIFY(qobject_cast<QState*>(machine.rootState()) != 0);
- QCOMPARE(qobject_cast<QState*>(machine.rootState())->parentState(), (QState*)0);
- QCOMPARE(machine.rootState()->parent(), (QObject*)&machine);
- QCOMPARE(machine.rootState()->machine(), &machine);
+ QCOMPARE(qobject_cast<QState*>(machine.parentState()), (QState*)0);
+ QCOMPARE(machine.machine(), (QStateMachine*)0);
- QState *s1 = new QState(machine.rootState());
- QCOMPARE(s1->parentState(), machine.rootState());
+ QState *s1 = new QState(&machine);
+ QCOMPARE(s1->parentState(), &machine);
QState *s2 = new QState();
s2->setParent(&machine);
- QCOMPARE(s2->parentState(), machine.rootState());
+ QCOMPARE(s2->parentState(), &machine);
}
void tst_QStateMachine::addAndRemoveState()
{
#ifdef QT_BUILD_INTERNAL
QStateMachine machine;
- QStatePrivate *root_d = QStatePrivate::get(machine.rootState());
+ QStatePrivate *root_d = QStatePrivate::get(&machine);
QCOMPARE(root_d->childStates().size(), 0);
QTest::ignoreMessage(QtWarningMsg, "QStateMachine::addState: cannot add null state");
@@ -1041,7 +1043,7 @@ void tst_QStateMachine::addAndRemoveState()
QCOMPARE(s1->machine(), (QStateMachine*)0);
machine.addState(s1);
QCOMPARE(s1->machine(), &machine);
- QCOMPARE(s1->parentState(), machine.rootState());
+ QCOMPARE(s1->parentState(), &machine);
QCOMPARE(root_d->childStates().size(), 1);
QCOMPARE(root_d->childStates().at(0), (QAbstractState*)s1);
@@ -1051,7 +1053,7 @@ void tst_QStateMachine::addAndRemoveState()
QState *s2 = new QState();
QCOMPARE(s2->parentState(), (QState*)0);
machine.addState(s2);
- QCOMPARE(s2->parentState(), machine.rootState());
+ QCOMPARE(s2->parentState(), &machine);
QCOMPARE(root_d->childStates().size(), 2);
QCOMPARE(root_d->childStates().at(0), (QAbstractState*)s1);
QCOMPARE(root_d->childStates().at(1), (QAbstractState*)s2);
@@ -1076,13 +1078,13 @@ void tst_QStateMachine::addAndRemoveState()
{
QString warning;
warning.sprintf("QStateMachine::removeState: state %p's machine (%p) is different from this machine (%p)",
- machine2.rootState(), &machine2, &machine);
+ &machine2, (void*)0, &machine);
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
- machine.removeState(machine2.rootState());
+ machine.removeState(&machine2);
}
// ### check this behavior
- machine.addState(machine2.rootState());
- QCOMPARE(machine2.rootState()->parent(), (QObject*)machine.rootState());
+ machine.addState(&machine2);
+ QCOMPARE(machine2.parent(), (QObject*)&machine);
}
delete s1;
@@ -1098,7 +1100,7 @@ void tst_QStateMachine::stateEntryAndExit()
{
QStateMachine machine;
- TestState *s1 = new TestState(machine.rootState());
+ TestState *s1 = new TestState(&machine);
QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add transition to null state");
s1->addTransition((QAbstractState*)0);
QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add null transition");
@@ -1106,8 +1108,8 @@ void tst_QStateMachine::stateEntryAndExit()
QTest::ignoreMessage(QtWarningMsg, "QState::removeTransition: cannot remove null transition");
s1->removeTransition((QAbstractTransition*)0);
- TestState *s2 = new TestState(machine.rootState());
- QFinalState *s3 = new QFinalState(machine.rootState());
+ TestState *s2 = new TestState(&machine);
+ QFinalState *s3 = new QFinalState(&machine);
TestTransition *t = new TestTransition(s2);
QCOMPARE(t->machine(), (QStateMachine*)0);
@@ -1156,9 +1158,9 @@ void tst_QStateMachine::stateEntryAndExit()
QCOMPARE(machine.initialState(), (QAbstractState*)s1);
{
QString warning;
- warning.sprintf("QState::setInitialState: state %p is not a child of this state (%p)", machine.rootState(), machine.rootState());
+ warning.sprintf("QState::setInitialState: state %p is not a child of this state (%p)", &machine, &machine);
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
- machine.setInitialState(machine.rootState());
+ machine.setInitialState(&machine);
QCOMPARE(machine.initialState(), (QAbstractState*)s1);
}
QVERIFY(machine.configuration().isEmpty());
@@ -1205,11 +1207,11 @@ void tst_QStateMachine::stateEntryAndExit()
{
QStateMachine machine;
- TestState *s1 = new TestState(machine.rootState());
+ TestState *s1 = new TestState(&machine);
TestState *s11 = new TestState(s1);
TestState *s12 = new TestState(s1);
- TestState *s2 = new TestState(machine.rootState());
- QFinalState *s3 = new QFinalState(machine.rootState());
+ TestState *s2 = new TestState(&machine);
+ QFinalState *s3 = new QFinalState(&machine);
s1->setInitialState(s11);
TestTransition *t1 = new TestTransition(s12);
s11->addTransition(t1);
@@ -1268,13 +1270,13 @@ void tst_QStateMachine::stateEntryAndExit()
void tst_QStateMachine::assignProperty()
{
QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
QTest::ignoreMessage(QtWarningMsg, "QState::assignProperty: cannot assign property 'foo' of null object");
s1->assignProperty(0, "foo", QVariant());
s1->assignProperty(s1, "objectName", "s1");
- QFinalState *s2 = new QFinalState(machine.rootState());
+ QFinalState *s2 = new QFinalState(&machine);
s1->addTransition(s2);
machine.setInitialState(s1);
machine.start();
@@ -1320,9 +1322,9 @@ void tst_QStateMachine::assignPropertyWithAnimation()
QObject obj;
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->assignProperty(&obj, "foo", 123);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(&obj, "foo", 456);
s2->assignProperty(&obj, "bar", 789);
QAbstractTransition *trans = s1->addTransition(s2);
@@ -1342,7 +1344,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
trans->addAnimation(&anim);
QCOMPARE(trans->animations().size(), 1);
QCOMPARE(trans->animations().at(0), (QAbstractAnimation*)&anim);
- QFinalState *s3 = new QFinalState(machine.rootState());
+ QFinalState *s3 = new QFinalState(&machine);
s2->addTransition(s2, SIGNAL(polished()), s3);
machine.setInitialState(s1);
@@ -1358,9 +1360,9 @@ void tst_QStateMachine::assignPropertyWithAnimation()
QObject obj;
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->assignProperty(&obj, "foo", 123);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(&obj, "foo", 456);
s2->assignProperty(&obj, "bar", 789);
QAbstractTransition *trans = s1->addTransition(s2);
@@ -1370,7 +1372,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
QPropertyAnimation anim2(&obj, "bar");
anim2.setDuration(150);
trans->addAnimation(&anim2);
- QFinalState *s3 = new QFinalState(machine.rootState());
+ QFinalState *s3 = new QFinalState(&machine);
s2->addTransition(s2, SIGNAL(polished()), s3);
machine.setInitialState(s1);
@@ -1386,10 +1388,10 @@ void tst_QStateMachine::assignPropertyWithAnimation()
QObject obj;
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->assignProperty(&obj, "foo", 123);
s1->assignProperty(&obj, "bar", 321);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(&obj, "foo", 456);
s2->assignProperty(&obj, "bar", 654);
s2->assignProperty(&obj, "baz", 789);
@@ -1398,7 +1400,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
group.addAnimation(new QPropertyAnimation(&obj, "foo"));
group.addAnimation(new QPropertyAnimation(&obj, "bar"));
trans->addAnimation(&group);
- QFinalState *s3 = new QFinalState(machine.rootState());
+ QFinalState *s3 = new QFinalState(&machine);
s2->addTransition(s2, SIGNAL(polished()), s3);
machine.setInitialState(s1);
@@ -1415,7 +1417,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
QObject obj;
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
QCOMPARE(s1->childMode(), QState::ExclusiveStates);
s1->setChildMode(QState::ParallelStates);
QCOMPARE(s1->childMode(), QState::ParallelStates);
@@ -1425,7 +1427,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
s1->setObjectName("s1");
s1->assignProperty(&obj, "foo", 123);
s1->assignProperty(&obj, "bar", 456);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->setObjectName("s2");
s2->assignProperty(&obj, "foo", 321);
QState *s21 = new QState(s2);
@@ -1447,7 +1449,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
s21->addTransition(s21, SIGNAL(polished()), s22);
- QFinalState *s3 = new QFinalState(machine.rootState());
+ QFinalState *s3 = new QFinalState(&machine);
s22->addTransition(s2, SIGNAL(polished()), s3);
machine.setInitialState(s1);
@@ -1464,7 +1466,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
QObject obj;
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
- QState *group = new QState(machine.rootState());
+ QState *group = new QState(&machine);
QState *s1 = new QState(group);
group->setInitialState(s1);
s1->assignProperty(&obj, "foo", 123);
@@ -1590,12 +1592,12 @@ void tst_QStateMachine::postEvent()
void tst_QStateMachine::stateFinished()
{
QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
QState *s1_1 = new QState(s1);
QFinalState *s1_2 = new QFinalState(s1);
s1_1->addTransition(s1_2);
s1->setInitialState(s1_1);
- QFinalState *s2 = new QFinalState(machine.rootState());
+ QFinalState *s2 = new QFinalState(&machine);
s1->addTransition(s1, SIGNAL(finished()), s2);
machine.setInitialState(s1);
QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
@@ -1645,7 +1647,7 @@ void tst_QStateMachine::parallelStates()
void tst_QStateMachine::parallelRootState()
{
QStateMachine machine;
- QState *root = machine.rootState();
+ QState *root = &machine;
QCOMPARE(root->childMode(), QState::ExclusiveStates);
root->setChildMode(QState::ParallelStates);
QCOMPARE(root->childMode(), QState::ParallelStates);
@@ -1668,7 +1670,7 @@ void tst_QStateMachine::parallelRootState()
void tst_QStateMachine::allSourceToTargetConfigurations()
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
+ QState *s0 = new QState(&machine);
s0->setObjectName("s0");
QState *s1 = new QState(s0);
s1->setObjectName("s1");
@@ -1680,7 +1682,7 @@ void tst_QStateMachine::allSourceToTargetConfigurations()
s21->setObjectName("s21");
QState *s211 = new QState(s21);
s211->setObjectName("s211");
- QFinalState *f = new QFinalState(machine.rootState());
+ QFinalState *f = new QFinalState(&machine);
f->setObjectName("f");
s0->setInitialState(s1);
@@ -1754,7 +1756,7 @@ void tst_QStateMachine::signalTransitions()
{
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
+ QState *s0 = new QState(&machine);
QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: sender cannot be null");
QCOMPARE(s0->addTransition(0, SIGNAL(noSuchSignal()), 0), (QSignalTransition*)0);
@@ -1765,7 +1767,7 @@ void tst_QStateMachine::signalTransitions()
QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add transition to null state");
QCOMPARE(s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), 0), (QSignalTransition*)0);
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QFinalState *s1 = new QFinalState(&machine);
QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: no such signal SignalEmitter::noSuchSignal()");
QCOMPARE(s0->addTransition(&emitter, SIGNAL(noSuchSignal()), s1), (QSignalTransition*)0);
@@ -1816,8 +1818,8 @@ void tst_QStateMachine::signalTransitions()
}
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
SignalEmitter emitter;
QSignalTransition *trans = s0->addTransition(&emitter, "signalWithNoArg()", s1);
QVERIFY(trans != 0);
@@ -1844,8 +1846,8 @@ void tst_QStateMachine::signalTransitions()
}
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
SignalEmitter emitter;
TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithIntArg(int)), s1);
s0->addTransition(trans);
@@ -1863,8 +1865,8 @@ void tst_QStateMachine::signalTransitions()
}
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
SignalEmitter emitter;
TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithStringArg(QString)), s1);
s0->addTransition(trans);
@@ -1883,8 +1885,8 @@ void tst_QStateMachine::signalTransitions()
}
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
TestSignalTransition *trans = new TestSignalTransition();
QCOMPARE(trans->senderObject(), (QObject*)0);
@@ -1911,8 +1913,8 @@ void tst_QStateMachine::signalTransitions()
{
QStateMachine machine;
SignalEmitter emitter;
- QState *s0 = new QState(machine.rootState());
- QState *s1 = new QState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QState *s1 = new QState(&machine);
QSignalTransition *t0 = s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
QSignalTransition *t1 = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s0);
@@ -1956,12 +1958,12 @@ void tst_QStateMachine::signalTransitions()
{
QStateMachine machine;
SignalEmitter emitter;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
- QFinalState *s2 = new QFinalState(machine.rootState());
+ QFinalState *s2 = new QFinalState(&machine);
s0->addTransition(&emitter, SIGNAL(signalWithIntArg(int)), s2);
- QFinalState *s3 = new QFinalState(machine.rootState());
+ QFinalState *s3 = new QFinalState(&machine);
s0->addTransition(&emitter, SIGNAL(signalWithStringArg(QString)), s3);
QSignalSpy startedSpy(&machine, SIGNAL(started()));
@@ -1993,8 +1995,8 @@ void tst_QStateMachine::signalTransitions()
{
QStateMachine machine;
SignalEmitter emitter;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
QSignalTransition *t0 = s0->addTransition(&emitter, SIGNAL( signalWithNoArg( ) ), s1);
QVERIFY(t0 != 0);
QCOMPARE(t0->signal(), QByteArray(SIGNAL( signalWithNoArg( ) )));
@@ -2021,8 +2023,8 @@ void tst_QStateMachine::eventTransitions()
QPushButton button;
for (int x = 0; x < 2; ++x) {
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
QMouseEventTransition *trans;
if (x == 0) {
@@ -2070,8 +2072,8 @@ void tst_QStateMachine::eventTransitions()
}
for (int x = 0; x < 3; ++x) {
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
QEventTransition *trans;
if (x == 0) {
@@ -2105,8 +2107,8 @@ void tst_QStateMachine::eventTransitions()
}
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
QMouseEventTransition *trans = new QMouseEventTransition();
QCOMPARE(trans->eventObject(), (QObject*)0);
@@ -2131,8 +2133,8 @@ void tst_QStateMachine::eventTransitions()
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
QKeyEventTransition *trans = new QKeyEventTransition(&button, QEvent::KeyPress, Qt::Key_A);
QCOMPARE(trans->eventType(), QEvent::KeyPress);
@@ -2152,8 +2154,8 @@ void tst_QStateMachine::eventTransitions()
}
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
QKeyEventTransition *trans = new QKeyEventTransition();
QCOMPARE(trans->eventObject(), (QObject*)0);
@@ -2178,8 +2180,8 @@ void tst_QStateMachine::eventTransitions()
// Multiple transitions for same (object,event)
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QState *s1 = new QState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QState *s1 = new QState(&machine);
QEventTransition *t0 = new QEventTransition(&button, QEvent::MouseButtonPress);
t0->setTargetState(s1);
s0->addTransition(t0);
@@ -2226,9 +2228,9 @@ void tst_QStateMachine::eventTransitions()
// multiple event transitions from same source
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
- QFinalState *s2 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
+ QFinalState *s2 = new QFinalState(&machine);
QEventTransition *t0 = new QEventTransition(&button, QEvent::MouseButtonPress);
t0->setTargetState(s1);
s0->addTransition(t0);
@@ -2257,8 +2259,8 @@ void tst_QStateMachine::eventTransitions()
// custom event
{
QStateMachine machine;
- QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QState *s0 = new QState(&machine);
+ QFinalState *s1 = new QFinalState(&machine);
QEventTransition *trans = new QEventTransition(&button, QEvent::Type(QEvent::User+1));
trans->setTargetState(s1);
@@ -2276,7 +2278,7 @@ void tst_QStateMachine::historyStates()
{
for (int x = 0; x < 2; ++x) {
QStateMachine machine;
- QState *root = machine.rootState();
+ QState *root = &machine;
QState *s0 = new QState(root);
QState *s00 = new QState(s0);
QState *s01 = new QState(s0);
@@ -2360,7 +2362,7 @@ void tst_QStateMachine::startAndStop()
QCOMPARE(stoppedSpy.count(), 0);
QCOMPARE(finishedSpy.count(), 0);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
machine.start();
QTRY_COMPARE(machine.isRunning(), true);
@@ -2391,7 +2393,7 @@ void tst_QStateMachine::startAndStop()
void tst_QStateMachine::targetStateWithNoParent()
{
QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->setObjectName("s1");
QState s2;
s1->addTransition(&s2);
@@ -2411,9 +2413,9 @@ void tst_QStateMachine::targetStateWithNoParent()
void tst_QStateMachine::targetStateDeleted()
{
QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->setObjectName("s1");
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
QAbstractTransition *trans = s1->addTransition(s2);
delete s2;
QCOMPARE(trans->targetState(), (QAbstractState*)0);
@@ -2428,13 +2430,13 @@ void tst_QStateMachine::defaultGlobalRestorePolicy()
propertyHolder->setProperty("a", 1);
propertyHolder->setProperty("b", 2);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->assignProperty(propertyHolder, "a", 3);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(propertyHolder, "b", 4);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
s1->addTransition(new EventTransition(QEvent::User, s2));
s2->addTransition(new EventTransition(QEvent::User, s3));
@@ -2463,11 +2465,12 @@ void tst_QStateMachine::noInitialStateForInitialState()
{
QStateMachine machine;
- QState *initialState = new QState(machine.rootState());
+ QState *initialState = new QState(&machine);
initialState->setObjectName("initialState");
machine.setInitialState(initialState);
QState *childState = new QState(initialState);
+ (void)childState;
QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: "
"Missing initial state in compound state 'initialState'");
@@ -2487,7 +2490,7 @@ void tst_QStateMachine::restorePolicyNotInherited()
propertyHolder->setProperty("a", 1);
propertyHolder->setProperty("b", 2);
- QState *parentState = new QState(machine.rootState());
+ QState *parentState = new QState(&machine);
parentState->setObjectName("parentState");
parentState->setRestorePolicy(QState::RestoreProperties);
@@ -2536,13 +2539,13 @@ void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
propertyHolder->setProperty("a", 1);
propertyHolder->setProperty("b", 2);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->assignProperty(propertyHolder, "a", 3);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(propertyHolder, "b", 4);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
s1->addTransition(new EventTransition(QEvent::User, s2));
s2->addTransition(new EventTransition(QEvent::User, s3));
@@ -2646,7 +2649,7 @@ void tst_QStateMachine::restorePolicyOnChildState()
propertyHolder->setProperty("a", 1);
propertyHolder->setProperty("b", 2);
- QState *parentState = new QState(machine.rootState());
+ QState *parentState = new QState(&machine);
parentState->setObjectName("parentState");
QState *s1 = new QState(parentState);
@@ -2697,13 +2700,13 @@ void tst_QStateMachine::globalRestorePolicySetToRestore()
propertyHolder->setProperty("a", 1);
propertyHolder->setProperty("b", 2);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->assignProperty(propertyHolder, "a", 3);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(propertyHolder, "b", 4);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
s1->addTransition(new EventTransition(QEvent::User, s2));
s2->addTransition(new EventTransition(QEvent::User, s3));
@@ -2736,19 +2739,19 @@ void tst_QStateMachine::mixedRestoreProperties()
QObject *propertyHolder = new QObject();
propertyHolder->setProperty("a", 1);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
s1->setRestorePolicy(QState::RestoreProperties);
s1->assignProperty(propertyHolder, "a", 3);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(propertyHolder, "a", 4);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
- QState *s4 = new QState(machine.rootState());
+ QState *s4 = new QState(&machine);
s4->assignProperty(propertyHolder, "a", 5);
- QState *s5 = new QState(machine.rootState());
+ QState *s5 = new QState(&machine);
s5->setRestorePolicy(QState::RestoreProperties);
s5->assignProperty(propertyHolder, "a", 6);
@@ -2800,8 +2803,8 @@ void tst_QStateMachine::mixedRestoreProperties()
void tst_QStateMachine::transitionWithParent()
{
QStateMachine machine;
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
+ QState *s2 = new QState(&machine);
EventTransition *trans = new EventTransition(QEvent::User, s2, s1);
QCOMPARE(trans->sourceState(), s1);
QCOMPARE(trans->targetState(), (QAbstractState*)s2);
@@ -2816,8 +2819,8 @@ void tst_QStateMachine::simpleAnimation()
QObject *object = new QObject(&machine);
object->setProperty("fooBar", 1.0);
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "fooBar", 2.0);
EventTransition *et = new EventTransition(QEvent::User, s2);
@@ -2825,7 +2828,7 @@ void tst_QStateMachine::simpleAnimation()
et->addAnimation(animation);
s1->addTransition(et);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
s2->addTransition(animation, SIGNAL(finished()), s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
@@ -2860,8 +2863,8 @@ void tst_QStateMachine::twoAnimations()
object->setProperty("foo", 1.0);
object->setProperty("bar", 3.0);
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
s2->assignProperty(object, "bar", 10.0);
@@ -2878,7 +2881,7 @@ void tst_QStateMachine::twoAnimations()
et->addAnimation(animationBar);
s1->addTransition(et);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(s2, SIGNAL(polished()), s3);
@@ -2903,23 +2906,23 @@ void tst_QStateMachine::twoAnimatedTransitions()
QObject *object = new QObject(&machine);
object->setProperty("foo", 1.0);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
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());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
- QState *s4 = new QState(machine.rootState());
+ QState *s4 = new QState(&machine);
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());
+ QState *s5 = new QState(&machine);
QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
s4->addTransition(fooAnimation2, SIGNAL(finished()), s5);
@@ -2947,22 +2950,22 @@ void tst_QStateMachine::playAnimationTwice()
QObject *object = new QObject(&machine);
object->setProperty("foo", 1.0);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
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());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
- QState *s4 = new QState(machine.rootState());
+ QState *s4 = new QState(&machine);
s4->assignProperty(object, "foo", 2.0);
s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation);
- QState *s5 = new QState(machine.rootState());
+ QState *s5 = new QState(&machine);
QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
s4->addTransition(fooAnimation, SIGNAL(finished()), s5);
@@ -2993,8 +2996,8 @@ void tst_QStateMachine::nestedTargetStateForAnimation()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
@@ -3021,7 +3024,7 @@ void tst_QStateMachine::nestedTargetStateForAnimation()
connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
at->addAnimation(animation);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
s2->addTransition(s2Child, SIGNAL(polished()), s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
@@ -3049,13 +3052,13 @@ void tst_QStateMachine::animatedGlobalRestoreProperty()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
- QState *s2 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
- QState *s4 = new QState(machine.rootState());
+ QState *s4 = new QState(&machine);
QObject::connect(s4, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3093,16 +3096,16 @@ void tst_QStateMachine::specificTargetValueOfAnimation()
QObject *object = new QObject(&machine);
object->setProperty("foo", 1.0);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
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());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(anim, SIGNAL(finished()), s3);
@@ -3127,12 +3130,12 @@ void tst_QStateMachine::addDefaultAnimation()
QObject *object = new QObject();
object->setProperty("foo", 1.0);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3164,12 +3167,12 @@ void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3245,13 +3248,13 @@ void tst_QStateMachine::overrideDefaultAnimationWithSpecific()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3287,12 +3290,12 @@ void tst_QStateMachine::addDefaultAnimationForSource()
QObject *object = new QObject();
object->setProperty("foo", 1.0);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3319,12 +3322,12 @@ void tst_QStateMachine::addDefaultAnimationForTarget()
QObject *object = new QObject();
object->setProperty("foo", 1.0);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3348,88 +3351,88 @@ void tst_QStateMachine::removeDefaultAnimationForSource()
{
QStateMachine machine;
- QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 0);
QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
- machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+ machine.addDefaultAnimationForSourceState(&machine, 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));
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(&machine).contains(anim));
- machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+ machine.removeDefaultAnimationForTargetState(&machine, 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));
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(&machine).contains(anim));
- machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+ machine.removeDefaultAnimationForSourceState(&machine, anim);
- QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 0);
- machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+ machine.addDefaultAnimationForSourceState(&machine, anim);
QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
- machine.addDefaultAnimationForSourceState(machine.rootState(), anim2);
+ machine.addDefaultAnimationForSourceState(&machine, anim2);
- QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 2);
- QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
- QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 2);
+ QVERIFY(machine.defaultAnimationsForSourceState(&machine).contains(anim));
+ QVERIFY(machine.defaultAnimationsForSourceState(&machine).contains(anim2));
- machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+ machine.removeDefaultAnimationForSourceState(&machine, anim);
- QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
- QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(&machine).contains(anim2));
- machine.removeDefaultAnimationForSourceState(machine.rootState(), anim2);
- QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ machine.removeDefaultAnimationForSourceState(&machine, anim2);
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 0);
}
void tst_QStateMachine::removeDefaultAnimationForTarget()
{
QStateMachine machine;
- QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 0);
QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
- machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+ machine.addDefaultAnimationForTargetState(&machine, 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));
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(&machine).contains(anim));
- machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+ machine.removeDefaultAnimationForSourceState(&machine, 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));
+ QCOMPARE(machine.defaultAnimationsForSourceState(&machine).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(&machine).contains(anim));
- machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+ machine.removeDefaultAnimationForTargetState(&machine, anim);
- QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 0);
- machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+ machine.addDefaultAnimationForTargetState(&machine, anim);
QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
- machine.addDefaultAnimationForTargetState(machine.rootState(), anim2);
+ machine.addDefaultAnimationForTargetState(&machine, anim2);
- QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 2);
- QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
- QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 2);
+ QVERIFY(machine.defaultAnimationsForTargetState(&machine).contains(anim));
+ QVERIFY(machine.defaultAnimationsForTargetState(&machine).contains(anim2));
- machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+ machine.removeDefaultAnimationForTargetState(&machine, anim);
- QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
- QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(&machine).contains(anim2));
- machine.removeDefaultAnimationForTargetState(machine.rootState(), anim2);
- QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ machine.removeDefaultAnimationForTargetState(&machine, anim2);
+ QCOMPARE(machine.defaultAnimationsForTargetState(&machine).size(), 0);
}
void tst_QStateMachine::overrideDefaultAnimationWithSource()
@@ -3441,13 +3444,13 @@ void tst_QStateMachine::overrideDefaultAnimationWithSource()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3481,13 +3484,13 @@ void tst_QStateMachine::overrideDefaultAnimationWithTarget()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3522,13 +3525,13 @@ void tst_QStateMachine::overrideDefaultSourceAnimationWithSpecific()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3562,13 +3565,13 @@ void tst_QStateMachine::overrideDefaultTargetAnimationWithSpecific()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3602,13 +3605,13 @@ void tst_QStateMachine::overrideDefaultTargetAnimationWithSource()
SlotCalledCounter counter;
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(object, "foo", 2.0);
- QState *s3 = new QState(machine.rootState());
+ QState *s3 = new QState(&machine);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3644,10 +3647,10 @@ void tst_QStateMachine::parallelStateAssignmentsDone()
propertyHolder->setProperty("bar", 456);
propertyHolder->setProperty("zoot", 789);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ QState *parallelState = new QState(QState::ParallelStates, &machine);
parallelState->assignProperty(propertyHolder, "foo", 321);
QState *s2 = new QState(parallelState);
@@ -3676,10 +3679,10 @@ void tst_QStateMachine::transitionsFromParallelStateWithNoChildren()
{
QStateMachine machine;
- QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ QState *parallelState = new QState(QState::ParallelStates, &machine);
machine.setInitialState(parallelState);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
parallelState->addTransition(new EventTransition(QEvent::User, s1));
machine.start();
@@ -3700,7 +3703,7 @@ void tst_QStateMachine::parallelStateTransition()
{
QStateMachine machine;
- QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ QState *parallelState = new QState(QState::ParallelStates, &machine);
machine.setInitialState(parallelState);
QState *s1 = new QState(parallelState);
@@ -3749,10 +3752,10 @@ void tst_QStateMachine::nestedRestoreProperties()
propertyHolder->setProperty("foo", 1);
propertyHolder->setProperty("bar", 2);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(propertyHolder, "foo", 3);
QState *s21 = new QState(s2);
@@ -3801,10 +3804,10 @@ void tst_QStateMachine::nestedRestoreProperties2()
propertyHolder->setProperty("foo", 1);
propertyHolder->setProperty("bar", 2);
- QState *s1 = new QState(machine.rootState());
+ QState *s1 = new QState(&machine);
machine.setInitialState(s1);
- QState *s2 = new QState(machine.rootState());
+ QState *s2 = new QState(&machine);
s2->assignProperty(propertyHolder, "foo", 3);
QState *s21 = new QState(s2);
@@ -3856,6 +3859,46 @@ void tst_QStateMachine::nestedRestoreProperties2()
}
+void tst_QStateMachine::nestedStateMachines()
+{
+ QStateMachine machine;
+ QState *group = new QState(&machine);
+ group->setChildMode(QState::ParallelStates);
+ QStateMachine *subMachines[3];
+ for (int i = 0; i < 3; ++i) {
+ QState *subGroup = new QState(group);
+ QStateMachine *subMachine = new QStateMachine(subGroup);
+ {
+ QState *initial = new QState(subMachine);
+ QFinalState *done = new QFinalState(subMachine);
+ initial->addTransition(new EventTransition(QEvent::User, done));
+ subMachine->setInitialState(initial);
+ }
+ QFinalState *subMachineDone = new QFinalState(subGroup);
+ subMachine->addTransition(subMachine, SIGNAL(finished()), subMachineDone);
+ subGroup->setInitialState(subMachine);
+ subMachines[i] = subMachine;
+ }
+ QFinalState *final = new QFinalState(&machine);
+ group->addTransition(group, SIGNAL(finished()), final);
+ machine.setInitialState(group);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QTRY_COMPARE(machine.configuration().count(), 1+2*3);
+ QVERIFY(machine.configuration().contains(group));
+ for (int i = 0; i < 3; ++i)
+ QVERIFY(machine.configuration().contains(subMachines[i]));
+
+ QCoreApplication::processEvents(); // starts the submachines
+
+ for (int i = 0; i < 3; ++i)
+ subMachines[i]->postEvent(new QEvent(QEvent::User));
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+}
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"