LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
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
13
namespace
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
25
ModelIterator
&
ModelIterator::operator++
()
26
{
27
++GetIncrementable ();
28
return
*
this
;
29
}
30
31
ModelIterator
ModelIterator::operator++
(
int
)
32
{
33
ModelIterator
oldThis (*
this
);
34
++GetIncrementable ();
35
return
oldThis;
36
}
37
38
ModelIterator
&
ModelIterator::operator--
()
39
{
40
--GetIncrementable ();
41
return
*
this
;
42
}
43
44
ModelIterator
ModelIterator::operator--
(
int
)
45
{
46
ModelIterator
oldThis (*
this
);
47
--GetIncrementable ();
48
return
oldThis;
49
}
50
51
ModelIterator
&
ModelIterator::operator+=
(
int
diff)
52
{
53
GetIncrementable () += diff;
54
return
*
this
;
55
}
56
57
ModelIterator
&
ModelIterator::operator-=
(
int
diff)
58
{
59
GetIncrementable () -= diff;
60
return
*
this
;
61
}
62
63
int
ModelIterator::operator-
(
const
ModelIterator
& other)
const
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
81
int
ModelIterator::GetRow
()
const
82
{
83
return
Row_;
84
}
85
86
int
ModelIterator::GetCol
()
const
87
{
88
return
Col_;
89
}
90
91
ModelIterator::Direction
ModelIterator::GetDirection
()
const
92
{
93
return
Dir_;
94
}
95
96
int
& ModelIterator::GetIncrementable ()
97
{
98
switch
(Dir_)
99
{
100
case
Direction::Rows
:
101
return
Row_;
102
case
Direction::Cols
:
103
return
Col_;
104
}
105
106
qWarning () << Q_FUNC_INFO
107
<<
"unknown direction"
;
108
return
Row_;
109
}
110
111
int
ModelIterator::GetIncrementable ()
const
112
{
113
switch
(Dir_)
114
{
115
case
Direction::Rows
:
116
return
Row_;
117
case
Direction::Cols
:
118
return
Col_;
119
}
120
121
qWarning () << Q_FUNC_INFO
122
<<
"unknown direction"
;
123
return
Row_;
124
}
125
126
bool
UTIL_MODELS_API
operator==
(
const
ModelIterator
& left,
const
ModelRange::Sentinel
& right)
127
{
128
switch
(left.
GetDirection
())
129
{
130
case
ModelIterator::Direction::Rows
:
131
return
left.
GetRow
() == right.
End_
;
132
case
ModelIterator::Direction::Cols
:
133
return
left.
GetCol
() == right.
End_
;
134
}
135
136
std::unreachable ();
137
}
138
}
LC::Util::ModelIterator
Provides an iterator-based API to a Qt model.
Definition
modeliterator.h:31
LC::Util::ModelIterator::operator-=
ModelIterator & operator-=(int count)
Subtracts the given count to the traversable index.
Definition
modeliterator.cpp:57
LC::Util::ModelIterator::GetDirection
Direction GetDirection() const
Definition
modeliterator.cpp:91
LC::Util::ModelIterator::operator-
int operator-(const ModelIterator &other) const
Computes the distance between this and another iterator.
Definition
modeliterator.cpp:63
LC::Util::ModelIterator::ModelIterator
ModelIterator(const QAbstractItemModel *model, int row, int col=0, Direction dir=Direction::Rows, const QModelIndex &parent={})
Constructs an iterator.
Definition
modeliterator.cpp:15
LC::Util::ModelIterator::Direction
Direction
The direction of traversal.
Definition
modeliterator.h:41
LC::Util::ModelIterator::Direction::Rows
@ Rows
The model should be traversed by rows.
Definition
modeliterator.h:46
LC::Util::ModelIterator::Direction::Cols
@ Cols
The model should be traversed by columns.
Definition
modeliterator.h:52
LC::Util::ModelIterator::GetRow
int GetRow() const
Returns the current row.
Definition
modeliterator.cpp:81
LC::Util::ModelIterator::operator++
ModelIterator & operator++()
Increments the traversable index and returns the modified iterator.
Definition
modeliterator.cpp:25
LC::Util::ModelIterator::GetCol
int GetCol() const
Returns the current column.
Definition
modeliterator.cpp:86
LC::Util::ModelIterator::operator+=
ModelIterator & operator+=(int count)
Adds the given count to the traversable index.
Definition
modeliterator.cpp:51
LC::Util::ModelIterator::operator*
QModelIndex operator*() const
Returns the index currently pointed by the iterator.
Definition
modeliterator.cpp:76
LC::Util::ModelIterator::operator--
ModelIterator & operator--()
Decrements the traversable index and returns the modified iterator.
Definition
modeliterator.cpp:38
modeliterator.h
UTIL_MODELS_API
#define UTIL_MODELS_API
Definition
modelsconfig.h:16
LC::Util
Definition
icoreproxy.h:34
LC::Util::operator==
bool operator==(const ModelIterator &left, const ModelIterator &right)
Definition
modeliterator.cpp:68
LC::Util::ModelRange::Sentinel
Definition
modeliterator.h:172
LC::Util::ModelRange::Sentinel::End_
int End_
Definition
modeliterator.h:174
src
util
models
modeliterator.cpp
Generated by
1.17.0