LeechCraft  0.6.70-13729-g7046a9d2a7
Modular cross-platform feature rich live environment.
LC::Util::ModelItem Class Referencefinal

Provides a proxying API on top of an QAbstractItemModel. More...

#include "modelitem.h"

+ Inheritance diagram for LC::Util::ModelItem:
+ Collaboration diagram for LC::Util::ModelItem:

Public Types

typedef ModelItemsList_t::iterator iterator
 
typedef ModelItemsList_t::const_iterator const_iterator
 
- Public Types inherited from LC::Util::ModelItemBase< ModelItem >
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

 ModelItem ()=default
 Constructs a default (invalid) ModelItem having no model set. More...
 
 ModelItem (QAbstractItemModel *model, const QModelIndex &index, const ModelItem_wtr &parent)
 Constructs a ModelItem associated with a given index in the model. More...
 
ModelItemEnsureChild (int row)
 Ensures there is a child item at the given row. More...
 
const QModelIndex & GetIndex () const
 Returns the index this ModelItem instance wraps. More...
 
QAbstractItemModel * GetModel () const
 Returns the wrapped model. More...
 
void RefreshIndex (int modelStartingRow)
 Updates the wrapped index so that it points at the given row. More...
 
ModelItem_ptr FindChild (QModelIndex index) const
 Finds a child item for the given index. More...
 
- Public Member Functions inherited from LC::Util::ModelItemBase< ModelItem >
iterator begin ()
 Returns a non-const iterator pointing to the beginning of the child items list. More...
 
const_iterator begin () const
 Returns a 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 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_tGetChildren () const
 Returns a constant reference to the list of children. More...
 
TList_tGetChildren ()
 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...
 
T_ptrAppendChild (Args &&... args)
 Creates a new child item, appends it and returns it. More...
 
T_ptrInsertChild (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...
 

Additional Inherited Members

- Protected Types inherited from LC::Util::ModelItemBase< ModelItem >
using T_wptr = std::weak_ptr< ModelItem >
 
using T_ptr = std::shared_ptr< ModelItem >
 
using T_cptr = std::shared_ptr< const ModelItem >
 
using TList_t = QVector< T_ptr >
 
- Protected Member Functions inherited from LC::Util::ModelItemBase< ModelItem >
 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 inherited from LC::Util::ModelItemBase< ModelItem >
T_wptr Parent_
 
TList_t Children_
 

Detailed Description

Provides a proxying API on top of an QAbstractItemModel.

This class simplifies writing wrappers around QAbstractItemModel classes representing the data in different means than Qt's MVC.

Definition at line 54 of file modelitem.h.

Member Typedef Documentation

◆ const_iterator

typedef ModelItemsList_t::const_iterator LC::Util::ModelItem::const_iterator

Definition at line 60 of file modelitem.h.

◆ iterator

typedef ModelItemsList_t::iterator LC::Util::ModelItem::iterator

Definition at line 59 of file modelitem.h.

Constructor & Destructor Documentation

◆ ModelItem() [1/2]

LC::Util::ModelItem::ModelItem ( )
default

Constructs a default (invalid) ModelItem having no model set.

◆ ModelItem() [2/2]

LC::Util::ModelItem::ModelItem ( QAbstractItemModel *  model,
const QModelIndex &  index,
const ModelItem_wtr parent 
)

Constructs a ModelItem associated with a given index in the model.

Parameters
[in]modelThe model which this model item wraps.
[in]indexThe source index in this model.
[in]parentThe parent ModelItem, or an empty pointer if this is the root item.

Definition at line 37 of file modelitem.cpp.

Member Function Documentation

◆ EnsureChild()

ModelItem * LC::Util::ModelItem::EnsureChild ( int  row)

Ensures there is a child item at the given row.

If necessary, this function expands the list of children until there is a given row.

If no model item has been set for the given row, this function creates a proper ModelItem.

Parameters
[in]rowThe row for which to obtain a child item.
Returns
A child item already existing at the given row or a new child item if there was no item at the row.

Definition at line 44 of file modelitem.cpp.

References LC::Util::ModelItemBase< ModelItem >::Children_.

◆ FindChild()

ModelItem_ptr LC::Util::ModelItem::FindChild ( QModelIndex  index) const

Finds a child item for the given index.

The index is assumed to be the child of the one wrapped by this ModelItem.

Parameters
[in]indexThe index (a child of the one returned by GetIndex()) for which a child model item should be found.
Returns
The model item wrapping the given index or a null pointer if there is no such item.

Definition at line 73 of file modelitem.cpp.

References LC::Util::ModelItemBase< ModelItem >::Children_.

◆ GetIndex()

const QModelIndex & LC::Util::ModelItem::GetIndex ( ) const

Returns the index this ModelItem instance wraps.

Returns
The model index this item wraps, either the one passed to the constructor or the one obtained during the RefreshIndex() call.

Definition at line 57 of file modelitem.cpp.

◆ GetModel()

QAbstractItemModel * LC::Util::ModelItem::GetModel ( ) const

Returns the wrapped model.

Returns
The wrapped model.

Definition at line 68 of file modelitem.cpp.

Referenced by LC::Util::MergeModel::rowCount().

+ Here is the caller graph for this function:

◆ RefreshIndex()

void LC::Util::ModelItem::RefreshIndex ( int  modelStartingRow)

Updates the wrapped index so that it points at the given row.

Calling this function on a ModelItem wrapping the root of the underlying model (that is, constructed by the parameterless constructor) leads to undefined behavior.

Parameters
[in]modelStartingRowThe new row (among the children of this item's wrapped index) in the model this item should represent.

Definition at line 62 of file modelitem.cpp.

References LC::Util::ModelItemBase< ModelItem >::GetRow(), and LC::Util::ModelItemBase< ModelItem >::Parent_.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: