From f31d0f3a0a8542a0b6500852a973f68eada8b3e1 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 13 Jul 2022 14:04:00 +0200 Subject: [PATCH] QmlDesigner: Provide ProjectStorage::localPropertyDeclarationId Even if there is a property with that name in the prototype chain an invalid id should be returned. Task-nubmer: QDS-7281 Change-Id: I08611390c8e9a75036ed5d5b54d2e5637adcfd84 Reviewed-by: Qt CI Bot Reviewed-by: Reviewed-by: Tim Jenssen --- .../projectstorage/projectstorage.h | 12 +++++ tests/unit/unittest/projectstorage-test.cpp | 44 +++++++++++++++++++ 2 files changed, 56 insertions(+) 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