LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
LC::Util::ModelIterator Class Reference

Provides an iterator-based API to a Qt model. More...

#include "modeliterator.h"

Public Types

enum class  Direction {
  Rows ,
  Cols
}
 The direction of traversal. More...
 

Public Member Functions

 ModelIterator (QAbstractItemModel *model, int row, int col=0, Direction dir=Direction::Rows, const QModelIndex &parent={})
 Constructs an iterator.
 
ModelIteratoroperator++ ()
 Increments the traversable index and returns the modified iterator.
 
ModelIterator operator++ (int)
 Returns the current iterator and increments the traversable index.
 
ModelIteratoroperator-- ()
 Decrements the traversable index and returns the modified iterator.
 
ModelIterator operator-- (int)
 Returns the current iterator and decrements the traversable index.
 
ModelIteratoroperator+= (int count)
 Adds the given count to the traversable index.
 
ModelIteratoroperator-= (int count)
 Subtracts the given count to the traversable index.
 
int operator- (const ModelIterator &other) const
 Computes the distance between this and another iterator.
 
QModelIndex operator* () const
 Returns the index currently pointed by the iterator.
 
int GetRow () const
 Returns the current row.
 
int GetCol () const
 Returns the current column.
 

Friends

UTIL_MODELS_API bool operator== (const ModelIterator &left, const ModelIterator &right)
 Checks if two iterators are equal.
 
UTIL_MODELS_API bool operator!= (const ModelIterator &left, const ModelIterator &right)
 Checks if two iterators are not equal.
 

Detailed Description

Provides an iterator-based API to a Qt model.

This class wraps a subclass of QAbstractItemModel into an STL-iterator-friendly API. The provided iterator is of the random access category.

A model can be traversed either by rows (incrementing row index at each iterator increment) or by columns (incrementing column index at each iterator increment). The Direction enumeration controls the exact behavior. The exact index which is changed during iterating is called the traversable.

Definition at line 30 of file modeliterator.h.

Member Enumeration Documentation

◆ Direction

The direction of traversal.

Enumerator
Rows 

The model should be traversed by rows.

Thus, the traversable is the row index.

Cols 

The model should be traversed by columns.

Thus, the traversable is the column index.

Definition at line 40 of file modeliterator.h.

Constructor & Destructor Documentation

◆ ModelIterator()

LC::Util::ModelIterator::ModelIterator ( QAbstractItemModel * model,
int row,
int col = 0,
ModelIterator::Direction dir = Direction::Rows,
const QModelIndex & parent = {} )

Constructs an iterator.

Parameters
[in]modelThe model to iterate over.
[in]rowThe starting row of the iterator.
[in]colThe starting column of the iterator.
[in]dirThe direction of traversal.
[in]parentThe parent index to be used during traversal.

Definition at line 15 of file modeliterator.cpp.

Referenced by operator!=, operator++(), operator++(), operator+=(), operator-(), operator--(), operator--(), operator-=(), and operator==.

+ Here is the caller graph for this function:

Member Function Documentation

◆ GetCol()

int LC::Util::ModelIterator::GetCol ( ) const

Returns the current column.

Returns
The current column of the iterator.
See also
GetRow()

Definition at line 91 of file modeliterator.cpp.

◆ GetRow()

int LC::Util::ModelIterator::GetRow ( ) const

Returns the current row.

Returns
The current row of the iterator.
See also
GetCol()

Definition at line 86 of file modeliterator.cpp.

◆ operator*()

QModelIndex LC::Util::ModelIterator::operator* ( ) const

Returns the index currently pointed by the iterator.

Returns
The index defined by the parent index of this iterator and the current (row, column) pair.

Definition at line 81 of file modeliterator.cpp.

◆ operator++() [1/2]

ModelIterator & LC::Util::ModelIterator::operator++ ( )

Increments the traversable index and returns the modified iterator.

Returns
The modified iterator with the new traversable index.

Definition at line 25 of file modeliterator.cpp.

References ModelIterator().

+ Here is the call graph for this function:

◆ operator++() [2/2]

ModelIterator LC::Util::ModelIterator::operator++ ( int )

Returns the current iterator and increments the traversable index.

Returns
The iterator with the old traversable index.

Definition at line 31 of file modeliterator.cpp.

References ModelIterator().

+ Here is the call graph for this function:

◆ operator+=()

ModelIterator & LC::Util::ModelIterator::operator+= ( int count)

Adds the given count to the traversable index.

Parameters
[in]countThe number to add to the current traversable.
Returns
The modified iterator with the new traversable index.

Definition at line 51 of file modeliterator.cpp.

References ModelIterator().

+ Here is the call graph for this function:

◆ operator-()

int LC::Util::ModelIterator::operator- ( const ModelIterator & other) const

Computes the distance between this and another iterator.

The distance is the different between traversable indexes of this and other iterator.

If the iterators have different traverse directions, the behavior is undefined.

Parameters
[in]otherThe other iterator to compute distance with.
Returns
The distance between this and other iterator, which may be negative.

Definition at line 63 of file modeliterator.cpp.

References ModelIterator().

+ Here is the call graph for this function:

◆ operator--() [1/2]

ModelIterator & LC::Util::ModelIterator::operator-- ( )

Decrements the traversable index and returns the modified iterator.

Returns
The modified iterator with the new traversable index.

Definition at line 38 of file modeliterator.cpp.

References ModelIterator().

+ Here is the call graph for this function:

◆ operator--() [2/2]

ModelIterator LC::Util::ModelIterator::operator-- ( int )

Returns the current iterator and decrements the traversable index.

Returns
The iterator with the old traversable index.

Definition at line 44 of file modeliterator.cpp.

References ModelIterator().

+ Here is the call graph for this function:

◆ operator-=()

ModelIterator & LC::Util::ModelIterator::operator-= ( int count)

Subtracts the given count to the traversable index.

Parameters
[in]countThe number to subtract from the current traversable.
Returns
The modified iterator with the new traversable index.

Definition at line 57 of file modeliterator.cpp.

References ModelIterator().

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ operator!=

UTIL_MODELS_API bool operator!= ( const ModelIterator & left,
const ModelIterator & right )
friend

Checks if two iterators are not equal.

For iterators to not be equal at least either the model, parent index, row or column should be unequal. Traversal index is not taken into account.

Parameters
[in]leftFirst iterator to check for inequality.
[in]rightSecond iterator to check for inequality.
Returns
Whether left and right are equal.

Definition at line 76 of file modeliterator.cpp.

References ModelIterator().

◆ operator==

UTIL_MODELS_API bool operator== ( const ModelIterator & left,
const ModelIterator & right )
friend

Checks if two iterators are equal.

For iterators to be equal the model, parent index, row and column should all be equal. Traversal index is not taken into account.

Parameters
[in]leftFirst iterator to check for equality.
[in]rightSecond iterator to check for equality.
Returns
Whether left and right are equal.

Definition at line 68 of file modeliterator.cpp.

References ModelIterator().


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