Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qresultstore.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qresultstore.h"
5
7
8namespace QtPrivate {
9
16{
17 if (store.isEmpty())
18 return ResultIteratorBase(store.end());
20
21 // lowerBound returns either an iterator to the result or an iterator
22 // to the nearest greater index. If the latter happens it might be
23 // that the result is stored in a vector at the previous index.
24 if (it == store.end()) {
25 --it;
26 if (it.value().isVector() == false) {
27 return ResultIteratorBase(store.end());
28 }
29 } else {
30 if (it.key() > index) {
31 if (it == store.begin())
32 return ResultIteratorBase(store.end());
33 --it;
34 }
35 }
36
37 const int vectorIndex = index - it.key();
38
39 if (vectorIndex >= it.value().count())
40 return ResultIteratorBase(store.end());
41 else if (it.value().isVector() == false && vectorIndex != 0)
42 return ResultIteratorBase(store.end());
43 return ResultIteratorBase(it, vectorIndex);
44}
45
62 : mapIterator(QMap<int, ResultItem>::const_iterator()), m_vectorIndex(0) { }
64 : mapIterator(_mapIterator), m_vectorIndex(_vectorIndex) { }
65
68
70{
73 } else {
75 m_vectorIndex = 0;
76 }
77 return *this;
78}
79
81{
82 return mapIterator.value().count();
83}
84
86{
88 m_vectorIndex = 0;
89}
90
92{
93 return (mapIterator == other.mapIterator && m_vectorIndex == other.m_vectorIndex);
94}
95
97{
98 return !operator==(other);
99}
100
102{
103 return mapIterator.value().isVector();
104}
105
107{
108 return (m_vectorIndex + 1 < mapIterator.value().m_count);
109}
110
112{
113 return mapIterator.value().isValid();
114}
115
117 : insertIndex(0), resultCount(0), m_filterMode(false), filteredResults(0) { }
118
120{
121 // QFutureInterface's dtor must delete the contents of m_results.
122 Q_ASSERT(m_results.isEmpty());
123}
124
126{
128}
129
131{
132 return m_filterMode;
133}
134
136{
138 while (it != end()) {
139 resultCount += it.batchSize();
141 }
142}
143
145{
146 if (resultItem.isValid()) {
147 m_results[index] = resultItem;
149 } else {
150 filteredResults += resultItem.count();
151 }
152}
153
155{
156 int storeIndex;
157 if (m_filterMode && index != -1 && index > insertIndex) {
158 pendingResults[index] = resultItem;
159 storeIndex = index;
160 } else {
161 storeIndex = updateInsertIndex(index, resultItem.count());
162 insertResultItemIfValid(storeIndex - filteredResults, resultItem);
163 }
165 return storeIndex;
166}
167
169{
170 // index might refer to either visible or pending result
171 const bool inPending = m_filterMode && index != -1 && index > insertIndex;
172 const auto &store = inPending ? pendingResults : m_results;
173 auto it = findResult(store, index);
174 return it != ResultIteratorBase(store.end()) && it.isValid();
175}
176
178{
179 // check if we can insert any of the pending results:
181 while (it != pendingResults.end()) {
182 int index = it.key();
184 break;
185
186 ResultItem result = it.value();
188 pendingResults.erase(it);
189 it = pendingResults.begin();
190 }
191}
192
194{
195 ResultItem resultItem(result, 0); // 0 means "not a vector"
196 return insertResultItem(index, resultItem);
197}
198
199int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount)
200{
201 if (m_filterMode == false || vectorSize == totalCount) {
202 Q_ASSERT(vectorSize != 0);
203 ResultItem resultItem(results, vectorSize);
204 return insertResultItem(index, resultItem);
205 } else {
206 if (vectorSize > 0) {
207 ResultItem filteredIn(results, vectorSize);
208 insertResultItem(index, filteredIn);
209 }
210 ResultItem filteredAway(nullptr, totalCount - vectorSize);
211 return insertResultItem(index + vectorSize, filteredAway);
212 }
213}
214
216{
217 return ResultIteratorBase(m_results.begin());
218}
219
221{
222 return ResultIteratorBase(m_results.end());
223}
224
226{
227 return begin() != end();
228}
229
231{
232 return findResult(m_results, index);
233}
234
236{
237 return (resultAt(index) != end());
238}
239
241{
242 return resultCount;
243}
244
245// returns the insert index, calling this function with
246// index equal to -1 returns the next available index.
248{
249 if (index == -1) {
251 insertIndex += _count;
252 } else {
253 insertIndex = qMax(index + _count, insertIndex);
254 }
255 return index;
256}
257
258} // namespace QtPrivate
259
Definition qmap.h:186
iterator lowerBound(const Key &key)
Definition qmap.h:659
bool isEmpty() const
Definition qmap.h:268
iterator begin()
Definition qmap.h:597
iterator end()
Definition qmap.h:601
qsizetype count() const
Definition qset.h:154
bool operator==(const ResultIteratorBase &other) const
QMap< int, ResultItem >::const_iterator mapIterator
bool operator!=(const ResultIteratorBase &other) const
ResultIteratorBase operator++()
int addResults(int index, const void *results, int vectorSize, int logicalCount)
void insertResultItemIfValid(int index, ResultItem &resultItem)
ResultIteratorBase end() const
int insertResultItem(int index, ResultItem &resultItem)
void setFilterMode(bool enable)
ResultIteratorBase resultAt(int index) const
bool containsValidResultItem(int index) const
QMap< int, ResultItem > m_results
ResultIteratorBase begin() const
int updateInsertIndex(int index, int _count)
QMap< int, ResultItem > pendingResults
bool contains(int index) const
int addResult(int index, const void *result)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
\macro QT_NAMESPACE
static ResultIteratorBase findResult(const QMap< int, ResultItem > &store, int index)
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLuint index
[2]
GLboolean enable
GLuint64EXT * result
[6]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QSharedPointer< T > other(t)
[5]