![]() |
LeechCraft
0.6.70-13605-g8cd066ad6a
Modular cross-platform feature rich live environment.
|
Base class for model items for tree-like models. More...
#include "modelitembase.h"
Inheritance diagram for LC::Util::ModelItemBase< T >:
Collaboration diagram for LC::Util::ModelItemBase< T >: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 120 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 176 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 172 of file modelitembase.h.
|
protected |
Definition at line 151 of file modelitembase.h.
|
protected |
Definition at line 150 of file modelitembase.h.
|
protected |
Definition at line 149 of file modelitembase.h.
|
protected |
Definition at line 152 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 165 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 352 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 321 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 335 of file modelitembase.h.
|
inline |
Returns a non-const iterator pointing to the beginning of the child items list.
Definition at line 184 of file modelitembase.h.
|
inline |
Returns a const iterator pointing to the beginning of the child items list.
Definition at line 205 of file modelitembase.h.
|
inline |
Returns a non-const iterator pointing past the last child item.
Definition at line 194 of file modelitembase.h.
|
inline |
Returns a const iterator pointing past the last child item.
Definition at line 215 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 283 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 307 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 229 of file modelitembase.h.
|
inline |
Returns a non-constant reference to the list of children.
Definition at line 247 of file modelitembase.h.
|
inline |
Returns a constant reference to the list of children.
Definition at line 238 of file modelitembase.h.
|
inline |
Returns the pointer to the parent item.
Definition at line 385 of file modelitembase.h.
Referenced by LC::Util::ModelItemBase< ModelItem >::AppendExisting().
Here is the caller graph for this function:
|
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 422 of file modelitembase.h.
|
inline |
Returns the index of the item in the children list.
Definition at line 405 of file modelitembase.h.
|
inline |
Returns the index of the item in the children list.
Definition at line 395 of file modelitembase.h.
|
inline |
Returns the children count.
Definition at line 256 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 373 of file modelitembase.h.
|
inline |
Returns whether there are any children at all.
Definition at line 266 of file modelitembase.h.
|
protected |
Definition at line 155 of file modelitembase.h.
|
protected |
Definition at line 154 of file modelitembase.h.