15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_MODEL_SESSIONITEM_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_MODEL_SESSIONITEM_H
22 #include "mvvm/model_export.h"
49 std::string identifier()
const;
52 virtual std::string displayName()
const;
74 int childrenCount()
const;
76 std::vector<SessionItem*> children()
const;
78 int itemCount(
const std::string& tag)
const;
80 SessionItem* getItem(
const std::string& tag,
int row = 0)
const;
82 std::vector<SessionItem*> getItems(
const std::string& tag)
const;
84 template <
typename T> T* item(
const std::string& tag)
const;
85 template <
typename T = SessionItem> std::vector<T*> items(
const std::string& tag)
const;
89 void registerTag(
const TagInfo& tagInfo,
bool set_as_default =
false);
102 bool isEditable()
const;
105 bool isEnabled()
const;
108 std::string toolTip()
const;
109 SessionItem* setToolTip(
const std::string& tooltip);
111 std::string editorType()
const;
112 SessionItem* setEditorType(
const std::string& editor_type);
114 template <
typename T> T property(
const std::string& tag)
const;
115 template <
typename T>
void setProperty(
const std::string& tag,
const T& value);
116 void setProperty(
const std::string& tag,
const char* value);
124 bool set_data_internal(
const Variant& value,
int role,
bool direct);
125 Variant data_internal(
int role)
const;
128 void setAppearanceFlag(
int flag,
bool value);
130 void setDataAndTags(std::unique_ptr<SessionItemData> data,
131 std::unique_ptr<SessionItemTags> tags);
133 struct SessionItemImpl;
159 T* tag_item =
dynamic_cast<T*
>(
item);
161 throw std::runtime_error(
"Can't cast an item to given type");
171 std::vector<T*> result;
173 if (
auto casted =
dynamic_cast<T*
>(
item); casted)
174 result.push_back(casted);
Provides notifications on various changes for a specific item.
Converter between SessionItem and JSON object.
Handles data roles for SessionItem.
The main object representing an editable/displayable/serializable entity.
std::unique_ptr< SessionItemImpl > p_impl
std::vector< SessionItem * > getItems(const std::string &tag) const
Returns all children stored at given tag.
SessionItem & operator=(const SessionItem &)=delete
SessionItem * getItem(const std::string &tag, int row=0) const
Returns item at given row of given tag.
std::vector< T * > items(const std::string &tag) const
Returns all items under given tag casted to specific type.
bool setData(const T &value, int role=ItemDataRole::DATA, bool direct=false)
Sets data for a given role.
bool set_data_internal(const Variant &value, int role, bool direct)
Sets the data for given role. Method invented to hide implementaiton details.
T data(int role=ItemDataRole::DATA) const
Returns data of given type T for given role.
SessionItem(const SessionItem &)=delete
T property(const std::string &tag) const
Returns data stored in property item.
T * item(const std::string &tag) const
Returns first item under given tag casted to a specified type.
Variant data_internal(int role) const
Returns data for given role.
void setProperty(const std::string &tag, const T &value)
Sets value to property item.
Main class to hold hierarchy of SessionItem objects.
Holds info about single tag for SessionItem.
Aggregate to hold (tag, row) information for SessionModel.
Handles all data roles for SessionItem.
const model_type BaseType
const int DATA
main data role
materialitems.h Collection of materials to populate MaterialModel.
QString const & name(EShape k)