| 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 "qscxmlecmascriptplatformproperties_p.h" |
| 5 | #include "qscxmlstatemachine.h" |
| 6 | |
| 7 | #include <qjsengine.h> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | class QScxmlPlatformProperties::Data |
| 11 | { |
| 12 | public: |
| 13 | Data() |
| 14 | : m_stateMachine(nullptr) |
| 15 | {} |
| 16 | |
| 17 | QScxmlStateMachine *m_stateMachine; |
| 18 | QJSValue m_jsValue; |
| 19 | }; |
| 20 | |
| 21 | QScxmlPlatformProperties::QScxmlPlatformProperties(QObject *parent) |
| 22 | : QObject(parent) |
| 23 | , data(new Data) |
| 24 | {} |
| 25 | |
| 26 | QScxmlPlatformProperties *QScxmlPlatformProperties::create(QJSEngine *engine, QScxmlStateMachine *stateMachine) |
| 27 | { |
| 28 | QScxmlPlatformProperties *pp = new QScxmlPlatformProperties(engine); |
| 29 | pp->data->m_stateMachine = stateMachine; |
| 30 | pp->data->m_jsValue = engine->newQObject(object: pp); |
| 31 | return pp; |
| 32 | } |
| 33 | |
| 34 | QScxmlPlatformProperties::~QScxmlPlatformProperties() |
| 35 | { |
| 36 | delete data; |
| 37 | } |
| 38 | |
| 39 | QJSEngine *QScxmlPlatformProperties::engine() const |
| 40 | { |
| 41 | return qobject_cast<QJSEngine *>(object: parent()); |
| 42 | } |
| 43 | |
| 44 | QScxmlStateMachine *QScxmlPlatformProperties::stateMachine() const |
| 45 | { |
| 46 | return data->m_stateMachine; |
| 47 | } |
| 48 | |
| 49 | QJSValue QScxmlPlatformProperties::jsValue() const |
| 50 | { |
| 51 | return data->m_jsValue; |
| 52 | } |
| 53 | |
| 54 | /// _x.marks === "the spot" |
| 55 | QString QScxmlPlatformProperties::marks() const |
| 56 | { |
| 57 | return QStringLiteral("the spot"); |
| 58 | } |
| 59 | |
| 60 | bool QScxmlPlatformProperties::inState(const QString &stateName) |
| 61 | { |
| 62 | return stateMachine()->isActive(scxmlStateName: stateName); |
| 63 | } |
| 64 | |
| 65 | QT_END_NAMESPACE |
| 66 |
