From e64f3c270346bda5ab2e31a20f6348e9f7117899 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 1 Oct 2024 17:17:31 +0200 Subject: [PATCH] QmlDesigner: Improve support for project storage aliases Change-Id: I074aa01e2fc68dea01bece63d13e2688eadbea67 Reviewed-by: Thomas Hartmann --- .../qmldesigner/libs/designercore/CMakeLists.txt | 5 +++++ .../qmldesigner/libs/designercore/include/modelfwd.h | 3 ++- .../libs/designercore/projectstorage/filesystem.h | 7 ++++--- .../projectstorage/projectstorageinterface.h | 2 +- .../projectstorage/projectstorageupdater.h | 6 ++---- .../designercore/projectstorage/qmldocumentparser.cpp | 6 +++--- .../designercore/projectstorage/qmldocumentparser.h | 10 ++++------ src/plugins/qmldesigner/qmldesignerprojectmanager.cpp | 8 ++++---- tests/unit/tests/unittests/model/model-test.cpp | 2 +- 9 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/plugins/qmldesigner/libs/designercore/CMakeLists.txt b/src/plugins/qmldesigner/libs/designercore/CMakeLists.txt index 977bced8f23..1ebb8c48322 100644 --- a/src/plugins/qmldesigner/libs/designercore/CMakeLists.txt +++ b/src/plugins/qmldesigner/libs/designercore/CMakeLists.txt @@ -375,6 +375,11 @@ extend_qtc_library(QmlDesignerCore DEFINES QML_DOM_MSVC2019_COMPAT ) +extend_qtc_library(QmlDesignerCore + CONDITION WITH_TESTS + PUBLIC_DEFINES QDS_MODEL_USE_PROJECTSTORAGEINTERFACE +) + extend_qtc_library(QmlDesignerCore SOURCES_PREFIX projectstorage PUBLIC_INCLUDES projectstorage diff --git a/src/plugins/qmldesigner/libs/designercore/include/modelfwd.h b/src/plugins/qmldesigner/libs/designercore/include/modelfwd.h index 7cbfdba616a..a58e91a838c 100644 --- a/src/plugins/qmldesigner/libs/designercore/include/modelfwd.h +++ b/src/plugins/qmldesigner/libs/designercore/include/modelfwd.h @@ -39,6 +39,8 @@ constexpr bool useProjectStorage() return false; #endif } +class SourcePathStorage; +using PathCache = SourcePathCache; #ifdef QDS_MODEL_USE_PROJECTSTORAGEINTERFACE using ProjectStorageType = ProjectStorageInterface; @@ -46,7 +48,6 @@ class SourcePathCacheInterface; using PathCacheType = SourcePathCacheInterface; #else using ProjectStorageType = ProjectStorage; -class SourcePathStorage; using PathCacheType = SourcePathCache; #endif diff --git a/src/plugins/qmldesigner/libs/designercore/projectstorage/filesystem.h b/src/plugins/qmldesigner/libs/designercore/projectstorage/filesystem.h index 8e83cd2ff04..ae58b229d82 100644 --- a/src/plugins/qmldesigner/libs/designercore/projectstorage/filesystem.h +++ b/src/plugins/qmldesigner/libs/designercore/projectstorage/filesystem.h @@ -7,6 +7,8 @@ #include "filesysteminterface.h" #include "sourcepathstorage/nonlockingmutex.h" +#include + namespace QmlDesigner { class SourcePathStorage; @@ -16,10 +18,9 @@ class SourcePathCache; class QMLDESIGNERCORE_EXPORT FileSystem : public FileSystemInterface { - using PathCache = SourcePathCache; public: - FileSystem(PathCache &sourcePathCache) + FileSystem(PathCacheType &sourcePathCache) : m_sourcePathCache(sourcePathCache) {} @@ -33,7 +34,7 @@ public: void remove(const SourceIds &sourceIds) override; private: - PathCache &m_sourcePathCache; + PathCacheType &m_sourcePathCache; }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageinterface.h b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageinterface.h index 69674ffc8bf..9cf0daf4e8c 100644 --- a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageinterface.h +++ b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageinterface.h @@ -17,7 +17,7 @@ namespace QmlDesigner { class ProjectStorageInterface { - friend Storage::Info::CommonTypeCache; + friend Storage::Info::CommonTypeCache; public: ProjectStorageInterface(const ProjectStorageInterface &) = delete; diff --git a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.h b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.h index 344b0543a27..6c3353ff68a 100644 --- a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.h +++ b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageupdater.h @@ -41,12 +41,10 @@ class QMLDESIGNERCORE_EXPORT ProjectStorageUpdater final : public ProjectStoragePathWatcherNotifierInterface { public: - using PathCache = SourcePathCache; - ProjectStorageUpdater(FileSystemInterface &fileSystem, ProjectStorageType &projectStorage, FileStatusCache &fileStatusCache, - PathCache &pathCache, + PathCacheType &pathCache, QmlDocumentParserInterface &qmlDocumentParser, QmlTypesParserInterface &qmlTypesParser, class ProjectStoragePathWatcherInterface &pathWatcher, @@ -243,7 +241,7 @@ private: FileSystemInterface &m_fileSystem; ProjectStorageType &m_projectStorage; FileStatusCache &m_fileStatusCache; - PathCache &m_pathCache; + PathCacheType &m_pathCache; QmlDocumentParserInterface &m_qmlDocumentParser; QmlTypesParserInterface &m_qmlTypesParser; ProjectStoragePathWatcherInterface &m_pathWatcher; diff --git a/src/plugins/qmldesigner/libs/designercore/projectstorage/qmldocumentparser.cpp b/src/plugins/qmldesigner/libs/designercore/projectstorage/qmldocumentparser.cpp index b571cebac3d..17aa8ca9617 100644 --- a/src/plugins/qmldesigner/libs/designercore/projectstorage/qmldocumentparser.cpp +++ b/src/plugins/qmldesigner/libs/designercore/projectstorage/qmldocumentparser.cpp @@ -66,7 +66,7 @@ Utils::PathString createNormalizedPath(Utils::SmallStringView directoryPath, Storage::Import createImport(const QmlDom::Import &qmlImport, SourceId sourceId, Utils::SmallStringView directoryPath, - QmlDocumentParser::ProjectStorage &storage) + ProjectStorageType &storage) { using Storage::ModuleKind; using QmlUriKind = QQmlJS::Dom::QmlUri::Kind; @@ -99,7 +99,7 @@ Storage::Import createImport(const QmlDom::Import &qmlImport, QualifiedImports createQualifiedImports(const QList &qmlImports, SourceId sourceId, Utils::SmallStringView directoryPath, - QmlDocumentParser::ProjectStorage &storage) + ProjectStorageType &storage) { NanotraceHR::Tracer tracer{"create qualified imports"_t, category(), @@ -123,7 +123,7 @@ void addImports(Storage::Imports &imports, const QList &qmlImports, SourceId sourceId, Utils::SmallStringView directoryPath, - QmlDocumentParser::ProjectStorage &storage) + ProjectStorageType &storage) { int importCount = 0; for (const QmlDom::Import &qmlImport : qmlImports) { diff --git a/src/plugins/qmldesigner/libs/designercore/projectstorage/qmldocumentparser.h b/src/plugins/qmldesigner/libs/designercore/projectstorage/qmldocumentparser.h index 7b64322ab4f..af2dbbe99ca 100644 --- a/src/plugins/qmldesigner/libs/designercore/projectstorage/qmldocumentparser.h +++ b/src/plugins/qmldesigner/libs/designercore/projectstorage/qmldocumentparser.h @@ -7,8 +7,8 @@ #include "qmldocumentparserinterface.h" #include "sourcepathstorage/nonlockingmutex.h" +#include #include - namespace QmlDesigner { template @@ -18,11 +18,9 @@ class SourcePathStorage; class QMLDESIGNERCORE_EXPORT QmlDocumentParser final : public QmlDocumentParserInterface { public: - using ProjectStorage = QmlDesigner::ProjectStorage; - using PathCache = QmlDesigner::SourcePathCache; #ifdef QDS_BUILD_QMLPARSER - QmlDocumentParser(ProjectStorage &storage, PathCache &pathCache) + QmlDocumentParser(ProjectStorageType &storage, PathCacheType &pathCache) : m_storage{storage} , m_pathCache{pathCache} {} @@ -39,8 +37,8 @@ public: private: // m_pathCache and m_storage are only used when compiled for QDS #ifdef QDS_BUILD_QMLPARSER - ProjectStorage &m_storage; - PathCache &m_pathCache; + ProjectStorageType &m_storage; + PathCacheType &m_pathCache; #endif }; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/qmldesignerprojectmanager.cpp b/src/plugins/qmldesigner/qmldesignerprojectmanager.cpp index 6bba6c12369..9c04f9b1bd3 100644 --- a/src/plugins/qmldesigner/qmldesignerprojectmanager.cpp +++ b/src/plugins/qmldesigner/qmldesignerprojectmanager.cpp @@ -202,7 +202,7 @@ public: FileStatusCache fileStatusCache{fileSystem}; QmlDocumentParser qmlDocumentParser; QmlTypesParser qmlTypesParser{storage}; - ProjectStoragePathWatcher pathWatcher; + ProjectStoragePathWatcher pathWatcher; ProjectPartId projectPartId; ProjectStorageUpdater updater; }; @@ -265,7 +265,7 @@ public: Sqlite::LockingMode::Normal}; QmlDesigner::SourcePathStorage sourcePathStorage{sourcePathDatabase, sourcePathDatabase.isInitialized()}; - PathCacheType pathCache{sourcePathStorage}; + PathCache pathCache{sourcePathStorage}; }; QmlDesignerProjectManager::QmlDesignerProjectManager(ExternalDependenciesInterface &externalDependencies) @@ -322,12 +322,12 @@ AsynchronousImageCache &QmlDesignerProjectManager::asynchronousImageCache() } namespace { -[[maybe_unused]] ProjectStorage *dummyProjectStorage() +[[maybe_unused]] ProjectStorageType *dummyProjectStorage() { return nullptr; } -[[maybe_unused]] ProjectStorageUpdater::PathCache *dummyPathCache() +[[maybe_unused]] PathCacheType *dummyPathCache() { return nullptr; } diff --git a/tests/unit/tests/unittests/model/model-test.cpp b/tests/unit/tests/unittests/model/model-test.cpp index b6d453e74de..a374eb321c7 100644 --- a/tests/unit/tests/unittests/model/model-test.cpp +++ b/tests/unit/tests/unittests/model/model-test.cpp @@ -1041,7 +1041,7 @@ TEST_F(Model_MetaInfo, get_meta_info_by_module) ASSERT_THAT(metaInfo, model.qmlQtObjectMetaInfo()); } -TEST_F(Model_MetaInfo, get_invalid_meta_info_by_module_for_wrong_name) +TEST_F(Model_MetaInfo, get_invalid_meta_info_by_module_and_name_for_wrong_name) { auto module = model.module("QML", ModuleKind::QmlLibrary);