summaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/imports.pro3
-rw-r--r--src/imports/scxmlstatemachine/plugin.cpp (renamed from src/imports/plugin.cpp)0
-rw-r--r--src/imports/scxmlstatemachine/qmldir (renamed from src/imports/qmldir)0
-rw-r--r--src/imports/scxmlstatemachine/scxmlstatemachine.pro (renamed from src/imports/qml-module.pro)0
-rw-r--r--src/imports/scxmlstatemachine/signalevent.cpp (renamed from src/imports/signalevent.cpp)0
-rw-r--r--src/imports/scxmlstatemachine/signalevent.h (renamed from src/imports/signalevent.h)0
-rw-r--r--src/imports/scxmlstatemachine/state.cpp (renamed from src/imports/state.cpp)0
-rw-r--r--src/imports/scxmlstatemachine/state.h (renamed from src/imports/state.h)0
-rw-r--r--src/imports/scxmlstatemachine/statemachine.cpp (renamed from src/imports/statemachine.cpp)30
-rw-r--r--src/imports/scxmlstatemachine/statemachine.h (renamed from src/imports/statemachine.h)11
10 files changed, 28 insertions, 16 deletions
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
new file mode 100644
index 0000000..60a0bd2
--- /dev/null
+++ b/src/imports/imports.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+SUBDIRS = scxmlstatemachine
+
diff --git a/src/imports/plugin.cpp b/src/imports/scxmlstatemachine/plugin.cpp
index 9b2f4d4..9b2f4d4 100644
--- a/src/imports/plugin.cpp
+++ b/src/imports/scxmlstatemachine/plugin.cpp
diff --git a/src/imports/qmldir b/src/imports/scxmlstatemachine/qmldir
index a411f70..a411f70 100644
--- a/src/imports/qmldir
+++ b/src/imports/scxmlstatemachine/qmldir
diff --git a/src/imports/qml-module.pro b/src/imports/scxmlstatemachine/scxmlstatemachine.pro
index 4cbf853..4cbf853 100644
--- a/src/imports/qml-module.pro
+++ b/src/imports/scxmlstatemachine/scxmlstatemachine.pro
diff --git a/src/imports/signalevent.cpp b/src/imports/scxmlstatemachine/signalevent.cpp
index a9c3739..a9c3739 100644
--- a/src/imports/signalevent.cpp
+++ b/src/imports/scxmlstatemachine/signalevent.cpp
diff --git a/src/imports/signalevent.h b/src/imports/scxmlstatemachine/signalevent.h
index 473fc35..473fc35 100644
--- a/src/imports/signalevent.h
+++ b/src/imports/scxmlstatemachine/signalevent.h
diff --git a/src/imports/state.cpp b/src/imports/scxmlstatemachine/state.cpp
index da240b4..da240b4 100644
--- a/src/imports/state.cpp
+++ b/src/imports/scxmlstatemachine/state.cpp
diff --git a/src/imports/state.h b/src/imports/scxmlstatemachine/state.h
index 53c3e37..53c3e37 100644
--- a/src/imports/state.h
+++ b/src/imports/scxmlstatemachine/state.h
diff --git a/src/imports/statemachine.cpp b/src/imports/scxmlstatemachine/statemachine.cpp
index 2adec4c..c953018 100644
--- a/src/imports/statemachine.cpp
+++ b/src/imports/scxmlstatemachine/statemachine.cpp
@@ -26,7 +26,8 @@
#include <QQmlContext>
#include <QQmlEngine>
#include <QQmlInfo>
-#include <QFile>
+#include <QQmlFile>
+#include <QBuffer>
static void append(QQmlListProperty<QObject> *prop, QObject *o)
{
@@ -101,14 +102,14 @@ void StateMachine::setStateMachine(Scxml::StateTable *table)
}
}
-QString StateMachine::filename()
+QUrl StateMachine::filename()
{
return m_filename;
}
-void StateMachine::setFilename(const QString filename)
+void StateMachine::setFilename(const QUrl &filename)
{
- QString oldFilename = m_filename;
+ QUrl oldFilename = m_filename;
if (m_table) {
delete m_table;
m_table = nullptr;
@@ -125,22 +126,29 @@ void StateMachine::setFilename(const QString filename)
}
}
-bool StateMachine::parse(const QString &filename)
+bool StateMachine::parse(const QUrl &filename)
{
- QFile scxmlFile(filename);
- if (!scxmlFile.open(QIODevice::ReadOnly)) {
- qmlInfo(this) << QStringLiteral("ERROR: cannot open '%1' for reading!").arg(filename);
+ if (!QQmlFile::isSynchronous(filename)) {
+ qmlInfo(this) << QStringLiteral("ERROR: cannot open '%1' for reading: only synchronous file access is supported.").arg(filename.fileName());
+ return false;
+ }
+ QQmlFile scxmlFile(QQmlEngine::contextForObject(this)->engine(), filename);
+ 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());
return false;
}
- QXmlStreamReader xmlReader(&scxmlFile);
+ QByteArray data(scxmlFile.dataByteArray());
+ QBuffer buf(&data);
+ Q_ASSERT(buf.open(QIODevice::ReadOnly));
+ QXmlStreamReader xmlReader(&buf);
Scxml::ScxmlParser parser(&xmlReader);
parser.parse();
- scxmlFile.close();
setStateMachine(parser.table());
if (parser.state() != Scxml::ScxmlParser::FinishedParsing || m_table == nullptr) {
- qmlInfo(this) << QStringLiteral("Something went wrong while parsing '%1':").arg(filename) << endl;
+ qmlInfo(this) << QStringLiteral("Something went wrong while parsing '%1':").arg(filename.fileName()) << endl;
foreach (const Scxml::ErrorMessage &msg, parser.errors()) {
qmlInfo(this) << msg.fileName << QStringLiteral(":") << msg.line
<< QStringLiteral(":") << msg.column
diff --git a/src/imports/statemachine.h b/src/imports/scxmlstatemachine/statemachine.h
index a192a32..554e25d 100644
--- a/src/imports/statemachine.h
+++ b/src/imports/scxmlstatemachine/statemachine.h
@@ -19,6 +19,7 @@
#ifndef STATEMACHINE_H
#define STATEMACHINE_H
+#include <QUrl>
#include <QVector>
#include <QQmlParserStatus>
#include <QQmlListProperty>
@@ -33,7 +34,7 @@ class StateMachine: public QObject, public QQmlParserStatus
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QQmlListProperty<QObject> states READ states NOTIFY statesChanged DESIGNABLE false)
- Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged)
+ Q_PROPERTY(QUrl filename READ filename WRITE setFilename NOTIFY filenameChanged)
Q_PROPERTY(Scxml::StateTable* stateMachine READ stateMachine WRITE setStateMachine)
Q_CLASSINFO("DefaultProperty", "states")
@@ -49,18 +50,18 @@ public:
Scxml::StateTable *stateMachine() const;
void setStateMachine(Scxml::StateTable *stateMachine);
- QString filename();
- void setFilename(const QString filename);
+ QUrl filename();
+ void setFilename(const QUrl &filename);
Q_SIGNALS:
void statesChanged();
void filenameChanged();
private:
- bool parse(const QString &filename);
+ bool parse(const QUrl &filename);
private:
- QString m_filename;
+ QUrl m_filename;
Kids m_children;
Scxml::StateTable *m_table = nullptr;
};