52 m_itemManager->setItemPool(pool ? std::move(pool) : std::make_shared<ItemPool>());
58 m_root_item = m_itemManager->createRootItem();
59 m_root_item->setModel(m_self);
79 p_impl->m_root_item.reset();
81 p_impl->m_mapper->callOnModelDestroyed();
98 p_impl->m_commands->removeItem(parent, tagrow);
106 p_impl->m_commands->moveItem(item, new_parent, tagrow);
114 return p_impl->m_commands->copyItem(item, parent, tagrow);
128 return p_impl->m_commands->setData(item, value, role);
135 return p_impl->m_modelType;
142 return p_impl->m_root_item.get();
149 return p_impl->m_mapper.get();
156 return p_impl->m_commands->undoStack();
163 return p_impl->m_itemManager->factory();
170 return p_impl->m_itemManager->findItem(
id);
179 std::unique_ptr<ItemCatalogue> full_catalogue = std::move(catalogue);
181 p_impl->m_itemManager->setItemFactory(std::make_unique<ItemFactory>(std::move(full_catalogue)));
188 p_impl->m_commands->setUndoRedoEnabled(value);
209 p_impl->m_itemManager->registerInPool(item);
217 p_impl->m_itemManager->unregisterFromPool(item);
225 return p_impl->m_commands->insertNewItem(func, parent, tagrow);
229 const std::string& label)
231 p_impl->m_itemManager->factory()->registerItem(
modelType, func, label);
Provides undo/redo for all commands of SessionModel.
Interface class for all factories capable of producing SessionItem's.
virtual std::unique_ptr< SessionItem > createItem(const model_type &modelType) const =0
Manages item creation/registration for SessionModel.
Provides notifications on various SessionModel changes.
void callOnModelAboutToBeReset()
The main object representing an editable/displayable/serializable entity.
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
Main class to hold hierarchy of SessionItem objects.
bool setData(SessionItem *item, const Variant &value, int role)
Sets the data for given item.
void unregisterFromPool(SessionItem *item)
Unregister item from pool.
ModelMapper * mapper()
Returns model mapper. Can be used to subscribe to various model's signal.
std::string modelType() const
Returns model type.
SessionItem * insertNewItem(const model_type &modelType, SessionItem *parent=nullptr, const TagRow &tagrow={})
Insert new item using item's modelType.
void setUndoRedoEnabled(bool value)
Sets undo/redo either enabled or disabled. By default undo/redo is disabled.
void moveItem(SessionItem *item, SessionItem *new_parent, const TagRow &tagrow)
Move item from it's current parent to a new parent under given tag and row.
SessionItem * findItem(const identifier_type &id)
Returns SessionItem for given identifier.
SessionModel(std::string model_type={}, std::shared_ptr< ItemPool > pool={})
Main c-tor.
const ItemFactoryInterface * factory() const
Returns item factory which can generate all items supported by this model.
void registerInPool(SessionItem *item)
Registers item in pool. This will allow to find item pointer using its unique identifier.
SessionItem * copyItem(const SessionItem *item, SessionItem *parent, const TagRow &tagrow={})
Copy item and insert it in parent's tag and row. Item could belong to any model/parent.
void intern_register(const model_type &modelType, const item_factory_func_t &func, const std::string &label)
std::unique_ptr< SessionModelImpl > p_impl
void setItemCatalogue(std::unique_ptr< ItemCatalogue > catalogue)
Sets brand new catalog of user-defined items.
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.
UndoStackInterface * undoStack() const
Returns command stack to perform undo/redo.
Variant data(SessionItem *item, int role) const
Returns the data for given item and role.
void clear(std::function< void(SessionItem *)> callback={})
Removes all items from the model.
void removeItem(SessionItem *parent, const TagRow &tagrow)
Removes given row from parent.
static TagInfo universalTag(std::string name, std::vector< std::string > modelTypes={})
Constructs universal tag intended for unlimited amount of various items.
Aggregate to hold (tag, row) information for SessionModel.
Interface class for undo/redo stack.
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
MVVM_MODEL_EXPORT std::unique_ptr< ItemCatalogue > CreateStandardItemCatalogue()
Creates a catalog of items supported by SessionModel out-of-the-box.
Pimpl class for SessionModel.
void createRootItem()
Creates root item.
std::unique_ptr< ItemManager > m_itemManager
std::unique_ptr< SessionItem > m_root_item
std::unique_ptr< ModelMapper > m_mapper
std::unique_ptr< CommandService > m_commands
void setItemPool(std::shared_ptr< ItemPool > pool)
SessionModelImpl(SessionModel *self, std::string modelType, std::shared_ptr< ItemPool > pool)