1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \class QListIterator
|
---|
44 | \inmodule QtCore
|
---|
45 |
|
---|
46 | \brief The QListIterator class provides a Java-style const iterator for QList and QQueue.
|
---|
47 |
|
---|
48 | QList has both \l{Java-style iterators} and \l{STL-style
|
---|
49 | iterators}. The Java-style iterators are more high-level and
|
---|
50 | easier to use than the STL-style iterators; on the other hand,
|
---|
51 | they are slightly less efficient.
|
---|
52 |
|
---|
53 | An alternative to using iterators is to use index positions. Most
|
---|
54 | QList member functions take an index as their first parameter,
|
---|
55 | making it possible to access, modify, and remove items without
|
---|
56 | using iterators.
|
---|
57 |
|
---|
58 | QListIterator\<T\> allows you to iterate over a QList\<T\> (or a
|
---|
59 | QQueue\<T\>). If you want to modify the list as you iterate over
|
---|
60 | it, use QMutableListIterator\<T\> instead.
|
---|
61 |
|
---|
62 | The QListIterator constructor takes a QList as argument. After
|
---|
63 | construction, the iterator is located at the very beginning of
|
---|
64 | the list (before the first item). Here's how to iterate over all
|
---|
65 | the elements sequentially:
|
---|
66 |
|
---|
67 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 0
|
---|
68 |
|
---|
69 | The next() function returns the next item in the list and
|
---|
70 | advances the iterator. Unlike STL-style iterators, Java-style
|
---|
71 | iterators point \e between items rather than directly \e at
|
---|
72 | items. The first call to next() advances the iterator to the
|
---|
73 | position between the first and second item, and returns the first
|
---|
74 | item; the second call to next() advances the iterator to the
|
---|
75 | position between the second and third item, and returns the second
|
---|
76 | item; and so on.
|
---|
77 |
|
---|
78 | \img javaiterators1.png
|
---|
79 |
|
---|
80 | Here's how to iterate over the elements in reverse order:
|
---|
81 |
|
---|
82 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 1
|
---|
83 |
|
---|
84 | If you want to find all occurrences of a particular value, use
|
---|
85 | findNext() or findPrevious() in a loop.
|
---|
86 |
|
---|
87 | Multiple iterators can be used on the same list. If the list is
|
---|
88 | modified while a QListIterator is active, the QListIterator will
|
---|
89 | continue iterating over the original list, ignoring the modified
|
---|
90 | copy.
|
---|
91 |
|
---|
92 | \sa QMutableListIterator, QList::const_iterator
|
---|
93 | */
|
---|
94 |
|
---|
95 | /*!
|
---|
96 | \class QLinkedListIterator
|
---|
97 | \inmodule QtCore
|
---|
98 |
|
---|
99 | \brief The QLinkedListIterator class provides a Java-style const iterator for QLinkedList.
|
---|
100 |
|
---|
101 | QLinkedList has both \l{Java-style iterators} and
|
---|
102 | \l{STL-style iterators}. The Java-style iterators are more
|
---|
103 | high-level and easier to use than the STL-style iterators; on the
|
---|
104 | other hand, they are slightly less efficient.
|
---|
105 |
|
---|
106 | QLinkedListIterator\<T\> allows you to iterate over a
|
---|
107 | QLinkedList\<T\>. If you want to modify the list as you iterate
|
---|
108 | over it, use QMutableLinkedListIterator\<T\> instead.
|
---|
109 |
|
---|
110 | The QLinkedListIterator constructor takes a QLinkedList as
|
---|
111 | argument. After construction, the iterator is located at the very
|
---|
112 | beginning of the list (before the first item). Here's how to
|
---|
113 | iterate over all the elements sequentially:
|
---|
114 |
|
---|
115 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 2
|
---|
116 |
|
---|
117 | The next() function returns the next item in the list and
|
---|
118 | advances the iterator. Unlike STL-style iterators, Java-style
|
---|
119 | iterators point \e between items rather than directly \e at
|
---|
120 | items. The first call to next() advances the iterator to the
|
---|
121 | position between the first and second item, and returns the first
|
---|
122 | item; the second call to next() advances the iterator to the
|
---|
123 | position between the second and third item, and returns the second
|
---|
124 | item; and so on.
|
---|
125 |
|
---|
126 | \img javaiterators1.png
|
---|
127 |
|
---|
128 | Here's how to iterate over the elements in reverse order:
|
---|
129 |
|
---|
130 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 3
|
---|
131 |
|
---|
132 | If you want to find all occurrences of a particular value, use
|
---|
133 | findNext() or findPrevious() in a loop.
|
---|
134 |
|
---|
135 | Multiple iterators can be used on the same list. If the list is
|
---|
136 | modified while a QLinkedListIterator is active, the
|
---|
137 | QLinkedListIterator will continue iterating over the original
|
---|
138 | list, ignoring the modified copy.
|
---|
139 |
|
---|
140 | \sa QMutableLinkedListIterator, QLinkedList::const_iterator
|
---|
141 | */
|
---|
142 |
|
---|
143 | /*!
|
---|
144 | \class QVectorIterator
|
---|
145 | \inmodule QtCore
|
---|
146 | \brief The QVectorIterator class provides a Java-style const iterator for QVector and QStack.
|
---|
147 |
|
---|
148 | QVector has both \l{Java-style iterators} and \l{STL-style
|
---|
149 | iterators}. The Java-style iterators are more high-level and
|
---|
150 | easier to use than the STL-style iterators; on the other hand,
|
---|
151 | they are slightly less efficient.
|
---|
152 |
|
---|
153 | An alternative to using iterators is to use index positions. Most
|
---|
154 | QVector member functions take an index as their first parameter,
|
---|
155 | making it possible to access, insert, and remove items without
|
---|
156 | using iterators.
|
---|
157 |
|
---|
158 | QVectorIterator\<T\> allows you to iterate over a QVector\<T\>
|
---|
159 | (or a QStack\<T\>). If you want to modify the vector as you
|
---|
160 | iterate over it, use QMutableVectorIterator\<T\> instead.
|
---|
161 |
|
---|
162 | The QVectorIterator constructor takes a QVector as argument.
|
---|
163 | After construction, the iterator is located at the very beginning
|
---|
164 | of the vector (before the first item). Here's how to iterate over
|
---|
165 | all the elements sequentially:
|
---|
166 |
|
---|
167 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 4
|
---|
168 |
|
---|
169 | The next() function returns the next item in the vector and
|
---|
170 | advances the iterator. Unlike STL-style iterators, Java-style
|
---|
171 | iterators point \e between items rather than directly \e at
|
---|
172 | items. The first call to next() advances the iterator to the
|
---|
173 | position between the first and second item, and returns the first
|
---|
174 | item; the second call to next() advances the iterator to the
|
---|
175 | position between the second and third item, returning the second
|
---|
176 | item; and so on.
|
---|
177 |
|
---|
178 | \img javaiterators1.png
|
---|
179 |
|
---|
180 | Here's how to iterate over the elements in reverse order:
|
---|
181 |
|
---|
182 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 5
|
---|
183 |
|
---|
184 | If you want to find all occurrences of a particular value, use
|
---|
185 | findNext() or findPrevious() in a loop.
|
---|
186 |
|
---|
187 | Multiple iterators can be used on the same vector. If the vector
|
---|
188 | is modified while a QVectorIterator is active, the QVectorIterator
|
---|
189 | will continue iterating over the original vector, ignoring the
|
---|
190 | modified copy.
|
---|
191 |
|
---|
192 | \sa QMutableVectorIterator, QVector::const_iterator
|
---|
193 | */
|
---|
194 |
|
---|
195 | /*!
|
---|
196 | \class QSetIterator
|
---|
197 | \inmodule QtCore
|
---|
198 | \brief The QSetIterator class provides a Java-style const iterator for QSet.
|
---|
199 |
|
---|
200 | QSet supports both \l{Java-style iterators} and \l{STL-style
|
---|
201 | iterators}. The Java-style iterators are more high-level and
|
---|
202 | easier to use than the STL-style iterators; on the other hand,
|
---|
203 | they are slightly less efficient.
|
---|
204 |
|
---|
205 | QSetIterator\<T\> allows you to iterate over a QSet\<T\>. If you
|
---|
206 | want to modify the set as you iterate over it, use
|
---|
207 | QMutableSetIterator\<T\> instead.
|
---|
208 |
|
---|
209 | The constructor takes a QSet as argument. After construction, the
|
---|
210 | iterator is located at the very beginning of the set (before
|
---|
211 | the first item). Here's how to iterate over all the elements
|
---|
212 | sequentially:
|
---|
213 |
|
---|
214 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 6
|
---|
215 |
|
---|
216 | The next() function returns the next item in the set and
|
---|
217 | advances the iterator. Unlike STL-style iterators, Java-style
|
---|
218 | iterators point \e between items rather than directly \e at
|
---|
219 | items. The first call to next() advances the iterator to the
|
---|
220 | position between the first and second item, and returns the first
|
---|
221 | item; the second call to next() advances the iterator to the
|
---|
222 | position between the second and third item, returning the second
|
---|
223 | item; and so on.
|
---|
224 |
|
---|
225 | \img javaiterators1.png
|
---|
226 |
|
---|
227 | Here's how to iterate over the elements in reverse order:
|
---|
228 |
|
---|
229 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 7
|
---|
230 |
|
---|
231 | If you want to find all occurrences of a particular value, use
|
---|
232 | findNext() or findPrevious() in a loop.
|
---|
233 |
|
---|
234 | Multiple iterators can be used on the same set. If the set
|
---|
235 | is modified while a QSetIterator is active, the QSetIterator
|
---|
236 | will continue iterating over the original set, ignoring the
|
---|
237 | modified copy.
|
---|
238 |
|
---|
239 | \sa QMutableSetIterator, QSet::const_iterator
|
---|
240 | */
|
---|
241 |
|
---|
242 | /*!
|
---|
243 | \class QMutableListIterator
|
---|
244 | \inmodule QtCore
|
---|
245 |
|
---|
246 | \brief The QMutableListIterator class provides a Java-style non-const iterator for QList and QQueue.
|
---|
247 |
|
---|
248 | QList has both \l{Java-style iterators} and \l{STL-style
|
---|
249 | iterators}. The Java-style iterators are more high-level and
|
---|
250 | easier to use than the STL-style iterators; on the other hand,
|
---|
251 | they are slightly less efficient.
|
---|
252 |
|
---|
253 | An alternative to using iterators is to use index positions. Most
|
---|
254 | QList member functions take an index as their first parameter,
|
---|
255 | making it possible to access, insert, and remove items without
|
---|
256 | using iterators.
|
---|
257 |
|
---|
258 | QMutableListIterator\<T\> allows you to iterate over a QList\<T\>
|
---|
259 | (or a QQueue\<T\>) and modify the list. If you don't want to
|
---|
260 | modify the list (or have a const QList), use the slightly faster
|
---|
261 | QListIterator\<T\> instead.
|
---|
262 |
|
---|
263 | The QMutableListIterator constructor takes a QList as argument.
|
---|
264 | After construction, the iterator is located at the very beginning
|
---|
265 | of the list (before the first item). Here's how to iterate over
|
---|
266 | all the elements sequentially:
|
---|
267 |
|
---|
268 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 8
|
---|
269 |
|
---|
270 | The next() function returns the next item in the list and
|
---|
271 | advances the iterator. Unlike STL-style iterators, Java-style
|
---|
272 | iterators point \e between items rather than directly \e at
|
---|
273 | items. The first call to next() advances the iterator to the
|
---|
274 | position between the first and second item, and returns the first
|
---|
275 | item; the second call to next() advances the iterator to the
|
---|
276 | position between the second and third item, returning the second
|
---|
277 | item; and so on.
|
---|
278 |
|
---|
279 | \img javaiterators1.png
|
---|
280 |
|
---|
281 | Here's how to iterate over the elements in reverse order:
|
---|
282 |
|
---|
283 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 9
|
---|
284 |
|
---|
285 | If you want to find all occurrences of a particular value, use
|
---|
286 | findNext() or findPrevious() in a loop.
|
---|
287 |
|
---|
288 | If you want to remove items as you iterate over the list, use
|
---|
289 | remove(). If you want to modify the value of an item, use
|
---|
290 | setValue(). If you want to insert a new item in the list, use
|
---|
291 | insert().
|
---|
292 |
|
---|
293 | Example:
|
---|
294 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 10
|
---|
295 |
|
---|
296 | The example traverses a list, replacing negative numbers with
|
---|
297 | their absolute values, and eliminating zeroes.
|
---|
298 |
|
---|
299 | Only one mutable iterator can be active on a given list at any
|
---|
300 | time. Furthermore, no changes should be done directly to the list
|
---|
301 | while the iterator is active (as opposed to through the
|
---|
302 | iterator), since this could invalidate the iterator and lead to
|
---|
303 | undefined behavior.
|
---|
304 |
|
---|
305 | \sa QListIterator, QList::iterator
|
---|
306 | */
|
---|
307 |
|
---|
308 | /*!
|
---|
309 | \class QMutableLinkedListIterator
|
---|
310 | \inmodule QtCore
|
---|
311 |
|
---|
312 | \brief The QMutableLinkedListIterator class provides a Java-style non-const iterator for QLinkedList.
|
---|
313 |
|
---|
314 | QLinkedList has both \l{Java-style iterators} and
|
---|
315 | \l{STL-style iterators}. The Java-style iterators are more
|
---|
316 | high-level and easier to use than the STL-style iterators; on the
|
---|
317 | other hand, they are slightly less efficient.
|
---|
318 |
|
---|
319 | QMutableLinkedListIterator\<T\> allows you to iterate over a
|
---|
320 | QLinkedList\<T\> and modify the list. If you don't want to modify
|
---|
321 | the list (or have a const QLinkedList), use the slightly faster
|
---|
322 | QLinkedListIterator\<T\> instead.
|
---|
323 |
|
---|
324 | The QMutableLinkedListIterator constructor takes a QLinkedList as
|
---|
325 | argument. After construction, the iterator is located at the very
|
---|
326 | beginning of the list (before the first item). Here's how to
|
---|
327 | iterate over all the elements sequentially:
|
---|
328 |
|
---|
329 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 11
|
---|
330 |
|
---|
331 | The next() function returns the next item in the list and
|
---|
332 | advances the iterator. Unlike STL-style iterators, Java-style
|
---|
333 | iterators point \e between items rather than directly \e at
|
---|
334 | items. The first call to next() advances the iterator to the
|
---|
335 | position between the first and second item, and returns the first
|
---|
336 | item; the second call to next() advances the iterator to the
|
---|
337 | position between the second and third item, returning the second
|
---|
338 | item; and so on.
|
---|
339 |
|
---|
340 | \img javaiterators1.png
|
---|
341 |
|
---|
342 | Here's how to iterate over the elements in reverse order:
|
---|
343 |
|
---|
344 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 12
|
---|
345 |
|
---|
346 | If you want to find all occurrences of a particular value, use
|
---|
347 | findNext() or findPrevious() in a loop.
|
---|
348 |
|
---|
349 | If you want to remove items as you iterate over the list, use
|
---|
350 | remove(). If you want to modify the value of an item, use
|
---|
351 | setValue(). If you want to insert a new item in the list, use
|
---|
352 | insert().
|
---|
353 |
|
---|
354 | Example:
|
---|
355 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 13
|
---|
356 |
|
---|
357 | The example traverses a list, replacing negative numbers with
|
---|
358 | their absolute values, and eliminating zeroes.
|
---|
359 |
|
---|
360 | Only one mutable iterator can be active on a given list at any
|
---|
361 | time. Furthermore, no changes should be done directly to the list
|
---|
362 | while the iterator is active (as opposed to through the
|
---|
363 | iterator), since this could invalidate the iterator and lead to
|
---|
364 | undefined behavior.
|
---|
365 |
|
---|
366 | \sa QLinkedListIterator, QLinkedList::iterator
|
---|
367 | */
|
---|
368 |
|
---|
369 | /*!
|
---|
370 | \class QMutableVectorIterator
|
---|
371 | \inmodule QtCore
|
---|
372 |
|
---|
373 | \brief The QMutableVectorIterator class provides a Java-style non-const iterator for QVector and QStack.
|
---|
374 |
|
---|
375 | QVector has both \l{Java-style iterators} and \l{STL-style
|
---|
376 | iterators}. The Java-style iterators are more high-level and
|
---|
377 | easier to use than the STL-style iterators; on the other hand,
|
---|
378 | they are slightly less efficient.
|
---|
379 |
|
---|
380 | An alternative to using iterators is to use index positions. Most
|
---|
381 | QVector member functions take an index as their first parameter,
|
---|
382 | making it possible to access, insert, and remove items without
|
---|
383 | using iterators.
|
---|
384 |
|
---|
385 | QMutableVectorIterator\<T\> allows you to iterate over a
|
---|
386 | QVector\<T\> and modify the vector. If you don't want to modify
|
---|
387 | the vector (or have a const QVector), use the slightly faster
|
---|
388 | QVectorIterator\<T\> instead.
|
---|
389 |
|
---|
390 | The QMutableVectorIterator constructor takes a QVector as
|
---|
391 | argument. After construction, the iterator is located at the very
|
---|
392 | beginning of the list (before the first item). Here's how to
|
---|
393 | iterate over all the elements sequentially:
|
---|
394 |
|
---|
395 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 14
|
---|
396 |
|
---|
397 | The next() function returns the next item in the vector and
|
---|
398 | advances the iterator. Unlike STL-style iterators, Java-style
|
---|
399 | iterators point \e between items rather than directly \e at
|
---|
400 | items. The first call to next() advances the iterator to the
|
---|
401 | position between the first and second item, and returns the first
|
---|
402 | item; the second call to next() advances the iterator to the
|
---|
403 | position between the second and third item, returning the second
|
---|
404 | item; and so on.
|
---|
405 |
|
---|
406 | \img javaiterators1.png
|
---|
407 |
|
---|
408 | Here's how to iterate over the elements in reverse order:
|
---|
409 |
|
---|
410 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 15
|
---|
411 |
|
---|
412 | If you want to find all occurrences of a particular value, use
|
---|
413 | findNext() or findPrevious() in a loop.
|
---|
414 |
|
---|
415 | If you want to remove items as you iterate over the vector, use
|
---|
416 | remove(). If you want to modify the value of an item, use
|
---|
417 | setValue(). If you want to insert a new item in the vector, use
|
---|
418 | insert().
|
---|
419 |
|
---|
420 | Example:
|
---|
421 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 16
|
---|
422 |
|
---|
423 | The example traverses a vector, replacing negative numbers with
|
---|
424 | their absolute values, and eliminating zeroes.
|
---|
425 |
|
---|
426 | Only one mutable iterator can be active on a given vector at any
|
---|
427 | time. Furthermore, no changes should be done directly to the
|
---|
428 | vector while the iterator is active (as opposed to through the
|
---|
429 | iterator), since this could invalidate the iterator and lead to
|
---|
430 | undefined behavior.
|
---|
431 |
|
---|
432 | \sa QVectorIterator, QVector::iterator
|
---|
433 | */
|
---|
434 |
|
---|
435 | /*!
|
---|
436 | \class QMutableSetIterator
|
---|
437 | \inmodule QtCore
|
---|
438 | \since 4.2
|
---|
439 |
|
---|
440 | \brief The QMutableSetIterator class provides a Java-style non-const iterator for QSet.
|
---|
441 |
|
---|
442 | QSet has both \l{Java-style iterators} and \l{STL-style
|
---|
443 | iterators}. The Java-style iterators are more high-level and
|
---|
444 | easier to use than the STL-style iterators; on the other hand,
|
---|
445 | they are slightly less efficient.
|
---|
446 |
|
---|
447 | QMutableSetIterator\<T\> allows you to iterate over a QSet\<T\>
|
---|
448 | and remove items from the set as you iterate. If you don't want
|
---|
449 | to modify the set (or have a const QSet), use the slightly faster
|
---|
450 | QSetIterator\<T\> instead.
|
---|
451 |
|
---|
452 | The QMutableSetIterator constructor takes a QSet as argument.
|
---|
453 | After construction, the iterator is located at the very beginning
|
---|
454 | of the set (before the first item). Here's how to iterate over
|
---|
455 | all the elements sequentially:
|
---|
456 |
|
---|
457 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 17
|
---|
458 |
|
---|
459 | The next() function returns the next item in the set and
|
---|
460 | advances the iterator. Unlike STL-style iterators, Java-style
|
---|
461 | iterators point \e between items rather than directly \e at
|
---|
462 | items. The first call to next() advances the iterator to the
|
---|
463 | position between the first and second item, and returns the first
|
---|
464 | item; the second call to next() advances the iterator to the
|
---|
465 | position between the second and third item, returning the second
|
---|
466 | item; and so on.
|
---|
467 |
|
---|
468 | \img javaiterators1.png
|
---|
469 |
|
---|
470 | Here's how to iterate over the elements in reverse order:
|
---|
471 |
|
---|
472 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 18
|
---|
473 |
|
---|
474 | If you want to remove items as you iterate over the set, use
|
---|
475 | remove().
|
---|
476 |
|
---|
477 | Only one mutable iterator can be active on a given set at any
|
---|
478 | time. Furthermore, no changes should be done directly to the set
|
---|
479 | while the iterator is active (as opposed to through the
|
---|
480 | iterator), since this could invalidate the iterator and lead to
|
---|
481 | undefined behavior.
|
---|
482 |
|
---|
483 | \sa QSetIterator, QSet::iterator
|
---|
484 | */
|
---|
485 |
|
---|
486 | /*!
|
---|
487 | \fn QListIterator::QListIterator(const QList<T> &list)
|
---|
488 | \fn QLinkedListIterator::QLinkedListIterator(const QLinkedList<T> &list)
|
---|
489 | \fn QMutableListIterator::QMutableListIterator(QList<T> &list)
|
---|
490 | \fn QMutableLinkedListIterator::QMutableLinkedListIterator(QLinkedList<T> &list)
|
---|
491 |
|
---|
492 | Constructs an iterator for traversing \a list. The iterator is
|
---|
493 | set to be at the front of the list (before the first item).
|
---|
494 |
|
---|
495 | \sa operator=()
|
---|
496 | */
|
---|
497 |
|
---|
498 | /*!
|
---|
499 | \fn QVectorIterator::QVectorIterator(const QVector<T> &vector)
|
---|
500 | \fn QMutableVectorIterator::QMutableVectorIterator(QVector<T> &vector)
|
---|
501 |
|
---|
502 | Constructs an iterator for traversing \a vector. The iterator is
|
---|
503 | set to be at the front of the vector (before the first item).
|
---|
504 |
|
---|
505 | \sa operator=()
|
---|
506 | */
|
---|
507 |
|
---|
508 | /*!
|
---|
509 | \fn QSetIterator::QSetIterator(const QSet<T> &set)
|
---|
510 | \fn QMutableSetIterator::QMutableSetIterator(QSet<T> &set)
|
---|
511 |
|
---|
512 | Constructs an iterator for traversing \a set. The iterator is
|
---|
513 | set to be at the front of the set (before the first item).
|
---|
514 |
|
---|
515 | \sa operator=()
|
---|
516 | */
|
---|
517 |
|
---|
518 | /*!
|
---|
519 | \fn QMutableListIterator::~QMutableListIterator()
|
---|
520 | \fn QMutableLinkedListIterator::~QMutableLinkedListIterator()
|
---|
521 | \fn QMutableVectorIterator::~QMutableVectorIterator()
|
---|
522 | \fn QMutableSetIterator::~QMutableSetIterator()
|
---|
523 |
|
---|
524 | Destroys the iterator.
|
---|
525 |
|
---|
526 | \sa operator=()
|
---|
527 | */
|
---|
528 |
|
---|
529 | /*! \fn QMutableListIterator &QMutableListIterator::operator=(QList<T> &list)
|
---|
530 | \fn QMutableLinkedListIterator &QMutableLinkedListIterator::operator=(QLinkedList<T> &list)
|
---|
531 | \fn QListIterator &QListIterator::operator=(const QList<T> &list)
|
---|
532 | \fn QLinkedListIterator &QLinkedListIterator::operator=(const QLinkedList<T> &list)
|
---|
533 |
|
---|
534 | Makes the iterator operate on \a list. The iterator is set to be
|
---|
535 | at the front of the list (before the first item).
|
---|
536 |
|
---|
537 | \sa toFront(), toBack()
|
---|
538 | */
|
---|
539 |
|
---|
540 | /*! \fn QVectorIterator &QVectorIterator::operator=(const QVector<T> &vector)
|
---|
541 | \fn QMutableVectorIterator &QMutableVectorIterator::operator=(QVector<T> &vector)
|
---|
542 |
|
---|
543 | Makes the iterator operate on \a vector. The iterator is set to be
|
---|
544 | at the front of the vector (before the first item).
|
---|
545 |
|
---|
546 | \sa toFront(), toBack()
|
---|
547 | */
|
---|
548 |
|
---|
549 | /*! \fn QSetIterator &QSetIterator::operator=(const QSet<T> &set)
|
---|
550 | \fn QMutableSetIterator &QMutableSetIterator::operator=(QSet<T> &set)
|
---|
551 |
|
---|
552 | Makes the iterator operate on \a set. The iterator is set to be
|
---|
553 | at the front of the set (before the first item).
|
---|
554 |
|
---|
555 | \sa toFront(), toBack()
|
---|
556 | */
|
---|
557 |
|
---|
558 | /*! \fn void QListIterator::toFront()
|
---|
559 | \fn void QLinkedListIterator::toFront()
|
---|
560 | \fn void QVectorIterator::toFront()
|
---|
561 | \fn void QSetIterator::toFront()
|
---|
562 | \fn void QMutableListIterator::toFront()
|
---|
563 | \fn void QMutableLinkedListIterator::toFront()
|
---|
564 | \fn void QMutableVectorIterator::toFront()
|
---|
565 | \fn void QMutableSetIterator::toFront()
|
---|
566 |
|
---|
567 | Moves the iterator to the front of the container (before the
|
---|
568 | first item).
|
---|
569 |
|
---|
570 | \sa toBack(), next()
|
---|
571 | */
|
---|
572 |
|
---|
573 | /*! \fn void QListIterator::toBack()
|
---|
574 | \fn void QLinkedListIterator::toBack()
|
---|
575 | \fn void QVectorIterator::toBack()
|
---|
576 | \fn void QSetIterator::toBack()
|
---|
577 | \fn void QMutableListIterator::toBack()
|
---|
578 | \fn void QMutableLinkedListIterator::toBack()
|
---|
579 | \fn void QMutableVectorIterator::toBack()
|
---|
580 | \fn void QMutableSetIterator::toBack()
|
---|
581 |
|
---|
582 | Moves the iterator to the back of the container (after the last
|
---|
583 | item).
|
---|
584 |
|
---|
585 | \sa toFront(), previous()
|
---|
586 | */
|
---|
587 |
|
---|
588 | /*! \fn bool QListIterator::hasNext() const
|
---|
589 | \fn bool QLinkedListIterator::hasNext() const
|
---|
590 | \fn bool QVectorIterator::hasNext() const
|
---|
591 | \fn bool QSetIterator::hasNext() const
|
---|
592 | \fn bool QMutableListIterator::hasNext() const
|
---|
593 | \fn bool QMutableLinkedListIterator::hasNext() const
|
---|
594 | \fn bool QMutableVectorIterator::hasNext() const
|
---|
595 | \fn bool QMutableSetIterator::hasNext() const
|
---|
596 |
|
---|
597 | Returns true if there is at least one item ahead of the iterator,
|
---|
598 | i.e. the iterator is \e not at the back of the container;
|
---|
599 | otherwise returns false.
|
---|
600 |
|
---|
601 | \sa hasPrevious(), next()
|
---|
602 | */
|
---|
603 |
|
---|
604 | /*! \fn const T &QListIterator::next()
|
---|
605 | \fn const T &QLinkedListIterator::next()
|
---|
606 | \fn const T &QVectorIterator::next()
|
---|
607 | \fn const T &QSetIterator::next()
|
---|
608 | \fn const T &QMutableSetIterator::next()
|
---|
609 |
|
---|
610 | Returns the next item and advances the iterator by one position.
|
---|
611 |
|
---|
612 | Calling this function on an iterator located at the back of the
|
---|
613 | container leads to undefined results.
|
---|
614 |
|
---|
615 | \sa hasNext(), peekNext(), previous()
|
---|
616 | */
|
---|
617 |
|
---|
618 | /*! \fn T &QMutableListIterator::next()
|
---|
619 | \fn T &QMutableLinkedListIterator::next()
|
---|
620 | \fn T &QMutableVectorIterator::next()
|
---|
621 |
|
---|
622 | Returns a reference to the next item, and advances the iterator
|
---|
623 | by one position.
|
---|
624 |
|
---|
625 | Calling this function on an iterator located at the back of the
|
---|
626 | container leads to undefined results.
|
---|
627 |
|
---|
628 | \sa hasNext(), peekNext(), previous()
|
---|
629 | */
|
---|
630 |
|
---|
631 | /*! \fn const T &QListIterator::peekNext() const
|
---|
632 | \fn const T &QLinkedListIterator::peekNext() const
|
---|
633 | \fn const T &QVectorIterator::peekNext() const
|
---|
634 | \fn const T &QSetIterator::peekNext() const
|
---|
635 | \fn const T &QMutableSetIterator::peekNext() const
|
---|
636 |
|
---|
637 | Returns the next item without moving the iterator.
|
---|
638 |
|
---|
639 | Calling this function on an iterator located at the back of the
|
---|
640 | container leads to undefined results.
|
---|
641 |
|
---|
642 | \sa hasNext(), next(), peekPrevious()
|
---|
643 | */
|
---|
644 |
|
---|
645 | /*! \fn T &QMutableListIterator::peekNext() const
|
---|
646 | \fn T &QMutableLinkedListIterator::peekNext() const
|
---|
647 | \fn T &QMutableVectorIterator::peekNext() const
|
---|
648 |
|
---|
649 | Returns a reference to the next item, without moving the iterator.
|
---|
650 |
|
---|
651 | Calling this function on an iterator located at the back of the
|
---|
652 | container leads to undefined results.
|
---|
653 |
|
---|
654 | \sa hasNext(), next(), peekPrevious()
|
---|
655 | */
|
---|
656 |
|
---|
657 | /*! \fn bool QListIterator::hasPrevious() const
|
---|
658 | \fn bool QLinkedListIterator::hasPrevious() const
|
---|
659 | \fn bool QVectorIterator::hasPrevious() const
|
---|
660 | \fn bool QSetIterator::hasPrevious() const
|
---|
661 | \fn bool QMutableListIterator::hasPrevious() const
|
---|
662 | \fn bool QMutableLinkedListIterator::hasPrevious() const
|
---|
663 | \fn bool QMutableVectorIterator::hasPrevious() const
|
---|
664 | \fn bool QMutableSetIterator::hasPrevious() const
|
---|
665 |
|
---|
666 | Returns true if there is at least one item behind the iterator,
|
---|
667 | i.e. the iterator is \e not at the front of the container;
|
---|
668 | otherwise returns false.
|
---|
669 |
|
---|
670 | \sa hasNext(), previous()
|
---|
671 | */
|
---|
672 |
|
---|
673 | /*! \fn const T &QListIterator::previous()
|
---|
674 | \fn const T &QLinkedListIterator::previous()
|
---|
675 | \fn const T &QVectorIterator::previous()
|
---|
676 | \fn const T &QSetIterator::previous()
|
---|
677 | \fn const T &QMutableSetIterator::previous()
|
---|
678 |
|
---|
679 | Returns the previous item and moves the iterator back by one
|
---|
680 | position.
|
---|
681 |
|
---|
682 | Calling this function on an iterator located at the front of the
|
---|
683 | container leads to undefined results.
|
---|
684 |
|
---|
685 | \sa hasPrevious(), peekPrevious(), next()
|
---|
686 | */
|
---|
687 |
|
---|
688 | /*! \fn T &QMutableListIterator::previous()
|
---|
689 | \fn T &QMutableLinkedListIterator::previous()
|
---|
690 | \fn T &QMutableVectorIterator::previous()
|
---|
691 |
|
---|
692 | Returns a reference to the previous item and moves the iterator
|
---|
693 | back by one position.
|
---|
694 |
|
---|
695 | Calling this function on an iterator located at the front of the
|
---|
696 | container leads to undefined results.
|
---|
697 |
|
---|
698 | \sa hasPrevious(), peekPrevious(), next()
|
---|
699 | */
|
---|
700 |
|
---|
701 | /*! \fn const T &QListIterator::peekPrevious() const
|
---|
702 | \fn const T &QLinkedListIterator::peekPrevious() const
|
---|
703 | \fn const T &QVectorIterator::peekPrevious() const
|
---|
704 | \fn const T &QSetIterator::peekPrevious() const
|
---|
705 | \fn const T &QMutableSetIterator::peekPrevious() const
|
---|
706 |
|
---|
707 | Returns the previous item without moving the iterator.
|
---|
708 |
|
---|
709 | Calling this function on an iterator located at the front of the
|
---|
710 | container leads to undefined results.
|
---|
711 |
|
---|
712 | \sa hasPrevious(), previous(), peekNext()
|
---|
713 | */
|
---|
714 |
|
---|
715 | /*! \fn T &QMutableListIterator::peekPrevious() const
|
---|
716 | \fn T &QMutableLinkedListIterator::peekPrevious() const
|
---|
717 | \fn T &QMutableVectorIterator::peekPrevious() const
|
---|
718 |
|
---|
719 | Returns a reference to the previous item, without moving the iterator.
|
---|
720 |
|
---|
721 | Calling this function on an iterator located at the front of the
|
---|
722 | container leads to undefined results.
|
---|
723 |
|
---|
724 | \sa hasPrevious(), previous(), peekNext()
|
---|
725 | */
|
---|
726 |
|
---|
727 | /*! \fn bool QListIterator::findNext(const T &value)
|
---|
728 | \fn bool QLinkedListIterator::findNext(const T &value)
|
---|
729 | \fn bool QVectorIterator::findNext(const T &value)
|
---|
730 | \fn bool QSetIterator::findNext(const T &value)
|
---|
731 | \fn bool QMutableListIterator::findNext(const T &value)
|
---|
732 | \fn bool QMutableLinkedListIterator::findNext(const T &value)
|
---|
733 | \fn bool QMutableVectorIterator::findNext(const T &value)
|
---|
734 | \fn bool QMutableSetIterator::findNext(const T &value)
|
---|
735 |
|
---|
736 | Searches for \a value starting from the current iterator position
|
---|
737 | forward. Returns true if \a value is found; otherwise returns false.
|
---|
738 |
|
---|
739 | After the call, if \a value was found, the iterator is positioned
|
---|
740 | just after the matching item; otherwise, the iterator is
|
---|
741 | positioned at the back of the container.
|
---|
742 |
|
---|
743 | \sa findPrevious()
|
---|
744 | */
|
---|
745 |
|
---|
746 | /*! \fn bool QListIterator::findPrevious(const T &value)
|
---|
747 | \fn bool QLinkedListIterator::findPrevious(const T &value)
|
---|
748 | \fn bool QVectorIterator::findPrevious(const T &value)
|
---|
749 | \fn bool QSetIterator::findPrevious(const T &value)
|
---|
750 | \fn bool QMutableListIterator::findPrevious(const T &value)
|
---|
751 | \fn bool QMutableLinkedListIterator::findPrevious(const T &value)
|
---|
752 | \fn bool QMutableVectorIterator::findPrevious(const T &value)
|
---|
753 | \fn bool QMutableSetIterator::findPrevious(const T &value)
|
---|
754 |
|
---|
755 | Searches for \a value starting from the current iterator position
|
---|
756 | backward. Returns true if \a value is found; otherwise returns
|
---|
757 | false.
|
---|
758 |
|
---|
759 | After the call, if \a value was found, the iterator is positioned
|
---|
760 | just before the matching item; otherwise, the iterator is
|
---|
761 | positioned at the front of the container.
|
---|
762 |
|
---|
763 | \sa findNext()
|
---|
764 | */
|
---|
765 |
|
---|
766 | /*! \fn void QMutableListIterator::remove()
|
---|
767 |
|
---|
768 | Removes the last item that was jumped over using one of the
|
---|
769 | traversal functions (next(), previous(), findNext(), findPrevious()).
|
---|
770 |
|
---|
771 | Example:
|
---|
772 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 19
|
---|
773 |
|
---|
774 | \sa insert(), setValue()
|
---|
775 | */
|
---|
776 |
|
---|
777 | /*! \fn void QMutableLinkedListIterator::remove()
|
---|
778 |
|
---|
779 | Removes the last item that was jumped over using one of the
|
---|
780 | traversal functions (next(), previous(), findNext(), findPrevious()).
|
---|
781 |
|
---|
782 | Example:
|
---|
783 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 20
|
---|
784 |
|
---|
785 | \sa insert(), setValue()
|
---|
786 | */
|
---|
787 |
|
---|
788 | /*! \fn void QMutableVectorIterator::remove()
|
---|
789 |
|
---|
790 | Removes the last item that was jumped over using one of the
|
---|
791 | traversal functions (next(), previous(), findNext(), findPrevious()).
|
---|
792 |
|
---|
793 | Example:
|
---|
794 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 21
|
---|
795 |
|
---|
796 | \sa insert(), setValue()
|
---|
797 | */
|
---|
798 |
|
---|
799 | /*! \fn void QMutableSetIterator::remove()
|
---|
800 |
|
---|
801 | Removes the last item that was jumped over using one of the
|
---|
802 | traversal functions (next(), previous(), findNext(), findPrevious()).
|
---|
803 |
|
---|
804 | Example:
|
---|
805 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 22
|
---|
806 |
|
---|
807 | \sa value()
|
---|
808 | */
|
---|
809 |
|
---|
810 | /*! \fn void QMutableListIterator::setValue(const T &value) const
|
---|
811 |
|
---|
812 | Replaces the value of the last item that was jumped over using
|
---|
813 | one of the traversal functions with \a value.
|
---|
814 |
|
---|
815 | The traversal functions are next(), previous(), findNext(), and
|
---|
816 | findPrevious().
|
---|
817 |
|
---|
818 | Example:
|
---|
819 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 23
|
---|
820 |
|
---|
821 | \sa value(), remove(), insert()
|
---|
822 | */
|
---|
823 |
|
---|
824 | /*! \fn void QMutableLinkedListIterator::setValue(const T &value) const
|
---|
825 |
|
---|
826 | Replaces the value of the last item that was jumped over using
|
---|
827 | one of the traversal functions with \a value.
|
---|
828 |
|
---|
829 | The traversal functions are next(), previous(), findNext(), and
|
---|
830 | findPrevious().
|
---|
831 |
|
---|
832 | Example:
|
---|
833 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 24
|
---|
834 |
|
---|
835 | \sa value(), remove(), insert()
|
---|
836 | */
|
---|
837 |
|
---|
838 | /*! \fn void QMutableVectorIterator::setValue(const T &value) const
|
---|
839 |
|
---|
840 | Replaces the value of the last item that was jumped over using
|
---|
841 | one of the traversal functions with \a value.
|
---|
842 |
|
---|
843 | The traversal functions are next(), previous(), findNext(), and
|
---|
844 | findPrevious().
|
---|
845 |
|
---|
846 | Example:
|
---|
847 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 25
|
---|
848 |
|
---|
849 | \sa value(), remove(), insert()
|
---|
850 | */
|
---|
851 |
|
---|
852 | /*! \fn const T &QMutableListIterator::value() const
|
---|
853 | \fn const T &QMutableLinkedListIterator::value() const
|
---|
854 | \fn const T &QMutableVectorIterator::value() const
|
---|
855 | \fn const T &QMutableSetIterator::value() const
|
---|
856 |
|
---|
857 | Returns the value of the last item that was jumped over using one
|
---|
858 | of the traversal functions (next(), previous(), findNext(),
|
---|
859 | findPrevious()).
|
---|
860 |
|
---|
861 | After a call to next() or findNext(), value() is equivalent to
|
---|
862 | peekPrevious(). After a call to previous() or findPrevious(), value() is
|
---|
863 | equivalent to peekNext().
|
---|
864 | */
|
---|
865 |
|
---|
866 | /*!
|
---|
867 | \fn T &QMutableListIterator::value()
|
---|
868 | \fn T &QMutableLinkedListIterator::value()
|
---|
869 | \fn T &QMutableVectorIterator::value()
|
---|
870 | \overload
|
---|
871 |
|
---|
872 | Returns a non-const reference to the value of the last item that
|
---|
873 | was jumped over using one of the traversal functions.
|
---|
874 | */
|
---|
875 |
|
---|
876 | /*! \fn void QMutableListIterator::insert(const T &value)
|
---|
877 | \fn void QMutableLinkedListIterator::insert(const T &value)
|
---|
878 | \fn void QMutableVectorIterator::insert(const T &value)
|
---|
879 |
|
---|
880 | Inserts \a value at the current iterator position. After the
|
---|
881 | call, the iterator is located just after the inserted item.
|
---|
882 |
|
---|
883 | \sa remove(), setValue()
|
---|
884 | */
|
---|
885 |
|
---|
886 | /*!
|
---|
887 | \class QMapIterator
|
---|
888 | \inmodule QtCore
|
---|
889 |
|
---|
890 | \brief The QMapIterator class provides a Java-style const iterator for QMap and QMultiMap.
|
---|
891 |
|
---|
892 | QMap has both \l{Java-style iterators} and \l{STL-style
|
---|
893 | iterators}. The Java-style iterators are more high-level and
|
---|
894 | easier to use than the STL-style iterators; on the other hand,
|
---|
895 | they are slightly less efficient.
|
---|
896 |
|
---|
897 | QMapIterator\<Key, T\> allows you to iterate over a QMap (or a
|
---|
898 | QMultiMap). If you want to modify the map as you iterate over
|
---|
899 | it, use QMutableMapIterator instead.
|
---|
900 |
|
---|
901 | The QMapIterator constructor takes a QMap as argument. After
|
---|
902 | construction, the iterator is located at the very beginning of
|
---|
903 | the map (before the first item). Here's how to iterate over all
|
---|
904 | the elements sequentially:
|
---|
905 |
|
---|
906 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 26
|
---|
907 |
|
---|
908 | The next() function returns the next item in the map and
|
---|
909 | advances the iterator. The key() and value() functions return the
|
---|
910 | key and value of the last item that was jumped over.
|
---|
911 |
|
---|
912 | Unlike STL-style iterators, Java-style iterators point \e between
|
---|
913 | items rather than directly \e at items. The first call to next()
|
---|
914 | advances the iterator to the position between the first and
|
---|
915 | second item, and returns the first item; the second call to
|
---|
916 | next() advances the iterator to the position between the second
|
---|
917 | and third item; and so on.
|
---|
918 |
|
---|
919 | \img javaiterators1.png
|
---|
920 |
|
---|
921 | Here's how to iterate over the elements in reverse order:
|
---|
922 |
|
---|
923 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 27
|
---|
924 |
|
---|
925 | If you want to find all occurrences of a particular value, use
|
---|
926 | findNext() or findPrevious() in a loop. For example:
|
---|
927 |
|
---|
928 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 28
|
---|
929 |
|
---|
930 | Multiple iterators can be used on the same map. If the map is
|
---|
931 | modified while a QMapIterator is active, the QMapIterator will
|
---|
932 | continue iterating over the original map, ignoring the modified
|
---|
933 | copy.
|
---|
934 |
|
---|
935 | \sa QMutableMapIterator, QMap::const_iterator
|
---|
936 | */
|
---|
937 |
|
---|
938 | /*!
|
---|
939 | \class QHashIterator
|
---|
940 | \inmodule QtCore
|
---|
941 |
|
---|
942 | \brief The QHashIterator class provides a Java-style const iterator for QHash and QMultiHash.
|
---|
943 |
|
---|
944 | QHash has both \l{Java-style iterators} and \l{STL-style
|
---|
945 | iterators}. The Java-style iterators are more high-level and
|
---|
946 | easier to use than the STL-style iterators; on the other hand,
|
---|
947 | they are slightly less efficient.
|
---|
948 |
|
---|
949 | QHashIterator\<Key, T\> allows you to iterate over a QHash (or a
|
---|
950 | QMultiHash). If you want to modify the hash as you iterate over
|
---|
951 | it, use QMutableHashIterator instead.
|
---|
952 |
|
---|
953 | The QHashIterator constructor takes a QHash as argument. After
|
---|
954 | construction, the iterator is located at the very beginning of
|
---|
955 | the hash (before the first item). Here's how to iterate over all
|
---|
956 | the elements sequentially:
|
---|
957 |
|
---|
958 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 29
|
---|
959 |
|
---|
960 | The next() function returns the next item in the hash and
|
---|
961 | advances the iterator. The key() and value() functions return the
|
---|
962 | key and value of the last item that was jumped over.
|
---|
963 |
|
---|
964 | Unlike STL-style iterators, Java-style iterators point \e between
|
---|
965 | items rather than directly \e at items. The first call to next()
|
---|
966 | advances the iterator to the position between the first and
|
---|
967 | second item, and returns the first item; the second call to
|
---|
968 | next() advances the iterator to the position between the second
|
---|
969 | and third item; and so on.
|
---|
970 |
|
---|
971 | \img javaiterators1.png
|
---|
972 |
|
---|
973 | Here's how to iterate over the elements in reverse order:
|
---|
974 |
|
---|
975 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 30
|
---|
976 |
|
---|
977 | If you want to find all occurrences of a particular value, use
|
---|
978 | findNext() or findPrevious() in a loop. For example:
|
---|
979 |
|
---|
980 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 31
|
---|
981 |
|
---|
982 | Multiple iterators can be used on the same hash. If the hash is
|
---|
983 | modified while a QHashIterator is active, the QHashIterator will
|
---|
984 | continue iterating over the original hash, ignoring the modified
|
---|
985 | copy.
|
---|
986 |
|
---|
987 | \sa QMutableHashIterator, QHash::const_iterator
|
---|
988 | */
|
---|
989 |
|
---|
990 | /*!
|
---|
991 | \class QMutableMapIterator
|
---|
992 | \inmodule QtCore
|
---|
993 |
|
---|
994 | \brief The QMutableMapIterator class provides a Java-style non-const iterator for QMap and QMultiMap.
|
---|
995 |
|
---|
996 | QMap has both \l{Java-style iterators} and \l{STL-style
|
---|
997 | iterators}. The Java-style iterators are more high-level and
|
---|
998 | easier to use than the STL-style iterators; on the other hand,
|
---|
999 | they are slightly less efficient.
|
---|
1000 |
|
---|
1001 | QMutableMapIterator\<Key, T\> allows you to iterate over a QMap
|
---|
1002 | (or a QMultiMap) and modify the map. If you don't want to modify
|
---|
1003 | the map (or have a const QMap), use the slightly faster
|
---|
1004 | QMapIterator instead.
|
---|
1005 |
|
---|
1006 | The QMutableMapIterator constructor takes a QMap as argument.
|
---|
1007 | After construction, the iterator is located at the very beginning
|
---|
1008 | of the map (before the first item). Here's how to iterate over
|
---|
1009 | all the elements sequentially:
|
---|
1010 |
|
---|
1011 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 32
|
---|
1012 |
|
---|
1013 | The next() function returns the next item in the map and
|
---|
1014 | advances the iterator. The key() and value() functions return the
|
---|
1015 | key and value of the last item that was jumped over.
|
---|
1016 |
|
---|
1017 | Unlike STL-style iterators, Java-style iterators point \e between
|
---|
1018 | items rather than directly \e at items. The first call to next()
|
---|
1019 | advances the iterator to the position between the first and
|
---|
1020 | second item, and returns the first item; the second call to
|
---|
1021 | next() advances the iterator to the position between the second
|
---|
1022 | and third item; and so on.
|
---|
1023 |
|
---|
1024 | \img javaiterators1.png
|
---|
1025 |
|
---|
1026 | Here's how to iterate over the elements in reverse order:
|
---|
1027 |
|
---|
1028 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 33
|
---|
1029 |
|
---|
1030 | If you want to find all occurrences of a particular value, use
|
---|
1031 | findNext() or findPrevious() in a loop. For example:
|
---|
1032 |
|
---|
1033 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 34
|
---|
1034 |
|
---|
1035 | If you want to remove items as you iterate over the map, use
|
---|
1036 | remove(). If you want to modify the value of an item, use
|
---|
1037 | setValue().
|
---|
1038 |
|
---|
1039 | Example:
|
---|
1040 |
|
---|
1041 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 35
|
---|
1042 |
|
---|
1043 | The example removes all (key, value) pairs where the key and the
|
---|
1044 | value are the same.
|
---|
1045 |
|
---|
1046 | Only one mutable iterator can be active on a given map at any
|
---|
1047 | time. Furthermore, no changes should be done directly to the map
|
---|
1048 | while the iterator is active (as opposed to through the
|
---|
1049 | iterator), since this could invalidate the iterator and lead to
|
---|
1050 | undefined behavior.
|
---|
1051 |
|
---|
1052 | \sa QMapIterator, QMap::iterator
|
---|
1053 | */
|
---|
1054 |
|
---|
1055 | /*!
|
---|
1056 | \class QMutableHashIterator
|
---|
1057 | \inmodule QtCore
|
---|
1058 |
|
---|
1059 | \brief The QMutableHashIterator class provides a Java-style non-const iterator for QHash and QMultiHash.
|
---|
1060 |
|
---|
1061 | QHash has both \l{Java-style iterators} and \l{STL-style
|
---|
1062 | iterators}. The Java-style iterators are more high-level and
|
---|
1063 | easier to use than the STL-style iterators; on the other hand,
|
---|
1064 | they are slightly less efficient.
|
---|
1065 |
|
---|
1066 | QMutableHashIterator\<Key, T\> allows you to iterate over a QHash
|
---|
1067 | (or a QMultiHash) and modify the hash. If you don't want to modify
|
---|
1068 | the hash (or have a const QHash), use the slightly faster
|
---|
1069 | QHashIterator instead.
|
---|
1070 |
|
---|
1071 | The QMutableHashIterator constructor takes a QHash as argument.
|
---|
1072 | After construction, the iterator is located at the very beginning
|
---|
1073 | of the hash (before the first item). Here's how to iterate over
|
---|
1074 | all the elements sequentially:
|
---|
1075 |
|
---|
1076 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 36
|
---|
1077 |
|
---|
1078 | The next() function returns the next item in the hash and
|
---|
1079 | advances the iterator. The key() and value() functions return the
|
---|
1080 | key and value of the last item that was jumped over.
|
---|
1081 |
|
---|
1082 | Unlike STL-style iterators, Java-style iterators point \e between
|
---|
1083 | items rather than directly \e at items. The first call to next()
|
---|
1084 | advances the iterator to the position between the first and
|
---|
1085 | second item, and returns the first item; the second call to
|
---|
1086 | next() advances the iterator to the position between the second
|
---|
1087 | and third item; and so on.
|
---|
1088 |
|
---|
1089 | \img javaiterators1.png
|
---|
1090 |
|
---|
1091 | Here's how to iterate over the elements in reverse order:
|
---|
1092 |
|
---|
1093 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 37
|
---|
1094 |
|
---|
1095 | If you want to find all occurrences of a particular value, use
|
---|
1096 | findNext() or findPrevious() in a loop. For example:
|
---|
1097 |
|
---|
1098 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 38
|
---|
1099 |
|
---|
1100 | If you want to remove items as you iterate over the hash, use
|
---|
1101 | remove(). If you want to modify the value of an item, use
|
---|
1102 | setValue().
|
---|
1103 |
|
---|
1104 | Example:
|
---|
1105 |
|
---|
1106 | \snippet doc/src/snippets/code/doc_src_qiterator.qdoc 39
|
---|
1107 |
|
---|
1108 | The example removes all (key, value) pairs where the key and the
|
---|
1109 | value are the same.
|
---|
1110 |
|
---|
1111 | Only one mutable iterator can be active on a given hash at any
|
---|
1112 | time. Furthermore, no changes should be done directly to the hash
|
---|
1113 | while the iterator is active (as opposed to through the
|
---|
1114 | iterator), since this could invalidate the iterator and lead to
|
---|
1115 | undefined behavior.
|
---|
1116 |
|
---|
1117 | \sa QHashIterator, QHash::iterator
|
---|
1118 | */
|
---|
1119 |
|
---|
1120 | /*! \fn QMapIterator::QMapIterator(const QMap<Key, T> &map)
|
---|
1121 | \fn QMutableMapIterator::QMutableMapIterator(QMap<Key, T> &map)
|
---|
1122 |
|
---|
1123 | Constructs an iterator for traversing \a map. The iterator is set
|
---|
1124 | to be at the front of the map (before the first item).
|
---|
1125 |
|
---|
1126 | \sa operator=()
|
---|
1127 | */
|
---|
1128 |
|
---|
1129 | /*! \fn QHashIterator::QHashIterator(const QHash<Key, T> &hash)
|
---|
1130 | \fn QMutableHashIterator::QMutableHashIterator(QHash<Key, T> &hash)
|
---|
1131 |
|
---|
1132 | Constructs an iterator for traversing \a hash. The iterator is
|
---|
1133 | set to be at the front of the hash (before the first item).
|
---|
1134 |
|
---|
1135 | \sa operator=()
|
---|
1136 | */
|
---|
1137 |
|
---|
1138 | /*!
|
---|
1139 | \fn QMutableMapIterator::~QMutableMapIterator()
|
---|
1140 | \fn QMutableHashIterator::~QMutableHashIterator()
|
---|
1141 |
|
---|
1142 | Destroys the iterator.
|
---|
1143 |
|
---|
1144 | \sa operator=()
|
---|
1145 | */
|
---|
1146 |
|
---|
1147 | /*! \fn QMapIterator &QMapIterator::operator=(const QMap<Key, T> &map)
|
---|
1148 | \fn QMutableMapIterator &QMutableMapIterator::operator=(QMap<Key, T> &map)
|
---|
1149 |
|
---|
1150 | Makes the iterator operate on \a map. The iterator is set to be
|
---|
1151 | at the front of the map (before the first item).
|
---|
1152 |
|
---|
1153 | \sa toFront(), toBack()
|
---|
1154 | */
|
---|
1155 |
|
---|
1156 | /*! \fn QHashIterator &QHashIterator::operator=(const QHash<Key, T> &hash)
|
---|
1157 | \fn QMutableHashIterator &QMutableHashIterator::operator=(QHash<Key, T> &hash)
|
---|
1158 |
|
---|
1159 | Makes the iterator operate on \a hash. The iterator is set to be
|
---|
1160 | at the front of the hash (before the first item).
|
---|
1161 |
|
---|
1162 | \sa toFront(), toBack()
|
---|
1163 | */
|
---|
1164 |
|
---|
1165 | /*! \fn void QMapIterator::toFront()
|
---|
1166 | \fn void QHashIterator::toFront()
|
---|
1167 | \fn void QMutableMapIterator::toFront()
|
---|
1168 | \fn void QMutableHashIterator::toFront()
|
---|
1169 |
|
---|
1170 | Moves the iterator to the front of the container (before the
|
---|
1171 | first item).
|
---|
1172 |
|
---|
1173 | \sa toBack(), next()
|
---|
1174 | */
|
---|
1175 |
|
---|
1176 | /*! \fn void QMapIterator::toBack()
|
---|
1177 | \fn void QHashIterator::toBack()
|
---|
1178 | \fn void QMutableMapIterator::toBack()
|
---|
1179 | \fn void QMutableHashIterator::toBack()
|
---|
1180 |
|
---|
1181 | Moves the iterator to the back of the container (after the last
|
---|
1182 | item).
|
---|
1183 |
|
---|
1184 | \sa toFront(), previous()
|
---|
1185 | */
|
---|
1186 |
|
---|
1187 | /*! \fn bool QMapIterator::hasNext() const
|
---|
1188 | \fn bool QHashIterator::hasNext() const
|
---|
1189 | \fn bool QMutableMapIterator::hasNext() const
|
---|
1190 | \fn bool QMutableHashIterator::hasNext() const
|
---|
1191 |
|
---|
1192 | Returns true if there is at least one item ahead of the iterator,
|
---|
1193 | i.e. the iterator is \e not at the back of the container;
|
---|
1194 | otherwise returns false.
|
---|
1195 |
|
---|
1196 | \sa hasPrevious(), next()
|
---|
1197 | */
|
---|
1198 |
|
---|
1199 | /*! \fn QMapIterator::Item QMapIterator::next()
|
---|
1200 | \fn QHashIterator::Item QHashIterator::next()
|
---|
1201 |
|
---|
1202 | Returns the next item and advances the iterator by one position.
|
---|
1203 |
|
---|
1204 | Call key() on the return value to obtain the item's key, and
|
---|
1205 | value() to obtain the value.
|
---|
1206 |
|
---|
1207 | Calling this function on an iterator located at the back of the
|
---|
1208 | container leads to undefined results.
|
---|
1209 |
|
---|
1210 | \sa hasNext(), peekNext(), previous()
|
---|
1211 | */
|
---|
1212 |
|
---|
1213 | /*! \fn QMutableMapIterator::Item QMutableMapIterator::next()
|
---|
1214 | \fn QMutableHashIterator::Item QMutableHashIterator::next()
|
---|
1215 |
|
---|
1216 | Returns the next item and advances the iterator by one position.
|
---|
1217 |
|
---|
1218 | Call key() on the return value to obtain the item's key, and
|
---|
1219 | value() to obtain the value.
|
---|
1220 |
|
---|
1221 | Calling this function on an iterator located at the back of the
|
---|
1222 | container leads to undefined results.
|
---|
1223 |
|
---|
1224 | \sa hasNext(), peekNext(), previous()
|
---|
1225 | */
|
---|
1226 |
|
---|
1227 | /*! \fn QMapIterator::Item QMapIterator::peekNext() const
|
---|
1228 | \fn QHashIterator::Item QHashIterator::peekNext() const
|
---|
1229 |
|
---|
1230 | Returns the next item without moving the iterator.
|
---|
1231 |
|
---|
1232 | Call key() on the return value to obtain the item's key, and
|
---|
1233 | value() to obtain the value.
|
---|
1234 |
|
---|
1235 | Calling this function on an iterator located at the back of the
|
---|
1236 | container leads to undefined results.
|
---|
1237 |
|
---|
1238 | \sa hasNext(), next(), peekPrevious()
|
---|
1239 | */
|
---|
1240 |
|
---|
1241 | /*! \fn QMutableMapIterator::Item QMutableMapIterator::peekNext() const
|
---|
1242 | \fn QMutableHashIterator::Item QMutableHashIterator::peekNext() const
|
---|
1243 |
|
---|
1244 | Returns a reference to the next item without moving the iterator.
|
---|
1245 |
|
---|
1246 | Call key() on the return value to obtain the item's key, and
|
---|
1247 | value() to obtain the value.
|
---|
1248 |
|
---|
1249 | Calling this function on an iterator located at the back of the
|
---|
1250 | container leads to undefined results.
|
---|
1251 |
|
---|
1252 | \sa hasNext(), next(), peekPrevious()
|
---|
1253 | */
|
---|
1254 |
|
---|
1255 | /*! \fn bool QMapIterator::hasPrevious() const
|
---|
1256 | \fn bool QHashIterator::hasPrevious() const
|
---|
1257 | \fn bool QMutableMapIterator::hasPrevious() const
|
---|
1258 | \fn bool QMutableHashIterator::hasPrevious() const
|
---|
1259 |
|
---|
1260 | Returns true if there is at least one item behind the iterator,
|
---|
1261 | i.e. the iterator is \e not at the front of the container;
|
---|
1262 | otherwise returns false.
|
---|
1263 |
|
---|
1264 | \sa hasNext(), previous()
|
---|
1265 | */
|
---|
1266 |
|
---|
1267 | /*! \fn QMapIterator::Item QMapIterator::previous()
|
---|
1268 | \fn QHashIterator::Item QHashIterator::previous()
|
---|
1269 |
|
---|
1270 | Returns the previous item and moves the iterator back by one
|
---|
1271 | position.
|
---|
1272 |
|
---|
1273 | Call key() on the return value to obtain the item's key, and
|
---|
1274 | value() to obtain the value.
|
---|
1275 |
|
---|
1276 | Calling this function on an iterator located at the front of the
|
---|
1277 | container leads to undefined results.
|
---|
1278 |
|
---|
1279 | \sa hasPrevious(), peekPrevious(), next()
|
---|
1280 | */
|
---|
1281 |
|
---|
1282 | /*! \fn QMutableMapIterator::Item QMutableMapIterator::previous()
|
---|
1283 | \fn QMutableHashIterator::Item QMutableHashIterator::previous()
|
---|
1284 |
|
---|
1285 | Returns the previous item and moves the iterator back by one
|
---|
1286 | position.
|
---|
1287 |
|
---|
1288 | Call key() on the return value to obtain the item's key, and
|
---|
1289 | value() to obtain the value.
|
---|
1290 |
|
---|
1291 | Calling this function on an iterator located at the front of the
|
---|
1292 | container leads to undefined results.
|
---|
1293 |
|
---|
1294 | \sa hasPrevious(), peekPrevious(), next()
|
---|
1295 | */
|
---|
1296 |
|
---|
1297 | /*! \fn QMapIterator::Item QMapIterator::peekPrevious() const
|
---|
1298 | \fn QHashIterator::Item QHashIterator::peekPrevious() const
|
---|
1299 |
|
---|
1300 | Returns the previous item without moving the iterator.
|
---|
1301 |
|
---|
1302 | Call key() on the return value to obtain the item's key, and
|
---|
1303 | value() to obtain the value.
|
---|
1304 |
|
---|
1305 | Calling this function on an iterator located at the front of the
|
---|
1306 | container leads to undefined results.
|
---|
1307 |
|
---|
1308 | \sa hasPrevious(), previous(), peekNext()
|
---|
1309 | */
|
---|
1310 |
|
---|
1311 | /*! \fn QMutableMapIterator::Item QMutableMapIterator::peekPrevious() const
|
---|
1312 | \fn QMutableHashIterator::Item QMutableHashIterator::peekPrevious() const
|
---|
1313 |
|
---|
1314 | Returns the previous item without moving the iterator.
|
---|
1315 |
|
---|
1316 | Call key() on the return value to obtain the item's key, and
|
---|
1317 | value() to obtain the value.
|
---|
1318 |
|
---|
1319 | Calling this function on an iterator located at the front of the
|
---|
1320 | container leads to undefined results.
|
---|
1321 |
|
---|
1322 | \sa hasPrevious(), previous(), peekNext()
|
---|
1323 | */
|
---|
1324 |
|
---|
1325 | /*! \fn const T &QMapIterator::value() const
|
---|
1326 | \fn const T &QHashIterator::value() const
|
---|
1327 |
|
---|
1328 | Returns the value of the last item that was jumped over using one
|
---|
1329 | of the traversal functions (next(), previous(), findNext(),
|
---|
1330 | findPrevious()).
|
---|
1331 |
|
---|
1332 | After a call to next() or findNext(), value() is
|
---|
1333 | equivalent to peekPrevious().value(). After a call to previous()
|
---|
1334 | or findPrevious(), value() is equivalent to peekNext().value().
|
---|
1335 |
|
---|
1336 | \sa key()
|
---|
1337 | */
|
---|
1338 |
|
---|
1339 | /*!
|
---|
1340 | \fn const T &QMutableMapIterator::value() const
|
---|
1341 | \fn const T &QMutableHashIterator::value() const
|
---|
1342 |
|
---|
1343 | Returns the value of the last item that was jumped over using one
|
---|
1344 | of the traversal functions (next(), previous(), findNext(),
|
---|
1345 | findPrevious()).
|
---|
1346 |
|
---|
1347 | After a call to next() or findNext(), value() is
|
---|
1348 | equivalent to peekPrevious().value(). After a call to previous()
|
---|
1349 | or findPrevious(), value() is equivalent to peekNext().value().
|
---|
1350 |
|
---|
1351 | \sa key(), setValue()
|
---|
1352 | */
|
---|
1353 |
|
---|
1354 | /*!
|
---|
1355 | \fn T &QMutableMapIterator::value()
|
---|
1356 | \fn T &QMutableHashIterator::value()
|
---|
1357 | \overload
|
---|
1358 |
|
---|
1359 | Returns a non-const reference to the value of
|
---|
1360 | the last item that was jumped over using one
|
---|
1361 | of the traversal functions.
|
---|
1362 | */
|
---|
1363 |
|
---|
1364 | /*! \fn const Key &QMapIterator::key() const
|
---|
1365 | \fn const Key &QHashIterator::key() const
|
---|
1366 | \fn const Key &QMutableMapIterator::key() const
|
---|
1367 | \fn const Key &QMutableHashIterator::key() const
|
---|
1368 |
|
---|
1369 | Returns the key of the last item that was jumped over using one
|
---|
1370 | of the traversal functions (next(), previous(), findNext(),
|
---|
1371 | findPrevious()).
|
---|
1372 |
|
---|
1373 | After a call to next() or findNext(), key() is
|
---|
1374 | equivalent to peekPrevious().key(). After a call to previous() or
|
---|
1375 | findPrevious(), key() is equivalent to peekNext().key().
|
---|
1376 |
|
---|
1377 | \sa value()
|
---|
1378 | */
|
---|
1379 |
|
---|
1380 | /*! \fn bool QMapIterator::findNext(const T &value)
|
---|
1381 | \fn bool QHashIterator::findNext(const T &value)
|
---|
1382 | \fn bool QMutableMapIterator::findNext(const T &value)
|
---|
1383 | \fn bool QMutableHashIterator::findNext(const T &value)
|
---|
1384 |
|
---|
1385 | Searches for \a value starting from the current iterator position
|
---|
1386 | forward. Returns true if a (key, value) pair with value \a value
|
---|
1387 | is found; otherwise returns false.
|
---|
1388 |
|
---|
1389 | After the call, if \a value was found, the iterator is positioned
|
---|
1390 | just after the matching item; otherwise, the iterator is
|
---|
1391 | positioned at the back of the container.
|
---|
1392 |
|
---|
1393 | \sa findPrevious()
|
---|
1394 | */
|
---|
1395 |
|
---|
1396 | /*! \fn bool QMapIterator::findPrevious(const T &value)
|
---|
1397 | \fn bool QHashIterator::findPrevious(const T &value)
|
---|
1398 | \fn bool QMutableMapIterator::findPrevious(const T &value)
|
---|
1399 | \fn bool QMutableHashIterator::findPrevious(const T &value)
|
---|
1400 |
|
---|
1401 | Searches for \a value starting from the current iterator position
|
---|
1402 | backward. Returns true if a (key, value) pair with value \a value
|
---|
1403 | is found; otherwise returns false.
|
---|
1404 |
|
---|
1405 | After the call, if \a value was found, the iterator is positioned
|
---|
1406 | just before the matching item; otherwise, the iterator is
|
---|
1407 | positioned at the front of the container.
|
---|
1408 |
|
---|
1409 | \sa findNext()
|
---|
1410 | */
|
---|
1411 |
|
---|
1412 | /*! \fn void QMutableMapIterator::remove()
|
---|
1413 | \fn void QMutableHashIterator::remove()
|
---|
1414 |
|
---|
1415 | Removes the last item that was jumped over using one of the
|
---|
1416 | traversal functions (next(), previous(), findNext(), findPrevious()).
|
---|
1417 |
|
---|
1418 | \sa setValue()
|
---|
1419 | */
|
---|
1420 |
|
---|
1421 | /*! \fn void QMutableMapIterator::setValue(const T &value)
|
---|
1422 | \fn void QMutableHashIterator::setValue(const T &value)
|
---|
1423 |
|
---|
1424 | Replaces the value of the last item that was jumped over using
|
---|
1425 | one of the traversal functions with \a value.
|
---|
1426 |
|
---|
1427 | The traversal functions are next(), previous(), findNext(), and
|
---|
1428 | findPrevious().
|
---|
1429 |
|
---|
1430 | \sa key(), value(), remove()
|
---|
1431 | */
|
---|