diff options
5 files changed, 130 insertions, 3 deletions
diff --git a/examples/scxml/calculator-qml/calculator-qml.qml b/examples/scxml/calculator-qml/calculator-qml.qml index 9d679f6..fb32a69 100644 --- a/examples/scxml/calculator-qml/calculator-qml.qml +++ b/examples/scxml/calculator-qml/calculator-qml.qml @@ -62,7 +62,7 @@ Window { CalculatorStateMachine { id: statemachine running: true - property var connection: EventConnection { + EventConnection { events: ["updateDisplay"] onOccurred: resultText.text = event.data.display } diff --git a/src/imports/scxmlstatemachine/plugin.cpp b/src/imports/scxmlstatemachine/plugin.cpp index df833f0..817a972 100644 --- a/src/imports/scxmlstatemachine/plugin.cpp +++ b/src/imports/scxmlstatemachine/plugin.cpp @@ -40,6 +40,7 @@ #include "statemachineloader.h" #include "eventconnection.h" #include "qscxmlevent.h" +#include "statemachineextended.h" #include <QQmlExtensionPlugin> #include <qqml.h> @@ -68,6 +69,8 @@ public: Q_UNUSED(qScxmlEventMetaTypeId) qmlRegisterType<QScxmlStateMachineLoader>(uri, major, minor, "StateMachineLoader"); qmlRegisterType<QScxmlEventConnection>(uri, major, minor, "EventConnection"); + qmlRegisterExtendedUncreatableType<QScxmlStateMachine, QScxmlStateMachineExtended>( + uri, major, minor, "QScxmlStateMachine", "Only created through derived types"); qmlProtectModule(uri, 1); } }; diff --git a/src/imports/scxmlstatemachine/scxmlstatemachine.pro b/src/imports/scxmlstatemachine/scxmlstatemachine.pro index 40c3b49..2b87a85 100644 --- a/src/imports/scxmlstatemachine/scxmlstatemachine.pro +++ b/src/imports/scxmlstatemachine/scxmlstatemachine.pro @@ -6,11 +6,13 @@ QT = scxml qml-private core-private SOURCES = \ $$PWD/plugin.cpp \ $$PWD/statemachineloader.cpp \ - $$PWD/eventconnection.cpp + $$PWD/eventconnection.cpp \ + $$PWD/statemachineextended.cpp HEADERS = \ $$PWD/statemachineloader.h \ - $$PWD/eventconnection.h + $$PWD/eventconnection.h \ + $$PWD/statemachineextended.h load(qml_plugin) diff --git a/src/imports/scxmlstatemachine/statemachineextended.cpp b/src/imports/scxmlstatemachine/statemachineextended.cpp new file mode 100644 index 0000000..182fb70 --- /dev/null +++ b/src/imports/scxmlstatemachine/statemachineextended.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "statemachineextended.h" + +#include <QtScxml/qscxmlglobals.h> +#include <QtScxml/qscxmlstatemachine.h> + +QT_BEGIN_NAMESPACE + +QScxmlStateMachineExtended::QScxmlStateMachineExtended(QObject *extendee) : + QObject(extendee) +{ +} + +QQmlListProperty<QObject> QScxmlStateMachineExtended::children() +{ + return QQmlListProperty<QObject>(this, m_children); +} + +QT_END_NAMESPACE diff --git a/src/imports/scxmlstatemachine/statemachineextended.h b/src/imports/scxmlstatemachine/statemachineextended.h new file mode 100644 index 0000000..5f814b9 --- /dev/null +++ b/src/imports/scxmlstatemachine/statemachineextended.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef STATEMACHINEEXTENDED_H +#define STATEMACHINEEXTENDED_H + +#include <QtScxml/qscxmlglobals.h> +#include <QtCore/qobject.h> +#include <QtQml/qqmllist.h> + +QT_BEGIN_NAMESPACE + +/* Allow State Machines created from QML to have children. */ +class QScxmlStateMachineExtended : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<QObject> children READ children) + Q_CLASSINFO("DefaultProperty", "children") +public: + QScxmlStateMachineExtended(QObject *extendee); + QQmlListProperty<QObject> children(); + +private: + QObjectList m_children; +}; + +QT_END_NAMESPACE + +#endif // STATEMACHINEEXTENDED_H |