From 24580f35a58390b4177aef8edef1192dc05f8ac2 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 17 Jun 2009 11:25:30 +0200 Subject: perform all property assignments of initial state that's nested If the machine's initial state is nested, a set of states will be entered, and we need to do the property assignments of all of them. --- src/corelib/statemachine/qstatemachine.cpp | 4 ++-- tests/auto/qstatemachine/tst_qstatemachine.cpp | 30 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 04cce50..758bdbe 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -1171,9 +1171,9 @@ void QStateMachinePrivate::_q_start() transitions.append(initialTransition); QEvent nullEvent(QEvent::None); executeTransitionContent(&nullEvent, transitions); - enterStates(&nullEvent, transitions); + QList enteredStates = enterStates(&nullEvent, transitions); applyProperties(transitions, QList() << start, - QList() << initial); + enteredStates); delete start; #ifdef QSTATEMACHINE_DEBUG diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 9bccb97..cd0c71d 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1269,25 +1269,33 @@ void tst_QStateMachine::assignProperty() s1->addTransition(s2); machine.setInitialState(s1); machine.start(); - QCoreApplication::processEvents(); - QCOMPARE(s1->objectName(), QString::fromLatin1("s1")); + QTRY_COMPARE(s1->objectName(), QString::fromLatin1("s1")); s1->assignProperty(s1, "objectName", "foo"); machine.start(); - QCoreApplication::processEvents(); - QCOMPARE(s1->objectName(), QString::fromLatin1("foo")); + QTRY_COMPARE(s1->objectName(), QString::fromLatin1("foo")); s1->assignProperty(s1, "noSuchProperty", 123); machine.start(); - QCoreApplication::processEvents(); - QCOMPARE(s1->objectName(), QString::fromLatin1("foo")); - QCOMPARE(s1->dynamicPropertyNames().size(), 1); + QTRY_COMPARE(s1->dynamicPropertyNames().size(), 1); QCOMPARE(s1->dynamicPropertyNames().at(0), QByteArray("noSuchProperty")); + QCOMPARE(s1->objectName(), QString::fromLatin1("foo")); - QSignalSpy polishedSpy(s1, SIGNAL(polished())); - machine.start(); - QCoreApplication::processEvents(); - QCOMPARE(polishedSpy.count(), 1); + { + QSignalSpy polishedSpy(s1, SIGNAL(polished())); + machine.start(); + QTRY_COMPARE(polishedSpy.count(), 1); + } + + // nested states + { + QState *s11 = new QState(s1); + QString str = QString::fromLatin1("set by nested state"); + s11->assignProperty(s11, "objectName", str); + s1->setInitialState(s11); + machine.start(); + QTRY_COMPARE(s11->objectName(), str); + } } void tst_QStateMachine::assignPropertyWithAnimation() -- cgit v0.12