summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-02-16 10:09:37 +0200
committerJuha Vuolle <juha.vuolle@insta.fi>2021-05-03 13:51:49 +0300
commit4c6cdbf36f73a933daf8cc345156a2b52c03b7c1 (patch)
treecf4d4953bdacfa26d32d860bcf1c0afe035af703 /src
parentcd2f8a7e306a9af6f515eda2a8f1d715d46b37b4 (diff)
QScxmlEventConnection bindable support
QScxmlEventConnection is a class exposed for QML use Task-number: QTBUG-89895 Change-Id: I315c1e460cc01a57f841e832385959ef36618e91 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/scxmlqml/eventconnection.cpp43
-rw-r--r--src/scxmlqml/eventconnection_p.h17
2 files changed, 40 insertions, 20 deletions
diff --git a/src/scxmlqml/eventconnection.cpp b/src/scxmlqml/eventconnection.cpp
index 2a073bd..d5d594d 100644
--- a/src/scxmlqml/eventconnection.cpp
+++ b/src/scxmlqml/eventconnection.cpp
@@ -81,7 +81,7 @@ QT_BEGIN_NAMESPACE
QScxmlEventConnection::QScxmlEventConnection(QObject *parent) :
- QObject(parent), m_stateMachine(nullptr)
+ QObject(parent)
{
}
@@ -92,11 +92,18 @@ QStringList QScxmlEventConnection::events() const
void QScxmlEventConnection::setEvents(const QStringList &events)
{
- if (events != m_events) {
- m_events = events;
- doConnect();
- emit eventsChanged();
+ if (events == m_events.value()) {
+ m_events.removeBindingUnlessInWrapper();
+ return;
}
+ m_events = events;
+ doConnect();
+ m_events.notify();
+}
+
+QBindable<QStringList> QScxmlEventConnection::bindableEvents()
+{
+ return &m_events;
}
QScxmlStateMachine *QScxmlEventConnection::stateMachine() const
@@ -106,11 +113,18 @@ QScxmlStateMachine *QScxmlEventConnection::stateMachine() const
void QScxmlEventConnection::setStateMachine(QScxmlStateMachine *stateMachine)
{
- if (stateMachine != m_stateMachine) {
- m_stateMachine = stateMachine;
- doConnect();
- emit stateMachineChanged();
+ if (stateMachine == m_stateMachine.value()) {
+ m_stateMachine.removeBindingUnlessInWrapper();
+ return;
}
+ m_stateMachine = stateMachine;
+ doConnect();
+ m_stateMachine.notify();
+}
+
+QBindable<QScxmlStateMachine*> QScxmlEventConnection::bindableStateMachine()
+{
+ return &m_stateMachine;
}
void QScxmlEventConnection::doConnect()
@@ -119,13 +133,11 @@ void QScxmlEventConnection::doConnect()
disconnect(connection);
m_connections.clear();
if (m_stateMachine) {
- for (const QString &event : qAsConst(m_events)) {
+ for (const QString &event : qAsConst(m_events.value())) {
m_connections.append(m_stateMachine->connectToEvent(event, this,
&QScxmlEventConnection::occurred));
}
-
}
-
}
void QScxmlEventConnection::classBegin()
@@ -134,10 +146,9 @@ void QScxmlEventConnection::classBegin()
void QScxmlEventConnection::componentComplete()
{
- if (!m_stateMachine) {
- if ((m_stateMachine = qobject_cast<QScxmlStateMachine *>(parent())))
- doConnect();
- }
+ auto parentStateMachine = qobject_cast<QScxmlStateMachine *>(parent());
+ if (!m_stateMachine.value() && parentStateMachine)
+ setStateMachine(parentStateMachine);
}
QT_END_NAMESPACE
diff --git a/src/scxmlqml/eventconnection_p.h b/src/scxmlqml/eventconnection_p.h
index f2a8f60..8c2bd26 100644
--- a/src/scxmlqml/eventconnection_p.h
+++ b/src/scxmlqml/eventconnection_p.h
@@ -58,6 +58,8 @@
#include <QtCore/qobject.h>
#include <QtQml/qqmlparserstatus.h>
#include <QtQml/qqml.h>
+#include "QtCore/qproperty.h"
+#include <private/qproperty_p.h>
QT_BEGIN_NAMESPACE
@@ -73,9 +75,10 @@ struct Q_SCXMLQML_PRIVATE_EXPORT QScxmlEventForeign
class Q_SCXMLQML_PRIVATE_EXPORT QScxmlEventConnection : public QObject, public QQmlParserStatus
{
Q_OBJECT
- Q_PROPERTY(QStringList events READ events WRITE setEvents NOTIFY eventsChanged)
+ Q_PROPERTY(QStringList events READ events WRITE setEvents NOTIFY eventsChanged
+ BINDABLE bindableEvents)
Q_PROPERTY(QScxmlStateMachine *stateMachine READ stateMachine WRITE setStateMachine
- NOTIFY stateMachineChanged)
+ NOTIFY stateMachineChanged BINDABLE bindableStateMachine)
Q_INTERFACES(QQmlParserStatus)
QML_NAMED_ELEMENT(EventConnection)
QML_ADDED_IN_VERSION(5,8)
@@ -85,9 +88,11 @@ public:
QStringList events() const;
void setEvents(const QStringList &events);
+ QBindable<QStringList> bindableEvents();
QScxmlStateMachine *stateMachine() const;
void setStateMachine(QScxmlStateMachine *stateMachine);
+ QBindable<QScxmlStateMachine*> bindableStateMachine();
Q_SIGNALS:
void eventsChanged();
@@ -96,8 +101,12 @@ Q_SIGNALS:
void occurred(const QScxmlEvent &event);
private:
- QScxmlStateMachine *m_stateMachine;
- QStringList m_events;
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QScxmlEventConnection, QScxmlStateMachine*, m_stateMachine,
+ &QScxmlEventConnection::setStateMachine,
+ &QScxmlEventConnection::stateMachineChanged, nullptr);
+ Q_OBJECT_COMPAT_PROPERTY(QScxmlEventConnection, QStringList, m_events,
+ &QScxmlEventConnection::setEvents,
+ &QScxmlEventConnection::eventsChanged);
QList<QMetaObject::Connection> m_connections;