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