73 using T_ptr = std::shared_ptr<T>;
74 using T_cptr = std::shared_ptr<const T>;
109 return Children_.begin ();
119 return Children_.end ();
130 return Children_.begin ();
140 return Children_.end ();
154 return Children_.value (row);
181 return Children_.size ();
191 return Children_.isEmpty ();
208 return Children_.erase (it);
232 return Children_.erase (begin, end);
274 template<
typename... Args>
277 Children_.append (std::make_shared<T> (std::forward<Args> (args)...));
278 return Children_.last ();
295 template<
typename... Args>
298 Children_.insert (pos, std::make_shared<T> (std::forward<Args> (args)...));
299 return Children_ [
pos];
310 return Parent_.lock ();
320 return Children_.indexOf (item);
330 const auto pos = std::find (Children_.begin (), Children_.end (), item);
331 return pos == Children_.end () ?
333 std::distance (Children_.begin (),
pos);
350 return parent->GetRow (this->shared_from_this ());
T_ptr GetParent() const
Returns the pointer to the parent item.
ModelItemBase(const T_wptr &parent)
Constructs a ModelItemBase with a given parent item.
int GetRowCount() const
Returns the children count.
TList_t & GetChildren()
Returns a non-constant reference to the list of children.
std::weak_ptr< ModelItem > T_wptr
iterator EraseChildren(iterator begin, iterator end)
Erases all child items in the given range.
detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, boost::mpl::int_< Idx >> pos
std::shared_ptr< const ModelItem > T_cptr
T_ptr & InsertChild(int pos, Args &&...args)
Creates a new child item, inserts it at the given position and returns it.
iterator end()
Returns a non-const iterator pointing past the last child item.
typename TList_t::iterator iterator
A non-const iterator for the list of children.
const_iterator begin() const
Returns a const iterator pointing to the beginning of the child items list.
T_ptr GetChild(int row) const
Returns a child at the given row.
std::shared_ptr< ModelItem > T_ptr
bool IsEmpty() const
Returns whether there are any children at all.
Base class for model items for tree-like models.
int GetRow(const T_ptr &item) const
Returns the index of the item in the children list.
const_iterator end() const
Returns a const iterator pointing past the last child item.
ModelItemBase()=default
Constructs a default ModelItemBase with no parent.
iterator begin()
Returns a non-const iterator pointing to the beginning of the child items list.
iterator EraseChild(iterator it)
Erases a child item at the position defined by it.
T_ptr & AppendChild(Args &&...args)
Creates a new child item, appends it and returns it.
void AppendExisting(const T_ptr &t)
Appends a child item t to the list of child items.
int GetRow() const
Returns the index of this item in the parent's children list.
void AppendExisting(const TList_t &items)
Appends a list of items to the list of child items.
int GetRow(const T_cptr &item) const
Returns the index of the item in the children list.
const TList_t & GetChildren() const
Returns a constant reference to the list of children.
typename TList_t::const_iterator const_iterator
A const iterator for the list of children.