From 8dfe50a0a8841f944fd185c2015cfd922ff8c68c Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 20 Mar 2025 18:57:11 +0100 Subject: [PATCH] QmlDesigner: Support directory style qmldir files If no module entry is found, it is using the directory name. Change-Id: I7aca4216e66aec55e3cb0b9b0304ef72b78edf32 Reviewed-by: Thomas Hartmann --- .../projectstorage/projectstorageupdater.cpp | 10 ++++++++ .../projectstorageupdater-test.cpp | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.cpp b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.cpp index b3b64f77770..cfaff3d942a 100644 --- a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.cpp +++ b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.cpp @@ -401,6 +401,14 @@ bool isNotExisting(ProjectStorageUpdater::FileState state) return !isExisting(state); } +Utils::PathString directoryName(std::string_view directoryPath) +{ + using namespace std::views; + auto isNotSlash = std::bind_front(std::ranges::not_equal_to{}, '/'); + auto directoryName = directoryPath | reverse | take_while(isNotSlash) | reverse; + return {directoryName.begin(), directoryName.end()}; +} + } // namespace void ProjectStorageUpdater::updateDirectoryChanged(Utils::SmallStringView directoryPath, @@ -428,6 +436,8 @@ void ProjectStorageUpdater::updateDirectoryChanged(Utils::SmallStringView direct using Storage::ModuleKind; Utils::PathString moduleName{parser.typeNamespace()}; + if (moduleName.empty()) + moduleName = directoryName(directoryPath); ModuleId moduleId = m_projectStorage.moduleId(moduleName, ModuleKind::QmlLibrary); ModuleId cppModuleId = m_projectStorage.moduleId(moduleName, ModuleKind::CppLibrary); ModuleId pathModuleId = m_projectStorage.moduleId(directoryPath, ModuleKind::PathLibrary); diff --git a/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp b/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp index 8a306e45349..ed063b5291e 100644 --- a/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp +++ b/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp @@ -1066,6 +1066,31 @@ TEST_F(ProjectStorageUpdater, synchronize_qml_documents) updater.update({.qtDirectories = directories}); } +TEST_F(ProjectStorageUpdater, synchronize_qml_documents_with_missing_module_name) +{ + QString qmldir{R"(FirstType 1.0 First.qml + FirstType 2.2 First2.qml + SecondType 2.2 Second.qml)"}; + setContent(u"/path/qmldir", qmldir); + ModuleId directoryNameModuleId{storage.moduleId("path", ModuleKind::QmlLibrary)}; + + EXPECT_CALL(projectStorageMock, + synchronize(AllOf(Field( + &SynchronizationPackage::types, + Contains(AllOf(IsStorageType("First.qml", + ImportedType{"Object"}, + TypeTraitsKind::Reference, + qmlDocumentSourceId1, + ChangeLevel::Full), + Field("Type::exportedTypes", + &Type::exportedTypes, + UnorderedElementsAre( + IsExportedType(directoryNameModuleId, "FirstType", 1, 0), + IsExportedType(pathModuleId, "First", -1, -1))))))))); + + updater.update({.qtDirectories = directories}); +} + TEST_F(ProjectStorageUpdater, synchronize_qml_documents_in_project) { QString qmldir{R"(module Example