diff options
7 files changed, 37 insertions, 34 deletions
diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.qml b/examples/scxml/invoke-dynamic/invoke-dynamic.qml index 616928e..0e38d67 100644 --- a/examples/scxml/invoke-dynamic/invoke-dynamic.qml +++ b/examples/scxml/invoke-dynamic/invoke-dynamic.qml @@ -55,6 +55,6 @@ MainView { Scxml.StateMachineLoader { id: directions - filename: "qrc:///statemachine.scxml" + source: "qrc:///statemachine.scxml" } } diff --git a/examples/scxml/mediaplayer-common/Mediaplayer.qml b/examples/scxml/mediaplayer-common/Mediaplayer.qml index 1804b55..c5e0bcf 100644 --- a/examples/scxml/mediaplayer-common/Mediaplayer.qml +++ b/examples/scxml/mediaplayer-common/Mediaplayer.qml @@ -55,7 +55,7 @@ import QtScxml 5.7 Window { id: root property QtObject stateMachine: scxmlLoader.stateMachine - property alias filename: scxmlLoader.filename + property alias source: scxmlLoader.source visible: true width: 750 diff --git a/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qml b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qml index 3e936c3..864a76f 100644 --- a/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qml +++ b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qml @@ -49,5 +49,5 @@ ****************************************************************************/ Mediaplayer { - filename: "qrc:///mediaplayer.scxml" + source: "qrc:///mediaplayer.scxml" } diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml index 772d2fb..c04c877 100644 --- a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml +++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml @@ -53,7 +53,7 @@ import QtScxml 5.7 as Scxml TrafficLight { Scxml.StateMachineLoader { id: loader - filename: "qrc:///statemachine.scxml" + source: "qrc:///statemachine.scxml" } stateMachine: loader.stateMachine diff --git a/src/imports/scxmlstatemachine/plugins.qmltypes b/src/imports/scxmlstatemachine/plugins.qmltypes index 1366717..c066748 100644 --- a/src/imports/scxmlstatemachine/plugins.qmltypes +++ b/src/imports/scxmlstatemachine/plugins.qmltypes @@ -13,7 +13,7 @@ Module { prototype: "QObject" exports: ["QtScxml/StateMachineLoader 5.7"] exportMetaObjectRevisions: [0] - Property { name: "filename"; type: "QUrl" } + Property { name: "source"; type: "QUrl" } Property { name: "stateMachine"; type: "QScxmlStateMachine"; isReadonly: true; isPointer: true } Property { name: "initialValues"; type: "QVariantMap" } Property { name: "dataModel"; type: "QScxmlDataModel"; isPointer: true } diff --git a/src/imports/scxmlstatemachine/statemachineloader.cpp b/src/imports/scxmlstatemachine/statemachineloader.cpp index 81a1ea4..d255781 100644 --- a/src/imports/scxmlstatemachine/statemachineloader.cpp +++ b/src/imports/scxmlstatemachine/statemachineloader.cpp @@ -51,14 +51,14 @@ \instantiates QScxmlStateMachineLoader \inqmlmodule Scxml - \brief Dynamically loads an SCXML file and instantiates the state machine. + \brief Dynamically loads an SCXML document and instantiates the state machine. \since QtScxml 5.7 */ /*! - \qmlsignal StateMachineLoader::filenameChanged() - This signal is emitted when the user changes the filename. + \qmlsignal StateMachineLoader::sourceChanged() + This signal is emitted when the user changes the source URL for the SCXML document. */ /*! @@ -87,34 +87,34 @@ QT_PREPEND_NAMESPACE(QScxmlStateMachine) *QScxmlStateMachineLoader::stateMachine } /*! - \qmlproperty string StateMachineLoader::filename + \qmlproperty string StateMachineLoader::source - The name of the SCXML file to load. + The url of the SCXML document to load. Only synchronously accessible URLs are supported. */ -QUrl QScxmlStateMachineLoader::filename() +QUrl QScxmlStateMachineLoader::source() { - return m_filename; + return m_source; } -void QScxmlStateMachineLoader::setFilename(const QUrl &filename) +void QScxmlStateMachineLoader::setSource(const QUrl &source) { - if (!filename.isValid()) + if (!source.isValid()) return; - QUrl oldFilename = m_filename; + QUrl oldSource = m_source; if (m_stateMachine) { delete m_stateMachine; m_stateMachine = Q_NULLPTR; m_implicitDataModel = Q_NULLPTR; } - if (parse(filename)) { - m_filename = filename; - emit filenameChanged(); + if (parse(source)) { + m_source = source; + emit sourceChanged(); } else { - m_filename.clear(); - if (!oldFilename.isEmpty()) { - emit filenameChanged(); + m_source.clear(); + if (!oldSource.isEmpty()) { + emit sourceChanged(); } } } @@ -153,16 +153,17 @@ void QScxmlStateMachineLoader::setDataModel(QScxmlDataModel *dataModel) } } -bool QScxmlStateMachineLoader::parse(const QUrl &filename) +bool QScxmlStateMachineLoader::parse(const QUrl &source) { - if (!QQmlFile::isSynchronous(filename)) { - qmlInfo(this) << QStringLiteral("ERROR: cannot open '%1' for reading: only synchronous file access is supported.").arg(filename.fileName()); + if (!QQmlFile::isSynchronous(source)) { + qmlInfo(this) << QStringLiteral("ERROR: cannot open '%1' for reading: only synchronous access is supported.") + .arg(source.url()); return false; } - QQmlFile scxmlFile(QQmlEngine::contextForObject(this)->engine(), filename); + QQmlFile scxmlFile(QQmlEngine::contextForObject(this)->engine(), source); if (scxmlFile.isError()) { // the synchronous case can only fail when the file is not found (or not readable). - qmlInfo(this) << QStringLiteral("ERROR: cannot open '%1' for reading.").arg(filename.fileName()); + qmlInfo(this) << QStringLiteral("ERROR: cannot open '%1' for reading.").arg(source.url()); return false; } @@ -173,7 +174,7 @@ bool QScxmlStateMachineLoader::parse(const QUrl &filename) return false; } - m_stateMachine = QScxmlStateMachine::fromData(&buf, filename.toString()); + m_stateMachine = QScxmlStateMachine::fromData(&buf, source.toString()); m_stateMachine->setParent(this); m_implicitDataModel = m_stateMachine->dataModel(); @@ -188,7 +189,9 @@ bool QScxmlStateMachineLoader::parse(const QUrl &filename) QMetaObject::invokeMethod(m_stateMachine, "start", Qt::QueuedConnection); return true; } else { - qmlInfo(this) << QStringLiteral("Something went wrong while parsing '%1':").arg(filename.fileName()) << endl; + qmlInfo(this) << QStringLiteral("Something went wrong while parsing '%1':") + .arg(source.url()) + << endl; foreach (const QScxmlError &msg, m_stateMachine->parseErrors()) { qmlInfo(this) << msg.toString(); } diff --git a/src/imports/scxmlstatemachine/statemachineloader.h b/src/imports/scxmlstatemachine/statemachineloader.h index 0e73a50..30d774f 100644 --- a/src/imports/scxmlstatemachine/statemachineloader.h +++ b/src/imports/scxmlstatemachine/statemachineloader.h @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE class QScxmlStateMachineLoader: public QObject { Q_OBJECT - Q_PROPERTY(QUrl filename READ filename WRITE setFilename NOTIFY filenameChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QScxmlStateMachine* stateMachine READ stateMachine DESIGNABLE false NOTIFY stateMachineChanged) Q_PROPERTY(QVariantMap initialValues READ initialValues WRITE setInitialValues NOTIFY initialValuesChanged) Q_PROPERTY(QScxmlDataModel* dataModel READ dataModel WRITE setDataModel NOTIFY dataModelChanged) @@ -60,8 +60,8 @@ public: QScxmlStateMachine *stateMachine() const; - QUrl filename(); - void setFilename(const QUrl &filename); + QUrl source(); + void setSource(const QUrl &source); QVariantMap initialValues() const; void setInitialValues(const QVariantMap &initialValues); @@ -70,16 +70,16 @@ public: void setDataModel(QScxmlDataModel *dataModel); Q_SIGNALS: - void filenameChanged(); + void sourceChanged(); void initialValuesChanged(); void stateMachineChanged(); void dataModelChanged(); private: - bool parse(const QUrl &filename); + bool parse(const QUrl &source); private: - QUrl m_filename; + QUrl m_source; QVariantMap m_initialValues; QScxmlDataModel *m_dataModel; QScxmlDataModel *m_implicitDataModel; |