1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29
30#include <QTreeWidget>
31#include <QTreeWidgetItemIterator>
32#include <QTest>
33
34Q_DECLARE_METATYPE(QTreeWidgetItemIterator::IteratorFlag)
35Q_DECLARE_METATYPE(QTreeWidgetItemIterator::IteratorFlags)
36
37class tst_QTreeWidgetItemIterator : public QObject
38{
39 Q_OBJECT
40
41public:
42 using QObject::QObject;
43
44private slots:
45 void initTestCase();
46 void cleanupTestCase();
47
48 void postincrement();
49 void preincrement();
50 void postdecrement();
51 void predecrement();
52 void plus_eq_data();
53 void plus_eq();
54 void minus_eq_data();
55 void minus_eq();
56 void iteratorflags_data();
57 void iteratorflags();
58 void updateIfModifiedFromWidget_data();
59 void updateIfModifiedFromWidget();
60 void constructIteratorWithItem_data();
61 void constructIteratorWithItem();
62 void updateIteratorAfterDeletedItem_and_ContinueIteration_data();
63 void updateIteratorAfterDeletedItem_and_ContinueIteration();
64 void initializeIterator();
65 void sortingEnabled();
66private:
67 QTreeWidget *testWidget = nullptr;
68};
69
70void tst_QTreeWidgetItemIterator::initTestCase()
71{
72 testWidget = new QTreeWidget();
73 testWidget->clear();
74 testWidget->setColumnCount(2);
75 testWidget->show();
76
77
78 /**
79 * These are default:
80 *
81 * Qt::ItemIsSelectable
82 * |Qt::ItemIsUserCheckable
83 * |Qt::ItemIsEnabled
84 * |Qt::ItemIsDragEnabled
85 * |Qt::ItemIsDropEnabled
86 *
87 */
88 for (int i = 0; i <= 16; ++i) {
89 QTreeWidgetItem *top = new QTreeWidgetItem(testWidget);
90 const QString topS = QLatin1String("top") + QString::number(i);
91 top->setText(column: 0, atext: topS);
92 switch (i) {
93 case 0: top->setHidden(true);break;
94 case 1: top->setHidden(false);break;
95
96 case 2: top->setSelected(true);break;
97 case 3: top->setSelected(false);break;
98
99 case 4: top->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);break;
100 case 5: top->setFlags(Qt::ItemIsEnabled);break;
101
102 case 6: top->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);break;
103 case 7: top->setFlags(Qt::ItemIsEnabled);break;
104
105 case 8: top->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);break;
106 case 9: top->setFlags(Qt::ItemIsEnabled);break;
107
108 case 10: top->setFlags(Qt::ItemIsEnabled);break;
109 case 11: top->setFlags({});break;
110
111 case 12: top->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);break;
112 case 13: top->setFlags(Qt::ItemIsEnabled);break;
113
114 case 14: top->setCheckState(column: 0, state: Qt::Checked);break;
115 case 15: top->setCheckState(column: 0, state: Qt::Unchecked);break;
116 case 16: top->setCheckState(column: 0, state: Qt::PartiallyChecked);break;
117 }
118 for (int j=0; j <= 16; ++j) {
119 QTreeWidgetItem *child = new QTreeWidgetItem(top);
120 child->setText(column: 0, atext: topS + QLatin1String(",child") + QString::number(j));
121 switch (j) {
122 case 0: child->setHidden(true);break;
123 case 1: child->setHidden(false);break;
124
125 case 2: child->setSelected(true);break;
126 case 3: child->setSelected(false);break;
127
128 case 4: child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);break;
129 case 5: child->setFlags(Qt::ItemIsEnabled);break;
130
131 case 6: child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);break;
132 case 7: child->setFlags(Qt::ItemIsEnabled);break;
133
134 case 8: child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);break;
135 case 9: child->setFlags(Qt::ItemIsEnabled);break;
136
137 case 10: child->setFlags(Qt::ItemIsEnabled);break;
138 case 11: child->setFlags({});break;
139
140 case 12: child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);break;
141 case 13: child->setFlags(Qt::ItemIsEnabled);break;
142
143 case 14: child->setCheckState(column: 0, state: Qt::Checked);break;
144 case 15: child->setCheckState(column: 0, state: Qt::Unchecked);break;
145 case 16: child->setCheckState(column: 0, state: Qt::PartiallyChecked);break;
146 }
147
148 }
149 }
150}
151
152void tst_QTreeWidgetItemIterator::cleanupTestCase()
153{
154 testWidget->hide();
155 delete testWidget;
156}
157
158void tst_QTreeWidgetItemIterator::iteratorflags_data()
159{
160 /*
161 // Should preferably test for all these flags (and combinations).....
162
163 All = 0x00000000,
164 Hidden = 0x00000001,
165 NotHidden = 0x00000002,
166 Selected = 0x00000004,
167 Unselected = 0x00000008,
168 Selectable = 0x00000010,
169 NotSelectable = 0x00000020,
170 DragEnabled = 0x00000040,
171 DragDisabled = 0x00000080,
172 DropEnabled = 0x00000100,
173 DropDisabled = 0x00000200,
174 HasChildren = 0x00000400,
175 NoChildren = 0x00000800,
176 Checked = 0x00001000,
177 NotChecked = 0x00002000,
178 Enabled = 0x00004000,
179 Disabled = 0x00008000,
180 Editable = 0x00010000,
181 NotEditable = 0x00020000
182*/
183 QTest::addColumn<int>(name: "start");
184 QTest::addColumn<QTreeWidgetItemIterator::IteratorFlags>(name: "iteratorflags");
185 QTest::addColumn<QStringList>(name: "matches");
186
187 QTest::newRow(dataTag: "Match all") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::All)
188 << (QStringList()
189 << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
190 << "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7"
191 << "top0,child8" << "top0,child9" << "top0,child10" << "top0,child11"
192 << "top0,child12" << "top0,child13" << "top0,child14" << "top0,child15"
193 << "top0,child16"
194 << "top1" << "top1,child0" << "top1,child1" << "top1,child2" << "top1,child3"
195 << "top1,child4" << "top1,child5" << "top1,child6" << "top1,child7"
196 << "top1,child8" << "top1,child9" << "top1,child10" << "top1,child11"
197 << "top1,child12" << "top1,child13" << "top1,child14" << "top1,child15"
198 << "top1,child16"
199 << "top2" << "top2,child0" << "top2,child1" << "top2,child2" << "top2,child3"
200 << "top2,child4" << "top2,child5" << "top2,child6" << "top2,child7"
201 << "top2,child8" << "top2,child9" << "top2,child10" << "top2,child11"
202 << "top2,child12" << "top2,child13" << "top2,child14" << "top2,child15"
203 << "top2,child16"
204 << "top3" << "top3,child0" << "top3,child1" << "top3,child2" << "top3,child3"
205 << "top3,child4" << "top3,child5" << "top3,child6" << "top3,child7"
206 << "top3,child8" << "top3,child9" << "top3,child10" << "top3,child11"
207 << "top3,child12" << "top3,child13" << "top3,child14" << "top3,child15"
208 << "top3,child16"
209 << "top4" << "top4,child0" << "top4,child1" << "top4,child2" << "top4,child3"
210 << "top4,child4" << "top4,child5" << "top4,child6" << "top4,child7"
211 << "top4,child8" << "top4,child9" << "top4,child10" << "top4,child11"
212 << "top4,child12" << "top4,child13" << "top4,child14" << "top4,child15"
213 << "top4,child16"
214 << "top5" << "top5,child0" << "top5,child1" << "top5,child2" << "top5,child3"
215 << "top5,child4" << "top5,child5" << "top5,child6" << "top5,child7"
216 << "top5,child8" << "top5,child9" << "top5,child10" << "top5,child11"
217 << "top5,child12" << "top5,child13" << "top5,child14" << "top5,child15"
218 << "top5,child16"
219 << "top6" << "top6,child0" << "top6,child1" << "top6,child2" << "top6,child3"
220 << "top6,child4" << "top6,child5" << "top6,child6" << "top6,child7"
221 << "top6,child8" << "top6,child9" << "top6,child10" << "top6,child11"
222 << "top6,child12" << "top6,child13" << "top6,child14" << "top6,child15"
223 << "top6,child16"
224 << "top7" << "top7,child0" << "top7,child1" << "top7,child2" << "top7,child3"
225 << "top7,child4" << "top7,child5" << "top7,child6" << "top7,child7"
226 << "top7,child8" << "top7,child9" << "top7,child10" << "top7,child11"
227 << "top7,child12" << "top7,child13" << "top7,child14" << "top7,child15"
228 << "top7,child16"
229 << "top8" << "top8,child0" << "top8,child1" << "top8,child2" << "top8,child3"
230 << "top8,child4" << "top8,child5" << "top8,child6" << "top8,child7"
231 << "top8,child8" << "top8,child9" << "top8,child10" << "top8,child11"
232 << "top8,child12" << "top8,child13" << "top8,child14" << "top8,child15"
233 << "top8,child16"
234 << "top9" << "top9,child0" << "top9,child1" << "top9,child2" << "top9,child3"
235 << "top9,child4" << "top9,child5" << "top9,child6" << "top9,child7"
236 << "top9,child8" << "top9,child9" << "top9,child10" << "top9,child11"
237 << "top9,child12" << "top9,child13" << "top9,child14" << "top9,child15"
238 << "top9,child16"
239 << "top10" << "top10,child0" << "top10,child1" << "top10,child2" << "top10,child3"
240 << "top10,child4" << "top10,child5" << "top10,child6" << "top10,child7"
241 << "top10,child8" << "top10,child9" << "top10,child10" << "top10,child11"
242 << "top10,child12" << "top10,child13" << "top10,child14" << "top10,child15"
243 << "top10,child16"
244 << "top11" << "top11,child0" << "top11,child1" << "top11,child2" << "top11,child3"
245 << "top11,child4" << "top11,child5" << "top11,child6" << "top11,child7"
246 << "top11,child8" << "top11,child9" << "top11,child10" << "top11,child11"
247 << "top11,child12" << "top11,child13" << "top11,child14" << "top11,child15"
248 << "top11,child16"
249 << "top12" << "top12,child0" << "top12,child1" << "top12,child2" << "top12,child3"
250 << "top12,child4" << "top12,child5" << "top12,child6" << "top12,child7"
251 << "top12,child8" << "top12,child9" << "top12,child10" << "top12,child11"
252 << "top12,child12" << "top12,child13" << "top12,child14" << "top12,child15"
253 << "top12,child16"
254 << "top13" << "top13,child0" << "top13,child1" << "top13,child2" << "top13,child3"
255 << "top13,child4" << "top13,child5" << "top13,child6" << "top13,child7"
256 << "top13,child8" << "top13,child9" << "top13,child10" << "top13,child11"
257 << "top13,child12" << "top13,child13" << "top13,child14" << "top13,child15"
258 << "top13,child16"
259 << "top14" << "top14,child0" << "top14,child1" << "top14,child2" << "top14,child3"
260 << "top14,child4" << "top14,child5" << "top14,child6" << "top14,child7"
261 << "top14,child8" << "top14,child9" << "top14,child10" << "top14,child11"
262 << "top14,child12" << "top14,child13" << "top14,child14" << "top14,child15"
263 << "top14,child16"
264 << "top15" << "top15,child0" << "top15,child1" << "top15,child2" << "top15,child3"
265 << "top15,child4" << "top15,child5" << "top15,child6" << "top15,child7"
266 << "top15,child8" << "top15,child9" << "top15,child10" << "top15,child11"
267 << "top15,child12" << "top15,child13" << "top15,child14" << "top15,child15"
268 << "top15,child16"
269 << "top16" << "top16,child0" << "top16,child1" << "top16,child2" << "top16,child3"
270 << "top16,child4" << "top16,child5" << "top16,child6" << "top16,child7"
271 << "top16,child8" << "top16,child9" << "top16,child10" << "top16,child11"
272 << "top16,child12" << "top16,child13" << "top16,child14" << "top16,child15"
273 << "top16,child16");
274
275 QTest::newRow(dataTag: "Match hidden") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Hidden)
276 << (QStringList()
277 << "top0" << "top0,child0" // fails due to hidden row
278 << "top1,child0"
279 << "top2,child0"
280 << "top3,child0"
281 << "top4,child0"
282 << "top5,child0"
283 << "top6,child0"
284 << "top7,child0"
285 << "top8,child0"
286 << "top9,child0"
287 << "top10,child0"
288 << "top11,child0"
289 << "top12,child0"
290 << "top13,child0"
291 << "top14,child0"
292 << "top15,child0"
293 << "top16,child0");
294
295 QTest::newRow(dataTag: "Match not hidden") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::NotHidden)
296 << (QStringList()
297 << "top0,child1" << "top0,child2" << "top0,child3"
298 << "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7"
299 << "top0,child8" << "top0,child9" << "top0,child10" << "top0,child11"
300 << "top0,child12" << "top0,child13" << "top0,child14" << "top0,child15"
301 << "top0,child16"
302 << "top1" << "top1,child1" << "top1,child2" << "top1,child3"
303 << "top1,child4" << "top1,child5" << "top1,child6" << "top1,child7"
304 << "top1,child8" << "top1,child9" << "top1,child10" << "top1,child11"
305 << "top1,child12" << "top1,child13" << "top1,child14" << "top1,child15"
306 << "top1,child16"
307 << "top2" << "top2,child1" << "top2,child2" << "top2,child3"
308 << "top2,child4" << "top2,child5" << "top2,child6" << "top2,child7"
309 << "top2,child8" << "top2,child9" << "top2,child10" << "top2,child11"
310 << "top2,child12" << "top2,child13" << "top2,child14" << "top2,child15"
311 << "top2,child16"
312 << "top3" << "top3,child1" << "top3,child2" << "top3,child3"
313 << "top3,child4" << "top3,child5" << "top3,child6" << "top3,child7"
314 << "top3,child8" << "top3,child9" << "top3,child10" << "top3,child11"
315 << "top3,child12" << "top3,child13" << "top3,child14" << "top3,child15"
316 << "top3,child16"
317 << "top4" << "top4,child1" << "top4,child2" << "top4,child3"
318 << "top4,child4" << "top4,child5" << "top4,child6" << "top4,child7"
319 << "top4,child8" << "top4,child9" << "top4,child10" << "top4,child11"
320 << "top4,child12" << "top4,child13" << "top4,child14" << "top4,child15"
321 << "top4,child16"
322 << "top5" << "top5,child1" << "top5,child2" << "top5,child3"
323 << "top5,child4" << "top5,child5" << "top5,child6" << "top5,child7"
324 << "top5,child8" << "top5,child9" << "top5,child10" << "top5,child11"
325 << "top5,child12" << "top5,child13" << "top5,child14" << "top5,child15"
326 << "top5,child16"
327 << "top6" << "top6,child1" << "top6,child2" << "top6,child3"
328 << "top6,child4" << "top6,child5" << "top6,child6" << "top6,child7"
329 << "top6,child8" << "top6,child9" << "top6,child10" << "top6,child11"
330 << "top6,child12" << "top6,child13" << "top6,child14" << "top6,child15"
331 << "top6,child16"
332 << "top7" << "top7,child1" << "top7,child2" << "top7,child3"
333 << "top7,child4" << "top7,child5" << "top7,child6" << "top7,child7"
334 << "top7,child8" << "top7,child9" << "top7,child10" << "top7,child11"
335 << "top7,child12" << "top7,child13" << "top7,child14" << "top7,child15"
336 << "top7,child16"
337 << "top8" << "top8,child1" << "top8,child2" << "top8,child3"
338 << "top8,child4" << "top8,child5" << "top8,child6" << "top8,child7"
339 << "top8,child8" << "top8,child9" << "top8,child10" << "top8,child11"
340 << "top8,child12" << "top8,child13" << "top8,child14" << "top8,child15"
341 << "top8,child16"
342 << "top9" << "top9,child1" << "top9,child2" << "top9,child3"
343 << "top9,child4" << "top9,child5" << "top9,child6" << "top9,child7"
344 << "top9,child8" << "top9,child9" << "top9,child10" << "top9,child11"
345 << "top9,child12" << "top9,child13" << "top9,child14" << "top9,child15"
346 << "top9,child16"
347 << "top10" << "top10,child1" << "top10,child2" << "top10,child3"
348 << "top10,child4" << "top10,child5" << "top10,child6" << "top10,child7"
349 << "top10,child8" << "top10,child9" << "top10,child10" << "top10,child11"
350 << "top10,child12" << "top10,child13" << "top10,child14" << "top10,child15"
351 << "top10,child16"
352 << "top11" << "top11,child1" << "top11,child2" << "top11,child3"
353 << "top11,child4" << "top11,child5" << "top11,child6" << "top11,child7"
354 << "top11,child8" << "top11,child9" << "top11,child10" << "top11,child11"
355 << "top11,child12" << "top11,child13" << "top11,child14" << "top11,child15"
356 << "top11,child16"
357 << "top12" << "top12,child1" << "top12,child2" << "top12,child3"
358 << "top12,child4" << "top12,child5" << "top12,child6" << "top12,child7"
359 << "top12,child8" << "top12,child9" << "top12,child10" << "top12,child11"
360 << "top12,child12" << "top12,child13" << "top12,child14" << "top12,child15"
361 << "top12,child16"
362 << "top13" << "top13,child1" << "top13,child2" << "top13,child3"
363 << "top13,child4" << "top13,child5" << "top13,child6" << "top13,child7"
364 << "top13,child8" << "top13,child9" << "top13,child10" << "top13,child11"
365 << "top13,child12" << "top13,child13" << "top13,child14" << "top13,child15"
366 << "top13,child16"
367 << "top14" << "top14,child1" << "top14,child2" << "top14,child3"
368 << "top14,child4" << "top14,child5" << "top14,child6" << "top14,child7"
369 << "top14,child8" << "top14,child9" << "top14,child10" << "top14,child11"
370 << "top14,child12" << "top14,child13" << "top14,child14" << "top14,child15"
371 << "top14,child16"
372 << "top15" << "top15,child1" << "top15,child2" << "top15,child3"
373 << "top15,child4" << "top15,child5" << "top15,child6" << "top15,child7"
374 << "top15,child8" << "top15,child9" << "top15,child10" << "top15,child11"
375 << "top15,child12" << "top15,child13" << "top15,child14" << "top15,child15"
376 << "top15,child16"
377 << "top16" << "top16,child1" << "top16,child2" << "top16,child3"
378 << "top16,child4" << "top16,child5" << "top16,child6" << "top16,child7"
379 << "top16,child8" << "top16,child9" << "top16,child10" << "top16,child11"
380 << "top16,child12" << "top16,child13" << "top16,child14" << "top16,child15"
381 << "top16,child16");
382
383 QTest::newRow(dataTag: "Match selected") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Selected)
384 << (QStringList()
385 << "top0,child2"
386 << "top1,child2"
387 << "top2" << "top2,child2"
388 << "top3,child2"
389 << "top4,child2"
390 << "top5,child2"
391 << "top6,child2"
392 << "top7,child2"
393 << "top8,child2"
394 << "top9,child2"
395 << "top10,child2"
396 << "top11,child2"
397 << "top12,child2"
398 << "top13,child2"
399 << "top14,child2"
400 << "top15,child2"
401 << "top16,child2");
402
403 QTest::newRow(dataTag: "Match selectable") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Selectable)
404 << (QStringList()
405 << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
406 << "top0,child4"
407 << "top0,child14" << "top0,child15"
408 << "top0,child16"
409 << "top1" << "top1,child0" << "top1,child1" << "top1,child2" << "top1,child3"
410 << "top1,child4"
411 << "top1,child14" << "top1,child15"
412 << "top1,child16"
413 << "top2" << "top2,child0" << "top2,child1" << "top2,child2" << "top2,child3"
414 << "top2,child4"
415 << "top2,child14" << "top2,child15"
416 << "top2,child16"
417 << "top3" << "top3,child0" << "top3,child1" << "top3,child2" << "top3,child3"
418 << "top3,child4"
419 << "top3,child14" << "top3,child15"
420 << "top3,child16"
421 << "top4" << "top4,child0" << "top4,child1" << "top4,child2" << "top4,child3"
422 << "top4,child4"
423 << "top4,child14" << "top4,child15"
424 << "top4,child16"
425 /* "top5"*/ << "top5,child0" << "top5,child1" << "top5,child2" << "top5,child3"
426 << "top5,child4"
427 << "top5,child14" << "top5,child15"
428 << "top5,child16"
429 /* "top6"*/ << "top6,child0" << "top6,child1" << "top6,child2" << "top6,child3"
430 << "top6,child4"
431 << "top6,child14" << "top6,child15"
432 << "top6,child16"
433 /* "top7"*/ << "top7,child0" << "top7,child1" << "top7,child2" << "top7,child3"
434 << "top7,child4"
435 << "top7,child14" << "top7,child15"
436 << "top7,child16"
437 /* "top8"*/ << "top8,child0" << "top8,child1" << "top8,child2" << "top8,child3"
438 << "top8,child4"
439 << "top8,child14" << "top8,child15"
440 << "top8,child16"
441 /* "top9"*/ << "top9,child0" << "top9,child1" << "top9,child2" << "top9,child3"
442 << "top9,child4"
443 << "top9,child14" << "top9,child15"
444 << "top9,child16"
445 /* "top10*/ << "top10,child0" << "top10,child1" << "top10,child2" << "top10,child3"
446 << "top10,child4"
447 << "top10,child14" << "top10,child15"
448 << "top10,child16"
449 /* "top11*/ << "top11,child0" << "top11,child1" << "top11,child2" << "top11,child3"
450 << "top11,child4"
451 << "top11,child14" << "top11,child15"
452 << "top11,child16"
453 /* "top12*/ << "top12,child0" << "top12,child1" << "top12,child2" << "top12,child3"
454 << "top12,child4"
455 << "top12,child14" << "top12,child15"
456 << "top12,child16"
457 /* "top13*/ << "top13,child0" << "top13,child1" << "top13,child2" << "top13,child3"
458 << "top13,child4"
459 << "top13,child14" << "top13,child15"
460 << "top13,child16"
461 << "top14" << "top14,child0" << "top14,child1" << "top14,child2" << "top14,child3"
462 << "top14,child4"
463 << "top14,child14" << "top14,child15"
464 << "top14,child16"
465 << "top15" << "top15,child0" << "top15,child1" << "top15,child2" << "top15,child3"
466 << "top15,child4"
467 << "top15,child14" << "top15,child15"
468 << "top15,child16"
469 << "top16" << "top16,child0" << "top16,child1" << "top16,child2" << "top16,child3"
470 << "top16,child4"
471 << "top16,child14" << "top16,child15"
472 << "top16,child16");
473
474
475 QTest::newRow(dataTag: "Match DragEnabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DragEnabled)
476 << (QStringList()
477 << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
478 << "top0,child6"
479 << "top0,child14" << "top0,child15"
480 << "top0,child16"
481 << "top1" << "top1,child0" << "top1,child1" << "top1,child2" << "top1,child3"
482 << "top1,child6"
483 << "top1,child14" << "top1,child15"
484 << "top1,child16"
485 << "top2" << "top2,child0" << "top2,child1" << "top2,child2" << "top2,child3"
486 << "top2,child6"
487 << "top2,child14" << "top2,child15"
488 << "top2,child16"
489 << "top3" << "top3,child0" << "top3,child1" << "top3,child2" << "top3,child3"
490 << "top3,child6"
491 << "top3,child14" << "top3,child15"
492 << "top3,child16"
493 /* "top4"*/ << "top4,child0" << "top4,child1" << "top4,child2" << "top4,child3"
494 << "top4,child6"
495 << "top4,child14" << "top4,child15"
496 << "top4,child16"
497 /* "top5"*/ << "top5,child0" << "top5,child1" << "top5,child2" << "top5,child3"
498 << "top5,child6"
499 << "top5,child14" << "top5,child15"
500 << "top5,child16"
501 << "top6" << "top6,child0" << "top6,child1" << "top6,child2" << "top6,child3"
502 << "top6,child6"
503 << "top6,child14" << "top6,child15"
504 << "top6,child16"
505 /* "top7"*/ << "top7,child0" << "top7,child1" << "top7,child2" << "top7,child3"
506 << "top7,child6"
507 << "top7,child14" << "top7,child15"
508 << "top7,child16"
509 /* "top8"*/ << "top8,child0" << "top8,child1" << "top8,child2" << "top8,child3"
510 << "top8,child6"
511 << "top8,child14" << "top8,child15"
512 << "top8,child16"
513 /* "top9"*/ << "top9,child0" << "top9,child1" << "top9,child2" << "top9,child3"
514 << "top9,child6"
515 << "top9,child14" << "top9,child15"
516 << "top9,child16"
517 /* "top10*/ << "top10,child0" << "top10,child1" << "top10,child2" << "top10,child3"
518 << "top10,child6"
519 << "top10,child14" << "top10,child15"
520 << "top10,child16"
521 /* "top11*/ << "top11,child0" << "top11,child1" << "top11,child2" << "top11,child3"
522 << "top11,child6"
523 << "top11,child14" << "top11,child15"
524 << "top11,child16"
525 /* "top12*/ << "top12,child0" << "top12,child1" << "top12,child2" << "top12,child3"
526 << "top12,child6"
527 << "top12,child14" << "top12,child15"
528 << "top12,child16"
529 /* "top13*/ << "top13,child0" << "top13,child1" << "top13,child2" << "top13,child3"
530 << "top13,child6"
531 << "top13,child14" << "top13,child15"
532 << "top13,child16"
533 << "top14" << "top14,child0" << "top14,child1" << "top14,child2" << "top14,child3"
534 << "top14,child6"
535 << "top14,child14" << "top14,child15"
536 << "top14,child16"
537 << "top15" << "top15,child0" << "top15,child1" << "top15,child2" << "top15,child3"
538 << "top15,child6"
539 << "top15,child14" << "top15,child15"
540 << "top15,child16"
541 << "top16" << "top16,child0" << "top16,child1" << "top16,child2" << "top16,child3"
542 << "top16,child6"
543 << "top16,child14" << "top16,child15"
544 << "top16,child16");
545
546 QTest::newRow(dataTag: "Match DragDisabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DragDisabled)
547 << (QStringList()
548
549 /* top0 */
550 << "top0,child4" << "top0,child5" << "top0,child7" << "top0,child8"
551 << "top0,child9" << "top0,child10" << "top0,child11" << "top0,child12"
552 << "top0,child13"
553 /* top1 */
554 << "top1,child4" << "top1,child5" << "top1,child7" << "top1,child8"
555 << "top1,child9" << "top1,child10" << "top1,child11" << "top1,child12"
556 << "top1,child13"
557 /* top2 */
558 << "top2,child4" << "top2,child5" << "top2,child7" << "top2,child8"
559 << "top2,child9" << "top2,child10" << "top2,child11" << "top2,child12"
560 << "top2,child13"
561 /* top3 */
562 << "top3,child4" << "top3,child5" << "top3,child7" << "top3,child8"
563 << "top3,child9" << "top3,child10" << "top3,child11" << "top3,child12"
564 << "top3,child13"
565 << "top4"
566 << "top4,child4" << "top4,child5" << "top4,child7" << "top4,child8"
567 << "top4,child9" << "top4,child10" << "top4,child11" << "top4,child12"
568 << "top4,child13"
569 << "top5"
570 << "top5,child4" << "top5,child5" << "top5,child7" << "top5,child8"
571 << "top5,child9" << "top5,child10" << "top5,child11" << "top5,child12"
572 << "top5,child13"
573 /* "top6"*/
574 << "top6,child4" << "top6,child5" << "top6,child7" << "top6,child8"
575 << "top6,child9" << "top6,child10" << "top6,child11" << "top6,child12"
576 << "top6,child13"
577 << "top7"
578 << "top7,child4" << "top7,child5" << "top7,child7" << "top7,child8"
579 << "top7,child9" << "top7,child10" << "top7,child11" << "top7,child12"
580 << "top7,child13"
581 << "top8"
582 << "top8,child4" << "top8,child5" << "top8,child7" << "top8,child8"
583 << "top8,child9" << "top8,child10" << "top8,child11" << "top8,child12"
584 << "top8,child13"
585 << "top9"
586 << "top9,child4" << "top9,child5" << "top9,child7" << "top9,child8"
587 << "top9,child9" << "top9,child10" << "top9,child11" << "top9,child12"
588 << "top9,child13"
589 << "top10"
590 << "top10,child4" << "top10,child5" << "top10,child7" << "top10,child8"
591 << "top10,child9" << "top10,child10" << "top10,child11" << "top10,child12"
592 << "top10,child13"
593 << "top11"
594 << "top11,child4" << "top11,child5" << "top11,child7" << "top11,child8"
595 << "top11,child9" << "top11,child10" << "top11,child11" << "top11,child12"
596 << "top11,child13"
597 << "top12"
598 << "top12,child4" << "top12,child5" << "top12,child7" << "top12,child8"
599 << "top12,child9" << "top12,child10" << "top12,child11" << "top12,child12"
600 << "top12,child13"
601 << "top13"
602 << "top13,child4" << "top13,child5" << "top13,child7" << "top13,child8"
603 << "top13,child9" << "top13,child10" << "top13,child11" << "top13,child12"
604 << "top13,child13"
605 /* top14 */
606 << "top14,child4" << "top14,child5" << "top14,child7" << "top14,child8"
607 << "top14,child9" << "top14,child10" << "top14,child11" << "top14,child12"
608 << "top14,child13"
609 /* top15 */
610 << "top15,child4" << "top15,child5" << "top15,child7" << "top15,child8"
611 << "top15,child9" << "top15,child10" << "top15,child11" << "top15,child12"
612 << "top15,child13"
613 /* top16 */
614 << "top16,child4" << "top16,child5" << "top16,child7" << "top16,child8"
615 << "top16,child9" << "top16,child10" << "top16,child11" << "top16,child12"
616 << "top16,child13" );
617
618
619 QTest::newRow(dataTag: "Match DropEnabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DropEnabled)
620 << (QStringList()
621 << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
622 << "top0,child8"
623 << "top0,child14" << "top0,child15"
624 << "top0,child16"
625 << "top1" << "top1,child0" << "top1,child1" << "top1,child2" << "top1,child3"
626 << "top1,child8"
627 << "top1,child14" << "top1,child15"
628 << "top1,child16"
629 << "top2" << "top2,child0" << "top2,child1" << "top2,child2" << "top2,child3"
630 << "top2,child8"
631 << "top2,child14" << "top2,child15"
632 << "top2,child16"
633 << "top3" << "top3,child0" << "top3,child1" << "top3,child2" << "top3,child3"
634 << "top3,child8"
635 << "top3,child14" << "top3,child15"
636 << "top3,child16"
637 /* "top4"*/ << "top4,child0" << "top4,child1" << "top4,child2" << "top4,child3"
638 << "top4,child8"
639 << "top4,child14" << "top4,child15"
640 << "top4,child16"
641 /* "top5"*/ << "top5,child0" << "top5,child1" << "top5,child2" << "top5,child3"
642 << "top5,child8"
643 << "top5,child14" << "top5,child15"
644 << "top5,child16"
645 /* "top6"*/ << "top6,child0" << "top6,child1" << "top6,child2" << "top6,child3"
646 << "top6,child8"
647 << "top6,child14" << "top6,child15"
648 << "top6,child16"
649 /* "top7"*/ << "top7,child0" << "top7,child1" << "top7,child2" << "top7,child3"
650 << "top7,child8"
651 << "top7,child14" << "top7,child15"
652 << "top7,child16"
653 << "top8" << "top8,child0" << "top8,child1" << "top8,child2" << "top8,child3"
654 << "top8,child8"
655 << "top8,child14" << "top8,child15"
656 << "top8,child16"
657 /* "top9"*/ << "top9,child0" << "top9,child1" << "top9,child2" << "top9,child3"
658 << "top9,child8"
659 << "top9,child14" << "top9,child15"
660 << "top9,child16"
661 /* "top10*/ << "top10,child0" << "top10,child1" << "top10,child2" << "top10,child3"
662 << "top10,child8"
663 << "top10,child14" << "top10,child15"
664 << "top10,child16"
665 /* "top11*/ << "top11,child0" << "top11,child1" << "top11,child2" << "top11,child3"
666 << "top11,child8"
667 << "top11,child14" << "top11,child15"
668 << "top11,child16"
669 /* "top12*/ << "top12,child0" << "top12,child1" << "top12,child2" << "top12,child3"
670 << "top12,child8"
671 << "top12,child14" << "top12,child15"
672 << "top12,child16"
673 /* "top13*/ << "top13,child0" << "top13,child1" << "top13,child2" << "top13,child3"
674 << "top13,child8"
675 << "top13,child14" << "top13,child15"
676 << "top13,child16"
677 << "top14" << "top14,child0" << "top14,child1" << "top14,child2" << "top14,child3"
678 << "top14,child8"
679 << "top14,child14" << "top14,child15"
680 << "top14,child16"
681 << "top15" << "top15,child0" << "top15,child1" << "top15,child2" << "top15,child3"
682 << "top15,child8"
683 << "top15,child14" << "top15,child15"
684 << "top15,child16"
685 << "top16" << "top16,child0" << "top16,child1" << "top16,child2" << "top16,child3"
686 << "top16,child8"
687 << "top16,child14" << "top16,child15"
688 << "top16,child16");
689
690 QTest::newRow(dataTag: "Match HasChildren") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::HasChildren)
691 << (QStringList() << "top0" << "top1" << "top2" << "top3" << "top4" << "top5"
692 << "top6" << "top7" << "top8" << "top9" << "top10" << "top11" << "top12"
693 << "top13" << "top14" << "top15" << "top16");
694
695 QTest::newRow(dataTag: "Match Checked") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Checked)
696 << (QStringList()
697 << "top0,child14" << "top0,child16"
698 << "top1,child14" << "top1,child16"
699 << "top2,child14" << "top2,child16"
700 << "top3,child14" << "top3,child16"
701 << "top4,child14" << "top4,child16"
702 << "top5,child14" << "top5,child16"
703 << "top6,child14" << "top6,child16"
704 << "top7,child14" << "top7,child16"
705 << "top8,child14" << "top8,child16"
706 << "top9,child14" << "top9,child16"
707 << "top10,child14" << "top10,child16"
708 << "top11,child14" << "top11,child16"
709 << "top12,child14" << "top12,child16"
710 << "top13,child14" << "top13,child16"
711 << "top14"
712 << "top14,child14" << "top14,child16"
713 << "top15,child14" << "top15,child16"
714 << "top16"
715 << "top16,child14" << "top16,child16");
716
717 QTest::newRow(dataTag: "Match NotChecked") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::NotChecked)
718 << (QStringList()
719 << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3"
720 << "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7"
721 << "top0,child8" << "top0,child9" << "top0,child10" << "top0,child11"
722 << "top0,child12" << "top0,child13" << "top0,child15"
723
724 << "top1" << "top1,child0" << "top1,child1" << "top1,child2" << "top1,child3"
725 << "top1,child4" << "top1,child5" << "top1,child6" << "top1,child7"
726 << "top1,child8" << "top1,child9" << "top1,child10" << "top1,child11"
727 << "top1,child12" << "top1,child13" << "top1,child15"
728
729 << "top2" << "top2,child0" << "top2,child1" << "top2,child2" << "top2,child3"
730 << "top2,child4" << "top2,child5" << "top2,child6" << "top2,child7"
731 << "top2,child8" << "top2,child9" << "top2,child10" << "top2,child11"
732 << "top2,child12" << "top2,child13" << "top2,child15"
733
734 << "top3" << "top3,child0" << "top3,child1" << "top3,child2" << "top3,child3"
735 << "top3,child4" << "top3,child5" << "top3,child6" << "top3,child7"
736 << "top3,child8" << "top3,child9" << "top3,child10" << "top3,child11"
737 << "top3,child12" << "top3,child13" << "top3,child15"
738
739 << "top4" << "top4,child0" << "top4,child1" << "top4,child2" << "top4,child3"
740 << "top4,child4" << "top4,child5" << "top4,child6" << "top4,child7"
741 << "top4,child8" << "top4,child9" << "top4,child10" << "top4,child11"
742 << "top4,child12" << "top4,child13" << "top4,child15"
743
744 << "top5" << "top5,child0" << "top5,child1" << "top5,child2" << "top5,child3"
745 << "top5,child4" << "top5,child5" << "top5,child6" << "top5,child7"
746 << "top5,child8" << "top5,child9" << "top5,child10" << "top5,child11"
747 << "top5,child12" << "top5,child13" << "top5,child15"
748
749 << "top6" << "top6,child0" << "top6,child1" << "top6,child2" << "top6,child3"
750 << "top6,child4" << "top6,child5" << "top6,child6" << "top6,child7"
751 << "top6,child8" << "top6,child9" << "top6,child10" << "top6,child11"
752 << "top6,child12" << "top6,child13" << "top6,child15"
753
754 << "top7" << "top7,child0" << "top7,child1" << "top7,child2" << "top7,child3"
755 << "top7,child4" << "top7,child5" << "top7,child6" << "top7,child7"
756 << "top7,child8" << "top7,child9" << "top7,child10" << "top7,child11"
757 << "top7,child12" << "top7,child13" << "top7,child15"
758
759 << "top8" << "top8,child0" << "top8,child1" << "top8,child2" << "top8,child3"
760 << "top8,child4" << "top8,child5" << "top8,child6" << "top8,child7"
761 << "top8,child8" << "top8,child9" << "top8,child10" << "top8,child11"
762 << "top8,child12" << "top8,child13" << "top8,child15"
763
764 << "top9" << "top9,child0" << "top9,child1" << "top9,child2" << "top9,child3"
765 << "top9,child4" << "top9,child5" << "top9,child6" << "top9,child7"
766 << "top9,child8" << "top9,child9" << "top9,child10" << "top9,child11"
767 << "top9,child12" << "top9,child13" << "top9,child15"
768
769 << "top10" << "top10,child0" << "top10,child1" << "top10,child2" << "top10,child3"
770 << "top10,child4" << "top10,child5" << "top10,child6" << "top10,child7"
771 << "top10,child8" << "top10,child9" << "top10,child10" << "top10,child11"
772 << "top10,child12" << "top10,child13" << "top10,child15"
773
774 << "top11" << "top11,child0" << "top11,child1" << "top11,child2" << "top11,child3"
775 << "top11,child4" << "top11,child5" << "top11,child6" << "top11,child7"
776 << "top11,child8" << "top11,child9" << "top11,child10" << "top11,child11"
777 << "top11,child12" << "top11,child13" << "top11,child15"
778
779 << "top12" << "top12,child0" << "top12,child1" << "top12,child2" << "top12,child3"
780 << "top12,child4" << "top12,child5" << "top12,child6" << "top12,child7"
781 << "top12,child8" << "top12,child9" << "top12,child10" << "top12,child11"
782 << "top12,child12" << "top12,child13" << "top12,child15"
783
784 << "top13" << "top13,child0" << "top13,child1" << "top13,child2" << "top13,child3"
785 << "top13,child4" << "top13,child5" << "top13,child6" << "top13,child7"
786 << "top13,child8" << "top13,child9" << "top13,child10" << "top13,child11"
787 << "top13,child12" << "top13,child13" << "top13,child15"
788
789 /* "top14"*/<< "top14,child0" << "top14,child1" << "top14,child2" << "top14,child3"
790 << "top14,child4" << "top14,child5" << "top14,child6" << "top14,child7"
791 << "top14,child8" << "top14,child9" << "top14,child10" << "top14,child11"
792 << "top14,child12" << "top14,child13" << "top14,child15"
793
794 << "top15" << "top15,child0" << "top15,child1" << "top15,child2" << "top15,child3"
795 << "top15,child4" << "top15,child5" << "top15,child6" << "top15,child7"
796 << "top15,child8" << "top15,child9" << "top15,child10" << "top15,child11"
797 << "top15,child12" << "top15,child13" << "top15,child15"
798
799 /* "top16"*/<< "top16,child0" << "top16,child1" << "top16,child2" << "top16,child3"
800 << "top16,child4" << "top16,child5" << "top16,child6" << "top16,child7"
801 << "top16,child8" << "top16,child9" << "top16,child10" << "top16,child11"
802 << "top16,child12" << "top16,child13" << "top16,child15");
803
804
805
806 QTest::newRow(dataTag: "Match Disabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Disabled)
807 << (QStringList()
808 << "top0,child11"
809 << "top1,child11"
810 << "top2,child11"
811 << "top3,child11"
812 << "top4,child11"
813 << "top5,child11"
814 << "top6,child11"
815 << "top7,child11"
816 << "top8,child11"
817 << "top9,child11"
818 << "top10,child11"
819 << "top11"
820 << "top11,child0"
821 << "top11,child1"
822 << "top11,child2"
823 << "top11,child3"
824 << "top11,child4"
825 << "top11,child5"
826 << "top11,child6"
827 << "top11,child7"
828 << "top11,child8"
829 << "top11,child9"
830 << "top11,child10"
831 << "top11,child11"
832 << "top11,child12"
833 << "top11,child13"
834 << "top11,child14"
835 << "top11,child15"
836 << "top11,child16"
837
838 << "top12,child11"
839 << "top13,child11"
840 << "top14,child11"
841 << "top15,child11"
842 << "top16,child11");
843
844 QTest::newRow(dataTag: "Match Editable") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Editable)
845 << (QStringList()
846 << "top0,child12"
847 << "top1,child12"
848 << "top2,child12"
849 << "top3,child12"
850 << "top4,child12"
851 << "top5,child12"
852 << "top6,child12"
853 << "top7,child12"
854 << "top8,child12"
855 << "top9,child12"
856 << "top10,child12"
857 << "top11,child12"
858 << "top12"
859 << "top12,child12"
860 << "top13,child12"
861 << "top14,child12"
862 << "top15,child12"
863 << "top16,child12");
864
865 QTest::newRow(dataTag: "Match mutually exclusive Hidden|NotHidden") << 0 << (QTreeWidgetItemIterator::Hidden|QTreeWidgetItemIterator::NotHidden)
866 << QStringList();
867 QTest::newRow(dataTag: "Match mutually exclusive Selected|Unselected") << 0 << (QTreeWidgetItemIterator::Selected|QTreeWidgetItemIterator::Unselected)
868 << QStringList();
869 QTest::newRow(dataTag: "Match mutually exclusive Selectable|NotSelectable") << 0 << (QTreeWidgetItemIterator::Selectable|QTreeWidgetItemIterator::NotSelectable)
870 << QStringList();
871 QTest::newRow(dataTag: "Match mutually exclusive DragEnabled|DragDisabled") << 0 << (QTreeWidgetItemIterator::DragEnabled|QTreeWidgetItemIterator::DragDisabled)
872 << QStringList();
873 QTest::newRow(dataTag: "Match mutually exclusive DropEnabled|DropDisabled") << 0 << (QTreeWidgetItemIterator::DropEnabled|QTreeWidgetItemIterator::DropDisabled)
874 << QStringList();
875 QTest::newRow(dataTag: "Match mutually exclusive HasChildren|NoChildren") << 0 << (QTreeWidgetItemIterator::HasChildren|QTreeWidgetItemIterator::NoChildren)
876 << QStringList();
877 QTest::newRow(dataTag: "Match mutually exclusive Checked|NotChecked") << 0 << (QTreeWidgetItemIterator::Checked|QTreeWidgetItemIterator::NotChecked)
878 << QStringList();
879 QTest::newRow(dataTag: "Match mutually exclusive Disabled|Enabled") << 0 << (QTreeWidgetItemIterator::Disabled|QTreeWidgetItemIterator::Enabled)
880 << QStringList();
881 QTest::newRow(dataTag: "Match mutually exclusive Editable|NotEditable") << 0 << (QTreeWidgetItemIterator::Editable|QTreeWidgetItemIterator::NotEditable)
882 << QStringList();
883}
884
885void tst_QTreeWidgetItemIterator::iteratorflags()
886{
887 QFETCH(int, start);
888 QFETCH(QTreeWidgetItemIterator::IteratorFlags, iteratorflags);
889 QFETCH(QStringList, matches);
890
891 QTreeWidgetItemIterator it(testWidget, iteratorflags);
892 it += start;
893 int iMatch = 0;
894 while (*it && iMatch < matches.count()) {
895 QTreeWidgetItem *item = *it;
896 QCOMPARE(item->text(0), matches[iMatch]);
897 ++it;
898 ++iMatch;
899 }
900 // Make sure the expected result does not contain *more* items than the actual result.
901 QCOMPARE(iMatch, matches.size());
902}
903
904void tst_QTreeWidgetItemIterator::preincrement()
905{
906 QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::All);
907 QTreeWidgetItem *item = *(++it);
908 // should be the second one
909 QCOMPARE(item->text(0), QString("top0,child0"));
910}
911
912void tst_QTreeWidgetItemIterator::postincrement()
913{
914 QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::All);
915 QTreeWidgetItem *item = *(it++);
916 // should be the first one
917 QCOMPARE(item->text(0), QString("top0"));
918}
919
920void tst_QTreeWidgetItemIterator::predecrement()
921{
922 QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::All);
923 QTreeWidgetItem *item = *(++it);
924 // should be the second one
925 QCOMPARE(item->text(0), QString("top0,child0"));
926
927 item = *(--it);
928 QCOMPARE(item->text(0), QString("top0"));
929
930}
931
932void tst_QTreeWidgetItemIterator::postdecrement()
933{
934 QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::All);
935 QTreeWidgetItem *item = *(it++);
936 // should be the first one
937 QCOMPARE(item->text(0), QString("top0"));
938
939 //Iterator points to second one
940 item = *(it--);
941 QCOMPARE(item->text(0), QString("top0,child0"));
942
943}
944
945void tst_QTreeWidgetItemIterator::plus_eq_data()
946{
947 QTest::addColumn<int>(name: "start");
948 QTest::addColumn<int>(name: "addition");
949 QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>(name: "iteratorflags");
950 QTest::addColumn<QString>(name: "expecteditem");
951
952 QTest::newRow(dataTag: "+=0") << 0 << 0 << QTreeWidgetItemIterator::All << QString("top0");
953 QTest::newRow(dataTag: "+=1") << 0 << 1 << QTreeWidgetItemIterator::All << QString("top0,child0");
954 QTest::newRow(dataTag: "+=2") << 0 << 2 << QTreeWidgetItemIterator::All << QString("top0,child1");
955 QTest::newRow(dataTag: "+=(-1)") << 1 << -1 << QTreeWidgetItemIterator::All << QString("top0");
956 QTest::newRow(dataTag: "+=(-2)") << 3 << -2 << QTreeWidgetItemIterator::All << QString("top0,child0");
957}
958
959void tst_QTreeWidgetItemIterator::plus_eq()
960{
961 QFETCH(int, start);
962 QFETCH(int, addition);
963 QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags);
964 QFETCH(QString, expecteditem);
965
966 QTreeWidgetItemIterator it(testWidget, iteratorflags);
967 it += start;
968 it += addition;
969 QTreeWidgetItem *item = *it;
970
971 QVERIFY(item);
972 QCOMPARE(item->text(0), expecteditem);
973
974}
975
976void tst_QTreeWidgetItemIterator::minus_eq_data()
977{
978 QTest::addColumn<int>(name: "start");
979 QTest::addColumn<int>(name: "subtraction");
980 QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>(name: "iteratorflags");
981 QTest::addColumn<QString>(name: "expecteditem");
982
983 QTest::newRow(dataTag: "0-=0") << 0 << 0 << QTreeWidgetItemIterator::All << QString("top0");
984 QTest::newRow(dataTag: "2-=1") << 2 << 1 << QTreeWidgetItemIterator::All << QString("top0,child0");
985 QTest::newRow(dataTag: "4-=2") << 4 << 2 << QTreeWidgetItemIterator::All << QString("top0,child1");
986 QTest::newRow(dataTag: "0-=(-1)") << 0 << -1 << QTreeWidgetItemIterator::All << QString("top0,child0");
987 QTest::newRow(dataTag: "0-=(-2)") << 0 << -2 << QTreeWidgetItemIterator::All << QString("top0,child1");
988 QTest::newRow(dataTag: "18-=1") << 18 << 1 << QTreeWidgetItemIterator::All << QString("top0,child16");
989 QTest::newRow(dataTag: "1-=1") << 1 << 1 << QTreeWidgetItemIterator::All << QString("top0");
990}
991
992void tst_QTreeWidgetItemIterator::minus_eq()
993{
994 QFETCH(int, start);
995 QFETCH(int, subtraction);
996 QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags);
997 QFETCH(QString, expecteditem);
998
999 QTreeWidgetItemIterator it(testWidget, iteratorflags);
1000 it += start;
1001 it -= subtraction;
1002 QTreeWidgetItem *item = *it;
1003 // should be the first one
1004 QVERIFY(item);
1005 QCOMPARE(item->text(0), expecteditem);
1006}
1007
1008void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget_data()
1009{
1010 QTest::addColumn<int>(name: "topLevelItems");
1011 QTest::addColumn<int>(name: "childItems");
1012 QTest::addColumn<int>(name: "grandChildItems");
1013 QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>(name: "iteratorflags");
1014 QTest::addColumn<int>(name: "removeindex");
1015 QTest::addColumn<int>(name: "expecteditemindex");
1016 QTest::addColumn<QString>(name: "expecteditemvalue");
1017 QTest::addColumn<QString>(name: "expectedUpdatedCurrent");
1018 QTest::addColumn<int>(name: "expecteditemIsNull");
1019
1020 QTest::newRow(dataTag: "Remove 3, check 1") << 3 << 3 << 0 << QTreeWidgetItemIterator::All
1021 << 3 << 1 << QString("top0,child0") << QString("top1") << 0;
1022 QTest::newRow(dataTag: "Remove 1, check 0") << 3 << 3 << 0 << QTreeWidgetItemIterator::All
1023 << 1 << 0 << QString("top0") << QString("top0,child1") << 0;
1024 QTest::newRow(dataTag: "Remove 2, check 2") << 3 << 3 << 0 << QTreeWidgetItemIterator::All
1025 << 2 << 2 << QString("top0,child2") << QString("top0,child2") << 0;
1026 QTest::newRow(dataTag: "Remove 0, check 0") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
1027 << 0 << 0 << QString("top1") << QString("top1") << 0;
1028 QTest::newRow(dataTag: "Remove top1, check top1") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
1029 << 13 << 13 << QString("top2") << QString("top2") << 0;
1030 QTest::newRow(dataTag: "Remove top0, check top1") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
1031 << 0 << 13 << QString("top1") << QString("top1") << 0;
1032 QTest::newRow(dataTag: "Remove (top0,child1), check (top0,child1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
1033 << 5 << 5 << QString("top0,child2") << QString("top0,child2") << 0;
1034 QTest::newRow(dataTag: "Remove (t0,c0) check (t0,c0)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
1035 << 1 << 1 << QString("top0,child1") << QString("top0,child1") << 0;
1036 QTest::newRow(dataTag: "Remove (t0,c1) check (t0,c1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
1037 << 5 << 5 << QString("top0,child2") << QString("top0,child2") << 0;
1038 QTest::newRow(dataTag: "Remove (t0) check (t0,c1)") << 3 << 3 << 0 << QTreeWidgetItemIterator::All
1039 << 0 << 4 << QString("top1") << QString("top1") << 0;
1040 QTest::newRow(dataTag: "Remove (t0) check (t0,c0,g1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
1041 << 0 << 3 << QString("top1") << QString("top1") << 0;
1042 QTest::newRow(dataTag: "Remove (top2), check if top2 is null") << 3 << 3 << 3 << QTreeWidgetItemIterator::All
1043 << 2*13 << 2*13 << QString() << QString() << 1;
1044 QTest::newRow(dataTag: "Remove last item, check if iterator::current returns 0")
1045 << 3 << 0 << 0 << QTreeWidgetItemIterator::All << 2 << 2 << QString() << QString() << 1;
1046 QTest::newRow(dataTag: "remove 1, iterator points to 3, should move to 1")
1047 << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 1 << 3 << QString("top0,child1") << QString("top0,child1") << 0;
1048}
1049
1050static void populate3Levels(QTreeWidget &tw, int topLevelItems, int childItems, int grandChildItems)
1051{
1052 for (int i1 = 0; i1 < topLevelItems; ++i1) {
1053 QTreeWidgetItem *top = new QTreeWidgetItem(&tw);
1054 const QString top1S = QLatin1String("top") + QString::number(i1);
1055 top->setText(column: 0, atext: top1S);
1056 for (int i2 = 0; i2 < childItems; ++i2) {
1057 QTreeWidgetItem *child = new QTreeWidgetItem(top);
1058 const QString childS = top1S + QLatin1String(",child") + QString::number(i2);
1059 child->setText(column: 0, atext: childS);
1060 for (int i3 = 0; i3 < grandChildItems; ++i3) {
1061 QTreeWidgetItem *grandChild = new QTreeWidgetItem(child);
1062 grandChild->setText(column: 0, atext: childS + QLatin1String(",grandchild") + QString::number(i3));
1063 }
1064 }
1065 }
1066}
1067
1068void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget()
1069{
1070 QFETCH(int, topLevelItems);
1071 QFETCH(int, childItems);
1072 QFETCH(int, grandChildItems);
1073 QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags);
1074 QFETCH(int, removeindex);
1075 QFETCH(int, expecteditemindex);
1076 QFETCH(QString, expecteditemvalue);
1077 QFETCH(QString, expectedUpdatedCurrent);
1078 QFETCH(int, expecteditemIsNull);
1079
1080 QTreeWidget tw;
1081 tw.clear();
1082 tw.setColumnCount(2);
1083 populate3Levels(tw, topLevelItems, childItems, grandChildItems);
1084
1085 QTreeWidgetItemIterator it(&tw, iteratorflags);
1086 it+=expecteditemindex;
1087 QTreeWidgetItemIterator itRemove(&tw, QTreeWidgetItemIterator::IteratorFlags(iteratorflags));
1088 itRemove+=removeindex;
1089 QTreeWidgetItem *item = *itRemove;
1090 QVERIFY(item);
1091 delete item;
1092 item = *it;
1093 if (expecteditemIsNull) {
1094 QVERIFY(!item);
1095 } else {
1096 QVERIFY(item);
1097 QCOMPARE(item->text(0), expecteditemvalue);
1098 item = *itRemove;
1099 if (expectedUpdatedCurrent.isNull())
1100 QVERIFY(!item);
1101 else
1102 QCOMPARE(item->text(0), expectedUpdatedCurrent);
1103 }
1104}
1105
1106void tst_QTreeWidgetItemIterator::updateIteratorAfterDeletedItem_and_ContinueIteration_data()
1107{
1108 QTest::addColumn<int>(name: "topLevelItems");
1109 QTest::addColumn<int>(name: "childItems");
1110 QTest::addColumn<int>(name: "grandChildItems"); // Populate the tree data
1111 // we have one iterator pointing to an item in the tree.
1112 // This iterator will be updated if we delete the item it is pointing to.
1113 //
1114 QTest::addColumn<int>(name: "removeindex"); // The index of the node we want to remove
1115 QTest::addColumn<int>(name: "iterator_initial_index"); // The new expected index of
1116 QTest::addColumn<int>(name: "iterator_advance_after_removal");
1117 QTest::addColumn<QString>(name: "iterator_new_value"); // The new current item value of the iterator
1118 QTest::newRow(dataTag: "Remove 13, it points to 25, it-=1. We should get top0,child2,grandchild2") << 3 << 3 << 3 << 13 << 25 << -1 << QString("top0,child2,grandchild2");
1119 QTest::newRow(dataTag: "Remove 0, it points to 12, it+=1. We should get top1,child0") << 3 << 3 << 3 << 0 << 12 << 1 << QString("top1,child0");
1120 QTest::newRow(dataTag: "Remove 0, it points to 12, it-=1. We should get 0") << 3 << 3 << 3 << 0 << 12 << -1 << QString();
1121 QTest::newRow(dataTag: "Remove 0, it points to 1, it+=1. We should get top2") << 4 << 0 << 0 << 0 << 1 << 1 << QString("top2");
1122 QTest::newRow(dataTag: "Remove 2, it points to 1, it+=0. We should get top1") << 4 << 0 << 0 << 2 << 1 << 0 << QString("top1");
1123 QTest::newRow(dataTag: "Remove 2, it points to 1, it+=1. We should get top3") << 4 << 0 << 0 << 2 << 1 << 1 << QString("top3");
1124 QTest::newRow(dataTag: "Remove 1, it points to 2, it+=1. We should get top0,child2") << 3 << 3 << 0 << 1 << 2 << 1 << QString("top0,child2");
1125 QTest::newRow(dataTag: "Remove 1, it points to 2, it+=0. We should get top0,child1") << 3 << 3 << 0 << 1 << 2 << 0 << QString("top0,child1");
1126 QTest::newRow(dataTag: "Remove 1, it points to 2, it-=1. We should get top0") << 3 << 3 << 0 << 1 << 2 << -1 << QString("top0");
1127}
1128
1129void tst_QTreeWidgetItemIterator::updateIteratorAfterDeletedItem_and_ContinueIteration()
1130{
1131 QFETCH(int, topLevelItems);
1132 QFETCH(int, childItems);
1133 QFETCH(int, grandChildItems);
1134 QFETCH(int, removeindex);
1135 QFETCH(int, iterator_initial_index);
1136 QFETCH(int, iterator_advance_after_removal);
1137 QFETCH(QString, iterator_new_value);
1138
1139 QTreeWidget tw;
1140 tw.clear();
1141 tw.setColumnCount(2);
1142 populate3Levels(tw, topLevelItems, childItems, grandChildItems);
1143
1144 QTreeWidgetItemIterator it(&tw, QTreeWidgetItemIterator::All);
1145 it += iterator_initial_index;
1146 QTreeWidgetItemIterator itRemove(&tw, QTreeWidgetItemIterator::All);
1147 itRemove+=removeindex;
1148 QTreeWidgetItem *item = *itRemove;
1149 QVERIFY(item);
1150 delete item;
1151 it+=iterator_advance_after_removal;
1152 if (iterator_new_value.isNull())
1153 QCOMPARE((*it), nullptr);
1154 else
1155 QCOMPARE((*it)->text(0), iterator_new_value);
1156}
1157
1158void tst_QTreeWidgetItemIterator::constructIteratorWithItem_data()
1159{
1160 QTest::addColumn<int>(name: "indextoitem");
1161 QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>(name: "iteratorflags");
1162 QTest::addColumn<QString>(name: "expecteditem");
1163
1164 QTest::newRow(dataTag: "index 0") << 0 << QTreeWidgetItemIterator::All << QString("top0");
1165 QTest::newRow(dataTag: "index 1") << 1 << QTreeWidgetItemIterator::All << QString("top0,child0");
1166 QTest::newRow(dataTag: "index 2") << 2 << QTreeWidgetItemIterator::All << QString("top0,child1");
1167 QTest::newRow(dataTag: "index 30") << 30 << QTreeWidgetItemIterator::All << QString("top1,child11");
1168 QTest::newRow(dataTag: "305 (last item)") << 305 << QTreeWidgetItemIterator::All << QString("top16,child16");
1169 QTest::newRow(dataTag: "index 0, advance to next matching node") << 0 << QTreeWidgetItemIterator::NotHidden << QString("top0,child1");
1170}
1171
1172void tst_QTreeWidgetItemIterator::constructIteratorWithItem()
1173{
1174 QFETCH(int, indextoitem);
1175 QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags);
1176 QFETCH(QString, expecteditem);
1177
1178 QTreeWidgetItemIterator it(testWidget);
1179 it+=indextoitem;
1180 QTreeWidgetItem *item = *it;
1181 QTreeWidgetItemIterator it2(item, QTreeWidgetItemIterator::IteratorFlags(iteratorflags));
1182 QTreeWidgetItem *item2 = *it2;
1183
1184 QVERIFY(item2);
1185 QCOMPARE(item2->text(0), expecteditem);
1186
1187}
1188
1189void tst_QTreeWidgetItemIterator::initializeIterator()
1190{
1191 QTreeWidget tw;
1192 QTreeWidgetItemIterator it(&tw);
1193
1194 QCOMPARE((*it), nullptr);
1195}
1196
1197void tst_QTreeWidgetItemIterator::sortingEnabled()
1198{
1199 QTreeWidget *tree = new QTreeWidget;
1200 tree->setColumnCount(2);
1201 tree->headerItem()->setText(column: 0, atext: "Id");
1202 tree->headerItem()->setText(column: 1, atext: "Color");
1203
1204 tree->setSortingEnabled(true);
1205 tree->sortByColumn(column: 0, order: Qt::AscendingOrder);
1206
1207 QTreeWidgetItem *second = new QTreeWidgetItem;
1208 second->setText(column: 0, atext: "2");
1209 second->setText(column: 1, atext: "second");
1210 QTreeWidgetItem *first = new QTreeWidgetItem;
1211 first->setText(column: 0, atext: "1");
1212 first->setText(column: 1, atext: "first");
1213
1214 tree->addTopLevelItem(item: second);
1215 tree->addTopLevelItem(item: first);
1216
1217 QTreeWidgetItemIterator it(tree);
1218 QCOMPARE(*it, first);
1219 ++it;
1220 QCOMPARE(*it, second);
1221}
1222
1223QTEST_MAIN(tst_QTreeWidgetItemIterator)
1224#include "tst_qtreewidgetitemiterator.moc"
1225

source code of qtbase/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp