forked from qt-creator/qt-creator
QmlDesigner: Add is singleton to NodeMetaInfo
Change-Id: Icb657fd326b25a6d9c7f2e73dc35df5c4df42c1e Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
ee05b2a65a
commit
c110aab7a1
@@ -75,6 +75,7 @@ public:
|
||||
|
||||
MetaInfoType type() const;
|
||||
bool isFileComponent() const;
|
||||
bool isSingleton() const;
|
||||
FlagIs canBeContainer() const;
|
||||
FlagIs forceClip() const;
|
||||
FlagIs doesLayoutChildren() const;
|
||||
|
@@ -1527,6 +1527,26 @@ bool NodeMetaInfo::isFileComponent() const
|
||||
}
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isSingleton() const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
if (!isValid())
|
||||
return {};
|
||||
|
||||
using NanotraceHR::keyValue;
|
||||
NanotraceHR::Tracer tracer{"is singleton", category(), keyValue("type id", m_typeId)};
|
||||
|
||||
auto isSingleton = typeData().traits.isSingleton;
|
||||
|
||||
tracer.end(keyValue("is singleton", isSingleton));
|
||||
|
||||
return isSingleton;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
FlagIs NodeMetaInfo::canBeContainer() const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
|
@@ -236,6 +236,43 @@ TEST_F(NodeMetaInfo, component_is_file_component)
|
||||
ASSERT_TRUE(isFileComponent);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, object_is_not_singleton)
|
||||
{
|
||||
bool isSingleton = objectMetaInfo.isSingleton();
|
||||
|
||||
ASSERT_FALSE(isSingleton);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, default_is_not_ingleton)
|
||||
{
|
||||
bool isSingleton = QmlDesigner::NodeMetaInfo{}.isFileComponent();
|
||||
|
||||
ASSERT_FALSE(isSingleton);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, invalid_is_not_singleton)
|
||||
{
|
||||
auto node = model.createModelNode("Foo");
|
||||
auto metaInfo = node.metaInfo();
|
||||
|
||||
bool isSingleton = metaInfo.isSingleton();
|
||||
|
||||
ASSERT_FALSE(isSingleton);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, component_is_singleton)
|
||||
{
|
||||
auto moduleId = projectStorageMock.createModule("/path/to/project", ModuleKind::PathLibrary);
|
||||
TypeTraits traits{TypeTraitsKind::Reference};
|
||||
traits.isSingleton = true;
|
||||
auto typeId = projectStorageMock.createType(moduleId, "Foo", traits);
|
||||
QmlDesigner::NodeMetaInfo metaInfo{typeId, &projectStorageMock};
|
||||
|
||||
bool isSingleton = metaInfo.isSingleton();
|
||||
|
||||
ASSERT_TRUE(isSingleton);
|
||||
}
|
||||
|
||||
TEST_F(NodeMetaInfo, has_property)
|
||||
{
|
||||
auto metaInfo = model.qtQuickItemMetaInfo();
|
||||
|
Reference in New Issue
Block a user