aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlimport.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-05-13 00:28:14 +0200
committerLiang Qi <liang.qi@qt.io>2016-05-13 08:28:27 +0200
commitae745746a666134d9e9258b8c2ff00540624d835 (patch)
tree8294fffa3d752d61f79004fb04e21e927472fd8f /src/qml/qml/qqmlimport.cpp
parenta7b383ab989e74ef552c2ef9c38377e065f1ab0e (diff)
parent531d00c1909527cb1bc28f17197267ccde408b0c (diff)
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts: src/qml/jsapi/qjsengine.cpp src/qml/qml/qqmlengine_p.h src/quick/items/qquickanchors.cpp src/quick/items/qquickanimatedimage_p_p.h src/quick/items/qquickitem_p.h tests/auto/qml/qqmlecmascript/testtypes.h tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp tests/benchmarks/qml/creation/tst_creation.cpp Change-Id: I65861e32f16e8a04c7090a90231627e1ebf6ba6f
Diffstat (limited to 'src/qml/qml/qqmlimport.cpp')
-rw-r--r--src/qml/qml/qqmlimport.cpp112
1 files changed, 73 insertions, 39 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index 5ce3942be2..69adce3da2 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -85,12 +85,11 @@ QString resolveLocalUrl(const QString &url, const QString &relative)
} else if (relative.at(0) == Slash || !url.contains(Slash)) {
return relative;
} else {
- QString base(url.left(url.lastIndexOf(Slash) + 1));
-
+ const QStringRef baseRef = url.leftRef(url.lastIndexOf(Slash) + 1);
if (relative == QLatin1String("."))
- return base;
+ return baseRef.toString();
- base.append(relative);
+ QString base = baseRef + relative;
// Remove any relative directory elements in the path
int length = base.length();
@@ -483,20 +482,58 @@ QList<QQmlImports::ScriptReference> QQmlImports::resolvedScripts() const
return scripts;
}
+static QString joinStringRefs(const QVector<QStringRef> &refs, const QChar &sep)
+{
+ QString str;
+ for (auto it = refs.cbegin(); it != refs.cend(); ++it) {
+ if (it != refs.cbegin())
+ str += sep;
+ str += *it;
+ }
+ return str;
+}
+
/*!
- Form a complete path to a qmldir file, from a base URL, a module URI and version specification.
+ Forms complete paths to a qmldir file, from a base URL, a module URI and version specification.
+
+ For example, QtQml.Models 2.0:
+ - base/QtQml/Models.2.0/qmldir
+ - base/QtQml.2.0/Models/qmldir
+ - base/QtQml/Models.2/qmldir
+ - base/QtQml.2/Models/qmldir
+ - base/QtQml/Models/qmldir
*/
-QString QQmlImports::completeQmldirPath(const QString &uri, const QString &base, int vmaj, int vmin,
- ImportVersion version)
+QStringList QQmlImports::completeQmldirPaths(const QString &uri, const QStringList &basePaths, int vmaj, int vmin)
{
- QString url = uri;
- url.replace(Dot, Slash);
+ const QVector<QStringRef> parts = uri.splitRef(Dot, QString::SkipEmptyParts);
+
+ QStringList qmlDirPathsPaths;
+ // fully & partially versioned parts + 1 unversioned for each base path
+ qmlDirPathsPaths.reserve(basePaths.count() * (2 * parts.count() + 1));
+
+ for (int version = FullyVersioned; version <= Unversioned; ++version) {
+ const QString ver = versionString(vmaj, vmin, static_cast<QQmlImports::ImportVersion>(version));
+
+ for (const QString &path : basePaths) {
+ QString dir = path;
+ if (!dir.endsWith(Slash) && !dir.endsWith(Backslash))
+ dir += Slash;
+
+ // append to the end
+ qmlDirPathsPaths += dir + joinStringRefs(parts, Slash) + ver + Slash_qmldir;
- QString dir = base;
- if (!dir.endsWith(Slash) && !dir.endsWith(Backslash))
- dir += Slash;
+ if (version != Unversioned) {
+ // insert in the middle
+ for (int index = parts.count() - 2; index >= 0; --index) {
+ qmlDirPathsPaths += dir + joinStringRefs(parts.mid(0, index + 1), Slash)
+ + ver + Slash
+ + joinStringRefs(parts.mid(index + 1), Slash) + Slash_qmldir;
+ }
+ }
+ }
+ }
- return dir + url + versionString(vmaj, vmin, version) + Slash_qmldir;
+ return qmlDirPathsPaths;
}
QString QQmlImports::versionString(int vmaj, int vmin, ImportVersion version)
@@ -777,11 +814,11 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS
QString u1 = import->url;
QString u2 = import2->url;
if (base) {
- QString b = *base;
+ QStringRef b(base);
int dot = b.lastIndexOf(Dot);
if (dot >= 0) {
b = b.left(dot+1);
- QString l = b.left(dot);
+ QStringRef l = b.left(dot);
if (u1.startsWith(b))
u1 = u1.mid(b.count());
else if (u1 == l)
@@ -857,7 +894,7 @@ bool QQmlImportsPrivate::populatePluginPairVector(QVector<StaticPluginPair> &res
// the list the first time called to only contain QML plugins:
foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) {
if (qobject_cast<QQmlExtensionPlugin *>(plugin.instance()))
- plugins.append(plugin);
+ plugins.append(plugin);
}
}
@@ -1130,32 +1167,29 @@ bool QQmlImportsPrivate::locateQmldir(const QString &uri, int vmaj, int vmin, QQ
QStringList localImportPaths = database->importPathList(QQmlImportDatabase::Local);
// Search local import paths for a matching version
- for (int version = QQmlImports::FullyVersioned; version <= QQmlImports::Unversioned; ++version) {
- foreach (const QString &path, localImportPaths) {
- QString qmldirPath = QQmlImports::completeQmldirPath(uri, path, vmaj, vmin, static_cast<QQmlImports::ImportVersion>(version));
-
- QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath);
- if (!absoluteFilePath.isEmpty()) {
- QString url;
- QString absolutePath = absoluteFilePath.left(absoluteFilePath.lastIndexOf(Slash)+1);
- if (absolutePath.at(0) == Colon)
- url = QLatin1String("qrc://") + absolutePath.mid(1);
- else
- url = QUrl::fromLocalFile(absolutePath).toString();
+ const QStringList qmlDirPaths = QQmlImports::completeQmldirPaths(uri, localImportPaths, vmaj, vmin);
+ for (const QString &qmldirPath : qmlDirPaths) {
+ QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath);
+ if (!absoluteFilePath.isEmpty()) {
+ QString url;
+ const QStringRef absolutePath = absoluteFilePath.leftRef(absoluteFilePath.lastIndexOf(Slash) + 1);
+ if (absolutePath.at(0) == Colon)
+ url = QLatin1String("qrc://") + absolutePath.mid(1);
+ else
+ url = QUrl::fromLocalFile(absolutePath.toString()).toString();
- QQmlImportDatabase::QmldirCache *cache = new QQmlImportDatabase::QmldirCache;
- cache->versionMajor = vmaj;
- cache->versionMinor = vmin;
- cache->qmldirFilePath = absoluteFilePath;
- cache->qmldirPathUrl = url;
- cache->next = cacheHead;
- database->qmldirCache.insert(uri, cache);
+ QQmlImportDatabase::QmldirCache *cache = new QQmlImportDatabase::QmldirCache;
+ cache->versionMajor = vmaj;
+ cache->versionMinor = vmin;
+ cache->qmldirFilePath = absoluteFilePath;
+ cache->qmldirPathUrl = url;
+ cache->next = cacheHead;
+ database->qmldirCache.insert(uri, cache);
- *outQmldirFilePath = absoluteFilePath;
- *outQmldirPathUrl = url;
+ *outQmldirFilePath = absoluteFilePath;
+ *outQmldirPathUrl = url;
- return true;
- }
+ return true;
}
}