diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2009-05-19 07:39:44 (GMT) |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2009-05-19 07:39:44 (GMT) |
commit | 2d8a925309d2b5bfbff19df8bf607ccf3a343930 (patch) | |
tree | ebcba69f2b179793f78ad15450a0ab1cc32b448a /src | |
parent | 38a978121bef0efd1f6fd573c4289e40352b63a6 (diff) | |
download | Qt-2d8a925309d2b5bfbff19df8bf607ccf3a343930.zip Qt-2d8a925309d2b5bfbff19df8bf607ccf3a343930.tar.gz Qt-2d8a925309d2b5bfbff19df8bf607ccf3a343930.tar.bz2 |
Added QmlEngine::componentSearchPath()
componentSearchPath() returns the list of urls (folders) inspected
by qml to locate sub components. This is used in Bauhaus.
Autotests have been stored in new "declarative/qmlengine" directory.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 29 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.h | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 0209c1d..425cba4 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -615,6 +615,35 @@ QUrl QmlEngine::componentUrl(const QUrl& src, const QUrl& baseUrl) const } /*! + Returns the list of base urls the engine browses to find sub-components. + + The search path consists of the base of the \a url, and, in the case of local files, + the directories imported using the "import" statement in \a qml. + */ +QList<QUrl> QmlEngine::componentSearchPath(const QByteArray &qml, const QUrl &url) const +{ + QList<QUrl> searchPath; + + searchPath << url.resolved(QUrl(QLatin1String("."))); + + if (QFileInfo(url.toLocalFile()).exists()) { + QmlScriptParser parser; + if (parser.parse(qml, url)) { + for (int i = 0; i < parser.imports().size(); ++i) { + QUrl importUrl = QUrl(parser.imports().at(i).uri); + if (importUrl.isRelative()) { + searchPath << url.resolved(importUrl); + } else { + searchPath << importUrl; + } + } + } + } + + return searchPath; +} + +/*! Sets the common QNetworkAccessManager, \a network, used by all QML elements instantiated by this engine. diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index fde84d4..9382389 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -78,6 +78,8 @@ public: QMap<QString,QString> nameSpacePaths() const; QUrl componentUrl(const QUrl& src, const QUrl& baseUrl) const; + QList<QUrl> componentSearchPath(const QByteArray &qml, const QUrl &url) const; + void setNetworkAccessManager(QNetworkAccessManager *); QNetworkAccessManager *networkAccessManager() const; |