diff --git a/src/plugins/qmldesigner/libs/designercore/include/model.h b/src/plugins/qmldesigner/libs/designercore/include/model.h index 534c0d7ed00..48ec5c7c4c0 100644 --- a/src/plugins/qmldesigner/libs/designercore/include/model.h +++ b/src/plugins/qmldesigner/libs/designercore/include/model.h @@ -59,6 +59,8 @@ class TextModifier; class ItemLibraryEntry; using PropertyListType = QList>; +template +using SmallNodeMetaInfos = QVarLengthArray; enum class BypassModelResourceManagement { No, Yes }; @@ -201,7 +203,11 @@ public: NodeMetaInfo vector2dMetaInfo() const; NodeMetaInfo vector3dMetaInfo() const; NodeMetaInfo vector4dMetaInfo() const; - QVarLengthArray metaInfosForModule(Module module) const; + +#ifdef QDS_USE_PROJECTSTORAGE + SmallNodeMetaInfos<256> metaInfosForModule(Module module) const; + SmallNodeMetaInfos<256> singletonMetaInfos() const; +#endif QList itemLibraryEntries() const; diff --git a/src/plugins/qmldesigner/libs/designercore/include/nodemetainfo.h b/src/plugins/qmldesigner/libs/designercore/include/nodemetainfo.h index 43c2eebb651..149adfc37e9 100644 --- a/src/plugins/qmldesigner/libs/designercore/include/nodemetainfo.h +++ b/src/plugins/qmldesigner/libs/designercore/include/nodemetainfo.h @@ -293,6 +293,8 @@ private: }; using NodeMetaInfos = std::vector; +template +using SmallNodeMetaInfos = QVarLengthArray; } //QmlDesigner diff --git a/src/plugins/qmldesigner/libs/designercore/model/model.cpp b/src/plugins/qmldesigner/libs/designercore/model/model.cpp index f77bab2a3c4..ed933550008 100644 --- a/src/plugins/qmldesigner/libs/designercore/model/model.cpp +++ b/src/plugins/qmldesigner/libs/designercore/model/model.cpp @@ -2726,18 +2726,27 @@ NodeMetaInfo Model::vector4dMetaInfo() const } } +#ifdef QDS_USE_PROJECTSTORAGE + QVarLengthArray Model::metaInfosForModule(Module module) const { - if constexpr (useProjectStorage()) { using namespace Storage::Info; return Utils::transform>( d->projectStorage->typeIds(module.id()), NodeMetaInfo::bind(d->projectStorage)); - } else { - return {}; - } } +SmallNodeMetaInfos<256> Model::singletonMetaInfos() const +{ + using namespace Storage::Info; + + return Utils::transform>(d->projectStorage->singletonTypeIds( + d->m_sourceId), + NodeMetaInfo::bind(d->projectStorage)); +} + +#endif + QList Model::itemLibraryEntries() const { #ifdef QDS_USE_PROJECTSTORAGE diff --git a/tests/unit/tests/unittests/model/model-test.cpp b/tests/unit/tests/unittests/model/model-test.cpp index 4ea64c3ba33..b6d453e74de 100644 --- a/tests/unit/tests/unittests/model/model-test.cpp +++ b/tests/unit/tests/unittests/model/model-test.cpp @@ -1095,13 +1095,23 @@ TEST_F(Model_MetaInfo, meta_infos_for_mdoule) auto module = model.module("Foo", ModuleKind::QmlLibrary); auto typeId = projectStorageMock.createObject(module.id(), "Bar"); ON_CALL(projectStorageMock, typeIds(module.id())) - .WillByDefault(Return(QVarLengthArray{typeId})); + .WillByDefault(Return(QmlDesigner::SmallTypeIds<256>{typeId})); auto types = model.metaInfosForModule(module); 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) { auto node = model.createModelNode("Item");