aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2022-05-16 15:44:12 +0200
committerMarco Bubke <marco.bubke@qt.io>2022-05-25 09:24:43 +0000
commit8b31c4a0ba2f9c4dfc0bdde413e70250946028a0 (patch)
treeb4151dc30bbb6a575804cc394f3f6ca5bafd9657
parentd3c9e3afc9e62de9a86b0733c19095b51f7ec3eb (diff)
QmlDesigner: Support optional imports in qmldir
optional import Foo Task-number: QDS-6945 Change-Id: Ib1136f4ffb3b7883bf50532dc7fd7cbd1fe04508 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
-rw-r--r--src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp3
-rw-r--r--tests/unit/unittest/projectstorageupdater-test.cpp42
2 files changed, 42 insertions, 3 deletions
diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp
index 1c130de81e..7fb1a140e0 100644
--- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp
+++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp
@@ -145,9 +145,6 @@ void addModuleExportedImports(Storage::ModuleExportedImports &imports,
ProjectStorageInterface &projectStorage)
{
for (const QmlDirParser::Import &qmldirImport : qmldirImports) {
- if (qmldirImport.flags & QmlDirParser::Import::Flag::Optional)
- continue;
-
ModuleId exportedModuleId = projectStorage.moduleId(Utils::PathString{qmldirImport.module});
imports.emplace_back(moduleId,
exportedModuleId,
diff --git a/tests/unit/unittest/projectstorageupdater-test.cpp b/tests/unit/unittest/projectstorageupdater-test.cpp
index e9ab6ea4d1..0f5b27dad7 100644
--- a/tests/unit/unittest/projectstorageupdater-test.cpp
+++ b/tests/unit/unittest/projectstorageupdater-test.cpp
@@ -1258,4 +1258,46 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmldirImportsWithDoubleEntries)
updater.update(qmlDirs, {});
}
+TEST_F(ProjectStorageUpdater, SynchronizeQmldirOptionalImports)
+{
+ QString qmldir{R"(module Example
+ import Qml auto
+ import QML 2.1
+ optional import Quick
+ )"};
+ ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir));
+
+ EXPECT_CALL(projectStorageMock,
+ synchronize(
+ AllOf(Field(&SynchronizationPackage::moduleExportedImports,
+ UnorderedElementsAre(ModuleExportedImport{exampleModuleId,
+ qmlModuleId,
+ Storage::Version{},
+ IsAutoVersion::Yes},
+ ModuleExportedImport{exampleCppNativeModuleId,
+ qmlCppNativeModuleId,
+ Storage::Version{},
+ IsAutoVersion::No},
+ ModuleExportedImport{exampleModuleId,
+ builtinModuleId,
+ Storage::Version{2, 1},
+ IsAutoVersion::No},
+ ModuleExportedImport{exampleCppNativeModuleId,
+ builtinCppNativeModuleId,
+ Storage::Version{},
+ IsAutoVersion::No},
+ ModuleExportedImport{exampleModuleId,
+ quickModuleId,
+ Storage::Version{},
+ IsAutoVersion::No},
+ ModuleExportedImport{exampleCppNativeModuleId,
+ quickCppNativeModuleId,
+ Storage::Version{},
+ IsAutoVersion::No})),
+ Field(&SynchronizationPackage::updatedModuleIds,
+ ElementsAre(exampleModuleId)))));
+
+ updater.update(qmlDirs, {});
+}
+
} // namespace