diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index 4faaa9b6d6d..a5cf6f86c30 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -176,6 +176,14 @@ public: .template valueWithTransaction(&typeId, propertyName); } + Utils::optional propertyDeclaration( + PropertyDeclarationId propertyDeclarationId) const + { + return selectPropertyDeclarationForPropertyDeclarationIdStatement + .template optionalValueWithTransaction( + &propertyDeclarationId); + } + Utils::optional propertyName(PropertyDeclarationId propertyDeclarationId) const { return selectPropertyNameStatement.template optionalValueWithTransaction( @@ -2926,6 +2934,11 @@ public: "FROM propertyDeclarations " "WHERE typeId=?1 AND name=?2 LIMIT 1", database}; + mutable ReadStatement<4, 1> selectPropertyDeclarationForPropertyDeclarationIdStatement{ + "SELECT typeId, name, propertyTraits, propertyTypeId " + "FROM propertyDeclarations " + "WHERE propertyDeclarationId=?1 LIMIT 1", + database}; }; extern template class ProjectStorage; } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h index 5ce7cc587fb..28a3d110724 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h @@ -926,3 +926,36 @@ public: }; } // namespace QmlDesigner::Storage::Synchronization + +namespace QmlDesigner::Storage::Info { + +class PropertyDeclaration +{ +public: + PropertyDeclaration(long long typeId, + Utils::SmallStringView name, + long long traits, + long long propertyTypeId) + : typeId{typeId} + , name{name} + , traits{static_cast(traits)} + , propertyTypeId{propertyTypeId} + {} + + PropertyDeclaration(TypeId typeId, + Utils::SmallStringView name, + PropertyDeclarationTraits traits, + TypeId propertyTypeId) + : typeId{typeId} + , name{name} + , traits{traits} + , propertyTypeId{propertyTypeId} + {} + + TypeId typeId; + Utils::SmallString name; + PropertyDeclarationTraits traits; + TypeId propertyTypeId; +}; + +} // namespace QmlDesigner::Storage::Info diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 878fd70d184..8ba4245de67 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -548,6 +548,16 @@ std::ostream &operator<<(std::ostream &out, PropertyDeclarationTraits traits) } } // namespace Storage +namespace Storage::Info { +std::ostream &operator<<(std::ostream &out, const PropertyDeclaration &propertyDeclaration) +{ + using Utils::operator<<; + return out << "(\"" << propertyDeclaration.typeId << "\", " << propertyDeclaration.name << ", " + << propertyDeclaration.typeId << ", " << propertyDeclaration.traits << ", " + << propertyDeclaration.propertyTypeId << "\")"; +} +} // namespace Storage::Info + namespace Storage::Synchronization { namespace { diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index 6bccd008678..ce997de4797 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -159,6 +159,11 @@ enum class PropertyDeclarationTraits : int; std::ostream &operator<<(std::ostream &out, PropertyDeclarationTraits traits); } // namespace Storage +namespace Storage::Info { +class ProjectDeclaration; +std::ostream &operator<<(std::ostream &out, const ProjectDeclaration &declaration); +} // namespace Storage::Info + namespace Storage::Synchronization { class Type; class ExportedType; diff --git a/tests/unit/unittest/projectstorage-test.cpp b/tests/unit/unittest/projectstorage-test.cpp index cae9e9a4857..9d809d5d194 100644 --- a/tests/unit/unittest/projectstorage-test.cpp +++ b/tests/unit/unittest/projectstorage-test.cpp @@ -180,6 +180,21 @@ MATCHER_P4(IsPropertyDeclaration, && propertyDeclaration.traits == traits; } +MATCHER_P4(IsInfoPropertyDeclaration, + typeId, + name, + traits, + propertyTypeId, + std::string(negation ? "isn't " : "is ") + + PrintToString(Storage::Info::PropertyDeclaration{typeId, name, traits, propertyTypeId})) +{ + const Storage::Info::PropertyDeclaration &propertyDeclaration = arg; + + return propertyDeclaration.typeId == typeId && propertyDeclaration.name == name + && propertyDeclaration.propertyTypeId == propertyTypeId + && propertyDeclaration.traits == traits; +} + class HasNameMatcher { public: @@ -5644,4 +5659,29 @@ TEST_F(ProjectStorage, GetInvalidLocalPropertyDeclarationIdForWrongPropertyName) ASSERT_FALSE(propertyId); } +TEST_F(ProjectStorage, GetPropertyDeclaration) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + auto typeId2 = fetchTypeId(sourceId1, "QObject2"); + auto typeId3 = fetchTypeId(sourceId1, "QObject3"); + auto propertyId = storage.propertyDeclarationId(typeId3, "data2"); + + auto property = storage.propertyDeclaration(propertyId); + + ASSERT_THAT(property, + Optional(IsInfoPropertyDeclaration( + typeId2, "data2", Storage::PropertyDeclarationTraits::IsReadOnly, typeId3))); +} + +TEST_F(ProjectStorage, GetInvalidOptionalPropertyDeclarationForInvalidPropertyDeclarationId) +{ + auto package{createPackageWithProperties()}; + storage.synchronize(package); + + auto property = storage.propertyDeclaration(PropertyDeclarationId{}); + + ASSERT_THAT(property, Eq(Utils::nullopt)); +} + } // namespace