aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2021-12-02 17:51:27 +0100
committerMarco Bubke <marco.bubke@qt.io>2021-12-09 13:13:42 +0000
commit596ac61872905e587b4b0188dae19699f4c2e61d (patch)
treea4a4e9d16252b4556d7d8f219519ef06012884ff
parentf349de45f4ec1920bd4a4efc34f693561b270d8a (diff)
QmlDesigner: Synchronize without updating exports
If we only update the qml file we don't have to update the exports from the qmldir file. So if ChangeLevel::ExcludeExportedTypes is set we don't touch the exports for that type. Task-number: QDS-5537 Change-Id: I247228076b3f7ac7f6334d10011b408d6406df07 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
-rw-r--r--src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h63
-rw-r--r--tests/unit/unittest/projectstorage-test.cpp26
2 files changed, 76 insertions, 13 deletions
diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h
index 1d9fe437d2..3f10cbe817 100644
--- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h
+++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h
@@ -501,6 +501,26 @@ private:
};
};
+ SourceIds filterSourceIdsWithoutType(const SourceIds &updatedSourceIds, SourceIds &sourceIdsOfTypes)
+ {
+ std::sort(sourceIdsOfTypes.begin(), sourceIdsOfTypes.end());
+
+ SourceIds sourceIdsWithoutTypeSourceIds;
+ sourceIdsWithoutTypeSourceIds.reserve(updatedSourceIds.size());
+ std::set_difference(updatedSourceIds.begin(),
+ updatedSourceIds.end(),
+ sourceIdsOfTypes.begin(),
+ sourceIdsOfTypes.end(),
+ std::back_inserter(sourceIdsWithoutTypeSourceIds));
+
+ return sourceIdsWithoutTypeSourceIds;
+ }
+
+ TypeIds fetchTypeIds(const SourceIds &sourceIds)
+ {
+ return selectTypeIdsForSourceIdsStatement.template values<TypeId>(128, toIntegers(sourceIds));
+ }
+
void synchronizeTypes(Storage::Types &types,
TypeIds &updatedTypeIds,
AliasPropertyDeclarations &insertedAliasPropertyDeclarations,
@@ -512,18 +532,35 @@ private:
{
Storage::ExportedTypes exportedTypes;
exportedTypes.reserve(types.size() * 3);
+ SourceIds sourceIdsOfTypes;
+ sourceIdsOfTypes.reserve(updatedSourceIds.size());
+ SourceIds notUpdatedExportedSourceIds;
+ notUpdatedExportedSourceIds.reserve(updatedSourceIds.size());
+ TypeIds exportedTypeIds;
+ exportedTypeIds.reserve(types.size());
for (auto &&type : types) {
if (!type.sourceId)
throw TypeHasInvalidSourceId{};
TypeId typeId = declareType(type);
+ sourceIdsOfTypes.push_back(type.sourceId);
updatedTypeIds.push_back(typeId);
- extractExportedTypes(typeId, type, exportedTypes);
+ if (type.changeLevel != Storage::ChangeLevel::ExcludeExportedTypes) {
+ exportedTypeIds.push_back(typeId);
+ extractExportedTypes(typeId, type, exportedTypes);
+ }
}
- synchronizeExportedTypes(updatedSourceIds,
- updatedTypeIds,
+ std::sort(updatedTypeIds.begin(), updatedTypeIds.end());
+
+ SourceIds sourceIdsWithoutType = filterSourceIdsWithoutType(updatedSourceIds,
+ sourceIdsOfTypes);
+ TypeIds notUpdatedTypeIds = fetchTypeIds(sourceIdsWithoutType);
+ exportedTypeIds.insert(exportedTypeIds.end(),
+ notUpdatedTypeIds.begin(),
+ notUpdatedTypeIds.end());
+ synchronizeExportedTypes(exportedTypeIds,
exportedTypes,
relinkableAliasPropertyDeclarations,
relinkablePropertyDeclarations,
@@ -921,8 +958,7 @@ private:
updateAliasPropertyDeclarationValues(updatedAliasPropertyDeclarations);
}
- void synchronizeExportedTypes(const SourceIds &exportedSourceIds,
- const TypeIds &updatedTypeIds,
+ void synchronizeExportedTypes(const TypeIds &updatedTypeIds,
Storage::ExportedTypes &exportedTypes,
AliasPropertyDeclarations &relinkableAliasPropertyDeclarations,
PropertyDeclarations &relinkablePropertyDeclarations,
@@ -933,9 +969,8 @@ private:
< std::tie(second.moduleId, second.name, second.version);
});
- auto range = selectExportedTypesForSourceIdsStatement
- .template range<Storage::ExportedTypeView>(toIntegers(exportedSourceIds),
- toIntegers(updatedTypeIds));
+ auto range = selectExportedTypesForSourceIdsStatement.template range<Storage::ExportedTypeView>(
+ toIntegers(updatedTypeIds));
auto compareKey = [](const Storage::ExportedTypeView &view,
const Storage::ExportedType &type) -> long long {
@@ -2180,7 +2215,8 @@ public:
"SELECT sourceId, name, typeId, ifnull(prototypeId, -1), accessSemantics FROM types",
database};
ReadStatement<1> selectNotUpdatedTypesInSourcesStatement{
- "SELECT typeId FROM types WHERE (sourceId IN carray(?1) AND typeId NOT IN carray(?2))",
+ "SELECT DISTINCT typeId FROM types WHERE (sourceId IN carray(?1) AND typeId NOT IN "
+ "carray(?2))",
database};
WriteStatement deleteTypeNamesByTypeIdStatement{"DELETE FROM exportedTypeNames WHERE typeId=?",
database};
@@ -2517,10 +2553,9 @@ public:
WriteStatement deleteAllSourcesStatement{"DELETE FROM sources", database};
WriteStatement deleteAllSourceContextsStatement{"DELETE FROM sourceContexts", database};
mutable ReadStatement<6> selectExportedTypesForSourceIdsStatement{
- "SELECT moduleId, etn.name, ifnull(majorVersion, -1), ifnull(minorVersion, -1), typeId, "
- "exportedTypeNameId FROM exportedTypeNames AS etn JOIN types USING(typeId) WHERE sourceId "
- "IN carray(?1) OR typeId in carray(?2) ORDER BY moduleId, etn.name, majorVersion, "
- "minorVersion",
+ "SELECT moduleId, name, ifnull(majorVersion, -1), ifnull(minorVersion, -1), typeId, "
+ "exportedTypeNameId FROM exportedTypeNames WHERE typeId in carray(?1) ORDER BY moduleId, "
+ "name, majorVersion, minorVersion",
database};
WriteStatement insertExportedTypeNamesWithVersionStatement{
"INSERT INTO exportedTypeNames(moduleId, name, majorVersion, minorVersion, typeId) "
@@ -2552,6 +2587,8 @@ public:
"SELECT projectSourceId, sourceId, moduleId, fileType FROM projectDatas WHERE "
"projectSourceId=?1",
database};
+ ReadStatement<1> selectTypeIdsForSourceIdsStatement{
+ "SELECT typeId FROM types WHERE sourceId IN carray(?1)", database};
};
} // namespace QmlDesigner
diff --git a/tests/unit/unittest/projectstorage-test.cpp b/tests/unit/unittest/projectstorage-test.cpp
index 1e2cc0bd06..58a9886b7f 100644
--- a/tests/unit/unittest/projectstorage-test.cpp
+++ b/tests/unit/unittest/projectstorage-test.cpp
@@ -3843,4 +3843,30 @@ TEST_F(ProjectStorage, FetchProjectDatasByModuleId)
ASSERT_THAT(projectData, UnorderedElementsAre(projectData1, projectData2));
}
+TEST_F(ProjectStorage, ExcludeExportedTypes)
+{
+ auto package{createSimpleSynchronizationPackage()};
+ storage.synchronize(package);
+ package.types[0].exportedTypes.clear();
+ package.types[0].changeLevel = Storage::ChangeLevel::ExcludeExportedTypes;
+
+ storage.synchronize(std::move(package));
+
+ ASSERT_THAT(
+ storage.fetchTypes(),
+ UnorderedElementsAre(
+ AllOf(IsStorageType(sourceId2, "QObject", TypeId{}, TypeAccessSemantics::Reference),
+ Field(&Storage::Type::exportedTypes,
+ UnorderedElementsAre(IsExportedType(qmlModuleId, "Object"),
+ IsExportedType(qmlModuleId, "Obj"),
+ IsExportedType(qmlNativeModuleId, "QObject")))),
+ AllOf(IsStorageType(sourceId1,
+ "QQuickItem",
+ fetchTypeId(sourceId2, "QObject"),
+ TypeAccessSemantics::Reference),
+ Field(&Storage::Type::exportedTypes,
+ UnorderedElementsAre(IsExportedType(qtQuickModuleId, "Item"),
+ IsExportedType(qtQuickNativeModuleId, "QQuickItem"))))));
+}
+
} // namespace