diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2017-12-19 15:48:23 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2018-02-08 11:03:23 +0000 |
commit | b2739825454ba7585170d15c83de729b0af6c29a (patch) | |
tree | 68faa8db84e9002fdaba7a0dbd5a019be8962d6e /src/imports | |
parent | 8419ff45d4f99e585119fa77a1066d4ddaee827c (diff) |
Make XmlListModel work without qml-network
We can still load local files then. In fact we load all local files
without network requests now, as that is faster anyway. That means the
"progress" for local files is 1.0 right from the start as no real
loading takes place, and also no headers are sent.
Change-Id: I43f0d5179f8dd09bfdb5c6b3a51a6033226ea59c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/xmllistmodel/qqmlxmllistmodel.cpp | 32 | ||||
-rw-r--r-- | src/imports/xmllistmodel/qqmlxmllistmodel_p.h | 2 | ||||
-rw-r--r-- | src/imports/xmllistmodel/xmllistmodel.pro | 3 |
3 files changed, 35 insertions, 2 deletions
diff --git a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp index d14810a01b..d794118737 100644 --- a/src/imports/xmllistmodel/qqmlxmllistmodel.cpp +++ b/src/imports/xmllistmodel/qqmlxmllistmodel.cpp @@ -54,8 +54,10 @@ #include <QXmlResultItems> #include <QXmlNodeModelIndex> #include <QBuffer> +#if QT_CONFIG(qml_network) #include <QNetworkRequest> #include <QNetworkReply> +#endif #include <QTimer> #include <QMutex> @@ -542,7 +544,10 @@ class QQuickXmlListModelPrivate : public QAbstractItemModelPrivate public: QQuickXmlListModelPrivate() : isComponentComplete(true), size(0), highestRole(Qt::UserRole) - , reply(0), status(QQuickXmlListModel::Null), progress(0.0) +#if QT_CONFIG(qml_network) + , reply(0) +#endif + , status(QQuickXmlListModel::Null), progress(0.0) , queryId(-1), roleObjects(), redirectCount(0) {} @@ -555,6 +560,7 @@ public: emit q->statusChanged(status); } +#if QT_CONFIG(qml_network) void deleteReply() { Q_Q(QQuickXmlListModel); if (reply) { @@ -563,6 +569,7 @@ public: reply = 0; } } +#endif bool isComponentComplete; QUrl src; @@ -574,7 +581,9 @@ public: QStringList roleNames; int highestRole; +#if QT_CONFIG(qml_network) QNetworkReply *reply; +#endif QQuickXmlListModel::Status status; QString errorString; qreal progress; @@ -1036,10 +1045,12 @@ void QQuickXmlListModel::reload() if (d->size < 0) d->size = 0; +#if QT_CONFIG(qml_network) if (d->reply) { d->reply->abort(); d->deleteReply(); } +#endif if (!d->xml.isEmpty()) { d->queryId = QQuickXmlQueryEngine::instance(qmlEngine(this))->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects, d->keyRoleResultsCache); @@ -1050,7 +1061,19 @@ void QQuickXmlListModel::reload() d->notifyQueryStarted(false); QTimer::singleShot(0, this, SLOT(dataCleared())); + } else if (QQmlFile::isLocalFile(d->src)) { + QFile file(QQmlFile::urlToLocalFileOrQrc(d->src)); + QByteArray data = file.open(QIODevice::ReadOnly) ? file.readAll() : QByteArray(); + d->notifyQueryStarted(false); + if (data.isEmpty()) { + d->queryId = XMLLISTMODEL_CLEAR_ID; + QTimer::singleShot(0, this, SLOT(dataCleared())); + } else { + d->queryId = QQuickXmlQueryEngine::instance(qmlEngine(this))->doQuery( + d->query, d->namespaces, data, &d->roleObjects, d->keyRoleResultsCache); + } } else { +#if QT_CONFIG(qml_network) d->notifyQueryStarted(true); QNetworkRequest req(d->src); req.setRawHeader("Accept", "application/xml,*/*"); @@ -1058,11 +1081,17 @@ void QQuickXmlListModel::reload() QObject::connect(d->reply, SIGNAL(finished()), this, SLOT(requestFinished())); QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(requestProgress(qint64,qint64))); +#else + d->queryId = XMLLISTMODEL_CLEAR_ID; + d->notifyQueryStarted(false); + QTimer::singleShot(0, this, SLOT(dataCleared())); +#endif } } #define XMLLISTMODEL_MAX_REDIRECT 16 +#if QT_CONFIG(qml_network) void QQuickXmlListModel::requestFinished() { Q_D(QQuickXmlListModel); @@ -1108,6 +1137,7 @@ void QQuickXmlListModel::requestFinished() emit progressChanged(d->progress); } } +#endif void QQuickXmlListModel::requestProgress(qint64 received, qint64 total) { diff --git a/src/imports/xmllistmodel/qqmlxmllistmodel_p.h b/src/imports/xmllistmodel/qqmlxmllistmodel_p.h index e6a0898bb9..65f1299324 100644 --- a/src/imports/xmllistmodel/qqmlxmllistmodel_p.h +++ b/src/imports/xmllistmodel/qqmlxmllistmodel_p.h @@ -144,7 +144,9 @@ public Q_SLOTS: void reload(); private Q_SLOTS: +#if QT_CONFIG(qml_network) void requestFinished(); +#endif void requestProgress(qint64,qint64); void dataCleared(); void queryCompleted(const QQuickXmlQueryResult &); diff --git a/src/imports/xmllistmodel/xmllistmodel.pro b/src/imports/xmllistmodel/xmllistmodel.pro index 2308f26d1b..002b30d41c 100644 --- a/src/imports/xmllistmodel/xmllistmodel.pro +++ b/src/imports/xmllistmodel/xmllistmodel.pro @@ -3,7 +3,8 @@ TARGET = qmlxmllistmodelplugin TARGETPATH = QtQuick/XmlListModel IMPORT_VERSION = 2.0 -QT = network xmlpatterns qml-private core-private +QT = xmlpatterns qml-private core-private +qtConfig(qml-network): QT += network SOURCES += qqmlxmllistmodel.cpp plugin.cpp HEADERS += qqmlxmllistmodel_p.h |