aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlimport.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-01-27 17:31:06 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-03-17 14:44:17 +0100
commit1eb20d70619cc896fc283bd6605b257a8750c518 (patch)
tree1d308932d38759a643d8eef49b211329a2cd5467 /src/qml/qml/qqmlimport.cpp
parente3c64aff6579f04353608d4b218f031d9137d3f4 (diff)
Allow partial and absent version specifiers in import statements
An import statement without version specifier imports the latest version available, one with only a major version imports the latest minor version from that major version. Task-number: QTBUG-71278 Change-Id: I43907ae4e1052be533039d545de5391c41d38307 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlimport.cpp')
-rw-r--r--src/qml/qml/qqmlimport.cpp46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index 47f7b40938..7f8728f364 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -548,6 +548,19 @@ QStringList QQmlImports::completeQmldirPaths(const QString &uri, const QStringLi
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) {
@@ -711,15 +724,13 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedSt
QQmlImport::RecursionRestriction recursionRestriction,
QList<QQmlError> *errors) const
{
- if (version.hasMajorVersion() && version.hasMinorVersion()) {
- QQmlType t = QQmlMetaType::qmlType(type, uri, version);
- if (t.isValid()) {
- if (version_return)
- *version_return = version;
- if (type_return)
- *type_return = t;
- return true;
- }
+ QQmlType t = QQmlMetaType::qmlType(type, uri, version);
+ if (t.isValid()) {
+ if (version_return)
+ *version_return = version;
+ if (type_return)
+ *type_return = t;
+ return true;
}
const QString typeStr = type.toString();
@@ -1350,9 +1361,6 @@ QQmlImports::LocalQmldirResult QQmlImportsPrivate::locateLocalQmldir(
const QString &uri, QTypeRevision version, QQmlImportDatabase *database,
QString *outQmldirFilePath, QString *outQmldirPathUrl)
{
- // Versions are always specified for libraries
- Q_ASSERT(version.hasMajorVersion() && version.hasMinorVersion());
-
// Check cache first
QQmlImportDatabase::QmldirCache *cacheHead = nullptr;
@@ -1565,15 +1573,19 @@ bool QQmlImportsPrivate::addLibraryImport(
}
// Ensure that we are actually providing something
- if (!version.hasMajorVersion() || !version.hasMinorVersion()
- || !QQmlMetaType::isModule(uri, version)) {
+ if (!QQmlMetaType::isModule(uri, version)) {
if (inserted->qmlDirComponents.isEmpty() && inserted->qmlDirScripts.isEmpty()) {
QQmlError error;
if (QQmlMetaType::isAnyModule(uri)) {
- error.setDescription(QQmlImportDatabase::tr("module \"%1\" version %2.%3 is not installed")
- .arg(uri).arg(version.majorVersion()).arg(version.minorVersion()));
+ error.setDescription(QQmlImportDatabase::tr(
+ "module \"%1\" version %2.%3 is not installed")
+ .arg(uri).arg(version.majorVersion())
+ .arg(version.hasMinorVersion()
+ ? QString::number(version.minorVersion())
+ : QLatin1String("x")));
} else {
- error.setDescription(QQmlImportDatabase::tr("module \"%1\" is not installed").arg(uri));
+ error.setDescription(QQmlImportDatabase::tr("module \"%1\" is not installed")
+ .arg(uri));
}
errors->prepend(error);
return false;