LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
modeliterator.h
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
#pragma once
10
11
#include <QModelIndex>
12
#include "
modelsconfig.h
"
13
14
namespace
LC::Util
15
{
30
class
UTIL_MODELS_API
ModelIterator
31
{
32
const
QAbstractItemModel *Model_ =
nullptr
;
33
QModelIndex Parent_;
34
35
int
Row_;
36
int
Col_;
37
public
:
40
enum class
Direction
41
{
46
Rows,
47
52
Cols
53
};
54
private
:
55
Direction Dir_;
56
public
:
65
ModelIterator
(
const
QAbstractItemModel *model,
int
row,
int
col = 0,
66
Direction dir = Direction::Rows,
const
QModelIndex& parent = {});
67
73
ModelIterator& operator++ ();
74
80
ModelIterator operator++ (
int
);
81
87
ModelIterator& operator-- ();
88
94
ModelIterator operator-- (
int
);
95
101
ModelIterator& operator+= (
int
count);
102
109
ModelIterator& operator-= (
int
count);
110
123
int
operator- (
const
ModelIterator& other)
const
;
124
135
friend
UTIL_MODELS_API
bool
operator==
(
const
ModelIterator& left,
const
ModelIterator& right);
136
142
QModelIndex operator* ()
const
;
143
150
int
GetRow ()
const
;
151
158
int
GetCol ()
const
;
159
160
Direction GetDirection ()
const
;
161
private
:
162
int
& GetIncrementable ();
163
int
GetIncrementable ()
const
;
164
};
165
166
167
struct
ModelRange
168
{
169
const
ModelIterator
Begin_
;
170
171
struct
Sentinel
172
{
173
// One past the end
174
int
End_
= 0;
175
};
176
const
Sentinel
End_
;
177
178
auto
begin
()
const
{
return
Begin_
; }
179
auto
end
()
const
{
return
End_
; }
180
};
181
182
bool
UTIL_MODELS_API
operator==
(
const
ModelIterator& left,
const
ModelRange::Sentinel& right);
183
184
inline
ModelRange
AllModelRows
(
const
QAbstractItemModel& model,
int
column = 0)
185
{
186
return
ModelRange
187
{
188
.Begin_ = { &model, 0, column,
ModelIterator::Direction::Rows
},
189
.End_ = { model.rowCount () },
190
};
191
}
192
193
inline
ModelRange
ModelRows
(
const
QAbstractItemModel& model,
int
from,
int
to,
int
column = 0)
194
{
195
return
ModelRange
196
{
197
.Begin_ = { &model, from, column,
ModelIterator::Direction::Rows
},
198
.End_ = { to + 1 },
199
};
200
}
201
}
202
203
template
<>
204
struct
std::iterator_traits<
LC
::Util::ModelIterator>
205
{
206
typedef
QModelIndex
value_type
;
207
typedef
int
difference_type
;
208
209
typedef
random_access_iterator_tag
iterator_category
;
210
};
211
212
static_assert
(std::ranges::input_range<LC::Util::ModelRange>);
LC::Util::ModelIterator
Provides an iterator-based API to a Qt model.
Definition
modeliterator.h:31
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
operator==
auto operator==(const T &left, const T &right)
Definition
common.h:21
modelsconfig.h
UTIL_MODELS_API
#define UTIL_MODELS_API
Definition
modelsconfig.h:16
LC::Util
Definition
icoreproxy.h:34
LC::Util::ModelRows
ModelRange ModelRows(const QAbstractItemModel &model, int from, int to, int column=0)
Definition
modeliterator.h:193
LC::Util::operator==
bool operator==(const ModelIterator &left, const ModelIterator &right)
Definition
modeliterator.cpp:68
LC::Util::AllModelRows
ModelRange AllModelRows(const QAbstractItemModel &model, int column=0)
Definition
modeliterator.h:184
LC
Definition
constants.h:15
LC::Util::ModelRange::Sentinel
Definition
modeliterator.h:172
LC::Util::ModelRange::Sentinel::End_
int End_
Definition
modeliterator.h:174
LC::Util::ModelRange
Definition
modeliterator.h:168
LC::Util::ModelRange::End_
const Sentinel End_
Definition
modeliterator.h:176
LC::Util::ModelRange::end
auto end() const
Definition
modeliterator.h:179
LC::Util::ModelRange::Begin_
const ModelIterator Begin_
Definition
modeliterator.h:169
LC::Util::ModelRange::begin
auto begin() const
Definition
modeliterator.h:178
std::iterator_traits< LC::Util::ModelIterator >::difference_type
int difference_type
Definition
modeliterator.h:207
std::iterator_traits< LC::Util::ModelIterator >::iterator_category
random_access_iterator_tag iterator_category
Definition
modeliterator.h:209
std::iterator_traits< LC::Util::ModelIterator >::value_type
QModelIndex value_type
Definition
modeliterator.h:206
src
util
models
modeliterator.h
Generated by
1.17.0