~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/corelib/doc/snippets/code/doc_src_qiterator.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the documentation of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:BSD$
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
14
**   * Redistributions of source code must retain the above copyright
 
15
**     notice, this list of conditions and the following disclaimer.
 
16
**   * Redistributions in binary form must reproduce the above copyright
 
17
**     notice, this list of conditions and the following disclaimer in
 
18
**     the documentation and/or other materials provided with the
 
19
**     distribution.
 
20
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
 
21
**     of its contributors may be used to endorse or promote products derived
 
22
**     from this software without specific prior written permission.
 
23
**
 
24
**
 
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 
36
**
 
37
** $QT_END_LICENSE$
 
38
**
 
39
****************************************************************************/
 
40
 
 
41
//! [0]
 
42
QList<float> list;
 
43
...
 
44
QListIterator<float> i(list);
 
45
while (i.hasNext())
 
46
    qDebug() << i.next();
 
47
//! [0]
 
48
 
 
49
 
 
50
//! [1]
 
51
QListIterator<float> i(list);
 
52
i.toBack();
 
53
while (i.hasPrevious())
 
54
    qDebug() << i.previous();
 
55
//! [1]
 
56
 
 
57
 
 
58
//! [2]
 
59
QLinkedList<float> list;
 
60
...
 
61
QLinkedListIterator<float> i(list);
 
62
while (i.hasNext())
 
63
    qDebug() << i.next();
 
64
//! [2]
 
65
 
 
66
 
 
67
//! [3]
 
68
QLinkedListIterator<float> i(list);
 
69
i.toBack();
 
70
while (i.hasPrevious())
 
71
    qDebug() << i.previous();
 
72
//! [3]
 
73
 
 
74
 
 
75
//! [4]
 
76
QVector<float> vector;
 
77
...
 
78
QVectorIterator<float> i(vector);
 
79
while (i.hasNext())
 
80
    qDebug() << i.next();
 
81
//! [4]
 
82
 
 
83
 
 
84
//! [5]
 
85
QVectorIterator<float> i(vector);
 
86
i.toBack();
 
87
while (i.hasPrevious())
 
88
    qDebug() << i.previous();
 
89
//! [5]
 
90
 
 
91
 
 
92
//! [6]
 
93
QSet<QString> set;
 
94
...
 
95
QSetIterator<QString> i(set);
 
96
while (i.hasNext())
 
97
    qDebug() << i.next();
 
98
//! [6]
 
99
 
 
100
 
 
101
//! [7]
 
102
QSetIterator<QString> i(set);
 
103
i.toBack();
 
104
while (i.hasPrevious())
 
105
    qDebug() << i.previous();
 
106
//! [7]
 
107
 
 
108
 
 
109
//! [8]
 
110
QList<float> list;
 
111
...
 
112
QMutableListIterator<float> i(list);
 
113
while (i.hasNext())
 
114
    qDebug() << i.next();
 
115
//! [8]
 
116
 
 
117
 
 
118
//! [9]
 
119
QMutableListIterator<float> i(list);
 
120
i.toBack();
 
121
while (i.hasPrevious())
 
122
    qDebug() << i.previous();
 
123
//! [9]
 
124
 
 
125
 
 
126
//! [10]
 
127
QMutableListIterator<int> i(list);
 
128
while (i.hasNext()) {
 
129
    int val = i.next();
 
130
    if (val < 0) {
 
131
        i.setValue(-val);
 
132
    } else if (val == 0) {
 
133
        i.remove();
 
134
    }
 
135
}
 
136
//! [10]
 
137
 
 
138
 
 
139
//! [11]
 
140
QLinkedList<float> list;
 
141
...
 
142
QMutableLinkedListIterator<float> i(list);
 
143
while (i.hasNext())
 
144
    qDebug() << i.next();
 
145
//! [11]
 
146
 
 
147
 
 
148
//! [12]
 
149
QMutableLinkedListIterator<float> i(list);
 
150
i.toBack();
 
151
while (i.hasPrevious())
 
152
    qDebug() << i.previous();
 
153
//! [12]
 
154
 
 
155
 
 
156
//! [13]
 
