15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_MODEL_SESSIONMODEL_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_MODEL_SESSIONMODEL_H
23 #include "mvvm/model_export.h"
32 class ItemFactoryInterface;
33 class UndoStackInterface;
47 const TagRow& tagrow = {});
49 template <
typename T> T* insertItem(
SessionItem* parent =
nullptr,
const TagRow& tagrow = {});
51 void removeItem(
SessionItem* parent,
const TagRow& tagrow);
63 std::string modelType()
const;
69 UndoStackInterface* undoStack()
const;
71 const ItemFactoryInterface* factory()
const;
75 template <
typename T = SessionItem> std::vector<T*> topItems()
const;
77 template <
typename T = SessionItem> T* topItem()
const;
81 void setItemCatalogue(std::unique_ptr<ItemCatalogue> catalogue);
83 void setUndoRedoEnabled(
bool value);
85 void clear(std::function<
void(
SessionItem*)> callback = {});
87 template <
typename T>
void registerItem(
const std::string& label = {});
96 const std::string& label);
98 struct SessionModelImpl;
99 std::unique_ptr<SessionModelImpl>
p_impl;
106 return static_cast<T*
>(
intern_insert(ItemFactoryFunction<T>(), parent, tagrow));
114 std::vector<T*> result;
115 for (
auto child :
rootItem()->children()) {
116 if (
auto item =
dynamic_cast<T*
>(child))
117 result.push_back(item);
128 auto items = topItems<T>();
129 return items.empty() ? nullptr : items.front();
The main object representing an editable/displayable/serializable entity.
Main class to hold hierarchy of SessionItem objects.
SessionModel(const SessionModel &other)=delete
T * topItem() const
Returns top item of the given type.
std::vector< T * > topItems() const
Returns top items of the given type.
std::string modelType() const
Returns model type.
SessionModel & operator=(const SessionModel &other)=delete
void intern_register(const model_type &modelType, const item_factory_func_t &func, const std::string &label)
std::unique_ptr< SessionModelImpl > p_impl
SessionItem * intern_insert(const item_factory_func_t &func, SessionItem *parent, const TagRow &tagrow)
Insert new item into given parent using factory function provided.
SessionItem * rootItem() const
Returns root item of the model.
void registerItem(const std::string &label={})
Register used defined item to use with the model.
T * insertItem(SessionItem *parent=nullptr, const TagRow &tagrow={})
Inserts item into given parent under given tagrow.
Aggregate to hold (tag, row) information for SessionModel.
SessionItem * parent() const
Returns parent of this item.
T * item(const QString &tag) const
QString modelType() const
Get model type.
materialitems.h Collection of materials to populate MaterialModel.
std::function< std::unique_ptr< SessionItem >()> item_factory_func_t
Definition for item factory funciton.
std::string identifier_type