diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index 091ab2b5c06..6b8fcc986fb 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -169,6 +169,13 @@ public: .template valueWithTransaction(&typeId, propertyName); } + PropertyDeclarationId localPropertyDeclarationId(TypeId typeId, + Utils::SmallStringView propertyName) const + { + return selectLocalPropertyDeclarationIdForTypeAndPropertyNameStatement + .template valueWithTransaction(&typeId, propertyName); + } + Utils::optional propertyName(PropertyDeclarationId propertyDeclarationId) const { return selectPropertyNameStatement.template optionalValueWithTransaction( @@ -2914,6 +2921,11 @@ public: "SELECT propertyDeclarationId FROM typeChain JOIN propertyDeclarations " " USING(typeId) WHERE name=?2 ORDER BY level LIMIT 1", database}; + mutable ReadStatement<1, 2> selectLocalPropertyDeclarationIdForTypeAndPropertyNameStatement{ + "SELECT propertyDeclarationId " + "FROM propertyDeclarations " + "WHERE typeId=?1 AND name=?2 LIMIT 1", + database}; }; extern template class ProjectStorage; } // namespace QmlDesigner diff --git a/tests/unit/unittest/projectstorage-test.cpp b/tests/unit/unittest/projectstorage-test.cpp index 44ff161e70f..7d33bed62bb 100644 --- a/tests/unit/unittest/projectstorage-test.cpp +++ b/tests/unit/unittest/projectstorage-test.cpp @@ -5685,4 +5685,48 @@ TEST_F(ProjectStorage, GetInvalidPropertyDeclarationIdForWrongPropertyName) ASSERT_FALSE(propertyId); } +TEST_F(ProjectStorage, GetLocalPropertyDeclarationId) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId = fetchTypeId(sourceId1, "QObject"); + + auto propertyId = storage.localPropertyDeclarationId(typeId, "data"); + + ASSERT_THAT(propertyId, HasName("data")); +} + +TEST_F(ProjectStorage, GetInvalidLocalPropertyDeclarationIdForWrongType) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId = fetchTypeId(sourceId1, "QObject2"); + + auto propertyId = storage.localPropertyDeclarationId(typeId, "data"); + + ASSERT_FALSE(propertyId); +} + +TEST_F(ProjectStorage, GetInvalidLocalPropertyDeclarationIdForInvalidTypeId) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId = fetchTypeId(sourceId1, "WrongQObject"); + + auto propertyId = storage.localPropertyDeclarationId(typeId, "data"); + + ASSERT_FALSE(propertyId); +} + +TEST_F(ProjectStorage, GetInvalidLocalPropertyDeclarationIdForWrongPropertyName) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId = fetchTypeId(sourceId1, "QObject"); + + auto propertyId = storage.localPropertyDeclarationId(typeId, "wrongName"); + + ASSERT_FALSE(propertyId); +} + } // namespace