From 4268c50f30c8b160d135d966c998a84b552cbaf7 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 23 Apr 2024 18:29:18 +0200 Subject: [PATCH] QmlDesigner: Fix property editor lookup Task-number: QDS-11951 Change-Id: I22563aca2aacf515d2a2e66d87e39c418ea3b7d4 Reviewed-by: Reviewed-by: Tim Jenssen Reviewed-by: Qt CI Patch Build Bot --- .../projectstorage/projectstorageupdater.cpp | 25 ++++++++++++------- .../projectstorage/projectstorageupdater.h | 6 +++-- .../projectstorageupdater-test.cpp | 23 +++++++++++------ 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp index d8d0c6ef525..f1f8a2ca28f 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.cpp @@ -517,8 +517,12 @@ void ProjectStorageUpdater::updatePropertyEditorPaths( auto state = fileState(directorySourceId, package, notUpdatedSourceIds); - if (state == FileState::Changed) - updatePropertyEditorPath(pathInfo.filePath(), package, directorySourceId); + if (state == FileState::Changed) { + updatePropertyEditorPath(pathInfo.filePath(), + package, + directorySourceId, + propertyEditorResourcesPath.size() + 1); + } } } @@ -655,7 +659,8 @@ void ProjectStorageUpdater::updateTypeAnnotation(const QString &directoryPath, void ProjectStorageUpdater::updatePropertyEditorPath( const QString &directoryPath, Storage::Synchronization::SynchronizationPackage &package, - SourceId directorySourceId) + SourceId directorySourceId, + long long pathOffset) { NanotraceHR::Tracer tracer{"update property editor path"_t, category(), @@ -668,27 +673,29 @@ void ProjectStorageUpdater::updatePropertyEditorPath( auto dir = QDir{directoryPath}; const auto fileInfos = dir.entryInfoList({"*Pane.qml", "*Specifics.qml"}, QDir::Files); for (const auto &fileInfo : fileInfos) - updatePropertyEditorFilePath(fileInfo.filePath(), package, directorySourceId); + updatePropertyEditorFilePath(fileInfo.filePath(), package, directorySourceId, pathOffset); } void ProjectStorageUpdater::updatePropertyEditorFilePath( const QString &path, Storage::Synchronization::SynchronizationPackage &package, - SourceId directorySourceId) + SourceId directorySourceId, + long long pathOffset) { NanotraceHR::Tracer tracer{"update property editor file path"_t, category(), keyValue("directory path", path), keyValue("directory source id", directorySourceId)}; - QRegularExpression regex{R"xo(.+\/(\w+)\/(\w+)(Specifics|Pane).qml)xo"}; - auto match = regex.match(path); + QRegularExpression regex{R"xo((.+)\/(\w+)(Specifics|Pane).qml)xo"}; + auto match = regex.match(QStringView{path}.mid(pathOffset)); QString oldModuleName; ModuleId moduleId; if (match.hasMatch()) { - auto moduleName = match.capturedView(1); + auto moduleName = match.capturedView(1).toString(); + moduleName.replace('/', '.'); if (oldModuleName != moduleName) { - oldModuleName = moduleName.toString(); + oldModuleName = moduleName; moduleId = m_projectStorage.moduleId(Utils::SmallString{moduleName}); } Storage::TypeNameString typeName{match.capturedView(2)}; diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.h index 640969fe990..bbaa71a2891 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorageupdater.h @@ -177,10 +177,12 @@ private: Storage::Synchronization::SynchronizationPackage &package); void updatePropertyEditorPath(const QString &path, Storage::Synchronization::SynchronizationPackage &package, - SourceId directorySourceId); + SourceId directorySourceId, + long long pathOffset); void updatePropertyEditorFilePath(const QString &filePath, Storage::Synchronization::SynchronizationPackage &package, - SourceId directorySourceId); + SourceId directorySourceId, + long long pathOffset); void parseTypeInfos(const QStringList &typeInfos, const QList &qmldirDependencies, const QList &qmldirImports, diff --git a/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp b/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp index 0d8b5cfc34e..2d1e7aa61ea 100644 --- a/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp +++ b/tests/unit/tests/unittests/projectstorage/projectstorageupdater-test.cpp @@ -3533,19 +3533,26 @@ TEST_F(ProjectStorageUpdater, update_property_editor_specifics) ON_CALL(projectStorageMock, fetchFileStatus(_)).WillByDefault([](SourceId sourceId) { return FileStatus{sourceId, 1, 21}; }); - auto sourceId = sourcePathCache.sourceId( + auto textSourceId = sourcePathCache.sourceId( QmlDesigner::SourcePath{propertyEditorQmlPath + "/QtQuick/TextSpecifics.qml"}); - auto directoryId = sourcePathCache.sourceId( + auto qtQuickDirectoryId = sourcePathCache.sourceId( QmlDesigner::SourcePath{propertyEditorQmlPath + "/QtQuick/."}); - setFilesChanged({directoryId}); + auto buttonSourceId = sourcePathCache.sourceId( + QmlDesigner::SourcePath{propertyEditorQmlPath + "/QtQuick/Controls/ButtonSpecifics.qml"}); + auto controlsDirectoryId = sourcePathCache.sourceId( + QmlDesigner::SourcePath{propertyEditorQmlPath + "/QtQuick/Controls/."}); + setFilesChanged({qtQuickDirectoryId, controlsDirectoryId}); auto qtQuickModuleId = storage.moduleId("QtQuick"); + auto controlsModuleId = storage.moduleId("QtQuick.Controls"); EXPECT_CALL(projectStorageMock, - synchronize( - AllOf(Field(&SynchronizationPackage::propertyEditorQmlPaths, - Contains(IsPropertyEditorQmlPath(qtQuickModuleId, "Text", sourceId))), - Field(&SynchronizationPackage::updatedPropertyEditorQmlPathSourceIds, - ElementsAre(directoryId))))); + synchronize(AllOf( + Field(&SynchronizationPackage::propertyEditorQmlPaths, + IsSupersetOf( + {IsPropertyEditorQmlPath(qtQuickModuleId, "Text", textSourceId), + IsPropertyEditorQmlPath(controlsModuleId, "Button", buttonSourceId)})), + Field(&SynchronizationPackage::updatedPropertyEditorQmlPathSourceIds, + ElementsAre(qtQuickDirectoryId, controlsDirectoryId))))); updater.update({}, {}, propertyEditorQmlPath, {}); }