1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 | //! [0]
|
---|
42 | class Employee
|
---|
43 | {
|
---|
44 | public:
|
---|
45 | Employee() {}
|
---|
46 | Employee(const Employee &other);
|
---|
47 |
|
---|
48 | Employee &operator=(const Employee &other);
|
---|
49 |
|
---|
50 | private:
|
---|
51 | QString myName;
|
---|
52 | QDate myDateOfBirth;
|
---|
53 | };
|
---|
54 | //! [0]
|
---|
55 |
|
---|
56 |
|
---|
57 | //! [1]
|
---|
58 | QList<QString> list;
|
---|
59 | list << "A" << "B" << "C" << "D";
|
---|
60 |
|
---|
61 | QListIterator<QString> i(list);
|
---|
62 | while (i.hasNext())
|
---|
63 | qDebug() << i.next();
|
---|
64 | //! [1]
|
---|
65 |
|
---|
66 |
|
---|
67 | //! [2]
|
---|
68 | QListIterator<QString> i(list);
|
---|
69 | i.toBack();
|
---|
70 | while (i.hasPrevious())
|
---|
71 | qDebug() << i.previous();
|
---|
72 | //! [2]
|
---|
73 |
|
---|
74 |
|
---|
75 | //! [3]
|
---|
76 | QMutableListIterator<int> i(list);
|
---|
77 | while (i.hasNext()) {
|
---|
78 | if (i.next() % 2 != 0)
|
---|
79 | i.remove();
|
---|
80 | }
|
---|
81 | //! [3]
|
---|
82 |
|
---|
83 |
|
---|
84 | //! [4]
|
---|
85 | QMutableListIterator<int> i(list);
|
---|
86 | i.toBack();
|
---|
87 | while (i.hasPrevious()) {
|
---|
88 | if (i.previous() % 2 != 0)
|
---|
89 | i.remove();
|
---|
90 | }
|
---|
91 | //! [4]
|
---|
92 |
|
---|
93 |
|
---|
94 | //! [5]
|
---|
95 | QMutableListIterator<int> i(list);
|
---|
96 | while (i.hasNext()) {
|
---|
97 | if (i.next() > 128)
|
---|
98 | i.setValue(128);
|
---|
99 | }
|
---|
100 | //! [5]
|
---|
101 |
|
---|
102 |
|
---|
103 | //! [6]
|
---|
104 | QMutableListIterator<int> i(list);
|
---|
105 | while (i.hasNext())
|
---|
106 | i.next() *= 2;
|
---|
107 | //! [6]
|
---|
108 |
|
---|
109 |
|
---|
110 | //! [7]
|
---|
111 | QMap<QString, QString> map;
|
---|
112 | map.insert("Paris", "France");
|
---|
113 | map.insert("Guatemala City", "Guatemala");
|
---|
114 | map.insert("Mexico City", "Mexico");
|
---|
115 | map.insert("Moscow", "Russia");
|
---|
116 | ...
|
---|
117 |
|
---|
118 | QMutableMapIterator<QString, QString> i(map);
|
---|
119 | while (i.hasNext()) {
|
---|
120 | if (i.next().key().endsWith("City"))
|
---|
121 | i.remove();
|
---|
122 | }
|
---|
123 | //! [7]
|
---|
124 |
|
---|
125 |
|
---|
126 | //! [8]
|
---|
127 | QMap<int, QWidget *> map;
|
---|
128 | QHash<int, QWidget *> hash;
|
---|
129 |
|
---|
130 | QMapIterator<int, QWidget *> i(map);
|
---|
131 | while (i.hasNext()) {
|
---|
132 | i.next();
|
---|
133 | hash.insert(i.key(), i.value());
|
---|
134 | }
|
---|
135 | //! [8]
|
---|
136 |
|
---|
137 |
|
---|
138 | //! [9]
|
---|
139 | QMutableMapIterator<int, QWidget *> i(map);
|
---|
140 | while (i.findNext(widget))
|
---|
141 | i.remove();
|
---|
142 | //! [9]
|
---|
143 |
|
---|
144 |
|
---|
145 | //! [10]
|
---|
146 | QList<QString> list;
|
---|
147 | list << "A" << "B" << "C" << "D";
|
---|
148 |
|
---|
149 | QList<QString>::iterator i;
|
---|
150 | for (i = list.begin(); i != list.end(); ++i)
|
---|
151 | *i = (*i).toLower();
|
---|
152 | //! [10]
|
---|
153 |
|
---|
154 |
|
---|
155 | //! [11]
|
---|
156 | QList<QString> list;
|
---|
157 | list << "A" << "B" << "C" << "D";
|
---|
158 |
|
---|
159 | QList<QString>::iterator i = list.end();
|
---|
160 | while (i != list.begin()) {
|
---|
161 | --i;
|
---|
162 | *i = (*i).toLower();
|
---|
163 | }
|
---|
164 | //! [11]
|
---|
165 |
|
---|
166 |
|
---|
167 | //! [12]
|
---|
168 | QList<QString>::const_iterator i;
|
---|
169 | for (i = list.constBegin(); i != list.constEnd(); ++i)
|
---|
170 | qDebug() << *i;
|
---|
171 | //! [12]
|
---|
172 |
|
---|
173 |
|
---|
174 | //! [13]
|
---|
175 | QMap<int, int> map;
|
---|
176 | ...
|
---|
177 | QMap<int, int>::const_iterator i;
|
---|
178 | for (i = map.constBegin(); i != map.constEnd(); ++i)
|
---|
179 | qDebug() << i.key() << ":" << i.value();
|
---|
180 | //! [13]
|
---|
181 |
|
---|
182 |
|
---|
183 | //! [14]
|
---|
184 | // RIGHT
|
---|
185 | const QList<int> sizes = splitter->sizes();
|
---|
186 | QList<int>::const_iterator i;
|
---|
187 | for (i = sizes.begin(); i != sizes.end(); ++i)
|
---|
188 | ...
|
---|
189 |
|
---|
190 | // WRONG
|
---|
191 | QList<int>::const_iterator i;
|
---|
192 | for (i = splitter->sizes().begin();
|
---|
193 | i != splitter->sizes().end(); ++i)
|
---|
194 | ...
|
---|
195 | //! [14]
|
---|
196 |
|
---|
197 |
|
---|
198 | //! [15]
|
---|
199 | QLinkedList<QString> list;
|
---|
200 | ...
|
---|
201 | QString str;
|
---|
202 | foreach (str, list)
|
---|
203 | qDebug() << str;
|
---|
204 | //! [15]
|
---|
205 |
|
---|
206 |
|
---|
207 | //! [16]
|
---|
208 | QLinkedList<QString> list;
|
---|
209 | ...
|
---|
210 | QLinkedListIterator<QString> i(list);
|
---|
211 | while (i.hasNext())
|
---|
212 | qDebug() << i.next();
|
---|
213 | //! [16]
|
---|
214 |
|
---|
215 |
|
---|
216 | //! [17]
|
---|
217 | QLinkedList<QString> list;
|
---|
218 | ...
|
---|
219 | foreach (const QString &str, list)
|
---|
220 | qDebug() << str;
|
---|
221 | //! [17]
|
---|
222 |
|
---|
223 |
|
---|
224 | //! [18]
|
---|
225 | QLinkedList<QString> list;
|
---|
226 | ...
|
---|
227 | foreach (const QString &str, list) {
|
---|
228 | if (str.isEmpty())
|
---|
229 | break;
|
---|
230 | qDebug() << str;
|
---|
231 | }
|
---|
232 | //! [18]
|
---|
233 |
|
---|
234 |
|
---|
235 | //! [19]
|
---|
236 | QMap<QString, int> map;
|
---|
237 | ...
|
---|
238 | foreach (const QString &str, map.keys())
|
---|
239 | qDebug() << str << ":" << map.value(str);
|
---|
240 | //! [19]
|
---|
241 |
|
---|
242 |
|
---|
243 | //! [20]
|
---|
244 | QMultiMap<QString, int> map;
|
---|
245 | ...
|
---|
246 | foreach (const QString &str, map.uniqueKeys()) {
|
---|
247 | foreach (int i, map.values(str))
|
---|
248 | qDebug() << str << ":" << i;
|
---|
249 | }
|
---|
250 | //! [20]
|
---|
251 |
|
---|
252 |
|
---|
253 | //! [21]
|
---|
254 | forever {
|
---|
255 | ...
|
---|
256 | }
|
---|
257 | //! [21]
|
---|
258 |
|
---|
259 |
|
---|
260 | //! [22]
|
---|
261 | CONFIG += no_keywords
|
---|
262 | //! [22]
|
---|
263 |
|
---|
264 |
|
---|
265 | //! [23]
|
---|
266 | QString onlyLetters(const QString &in)
|
---|
267 | {
|
---|
268 | QString out;
|
---|
269 | for (int j = 0; j < in.size(); ++j) {
|
---|
270 | if (in[j].isLetter())
|
---|
271 | out += in[j];
|
---|
272 | }
|
---|
273 | return out;
|
---|
274 | }
|
---|
275 | //! [23]
|
---|