diff options
-rw-r--r-- | src/scxml/qscxmlstatemachine.cpp | 4 | ||||
-rw-r--r-- | src/scxml/qscxmlstatemachine.h | 1 | ||||
-rw-r--r-- | tests/auto/statemachine/eventoccurred.scxml | 45 | ||||
-rw-r--r-- | tests/auto/statemachine/tst_statemachine.cpp | 27 | ||||
-rw-r--r-- | tests/auto/statemachine/tst_statemachine.qrc | 1 |
5 files changed, 78 insertions, 0 deletions
diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp index 78a8542..3ef07ae 100644 --- a/src/scxml/qscxmlstatemachine.cpp +++ b/src/scxml/qscxmlstatemachine.cpp @@ -667,6 +667,10 @@ void QScxmlInternal::WrappedQStateMachine::beginSelectTransitions(QEvent *event) emit d->stateMachine()->eventOccurred(*scxmlEvent); } + if (scxmlEvent->originType() == QLatin1String("qt:signal")) { + emit d->stateMachine()->externalEventOccurred(*scxmlEvent); + } + if (smp->m_eventFilter && !smp->m_eventFilter->handle(scxmlEvent, d->stateMachine())) { scxmlEvent->makeIgnorable(); scxmlEvent->clear(); diff --git a/src/scxml/qscxmlstatemachine.h b/src/scxml/qscxmlstatemachine.h index 0037fef..5a800d5 100644 --- a/src/scxml/qscxmlstatemachine.h +++ b/src/scxml/qscxmlstatemachine.h @@ -141,6 +141,7 @@ Q_SIGNALS: void dataModelChanged(QScxmlDataModel *model); void initialValuesChanged(const QVariantMap &initialValues); void initializedChanged(bool initialized); + void externalEventOccurred(const QScxmlEvent &event); public Q_SLOTS: void start(); diff --git a/tests/auto/statemachine/eventoccurred.scxml b/tests/auto/statemachine/eventoccurred.scxml new file mode 100644 index 0000000..6c164c2 --- /dev/null +++ b/tests/auto/statemachine/eventoccurred.scxml @@ -0,0 +1,45 @@ +<?xml version="1.0" ?> +<!-- +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtScxml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +--> +<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" + name="EventOccurred" datamodel="ecmascript"> + <state id="top"> + <state id="a"> + <onentry> + <raise event="internalEvent1"/> + <send event="internalEvent2"/> + <send type="qt:signal" event="externalEvent"/> + <send event="timeout" delay="1s"/> + </onentry> + <transition event="timeout" target="final"/> + </state> + <final id="final"/> + </state> +</scxml> diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp index 7a269b2..fccfd25 100644 --- a/tests/auto/statemachine/tst_statemachine.cpp +++ b/tests/auto/statemachine/tst_statemachine.cpp @@ -46,6 +46,7 @@ private Q_SLOTS: void activeStateNames_data(); void activeStateNames(); void connectToFinal(); + void eventOccurred(); }; void tst_StateMachine::stateNames_data() @@ -128,6 +129,32 @@ void tst_StateMachine::connectToFinal() QVERIFY(stateMachine->connectToState(QString("final"), &dummy, SLOT(deleteLater()))); } +void tst_StateMachine::eventOccurred() +{ + QScopedPointer<QScxmlStateMachine> stateMachine(QScxmlStateMachine::fromFile(QString(":/tst_statemachine/eventoccurred.scxml"))); + QVERIFY(!stateMachine.isNull()); + + qRegisterMetaType<QScxmlEvent>(); + QSignalSpy finishedSpy(stateMachine.data(), SIGNAL(finished())); + QSignalSpy eventOccurredSpy(stateMachine.data(), SIGNAL(eventOccurred(QScxmlEvent))); + QSignalSpy externalEventOccurredSpy(stateMachine.data(), SIGNAL(externalEventOccurred(QScxmlEvent))); + + stateMachine->start(); + + finishedSpy.wait(5000); + + QCOMPARE(eventOccurredSpy.count(), 4); + QCOMPARE(qvariant_cast<QScxmlEvent>(eventOccurredSpy.at(0).at(0)).name(), QLatin1String("internalEvent2")); + QCOMPARE(qvariant_cast<QScxmlEvent>(eventOccurredSpy.at(1).at(0)).name(), QLatin1String("externalEvent")); + QCOMPARE(qvariant_cast<QScxmlEvent>(eventOccurredSpy.at(2).at(0)).name(), QLatin1String("timeout")); + QCOMPARE(qvariant_cast<QScxmlEvent>(eventOccurredSpy.at(3).at(0)).name(), QLatin1String("done.state.top")); + + + QCOMPARE(externalEventOccurredSpy.count(), 1); + QCOMPARE(qvariant_cast<QScxmlEvent>(externalEventOccurredSpy.at(0).at(0)).name(), QLatin1String("externalEvent")); +} + + QTEST_MAIN(tst_StateMachine) #include "tst_statemachine.moc" diff --git a/tests/auto/statemachine/tst_statemachine.qrc b/tests/auto/statemachine/tst_statemachine.qrc index 69c96ae..8a006d7 100644 --- a/tests/auto/statemachine/tst_statemachine.qrc +++ b/tests/auto/statemachine/tst_statemachine.qrc @@ -1,5 +1,6 @@ <RCC> <qresource prefix="/tst_statemachine"> + <file>eventoccurred.scxml</file> <file>statenames.scxml</file> <file>statenamesnested.scxml</file> </qresource> |