diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-10 16:25:16 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-10 17:48:01 +0200 |
commit | 31ee1bc904e4fc565f7198b47fcf7305e4f4d5d7 (patch) | |
tree | 8bc50b39cf5d1eb9e5f8c4e0960985a8b58114bb /src/qml/qml/qqmlimport.cpp | |
parent | facf085fbcf614a25c6cfdff39ad80a46180a322 (diff) |
Deduplicate the import resolution algorithm
We will need it in various other places, too.
Change-Id: I61c55f88b66ab85448ae8fff125fe34108532fc4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlimport.cpp')
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 58 |
1 files changed, 5 insertions, 53 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index fec42827b6..a6a230090e 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -59,6 +59,7 @@ #include <QtCore/qjsonobject.h> #include <QtCore/qjsonarray.h> #include <QtQml/private/qqmltype_p_p.h> +#include <QtQml/private/qqmlimportresolver_p.h> #include <algorithm> #include <functional> @@ -536,17 +537,6 @@ 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; -} - /*! Forms complete paths to a qmldir file, from a base URL, a module URI and version specification. @@ -560,48 +550,10 @@ static QString joinStringRefs(const QVector<QStringRef> &refs, const QChar &sep) QStringList QQmlImports::completeQmldirPaths(const QString &uri, const QStringList &basePaths, QTypeRevision version) { - const QVector<QStringRef> parts = uri.splitRef(Dot, Qt::SkipEmptyParts); - - QStringList qmlDirPathsPaths; - // fully & partially versioned parts + 1 unversioned for each base path - qmlDirPathsPaths.reserve(basePaths.count() * (2 * parts.count() + 1)); - - for (int versionMode = FullyVersioned; versionMode <= Unversioned; ++versionMode) { - switch (versionMode) { - case FullyVersioned: - if (!version.hasMinorVersion()) - continue; - break; - case PartiallyVersioned: - if (!version.hasMajorVersion()) - continue; - break; - default: - break; - } - - const QString ver = versionString(version, QQmlImports::ImportVersion(versionMode)); - - 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; - - if (versionMode != 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 qmlDirPathsPaths; + QStringList paths = qQmlResolveImportPaths(uri, basePaths, version); + for (QString &path : paths) + path += Slash_qmldir; + return paths; } QString QQmlImports::versionString(QTypeRevision version, ImportVersion versionMode) |