LeechCraft
0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
|
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... | |
ModelIterator & | operator++ () |
Increments the traversable index and returns the modified iterator. More... | |
ModelIterator | operator++ (int) |
Returns the current iterator and increments the traversable index. More... | |
ModelIterator & | operator-- () |
Decrements the traversable index and returns the modified iterator. More... | |
ModelIterator | operator-- (int) |
Returns the current iterator and decrements the traversable index. More... | |
ModelIterator & | operator+= (int count) |
Adds the given count to the traversable index. More... | |
ModelIterator & | operator-= (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... | |
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.
|
strong |
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.
LC::Util::ModelIterator::ModelIterator | ( | QAbstractItemModel * | model, |
int | row, | ||
int | col = 0 , |
||
ModelIterator::Direction | dir = Direction::Rows , |
||
const QModelIndex & | parent = {} |
||
) |
Constructs an iterator.
[in] | model | The model to iterate over. |
[in] | row | The starting row of the iterator. |
[in] | col | The starting column of the iterator. |
[in] | dir | The direction of traversal. |
[in] | parent | The parent index to be used during traversal. |
Definition at line 21 of file modeliterator.cpp.
int LC::Util::ModelIterator::GetCol | ( | ) | const |
Returns the current column.
Definition at line 97 of file modeliterator.cpp.
int LC::Util::ModelIterator::GetRow | ( | ) | const |
Returns the current row.
Definition at line 92 of file modeliterator.cpp.
QModelIndex LC::Util::ModelIterator::operator* | ( | ) | const |
Returns the index currently pointed by the iterator.
Definition at line 87 of file modeliterator.cpp.
ModelIterator & LC::Util::ModelIterator::operator++ | ( | ) |
Increments the traversable index and returns the modified iterator.
Definition at line 31 of file modeliterator.cpp.
ModelIterator LC::Util::ModelIterator::operator++ | ( | int | ) |
Returns the current iterator and increments the traversable index.
Definition at line 37 of file modeliterator.cpp.
ModelIterator & LC::Util::ModelIterator::operator+= | ( | int | count | ) |
Adds the given count to the traversable index.
[in] | count | The number to add to the current traversable. |
Definition at line 57 of file modeliterator.cpp.
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.
[in] | other | The other iterator to compute distance with. |
Definition at line 69 of file modeliterator.cpp.
ModelIterator & LC::Util::ModelIterator::operator-- | ( | ) |
Decrements the traversable index and returns the modified iterator.
Definition at line 44 of file modeliterator.cpp.
ModelIterator LC::Util::ModelIterator::operator-- | ( | int | ) |
Returns the current iterator and decrements the traversable index.
Definition at line 50 of file modeliterator.cpp.
ModelIterator & LC::Util::ModelIterator::operator-= | ( | int | count | ) |
Subtracts the given count to the traversable index.
[in] | count | The number to subtract from the current traversable. |
Definition at line 63 of file modeliterator.cpp.
|
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.
[in] | left | First iterator to check for inequality. |
[in] | right | Second iterator to check for inequality. |
Definition at line 82 of file modeliterator.cpp.
|
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.
[in] | left | First iterator to check for equality. |
[in] | right | Second iterator to check for equality. |
Definition at line 74 of file modeliterator.cpp.