15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_MODEL_MODELUTILS_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_MODEL_MODELUTILS_H
22 #include "mvvm/model_export.h"
36 std::vector<T*> result;
38 if (
auto item =
dynamic_cast<T*
>(child); item)
39 result.push_back(item);
49 auto items = TopItems<T>(model);
50 return items.empty() ? nullptr : items.front();
57 std::vector<T*> result;
60 if (
auto concrete =
dynamic_cast<T*
>(item); concrete)
61 result.push_back(concrete);
81 template <
typename T = SessionModel> std::unique_ptr<T>
CreateCopy(
const T& model)
83 auto result = std::make_unique<T>();
90 template <
typename T = SessionModel> std::unique_ptr<T>
CreateClone(
const T& model)
92 auto result = std::make_unique<T>();
Base class for all converters of SessionModel to/from json object.
Supports navigation through SessionModel.
The main object representing an editable/displayable/serializable entity.
std::vector< SessionItem * > children() const
Returns vector of children formed from all chidlren from all tags.
Main class to hold hierarchy of SessionItem objects.
SessionItem * rootItem() const
Returns root item of the model.
std::unique_ptr< T > CreateCopy(const T &model)
Creates full deep copy of given model. All item's ID will be generated.
MVVM_MODEL_EXPORT void EndMacros(const SessionItem *item)
Finishes undo/redo macros.
MVVM_MODEL_EXPORT void MoveDown(SessionItem *item)
Moves item down (increments row of the item). Works on children belonging to single tag.
MVVM_MODEL_EXPORT void BeginMacros(const SessionItem *item, const std::string ¯o_name)
Begin undo/redo macros with given name.
MVVM_MODEL_EXPORT void iterate(SessionItem *item, const std::function< void(SessionItem *)> &fun)
Iterates through item and all its children.
MVVM_MODEL_EXPORT void MoveUp(SessionItem *item)
Moves item up (decrements row of the item). Works on children belonging to single tag.
MVVM_MODEL_EXPORT SessionItem * ItemFromPath(const SessionModel &moodel, const Path &path)
Returns item found in the model following given Path.
T * TopItem(const SessionModel *model)
Returns top level item of given type.
std::unique_ptr< T > CreateClone(const T &model)
Creates exact clone of given model. All item's ID will be preserved.
MVVM_MODEL_EXPORT void Undo(SessionModel &model)
Undo last model operation. If not undo/redo enabled, will do nothing.
MVVM_MODEL_EXPORT Path PathFromItem(const SessionItem *item)
Constructs path to find given item. Item must belong to a model.
MVVM_MODEL_EXPORT void Redo(SessionModel &model)
Redo model operation which was undone just before. If not undo/redo enabled, will do nothing.
std::vector< T * > FindItems(const SessionModel *model)
Returns all items in a tree of given type.
std::vector< T * > TopItems(const SessionModel *model)
Returns all top level items of given type.
MVVM_MODEL_EXPORT void PopulateEmptyModel(const JsonModelConverterInterface *converter, const SessionModel &source, SessionModel &target)
Populate empty model with content of target model using provided converter.
MVVM_MODEL_EXPORT void DeleteItemFromModel(SessionItem *item)
Removes and deletes item from its model.
materialitems.h Collection of materials to populate MaterialModel.
MVVM_MODEL_EXPORT std::unique_ptr< JsonModelConverterInterface > CreateModelCopyConverter()
Creates a JSON model converter intended for model copying.
MVVM_MODEL_EXPORT std::unique_ptr< JsonModelConverterInterface > CreateModelCloneConverter()
Creates a JSON model converter intended for model cloning.