summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@theqtcompany.com>2016-02-10 09:56:29 +0100
committerJarek Kobus <jaroslaw.kobus@theqtcompany.com>2016-04-12 19:09:52 +0000
commite1513d7f904f03617c38f14d65cdaa8afd4ff2b2 (patch)
tree0af97ecae076945fdcf18b44d025a04a7d6a747f
parentfcd9af589dbf5bc9dcf100c7fa8ebdfed7d88243 (diff)
Add externalEventOccurred() signal.v5.7.0-beta1
This signal is emitted only for events sent from SCXML file which are of qt:signal type. Reasoning: I want to use state names which contain dots, e.g. "Letter.A", "Letter.B", etc. The reason for that is I may listen to "done.state.Letter.*" event, which will be generated automatically whenever one of Letter.* went to its final state. Unfortunately, I cannot use qt-mode in that case, since dots in state names are not allowed in qt-mode. I'm forced to use non-qt-mode. In the same document I send external signals with <send type="qt:signal">. In order to listen to these signals I need to connect to the generic eventOccurred() signal in cpp code, since there is no other way in non-qt-mode. However, when I'm connected to eventOccurred() my slot is being invoked for every internal event, which slows down the execution. Practically, I'm not interested in internal events at all, but only for those marked with type="qt:signal". That's why this patch provides additional generic signal for "qt:signal" only event. Change-Id: Ic9206e98a20f72142f5584e0568f9f33d56f8e97 Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
-rw-r--r--src/scxml/qscxmlstatemachine.cpp4
-rw-r--r--src/scxml/qscxmlstatemachine.h1
-rw-r--r--tests/auto/statemachine/eventoccurred.scxml45
-rw-r--r--tests/auto/statemachine/tst_statemachine.cpp27
-rw-r--r--tests/auto/statemachine/tst_statemachine.qrc1
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>