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#include "invokedservices_p.h"
5#include <QtScxml/qscxmlinvokableservice.h>
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \qmltype InvokedServices
11//! \instantiates QScxmlInvokedServices
12 \inqmlmodule QtScxml
13 \since QtScxml 5.8
14
15 \brief Provices access to the services invoked by state machines.
16
17 Makes the invoked services easily accessible by their names, without
18 constantly iterating through QScxmlStateMachine::invokedServices.
19
20 The services are called from state machines via the mechanism described in
21 \l{SCXML Specification - 6.4 <invoke>}.
22*/
23
24QScxmlInvokedServices::QScxmlInvokedServices(QObject *parent) : QObject(parent)
25{
26}
27
28/*!
29 \qmlproperty var InvokedServices::children
30
31 The services invoked by the state machine.
32*/
33
34QVariantMap QScxmlInvokedServices::children()
35{
36 return m_children.value();
37}
38
39QVariantMap QScxmlInvokedServices::childrenActualCalculation() const
40{
41 QVariantMap ret;
42 if (m_stateMachine.value()) {
43 const QList<QScxmlInvokableService *> children = m_stateMachine->invokedServices();
44 for (QScxmlInvokableService *service : children)
45 ret.insert(key: service->name(), value: QVariant::fromValue(value: service));
46 }
47 return ret;
48}
49
50QBindable<QVariantMap> QScxmlInvokedServices::bindableChildren()
51{
52 return &m_children;
53}
54
55void QScxmlInvokedServices::classBegin()
56{
57}
58
59/*!
60 \qmlproperty ScxmlStateMachine InvokedServices::stateMachine
61
62 The state machine that invoked the services.
63*/
64
65QScxmlStateMachine *QScxmlInvokedServices::stateMachine() const
66{
67 return m_stateMachine;
68}
69
70void QScxmlInvokedServices::setStateMachine(QScxmlStateMachine *stateMachine)
71{
72 if (stateMachine == m_stateMachine.value()) {
73 m_stateMachine.removeBindingUnlessInWrapper();
74 return;
75 }
76
77 QObject::disconnect(m_serviceConnection);
78 m_stateMachine = stateMachine;
79
80 if (m_stateMachine.value()) {
81 m_serviceConnection = QObject::connect(
82 sender: m_stateMachine.value(), signal: &QScxmlStateMachine::invokedServicesChanged,
83 slot: [this](){
84 m_children.notify();
85 emit childrenChanged();
86 });
87 }
88 m_stateMachine.notify();
89 m_children.notify();
90 emit childrenChanged();
91}
92
93QBindable<QScxmlStateMachine*> QScxmlInvokedServices::bindableStateMachine()
94{
95 return &m_stateMachine;
96}
97
98/*!
99 \qmlproperty list<QtObject> InvokedServices::qmlChildren
100
101 A list of additional QtObject types nested in this type.
102*/
103
104QQmlListProperty<QObject> QScxmlInvokedServices::qmlChildren()
105{
106 return QQmlListProperty<QObject>(this, &m_qmlChildren);
107}
108
109void QScxmlInvokedServices::componentComplete()
110{
111 if (!m_stateMachine.value())
112 setStateMachine(qobject_cast<QScxmlStateMachine *>(object: parent()));
113}
114
115QT_END_NAMESPACE
116

source code of qtscxml/src/scxmlqml/invokedservices.cpp