Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
15static ResultIteratorBase findResult(const QMap<int, ResultItem> &store, int index)
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
90
92{
93 return mapIterator.value().isVector();
94}
95
97{
98 return (m_vectorIndex + 1 < mapIterator.value().m_count);
99}
100
102{
103 return mapIterator.value().isValid();
104}
105
107 : insertIndex(0), resultCount(0), m_filterMode(false), filteredResults(0) { }
108
110{
111 // QFutureInterface's dtor must delete the contents of m_results.
112 Q_ASSERT(m_results.isEmpty());
113}
114
119
121{
122 return m_filterMode;
123}
124
126{
128 while (it != end()) {
129 resultCount += it.batchSize();
131 }
132}
133
135{
136 if (resultItem.isValid()) {
137 m_results[index] = resultItem;
139 } else {
140 filteredResults += resultItem.count();
141 }
142}
143
145{
146 int storeIndex;
147 if (m_filterMode && index != -1 && index > insertIndex) {
148 pendingResults[index] = resultItem;
149 storeIndex = index;
150 } else {
151 storeIndex = updateInsertIndex(index, resultItem.count());
152 insertResultItemIfValid(storeIndex - filteredResults, resultItem);
153 }
155 return storeIndex;
156}
157
159{
160 // index might refer to either visible or pending result
161 const bool inPending = m_filterMode && index != -1 && index > insertIndex;
162 const auto &store = inPending ? pendingResults : m_results;
163 auto it = findResult(store, index);
164 return it != ResultIteratorBase(store.end()) && it.isValid();
165}
166
168{
169 // check if we can insert any of the pending results:
171 while (it != pendingResults.end()) {
172 int index = it.key();
174 break;
175
176 ResultItem result = it.value();
178 pendingResults.erase(it);
179 it = pendingResults.begin();
180 }
181}
182
184{
185 ResultItem resultItem(result, 0); // 0 means "not a vector"
186 return insertResultItem(index, resultItem);
187}
188
189int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount)
190{
191 if (m_filterMode == false || vectorSize == totalCount) {
192 Q_ASSERT(vectorSize != 0);
193 ResultItem resultItem(results, vectorSize);
194 return insertResultItem(index, resultItem);
195 } else {
196 if (vectorSize > 0) {
197 ResultItem filteredIn(results, vectorSize);
198 insertResultItem(index, filteredIn);
199 }
200 ResultItem filteredAway(nullptr, totalCount - vectorSize);
201 return insertResultItem(index + vectorSize, filteredAway);
202 }
203}
204
209
214
216{
217 return begin() != end();
218}
219
224
226{
227 return (resultAt(index) != end());
228}
229
231{
232 return resultCount;
233}
234
235// returns the insert index, calling this function with
236// index equal to -1 returns the next available index.
238{
239 if (index == -1) {
241 insertIndex += _count;
242 } else {
243 insertIndex = qMax(index + _count, insertIndex);
244 }
245 return index;
246}
247
248} // namespace QtPrivate
249
Definition qmap.h:187
qsizetype count() const
Definition qset.h:154
QMap< int, ResultItem >::const_iterator mapIterator
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_NO_KEYWORDS >
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