diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-22 18:10:23 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-29 15:51:16 +0200 |
commit | d8513d338d8537506984a13bf1f4ef6507678286 (patch) | |
tree | 087b524a17c38a9bfa44849e3c8e45fdeba3423b /src/qml/qml/qqmlmetatype.cpp | |
parent | bd1c28a82c2ff955e0d154fac2e2df8d5a110dd7 (diff) |
Match specific module imports also for versionless QML imports
Previously, if you registered a module import for a specific version X
of a module, and the user imported the module without specifying a
version, the module import would not be carried out even if X was the
version actually imported.
Change-Id: I853ed6f275501cf4cbd4e5a360985e67b07f3773
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 77d3571a05..e3b93c4c61 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -920,13 +920,20 @@ QRecursiveMutex *QQmlMetaType::typeRegistrationLock() } /* - Returns true if a module \a uri of any version is installed. + Returns the latest version of \a uri installed, or an in valid QTypeRevision(). */ -bool QQmlMetaType::isAnyModule(const QString &uri) +QTypeRevision QQmlMetaType::latestModuleVersion(const QString &uri) { QQmlMetaTypeDataPtr data; - return std::binary_search(data->uriToModule.begin(), data->uriToModule.end(), uri, - std::less<ModuleUri>()); + auto upper = std::upper_bound(data->uriToModule.begin(), data->uriToModule.end(), uri, + std::less<ModuleUri>()); + if (upper == data->uriToModule.begin()) + return QTypeRevision(); + + const auto module = (--upper)->get(); + return (module->module() == uri) + ? QTypeRevision::fromVersion(module->majorVersion(), module->maximumMinorVersion()) + : QTypeRevision(); } /* @@ -942,27 +949,31 @@ bool QQmlMetaType::isLockedModule(const QString &uri, QTypeRevision version) } /* - Returns true if any type or API has been registered for the given \a module with at least - versionMajor.versionMinor, or if types have been registered for \a module with at most - versionMajor.versionMinor. - - So if only 4.7 and 4.9 have been registered, 4.7,4.8, and 4.9 are valid, but not 4.6 nor 4.10. + Returns the best matching registered version for the given \a module. If \a version is + the does not have a major version, returns the latest registered version. Otherwise + chooses the same major version and checks if the minor version is within the range + of registered minor versions. If so, retuens the original version, otherwise returns + an invalid version. If \a version does not have a minor version, chooses the latest one. */ -bool QQmlMetaType::isModule(const QString &module, QTypeRevision version) +QTypeRevision QQmlMetaType::matchingModuleVersion(const QString &module, QTypeRevision version) { if (!version.hasMajorVersion()) - return isAnyModule(module); + return latestModuleVersion(module); QQmlMetaTypeDataPtr data; // first, check Types if (QQmlTypeModule *tm = data->findTypeModule(module, version)) { - return !version.hasMinorVersion() - || (tm->minimumMinorVersion() <= version.minorVersion() - && tm->maximumMinorVersion() >= version.minorVersion()); + if (!version.hasMinorVersion()) + return QTypeRevision::fromVersion(version.majorVersion(), tm->maximumMinorVersion()); + + if (tm->minimumMinorVersion() <= version.minorVersion() + && tm->maximumMinorVersion() >= version.minorVersion()) { + return version; + } } - return false; + return QTypeRevision(); } QQmlTypeModule *QQmlMetaType::typeModule(const QString &uri, QTypeRevision version) |