Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qlist.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
6 | ** | - | ||||||
7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||
8 | ** | - | ||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
10 | ** Commercial License Usage | - | ||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
17 | ** | - | ||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
25 | ** | - | ||||||
26 | ** GNU General Public License Usage | - | ||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
36 | ** | - | ||||||
37 | ** $QT_END_LICENSE$ | - | ||||||
38 | ** | - | ||||||
39 | ****************************************************************************/ | - | ||||||
40 | - | |||||||
41 | #include <new> | - | ||||||
42 | #include "qlist.h" | - | ||||||
43 | #include "qtools_p.h" | - | ||||||
44 | - | |||||||
45 | #include <string.h> | - | ||||||
46 | #include <stdlib.h> | - | ||||||
47 | - | |||||||
48 | QT_BEGIN_NAMESPACE | - | ||||||
49 | - | |||||||
50 | /* | - | ||||||
51 | QList as an array-list combines the easy-of-use of a random | - | ||||||
52 | access interface with fast list operations and the low memory | - | ||||||
53 | management overhead of an array. Accessing elements by index, | - | ||||||
54 | appending, prepending, and removing elements from both the front | - | ||||||
55 | and the back all happen in constant time O(1). Inserting or | - | ||||||
56 | removing elements at random index positions \ai happens in linear | - | ||||||
57 | time, or more precisly in O(min{i,n-i}) <= O(n/2), with n being | - | ||||||
58 | the number of elements in the list. | - | ||||||
59 | */ | - | ||||||
60 | - | |||||||
61 | const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, { 0 } }; | - | ||||||
62 | - | |||||||
static int grow(int size) | ||||||||
{ | ||||||||
if (size_t(size) > (MaxAllocSize - QListData::DataHeaderSize) / sizeof(void *)) | ||||||||
qBadAlloc(); | ||||||||
volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *); | ||||||||
return x; | ||||||||
}/*! | ||||||||
64 | * Detaches the QListData by allocating new memory for a list which will be bigger | - | ||||||
65 | * than the copied one and is expected to grow further. | - | ||||||
66 | * *idx is the desired insertion point and is clamped to the actual size of the list. | - | ||||||
67 | * num is the number of new elements to insert at the insertion point. | - | ||||||
68 | * Returns the old (shared) data, it is up to the caller to deref() and free(). | - | ||||||
69 | * For the new data node_copy needs to be called. | - | ||||||
70 | * | - | ||||||
71 | * \internal | - | ||||||
72 | */ | - | ||||||
73 | QListData::Data *QListData::detach_grow(int *idx, int num) | - | ||||||
74 | { | - | ||||||
75 | Data *x = d; | - | ||||||
76 | int l = x->end - x->begin; | - | ||||||
77 | int nl = l + num; | - | ||||||
78 | int allocauto blockInfo = growqCalculateGrowingBlockSize(nl, sizeof(void *), DataHeaderSize); | - | ||||||
79 | Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *)));blockInfo.size)); | - | ||||||
80 | Q_CHECK_PTR(t); never executed: qBadAlloc();
| 0-1170293 | ||||||
81 | t->alloc = int(uint(blockInfo.elementCount)); | - | ||||||
82 | - | |||||||
83 | t->ref.initializeOwned(); | - | ||||||
84 | t->alloc = alloc;// The space reservation algorithm's optimization is biased towards appending: | - | ||||||
85 | // Something which looks like an append will put the data at the beginning, | - | ||||||
86 | // while something which looks like a prepend will put it in the middle | - | ||||||
87 | // instead of at the end. That's based on the assumption that prepending | - | ||||||
88 | // is uncommon and even an initial prepend will eventually be followed by | - | ||||||
89 | // at least some appends. | - | ||||||
90 | int bg; | - | ||||||
91 | if (*idx < 0) {
| 0-1170293 | ||||||
92 | *idx = 0; | - | ||||||
93 | bg = (t->alloc - nl) >> 1; | - | ||||||
94 | } else if (*idx > l) { never executed: end of block
| 0-1005874 | ||||||
95 | *idx = l; | - | ||||||
96 | bg = 0; | - | ||||||
97 | } else if (*idx < (l >> 1)) { executed 1005874 times by 588 tests: end of block Executed by:
| 3831-1005874 | ||||||
98 | bg = (t->alloc - nl) >> 1; | - | ||||||
99 | } else { executed 3831 times by 13 tests: end of block Executed by:
| 3831 | ||||||
100 | bg = 0; | - | ||||||
101 | } executed 160588 times by 278 tests: end of block Executed by:
| 160588 | ||||||
102 | t->begin = bg; | - | ||||||
103 | t->end = bg + nl; | - | ||||||
104 | d = t; | - | ||||||
105 | - | |||||||
106 | return x; executed 1170293 times by 591 tests: return x; Executed by:
| 1170293 | ||||||
107 | } | - | ||||||
108 | - | |||||||
109 | /*! | - | ||||||
110 | * Detaches the QListData by allocating new memory for a list which possibly | - | ||||||
111 | * has a different size than the copied one. | - | ||||||
112 | * Returns the old (shared) data, it is up to the caller to deref() and free() | - | ||||||
113 | * For the new data node_copy needs to be called. | - | ||||||
114 | * | - | ||||||
115 | * \internal | - | ||||||
116 | */ | - | ||||||
117 | QListData::Data *QListData::detach(int alloc) | - | ||||||
118 | { | - | ||||||
119 | Data *x = d; | - | ||||||
120 | Data* t = static_cast<Data *>(::malloc(DataHeaderSize +qCalculateBlockSize(alloc*, sizeof(void*)));*), DataHeaderSize))); | - | ||||||
121 | Q_CHECK_PTR(t); never executed: qBadAlloc();
| 0-210646 | ||||||
122 | - | |||||||
123 | t->ref.initializeOwned(); | - | ||||||
124 | t->alloc = alloc; | - | ||||||
125 | if (!alloc) {
| 32574-178072 | ||||||
126 | t->begin = 0; | - | ||||||
127 | t->end = 0; | - | ||||||
128 | } else { executed 32574 times by 128 tests: end of block Executed by:
| 32574 | ||||||
129 | t->begin = x->begin; | - | ||||||
130 | t->end = x->end; | - | ||||||
131 | } executed 178072 times by 429 tests: end of block Executed by:
| 178072 | ||||||
132 | d = t; | - | ||||||
133 | - | |||||||
134 | return x; executed 210646 times by 442 tests: return x; Executed by:
| 210646 | ||||||
135 | } | - | ||||||
136 | - | |||||||
137 | void QListData::realloc(int alloc) | - | ||||||
138 | { | - | ||||||
139 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
140 | Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize +qCalculateBlockSize(alloc*, sizeof(void *)));*), DataHeaderSize))); | - | ||||||
141 | Q_CHECK_PTR(x); never executed: qBadAlloc();
| 0-838 | ||||||
142 | - | |||||||
143 | d = x; | - | ||||||
144 | d->alloc = alloc; | - | ||||||
145 | if (!alloc)
| 0-838 | ||||||
146 | d->begin = d->end = 0; never executed: d->begin = d->end = 0; | 0 | ||||||
147 | } executed 838 times by 15 tests: end of block Executed by:
| 838 | ||||||
148 | - | |||||||
149 | void QListData::realloc_grow(int growth) | - | ||||||
150 | { | - | ||||||
151 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
152 | int allocauto r = growqCalculateGrowingBlockSize(d->alloc + growth, sizeof(void *), DataHeaderSize); | - | ||||||
153 | Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize + alloc * sizeof(void *)));r.size)); | - | ||||||
154 | Q_CHECK_PTR(x); never executed: qBadAlloc();
| 0-423175 | ||||||
155 | - | |||||||
156 | d = x; | - | ||||||
157 | d->alloc = alloc;int(uint(r.elementCount)); | - | ||||||
158 | } executed 423175 times by 395 tests: end of block Executed by:
| 423175 | ||||||
159 | - | |||||||
160 | void QListData::dispose(Data *d) | - | ||||||
161 | { | - | ||||||
162 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
163 | free(d); | - | ||||||
164 | } | - | ||||||
165 | - | |||||||
166 | // ensures that enough space is available to append n elements | - | ||||||
167 | void **QListData::append(int n) | - | ||||||
168 | { | - | ||||||
169 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
170 | int e = d->end; | - | ||||||
171 | if (e + n > d->alloc) { | - | ||||||
172 | int b = d->begin; | - | ||||||
173 | if (b - n >= 2 * d->alloc / 3) { | - | ||||||
174 | // we have enough space. Just not at the end -> move it. | - | ||||||
175 | e -= b; | - | ||||||
176 | ::memcpy(d->array, d->array + b, e * sizeof(void *)); | - | ||||||
177 | d->begin = 0; | - | ||||||
178 | } else { | - | ||||||
179 | realloc_grow(n); | - | ||||||
180 | } | - | ||||||
181 | } | - | ||||||
182 | d->end = e + n; | - | ||||||
183 | return d->array + e; | - | ||||||
184 | } | - | ||||||
185 | - | |||||||
186 | // ensures that enough space is available to append one element | - | ||||||
187 | void **QListData::append() | - | ||||||
188 | { | - | ||||||
189 | return append(1); | - | ||||||
190 | } | - | ||||||
191 | - | |||||||
192 | // ensures that enough space is available to append the list | - | ||||||
193 | void **QListData::append(const QListData& l) | - | ||||||
194 | { | - | ||||||
195 | return append(l.d->end - l.d->begin); | - | ||||||
196 | } | - | ||||||
197 | - | |||||||
198 | void **QListData::prepend() | - | ||||||
199 | { | - | ||||||
200 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
201 | if (d->begin == 0) { | - | ||||||
202 | if (d->end >= d->alloc / 3) | - | ||||||
203 | realloc_grow(1); | - | ||||||
204 | - | |||||||
205 | if (d->end < d->alloc / 3) | - | ||||||
206 | d->begin = d->alloc - 2 * d->end; | - | ||||||
207 | else | - | ||||||
208 | d->begin = d->alloc - d->end; | - | ||||||
209 | - | |||||||
210 | ::memmove(d->array + d->begin, d->array, d->end * sizeof(void *)); | - | ||||||
211 | d->end += d->begin; | - | ||||||
212 | } | - | ||||||
213 | return d->array + --d->begin; | - | ||||||
214 | } | - | ||||||
215 | - | |||||||
216 | void **QListData::insert(int i) | - | ||||||
217 | { | - | ||||||
218 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
219 | if (i <= 0) | - | ||||||
220 | return prepend(); | - | ||||||
221 | int size = d->end - d->begin; | - | ||||||
222 | if (i >= size) | - | ||||||
223 | return append(); | - | ||||||
224 | - | |||||||
225 | bool leftward = false; | - | ||||||
226 | - | |||||||
227 | if (d->begin == 0) { | - | ||||||
228 | if (d->end == d->alloc) { | - | ||||||
229 | // If the array is full, we expand it and move some items rightward | - | ||||||
230 | realloc_grow(1); | - | ||||||
231 | } else { | - | ||||||
232 | // If there is free space at the end of the array, we move some items rightward | - | ||||||
233 | } | - | ||||||
234 | } else { | - | ||||||
235 | if (d->end == d->alloc) { | - | ||||||
236 | // If there is free space at the beginning of the array, we move some items leftward | - | ||||||
237 | leftward = true; | - | ||||||
238 | } else { | - | ||||||
239 | // If there is free space at both ends, we move as few items as possible | - | ||||||
240 | leftward = (i < size - i); | - | ||||||
241 | } | - | ||||||
242 | } | - | ||||||
243 | - | |||||||
244 | if (leftward) { | - | ||||||
245 | --d->begin; | - | ||||||
246 | ::memmove(d->array + d->begin, d->array + d->begin + 1, i * sizeof(void *)); | - | ||||||
247 | } else { | - | ||||||
248 | ::memmove(d->array + d->begin + i + 1, d->array + d->begin + i, | - | ||||||
249 | (size - i) * sizeof(void *)); | - | ||||||
250 | ++d->end; | - | ||||||
251 | } | - | ||||||
252 | return d->array + d->begin + i; | - | ||||||
253 | } | - | ||||||
254 | - | |||||||
255 | void QListData::remove(int i) | - | ||||||
256 | { | - | ||||||
257 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
258 | i += d->begin; | - | ||||||
259 | if (i - d->begin < d->end - i) { | - | ||||||
260 | if (int offset = i - d->begin) | - | ||||||
261 | ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *)); | - | ||||||
262 | d->begin++; | - | ||||||
263 | } else { | - | ||||||
264 | if (int offset = d->end - i - 1) | - | ||||||
265 | ::memmove(d->array + i, d->array + i + 1, offset * sizeof(void *)); | - | ||||||
266 | d->end--; | - | ||||||
267 | } | - | ||||||
268 | } | - | ||||||
269 | - | |||||||
270 | void QListData::remove(int i, int n) | - | ||||||
271 | { | - | ||||||
272 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
273 | i += d->begin; | - | ||||||
274 | int middle = i + n/2; | - | ||||||
275 | if (middle - d->begin < d->end - middle) { | - | ||||||
276 | ::memmove(d->array + d->begin + n, d->array + d->begin, | - | ||||||
277 | (i - d->begin) * sizeof(void*)); | - | ||||||
278 | d->begin += n; | - | ||||||
279 | } else { | - | ||||||
280 | ::memmove(d->array + i, d->array + i + n, | - | ||||||
281 | (d->end - i - n) * sizeof(void*)); | - | ||||||
282 | d->end -= n; | - | ||||||
283 | } | - | ||||||
284 | } | - | ||||||
285 | - | |||||||
286 | void QListData::move(int from, int to) | - | ||||||
287 | { | - | ||||||
288 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
289 | if (from == to) | - | ||||||
290 | return; | - | ||||||
291 | - | |||||||
292 | from += d->begin; | - | ||||||
293 | to += d->begin; | - | ||||||
294 | void *t = d->array[from]; | - | ||||||
295 | - | |||||||
296 | if (from < to) { | - | ||||||
297 | if (d->end == d->alloc || 3 * (to - from) < 2 * (d->end - d->begin)) { | - | ||||||
298 | ::memmove(d->array + from, d->array + from + 1, (to - from) * sizeof(void *)); | - | ||||||
299 | } else { | - | ||||||
300 | // optimization | - | ||||||
301 | if (int offset = from - d->begin) | - | ||||||
302 | ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *)); | - | ||||||
303 | if (int offset = d->end - (to + 1)) | - | ||||||
304 | ::memmove(d->array + to + 2, d->array + to + 1, offset * sizeof(void *)); | - | ||||||
305 | ++d->begin; | - | ||||||
306 | ++d->end; | - | ||||||
307 | ++to; | - | ||||||
308 | } | - | ||||||
309 | } else { | - | ||||||
310 | if (d->begin == 0 || 3 * (from - to) < 2 * (d->end - d->begin)) { | - | ||||||
311 | ::memmove(d->array + to + 1, d->array + to, (from - to) * sizeof(void *)); | - | ||||||
312 | } else { | - | ||||||
313 | // optimization | - | ||||||
314 | if (int offset = to - d->begin) | - | ||||||
315 | ::memmove(d->array + d->begin - 1, d->array + d->begin, offset * sizeof(void *)); | - | ||||||
316 | if (int offset = d->end - (from + 1)) | - | ||||||
317 | ::memmove(d->array + from, d->array + from + 1, offset * sizeof(void *)); | - | ||||||
318 | --d->begin; | - | ||||||
319 | --d->end; | - | ||||||
320 | --to; | - | ||||||
321 | } | - | ||||||
322 | } | - | ||||||
323 | d->array[to] = t; | - | ||||||
324 | } | - | ||||||
325 | - | |||||||
326 | void **QListData::erase(void **xi) | - | ||||||
327 | { | - | ||||||
328 | Q_ASSERT(!d->ref.isShared()); | - | ||||||
329 | int i = xi - (d->array + d->begin); | - | ||||||
330 | remove(i); | - | ||||||
331 | return d->array + d->begin + i; | - | ||||||
332 | } | - | ||||||
333 | - | |||||||
334 | /*! \class QList | - | ||||||
335 | \inmodule QtCore | - | ||||||
336 | \brief The QList class is a template class that provides lists. | - | ||||||
337 | - | |||||||
338 | \ingroup tools | - | ||||||
339 | \ingroup shared | - | ||||||
340 | - | |||||||
341 | \reentrant | - | ||||||
342 | - | |||||||
343 | QList\<T\> is one of Qt's generic \l{container classes}. It | - | ||||||
344 | stores items in a list that provides fast index-based access | - | ||||||
345 | and index-based insertions and removals. | - | ||||||
346 | - | |||||||
347 | QList\<T\>, QLinkedList\<T\>, and QVector\<T\> provide similar | - | ||||||
348 | APIs and functionality. They are often interchangeable, but there | - | ||||||
349 | are performance consequences. Here is an overview of use cases: | - | ||||||
350 | - | |||||||
351 | \list | - | ||||||
352 | \li QVector should be your default first choice. | - | ||||||
353 | QVector\<T\> will usually give better performance than QList\<T\>, | - | ||||||
354 | because QVector\<T\> always stores its items sequentially in memory, | - | ||||||
355 | where QList\<T\> will allocate its items on the heap unless | - | ||||||
356 | \c {sizeof(T) <= sizeof(void*)} and T has been declared to be | - | ||||||
357 | either a \c{Q_MOVABLE_TYPE} or a \c{Q_PRIMITIVE_TYPE} using | - | ||||||
358 | \l {Q_DECLARE_TYPEINFO}. See the \l {Pros and Cons of Using QList} | - | ||||||
359 | for an explanation. | - | ||||||
360 | \li However, QList is used throughout the Qt APIs for passing | - | ||||||
361 | parameters and for returning values. Use QList to interface with | - | ||||||
362 | those APIs. | - | ||||||
363 | \li If you need a real linked list, which guarantees | - | ||||||
364 | \l {Algorithmic Complexity}{constant time} insertions mid-list and | - | ||||||
365 | uses iterators to items rather than indexes, use QLinkedList. | - | ||||||
366 | \endlist | - | ||||||
367 | - | |||||||
368 | \note QVector and QVarLengthArray both guarantee C-compatible | - | ||||||
369 | array layout. QList does not. This might be important if your | - | ||||||
370 | application must interface with a C API. | - | ||||||
371 | - | |||||||
372 | \note Iterators into a QLinkedList and references into | - | ||||||
373 | heap-allocating QLists remain valid as long as the referenced items | - | ||||||
374 | remain in the container. This is not true for iterators and | - | ||||||
375 | references into a QVector and non-heap-allocating QLists. | - | ||||||
376 | - | |||||||
377 | Internally, QList\<T\> is represented as an array of T if | - | ||||||
378 | \c{sizeof(T) <= sizeof(void*)} and T has been declared to be | - | ||||||
379 | either a \c{Q_MOVABLE_TYPE} or a \c{Q_PRIMITIVE_TYPE} using | - | ||||||
380 | \l {Q_DECLARE_TYPEINFO}. Otherwise, QList\<T\> is represented | - | ||||||
381 | as an array of T* and the items are allocated on the heap. | - | ||||||
382 | - | |||||||
383 | The array representation allows very fast insertions and | - | ||||||
384 | index-based access. The prepend() and append() operations are | - | ||||||
385 | also very fast because QList preallocates memory at both | - | ||||||
386 | ends of its internal array. (See \l{Algorithmic Complexity} for | - | ||||||
387 | details. | - | ||||||
388 | - | |||||||
389 | Note, however, that when the conditions specified above are not met, | - | ||||||
390 | each append or insert of a new item requires allocating the new item | - | ||||||
391 | on the heap, and this per item allocation will make QVector a better | - | ||||||
392 | choice for use cases that do a lot of appending or inserting, because | - | ||||||
393 | QVector can allocate memory for many items in a single heap allocation. | - | ||||||
394 | - | |||||||
395 | Note that the internal array only ever gets bigger over the life | - | ||||||
396 | of the list. It never shrinks. The internal array is deallocated | - | ||||||
397 | by the destructor and by the assignment operator, when one list | - | ||||||
398 | is assigned to another. | - | ||||||
399 | - | |||||||
400 | Here's an example of a QList that stores integers and | - | ||||||
401 | a QList that stores QDate values: | - | ||||||
402 | - | |||||||
403 | \snippet code/src_corelib_tools_qlistdata.cpp 0 | - | ||||||
404 | - | |||||||
405 | Qt includes a QStringList class that inherits QList\<QString\> | - | ||||||
406 | and adds a few convenience functions, such as QStringList::join() | - | ||||||
407 | and QStringList::filter(). QString::split() creates QStringLists | - | ||||||
408 | from strings. | - | ||||||
409 | - | |||||||
410 | QList stores a list of items. The default constructor creates an | - | ||||||
411 | empty list. To insert items into the list, you can use | - | ||||||
412 | operator<<(): | - | ||||||
413 | - | |||||||
414 | \snippet code/src_corelib_tools_qlistdata.cpp 1 | - | ||||||
415 | - | |||||||
416 | QList provides these basic functions to add, move, and remove | - | ||||||
417 | items: insert(), replace(), removeAt(), move(), and swap(). In | - | ||||||
418 | addition, it provides the following convenience functions: | - | ||||||
419 | append(), prepend(), removeFirst(), and removeLast(). | - | ||||||
420 | - | |||||||
421 | QList uses 0-based indexes, just like C++ arrays. To access the | - | ||||||
422 | item at a particular index position, you can use operator[](). On | - | ||||||
423 | non-const lists, operator[]() returns a reference to the item and | - | ||||||
424 | can be used on the left side of an assignment: | - | ||||||
425 | - | |||||||
426 | \snippet code/src_corelib_tools_qlistdata.cpp 2 | - | ||||||
427 | - | |||||||
428 | Because QList is implemented as an array of pointers for types | - | ||||||
429 | that are larger than a pointer or are not movable, this operation | - | ||||||
430 | requires (\l{Algorithmic Complexity}{constant time}). For read-only | - | ||||||
431 | access, an alternative syntax is to use at(): | - | ||||||
432 | - | |||||||
433 | \snippet code/src_corelib_tools_qlistdata.cpp 3 | - | ||||||
434 | - | |||||||
435 | at() can be faster than operator[](), because it never causes a | - | ||||||
436 | \l{deep copy} to occur. | - | ||||||
437 | - | |||||||
438 | A common requirement is to remove an item from a list and do | - | ||||||
439 | something with it. For this, QList provides takeAt(), takeFirst(), | - | ||||||
440 | and takeLast(). Here's a loop that removes the items from a list | - | ||||||
441 | one at a time and calls \c delete on them: | - | ||||||
442 | - | |||||||
443 | \snippet code/src_corelib_tools_qlistdata.cpp 4 | - | ||||||
444 | - | |||||||
445 | Inserting and removing items at either end of the list is very | - | ||||||
446 | fast (\l{Algorithmic Complexity}{constant time} in most cases), | - | ||||||
447 | because QList preallocates extra space on both sides of its | - | ||||||
448 | internal buffer to allow for fast growth at both ends of the list. | - | ||||||
449 | - | |||||||
450 | If you want to find all occurrences of a particular value in a | - | ||||||
451 | list, use indexOf() or lastIndexOf(). The former searches forward | - | ||||||
452 | starting from a given index position, the latter searches | - | ||||||
453 | backward. Both return the index of a matching item if they find | - | ||||||
454 | it; otherwise, they return -1. For example: | - | ||||||
455 | - | |||||||
456 | \snippet code/src_corelib_tools_qlistdata.cpp 5 | - | ||||||
457 | - | |||||||
458 | If you simply want to check whether a list contains a particular | - | ||||||
459 | value, use contains(). If you want to find out how many times a | - | ||||||
460 | particular value occurs in the list, use count(). If you want to | - | ||||||
461 | replace all occurrences of a particular value with another, use | - | ||||||
462 | replace(). | - | ||||||
463 | - | |||||||
464 | QList's value type must be an \l{assignable data type}. This | - | ||||||
465 | covers most data types that are commonly used, but the compiler | - | ||||||
466 | won't let you, for example, store a QWidget as a value; instead, | - | ||||||
467 | store a QWidget *. A few functions have additional requirements; | - | ||||||
468 | for example, indexOf() and lastIndexOf() expect the value type to | - | ||||||
469 | support \c operator==(). These requirements are documented on a | - | ||||||
470 | per-function basis. | - | ||||||
471 | - | |||||||
472 | Like the other container classes, QList provides \l{Java-style | - | ||||||
473 | iterators} (QListIterator and QMutableListIterator) and | - | ||||||
474 | \l{STL-style iterators} (QList::const_iterator and | - | ||||||
475 | QList::iterator). In practice, these are rarely used, because you | - | ||||||
476 | can use indexes into the QList. QList is implemented in such a way | - | ||||||
477 | that direct index-based access is just as fast as using iterators. | - | ||||||
478 | - | |||||||
479 | QList does \e not support inserting, prepending, appending or | - | ||||||
480 | replacing with references to its own values. Doing so will cause | - | ||||||
481 | your application to abort with an error message. | - | ||||||
482 | - | |||||||
483 | To make QList as efficient as possible, its member functions don't | - | ||||||
484 | validate their input before using it. Except for isEmpty(), member | - | ||||||
485 | functions always assume the list is \e not empty. Member functions | - | ||||||
486 | that take index values as parameters always assume their index | - | ||||||
487 | value parameters are in the valid range. This means QList member | - | ||||||
488 | functions can fail. If you define QT_NO_DEBUG when you compile, | - | ||||||
489 | failures will not be detected. If you \e don't define QT_NO_DEBUG, | - | ||||||
490 | failures will be detected using Q_ASSERT() or Q_ASSERT_X() with an | - | ||||||
491 | appropriate message. | - | ||||||
492 | - | |||||||
493 | To avoid failures when your list can be empty, call isEmpty() | - | ||||||
494 | before calling other member functions. If you must pass an index | - | ||||||
495 | value that might not be in the valid range, check that it is less | - | ||||||
496 | than the value returned by size() but \e not less than 0. | - | ||||||
497 | - | |||||||
498 | \section1 More Members | - | ||||||
499 | - | |||||||
500 | If T is a QByteArray, this class has a couple more members that can be | - | ||||||
501 | used. See the documentation for QByteArrayList for more information. | - | ||||||
502 | - | |||||||
503 | If T is QString, this class has the following additional members: | - | ||||||
504 | \l{QStringList::filter()}{filter}, | - | ||||||
505 | \l{QStringList::join()}{join}, | - | ||||||
506 | \l{QStringList::removeDuplicates()}{removeDuplicates}, | - | ||||||
507 | \l{QStringList::sort()}{sort}. | - | ||||||
508 | - | |||||||
509 | \section1 More Information on Using Qt Containers | - | ||||||
510 | - | |||||||
511 | For a detailed discussion comparing Qt containers with each other and | - | ||||||
512 | with STL containers, see \l {Understand the Qt Containers}. | - | ||||||
513 | - | |||||||
514 | \sa QListIterator, QMutableListIterator, QLinkedList, QVector | - | ||||||
515 | */ | - | ||||||
516 | - | |||||||
517 | /*! | - | ||||||
518 | \fn QList::QList(QList<T> &&other) | - | ||||||
519 | - | |||||||
520 | Move-constructs a QList instance, making it point at the same | - | ||||||
521 | object that \a other was pointing to. | - | ||||||
522 | - | |||||||
523 | \since 5.2 | - | ||||||
524 | */ | - | ||||||
525 | - | |||||||
526 | /*! | - | ||||||
527 | \fn QList<T> QList<T>::mid(int pos, int length) const | - | ||||||
528 | - | |||||||
529 | Returns a sub-list which includes elements from this list, | - | ||||||
530 | starting at position \a pos. If \a length is -1 (the default), all | - | ||||||
531 | elements from \a pos are included; otherwise \a length elements (or | - | ||||||
532 | all remaining elements if there are less than \a length elements) | - | ||||||
533 | are included. | - | ||||||
534 | */ | - | ||||||
535 | - | |||||||
536 | /*! \fn QList::QList() | - | ||||||
537 | - | |||||||
538 | Constructs an empty list. | - | ||||||
539 | */ | - | ||||||
540 | - | |||||||
541 | /*! \fn QList::QList(const QList<T> &other) | - | ||||||
542 | - | |||||||
543 | Constructs a copy of \a other. | - | ||||||
544 | - | |||||||
545 | This operation takes \l{Algorithmic Complexity}{constant time}, | - | ||||||
546 | because QList is \l{implicitly shared}. This makes returning a | - | ||||||
547 | QList from a function very fast. If a shared instance is modified, | - | ||||||
548 | it will be copied (copy-on-write), and that takes | - | ||||||
549 | \l{Algorithmic Complexity}{linear time}. | - | ||||||
550 | - | |||||||
551 | \sa operator=() | - | ||||||
552 | */ | - | ||||||
553 | - | |||||||
554 | /*! \fn inline QList::QList(std::initializer_list<T> args) | - | ||||||
555 | \since 4.8 | - | ||||||
556 | - | |||||||
557 | Construct a list from the std::initializer_list specified by \a args. | - | ||||||
558 | - | |||||||
559 | This constructor is only enabled if the compiler supports C++11 initializer | - | ||||||
560 | lists. | - | ||||||
561 | */ | - | ||||||
562 | - | |||||||
563 | /*! \fn QList::~QList() | - | ||||||
564 | - | |||||||
565 | Destroys the list. References to the values in the list and all | - | ||||||
566 | iterators of this list become invalid. | - | ||||||
567 | */ | - | ||||||
568 | - | |||||||
569 | /*! \fn QList<T> &QList::operator=(const QList<T> &other) | - | ||||||
570 | - | |||||||
571 | Assigns \a other to this list and returns a reference to this | - | ||||||
572 | list. | - | ||||||
573 | */ | - | ||||||
574 | - | |||||||
575 | /*! | - | ||||||
576 | \fn QList &QList::operator=(QList<T> &&other) | - | ||||||
577 | - | |||||||
578 | Move-assigns \a other to this QList instance. | - | ||||||
579 | - | |||||||
580 | \since 5.2 | - | ||||||
581 | */ | - | ||||||
582 | - | |||||||
583 | /*! \fn void QList::swap(QList<T> &other) | - | ||||||
584 | \since 4.8 | - | ||||||
585 | - | |||||||
586 | Swaps list \a other with this list. This operation is very | - | ||||||
587 | fast and never fails. | - | ||||||
588 | */ | - | ||||||
589 | - | |||||||
590 | /*! \fn bool QList::operator==(const QList<T> &other) const | - | ||||||
591 | - | |||||||
592 | Returns \c true if \a other is equal to this list; otherwise returns | - | ||||||
593 | false. | - | ||||||
594 | - | |||||||
595 | Two lists are considered equal if they contain the same values in | - | ||||||
596 | the same order. | - | ||||||
597 | - | |||||||
598 | This function requires the value type to have an implementation of | - | ||||||
599 | \c operator==(). | - | ||||||
600 | - | |||||||
601 | \sa operator!=() | - | ||||||
602 | */ | - | ||||||
603 | - | |||||||
604 | /*! \fn bool QList::operator!=(const QList<T> &other) const | - | ||||||
605 | - | |||||||
606 | Returns \c true if \a other is not equal to this list; otherwise | - | ||||||
607 | returns \c false. | - | ||||||
608 | - | |||||||
609 | Two lists are considered equal if they contain the same values in | - | ||||||
610 | the same order. | - | ||||||
611 | - | |||||||
612 | This function requires the value type to have an implementation of | - | ||||||
613 | \c operator==(). | - | ||||||
614 | - | |||||||
615 | \sa operator==() | - | ||||||
616 | */ | - | ||||||
617 | - | |||||||
618 | /*! \fn bool operator<(const QList<T> &lhs, const QList<T> &rhs) | - | ||||||
619 | \since 5.6 | - | ||||||
620 | \relates QList | - | ||||||
621 | - | |||||||
622 | Returns \c true if list \a lhs is | - | ||||||
623 | \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} | - | ||||||
624 | {lexicographically less than} \a rhs; otherwise returns \c false. | - | ||||||
625 | - | |||||||
626 | This function requires the value type to have an implementation | - | ||||||
627 | of \c operator<(). | - | ||||||
628 | */ | - | ||||||
629 | - | |||||||
630 | /*! \fn bool operator<=(const QList<T> &lhs, const QList<T> &rhs) | - | ||||||
631 | \since 5.6 | - | ||||||
632 | \relates QList | - | ||||||
633 | - | |||||||
634 | Returns \c true if list \a lhs is | - | ||||||
635 | \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} | - | ||||||
636 | {lexicographically less than or equal to} \a rhs; otherwise returns \c false. | - | ||||||
637 | - | |||||||
638 | This function requires the value type to have an implementation | - | ||||||
639 | of \c operator<(). | - | ||||||
640 | */ | - | ||||||
641 | - | |||||||
642 | /*! \fn bool operator>(const QList<T> &lhs, const QList<T> &rhs) | - | ||||||
643 | \since 5.6 | - | ||||||
644 | \relates QList | - | ||||||
645 | - | |||||||
646 | Returns \c true if list \a lhs is | - | ||||||
647 | \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} | - | ||||||
648 | {lexicographically greater than} \a rhs; otherwise returns \c false. | - | ||||||
649 | - | |||||||
650 | This function requires the value type to have an implementation | - | ||||||
651 | of \c operator<(). | - | ||||||
652 | */ | - | ||||||
653 | - | |||||||
654 | /*! \fn bool operator>=(const QList<T> &lhs, const QList<T> &rhs) | - | ||||||
655 | \since 5.6 | - | ||||||
656 | \relates QList | - | ||||||
657 | - | |||||||
658 | Returns \c true if list \a lhs is | - | ||||||
659 | \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} | - | ||||||
660 | {lexicographically greater than or equal to} \a rhs; otherwise returns \c false. | - | ||||||
661 | - | |||||||
662 | This function requires the value type to have an implementation | - | ||||||
663 | of \c operator<(). | - | ||||||
664 | */ | - | ||||||
665 | - | |||||||
666 | /*! | - | ||||||
667 | \fn uint qHash(const QList<T> &key, uint seed = 0) | - | ||||||
668 | \since 5.6 | - | ||||||
669 | \relates QList | - | ||||||
670 | - | |||||||
671 | Returns the hash value for \a key, | - | ||||||
672 | using \a seed to seed the calculation. | - | ||||||
673 | - | |||||||
674 | This function requires qHash() to be overloaded for the value type \c T. | - | ||||||
675 | */ | - | ||||||
676 | - | |||||||
677 | /*! | - | ||||||
678 | \fn int QList::size() const | - | ||||||
679 | - | |||||||
680 | Returns the number of items in the list. | - | ||||||
681 | - | |||||||
682 | \sa isEmpty(), count() | - | ||||||
683 | */ | - | ||||||
684 | - | |||||||
685 | /*! \fn void QList::detach() | - | ||||||
686 | - | |||||||
687 | \internal | - | ||||||
688 | */ | - | ||||||
689 | - | |||||||
690 | /*! \fn void QList::detachShared() | - | ||||||
691 | - | |||||||
692 | \internal | - | ||||||
693 | - | |||||||
694 | like detach(), but does nothing if we're shared_null. | - | ||||||
695 | This prevents needless mallocs, and makes QList more exception safe | - | ||||||
696 | in case of cleanup work done in destructors on empty lists. | - | ||||||
697 | */ | - | ||||||
698 | - | |||||||
699 | /*! \fn bool QList::isDetached() const | - | ||||||
700 | - | |||||||
701 | \internal | - | ||||||
702 | */ | - | ||||||
703 | - | |||||||
704 | /*! \fn void QList::setSharable(bool sharable) | - | ||||||
705 | - | |||||||
706 | \internal | - | ||||||
707 | */ | - | ||||||
708 | - | |||||||
709 | /*! \fn bool QList::isSharedWith(const QList<T> &other) const | - | ||||||
710 | - | |||||||
711 | \internal | - | ||||||
712 | */ | - | ||||||
713 | - | |||||||
714 | /*! \fn bool QList::isEmpty() const | - | ||||||
715 | - | |||||||
716 | Returns \c true if the list contains no items; otherwise returns | - | ||||||
717 | false. | - | ||||||
718 | - | |||||||
719 | \sa size() | - | ||||||
720 | */ | - | ||||||
721 | - | |||||||
722 | /*! \fn void QList::clear() | - | ||||||
723 | - | |||||||
724 | Removes all items from the list. | - | ||||||
725 | - | |||||||
726 | \sa removeAll() | - | ||||||
727 | */ | - | ||||||
728 | - | |||||||
729 | /*! \fn const T &QList::at(int i) const | - | ||||||
730 | - | |||||||
731 | Returns the item at index position \a i in the list. \a i must be | - | ||||||
732 | a valid index position in the list (i.e., 0 <= \a i < size()). | - | ||||||
733 | - | |||||||
734 | This function is very fast (\l{Algorithmic Complexity}{constant time}). | - | ||||||
735 | - | |||||||
736 | \sa value(), operator[]() | - | ||||||
737 | */ | - | ||||||
738 | - | |||||||
739 | /*! \fn T &QList::operator[](int i) | - | ||||||
740 | - | |||||||
741 | Returns the item at index position \a i as a modifiable reference. | - | ||||||
742 | \a i must be a valid index position in the list (i.e., 0 <= \a i < | - | ||||||
743 | size()). | - | ||||||
744 | - | |||||||
745 | If this function is called on a list that is currently being shared, it | - | ||||||
746 | will trigger a copy of all elements. Otherwise, this function runs in | - | ||||||
747 | \l{Algorithmic Complexity}{constant time}. If you do not want to modify | - | ||||||
748 | the list you should use QList::at(). | - | ||||||
749 | - | |||||||
750 | \sa at(), value() | - | ||||||
751 | */ | - | ||||||
752 | - | |||||||
753 | /*! \fn const T &QList::operator[](int i) const | - | ||||||
754 | - | |||||||
755 | \overload | - | ||||||
756 | - | |||||||
757 | Same as at(). This function runs in \l{Algorithmic Complexity}{constant time}. | - | ||||||
758 | */ | - | ||||||
759 | - | |||||||
760 | /*! \fn QList::reserve(int alloc) | - | ||||||
761 | - | |||||||
762 | Reserve space for \a alloc elements. | - | ||||||
763 | - | |||||||
764 | If \a alloc is smaller than the current size of the list, nothing will happen. | - | ||||||
765 | - | |||||||
766 | Use this function to avoid repetetive reallocation of QList's internal | - | ||||||
767 | data if you can predict how many elements will be appended. | - | ||||||
768 | Note that the reservation applies only to the internal pointer array. | - | ||||||
769 | - | |||||||
770 | \since 4.7 | - | ||||||
771 | */ | - | ||||||
772 | - | |||||||
773 | /*! \fn void QList::append(const T &value) | - | ||||||
774 | - | |||||||
775 | Inserts \a value at the end of the list. | - | ||||||
776 | - | |||||||
777 | Example: | - | ||||||
778 | \snippet code/src_corelib_tools_qlistdata.cpp 6 | - | ||||||
779 | - | |||||||
780 | This is the same as list.insert(size(), \a value). | - | ||||||
781 | - | |||||||
782 | If this list is not shared, this operation is typically | - | ||||||
783 | very fast (amortized \l{Algorithmic Complexity}{constant time}), | - | ||||||
784 | because QList preallocates extra space on both sides of its | - | ||||||
785 | internal buffer to allow for fast growth at both ends of the list. | - | ||||||
786 | - | |||||||
787 | \sa operator<<(), prepend(), insert() | - | ||||||
788 | */ | - | ||||||
789 | - | |||||||
790 | /*! \fn void QList::append(const QList<T> &value) | - | ||||||
791 | - | |||||||
792 | \overload | - | ||||||
793 | - | |||||||
794 | \since 4.5 | - | ||||||
795 | - | |||||||
796 | Appends the items of the \a value list to this list. | - | ||||||
797 | - | |||||||
798 | \sa operator<<(), operator+=() | - | ||||||
799 | */ | - | ||||||
800 | - | |||||||
801 | /*! \fn void QList::prepend(const T &value) | - | ||||||
802 | - | |||||||
803 | Inserts \a value at the beginning of the list. | - | ||||||
804 | - | |||||||
805 | Example: | - | ||||||
806 | \snippet code/src_corelib_tools_qlistdata.cpp 7 | - | ||||||
807 | - | |||||||
808 | This is the same as list.insert(0, \a value). | - | ||||||
809 | - | |||||||
810 | If this list is not shared, this operation is typically | - | ||||||
811 | very fast (amortized \l{Algorithmic Complexity}{constant time}), | - | ||||||
812 | because QList preallocates extra space on both sides of its | - | ||||||
813 | internal buffer to allow for fast growth at both ends of the list. | - | ||||||
814 | - | |||||||
815 | \sa append(), insert() | - | ||||||
816 | */ | - | ||||||
817 | - | |||||||
818 | /*! \fn void QList::insert(int i, const T &value) | - | ||||||
819 | - | |||||||
820 | Inserts \a value at index position \a i in the list. If \a i <= 0, | - | ||||||
821 | the value is prepended to the list. If \a i >= size(), the | - | ||||||
822 | value is appended to the list. | - | ||||||
823 | - | |||||||
824 | Example: | - | ||||||
825 | \snippet code/src_corelib_tools_qlistdata.cpp 8 | - | ||||||
826 | - | |||||||
827 | \sa append(), prepend(), replace(), removeAt() | - | ||||||
828 | */ | - | ||||||
829 | - | |||||||
830 | /*! \fn QList::iterator QList::insert(iterator before, const T &value) | - | ||||||
831 | - | |||||||
832 | \overload | - | ||||||
833 | - | |||||||
834 | Inserts \a value in front of the item pointed to by the | - | ||||||
835 | iterator \a before. Returns an iterator pointing at the inserted | - | ||||||
836 | item. Note that the iterator passed to the function will be | - | ||||||
837 | invalid after the call; the returned iterator should be used | - | ||||||
838 | instead. | - | ||||||
839 | */ | - | ||||||
840 | - | |||||||
841 | /*! \fn void QList::replace(int i, const T &value) | - | ||||||
842 | - | |||||||
843 | Replaces the item at index position \a i with \a value. \a i must | - | ||||||
844 | be a valid index position in the list (i.e., 0 <= \a i < size()). | - | ||||||
845 | - | |||||||
846 | \sa operator[](), removeAt() | - | ||||||
847 | */ | - | ||||||
848 | - | |||||||
849 | /*! | - | ||||||
850 | \fn int QList::removeAll(const T &value) | - | ||||||
851 | - | |||||||
852 | Removes all occurrences of \a value in the list and returns the | - | ||||||
853 | number of entries removed. | - | ||||||
854 | - | |||||||
855 | Example: | - | ||||||
856 | \snippet code/src_corelib_tools_qlistdata.cpp 9 | - | ||||||
857 | - | |||||||
858 | This function requires the value type to have an implementation of | - | ||||||
859 | \c operator==(). | - | ||||||
860 | - | |||||||
861 | \sa removeOne(), removeAt(), takeAt(), replace() | - | ||||||
862 | */ | - | ||||||
863 | - | |||||||
864 | /*! | - | ||||||
865 | \fn bool QList::removeOne(const T &value) | - | ||||||
866 | \since 4.4 | - | ||||||
867 | - | |||||||
868 | Removes the first occurrence of \a value in the list and returns | - | ||||||
869 | true on success; otherwise returns \c false. | - | ||||||
870 | - | |||||||
871 | Example: | - | ||||||
872 | \snippet code/src_corelib_tools_qlistdata.cpp 10 | - | ||||||
873 | - | |||||||
874 | This function requires the value type to have an implementation of | - | ||||||
875 | \c operator==(). | - | ||||||
876 | - | |||||||
877 | \sa removeAll(), removeAt(), takeAt(), replace() | - | ||||||
878 | */ | - | ||||||
879 | - | |||||||
880 | /*! \fn void QList::removeAt(int i) | - | ||||||
881 | - | |||||||
882 | Removes the item at index position \a i. \a i must be a valid | - | ||||||
883 | index position in the list (i.e., 0 <= \a i < size()). | - | ||||||
884 | - | |||||||
885 | \sa takeAt(), removeFirst(), removeLast(), removeOne() | - | ||||||
886 | */ | - | ||||||
887 | - | |||||||
888 | /*! \fn T QList::takeAt(int i) | - | ||||||
889 | - | |||||||
890 | Removes the item at index position \a i and returns it. \a i must | - | ||||||
891 | be a valid index position in the list (i.e., 0 <= \a i < size()). | - | ||||||
892 | - | |||||||
893 | If you don't use the return value, removeAt() is more efficient. | - | ||||||
894 | - | |||||||
895 | \sa removeAt(), takeFirst(), takeLast() | - | ||||||
896 | */ | - | ||||||
897 | - | |||||||
898 | /*! \fn T QList::takeFirst() | - | ||||||
899 | - | |||||||
900 | Removes the first item in the list and returns it. This is the | - | ||||||
901 | same as takeAt(0). This function assumes the list is not empty. To | - | ||||||
902 | avoid failure, call isEmpty() before calling this function. | - | ||||||
903 | - | |||||||
904 | If this list is not shared, this operation takes | - | ||||||
905 | \l {Algorithmic Complexity}{constant time}. | - | ||||||
906 | - | |||||||
907 | If you don't use the return value, removeFirst() is more | - | ||||||
908 | efficient. | - | ||||||
909 | - | |||||||
910 | \sa takeLast(), takeAt(), removeFirst() | - | ||||||
911 | */ | - | ||||||
912 | - | |||||||
913 | /*! \fn T QList::takeLast() | - | ||||||
914 | - | |||||||
915 | Removes the last item in the list and returns it. This is the | - | ||||||
916 | same as takeAt(size() - 1). This function assumes the list is | - | ||||||
917 | not empty. To avoid failure, call isEmpty() before calling this | - | ||||||
918 | function. | - | ||||||
919 | - | |||||||
920 | If this list is not shared, this operation takes | - | ||||||
921 | \l {Algorithmic Complexity}{constant time}. | - | ||||||
922 | - | |||||||
923 | If you don't use the return value, removeLast() is more | - | ||||||
924 | efficient. | - | ||||||
925 | - | |||||||
926 | \sa takeFirst(), takeAt(), removeLast() | - | ||||||
927 | */ | - | ||||||
928 | - | |||||||
929 | /*! \fn void QList::move(int from, int to) | - | ||||||
930 | - | |||||||
931 | Moves the item at index position \a from to index position \a to. | - | ||||||
932 | - | |||||||
933 | Example: | - | ||||||
934 | \snippet code/src_corelib_tools_qlistdata.cpp 11 | - | ||||||
935 | - | |||||||
936 | This is the same as insert(\a{to}, takeAt(\a{from})).This function | - | ||||||
937 | assumes that both \a from and \a to are at least 0 but less than | - | ||||||
938 | size(). To avoid failure, test that both \a from and \a to are at | - | ||||||
939 | least 0 and less than size(). | - | ||||||
940 | - | |||||||
941 | \sa swap(), insert(), takeAt() | - | ||||||
942 | */ | - | ||||||
943 | - | |||||||
944 | /*! \fn void QList::swap(int i, int j) | - | ||||||
945 | - | |||||||
946 | Exchange the item at index position \a i with the item at index | - | ||||||
947 | position \a j. This function assumes that both \a i and \a j are | - | ||||||
948 | at least 0 but less than size(). To avoid failure, test that both | - | ||||||
949 | \a i and \a j are at least 0 and less than size(). | - | ||||||
950 | - | |||||||
951 | Example: | - | ||||||
952 | \snippet code/src_corelib_tools_qlistdata.cpp 12 | - | ||||||
953 | - | |||||||
954 | \sa move() | - | ||||||
955 | */ | - | ||||||
956 | - | |||||||
957 | /*! \fn int QList::indexOf(const T &value, int from = 0) const | - | ||||||
958 | - | |||||||
959 | Returns the index position of the first occurrence of \a value in | - | ||||||
960 | the list, searching forward from index position \a from. Returns | - | ||||||
961 | -1 if no item matched. | - | ||||||
962 | - | |||||||
963 | Example: | - | ||||||
964 | \snippet code/src_corelib_tools_qlistdata.cpp 13 | - | ||||||
965 | - | |||||||
966 | This function requires the value type to have an implementation of | - | ||||||
967 | \c operator==(). | - | ||||||
968 | - | |||||||
969 | Note that QList uses 0-based indexes, just like C++ arrays. Negative | - | ||||||
970 | indexes are not supported with the exception of the value mentioned | - | ||||||
971 | above. | - | ||||||
972 | - | |||||||
973 | \sa lastIndexOf(), contains() | - | ||||||
974 | */ | - | ||||||
975 | - | |||||||
976 | /*! \fn int QList::lastIndexOf(const T &value, int from = -1) const | - | ||||||
977 | - | |||||||
978 | Returns the index position of the last occurrence of \a value in | - | ||||||
979 | the list, searching backward from index position \a from. If \a | - | ||||||
980 | from is -1 (the default), the search starts at the last item. | - | ||||||
981 | Returns -1 if no item matched. | - | ||||||
982 | - | |||||||
983 | Example: | - | ||||||
984 | \snippet code/src_corelib_tools_qlistdata.cpp 14 | - | ||||||
985 | - | |||||||
986 | This function requires the value type to have an implementation of | - | ||||||
987 | \c operator==(). | - | ||||||
988 | - | |||||||
989 | Note that QList uses 0-based indexes, just like C++ arrays. Negative | - | ||||||
990 | indexes are not supported with the exception of the value mentioned | - | ||||||
991 | above. | - | ||||||
992 | - | |||||||
993 | \sa indexOf() | - | ||||||
994 | */ | - | ||||||
995 | - | |||||||
996 | /*! \fn bool QList::contains(const T &value) const | - | ||||||
997 | - | |||||||
998 | Returns \c true if the list contains an occurrence of \a value; | - | ||||||
999 | otherwise returns \c false. | - | ||||||
1000 | - | |||||||
1001 | This function requires the value type to have an implementation of | - | ||||||
1002 | \c operator==(). | - | ||||||
1003 | - | |||||||
1004 | \sa indexOf(), count() | - | ||||||
1005 | */ | - | ||||||
1006 | - | |||||||
1007 | /*! \fn int QList::count(const T &value) const | - | ||||||
1008 | - | |||||||
1009 | Returns the number of occurrences of \a value in the list. | - | ||||||
1010 | - | |||||||
1011 | This function requires the value type to have an implementation of | - | ||||||
1012 | \c operator==(). | - | ||||||
1013 | - | |||||||
1014 | \sa contains(), indexOf() | - | ||||||
1015 | */ | - | ||||||
1016 | - | |||||||
1017 | /*! \fn bool QList::startsWith(const T &value) const | - | ||||||
1018 | \since 4.5 | - | ||||||
1019 | - | |||||||
1020 | Returns \c true if this list is not empty and its first | - | ||||||
1021 | item is equal to \a value; otherwise returns \c false. | - | ||||||
1022 | - | |||||||
1023 | \sa isEmpty(), contains() | - | ||||||
1024 | */ | - | ||||||
1025 | - | |||||||
1026 | /*! \fn bool QList::endsWith(const T &value) const | - | ||||||
1027 | \since 4.5 | - | ||||||
1028 | - | |||||||
1029 | Returns \c true if this list is not empty and its last | - | ||||||
1030 | item is equal to \a value; otherwise returns \c false. | - | ||||||
1031 | - | |||||||
1032 | \sa isEmpty(), contains() | - | ||||||
1033 | */ | - | ||||||
1034 | - | |||||||
1035 | /*! \fn QList::iterator QList::begin() | - | ||||||
1036 | - | |||||||
1037 | Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in | - | ||||||
1038 | the list. | - | ||||||
1039 | - | |||||||
1040 | \sa constBegin(), end() | - | ||||||
1041 | */ | - | ||||||
1042 | - | |||||||
1043 | /*! \fn QList::const_iterator QList::begin() const | - | ||||||
1044 | - | |||||||
1045 | \overload | - | ||||||
1046 | */ | - | ||||||
1047 | - | |||||||
1048 | /*! \fn QList::const_iterator QList::cbegin() const | - | ||||||
1049 | \since 5.0 | - | ||||||
1050 | - | |||||||
1051 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item | - | ||||||
1052 | in the list. | - | ||||||
1053 | - | |||||||
1054 | \sa begin(), cend() | - | ||||||
1055 | */ | - | ||||||
1056 | - | |||||||
1057 | /*! \fn QList::const_iterator QList::constBegin() const | - | ||||||
1058 | - | |||||||
1059 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item | - | ||||||
1060 | in the list. | - | ||||||
1061 | - | |||||||
1062 | \sa begin(), constEnd() | - | ||||||
1063 | */ | - | ||||||
1064 | - | |||||||
1065 | /*! \fn QList::iterator QList::end() | - | ||||||
1066 | - | |||||||
1067 | Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item | - | ||||||
1068 | after the last item in the list. | - | ||||||
1069 | - | |||||||
1070 | \sa begin(), constEnd() | - | ||||||
1071 | */ | - | ||||||
1072 | - | |||||||
1073 | /*! \fn const_iterator QList::end() const | - | ||||||
1074 | - | |||||||
1075 | \overload | - | ||||||
1076 | */ | - | ||||||
1077 | - | |||||||
1078 | /*! \fn QList::const_iterator QList::cend() const | - | ||||||
1079 | \since 5.0 | - | ||||||
1080 | - | |||||||
1081 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - | ||||||
1082 | item after the last item in the list. | - | ||||||
1083 | - | |||||||
1084 | \sa cbegin(), end() | - | ||||||
1085 | */ | - | ||||||
1086 | - | |||||||
1087 | /*! \fn QList::const_iterator QList::constEnd() const | - | ||||||
1088 | - | |||||||
1089 | Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary | - | ||||||
1090 | item after the last item in the list. | - | ||||||
1091 | - | |||||||
1092 | \sa constBegin(), end() | - | ||||||
1093 | */ | - | ||||||
1094 | - | |||||||
1095 | /*! \fn QList::reverse_iterator QList::rbegin() | - | ||||||
1096 | \since 5.6 | - | ||||||
1097 | - | |||||||
1098 | Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first | - | ||||||
1099 | item in the list, in reverse order. | - | ||||||
1100 | - | |||||||
1101 | \sa begin(), crbegin(), rend() | - | ||||||
1102 | */ | - | ||||||
1103 | - | |||||||
1104 | /*! \fn QList::const_reverse_iterator QList::rbegin() const | - | ||||||
1105 | \since 5.6 | - | ||||||
1106 | \overload | - | ||||||
1107 | */ | - | ||||||
1108 | - | |||||||
1109 | /*! \fn QList::const_reverse_iterator QList::crbegin() const | - | ||||||
1110 | \since 5.6 | - | ||||||
1111 | - | |||||||
1112 | Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first | - | ||||||
1113 | item in the list, in reverse order. | - | ||||||
1114 | - | |||||||
1115 | \sa begin(), rbegin(), rend() | - | ||||||
1116 | */ | - | ||||||
1117 | - | |||||||
1118 | /*! \fn QList::reverse_iterator QList::rend() | - | ||||||
1119 | \since 5.6 | - | ||||||
1120 | - | |||||||
1121 | Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past | - | ||||||
1122 | the last item in the list, in reverse order. | - | ||||||
1123 | - | |||||||
1124 | \sa end(), crend(), rbegin() | - | ||||||
1125 | */ | - | ||||||
1126 | - | |||||||
1127 | /*! \fn QList::const_reverse_iterator QList::rend() const | - | ||||||
1128 | \since 5.6 | - | ||||||
1129 | \overload | - | ||||||
1130 | */ | - | ||||||
1131 | - | |||||||
1132 | /*! \fn QList::const_reverse_iterator QList::crend() const | - | ||||||
1133 | \since 5.6 | - | ||||||
1134 | - | |||||||
1135 | Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one | - | ||||||
1136 | past the last item in the list, in reverse order. | - | ||||||
1137 | - | |||||||
1138 | \sa end(), rend(), rbegin() | - | ||||||
1139 | */ | - | ||||||
1140 | - | |||||||
1141 | /*! \fn QList::iterator QList::erase(iterator pos) | - | ||||||
1142 | - | |||||||
1143 | Removes the item associated with the iterator \a pos from the | - | ||||||
1144 | list, and returns an iterator to the next item in the list (which | - | ||||||
1145 | may be end()). | - | ||||||
1146 | - | |||||||
1147 | \sa insert(), removeAt() | - | ||||||
1148 | */ | - | ||||||
1149 | - | |||||||
1150 | /*! \fn QList::iterator QList::erase(iterator begin, iterator end) | - | ||||||
1151 | - | |||||||
1152 | \overload | - | ||||||
1153 | - | |||||||
1154 | Removes all the items from \a begin up to (but not including) \a | - | ||||||
1155 | end. Returns an iterator to the same item that \a end referred to | - | ||||||
1156 | before the call. | - | ||||||
1157 | */ | - | ||||||
1158 | - | |||||||
1159 | /*! \typedef QList::Iterator | - | ||||||
1160 | - | |||||||
1161 | Qt-style synonym for QList::iterator. | - | ||||||
1162 | */ | - | ||||||
1163 | - | |||||||
1164 | /*! \typedef QList::ConstIterator | - | ||||||
1165 | - | |||||||
1166 | Qt-style synonym for QList::const_iterator. | - | ||||||
1167 | */ | - | ||||||
1168 | - | |||||||
1169 | /*! | - | ||||||
1170 | \typedef QList::size_type | - | ||||||
1171 | - | |||||||
1172 | Typedef for int. Provided for STL compatibility. | - | ||||||
1173 | */ | - | ||||||
1174 | - | |||||||
1175 | /*! | - | ||||||
1176 | \typedef QList::value_type | - | ||||||
1177 | - | |||||||
1178 | Typedef for T. Provided for STL compatibility. | - | ||||||
1179 | */ | - | ||||||
1180 | - | |||||||
1181 | /*! | - | ||||||
1182 | \typedef QList::difference_type | - | ||||||
1183 | - | |||||||
1184 | Typedef for ptrdiff_t. Provided for STL compatibility. | - | ||||||
1185 | */ | - | ||||||
1186 | - | |||||||
1187 | /*! | - | ||||||
1188 | \typedef QList::pointer | - | ||||||
1189 | - | |||||||
1190 | Typedef for T *. Provided for STL compatibility. | - | ||||||
1191 | */ | - | ||||||
1192 | - | |||||||
1193 | /*! | - | ||||||
1194 | \typedef QList::const_pointer | - | ||||||
1195 | - | |||||||
1196 | Typedef for const T *. Provided for STL compatibility. | - | ||||||
1197 | */ | - | ||||||
1198 | - | |||||||
1199 | /*! | - | ||||||
1200 | \typedef QList::reference | - | ||||||
1201 | - | |||||||
1202 | Typedef for T &. Provided for STL compatibility. | - | ||||||
1203 | */ | - | ||||||
1204 | - | |||||||
1205 | /*! | - | ||||||
1206 | \typedef QList::const_reference | - | ||||||
1207 | - | |||||||
1208 | Typedef for const T &. Provided for STL compatibility. | - | ||||||
1209 | */ | - | ||||||
1210 | - | |||||||
1211 | /*! \typedef QList::reverse_iterator | - | ||||||
1212 | \since 5.6 | - | ||||||
1213 | - | |||||||
1214 | The QList::reverse_iterator typedef provides an STL-style non-const | - | ||||||
1215 | reverse iterator for QList. | - | ||||||
1216 | - | |||||||
1217 | It is simply a typedef for \c{std::reverse_iterator<iterator>}. | - | ||||||
1218 | - | |||||||
1219 | \warning Iterators on implicitly shared containers do not work | - | ||||||
1220 | exactly like STL-iterators. You should avoid copying a container | - | ||||||
1221 | while iterators are active on that container. For more information, | - | ||||||
1222 | read \l{Implicit sharing iterator problem}. | - | ||||||
1223 | - | |||||||
1224 | \sa QList::rbegin(), QList::rend(), QList::const_reverse_iterator, QList::iterator | - | ||||||
1225 | */ | - | ||||||
1226 | - | |||||||
1227 | /*! \typedef QList::const_reverse_iterator | - | ||||||
1228 | \since 5.6 | - | ||||||
1229 | - | |||||||
1230 | The QList::const_reverse_iterator typedef provides an STL-style const | - | ||||||
1231 | reverse iterator for QList. | - | ||||||
1232 | - | |||||||
1233 | It is simply a typedef for \c{std::reverse_iterator<const_iterator>}. | - | ||||||
1234 | - | |||||||
1235 | \warning Iterators on implicitly shared containers do not work | - | ||||||
1236 | exactly like STL-iterators. You should avoid copying a container | - | ||||||
1237 | while iterators are active on that container. For more information, | - | ||||||
1238 | read \l{Implicit sharing iterator problem}. | - | ||||||
1239 | - | |||||||
1240 | \sa QList::rbegin(), QList::rend(), QList::reverse_iterator, QList::const_iterator | - | ||||||
1241 | */ | - | ||||||
1242 | - | |||||||
1243 | /*! \fn int QList::count() const | - | ||||||
1244 | - | |||||||
1245 | Returns the number of items in the list. This is effectively the | - | ||||||
1246 | same as size(). | - | ||||||
1247 | */ | - | ||||||
1248 | - | |||||||
1249 | /*! \fn int QList::length() const | - | ||||||
1250 | \since 4.5 | - | ||||||
1251 | - | |||||||
1252 | This function is identical to count(). | - | ||||||
1253 | - | |||||||
1254 | \sa count() | - | ||||||
1255 | */ | - | ||||||
1256 | - | |||||||
1257 | /*! \fn T& QList::first() | - | ||||||
1258 | - | |||||||
1259 | Returns a reference to the first item in the list. The list must | - | ||||||
1260 | not be empty. If the list can be empty, call isEmpty() before | - | ||||||
1261 | calling this function. | - | ||||||
1262 | - | |||||||
1263 | \sa constFirst(), last(), isEmpty() | - | ||||||
1264 | */ | - | ||||||
1265 | - | |||||||
1266 | /*! \fn const T& QList::first() const | - | ||||||
1267 | - | |||||||
1268 | \overload | - | ||||||
1269 | */ | - | ||||||
1270 | - | |||||||
1271 | /*! \fn const T& QList::constFirst() const | - | ||||||
1272 | \since 5.6 | - | ||||||
1273 | - | |||||||
1274 | Returns a const reference to the first item in the list. The list must | - | ||||||
1275 | not be empty. If the list can be empty, call isEmpty() before | - | ||||||
1276 | calling this function. | - | ||||||
1277 | - | |||||||
1278 | \sa constLast(), isEmpty(), first() | - | ||||||
1279 | */ | - | ||||||
1280 | - | |||||||
1281 | /*! \fn T& QList::last() | - | ||||||
1282 | - | |||||||
1283 | Returns a reference to the last item in the list. The list must | - | ||||||
1284 | not be empty. If the list can be empty, call isEmpty() before | - | ||||||
1285 | calling this function. | - | ||||||
1286 | - | |||||||
1287 | \sa constLast(), first(), isEmpty() | - | ||||||
1288 | */ | - | ||||||
1289 | - | |||||||
1290 | /*! \fn const T& QList::last() const | - | ||||||
1291 | - | |||||||
1292 | \overload | - | ||||||
1293 | */ | - | ||||||
1294 | - | |||||||
1295 | /*! \fn const T& QList::constLast() const | - | ||||||
1296 | \since 5.6 | - | ||||||
1297 | - | |||||||
1298 | Returns a reference to the last item in the list. The list must | - | ||||||
1299 | not be empty. If the list can be empty, call isEmpty() before | - | ||||||
1300 | calling this function. | - | ||||||
1301 | - | |||||||
1302 | \sa constFirst(), isEmpty(), last() | - | ||||||
1303 | */ | - | ||||||
1304 | - | |||||||
1305 | /*! \fn void QList::removeFirst() | - | ||||||
1306 | - | |||||||
1307 | Removes the first item in the list. Calling this function is | - | ||||||
1308 | equivalent to calling removeAt(0). The list must not be empty. If | - | ||||||
1309 | the list can be empty, call isEmpty() before calling this | - | ||||||
1310 | function. | - | ||||||
1311 | - | |||||||
1312 | \sa removeAt(), takeFirst() | - | ||||||
1313 | */ | - | ||||||
1314 | - | |||||||
1315 | /*! \fn void QList::removeLast() | - | ||||||
1316 | - | |||||||
1317 | Removes the last item in the list. Calling this function is | - | ||||||
1318 | equivalent to calling removeAt(size() - 1). The list must not be | - | ||||||
1319 | empty. If the list can be empty, call isEmpty() before calling | - | ||||||
1320 | this function. | - | ||||||
1321 | - | |||||||
1322 | \sa removeAt(), takeLast() | - | ||||||
1323 | */ | - | ||||||
1324 | - | |||||||
1325 | /*! \fn T QList::value(int i) const | - | ||||||
1326 | - | |||||||
1327 | Returns the value at index position \a i in the list. | - | ||||||
1328 | - | |||||||
1329 | If the index \a i is out of bounds, the function returns a | - | ||||||
1330 | \l{default-constructed value}. If you are certain that the index | - | ||||||
1331 | is going to be within bounds, you can use at() instead, which is | - | ||||||
1332 | slightly faster. | - | ||||||
1333 | - | |||||||
1334 | \sa at(), operator[]() | - | ||||||
1335 | */ | - | ||||||
1336 | - | |||||||
1337 | /*! \fn T QList::value(int i, const T &defaultValue) const | - | ||||||
1338 | - | |||||||
1339 | \overload | - | ||||||
1340 | - | |||||||
1341 | If the index \a i is out of bounds, the function returns | - | ||||||
1342 | \a defaultValue. | - | ||||||
1343 | */ | - | ||||||
1344 | - | |||||||
1345 | /*! \fn void QList::push_back(const T &value) | - | ||||||
1346 | - | |||||||
1347 | This function is provided for STL compatibility. It is equivalent | - | ||||||
1348 | to \l{QList::append()}{append(\a value)}. | - | ||||||
1349 | */ | - | ||||||
1350 | - | |||||||
1351 | /*! \fn void QList::push_front(const T &value) | - | ||||||
1352 | - | |||||||
1353 | This function is provided for STL compatibility. It is equivalent | - | ||||||
1354 | to \l{QList::prepend()}{prepend(\a value)}. | - | ||||||
1355 | */ | - | ||||||
1356 | - | |||||||
1357 | /*! \fn T& QList::front() | - | ||||||
1358 | - | |||||||
1359 | This function is provided for STL compatibility. It is equivalent | - | ||||||
1360 | to first(). The list must not be empty. If the list can be empty, | - | ||||||
1361 | call isEmpty() before calling this function. | - | ||||||
1362 | */ | - | ||||||
1363 | - | |||||||
1364 | /*! \fn const T& QList::front() const | - | ||||||
1365 | - | |||||||
1366 | \overload | - | ||||||
1367 | */ | - | ||||||
1368 | - | |||||||
1369 | /*! \fn T& QList::back() | - | ||||||
1370 | - | |||||||
1371 | This function is provided for STL compatibility. It is equivalent | - | ||||||
1372 | to last(). The list must not be empty. If the list can be empty, | - | ||||||
1373 | call isEmpty() before calling this function. | - | ||||||
1374 | */ | - | ||||||
1375 | - | |||||||
1376 | /*! \fn const T& QList::back() const | - | ||||||
1377 | - | |||||||
1378 | \overload | - | ||||||
1379 | */ | - | ||||||
1380 | - | |||||||
1381 | /*! \fn void QList::pop_front() | - | ||||||
1382 | - | |||||||
1383 | This function is provided for STL compatibility. It is equivalent | - | ||||||
1384 | to removeFirst(). The list must not be empty. If the list can be | - | ||||||
1385 | empty, call isEmpty() before calling this function. | - | ||||||
1386 | */ | - | ||||||
1387 | - | |||||||
1388 | /*! \fn void QList::pop_back() | - | ||||||
1389 | - | |||||||
1390 | This function is provided for STL compatibility. It is equivalent | - | ||||||
1391 | to removeLast(). The list must not be empty. If the list can be | - | ||||||
1392 | empty, call isEmpty() before calling this function. | - | ||||||
1393 | */ | - | ||||||
1394 | - | |||||||
1395 | /*! \fn bool QList::empty() const | - | ||||||
1396 | - | |||||||
1397 | This function is provided for STL compatibility. It is equivalent | - | ||||||
1398 | to isEmpty() and returns \c true if the list is empty. | - | ||||||
1399 | */ | - | ||||||
1400 | - | |||||||
1401 | /*! \fn QList<T> &QList::operator+=(const QList<T> &other) | - | ||||||
1402 | - | |||||||
1403 | Appends the items of the \a other list to this list and returns a | - | ||||||
1404 | reference to this list. | - | ||||||
1405 | - | |||||||
1406 | \sa operator+(), append() | - | ||||||
1407 | */ | - | ||||||
1408 | - | |||||||
1409 | /*! \fn void QList::operator+=(const T &value) | - | ||||||
1410 | - | |||||||
1411 | \overload | - | ||||||
1412 | - | |||||||
1413 | Appends \a value to the list. | - | ||||||
1414 | - | |||||||
1415 | \sa append(), operator<<() | - | ||||||
1416 | */ | - | ||||||
1417 | - | |||||||
1418 | /*! \fn QList<T> QList::operator+(const QList<T> &other) const | - | ||||||
1419 | - | |||||||
1420 | Returns a list that contains all the items in this list followed | - | ||||||
1421 | by all the items in the \a other list. | - | ||||||
1422 | - | |||||||
1423 | \sa operator+=() | - | ||||||
1424 | */ | - | ||||||
1425 | - | |||||||
1426 | /*! \fn QList<T> &QList::operator<<(const QList<T> &other) | - | ||||||
1427 | - | |||||||
1428 | Appends the items of the \a other list to this list and returns a | - | ||||||
1429 | reference to this list. | - | ||||||
1430 | - | |||||||
1431 | \sa operator+=(), append() | - | ||||||
1432 | */ | - | ||||||
1433 | - | |||||||
1434 | /*! \fn void QList::operator<<(const T &value) | - | ||||||
1435 | - | |||||||
1436 | \overload | - | ||||||
1437 | - | |||||||
1438 | Appends \a value to the list. | - | ||||||
1439 | */ | - | ||||||
1440 | - | |||||||
1441 | /*! \class QList::iterator | - | ||||||
1442 | \inmodule QtCore | - | ||||||
1443 | \brief The QList::iterator class provides an STL-style non-const iterator for QList and QQueue. | - | ||||||
1444 | - | |||||||
1445 | QList features both \l{STL-style iterators} and \l{Java-style | - | ||||||
1446 | iterators}. The STL-style iterators are more low-level and more | - | ||||||
1447 | cumbersome to use; on the other hand, they are slightly faster | - | ||||||
1448 | and, for developers who already know STL, have the advantage of | - | ||||||
1449 | familiarity. | - | ||||||
1450 | - | |||||||
1451 | QList\<T\>::iterator allows you to iterate over a QList\<T\> (or | - | ||||||
1452 | QQueue\<T\>) and to modify the list item associated with the | - | ||||||
1453 | iterator. If you want to iterate over a const QList, use | - | ||||||
1454 | QList::const_iterator instead. It is generally good practice to | - | ||||||
1455 | use QList::const_iterator on a non-const QList as well, unless | - | ||||||
1456 | you need to change the QList through the iterator. Const | - | ||||||
1457 | iterators are slightly faster, and can improve code readability. | - | ||||||
1458 | - | |||||||
1459 | The default QList::iterator constructor creates an uninitialized | - | ||||||
1460 | iterator. You must initialize it using a QList function like | - | ||||||
1461 | QList::begin(), QList::end(), or QList::insert() before you can | - | ||||||
1462 | start iterating. Here's a typical loop that prints all the items | - | ||||||
1463 | stored in a list: | - | ||||||
1464 | - | |||||||
1465 | \snippet code/src_corelib_tools_qlistdata.cpp 15 | - | ||||||
1466 | - | |||||||
1467 | Let's see a few examples of things we can do with a | - | ||||||
1468 | QList::iterator that we cannot do with a QList::const_iterator. | - | ||||||
1469 | Here's an example that increments every value stored in a | - | ||||||
1470 | QList\<int\> by 2: | - | ||||||
1471 | - | |||||||
1472 | \snippet code/src_corelib_tools_qlistdata.cpp 16 | - | ||||||
1473 | - | |||||||
1474 | Most QList functions accept an integer index rather than an | - | ||||||
1475 | iterator. For that reason, iterators are rarely useful in | - | ||||||
1476 | connection with QList. One place where STL-style iterators do | - | ||||||
1477 | make sense is as arguments to \l{generic algorithms}. | - | ||||||
1478 | - | |||||||
1479 | For example, here's how to delete all the widgets stored in a | - | ||||||
1480 | QList\<QWidget *\>: | - | ||||||
1481 | - | |||||||
1482 | \snippet code/src_corelib_tools_qlistdata.cpp 17 | - | ||||||
1483 | - | |||||||
1484 | Multiple iterators can be used on the same list. However, be | - | ||||||
1485 | aware that any non-const function call performed on the QList | - | ||||||
1486 | will render all existing iterators undefined. If you need to keep | - | ||||||
1487 | iterators over a long period of time, we recommend that you use | - | ||||||
1488 | QLinkedList rather than QList. | - | ||||||
1489 | - | |||||||
1490 | \warning Iterators on implicitly shared containers do not work | - | ||||||
1491 | exactly like STL-iterators. You should avoid copying a container | - | ||||||
1492 | while iterators are active on that container. For more information, | - | ||||||
1493 | read \l{Implicit sharing iterator problem}. | - | ||||||
1494 | - | |||||||
1495 | \sa QList::const_iterator, QMutableListIterator | - | ||||||
1496 | */ | - | ||||||
1497 | - | |||||||
1498 | /*! \typedef QList::iterator::iterator_category | - | ||||||
1499 | - | |||||||
1500 | A synonym for \e {std::random_access_iterator_tag} indicating | - | ||||||
1501 | this iterator is a random access iterator. | - | ||||||
1502 | */ | - | ||||||
1503 | - | |||||||
1504 | /*! \typedef QList::iterator::difference_type | - | ||||||
1505 | - | |||||||
1506 | \internal | - | ||||||
1507 | */ | - | ||||||
1508 | - | |||||||
1509 | /*! \typedef QList::iterator::value_type | - | ||||||
1510 | - | |||||||
1511 | \internal | - | ||||||
1512 | */ | - | ||||||
1513 | - | |||||||
1514 | /*! \typedef QList::iterator::pointer | - | ||||||
1515 | - | |||||||
1516 | \internal | - | ||||||
1517 | */ | - | ||||||
1518 | - | |||||||
1519 | /*! \typedef QList::iterator::reference | - | ||||||
1520 | - | |||||||
1521 | \internal | - | ||||||
1522 | */ | - | ||||||
1523 | - | |||||||
1524 | /*! \fn QList::iterator::iterator() | - | ||||||
1525 | - | |||||||
1526 | Constructs an uninitialized iterator. | - | ||||||
1527 | - | |||||||
1528 | Functions like operator*() and operator++() should not be called | - | ||||||
1529 | on an uninitialized iterator. Use operator=() to assign a value | - | ||||||
1530 | to it before using it. | - | ||||||
1531 | - | |||||||
1532 | \sa QList::begin(), QList::end() | - | ||||||
1533 | */ | - | ||||||
1534 | - | |||||||
1535 | /*! \fn QList::iterator::iterator(Node *node) | - | ||||||
1536 | - | |||||||
1537 | \internal | - | ||||||
1538 | */ | - | ||||||
1539 | - | |||||||
1540 | /*! \fn QList::iterator::iterator(const iterator &other) | - | ||||||
1541 | - | |||||||
1542 | Constructs a copy of \a other. | - | ||||||
1543 | */ | - | ||||||
1544 | - | |||||||
1545 | /*! \fn T &QList::iterator::operator*() const | - | ||||||
1546 | - | |||||||
1547 | Returns a modifiable reference to the current item. | - | ||||||
1548 | - | |||||||
1549 | You can change the value of an item by using operator*() on the | - | ||||||
1550 | left side of an assignment, for example: | - | ||||||
1551 | - | |||||||
1552 | \snippet code/src_corelib_tools_qlistdata.cpp 18 | - | ||||||
1553 | - | |||||||
1554 | \sa operator->() | - | ||||||
1555 | */ | - | ||||||
1556 | - | |||||||
1557 | /*! \fn T *QList::iterator::operator->() const | - | ||||||
1558 | - | |||||||
1559 | Returns a pointer to the current item. | - | ||||||
1560 | - | |||||||
1561 | \sa operator*() | - | ||||||
1562 | */ | - | ||||||
1563 | - | |||||||
1564 | /*! \fn T &QList::iterator::operator[](difference_type j) const | - | ||||||
1565 | - | |||||||
1566 | Returns a modifiable reference to the item at position *this + | - | ||||||
1567 | \a{j}. | - | ||||||
1568 | - | |||||||
1569 | This function is provided to make QList iterators behave like C++ | - | ||||||
1570 | pointers. | - | ||||||
1571 | - | |||||||
1572 | \sa operator+() | - | ||||||
1573 | */ | - | ||||||
1574 | - | |||||||
1575 | /*! | - | ||||||
1576 | \fn bool QList::iterator::operator==(const iterator &other) const | - | ||||||
1577 | \fn bool QList::iterator::operator==(const const_iterator &other) const | - | ||||||
1578 | - | |||||||
1579 | Returns \c true if \a other points to the same item as this | - | ||||||
1580 | iterator; otherwise returns \c false. | - | ||||||
1581 | - | |||||||
1582 | \sa operator!=() | - | ||||||
1583 | */ | - | ||||||
1584 | - | |||||||
1585 | /*! | - | ||||||
1586 | \fn bool QList::iterator::operator!=(const iterator &other) const | - | ||||||
1587 | \fn bool QList::iterator::operator!=(const const_iterator &other) const | - | ||||||
1588 | - | |||||||
1589 | Returns \c true if \a other points to a different item than this | - | ||||||
1590 | iterator; otherwise returns \c false. | - | ||||||
1591 | - | |||||||
1592 | \sa operator==() | - | ||||||
1593 | */ | - | ||||||
1594 | - | |||||||
1595 | /*! | - | ||||||
1596 | \fn bool QList::iterator::operator<(const iterator& other) const | - | ||||||
1597 | \fn bool QList::iterator::operator<(const const_iterator& other) const | - | ||||||
1598 | - | |||||||
1599 | Returns \c true if the item pointed to by this iterator is less than | - | ||||||
1600 | the item pointed to by the \a other iterator. | - | ||||||
1601 | */ | - | ||||||
1602 | - | |||||||
1603 | /*! | - | ||||||
1604 | \fn bool QList::iterator::operator<=(const iterator& other) const | - | ||||||
1605 | \fn bool QList::iterator::operator<=(const const_iterator& other) const | - | ||||||
1606 | - | |||||||
1607 | Returns \c true if the item pointed to by this iterator is less than | - | ||||||
1608 | or equal to the item pointed to by the \a other iterator. | - | ||||||
1609 | */ | - | ||||||
1610 | - | |||||||
1611 | /*! | - | ||||||
1612 | \fn bool QList::iterator::operator>(const iterator& other) const | - | ||||||
1613 | \fn bool QList::iterator::operator>(const const_iterator& other) const | - | ||||||
1614 | - | |||||||
1615 | Returns \c true if the item pointed to by this iterator is greater | - | ||||||
1616 | than the item pointed to by the \a other iterator. | - | ||||||
1617 | */ | - | ||||||
1618 | - | |||||||
1619 | /*! | - | ||||||
1620 | \fn bool QList::iterator::operator>=(const iterator& other) const | - | ||||||
1621 | \fn bool QList::iterator::operator>=(const const_iterator& other) const | - | ||||||
1622 | - | |||||||
1623 | Returns \c true if the item pointed to by this iterator is greater | - | ||||||
1624 | than or equal to the item pointed to by the \a other iterator. | - | ||||||
1625 | */ | - | ||||||
1626 | - | |||||||
1627 | /*! \fn QList::iterator &QList::iterator::operator++() | - | ||||||
1628 | - | |||||||
1629 | The prefix ++ operator (\c{++it}) advances the iterator to the | - | ||||||
1630 | next item in the list and returns an iterator to the new current | - | ||||||
1631 | item. | - | ||||||
1632 | - | |||||||
1633 | Calling this function on QList::end() leads to undefined results. | - | ||||||
1634 | - | |||||||
1635 | \sa operator--() | - | ||||||
1636 | */ | - | ||||||
1637 | - | |||||||
1638 | /*! \fn QList::iterator QList::iterator::operator++(int) | - | ||||||
1639 | - | |||||||
1640 | \overload | - | ||||||
1641 | - | |||||||
1642 | The postfix ++ operator (\c{it++}) advances the iterator to the | - | ||||||
1643 | next item in the list and returns an iterator to the previously | - | ||||||
1644 | current item. | - | ||||||
1645 | */ | - | ||||||
1646 | - | |||||||
1647 | /*! \fn QList::iterator &QList::iterator::operator--() | - | ||||||
1648 | - | |||||||
1649 | The prefix -- operator (\c{--it}) makes the preceding item | - | ||||||
1650 | current and returns an iterator to the new current item. | - | ||||||
1651 | - | |||||||
1652 | Calling this function on QList::begin() leads to undefined results. | - | ||||||
1653 | - | |||||||
1654 | \sa operator++() | - | ||||||
1655 | */ | - | ||||||
1656 | - | |||||||
1657 | /*! \fn QList::iterator QList::iterator::operator--(int) | - | ||||||
1658 | - | |||||||
1659 | \overload | - | ||||||
1660 | - | |||||||
1661 | The postfix -- operator (\c{it--}) makes the preceding item | - | ||||||
1662 | current and returns an iterator to the previously current item. | - | ||||||
1663 | */ | - | ||||||
1664 | - | |||||||
1665 | /*! \fn QList::iterator &QList::iterator::operator+=(difference_type j) | - | ||||||
1666 | - | |||||||
1667 | Advances the iterator by \a j items. (If \a j is negative, the | - | ||||||
1668 | iterator goes backward.) | - | ||||||
1669 | - | |||||||
1670 | \sa operator-=(), operator+() | - | ||||||
1671 | */ | - | ||||||
1672 | - | |||||||
1673 | /*! \fn QList::iterator &QList::iterator::operator-=(difference_type j) | - | ||||||
1674 | - | |||||||
1675 | Makes the iterator go back by \a j items. (If \a j is negative, | - | ||||||
1676 | the iterator goes forward.) | - | ||||||
1677 | - | |||||||
1678 | \sa operator+=(), operator-() | - | ||||||
1679 | */ | - | ||||||
1680 | - | |||||||
1681 | /*! \fn QList::iterator QList::iterator::operator+(difference_type j) const | - | ||||||
1682 | - | |||||||
1683 | Returns an iterator to the item at \a j positions forward from | - | ||||||
1684 | this iterator. (If \a j is negative, the iterator goes backward.) | - | ||||||
1685 | - | |||||||
1686 | \sa operator-(), operator+=() | - | ||||||
1687 | */ | - | ||||||
1688 | - | |||||||
1689 | /*! \fn QList::iterator QList::iterator::operator-(difference_type j) const | - | ||||||
1690 | - | |||||||
1691 | Returns an iterator to the item at \a j positions backward from | - | ||||||
1692 | this iterator. (If \a j is negative, the iterator goes forward.) | - | ||||||
1693 | - | |||||||
1694 | \sa operator+(), operator-=() | - | ||||||
1695 | */ | - | ||||||
1696 | - | |||||||
1697 | /*! \fn int QList::iterator::operator-(iterator other) const | - | ||||||
1698 | - | |||||||
1699 | Returns the number of items between the item pointed to by \a | - | ||||||
1700 | other and the item pointed to by this iterator. | - | ||||||
1701 | */ | - | ||||||
1702 | - | |||||||
1703 | /*! \class QList::const_iterator | - | ||||||
1704 | \inmodule QtCore | - | ||||||
1705 | \brief The QList::const_iterator class provides an STL-style const iterator for QList and QQueue. | - | ||||||
1706 | - | |||||||
1707 | QList provides both \l{STL-style iterators} and \l{Java-style | - | ||||||
1708 | iterators}. The STL-style iterators are more low-level and more | - | ||||||
1709 | cumbersome to use; on the other hand, they are slightly faster | - | ||||||
1710 | and, for developers who already know STL, have the advantage of | - | ||||||
1711 | familiarity. | - | ||||||
1712 | - | |||||||
1713 | QList\<T\>::const_iterator allows you to iterate over a | - | ||||||
1714 | QList\<T\> (or a QQueue\<T\>). If you want to modify the QList as | - | ||||||
1715 | you iterate over it, use QList::iterator instead. It is generally | - | ||||||
1716 | good practice to use QList::const_iterator on a non-const QList | - | ||||||
1717 | as well, unless you need to change the QList through the | - | ||||||
1718 | iterator. Const iterators are slightly faster, and can improve | - | ||||||
1719 | code readability. | - | ||||||
1720 | - | |||||||
1721 | The default QList::const_iterator constructor creates an | - | ||||||
1722 | uninitialized iterator. You must initialize it using a QList | - | ||||||
1723 | function like QList::constBegin(), QList::constEnd(), or | - | ||||||
1724 | QList::insert() before you can start iterating. Here's a typical | - | ||||||
1725 | loop that prints all the items stored in a list: | - | ||||||
1726 | - | |||||||
1727 | \snippet code/src_corelib_tools_qlistdata.cpp 19 | - | ||||||
1728 | - | |||||||
1729 | Most QList functions accept an integer index rather than an | - | ||||||
1730 | iterator. For that reason, iterators are rarely useful in | - | ||||||
1731 | connection with QList. One place where STL-style iterators do | - | ||||||
1732 | make sense is as arguments to \l{generic algorithms}. | - | ||||||
1733 | - | |||||||
1734 | For example, here's how to delete all the widgets stored in a | - | ||||||
1735 | QList\<QWidget *\>: | - | ||||||
1736 | - | |||||||
1737 | \snippet code/src_corelib_tools_qlistdata.cpp 20 | - | ||||||
1738 | - | |||||||
1739 | Multiple iterators can be used on the same list. However, be | - | ||||||
1740 | aware that any non-const function call performed on the QList | - | ||||||
1741 | will render all existing iterators undefined. If you need to keep | - | ||||||
1742 | iterators over a long period of time, we recommend that you use | - | ||||||
1743 | QLinkedList rather than QList. | - | ||||||
1744 | - | |||||||
1745 | \warning Iterators on implicitly shared containers do not work | - | ||||||
1746 | exactly like STL-iterators. You should avoid copying a container | - | ||||||
1747 | while iterators are active on that container. For more information, | - | ||||||
1748 | read \l{Implicit sharing iterator problem}. | - | ||||||
1749 | - | |||||||
1750 | \sa QList::iterator, QListIterator | - | ||||||
1751 | */ | - | ||||||
1752 | - | |||||||
1753 | /*! \fn QList::const_iterator::const_iterator() | - | ||||||
1754 | - | |||||||
1755 | Constructs an uninitialized iterator. | - | ||||||
1756 | - | |||||||
1757 | Functions like operator*() and operator++() should not be called | - | ||||||
1758 | on an uninitialized iterator. Use operator=() to assign a value | - | ||||||
1759 | to it before using it. | - | ||||||
1760 | - | |||||||
1761 | \sa QList::constBegin(), QList::constEnd() | - | ||||||
1762 | */ | - | ||||||
1763 | - | |||||||
1764 | /*! \typedef QList::const_iterator::iterator_category | - | ||||||
1765 | - | |||||||
1766 | A synonym for \e {std::random_access_iterator_tag} indicating | - | ||||||
1767 | this iterator is a random access iterator. | - | ||||||
1768 | */ | - | ||||||
1769 | - | |||||||
1770 | /*! \typedef QList::const_iterator::difference_type | - | ||||||
1771 | - | |||||||
1772 | \internal | - | ||||||
1773 | */ | - | ||||||
1774 | - | |||||||
1775 | /*! \typedef QList::const_iterator::value_type | - | ||||||
1776 | - | |||||||
1777 | \internal | - | ||||||
1778 | */ | - | ||||||
1779 | - | |||||||
1780 | /*! \typedef QList::const_iterator::pointer | - | ||||||
1781 | - | |||||||
1782 | \internal | - | ||||||
1783 | */ | - | ||||||
1784 | - | |||||||
1785 | /*! \typedef QList::const_iterator::reference | - | ||||||
1786 | - | |||||||
1787 | \internal | - | ||||||
1788 | */ | - | ||||||
1789 | - | |||||||
1790 | /*! \fn QList::const_iterator::const_iterator(Node *node) | - | ||||||
1791 | - | |||||||
1792 | \internal | - | ||||||
1793 | */ | - | ||||||
1794 | - | |||||||
1795 | /*! \fn QList::const_iterator::const_iterator(const const_iterator &other) | - | ||||||
1796 | - | |||||||
1797 | Constructs a copy of \a other. | - | ||||||
1798 | */ | - | ||||||
1799 | - | |||||||
1800 | /*! \fn QList::const_iterator::const_iterator(const iterator &other) | - | ||||||
1801 | - | |||||||
1802 | Constructs a copy of \a other. | - | ||||||
1803 | */ | - | ||||||
1804 | - | |||||||
1805 | /*! \fn const T &QList::const_iterator::operator*() const | - | ||||||
1806 | - | |||||||
1807 | Returns the current item. | - | ||||||
1808 | - | |||||||
1809 | \sa operator->() | - | ||||||
1810 | */ | - | ||||||
1811 | - | |||||||
1812 | /*! \fn const T *QList::const_iterator::operator->() const | - | ||||||
1813 | - | |||||||
1814 | Returns a pointer to the current item. | - | ||||||
1815 | - | |||||||
1816 | \sa operator*() | - | ||||||
1817 | */ | - | ||||||
1818 | - | |||||||
1819 | /*! \fn const T &QList::const_iterator::operator[](difference_type j) const | - | ||||||
1820 | - | |||||||
1821 | Returns the item at position *this + \a{j}. | - | ||||||
1822 | - | |||||||
1823 | This function is provided to make QList iterators behave like C++ | - | ||||||
1824 | pointers. | - | ||||||
1825 | - | |||||||
1826 | \sa operator+() | - | ||||||
1827 | */ | - | ||||||
1828 | - | |||||||
1829 | /*! \fn bool QList::const_iterator::operator==(const const_iterator &other) const | - | ||||||
1830 | - | |||||||
1831 | Returns \c true if \a other points to the same item as this | - | ||||||
1832 | iterator; otherwise returns \c false. | - | ||||||
1833 | - | |||||||
1834 | \sa operator!=() | - | ||||||
1835 | */ | - | ||||||
1836 | - | |||||||
1837 | /*! \fn bool QList::const_iterator::operator!=(const const_iterator &other) const | - | ||||||
1838 | - | |||||||
1839 | Returns \c true if \a other points to a different item than this | - | ||||||
1840 | iterator; otherwise returns \c false. | - | ||||||
1841 | - | |||||||
1842 | \sa operator==() | - | ||||||
1843 | */ | - | ||||||
1844 | - | |||||||
1845 | /*! | - | ||||||
1846 | \fn bool QList::const_iterator::operator<(const const_iterator& other) const | - | ||||||
1847 | - | |||||||
1848 | Returns \c true if the item pointed to by this iterator is less than | - | ||||||
1849 | the item pointed to by the \a other iterator. | - | ||||||
1850 | */ | - | ||||||
1851 | - | |||||||
1852 | /*! | - | ||||||
1853 | \fn bool QList::const_iterator::operator<=(const const_iterator& other) const | - | ||||||
1854 | - | |||||||
1855 | Returns \c true if the item pointed to by this iterator is less than | - | ||||||
1856 | or equal to the item pointed to by the \a other iterator. | - | ||||||
1857 | */ | - | ||||||
1858 | - | |||||||
1859 | /*! | - | ||||||
1860 | \fn bool QList::const_iterator::operator>(const const_iterator& other) const | - | ||||||
1861 | - | |||||||
1862 | Returns \c true if the item pointed to by this iterator is greater | - | ||||||
1863 | than the item pointed to by the \a other iterator. | - | ||||||
1864 | */ | - | ||||||
1865 | - | |||||||
1866 | /*! | - | ||||||
1867 | \fn bool QList::const_iterator::operator>=(const const_iterator& other) const | - | ||||||
1868 | - | |||||||
1869 | Returns \c true if the item pointed to by this iterator is greater | - | ||||||
1870 | than or equal to the item pointed to by the \a other iterator. | - | ||||||
1871 | */ | - | ||||||
1872 | - | |||||||
1873 | /*! \fn QList::const_iterator &QList::const_iterator::operator++() | - | ||||||
1874 | - | |||||||
1875 | The prefix ++ operator (\c{++it}) advances the iterator to the | - | ||||||
1876 | next item in the list and returns an iterator to the new current | - | ||||||
1877 | item. | - | ||||||
1878 | - | |||||||
1879 | Calling this function on QList::end() leads to undefined results. | - | ||||||
1880 | - | |||||||
1881 | \sa operator--() | - | ||||||
1882 | */ | - | ||||||
1883 | - | |||||||
1884 | /*! \fn QList::const_iterator QList::const_iterator::operator++(int) | - | ||||||
1885 | - | |||||||
1886 | \overload | - | ||||||
1887 | - | |||||||
1888 | The postfix ++ operator (\c{it++}) advances the iterator to the | - | ||||||
1889 | next item in the list and returns an iterator to the previously | - | ||||||
1890 | current item. | - | ||||||
1891 | */ | - | ||||||
1892 | - | |||||||
1893 | /*! \fn QList::const_iterator &QList::const_iterator::operator--() | - | ||||||
1894 | - | |||||||
1895 | The prefix -- operator (\c{--it}) makes the preceding item | - | ||||||
1896 | current and returns an iterator to the new current item. | - | ||||||
1897 | - | |||||||
1898 | Calling this function on QList::begin() leads to undefined results. | - | ||||||
1899 | - | |||||||
1900 | \sa operator++() | - | ||||||
1901 | */ | - | ||||||
1902 | - | |||||||
1903 | /*! \fn QList::const_iterator QList::const_iterator::operator--(int) | - | ||||||
1904 | - | |||||||
1905 | \overload | - | ||||||
1906 | - | |||||||
1907 | The postfix -- operator (\c{it--}) makes the preceding item | - | ||||||
1908 | current and returns an iterator to the previously current item. | - | ||||||
1909 | */ | - | ||||||
1910 | - | |||||||
1911 | /*! \fn QList::const_iterator &QList::const_iterator::operator+=(difference_type j) | - | ||||||
1912 | - | |||||||
1913 | Advances the iterator by \a j items. (If \a j is negative, the | - | ||||||
1914 | iterator goes backward.) | - | ||||||
1915 | - | |||||||
1916 | \sa operator-=(), operator+() | - | ||||||
1917 | */ | - | ||||||
1918 | - | |||||||
1919 | /*! \fn QList::const_iterator &QList::const_iterator::operator-=(difference_type j) | - | ||||||
1920 | - | |||||||
1921 | Makes the iterator go back by \a j items. (If \a j is negative, | - | ||||||
1922 | the iterator goes forward.) | - | ||||||
1923 | - | |||||||
1924 | \sa operator+=(), operator-() | - | ||||||
1925 | */ | - | ||||||
1926 | - | |||||||
1927 | /*! \fn QList::const_iterator QList::const_iterator::operator+(difference_type j) const | - | ||||||
1928 | - | |||||||
1929 | Returns an iterator to the item at \a j positions forward from | - | ||||||
1930 | this iterator. (If \a j is negative, the iterator goes backward.) | - | ||||||
1931 | - | |||||||
1932 | \sa operator-(), operator+=() | - | ||||||
1933 | */ | - | ||||||
1934 | - | |||||||
1935 | /*! \fn QList::const_iterator QList::const_iterator::operator-(difference_type j) const | - | ||||||
1936 | - | |||||||
1937 | Returns an iterator to the item at \a j positions backward from | - | ||||||
1938 | this iterator. (If \a j is negative, the iterator goes forward.) | - | ||||||
1939 | - | |||||||
1940 | \sa operator+(), operator-=() | - | ||||||
1941 | */ | - | ||||||
1942 | - | |||||||
1943 | /*! \fn int QList::const_iterator::operator-(const_iterator other) const | - | ||||||
1944 | - | |||||||
1945 | Returns the number of items between the item pointed to by \a | - | ||||||
1946 | other and the item pointed to by this iterator. | - | ||||||
1947 | */ | - | ||||||
1948 | - | |||||||
1949 | /*! \fn QDataStream &operator<<(QDataStream &out, const QList<T> &list) | - | ||||||
1950 | \relates QList | - | ||||||
1951 | - | |||||||
1952 | Writes the list \a list to stream \a out. | - | ||||||
1953 | - | |||||||
1954 | This function requires the value type to implement \c | - | ||||||
1955 | operator<<(). | - | ||||||
1956 | - | |||||||
1957 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||
1958 | */ | - | ||||||
1959 | - | |||||||
1960 | /*! \fn QDataStream &operator>>(QDataStream &in, QList<T> &list) | - | ||||||
1961 | \relates QList | - | ||||||
1962 | - | |||||||
1963 | Reads a list from stream \a in into \a list. | - | ||||||
1964 | - | |||||||
1965 | This function requires the value type to implement \c | - | ||||||
1966 | operator>>(). | - | ||||||
1967 | - | |||||||
1968 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||
1969 | */ | - | ||||||
1970 | - | |||||||
1971 | /*! \fn QList<T> QList<T>::fromVector(const QVector<T> &vector) | - | ||||||
1972 | - | |||||||
1973 | Returns a QList object with the data contained in \a vector. | - | ||||||
1974 | - | |||||||
1975 | Example: | - | ||||||
1976 | - | |||||||
1977 | \snippet code/src_corelib_tools_qlistdata.cpp 21 | - | ||||||
1978 | - | |||||||
1979 | \sa fromSet(), toVector(), QVector::toList() | - | ||||||
1980 | */ | - | ||||||
1981 | - | |||||||
1982 | /*! \fn QVector<T> QList<T>::toVector() const | - | ||||||
1983 | - | |||||||
1984 | Returns a QVector object with the data contained in this QList. | - | ||||||
1985 | - | |||||||
1986 | Example: | - | ||||||
1987 | - | |||||||
1988 | \snippet code/src_corelib_tools_qlistdata.cpp 22 | - | ||||||
1989 | - | |||||||
1990 | \sa toSet(), fromVector(), QVector::fromList() | - | ||||||
1991 | */ | - | ||||||
1992 | - | |||||||
1993 | /*! \fn QList<T> QList<T>::fromSet(const QSet<T> &set) | - | ||||||
1994 | - | |||||||
1995 | Returns a QList object with the data contained in \a set. The | - | ||||||
1996 | order of the elements in the QList is undefined. | - | ||||||
1997 | - | |||||||
1998 | Example: | - | ||||||
1999 | - | |||||||
2000 | \snippet code/src_corelib_tools_qlistdata.cpp 23 | - | ||||||
2001 | - | |||||||
2002 | \sa fromVector(), toSet(), QSet::toList() | - | ||||||
2003 | */ | - | ||||||
2004 | - | |||||||
2005 | /*! \fn QSet<T> QList<T>::toSet() const | - | ||||||
2006 | - | |||||||
2007 | Returns a QSet object with the data contained in this QList. | - | ||||||
2008 | Since QSet doesn't allow duplicates, the resulting QSet might be | - | ||||||
2009 | smaller than the original list was. | - | ||||||
2010 | - | |||||||
2011 | Example: | - | ||||||
2012 | - | |||||||
2013 | \snippet code/src_corelib_tools_qlistdata.cpp 24 | - | ||||||
2014 | - | |||||||
2015 | \sa toVector(), fromSet(), QSet::fromList() | - | ||||||
2016 | */ | - | ||||||
2017 | - | |||||||
2018 | /*! \fn QList<T> QList<T>::fromStdList(const std::list<T> &list) | - | ||||||
2019 | - | |||||||
2020 | Returns a QList object with the data contained in \a list. The | - | ||||||
2021 | order of the elements in the QList is the same as in \a list. | - | ||||||
2022 | - | |||||||
2023 | Example: | - | ||||||
2024 | - | |||||||
2025 | \snippet code/src_corelib_tools_qlistdata.cpp 25 | - | ||||||
2026 | - | |||||||
2027 | \sa toStdList(), QVector::fromStdVector() | - | ||||||
2028 | */ | - | ||||||
2029 | - | |||||||
2030 | /*! \fn std::list<T> QList<T>::toStdList() const | - | ||||||
2031 | - | |||||||
2032 | Returns a std::list object with the data contained in this QList. | - | ||||||
2033 | Example: | - | ||||||
2034 | - | |||||||
2035 | \snippet code/src_corelib_tools_qlistdata.cpp 26 | - | ||||||
2036 | - | |||||||
2037 | \sa fromStdList(), QVector::toStdVector() | - | ||||||
2038 | */ | - | ||||||
2039 | - | |||||||
2040 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |