forked from qt-creator/qt-creator
QmlDesigner: Add ProjectStorage::propertyDeclaration
Returns for a property declaration id the property declaration infos. If there are no infos a null optional is returned. Task-number: QDS-7278 Change-Id: I4faa158008130f00f31062bab94baa7f88d70edf Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -176,6 +176,14 @@ public:
|
|||||||
.template valueWithTransaction<PropertyDeclarationId>(&typeId, propertyName);
|
.template valueWithTransaction<PropertyDeclarationId>(&typeId, propertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::optional<Storage::Info::PropertyDeclaration> propertyDeclaration(
|
||||||
|
PropertyDeclarationId propertyDeclarationId) const
|
||||||
|
{
|
||||||
|
return selectPropertyDeclarationForPropertyDeclarationIdStatement
|
||||||
|
.template optionalValueWithTransaction<Storage::Info::PropertyDeclaration>(
|
||||||
|
&propertyDeclarationId);
|
||||||
|
}
|
||||||
|
|
||||||
Utils::optional<Utils::SmallString> propertyName(PropertyDeclarationId propertyDeclarationId) const
|
Utils::optional<Utils::SmallString> propertyName(PropertyDeclarationId propertyDeclarationId) const
|
||||||
{
|
{
|
||||||
return selectPropertyNameStatement.template optionalValueWithTransaction<Utils::SmallString>(
|
return selectPropertyNameStatement.template optionalValueWithTransaction<Utils::SmallString>(
|
||||||
@@ -2926,6 +2934,11 @@ public:
|
|||||||
"FROM propertyDeclarations "
|
"FROM propertyDeclarations "
|
||||||
"WHERE typeId=?1 AND name=?2 LIMIT 1",
|
"WHERE typeId=?1 AND name=?2 LIMIT 1",
|
||||||
database};
|
database};
|
||||||
|
mutable ReadStatement<4, 1> selectPropertyDeclarationForPropertyDeclarationIdStatement{
|
||||||
|
"SELECT typeId, name, propertyTraits, propertyTypeId "
|
||||||
|
"FROM propertyDeclarations "
|
||||||
|
"WHERE propertyDeclarationId=?1 LIMIT 1",
|
||||||
|
database};
|
||||||
};
|
};
|
||||||
extern template class ProjectStorage<Sqlite::Database>;
|
extern template class ProjectStorage<Sqlite::Database>;
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -926,3 +926,36 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner::Storage::Synchronization
|
} // 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<PropertyDeclarationTraits>(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
|
||||||
|
@@ -548,6 +548,16 @@ std::ostream &operator<<(std::ostream &out, PropertyDeclarationTraits traits)
|
|||||||
}
|
}
|
||||||
} // namespace Storage
|
} // 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 Storage::Synchronization {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@@ -159,6 +159,11 @@ enum class PropertyDeclarationTraits : int;
|
|||||||
std::ostream &operator<<(std::ostream &out, PropertyDeclarationTraits traits);
|
std::ostream &operator<<(std::ostream &out, PropertyDeclarationTraits traits);
|
||||||
} // namespace Storage
|
} // namespace Storage
|
||||||
|
|
||||||
|
namespace Storage::Info {
|
||||||
|
class ProjectDeclaration;
|
||||||
|
std::ostream &operator<<(std::ostream &out, const ProjectDeclaration &declaration);
|
||||||
|
} // namespace Storage::Info
|
||||||
|
|
||||||
namespace Storage::Synchronization {
|
namespace Storage::Synchronization {
|
||||||
class Type;
|
class Type;
|
||||||
class ExportedType;
|
class ExportedType;
|
||||||
|
@@ -180,6 +180,21 @@ MATCHER_P4(IsPropertyDeclaration,
|
|||||||
&& propertyDeclaration.traits == traits;
|
&& 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
|
class HasNameMatcher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -5644,4 +5659,29 @@ TEST_F(ProjectStorage, GetInvalidLocalPropertyDeclarationIdForWrongPropertyName)
|
|||||||
ASSERT_FALSE(propertyId);
|
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
|
} // namespace
|
||||||
|
Reference in New Issue
Block a user