QmlDesigner: Fix property editor lookup

Task-number: QDS-11951
Change-Id: I22563aca2aacf515d2a2e66d87e39c418ea3b7d4
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
Marco Bubke
2024-04-23 18:29:18 +02:00
parent 7f8d7f511d
commit 4268c50f30
3 changed files with 35 additions and 19 deletions

View File

@@ -517,8 +517,12 @@ void ProjectStorageUpdater::updatePropertyEditorPaths(
auto state = fileState(directorySourceId, package, notUpdatedSourceIds); auto state = fileState(directorySourceId, package, notUpdatedSourceIds);
if (state == FileState::Changed) if (state == FileState::Changed) {
updatePropertyEditorPath(pathInfo.filePath(), package, directorySourceId); updatePropertyEditorPath(pathInfo.filePath(),
package,
directorySourceId,
propertyEditorResourcesPath.size() + 1);
}
} }
} }
@@ -655,7 +659,8 @@ void ProjectStorageUpdater::updateTypeAnnotation(const QString &directoryPath,
void ProjectStorageUpdater::updatePropertyEditorPath( void ProjectStorageUpdater::updatePropertyEditorPath(
const QString &directoryPath, const QString &directoryPath,
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
SourceId directorySourceId) SourceId directorySourceId,
long long pathOffset)
{ {
NanotraceHR::Tracer tracer{"update property editor path"_t, NanotraceHR::Tracer tracer{"update property editor path"_t,
category(), category(),
@@ -668,27 +673,29 @@ void ProjectStorageUpdater::updatePropertyEditorPath(
auto dir = QDir{directoryPath}; auto dir = QDir{directoryPath};
const auto fileInfos = dir.entryInfoList({"*Pane.qml", "*Specifics.qml"}, QDir::Files); const auto fileInfos = dir.entryInfoList({"*Pane.qml", "*Specifics.qml"}, QDir::Files);
for (const auto &fileInfo : fileInfos) for (const auto &fileInfo : fileInfos)
updatePropertyEditorFilePath(fileInfo.filePath(), package, directorySourceId); updatePropertyEditorFilePath(fileInfo.filePath(), package, directorySourceId, pathOffset);
} }
void ProjectStorageUpdater::updatePropertyEditorFilePath( void ProjectStorageUpdater::updatePropertyEditorFilePath(
const QString &path, const QString &path,
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
SourceId directorySourceId) SourceId directorySourceId,
long long pathOffset)
{ {
NanotraceHR::Tracer tracer{"update property editor file path"_t, NanotraceHR::Tracer tracer{"update property editor file path"_t,
category(), category(),
keyValue("directory path", path), keyValue("directory path", path),
keyValue("directory source id", directorySourceId)}; keyValue("directory source id", directorySourceId)};
QRegularExpression regex{R"xo(.+\/(\w+)\/(\w+)(Specifics|Pane).qml)xo"}; QRegularExpression regex{R"xo((.+)\/(\w+)(Specifics|Pane).qml)xo"};
auto match = regex.match(path); auto match = regex.match(QStringView{path}.mid(pathOffset));
QString oldModuleName; QString oldModuleName;
ModuleId moduleId; ModuleId moduleId;
if (match.hasMatch()) { if (match.hasMatch()) {
auto moduleName = match.capturedView(1); auto moduleName = match.capturedView(1).toString();
moduleName.replace('/', '.');
if (oldModuleName != moduleName) { if (oldModuleName != moduleName) {
oldModuleName = moduleName.toString(); oldModuleName = moduleName;
moduleId = m_projectStorage.moduleId(Utils::SmallString{moduleName}); moduleId = m_projectStorage.moduleId(Utils::SmallString{moduleName});
} }
Storage::TypeNameString typeName{match.capturedView(2)}; Storage::TypeNameString typeName{match.capturedView(2)};

View File

@@ -177,10 +177,12 @@ private:
Storage::Synchronization::SynchronizationPackage &package); Storage::Synchronization::SynchronizationPackage &package);
void updatePropertyEditorPath(const QString &path, void updatePropertyEditorPath(const QString &path,
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
SourceId directorySourceId); SourceId directorySourceId,
long long pathOffset);
void updatePropertyEditorFilePath(const QString &filePath, void updatePropertyEditorFilePath(const QString &filePath,
Storage::Synchronization::SynchronizationPackage &package, Storage::Synchronization::SynchronizationPackage &package,
SourceId directorySourceId); SourceId directorySourceId,
long long pathOffset);
void parseTypeInfos(const QStringList &typeInfos, void parseTypeInfos(const QStringList &typeInfos,
const QList<QmlDirParser::Import> &qmldirDependencies, const QList<QmlDirParser::Import> &qmldirDependencies,
const QList<QmlDirParser::Import> &qmldirImports, const QList<QmlDirParser::Import> &qmldirImports,

View File

@@ -3533,19 +3533,26 @@ TEST_F(ProjectStorageUpdater, update_property_editor_specifics)
ON_CALL(projectStorageMock, fetchFileStatus(_)).WillByDefault([](SourceId sourceId) { ON_CALL(projectStorageMock, fetchFileStatus(_)).WillByDefault([](SourceId sourceId) {
return FileStatus{sourceId, 1, 21}; return FileStatus{sourceId, 1, 21};
}); });
auto sourceId = sourcePathCache.sourceId( auto textSourceId = sourcePathCache.sourceId(
QmlDesigner::SourcePath{propertyEditorQmlPath + "/QtQuick/TextSpecifics.qml"}); QmlDesigner::SourcePath{propertyEditorQmlPath + "/QtQuick/TextSpecifics.qml"});
auto directoryId = sourcePathCache.sourceId( auto qtQuickDirectoryId = sourcePathCache.sourceId(
QmlDesigner::SourcePath{propertyEditorQmlPath + "/QtQuick/."}); 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 qtQuickModuleId = storage.moduleId("QtQuick");
auto controlsModuleId = storage.moduleId("QtQuick.Controls");
EXPECT_CALL(projectStorageMock, EXPECT_CALL(projectStorageMock,
synchronize( synchronize(AllOf(
AllOf(Field(&SynchronizationPackage::propertyEditorQmlPaths, Field(&SynchronizationPackage::propertyEditorQmlPaths,
Contains(IsPropertyEditorQmlPath(qtQuickModuleId, "Text", sourceId))), IsSupersetOf(
{IsPropertyEditorQmlPath(qtQuickModuleId, "Text", textSourceId),
IsPropertyEditorQmlPath(controlsModuleId, "Button", buttonSourceId)})),
Field(&SynchronizationPackage::updatedPropertyEditorQmlPathSourceIds, Field(&SynchronizationPackage::updatedPropertyEditorQmlPathSourceIds,
ElementsAre(directoryId))))); ElementsAre(qtQuickDirectoryId, controlsDirectoryId)))));
updater.update({}, {}, propertyEditorQmlPath, {}); updater.update({}, {}, propertyEditorQmlPath, {});
} }