LeechCraft
0.6.70-15082-g543737046d
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 52 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 88 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 84 of file modelitembase.h.
|
protected |
Definition at line 63 of file modelitembase.h.
|
protected |
Definition at line 62 of file modelitembase.h.
|
protected |
Definition at line 61 of file modelitembase.h.
|
protected |
Definition at line 64 of file modelitembase.h.
|
protecteddefault |
Constructs a default ModelItemBase with no parent.
|
inlineexplicitprotected |
Constructs a ModelItemBase with a given parent item.
[in] | parent | The weak reference to the parent item. |
Definition at line 77 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 264 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 233 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 247 of file modelitembase.h.
|
inline |
Returns a non-const iterator pointing to the beginning of the child items list.
Definition at line 96 of file modelitembase.h.
|
inline |
Returns a const iterator pointing to the beginning of the child items list.
Definition at line 117 of file modelitembase.h.
|
inline |
Returns a non-const iterator pointing past the last child item.
Definition at line 106 of file modelitembase.h.
|
inline |
Returns a const iterator pointing past the last child item.
Definition at line 127 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 195 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 219 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 141 of file modelitembase.h.
|
inline |
Returns a non-constant reference to the list of children.
Definition at line 159 of file modelitembase.h.
|
inline |
Returns a constant reference to the list of children.
Definition at line 150 of file modelitembase.h.
|
inline |
Returns the pointer to the parent item.
Definition at line 297 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 334 of file modelitembase.h.
|
inline |
Returns the index of the item in the children list.
Definition at line 317 of file modelitembase.h.
|
inline |
Returns the index of the item in the children list.
Definition at line 307 of file modelitembase.h.
|
inline |
Returns the children count.
Definition at line 168 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 285 of file modelitembase.h.
|
inline |
Returns whether there are any children at all.
Definition at line 178 of file modelitembase.h.
|
protected |
Definition at line 67 of file modelitembase.h.
Referenced by LC::Util::ModelItemBase< ModelItem >::end().
|
protected |
Definition at line 66 of file modelitembase.h.
Referenced by LC::Util::ModelItemBase< ModelItem >::InsertChild().