QmlDesigner: Add singleton getter to model

Task-number: QDS-13601
Change-Id: Iaf97f18f98435b05a801453a7d253eba73eaa237
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2024-09-10 18:26:08 +02:00
parent fae113f5f8
commit ae1de42093
4 changed files with 33 additions and 6 deletions

View File

@@ -59,6 +59,8 @@ class TextModifier;
class ItemLibraryEntry; class ItemLibraryEntry;
using PropertyListType = QList<QPair<PropertyName, QVariant>>; using PropertyListType = QList<QPair<PropertyName, QVariant>>;
template<qsizetype size>
using SmallNodeMetaInfos = QVarLengthArray<NodeMetaInfo, size>;
enum class BypassModelResourceManagement { No, Yes }; enum class BypassModelResourceManagement { No, Yes };
@@ -201,7 +203,11 @@ public:
NodeMetaInfo vector2dMetaInfo() const; NodeMetaInfo vector2dMetaInfo() const;
NodeMetaInfo vector3dMetaInfo() const; NodeMetaInfo vector3dMetaInfo() const;
NodeMetaInfo vector4dMetaInfo() const; NodeMetaInfo vector4dMetaInfo() const;
QVarLengthArray<NodeMetaInfo, 256> metaInfosForModule(Module module) const;
#ifdef QDS_USE_PROJECTSTORAGE
SmallNodeMetaInfos<256> metaInfosForModule(Module module) const;
SmallNodeMetaInfos<256> singletonMetaInfos() const;
#endif
QList<ItemLibraryEntry> itemLibraryEntries() const; QList<ItemLibraryEntry> itemLibraryEntries() const;

View File

@@ -293,6 +293,8 @@ private:
}; };
using NodeMetaInfos = std::vector<NodeMetaInfo>; using NodeMetaInfos = std::vector<NodeMetaInfo>;
template<qsizetype size>
using SmallNodeMetaInfos = QVarLengthArray<NodeMetaInfo, size>;
} //QmlDesigner } //QmlDesigner

View File

@@ -2726,18 +2726,27 @@ NodeMetaInfo Model::vector4dMetaInfo() const
} }
} }
#ifdef QDS_USE_PROJECTSTORAGE
QVarLengthArray<NodeMetaInfo, 256> Model::metaInfosForModule(Module module) const QVarLengthArray<NodeMetaInfo, 256> Model::metaInfosForModule(Module module) const
{ {
if constexpr (useProjectStorage()) {
using namespace Storage::Info; using namespace Storage::Info;
return Utils::transform<QVarLengthArray<NodeMetaInfo, 256>>( return Utils::transform<QVarLengthArray<NodeMetaInfo, 256>>(
d->projectStorage->typeIds(module.id()), NodeMetaInfo::bind(d->projectStorage)); d->projectStorage->typeIds(module.id()), NodeMetaInfo::bind(d->projectStorage));
} else {
return {};
}
} }
SmallNodeMetaInfos<256> Model::singletonMetaInfos() const
{
using namespace Storage::Info;
return Utils::transform<QVarLengthArray<NodeMetaInfo, 256>>(d->projectStorage->singletonTypeIds(
d->m_sourceId),
NodeMetaInfo::bind(d->projectStorage));
}
#endif
QList<ItemLibraryEntry> Model::itemLibraryEntries() const QList<ItemLibraryEntry> Model::itemLibraryEntries() const
{ {
#ifdef QDS_USE_PROJECTSTORAGE #ifdef QDS_USE_PROJECTSTORAGE

View File

@@ -1095,13 +1095,23 @@ TEST_F(Model_MetaInfo, meta_infos_for_mdoule)
auto module = model.module("Foo", ModuleKind::QmlLibrary); auto module = model.module("Foo", ModuleKind::QmlLibrary);
auto typeId = projectStorageMock.createObject(module.id(), "Bar"); auto typeId = projectStorageMock.createObject(module.id(), "Bar");
ON_CALL(projectStorageMock, typeIds(module.id())) ON_CALL(projectStorageMock, typeIds(module.id()))
.WillByDefault(Return(QVarLengthArray<QmlDesigner::TypeId, 256>{typeId})); .WillByDefault(Return(QmlDesigner::SmallTypeIds<256>{typeId}));
auto types = model.metaInfosForModule(module); auto types = model.metaInfosForModule(module);
ASSERT_THAT(types, ElementsAre(Eq(QmlDesigner::NodeMetaInfo{typeId, &projectStorageMock}))); ASSERT_THAT(types, ElementsAre(Eq(QmlDesigner::NodeMetaInfo{typeId, &projectStorageMock})));
} }
TEST_F(Model_MetaInfo, singleton_meta_infos)
{
ON_CALL(projectStorageMock, singletonTypeIds(filePathId))
.WillByDefault(Return(QmlDesigner::SmallTypeIds<256>{itemTypeId}));
auto types = model.singletonMetaInfos();
ASSERT_THAT(types, ElementsAre(Eq(QmlDesigner::NodeMetaInfo{itemTypeId, &projectStorageMock})));
}
TEST_F(Model_MetaInfo, create_node_resolved_meta_type) TEST_F(Model_MetaInfo, create_node_resolved_meta_type)
{ {
auto node = model.createModelNode("Item"); auto node = model.createModelNode("Item");