diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-07-13 15:34:05 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-17 03:52:04 +0200 |
commit | 20cecd7b003f27485789e93b4c2b6f5f734e5bea (patch) | |
tree | 2dd4a623ac459176d6c541eff8c5217dcaaa1f5b /src/qml/qml/qqmlimport.cpp | |
parent | d6bd6cd323f91b9cb01d94c560cf8b40dafeb790 (diff) |
Select appropriate version for located module components
When a located module is imported with a version specifier, ensure that
the components resolved from that module use the appropriate version.
Task-number: QTBUG-26473
Change-Id: I33209ddef3fe9bb0ab9d096dfe19aff233744afc
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlimport.cpp')
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 00ea8c5d26..55c07ac35a 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -508,41 +508,43 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader, } } - bool typeWasDeclaredInQmldir = false; - if (!qmlDirComponents.isEmpty()) { - QQmlDirComponents::ConstIterator it = qmlDirComponents.find(type); - if (it != qmlDirComponents.end()) { - typeWasDeclaredInQmldir = true; - // first found is last inserted - process in reverse - QQmlDirComponents::ConstIterator begin = it; - while (++it != qmlDirComponents.end() && it.key() == type) {} - do { - --it; - const QQmlDirParser::Component &c = *it; - - // importing version -1 means import ALL versions - if ((majversion == -1) || (c.majorVersion == majversion && - minversion >= c.minorVersion)) { - - QString candidate = resolveLocalUrl(QString(url + c.typeName + dotqml_string), c.fileName); + QQmlDirComponents::ConstIterator it = qmlDirComponents.find(type), end = qmlDirComponents.end(); + if (it != end) { + QString componentUrl; + QQmlDirComponents::ConstIterator candidate = end; + for ( ; it != end && it.key() == type; ++it) { + const QQmlDirParser::Component &c = *it; + + // importing version -1 means import ALL versions + if ((majversion == -1) || + (c.majorVersion == majversion && c.minorVersion <= minversion)) { + // Is this better than the previous candidate? + if ((candidate == end) || + (c.majorVersion > candidate->majorVersion) || + ((c.majorVersion == candidate->majorVersion) && (c.minorVersion > candidate->minorVersion))) { + componentUrl = resolveLocalUrl(QString(url + c.typeName + dotqml_string), c.fileName); if (c.internal && base) { - if (resolveLocalUrl(*base, c.fileName) != candidate) + if (resolveLocalUrl(*base, c.fileName) != componentUrl) continue; // failed attempt to access an internal type } - if (base && *base == candidate) { + if (base && (*base == componentUrl)) { if (typeRecursionDetected) *typeRecursionDetected = true; continue; // no recursion } - if (url_return) - *url_return = candidate; - return true; + + // This is our best candidate so far + candidate = it; } - } while (it != begin); + } } - } - if (!typeWasDeclaredInQmldir && !isLibrary) { + if (candidate != end) { + if (url_return) + *url_return = componentUrl; + return true; + } + } else if (!isLibrary) { QString qmlUrl = url + QString::fromRawData(type.constData(), type.length()) + dotqml_string; bool exists = false; @@ -554,7 +556,7 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader, } if (exists) { - if (base && *base == qmlUrl) { // no recursion + if (base && (*base == qmlUrl)) { // no recursion if (typeRecursionDetected) *typeRecursionDetected = true; } else { |