LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
LC::Util::ModelIterator Class Reference

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

#include "modeliterator.h"

Public Types

enum  Direction {
  Direction::Rows,
  Direction::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. More...
 
ModelIteratoroperator++ ()
 Increments the traversable index and returns the modified iterator. More...
 
ModelIterator operator++ (int)
 Returns the current iterator and increments the traversable index. More...
 
ModelIteratoroperator-- ()
 Decrements the traversable index and returns the modified iterator. More...
 
ModelIterator operator-- (int)
 Returns the current iterator and decrements the traversable index. More...
 
ModelIteratoroperator+= (int count)
 Adds the given count to the traversable index. More...
 
ModelIteratoroperator-= (int count)
 Subtracts the given count to the traversable index. More...
 
int operator- (const ModelIterator &other) const
 Computes the distance between this and another iterator. More...
 
QModelIndex operator* () const
 Returns the index currently pointed by the iterator. More...
 
int GetRow () const
 Returns the current row. More...
 
int GetCol () const
 Returns the current column. More...
 

Friends

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

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 36 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 52 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 21 of file modeliterator.cpp.

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 97 of file modeliterator.cpp.

References Cols, and Rows.

◆ GetRow()

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

Returns the current row.

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

Definition at line 92 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 87 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 31 of file modeliterator.cpp.

◆ 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 37 of file modeliterator.cpp.

◆ 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 57 of file modeliterator.cpp.

◆ 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 69 of file modeliterator.cpp.

◆ 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 44 of file modeliterator.cpp.

◆ 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 50 of file modeliterator.cpp.

◆ 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 63 of file modeliterator.cpp.

Friends And Related Function 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 82 of file modeliterator.cpp.

◆ 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 74 of file modeliterator.cpp.


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