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 <qt_ci_bot@qt-project.org>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2022-07-21 16:45:53 +02:00
parent ab30e8fe06
commit c56c3ea024
3 changed files with 12 additions and 9 deletions

View File

@@ -3095,8 +3095,8 @@ public:
"UPDATE types SET defaultPropertyId=?2 WHERE typeId=?1", database}; "UPDATE types SET defaultPropertyId=?2 WHERE typeId=?1", database};
WriteStatement<1> updateDefaultPropertyIdToNullStatement{ WriteStatement<1> updateDefaultPropertyIdToNullStatement{
"UPDATE types SET defaultPropertyId=NULL WHERE defaultPropertyId=?1", database}; "UPDATE types SET defaultPropertyId=NULL WHERE defaultPropertyId=?1", database};
mutable ReadStatement<1, 1> selectInfoTypeByTypeIdStatement{ mutable ReadStatement<2, 1> selectInfoTypeByTypeIdStatement{
"SELECT defaultPropertyId FROM types WHERE typeId=?", database}; "SELECT defaultPropertyId, traits FROM types WHERE typeId=?", database};
}; };
extern template class ProjectStorage<Sqlite::Database>; extern template class ProjectStorage<Sqlite::Database>;
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -936,11 +936,13 @@ public:
class Type class Type
{ {
public: public:
Type(PropertyDeclarationId defaultPropertyId) Type(PropertyDeclarationId defaultPropertyId, TypeTraits traits)
: defaultPropertyId{defaultPropertyId} : defaultPropertyId{defaultPropertyId}
, traits{traits}
{} {}
PropertyDeclarationId defaultPropertyId; PropertyDeclarationId defaultPropertyId;
TypeTraits traits;
}; };
} // namespace QmlDesigner::Storage::Info } // namespace QmlDesigner::Storage::Info

View File

@@ -246,14 +246,15 @@ MATCHER(StringsAreSorted, std::string(negation ? "isn't sorted" : "is sorted"))
}); });
} }
MATCHER_P(IsInfoType, MATCHER_P2(IsInfoType,
defaultPropertyId, defaultPropertyId,
std::string(negation ? "isn't " : "is ") traits,
+ PrintToString(Storage::Info::Type{defaultPropertyId})) std::string(negation ? "isn't " : "is ")
+ PrintToString(Storage::Info::Type{defaultPropertyId, traits}))
{ {
const Storage::Info::Type &type = arg; const Storage::Info::Type &type = arg;
return type.defaultPropertyId == defaultPropertyId; return type.defaultPropertyId == defaultPropertyId && type.traits == traits;
} }
class ProjectStorage : public testing::Test class ProjectStorage : public testing::Test
@@ -5874,7 +5875,7 @@ TEST_F(ProjectStorage, GetType)
auto type = storage.type(typeId); auto type = storage.type(typeId);
ASSERT_THAT(type, Optional(IsInfoType(defaultPropertyId))); ASSERT_THAT(type, Optional(IsInfoType(defaultPropertyId, TypeTraits::Reference)));
} }
TEST_F(ProjectStorage, DontGetTypeForInvalidId) TEST_F(ProjectStorage, DontGetTypeForInvalidId)