157
QMutableLinkedListIterator<int> i(list);
 
158
while (i.hasNext()) {
 
159
    int val = i.next();
 
160
    if (val < 0) {
 
161
        i.setValue(-val);
 
162
    } else if (val == 0) {
 
163
        i.remove();
 
164
    }
 
165
}
 
166
//! [13]
 
167
 
 
168
 
 
169
//! [14]
 
170
QVector<float> vector;
 
171
...
 
172
QMutableVectorIterator<float> i(vector);
 
173
while (i.hasNext())
 
174
    qDebug() << i.next();
 
175
//! [14]
 
176
 
 
177
 
 
178
//! [15]
 
179
QMutableVectorIterator<float> i(vector);
 
180
i.toBack();
 
181
while (i.hasPrevious())
 
182
    qDebug() << i.previous();
 
183
//! [15]
 
184
 
 
185
 
 
186
//! [16]
 
187
QMutableVectorIterator<int> i(vector);
 
188
while (i.hasNext()) {
 
189
    int val = i.next();
 
190
    if (val < 0) {
 
191
        i.setValue(-val);
 
192
    } else if (val == 0) {
 
193
        i.remove();
 
194
    }
 
195
}
 
196
//! [16]
 
197
 
 
198
 
 
199
//! [17]
 
200
QSet<float> set;
 
201
...
 
202
QMutableSetIterator<float> i(set);
 
203
while (i.hasNext())
 
204
    qDebug() << i.next();
 
205
//! [17]
 
206
 
 
207
 
 
208
//! [18]
 
209
QMutableSetIterator<float> i(set);
 
210
i.toBack();
 
211
while (i.hasPrevious())
 
212
    qDebug() << i.previous();
 
213
//! [18]
 
214
 
 
215
 
 
216
//! [19]
 
217
QMutableListIterator<int> i(list);
 
218
while (i.hasNext()) {
 
219
    int val = i.next();
 
220
    if (val < -32768 || val > 32767)
 
221
        i.remove();
 
222
}
 
223
//! [19]
 
224
 
 
225
 
 
226
//! [20]
 
227
QMutableLinkedListIterator<int> i(list);
 
228
while (i.hasNext()) {
 
229
    int val = i.next();
 
230
    if (val < -32768 || val > 32767)
 
231
        i.remove();
 
232
}
 
233
//! [20]
 
234
 
 
235
 
 
236
//! [21]
 
237
QMutableVectorIterator<int> i(vector);
 
238
while (i.hasNext()) {
 
239
    int val = i.next();
 
240
    if (val < -32768 || val > 32767)
 
241
        i.remove();
 
242
}
 
243
//! [21]
 
244
 
 
245
 
 
246
//! [22]
 
247
QMutableSetIterator<int> i(set);
 
248
while (i.hasNext()) {
 
249
    int val = i.next();
 
250
    if (val < -32768 || val > 32767)
 
251
        i.remove();
 
252
}
 
253
//! [22]
 
254
 
 
255
 
 
256
//! [23]
 
257
QMutableListIterator<double> i(list);
 
258
while (i.hasNext()) {
 
259
    double val = i.next();
 
260
    i.setValue(sqrt(val));
 
261
}
 
262
//! [23]
 
263
 
 
264
 
 
265
//! [24]
 
266
QMutableLinkedListIterator<double> i(list);
 
267
while (i.hasNext()) {
 
268
    double val = i.next();
 
269
    i.setValue(sqrt(val));
 
270
}
 
271
//! [24]
 
272
 
 
273
 
 
274
//! [25]
 
275
QMutableVectorIterator<double> i(list);
 
276
while (i.hasNext()) {
 
277
    double val = i.next();
 
278
    i.setValue(sqrt(val));
 
279
}
 
280
//! [25]
 
281
 
 
282
 
 
283
//! [26]
 
284
QMap<int, QWidget *> map;
 
285
...
 
286
QMapIterator<int, QWidget *> i(map);
 
287
while (i.hasNext()) {
 
288
    i.next();
 
289
    qDebug() << i.key() << ": " << i.value();
 
290
}
 
291
//! [26]
 
