forked from qt-creator/qt-creator
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:
@@ -59,6 +59,8 @@ class TextModifier;
|
||||
class ItemLibraryEntry;
|
||||
|
||||
using PropertyListType = QList<QPair<PropertyName, QVariant>>;
|
||||
template<qsizetype size>
|
||||
using SmallNodeMetaInfos = QVarLengthArray<NodeMetaInfo, size>;
|
||||
|
||||
enum class BypassModelResourceManagement { No, Yes };
|
||||
|
||||
@@ -201,7 +203,11 @@ public:
|
||||
NodeMetaInfo vector2dMetaInfo() const;
|
||||
NodeMetaInfo vector3dMetaInfo() 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;
|
||||
|
||||
|
@@ -293,6 +293,8 @@ private:
|
||||
};
|
||||
|
||||
using NodeMetaInfos = std::vector<NodeMetaInfo>;
|
||||
template<qsizetype size>
|
||||
using SmallNodeMetaInfos = QVarLengthArray<NodeMetaInfo, size>;
|
||||
|
||||
} //QmlDesigner
|
||||
|
||||
|
@@ -2726,18 +2726,27 @@ NodeMetaInfo Model::vector4dMetaInfo() const
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef QDS_USE_PROJECTSTORAGE
|
||||
|
||||
QVarLengthArray<NodeMetaInfo, 256> Model::metaInfosForModule(Module module) const
|
||||
{
|
||||
if constexpr (useProjectStorage()) {
|
||||
using namespace Storage::Info;
|
||||
|
||||
return Utils::transform<QVarLengthArray<NodeMetaInfo, 256>>(
|
||||
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
|
||||
{
|
||||
#ifdef QDS_USE_PROJECTSTORAGE
|
||||
|
@@ -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<QmlDesigner::TypeId, 256>{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");
|
||||
|
Reference in New Issue
Block a user