![]() |
LeechCraft
0.6.70-13729-g7046a9d2a7
Modular cross-platform feature rich live environment.
|
Base class for model items for tree-like models. More...
#include "modelitembase.h"
Public Types | |
using | iterator = typename TList_t::iterator |
A non-const iterator for the list of children. More... | |
using | const_iterator = typename TList_t::const_iterator |
A const iterator for the list of children. More... | |
Public Member Functions | |
iterator | begin () |
Returns a non-const iterator pointing to the beginning of the child items list. More... | |
iterator | end () |
Returns a non-const iterator pointing past the last child item. More... | |
const_iterator | begin () const |
Returns a const iterator pointing to the beginning of the child items list. More... | |
const_iterator | end () const |
Returns a const iterator pointing past the last child item. More... | |
T_ptr | GetChild (int row) const |
Returns a child at the given row. More... | |
const TList_t & | GetChildren () const |
Returns a constant reference to the list of children. More... | |
TList_t & | GetChildren () |
Returns a non-constant reference to the list of children. More... | |
int | GetRowCount () const |
Returns the children count. More... | |
bool | IsEmpty () const |
Returns whether there are any children at all. More... | |
iterator | EraseChild (iterator it) |
Erases a child item at the position defined by it. More... | |
iterator | EraseChildren (iterator begin, iterator end) |
Erases all child items in the given range. More... | |
void | AppendExisting (const T_ptr &t) |
Appends a child item t to the list of child items. More... | |
void | AppendExisting (const TList_t &items) |
Appends a list of items to the list of child items. More... | |
template<typename... Args> | |
T_ptr & | AppendChild (Args &&... args) |
Creates a new child item, appends it and returns it. More... | |
template<typename... Args> | |
T_ptr & | InsertChild (int pos, Args &&... args) |
Creates a new child item, inserts it at the given position and returns it. More... | |
T_ptr | GetParent () const |
Returns the pointer to the parent item. More... | |
int | GetRow (const T_ptr &item) const |
Returns the index of the item in the children list. More... | |
int | GetRow (const T_cptr &item) const |
Returns the index of the item in the children list. More... | |
int | GetRow () const |
Returns the index of this item in the parent's children list. More... | |
Protected Types | |
using | T_wptr = std::weak_ptr< T > |
using | T_ptr = std::shared_ptr< T > |
using | T_cptr = std::shared_ptr< const T > |
using | TList_t = QVector< T_ptr > |
Protected Member Functions | |
ModelItemBase ()=default | |
Constructs a default ModelItemBase with no parent. More... | |
ModelItemBase (const T_wptr &parent) | |
Constructs a ModelItemBase with a given parent item. More... | |
Protected Attributes | |
T_wptr | Parent_ |
TList_t | Children_ |
Base class for model items for tree-like models.
A ModelItemBase only manages its children items and keeps track of its parent item. It does not contain any data itself.
This class is intended to be a base class for some concreted model item implementation (see ModelItem class for an example). In particular it cannot be instantiated itself since its constructors are protected.
The lifetime of the items is also managed. Shared pointers are used for this: the ModelItemBase stores a list of shared pointers to its children and a weak pointer to its parent.
In particular, child items are automatically deleted when they are removed from the children list of an item via EraseChild() or EraseChildren() functions, unless a shared pointer reference is kept to a child. A new child can be added via AppendChild(), InsertChild() or AppendExisting().
An STL iterator-like interface to the children is also provided, so a ModelItemBase can also be used in a range-for loop.
T | The type of the class derived from ModelItemBase. |
Definition at line 69 of file modelitembase.h.
using LC::Util::ModelItemBase< T >::const_iterator = typename TList_t::const_iterator |
A const iterator for the list of children.
Definition at line 99 of file modelitembase.h.
using LC::Util::ModelItemBase< T >::iterator = typename TList_t::iterator |
A non-const iterator for the list of children.
Definition at line 95 of file modelitembase.h.
|
protected |
Definition at line 74 of file modelitembase.h.
|
protected |
Definition at line 73 of file modelitembase.h.
|
protected |
Definition at line 72 of file modelitembase.h.
|
protected |
Definition at line 75 of file modelitembase.h.
|
protecteddefault |
Constructs a default ModelItemBase with no parent.
|
inlineprotected |
Constructs a ModelItemBase with a given parent item.
[in] | parent | The weak reference to the parent item. |
Definition at line 88 of file modelitembase.h.
|
inline |
Creates a new child item, appends it and returns it.
Args | The types of the arguments to the constructor of of the model. |
[in] | args | The arguments to the constructor of the model item type T. |
Definition at line 275 of file modelitembase.h.
|
inline |
Appends a child item t to the list of child items.
This function invalidates all iterators.
[in] | t | The child item to append. |
Definition at line 244 of file modelitembase.h.
|
inline |
Appends a list of items to the list of child items.
This function invalidates all iterators.
[in] | items | The list of items to append. |
Definition at line 258 of file modelitembase.h.
|
inline |
Returns a non-const iterator pointing to the beginning of the child items list.
Definition at line 107 of file modelitembase.h.
Referenced by LC::Util::ModelItemBase< ModelItem >::EraseChildren().
|
inline |
Returns a const iterator pointing to the beginning of the child items list.
Definition at line 128 of file modelitembase.h.
|
inline |
Returns a non-const iterator pointing past the last child item.
Definition at line 117 of file modelitembase.h.
Referenced by LC::Util::ModelItemBase< ModelItem >::EraseChildren().
|
inline |
Returns a const iterator pointing past the last child item.
Definition at line 138 of file modelitembase.h.
|
inline |
Erases a child item at the position defined by it.
If it is invalid iterator, the behavior is undefined.
This function invalidates all iterators.
[in] | it | The iterator pointing to the child to be erased. |
Definition at line 206 of file modelitembase.h.
|
inline |
Erases all child items in the given range.
The range is half-open, comprised of items in the [begin; end)
range of iterators.
If the range contains invalid iterators, the behavior is undefined.
This function invalidates all iterators.
[in] | begin | The iterator pointing to the first item to be erased. |
[in] | end | The iterator pointing past the last item to be erased. |
Definition at line 230 of file modelitembase.h.
|
inline |
Returns a child at the given row.
If there is no child at the given row, returns a null shared_ptr.
[in] | row | The index of the child to be returned. |
Definition at line 152 of file modelitembase.h.
|
inline |
Returns a constant reference to the list of children.
Definition at line 161 of file modelitembase.h.
|
inline |
Returns a non-constant reference to the list of children.
Definition at line 170 of file modelitembase.h.
|
inline |
Returns the pointer to the parent item.
Definition at line 308 of file modelitembase.h.
Referenced by LC::Util::ModelItemBase< ModelItem >::GetRow().
|
inline |
Returns the index of the item in the children list.
Definition at line 318 of file modelitembase.h.
|
inline |
Returns the index of the item in the children list.
Definition at line 328 of file modelitembase.h.
|
inline |
Returns the index of this item in the parent's children list.
If the parent is already deleted or there is no parent, -1 is returned.
Definition at line 345 of file modelitembase.h.
|
inline |
Returns the children count.
Definition at line 179 of file modelitembase.h.
|
inline |
Creates a new child item, inserts it at the given position and returns it.
Args | The types of the arguments to the constructor of of the model. |
[in] | pos | The index where the newly created item should be inserted. |
[in] | args | The arguments to the constructor of the model item type T. |
Definition at line 296 of file modelitembase.h.
|
inline |
Returns whether there are any children at all.
Definition at line 189 of file modelitembase.h.
|
protected |
Definition at line 78 of file modelitembase.h.
Referenced by LC::Util::ModelItemBase< ModelItem >::AppendChild(), LC::Util::ModelItemBase< ModelItem >::AppendExisting(), LC::Util::ModelItemBase< ModelItem >::begin(), LC::Util::ModelItemBase< ModelItem >::end(), LC::Util::ModelItemBase< ModelItem >::EraseChild(), LC::Util::ModelItemBase< ModelItem >::EraseChildren(), LC::Util::ModelItemBase< ModelItem >::GetChild(), LC::Util::ModelItemBase< ModelItem >::GetChildren(), LC::Util::ModelItemBase< ModelItem >::GetRow(), LC::Util::ModelItemBase< ModelItem >::GetRowCount(), LC::Util::ModelItemBase< ModelItem >::InsertChild(), and LC::Util::ModelItemBase< ModelItem >::IsEmpty().
|
protected |
Definition at line 77 of file modelitembase.h.
Referenced by LC::Util::ModelItemBase< ModelItem >::GetParent().