292
 
 
293
 
 
294
//! [27]
 
295
QMapIterator<int, QWidget *> i(map);
 
296
i.toBack();
 
297
while (i.hasPrevious()) {
 
298
    i.previous();
 
299
    qDebug() << i.key() << ": " << i.value();
 
300
}
 
301
//! [27]
 
302
 
 
303
 
 
304
//! [28]
 
305
QMapIterator<int, QWidget *> i(map);
 
306
while (i.findNext(widget)) {
 
307
    qDebug() << "Found widget " << widget << " under key "
 
308
             << i.key();
 
309
}
 
310
//! [28]
 
311
 
 
312
 
 
313
//! [29]
 
314
QHash<int, QWidget *> hash;
 
315
...
 
316
QHashIterator<int, QWidget *> i(hash);
 
317
while (i.hasNext()) {
 
318
    i.next();
 
319
    qDebug() << i.key() << ": " << i.value();
 
320
}
 
321
//! [29]
 
322
 
 
323
 
 
324
//! [30]
 
325
QHashIterator<int, QWidget *> i(hash);
 
326
i.toBack();
 
327
while (i.hasPrevious()) {
 
328
    i.previous();
 
329
    qDebug() << i.key() << ": " << i.value();
 
330
}
 
331
//! [30]
 
332
 
 
333
 
 
334
//! [31]
 
335
QHashIterator<int, QWidget *> i(hash);
 
336
while (i.findNext(widget)) {
 
337
    qDebug() << "Found widget " << widget << " under key "
 
338
             << i.key();
 
339
}
 
340
//! [31]
 
341
 
 
342
 
 
343
//! [32]
 
344
QMap<int, QWidget *> map;
 
345
...
 
346
QMutableMapIterator<int, QWidget *> i(map);
 
347
while (i.hasNext()) {
 
348
    i.next();
 
349
    qDebug() << i.key() << ": " << i.value();
 
350
}
 
351
//! [32]
 
352
 
 
353
 
 
354
//! [33]
 
355
QMutableMapIterator<int, QWidget *> i(map);
 
356
i.toBack();
 
357
while (i.hasPrevious()) {
 
358
    i.previous();
 
359
    qDebug() << i.key() << ": " << i.value();
 
360
}
 
361
//! [33]
 
362
 
 
363
 
 
364
//! [34]
 
365
QMutableMapIterator<int, QWidget *> i(map);
 
366
while (i.findNext(widget)) {
 
367
    qDebug() << "Found widget " << widget << " under key "
 
368
             << i.key();
 
369
}
 
370
//! [34]
 
371
 
 
372
 
 
373
//! [35]
 
374
QMutableMapIterator<QString, QString> i(map);
 
375
while (i.hasNext()) {
 
376
    i.next();
 
377
    if (i.key() == i.value())
 
378
        i.remove();
 
379
}
 
380
//! [35]
 
381
 
 
382
 
 
383
//! [36]
 
384
QHash<int, QWidget *> hash;
 
385
...
 
386
QMutableHashIterator<QString, QWidget *> i(hash);
 
387
while (i.hasNext()) {
 
388
    i.next();
 
389
    qDebug() << i.key() << ": " << i.value();
 
390
}
 
391
//! [36]
 
392
 
 
393
 
 
394
//! [37]
 
395
QMutableHashIterator<int, QWidget *> i(hash);
 
396
i.toBack();
 
397
while (i.hasPrevious()) {
 
398
    i.previous();
 
399
    qDebug() << i.key() << ": " << i.value();
 
400
}
 
401
//! [37]
 
402
 
 
403
 
 
404
//! [38]
 
405
QMutableHashIterator<int, QWidget *> i(hash);
 
406
while (i.findNext(widget)) {
 
407
    qDebug() << "Found widget " << widget << " under key "
 
408
             << i.key();
 
409
}
 
410
//! [38]
 
411
 
 
412
 
 
413
//! [39]
 
414
QMutableHashIterator<QString, QString> i(hash);
 
415
while (i.hasNext()) {
 
416
    i.next();
 
417
    if (i.key() == i.value())
 
418
        i.remove();
 
419
}
 
420
//! [39]