From 4ca769afb1f7c1fb3a5c8c4ada270ac442f7826e Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 13 Jul 2022 17:40:50 +0200 Subject: [PATCH] QmlDesigner: Add ProjectStorage::functionDeclarationNames As we changed the MetaInfo interface we can return ids too but as an intermediate step we return the sorted function names. Beware that the sort is not matching the normal SmallString "<" operator because it is not using size. Task-number: QDS-7284 Change-Id: I96c6494d7c36f37d451d439be8aee35e0221f20b Reviewed-by: Thomas Hartmann --- .../projectstorage/projectstorage.h | 16 ++++++ tests/unit/unittest/projectstorage-test.cpp | 50 +++++++++++++++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index eb7a7feee96..5e565d15918 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -190,6 +190,12 @@ public: .template valuesWithTransaction(32, &typeId); } + std::vector functionDeclarationNames(TypeId typeId) const + { + return selectFuncionDeclarationNamesForTypeStatement + .template valuesWithTransaction(32, &typeId); + } + Utils::optional propertyName(PropertyDeclarationId propertyDeclarationId) const { return selectPropertyNameStatement.template optionalValueWithTransaction( @@ -2955,6 +2961,16 @@ public: "SELECT name FROM typeChain JOIN signalDeclarations " " USING(typeId) ORDER BY name", database}; + mutable ReadStatement<1, 1> selectFuncionDeclarationNamesForTypeStatement{ + "WITH RECURSIVE " + " typeChain(typeId) AS (" + " VALUES(?1)" + " UNION ALL " + " SELECT prototypeId FROM types JOIN typeChain " + " USING(typeId) WHERE prototypeId IS NOT NULL)" + "SELECT name FROM typeChain JOIN functionDeclarations " + " USING(typeId) ORDER BY name", + database}; }; extern template class ProjectStorage; } // namespace QmlDesigner diff --git a/tests/unit/unittest/projectstorage-test.cpp b/tests/unit/unittest/projectstorage-test.cpp index 802a5743e57..a82f64c44a6 100644 --- a/tests/unit/unittest/projectstorage-test.cpp +++ b/tests/unit/unittest/projectstorage-test.cpp @@ -787,7 +787,7 @@ protected: Storage::Synchronization::ImportedType{"Object"}, Storage::PropertyDeclarationTraits::IsList | Storage::PropertyDeclarationTraits::IsReadOnly}}, - {}, + {Storage::Synchronization::FunctionDeclaration{"values", {}, {}}}, {Storage::Synchronization::SignalDeclaration{"valuesChanged", {}}}}); package.types.push_back(Storage::Synchronization::Type{ "QObject2", @@ -806,7 +806,7 @@ protected: Storage::Synchronization::ImportedType{"Object3"}, Storage::PropertyDeclarationTraits::IsList | Storage::PropertyDeclarationTraits::IsReadOnly}}, - {}, + {Storage::Synchronization::FunctionDeclaration{"items", {}, {}}}, {Storage::Synchronization::SignalDeclaration{"itemsChanged", {}}}}); package.types.push_back(Storage::Synchronization::Type{ "QObject3", @@ -825,7 +825,7 @@ protected: Storage::Synchronization::ImportedType{"Object2"}, Storage::PropertyDeclarationTraits::IsList | Storage::PropertyDeclarationTraits::IsReadOnly}}, - {}, + {Storage::Synchronization::FunctionDeclaration{"objects", {}, {}}}, {Storage::Synchronization::SignalDeclaration{"objectsChanged", {}}}}); package.updatedSourceIds.push_back(sourceId1); @@ -5741,4 +5741,48 @@ TEST_F(ProjectStorage, GetOnlySignalDeclarationNamesFromUpIntoThePrototypeChain) ASSERT_THAT(signalNames, ElementsAre("itemsChanged", "valuesChanged")); } +TEST_F(ProjectStorage, GetFunctionDeclarationNames) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId = fetchTypeId(sourceId1, "QObject3"); + + auto functionNames = storage.functionDeclarationNames(typeId); + + ASSERT_THAT(functionNames, ElementsAre("items", "objects", "values")); +} + +TEST_F(ProjectStorage, GetFunctionDeclarationNamesAreOrdered) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId = fetchTypeId(sourceId1, "QObject3"); + + auto functionNames = storage.functionDeclarationNames(typeId); + + ASSERT_THAT(functionNames, StringsAreSorted()); +} + +TEST_F(ProjectStorage, GetNoFunctionDeclarationNamesForInvalidTypeId) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId = fetchTypeId(sourceId1, "WrongObject"); + + auto functionNames = storage.functionDeclarationNames(typeId); + + ASSERT_THAT(functionNames, IsEmpty()); +} + +TEST_F(ProjectStorage, GetOnlyFunctionDeclarationNamesFromUpIntoThePrototypeChain) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId = fetchTypeId(sourceId1, "QObject2"); + + auto functionNames = storage.functionDeclarationNames(typeId); + + ASSERT_THAT(functionNames, ElementsAre("items", "values")); +} + } // namespace