summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-03-11 14:28:22 +0200
committerJuha Vuolle <juha.vuolle@insta.fi>2021-05-03 13:52:17 +0300
commit325d27bf651441f5252e727b24ab8d1c673e8137 (patch)
tree9ed6bdbbae31b8b86663957faeadd8940b43fb2d /src
parent26d9862c83d7f18eb4a23da342b6d3130494c4cb (diff)
QtScxml bindable support to QScxmlDataModel::stateMachine
Task-number: QTBUG-89895 Change-Id: I11f1caec9eee9b9767691c93e4deb0dbf57be496 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/scxml/qscxmldatamodel.cpp15
-rw-r--r--src/scxml/qscxmldatamodel.h4
-rw-r--r--src/scxml/qscxmldatamodel_p.h19
3 files changed, 30 insertions, 8 deletions
diff --git a/src/scxml/qscxmldatamodel.cpp b/src/scxml/qscxmldatamodel.cpp
index 2a827a1..fd7af27 100644
--- a/src/scxml/qscxmldatamodel.cpp
+++ b/src/scxml/qscxmldatamodel.cpp
@@ -131,11 +131,12 @@ void QScxmlDataModel::setStateMachine(QScxmlStateMachine *stateMachine)
{
Q_D(QScxmlDataModel);
- if (d->m_stateMachine == nullptr && stateMachine != nullptr) {
+ if (d->m_stateMachine.value() == nullptr && stateMachine != nullptr) {
+ // the binding is removed only on the first valid set
+ // as the later attempts are ignored (removed when value is set below)
d->m_stateMachine = stateMachine;
- if (stateMachine)
- stateMachine->setDataModel(this);
- emit stateMachineChanged(stateMachine);
+ stateMachine->setDataModel(this);
+ d->m_stateMachine.notify();
}
}
@@ -148,6 +149,12 @@ QScxmlStateMachine *QScxmlDataModel::stateMachine() const
return d->m_stateMachine;
}
+QBindable<QScxmlStateMachine*> QScxmlDataModel::bindableStateMachine()
+{
+ Q_D(QScxmlDataModel);
+ return &d->m_stateMachine;
+}
+
/*!
* Creates a data model from a plugin specified by a \a pluginKey.
*/
diff --git a/src/scxml/qscxmldatamodel.h b/src/scxml/qscxmldatamodel.h
index d9c07c9..e72a23c 100644
--- a/src/scxml/qscxmldatamodel.h
+++ b/src/scxml/qscxmldatamodel.h
@@ -57,7 +57,8 @@ class Q_SCXML_EXPORT QScxmlDataModel : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QScxmlDataModel)
- Q_PROPERTY(QScxmlStateMachine *stateMachine READ stateMachine WRITE setStateMachine NOTIFY stateMachineChanged)
+ Q_PROPERTY(QScxmlStateMachine *stateMachine READ stateMachine WRITE setStateMachine
+ NOTIFY stateMachineChanged BINDABLE bindableStateMachine)
public:
class Q_SCXML_EXPORT ForeachLoopBody
@@ -76,6 +77,7 @@ public:
void setStateMachine(QScxmlStateMachine *stateMachine);
QScxmlStateMachine *stateMachine() const;
+ QBindable<QScxmlStateMachine*> bindableStateMachine();
Q_INVOKABLE virtual bool setup(const QVariantMap &initialDataValues) = 0;
diff --git a/src/scxml/qscxmldatamodel_p.h b/src/scxml/qscxmldatamodel_p.h
index b91c63c..b2a1ebf 100644
--- a/src/scxml/qscxmldatamodel_p.h
+++ b/src/scxml/qscxmldatamodel_p.h
@@ -54,18 +54,31 @@
#include "qscxmldatamodel.h"
#include "qscxmlcompiler_p.h"
#include <private/qobject_p.h>
+#include <private/qproperty_p.h>
QT_BEGIN_NAMESPACE
class QScxmlDataModelPrivate : public QObjectPrivate
{
+ Q_DECLARE_PUBLIC(QScxmlDataModel)
public:
- QScxmlDataModelPrivate() : m_stateMachine(nullptr) {}
+ QScxmlDataModelPrivate() = default;
static QScxmlDataModel *instantiateDataModel(DocumentModel::Scxml::DataModelType type);
-public:
- QScxmlStateMachine *m_stateMachine;
+ void setStateMachine(QScxmlStateMachine* stateMachine)
+ {
+ q_func()->setStateMachine(stateMachine);
+ }
+
+ void emitStateMachineChanged(QScxmlStateMachine* newValue)
+ {
+ emit q_func()->stateMachineChanged(newValue);
+ }
+
+ Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QScxmlDataModelPrivate, QScxmlStateMachine*, m_stateMachine,
+ &QScxmlDataModelPrivate::setStateMachine,
+ &QScxmlDataModelPrivate::emitStateMachineChanged, nullptr)
};
QT_END_NAMESPACE