LeechCraft 0.6.70-17335-ge406ffdcaf
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
modeliterator.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "modeliterator.h"
10#include <QAbstractItemModel>
11#include <QtDebug>
12
13namespace LC::Util
14{
15 ModelIterator::ModelIterator (const QAbstractItemModel *model,
16 int row, int col, ModelIterator::Direction dir, const QModelIndex& parent)
17 : Model_ (model)
18 , Parent_ (parent)
19 , Row_ (row)
20 , Col_ (col)
21 , Dir_ (dir)
22 {
23 }
24
26 {
27 ++GetIncrementable ();
28 return *this;
29 }
30
32 {
33 ModelIterator oldThis (*this);
34 ++GetIncrementable ();
35 return oldThis;
36 }
37
39 {
40 --GetIncrementable ();
41 return *this;
42 }
43
45 {
46 ModelIterator oldThis (*this);
47 --GetIncrementable ();
48 return oldThis;
49 }
50
52 {
53 GetIncrementable () += diff;
54 return *this;
55 }
56
58 {
59 GetIncrementable () -= diff;
60 return *this;
61 }
62
64 {
65 return GetIncrementable () - other.GetIncrementable ();
66 }
67
68 bool operator== (const ModelIterator& left, const ModelIterator& right)
69 {
70 return left.Row_ == right.Row_ &&
71 left.Col_ == right.Col_ &&
72 left.Model_ == right.Model_ &&
73 left.Parent_ == right.Parent_;
74 }
75
76 QModelIndex ModelIterator::operator*() const
77 {
78 return Model_->index (Row_, Col_, Parent_);
79 }
80
82 {
83 return Row_;
84 }
85
87 {
88 return Col_;
89 }
90
91 int& ModelIterator::GetIncrementable ()
92 {
93 switch (Dir_)
94 {
95 case Direction::Rows:
96 return Row_;
97 case Direction::Cols:
98 return Col_;
99 }
100
101 qWarning () << Q_FUNC_INFO
102 << "unknown direction";
103 return Row_;
104 }
105
106 int ModelIterator::GetIncrementable () const
107 {
108 switch (Dir_)
109 {
110 case Direction::Rows:
111 return Row_;
112 case Direction::Cols:
113 return Col_;
114 }
115
116 qWarning () << Q_FUNC_INFO
117 << "unknown direction";
118 return Row_;
119 }
120}
ModelIterator & operator-=(int count)
Subtracts the given count to the traversable index.
int operator-(const ModelIterator &other) const
Computes the distance between this and another iterator.
ModelIterator(const QAbstractItemModel *model, int row, int col=0, Direction dir=Direction::Rows, const QModelIndex &parent={})
Constructs an iterator.
Direction
The direction of traversal.
@ Rows
The model should be traversed by rows.
@ Cols
The model should be traversed by columns.
int GetRow() const
Returns the current row.
ModelIterator & operator++()
Increments the traversable index and returns the modified iterator.
int GetCol() const
Returns the current column.
ModelIterator & operator+=(int count)
Adds the given count to the traversable index.
QModelIndex operator*() const
Returns the index currently pointed by the iterator.
ModelIterator & operator--()
Decrements the traversable index and returns the modified iterator.
bool operator==(const ModelIterator &left, const ModelIterator &right)