From c56c3ea024e125ccd2806957ab29404cc8f049eb Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 21 Jul 2022 16:45:53 +0200 Subject: [PATCH] QmlDesigner: Provide TypeTraits for type getter The type traits contains already information like if the file is a file component etc.. Task-number: QDS-7327 Change-Id: I7713840fd1107046e8a6710c0ca493dc54edf823 Reviewed-by: Qt CI Bot Reviewed-by: Tim Jenssen --- .../designercore/projectstorage/projectstorage.h | 4 ++-- .../projectstorage/projectstoragetypes.h | 4 +++- tests/unit/unittest/projectstorage-test.cpp | 13 +++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index c224cadaa1e..ddfda08fdc1 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -3095,8 +3095,8 @@ public: "UPDATE types SET defaultPropertyId=?2 WHERE typeId=?1", database}; WriteStatement<1> updateDefaultPropertyIdToNullStatement{ "UPDATE types SET defaultPropertyId=NULL WHERE defaultPropertyId=?1", database}; - mutable ReadStatement<1, 1> selectInfoTypeByTypeIdStatement{ - "SELECT defaultPropertyId FROM types WHERE typeId=?", database}; + mutable ReadStatement<2, 1> selectInfoTypeByTypeIdStatement{ + "SELECT defaultPropertyId, traits FROM types WHERE typeId=?", 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 cea3f94c099..25be97f1eb3 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstoragetypes.h @@ -936,11 +936,13 @@ public: class Type { public: - Type(PropertyDeclarationId defaultPropertyId) + Type(PropertyDeclarationId defaultPropertyId, TypeTraits traits) : defaultPropertyId{defaultPropertyId} + , traits{traits} {} PropertyDeclarationId defaultPropertyId; + TypeTraits traits; }; } // namespace QmlDesigner::Storage::Info diff --git a/tests/unit/unittest/projectstorage-test.cpp b/tests/unit/unittest/projectstorage-test.cpp index ba14890df4d..14a54826f0e 100644 --- a/tests/unit/unittest/projectstorage-test.cpp +++ b/tests/unit/unittest/projectstorage-test.cpp @@ -246,14 +246,15 @@ MATCHER(StringsAreSorted, std::string(negation ? "isn't sorted" : "is sorted")) }); } -MATCHER_P(IsInfoType, - defaultPropertyId, - std::string(negation ? "isn't " : "is ") - + PrintToString(Storage::Info::Type{defaultPropertyId})) +MATCHER_P2(IsInfoType, + defaultPropertyId, + traits, + std::string(negation ? "isn't " : "is ") + + PrintToString(Storage::Info::Type{defaultPropertyId, traits})) { const Storage::Info::Type &type = arg; - return type.defaultPropertyId == defaultPropertyId; + return type.defaultPropertyId == defaultPropertyId && type.traits == traits; } class ProjectStorage : public testing::Test @@ -5874,7 +5875,7 @@ TEST_F(ProjectStorage, GetType) auto type = storage.type(typeId); - ASSERT_THAT(type, Optional(IsInfoType(defaultPropertyId))); + ASSERT_THAT(type, Optional(IsInfoType(defaultPropertyId, TypeTraits::Reference))); } TEST_F(ProjectStorage, DontGetTypeForInvalidId)