| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef EVENTCONNECTION_P_H |
| 5 | #define EVENTCONNECTION_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qscxmlqmlglobals_p.h" |
| 19 | |
| 20 | #include <QtScxml/qscxmlstatemachine.h> |
| 21 | #include <QtScxml/qscxmlevent.h> |
| 22 | #include <QtCore/qobject.h> |
| 23 | #include <QtQml/qqmlparserstatus.h> |
| 24 | #include <QtQml/qqml.h> |
| 25 | #include "QtCore/qproperty.h" |
| 26 | #include <private/qproperty_p.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | // QScxmlEvent is used as signal parameter, and defined in the cpp lib |
| 31 | struct Q_SCXMLQML_EXPORT QScxmlEventForeign |
| 32 | { |
| 33 | Q_GADGET |
| 34 | QML_ANONYMOUS |
| 35 | QML_FOREIGN(QScxmlEvent) |
| 36 | QML_ADDED_IN_VERSION(5,8) |
| 37 | }; |
| 38 | |
| 39 | class Q_SCXMLQML_EXPORT QScxmlEventConnection : public QObject, public QQmlParserStatus |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | Q_PROPERTY(QStringList events READ events WRITE setEvents NOTIFY eventsChanged |
| 43 | BINDABLE bindableEvents) |
| 44 | Q_PROPERTY(QScxmlStateMachine *stateMachine READ stateMachine WRITE setStateMachine |
| 45 | NOTIFY stateMachineChanged BINDABLE bindableStateMachine) |
| 46 | Q_INTERFACES(QQmlParserStatus) |
| 47 | QML_NAMED_ELEMENT(EventConnection) |
| 48 | QML_ADDED_IN_VERSION(5,8) |
| 49 | |
| 50 | public: |
| 51 | QScxmlEventConnection(QObject *parent = nullptr); |
| 52 | |
| 53 | QStringList events() const; |
| 54 | void setEvents(const QStringList &events); |
| 55 | QBindable<QStringList> bindableEvents(); |
| 56 | |
| 57 | QScxmlStateMachine *stateMachine() const; |
| 58 | void setStateMachine(QScxmlStateMachine *stateMachine); |
| 59 | QBindable<QScxmlStateMachine*> bindableStateMachine(); |
| 60 | |
| 61 | Q_SIGNALS: |
| 62 | void eventsChanged(); |
| 63 | void stateMachineChanged(); |
| 64 | |
| 65 | void occurred(const QScxmlEvent &event); |
| 66 | |
| 67 | private: |
| 68 | Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QScxmlEventConnection, QScxmlStateMachine*, m_stateMachine, |
| 69 | &QScxmlEventConnection::setStateMachine, |
| 70 | &QScxmlEventConnection::stateMachineChanged, nullptr); |
| 71 | Q_OBJECT_COMPAT_PROPERTY(QScxmlEventConnection, QStringList, m_events, |
| 72 | &QScxmlEventConnection::setEvents, |
| 73 | &QScxmlEventConnection::eventsChanged); |
| 74 | |
| 75 | QList<QMetaObject::Connection> m_connections; |
| 76 | |
| 77 | void doConnect(); |
| 78 | void classBegin() override; |
| 79 | void componentComplete() override; |
| 80 | }; |
| 81 | |
| 82 | QT_END_NAMESPACE |
| 83 | |
| 84 | #endif // EVENTCONNECTION_P_H |
| 85 | |