author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <qtreewidget.h> |
|
45 |
#include <qtreewidgetitemiterator.h> |
|
46 |
#include <qapplication.h> |
|
47 |
#include <qeventloop.h> |
|
48 |
#include <qdebug.h> |
|
49 |
#include <qheaderview.h> |
|
50 |
#include <qlineedit.h> |
|
51 |
#include <QScrollBar> |
|
52 |
#include <QStyledItemDelegate> |
|
53 |
||
54 |
#include "../../shared/util.h" |
|
55 |
||
56 |
||
57 |
//TESTED_CLASS= |
|
58 |
//TESTED_FILES= |
|
59 |
||
60 |
class CustomTreeWidget : public QTreeWidget |
|
61 |
{ |
|
62 |
Q_OBJECT |
|
63 |
public: |
|
64 |
QModelIndex indexFromItem(QTreeWidgetItem *item, int column = 0) const |
|
65 |
{ return QTreeWidget::indexFromItem(item, column); } |
|
66 |
}; |
|
67 |
||
68 |
class tst_QTreeWidget : public QObject |
|
69 |
{ |
|
70 |
Q_OBJECT |
|
71 |
||
72 |
public: |
|
73 |
tst_QTreeWidget(); |
|
74 |
~tst_QTreeWidget(); |
|
75 |
||
76 |
||
77 |
public slots: |
|
78 |
void initTestCase(); |
|
79 |
void cleanupTestCase(); |
|
80 |
void init(); |
|
81 |
void cleanup(); |
|
82 |
||
83 |
private slots: |
|
84 |
void getSetCheck(); |
|
85 |
void addTopLevelItem(); |
|
86 |
void currentItem_data(); |
|
87 |
void currentItem(); |
|
88 |
void editItem_data(); |
|
89 |
void editItem(); |
|
90 |
void takeItem_data(); |
|
91 |
void takeItem(); |
|
92 |
void removeChild_data(); |
|
93 |
void removeChild(); |
|
94 |
void setItemHidden(); |
|
95 |
void setItemHidden2(); |
|
96 |
void selectedItems_data(); |
|
97 |
void selectedItems(); |
|
98 |
void itemAssignment(); |
|
99 |
void clone_data(); |
|
100 |
void clone(); |
|
101 |
void expand_data(); |
|
102 |
void expand(); |
|
103 |
void checkState_data(); |
|
104 |
void checkState(); |
|
105 |
void findItems_data(); |
|
106 |
void findItems(); |
|
107 |
void findItemsInColumn(); |
|
108 |
void sortItems_data(); |
|
109 |
void sortItems(); |
|
110 |
void deleteItems_data(); |
|
111 |
void deleteItems(); |
|
112 |
void itemAboveOrBelow(); |
|
113 |
void itemStreaming_data(); |
|
114 |
void itemStreaming(); |
|
115 |
void insertTopLevelItems_data(); |
|
116 |
void insertTopLevelItems(); |
|
117 |
void keyboardNavigation(); |
|
118 |
void scrollToItem(); |
|
119 |
void setSortingEnabled(); |
|
120 |
void match(); |
|
121 |
void columnCount(); |
|
122 |
void setHeaderLabels(); |
|
123 |
void setHeaderItem(); |
|
124 |
void itemWidget_data(); |
|
125 |
void itemWidget(); |
|
126 |
void insertItemsWithSorting_data(); |
|
127 |
void insertItemsWithSorting(); |
|
128 |
void insertExpandedItemsWithSorting_data(); |
|
129 |
void insertExpandedItemsWithSorting(); |
|
130 |
void changeDataWithSorting_data(); |
|
131 |
void changeDataWithSorting(); |
|
132 |
void changeDataWithStableSorting_data(); |
|
133 |
void changeDataWithStableSorting(); |
|
134 |
||
135 |
void sortedIndexOfChild_data(); |
|
136 |
void sortedIndexOfChild(); |
|
137 |
void defaultRowSizes(); |
|
138 |
||
139 |
void task191552_rtl(); |
|
140 |
void task203673_selection(); |
|
141 |
void rootItemFlags(); |
|
142 |
void task218661_setHeaderData(); |
|
143 |
void task245280_sortChildren(); |
|
144 |
void task253109_itemHeight(); |
|
145 |
||
146 |
// QTreeWidgetItem |
|
147 |
void itemOperatorLessThan(); |
|
148 |
void addChild(); |
|
149 |
void setData(); |
|
150 |
void enableDisable(); |
|
151 |
||
152 |
void expandAndCallapse(); |
|
153 |
void itemData(); |
|
154 |
void setDisabled(); |
|
155 |
void removeSelectedItem(); |
|
156 |
void removeCurrentItem(); |
|
157 |
void removeCurrentItem_task186451(); |
|
158 |
void randomExpand(); |
|
159 |
void crashTest(); |
|
160 |
void sortAndSelect(); |
|
161 |
||
162 |
void task206367_duplication(); |
|
163 |
void selectionOrder(); |
|
164 |
||
165 |
void setSelectionModel(); |
|
166 |
void task217309(); |
|
167 |
void setCurrentItemExpandsParent(); |
|
168 |
void task239150_editorWidth(); |
|
169 |
void setTextUpdate(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
void taskQTBUG2844_visualItemRect(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
void setChildIndicatorPolicy(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
|
0 | 173 |
|
174 |
public slots: |
|
175 |
void itemSelectionChanged(); |
|
176 |
void emitDataChanged(); |
|
177 |
||
178 |
private: |
|
179 |
CustomTreeWidget *testWidget; |
|
180 |
}; |
|
181 |
||
182 |
// Testing get/set functions |
|
183 |
void tst_QTreeWidget::getSetCheck() |
|
184 |
{ |
|
185 |
QTreeWidget obj1; |
|
186 |
// int QTreeWidget::columnCount() |
|
187 |
// void QTreeWidget::setColumnCount(int) |
|
188 |
obj1.setColumnCount(0); |
|
189 |
QCOMPARE(obj1.columnCount(), 0); |
|
190 |
||
191 |
obj1.setColumnCount(INT_MIN); |
|
192 |
QCOMPARE(obj1.columnCount(), 0); |
|
193 |
||
194 |
//obj1.setColumnCount(INT_MAX); |
|
195 |
//QCOMPARE(obj1.columnCount(), INT_MAX); |
|
196 |
// Since setColumnCount allocates memory, there is no way this will succeed |
|
197 |
||
198 |
obj1.setColumnCount(100); |
|
199 |
QCOMPARE(obj1.columnCount(), 100); |
|
200 |
||
201 |
// QTreeWidgetItem * QTreeWidget::headerItem() |
|
202 |
// void QTreeWidget::setHeaderItem(QTreeWidgetItem *) |
|
203 |
QTreeWidgetItem *var2 = new QTreeWidgetItem(); |
|
204 |
obj1.setHeaderItem(var2); |
|
205 |
QCOMPARE(obj1.headerItem(), var2); |
|
206 |
||
207 |
obj1.setHeaderItem((QTreeWidgetItem *)0); |
|
208 |
// QCOMPARE(obj1.headerItem(), (QTreeWidgetItem *)0); |
|
209 |
||
210 |
// QTreeWidgetItem * QTreeWidget::currentItem() |
|
211 |
// void QTreeWidget::setCurrentItem(QTreeWidgetItem *) |
|
212 |
QTreeWidgetItem *var3 = new QTreeWidgetItem(&obj1); |
|
213 |
obj1.setCurrentItem(var3); |
|
214 |
QCOMPARE(obj1.currentItem(), var3); |
|
215 |
||
216 |
obj1.setCurrentItem((QTreeWidgetItem *)0); |
|
217 |
QCOMPARE(obj1.currentItem(), (QTreeWidgetItem *)0); |
|
218 |
} |
|
219 |
||
220 |
typedef QList<int> IntList; |
|
221 |
typedef QList<IntList> ListIntList; |
|
222 |
||
223 |
Q_DECLARE_METATYPE(IntList) |
|
224 |
Q_DECLARE_METATYPE(ListIntList) |
|
225 |
Q_DECLARE_METATYPE(QModelIndex) |
|
226 |
Q_DECLARE_METATYPE(Qt::Orientation) |
|
227 |
||
228 |
typedef QTreeWidgetItem TreeItem; |
|
229 |
typedef QList<TreeItem*> TreeItemList; |
|
230 |
||
231 |
Q_DECLARE_METATYPE(QTreeWidgetItem*) |
|
232 |
Q_DECLARE_METATYPE(TreeItemList) |
|
233 |
||
234 |
tst_QTreeWidget::tst_QTreeWidget(): testWidget(0) |
|
235 |
{ |
|
236 |
} |
|
237 |
||
238 |
tst_QTreeWidget::~tst_QTreeWidget() |
|
239 |
{ |
|
240 |
} |
|
241 |
||
242 |
void tst_QTreeWidget::initTestCase() |
|
243 |
{ |
|
244 |
qMetaTypeId<QModelIndex>(); |
|
245 |
qMetaTypeId<Qt::Orientation>(); |
|
246 |
qRegisterMetaType<QTreeWidgetItem*>("QTreeWidgetItem*"); |
|
247 |
||
248 |
testWidget = new CustomTreeWidget(); |
|
249 |
testWidget->show(); |
|
250 |
#ifdef Q_WS_X11 |
|
251 |
qt_x11_wait_for_window_manager(testWidget); |
|
252 |
#endif |
|
253 |
} |
|
254 |
||
255 |
void tst_QTreeWidget::cleanupTestCase() |
|
256 |
{ |
|
257 |
testWidget->hide(); |
|
258 |
delete testWidget; |
|
259 |
} |
|
260 |
||
261 |
void tst_QTreeWidget::init() |
|
262 |
{ |
|
263 |
testWidget->clear(); |
|
264 |
testWidget->setColumnCount(2); |
|
265 |
} |
|
266 |
||
267 |
void tst_QTreeWidget::cleanup() |
|
268 |
{ |
|
269 |
} |
|
270 |
||
271 |
TreeItem *operator<<(TreeItem *parent, const TreeItemList &children) { |
|
272 |
for (int i = 0; i < children.count(); ++i) |
|
273 |
parent->addChild(children.at(i)); |
|
274 |
return parent; |
|
275 |
} |
|
276 |
||
277 |
static void populate(QTreeWidget *widget, const TreeItemList &topLevelItems, |
|
278 |
TreeItem *headerItem = 0) |
|
279 |
{ |
|
280 |
widget->clear(); |
|
281 |
widget->setHeaderItem(headerItem); |
|
282 |
foreach (TreeItem *item, topLevelItems) |
|
283 |
widget->addTopLevelItem(item); |
|
284 |
} |
|
285 |
||
286 |
void tst_QTreeWidget::addTopLevelItem() |
|
287 |
{ |
|
288 |
QTreeWidget tree; |
|
289 |
QCOMPARE(tree.topLevelItemCount(), 0); |
|
290 |
||
291 |
// try to add 0 |
|
292 |
tree.addTopLevelItem(0); |
|
293 |
QCOMPARE(tree.topLevelItemCount(), 0); |
|
294 |
QCOMPARE(tree.indexOfTopLevelItem(0), -1); |
|
295 |
||
296 |
// add one at a time |
|
297 |
QList<TreeItem*> tops; |
|
298 |
for (int i = 0; i < 10; ++i) { |
|
299 |
TreeItem *ti = new TreeItem(); |
|
300 |
QCOMPARE(tree.indexOfTopLevelItem(ti), -1); |
|
301 |
tree.addTopLevelItem(ti); |
|
302 |
QCOMPARE(tree.topLevelItemCount(), i+1); |
|
303 |
QCOMPARE(tree.topLevelItem(i), ti); |
|
304 |
QCOMPARE(tree.topLevelItem(-1), static_cast<TreeItem*>(0)); |
|
305 |
QCOMPARE(tree.indexOfTopLevelItem(ti), i); |
|
306 |
QCOMPARE(ti->parent(), static_cast<TreeItem*>(0)); |
|
307 |
tree.addTopLevelItem(ti); |
|
308 |
QCOMPARE(tree.topLevelItemCount(), i+1); |
|
309 |
tops.append(ti); |
|
310 |
} |
|
311 |
||
312 |
// delete one at a time |
|
313 |
while (!tops.isEmpty()) { |
|
314 |
TreeItem *ti = tops.takeFirst(); |
|
315 |
delete ti; |
|
316 |
QCOMPARE(tree.topLevelItemCount(), tops.count()); |
|
317 |
for (int i = 0; i < tops.count(); ++i) |
|
318 |
QCOMPARE(tree.topLevelItem(i), tops.at(i)); |
|
319 |
} |
|
320 |
||
321 |
// add none |
|
322 |
{ |
|
323 |
int count = tree.topLevelItemCount(); |
|
324 |
tree.addTopLevelItems(tops); |
|
325 |
QCOMPARE(tree.topLevelItemCount(), count); |
|
326 |
} |
|
327 |
||
328 |
// add many at a time |
|
329 |
{ |
|
330 |
const int count = 10; |
|
331 |
for (int i = 0; i < 100; i += count) { |
|
332 |
tops.clear(); |
|
333 |
for (int j = 0; j < count; ++j) |
|
334 |
tops << new TreeItem(QStringList() << QString("%0").arg(j)); |
|
335 |
tree.addTopLevelItems(tops); |
|
336 |
QCOMPARE(tree.topLevelItemCount(), count + i); |
|
337 |
for (int j = 0; j < count; ++j) |
|
338 |
QCOMPARE(tree.topLevelItem(i+j), tops.at(j)); |
|
339 |
||
340 |
tree.addTopLevelItems(tops); |
|
341 |
QCOMPARE(tree.topLevelItemCount(), count + i); |
|
342 |
} |
|
343 |
} |
|
344 |
||
345 |
// insert |
|
346 |
{ |
|
347 |
tops.clear(); |
|
348 |
for (int i = 0; i < 10; ++i) |
|
349 |
tops << new TreeItem(); |
|
350 |
int count = tree.topLevelItemCount(); |
|
351 |
tree.insertTopLevelItems(100000, tops); |
|
352 |
// ### fixme |
|
353 |
QCOMPARE(tree.topLevelItemCount(), count + 10); |
|
354 |
} |
|
355 |
} |
|
356 |
||
357 |
void tst_QTreeWidget::currentItem_data() |
|
358 |
{ |
|
359 |
QTest::addColumn<TreeItemList>("topLevelItems"); |
|
360 |
||
361 |
QTest::newRow("only top-level items, 2 columns") |
|
362 |
<< (TreeItemList() |
|
363 |
<< new TreeItem(QStringList() << "a" << "b") |
|
364 |
<< new TreeItem(QStringList() << "c" << "d")); |
|
365 |
TreeItemList lst; |
|
366 |
lst << (new TreeItem(QStringList() << "a" << "b") |
|
367 |
<< (TreeItemList() |
|
368 |
<< new TreeItem(QStringList() << "c" << "d") |
|
369 |
<< new TreeItem(QStringList() << "c" << "d") |
|
370 |
) |
|
371 |
) |
|
372 |
<< (new TreeItem(QStringList() << "e" << "f") |
|
373 |
<< (TreeItemList() |
|
374 |
<< new TreeItem(QStringList() << "g" << "h") |
|
375 |
<< new TreeItem(QStringList() << "g" << "h") |
|
376 |
) |
|
377 |
); |
|
378 |
QTest::newRow("hierarchy, 2 columns") << lst; |
|
379 |
} |
|
380 |
||
381 |
void tst_QTreeWidget::currentItem() |
|
382 |
{ |
|
383 |
QFETCH(TreeItemList, topLevelItems); |
|
384 |
||
385 |
QTreeWidget tree; |
|
386 |
tree.show(); |
|
387 |
populate(&tree, topLevelItems, new TreeItem(QStringList() << "1" << "2")); |
|
388 |
QTreeWidgetItem *previous = 0; |
|
389 |
for (int x = 0; x < 2; ++x) { |
|
390 |
tree.setSelectionBehavior(x ? QAbstractItemView::SelectItems |
|
391 |
: QAbstractItemView::SelectRows); |
|
392 |
QSignalSpy currentItemChangedSpy( |
|
393 |
&tree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); |
|
394 |
QSignalSpy itemSelectionChangedSpy( |
|
395 |
&tree, SIGNAL(itemSelectionChanged())); |
|
396 |
||
397 |
QTreeWidgetItemIterator it(&tree); |
|
398 |
// do all items |
|
399 |
while (QTreeWidgetItem *item = (*it++)) { |
|
400 |
tree.setCurrentItem(item); |
|
401 |
QCOMPARE(tree.currentItem(), item); |
|
402 |
||
403 |
QCOMPARE(currentItemChangedSpy.count(), 1); |
|
404 |
QVariantList args = currentItemChangedSpy.takeFirst(); |
|
405 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
406 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(1)), previous); |
|
407 |
||
408 |
QCOMPARE(itemSelectionChangedSpy.count(), 1); |
|
409 |
itemSelectionChangedSpy.clear(); |
|
410 |
||
411 |
previous = item; |
|
412 |
// do all columns |
|
413 |
for (int col = 0; col < item->columnCount(); ++col) { |
|
414 |
tree.setCurrentItem(item, col); |
|
415 |
QCOMPARE(tree.currentItem(), item); |
|
416 |
QCOMPARE(tree.currentColumn(), col); |
|
417 |
||
418 |
if (!currentItemChangedSpy.isEmpty()) { |
|
419 |
// ### we get a currentItemChanged() when what really |
|
420 |
// changed was just currentColumn(). Should it be like this? |
|
421 |
QCOMPARE(currentItemChangedSpy.count(), 1); |
|
422 |
QVariantList args = currentItemChangedSpy.takeFirst(); |
|
423 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
424 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(1)), item); |
|
425 |
if (tree.selectionBehavior() == QAbstractItemView::SelectItems) { |
|
426 |
QCOMPARE(itemSelectionChangedSpy.count(), 1); |
|
427 |
itemSelectionChangedSpy.clear(); |
|
428 |
} else { |
|
429 |
QCOMPARE(itemSelectionChangedSpy.count(), 0); |
|
430 |
} |
|
431 |
} |
|
432 |
} |
|
433 |
} |
|
434 |
} |
|
435 |
||
436 |
// can't set the headerItem to be the current item |
|
437 |
tree.setCurrentItem(tree.headerItem()); |
|
438 |
QCOMPARE(tree.currentItem(), static_cast<TreeItem*>(0)); |
|
439 |
} |
|
440 |
||
441 |
void tst_QTreeWidget::editItem_data() |
|
442 |
{ |
|
443 |
QTest::addColumn<TreeItemList>("topLevelItems"); |
|
444 |
||
445 |
{ |
|
446 |
TreeItemList list; |
|
447 |
for (int i = 0; i < 10; i++) { |
|
448 |
TreeItem *item = new TreeItem(QStringList() << "col1" << "col2"); |
|
449 |
if ((i & 1) == 0) |
|
450 |
item->setFlags(item->flags() | Qt::ItemIsEditable); |
|
451 |
else |
|
452 |
item->setFlags(item->flags() & ~Qt::ItemIsEditable); |
|
453 |
list << item; |
|
454 |
} |
|
455 |
QTest::newRow("2 columns, only even items editable") |
|
456 |
<< list; |
|
457 |
} |
|
458 |
} |
|
459 |
||
460 |
void tst_QTreeWidget::editItem() |
|
461 |
{ |
|
462 |
QFETCH(TreeItemList, topLevelItems); |
|
463 |
||
464 |
QTreeWidget tree; |
|
465 |
populate(&tree, topLevelItems, new TreeItem(QStringList() << "1" << "2")); |
|
466 |
tree.show(); |
|
467 |
||
468 |
QSignalSpy itemChangedSpy( |
|
469 |
&tree, SIGNAL(itemChanged(QTreeWidgetItem*,int))); |
|
470 |
||
471 |
QTreeWidgetItemIterator it(&tree); |
|
472 |
while (QTreeWidgetItem *item = (*it++)) { |
|
473 |
for (int col = 0; col < item->columnCount(); ++col) { |
|
474 |
if (!(item->flags() & Qt::ItemIsEditable)) |
|
475 |
QTest::ignoreMessage(QtWarningMsg, "edit: editing failed"); |
|
476 |
tree.editItem(item, col); |
|
477 |
QApplication::instance()->processEvents(); |
|
478 |
QApplication::instance()->processEvents(); |
|
479 |
QLineEdit *editor = qFindChild<QLineEdit*>(&tree); |
|
480 |
if (editor) { |
|
481 |
QVERIFY(item->flags() & Qt::ItemIsEditable); |
|
482 |
QCOMPARE(editor->selectedText(), editor->text()); |
|
483 |
QTest::keyClick(editor, Qt::Key_A); |
|
484 |
QTest::keyClick(editor, Qt::Key_Enter); |
|
485 |
QApplication::instance()->processEvents(); |
|
486 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
487 |
QVariantList args = itemChangedSpy.takeFirst(); |
|
488 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
489 |
QCOMPARE(qvariant_cast<int>(args.at(1)), col); |
|
490 |
} else { |
|
491 |
QVERIFY(!(item->flags() & Qt::ItemIsEditable)); |
|
492 |
} |
|
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
||
497 |
void tst_QTreeWidget::takeItem_data() |
|
498 |
{ |
|
499 |
QTest::addColumn<int>("index"); |
|
500 |
QTest::addColumn<bool>("topLevel"); |
|
501 |
QTest::addColumn<bool>("outOfBounds"); |
|
502 |
||
503 |
QTest::newRow("First, topLevel") << 0 << true << false; |
|
504 |
QTest::newRow("Last, topLevel") << 2 << true << false; |
|
505 |
QTest::newRow("Middle, topLevel") << 1 << true << false; |
|
506 |
QTest::newRow("Out of bounds, toplevel, (index: -1)") << -1 << true << true; |
|
507 |
QTest::newRow("Out of bounds, toplevel, (index: 3)") << 3 << true << true; |
|
508 |
||
509 |
QTest::newRow("First, child of topLevel") << 0 << false << false; |
|
510 |
QTest::newRow("Last, child of topLevel") << 2 << false << false; |
|
511 |
QTest::newRow("Middle, child of topLevel") << 1 << false << false; |
|
512 |
QTest::newRow("Out of bounds, child of toplevel, (index: -1)") << -1 << false << true; |
|
513 |
QTest::newRow("Out of bounds, child of toplevel, (index: 3)") << 3 << false << true; |
|
514 |
} |
|
515 |
||
516 |
void tst_QTreeWidget::takeItem() |
|
517 |
{ |
|
518 |
QFETCH(int, index); |
|
519 |
QFETCH(bool, topLevel); |
|
520 |
QFETCH(bool, outOfBounds); |
|
521 |
||
522 |
for (int i=0; i<3; ++i) { |
|
523 |
QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); |
|
524 |
top->setText(0, QString("top%1").arg(i)); |
|
525 |
for (int j=0; j<3; ++j) { |
|
526 |
QTreeWidgetItem *child = new QTreeWidgetItem(top); |
|
527 |
child->setText(0, QString("child%1").arg(j)); |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
QCOMPARE(testWidget->topLevelItemCount(), 3); |
|
532 |
QCOMPARE(testWidget->topLevelItem(0)->childCount(), 3); |
|
533 |
||
534 |
if (topLevel) { |
|
535 |
int count = testWidget->topLevelItemCount(); |
|
536 |
QTreeWidgetItem *item = testWidget->takeTopLevelItem(index); |
|
537 |
if (outOfBounds) { |
|
538 |
QCOMPARE(item, (QTreeWidgetItem *)0); |
|
539 |
QCOMPARE(count, testWidget->topLevelItemCount()); |
|
540 |
} else { |
|
541 |
QCOMPARE(item->text(0), QString("top%1").arg(index)); |
|
542 |
QCOMPARE(count-1, testWidget->topLevelItemCount()); |
|
543 |
delete item; |
|
544 |
} |
|
545 |
} else { |
|
546 |
int count = testWidget->topLevelItem(0)->childCount(); |
|
547 |
QTreeWidgetItem *item = testWidget->topLevelItem(0)->takeChild(index); |
|
548 |
if (outOfBounds) { |
|
549 |
QCOMPARE(item, (QTreeWidgetItem *)0); |
|
550 |
QCOMPARE(count, testWidget->topLevelItem(0)->childCount()); |
|
551 |
} else { |
|
552 |
QCOMPARE(item->text(0), QString("child%1").arg(index)); |
|
553 |
QCOMPARE(count-1, testWidget->topLevelItem(0)->childCount()); |
|
554 |
delete item; |
|
555 |
} |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
void tst_QTreeWidget::removeChild_data() |
|
560 |
{ |
|
561 |
QTest::addColumn<int>("childCount"); |
|
562 |
QTest::addColumn<int>("removeAt"); |
|
563 |
||
564 |
QTest::newRow("10 remove 3") << 10 << 3; |
|
565 |
} |
|
566 |
||
567 |
void tst_QTreeWidget::removeChild() |
|
568 |
{ |
|
569 |
QFETCH(int, childCount); |
|
570 |
QFETCH(int, removeAt); |
|
571 |
||
572 |
QTreeWidgetItem *root = new QTreeWidgetItem; |
|
573 |
for (int i = 0; i < childCount; ++i) |
|
574 |
new QTreeWidgetItem(root, QStringList(QString::number(i))); |
|
575 |
||
576 |
QCOMPARE(root->childCount(), childCount); |
|
577 |
for (int j = 0; j < childCount; ++j) |
|
578 |
QCOMPARE(root->child(j)->text(0), QString::number(j)); |
|
579 |
||
580 |
QTreeWidgetItem *remove = root->child(removeAt); |
|
581 |
root->removeChild(remove); |
|
582 |
||
583 |
QCOMPARE(root->childCount(), childCount - 1); |
|
584 |
for (int k = 0; k < childCount; ++k) { |
|
585 |
if (k == removeAt) |
|
586 |
QCOMPARE(remove->text(0), QString::number(k)); |
|
587 |
else if (k < removeAt) |
|
588 |
QCOMPARE(root->child(k)->text(0), QString::number(k)); |
|
589 |
else if (k > removeAt) |
|
590 |
QCOMPARE(root->child(k - 1)->text(0), QString::number(k)); |
|
591 |
} |
|
592 |
delete root; |
|
593 |
} |
|
594 |
||
595 |
void tst_QTreeWidget::setItemHidden() |
|
596 |
{ |
|
597 |
QTreeWidgetItem *parent = new QTreeWidgetItem(testWidget); |
|
598 |
parent->setText(0, "parent"); |
|
599 |
QTreeWidgetItem *child = new QTreeWidgetItem(parent); |
|
600 |
child->setText(0, "child"); |
|
601 |
QVERIFY(child->parent()); |
|
602 |
||
603 |
testWidget->expandItem(parent); |
|
604 |
testWidget->scrollToItem(child); |
|
605 |
||
606 |
QVERIFY(testWidget->visualItemRect(parent).isValid() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
607 |
&& testWidget->viewport()->rect().intersects(testWidget->visualItemRect(parent))); |
0 | 608 |
QVERIFY(testWidget->visualItemRect(child).isValid() |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
&& testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child))); |
0 | 610 |
|
611 |
QVERIFY(!testWidget->isItemHidden(parent)); |
|
612 |
QVERIFY(!testWidget->isItemHidden(child)); |
|
613 |
||
614 |
testWidget->setItemHidden(parent, true); |
|
615 |
||
616 |
QVERIFY(!(testWidget->visualItemRect(parent).isValid() |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
617 |
&& testWidget->viewport()->rect().intersects(testWidget->visualItemRect(parent)))); |
0 | 618 |
QVERIFY(!(testWidget->visualItemRect(child).isValid() |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
619 |
&& testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child)))); |
0 | 620 |
|
621 |
QVERIFY(testWidget->isItemHidden(parent)); |
|
622 |
QVERIFY(!testWidget->isItemHidden(child)); |
|
623 |
||
624 |
// From task 78670 (This caused an core dump) |
|
625 |
// Check if we can set an item visible if it already is visible. |
|
626 |
testWidget->setItemHidden(parent, false); |
|
627 |
testWidget->setItemHidden(parent, false); |
|
628 |
QVERIFY(!testWidget->isItemHidden(parent)); |
|
629 |
||
630 |
||
631 |
// hide, hide and then unhide. |
|
632 |
testWidget->setItemHidden(parent, true); |
|
633 |
testWidget->setItemHidden(parent, true); |
|
634 |
testWidget->setItemHidden(parent, false); |
|
635 |
QVERIFY(!testWidget->isItemHidden(parent)); |
|
636 |
||
637 |
||
638 |
} |
|
639 |
||
640 |
||
641 |
void tst_QTreeWidget::setItemHidden2() |
|
642 |
{ |
|
643 |
// From Task 78587 |
|
644 |
QStringList hl; |
|
645 |
hl << "ID" << "Desc"; |
|
646 |
testWidget->setColumnCount(hl.count()); |
|
647 |
testWidget->setHeaderLabels(hl); |
|
648 |
testWidget->setSortingEnabled(true); |
|
649 |
||
650 |
QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); |
|
651 |
QTreeWidgetItem *leaf = 0; |
|
652 |
top->setText(0, "ItemList"); |
|
653 |
for (int i = 1; i <= 4; i++) { |
|
654 |
leaf = new QTreeWidgetItem(top); |
|
655 |
leaf->setText(0, QString().sprintf("%d", i)); |
|
656 |
leaf->setText(1, QString().sprintf("Item %d", i)); |
|
657 |
} |
|
658 |
||
659 |
if (testWidget->topLevelItemCount() > 0) { |
|
660 |
top = testWidget->topLevelItem(0); |
|
661 |
testWidget->setItemExpanded(top, true); |
|
662 |
} |
|
663 |
||
664 |
if (testWidget->topLevelItemCount() > 0) { |
|
665 |
top = testWidget->topLevelItem(0); |
|
666 |
for (int i = 0; i < top->childCount(); i++) { |
|
667 |
leaf = top->child(i); |
|
668 |
if (leaf->text(0).toInt() % 2 == 0) { |
|
669 |
if (!testWidget->isItemHidden(leaf)) { |
|
670 |
testWidget->setItemHidden(leaf, true); |
|
671 |
} |
|
672 |
} |
|
673 |
} |
|
674 |
} |
|
675 |
} |
|
676 |
||
677 |
||
678 |
void tst_QTreeWidget::selectedItems_data() |
|
679 |
{ |
|
680 |
QTest::addColumn<int>("topLevel"); |
|
681 |
QTest::addColumn<int>("children"); |
|
682 |
QTest::addColumn<bool>("closeTopLevel"); |
|
683 |
QTest::addColumn<ListIntList>("selectedItems"); |
|
684 |
QTest::addColumn<ListIntList>("hiddenItems"); |
|
685 |
QTest::addColumn<ListIntList>("expectedItems"); |
|
686 |
||
687 |
ListIntList selectedItems; |
|
688 |
ListIntList hiddenItems; |
|
689 |
ListIntList expectedItems; |
|
690 |
||
691 |
selectedItems.clear(); hiddenItems.clear(); expectedItems.clear(); |
|
692 |
selectedItems |
|
693 |
<< (IntList() |
|
694 |
<< 0); |
|
695 |
expectedItems |
|
696 |
<< (IntList() << 0); |
|
697 |
QTest::newRow("2 top with 2 children, closed, top0 selected, no hidden") |
|
698 |
<< 2 << 2 << true << selectedItems << hiddenItems << expectedItems; |
|
699 |
||
700 |
selectedItems.clear(); hiddenItems.clear(); expectedItems.clear(); |
|
701 |
selectedItems |
|
702 |
<< (IntList() |
|
703 |
<< 0 << 0); |
|
704 |
expectedItems |
|
705 |
<< (IntList() << 0 << 0); |
|
706 |
QTest::newRow("2 top with 2 children, closed, top0child0 selected, no hidden") |
|
707 |
<< 2 << 2 << true << selectedItems << hiddenItems << expectedItems; |
|
708 |
||
709 |
selectedItems.clear(); hiddenItems.clear(); expectedItems.clear(); |
|
710 |
selectedItems |
|
711 |
<< (IntList() |
|
712 |
<< 0 << 0); |
|
713 |
expectedItems |
|
714 |
<< (IntList() |
|
715 |
<< 0 << 0); |
|
716 |
QTest::newRow("2 top with 2 children, open, top0child0 selected, no hidden") |
|
717 |
<< 2 << 2 << false << selectedItems << hiddenItems << expectedItems; |
|
718 |
||
719 |
selectedItems.clear(); hiddenItems.clear(); expectedItems.clear(); |
|
720 |
selectedItems << (IntList() << 0); |
|
721 |
hiddenItems << (IntList() << 0); |
|
722 |
QTest::newRow("2 top with 2 children, closed, top0 selected, top0 hidden") |
|
723 |
<< 2 << 2 << true << selectedItems << hiddenItems << expectedItems; |
|
724 |
||
725 |
selectedItems.clear(); hiddenItems.clear(); expectedItems.clear(); |
|
726 |
selectedItems << (IntList() << 0 << 0); |
|
727 |
hiddenItems << (IntList() << 0); |
|
728 |
expectedItems << (IntList() << 0 << 0); |
|
729 |
QTest::newRow("2 top with 2 children, closed, top0child0 selected, top0 hidden") |
|
730 |
<< 2 << 2 << true << selectedItems << hiddenItems << expectedItems; |
|
731 |
||
732 |
selectedItems.clear(); hiddenItems.clear(); expectedItems.clear(); |
|
733 |
selectedItems |
|
734 |
<< (IntList() << 0) |
|
735 |
<< (IntList() << 0 << 0) |
|
736 |
<< (IntList() << 0 << 1) |
|
737 |
<< (IntList() << 1) |
|
738 |
<< (IntList() << 1 << 0) |
|
739 |
<< (IntList() << 1 << 1); |
|
740 |
expectedItems |
|
741 |
<< (IntList() << 0) |
|
742 |
<< (IntList() << 0 << 0) |
|
743 |
<< (IntList() << 0 << 1) |
|
744 |
<< (IntList() << 1) |
|
745 |
<< (IntList() << 1 << 0) |
|
746 |
<< (IntList() << 1 << 1); |
|
747 |
QTest::newRow("2 top with 2 children, closed, all selected, no hidden") |
|
748 |
<< 2 << 2 << true << selectedItems << hiddenItems << expectedItems; |
|
749 |
||
750 |
||
751 |
selectedItems.clear(); hiddenItems.clear(); expectedItems.clear(); |
|
752 |
selectedItems |
|
753 |
<< (IntList() << 0) |
|
754 |
<< (IntList() << 0 << 0) |
|
755 |
<< (IntList() << 0 << 1) |
|
756 |
<< (IntList() << 1) |
|
757 |
<< (IntList() << 1 << 0) |
|
758 |
<< (IntList() << 1 << 1); |
|
759 |
hiddenItems |
|
760 |
<< (IntList() << 0); |
|
761 |
expectedItems |
|
762 |
//<< (IntList() << 0) |
|
763 |
<< (IntList() << 0 << 0) |
|
764 |
<< (IntList() << 0 << 1) |
|
765 |
<< (IntList() << 1) |
|
766 |
<< (IntList() << 1 << 0) |
|
767 |
<< (IntList() << 1 << 1); |
|
768 |
QTest::newRow("2 top with 2 children, closed, all selected, top0 hidden") |
|
769 |
<< 2 << 2 << true << selectedItems << hiddenItems << expectedItems; |
|
770 |
||
771 |
selectedItems.clear(); hiddenItems.clear(); expectedItems.clear(); |
|
772 |
selectedItems |
|
773 |
<< (IntList() << 0) |
|
774 |
<< (IntList() << 0 << 0) |
|
775 |
<< (IntList() << 0 << 1) |
|
776 |
<< (IntList() << 1) |
|
777 |
<< (IntList() << 1 << 0) |
|
778 |
<< (IntList() << 1 << 1); |
|
779 |
hiddenItems |
|
780 |
<< (IntList() << 0 << 1) |
|
781 |
<< (IntList() << 1); |
|
782 |
expectedItems |
|
783 |
<< (IntList() << 0) |
|
784 |
<< (IntList() << 0 << 0) |
|
785 |
//<< (IntList() << 0 << 1) |
|
786 |
//<< (IntList() << 1) |
|
787 |
<< (IntList() << 1 << 0) |
|
788 |
<< (IntList() << 1 << 1); |
|
789 |
||
790 |
QTest::newRow("2 top with 2 children, closed, all selected, top0child1 and top1") |
|
791 |
<< 2 << 2 << true << selectedItems << hiddenItems << expectedItems; |
|
792 |
||
793 |
} |
|
794 |
||
795 |
void tst_QTreeWidget::selectedItems() |
|
796 |
{ |
|
797 |
QFETCH(int, topLevel); |
|
798 |
QFETCH(int, children); |
|
799 |
QFETCH(bool, closeTopLevel); |
|
800 |
QFETCH(ListIntList, selectedItems); |
|
801 |
QFETCH(ListIntList, hiddenItems); |
|
802 |
QFETCH(ListIntList, expectedItems); |
|
803 |
||
804 |
// create items |
|
805 |
for (int t=0; t<topLevel; ++t) { |
|
806 |
QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); |
|
807 |
top->setText(0, QString("top%1").arg(t)); |
|
808 |
for (int c=0; c<children; ++c) { |
|
809 |
QTreeWidgetItem *child = new QTreeWidgetItem(top); |
|
810 |
child->setText(0, QString("top%1child%2").arg(t).arg(c)); |
|
811 |
} |
|
812 |
} |
|
813 |
||
814 |
// set selected |
|
815 |
foreach (IntList itemPath, selectedItems) { |
|
816 |
QTreeWidgetItem *item = 0; |
|
817 |
foreach(int index, itemPath) { |
|
818 |
if (!item) |
|
819 |
item = testWidget->topLevelItem(index); |
|
820 |
else |
|
821 |
item = item->child(index); |
|
822 |
} |
|
823 |
testWidget->setItemSelected(item, true); |
|
824 |
} |
|
825 |
||
826 |
// hide rows |
|
827 |
foreach (IntList itemPath, hiddenItems) { |
|
828 |
QTreeWidgetItem *item = 0; |
|
829 |
foreach(int index, itemPath) { |
|
830 |
if (!item) |
|
831 |
item = testWidget->topLevelItem(index); |
|
832 |
else |
|
833 |
item = item->child(index); |
|
834 |
} |
|
835 |
testWidget->setItemHidden(item, true); |
|
836 |
} |
|
837 |
||
838 |
// open/close toplevel |
|
839 |
for (int i=0; i<testWidget->topLevelItemCount(); ++i) { |
|
840 |
if (closeTopLevel) |
|
841 |
testWidget->collapseItem(testWidget->topLevelItem(i)); |
|
842 |
else |
|
843 |
testWidget->expandItem(testWidget->topLevelItem(i)); |
|
844 |
} |
|
845 |
||
846 |
// check selectedItems |
|
847 |
QList<QTreeWidgetItem*> sel = testWidget->selectedItems(); |
|
848 |
QCOMPARE(sel.count(), expectedItems.count()); |
|
849 |
foreach (IntList itemPath, expectedItems) { |
|
850 |
QTreeWidgetItem *item = 0; |
|
851 |
foreach(int index, itemPath) { |
|
852 |
if (!item) |
|
853 |
item = testWidget->topLevelItem(index); |
|
854 |
else |
|
855 |
item = item->child(index); |
|
856 |
} |
|
857 |
if (item) |
|
858 |
QVERIFY(sel.contains(item)); |
|
859 |
} |
|
860 |
||
861 |
// compare isSelected |
|
862 |
for (int t=0; t<testWidget->topLevelItemCount(); ++t) { |
|
863 |
QTreeWidgetItem *top = testWidget->topLevelItem(t); |
|
864 |
if (testWidget->isItemSelected(top) && !testWidget->isItemHidden(top)) |
|
865 |
QVERIFY(sel.contains(top)); |
|
866 |
for (int c=0; c<top->childCount(); ++c) { |
|
867 |
QTreeWidgetItem *child = top->child(c); |
|
868 |
if (testWidget->isItemSelected(child) && !testWidget->isItemHidden(child)) |
|
869 |
QVERIFY(sel.contains(child)); |
|
870 |
} |
|
871 |
} |
|
872 |
||
873 |
// Possible to select null without crashing? |
|
874 |
testWidget->setItemSelected(0, true); |
|
875 |
QVERIFY(!testWidget->isItemSelected(0)); |
|
876 |
||
877 |
// unselect |
|
878 |
foreach (IntList itemPath, selectedItems) { |
|
879 |
QTreeWidgetItem *item = 0; |
|
880 |
foreach(int index, itemPath) { |
|
881 |
if (!item) |
|
882 |
item = testWidget->topLevelItem(index); |
|
883 |
else |
|
884 |
item = item->child(index); |
|
885 |
} |
|
886 |
testWidget->setItemSelected(item, false); |
|
887 |
} |
|
888 |
QCOMPARE(testWidget->selectedItems().count(), 0); |
|
889 |
} |
|
890 |
||
891 |
void tst_QTreeWidget::itemAssignment() |
|
892 |
{ |
|
893 |
// create item with children and parent but not insert in the view |
|
894 |
QTreeWidgetItem grandParent; |
|
895 |
QTreeWidgetItem *parent = new QTreeWidgetItem(&grandParent); |
|
896 |
parent->setText(0, "foo"); |
|
897 |
parent->setText(1, "bar"); |
|
898 |
for (int i=0; i<5; ++i) { |
|
899 |
QTreeWidgetItem *child = new QTreeWidgetItem(parent); |
|
900 |
child->setText(0, "bingo"); |
|
901 |
child->setText(1, "bango"); |
|
902 |
} |
|
903 |
QCOMPARE(parent->parent(), &grandParent); |
|
904 |
QVERIFY(!parent->treeWidget()); |
|
905 |
QCOMPARE(parent->columnCount(), 2); |
|
906 |
QCOMPARE(parent->text(0), QString("foo")); |
|
907 |
QCOMPARE(parent->childCount(), 5); |
|
908 |
QCOMPARE(parent->child(0)->parent(), parent); |
|
909 |
||
910 |
// create item which is inserted in the widget |
|
911 |
QTreeWidgetItem item(testWidget); |
|
912 |
item.setText(0, "baz"); |
|
913 |
QVERIFY(!item.parent()); |
|
914 |
QCOMPARE(item.treeWidget(), static_cast<QTreeWidget *>(testWidget)); |
|
915 |
QCOMPARE(item.columnCount(), 1); |
|
916 |
QCOMPARE(item.text(0), QString("baz")); |
|
917 |
QCOMPARE(item.childCount(), 0); |
|
918 |
||
919 |
// assign and test |
|
920 |
*parent = item; |
|
921 |
QCOMPARE(parent->parent(), &grandParent); |
|
922 |
QVERIFY(!parent->treeWidget()); |
|
923 |
QCOMPARE(parent->columnCount(), 1); |
|
924 |
QCOMPARE(parent->text(0), QString("baz")); |
|
925 |
QCOMPARE(parent->childCount(), 5); |
|
926 |
QCOMPARE(parent->child(0)->parent(), parent); |
|
927 |
} |
|
928 |
||
929 |
void tst_QTreeWidget::clone_data() |
|
930 |
{ |
|
931 |
QTest::addColumn<int>("column"); |
|
932 |
QTest::addColumn<int>("topLevelIndex"); |
|
933 |
QTest::addColumn<int>("childIndex"); |
|
934 |
QTest::addColumn<QStringList>("topLevelText"); |
|
935 |
QTest::addColumn<QStringList>("childText"); |
|
936 |
QTest::addColumn<bool>("cloneChild"); |
|
937 |
||
938 |
QTest::newRow("clone parent with child") << 0 << 0 << 0 |
|
939 |
<< (QStringList() << "some text") |
|
940 |
<< (QStringList() << "more text") |
|
941 |
<< false; |
|
942 |
||
943 |
QTest::newRow("clone child") << 0 << 0 << 0 |
|
944 |
<< (QStringList() << "some text") |
|
945 |
<< (QStringList() << "more text") |
|
946 |
<< true; |
|
947 |
} |
|
948 |
||
949 |
void tst_QTreeWidget::clone() |
|
950 |
{ |
|
951 |
QFETCH(int, column); |
|
952 |
QFETCH(int, topLevelIndex); |
|
953 |
QFETCH(int, childIndex); |
|
954 |
QFETCH(QStringList, topLevelText); |
|
955 |
QFETCH(QStringList, childText); |
|
956 |
QFETCH(bool, cloneChild); |
|
957 |
||
958 |
for (int i = 0; i < topLevelText.count(); ++i) { |
|
959 |
QTreeWidgetItem *item = new QTreeWidgetItem(testWidget); |
|
960 |
item->setText(column, topLevelText.at(i)); |
|
961 |
for (int j = 0; j < childText.count(); ++j) { |
|
962 |
QTreeWidgetItem *child = new QTreeWidgetItem(item); |
|
963 |
child->setText(column, childText.at(j)); |
|
964 |
} |
|
965 |
} |
|
966 |
||
967 |
QTreeWidgetItem *original = testWidget->topLevelItem(topLevelIndex); |
|
968 |
QTreeWidgetItem *copy = original->clone(); |
|
969 |
QCOMPARE(copy->text(column), original->text(column)); |
|
970 |
QCOMPARE(copy->childCount(), original->childCount()); |
|
971 |
QVERIFY(!copy->parent()); |
|
972 |
QVERIFY(!copy->treeWidget()); |
|
973 |
||
974 |
QTreeWidgetItem *originalChild = original->child(childIndex); |
|
975 |
QTreeWidgetItem *copiedChild = cloneChild ? originalChild->clone() : copy->child(childIndex); |
|
976 |
QVERIFY(copiedChild != originalChild); |
|
977 |
QCOMPARE(copiedChild->text(column), originalChild->text(column)); |
|
978 |
QCOMPARE(copiedChild->childCount(), originalChild->childCount()); |
|
979 |
QCOMPARE(copiedChild->parent(), cloneChild ? 0 : copy); |
|
980 |
QVERIFY(!copiedChild->treeWidget()); |
|
981 |
if (cloneChild) |
|
982 |
delete copiedChild; |
|
983 |
delete copy; |
|
984 |
} |
|
985 |
||
986 |
void tst_QTreeWidget::expand_data() |
|
987 |
{ |
|
988 |
QTest::addColumn<int>("topLevelIndex"); |
|
989 |
QTest::addColumn<int>("topLevelCount"); |
|
990 |
QTest::addColumn<int>("childIndex"); |
|
991 |
QTest::addColumn<int>("childCount"); |
|
992 |
||
993 |
QTest::newRow("the only test data for now") << 0 << 1 << 0 << 1; |
|
994 |
} |
|
995 |
||
996 |
void tst_QTreeWidget::expand() |
|
997 |
{ |
|
998 |
QFETCH(int, topLevelIndex); |
|
999 |
QFETCH(int, topLevelCount); |
|
1000 |
QFETCH(int, childIndex); |
|
1001 |
QFETCH(int, childCount); |
|
1002 |
||
1003 |
for (int i = 0; i < topLevelCount; ++i) { |
|
1004 |
QTreeWidgetItem *item = new QTreeWidgetItem(testWidget); |
|
1005 |
for (int j = 0; j < childCount; ++j) |
|
1006 |
new QTreeWidgetItem(item); |
|
1007 |
} |
|
1008 |
||
1009 |
QTreeWidgetItem *topLevelItem = testWidget->topLevelItem(topLevelIndex); |
|
1010 |
QTreeWidgetItem *childItem = topLevelItem->child(childIndex); |
|
1011 |
||
1012 |
QVERIFY(!testWidget->isItemExpanded(topLevelItem)); |
|
1013 |
testWidget->setItemExpanded(topLevelItem, true); |
|
1014 |
QVERIFY(testWidget->isItemExpanded(topLevelItem)); |
|
1015 |
||
1016 |
QVERIFY(!testWidget->isItemExpanded(childItem)); |
|
1017 |
testWidget->setItemExpanded(childItem, true); |
|
1018 |
QVERIFY(testWidget->isItemExpanded(childItem)); |
|
1019 |
||
1020 |
QVERIFY(testWidget->isItemExpanded(topLevelItem)); |
|
1021 |
testWidget->setItemExpanded(topLevelItem, false); |
|
1022 |
QVERIFY(!testWidget->isItemExpanded(topLevelItem)); |
|
1023 |
||
1024 |
QVERIFY(testWidget->isItemExpanded(childItem)); |
|
1025 |
testWidget->setItemExpanded(childItem, false); |
|
1026 |
QVERIFY(!testWidget->isItemExpanded(childItem)); |
|
1027 |
} |
|
1028 |
||
1029 |
void tst_QTreeWidget::checkState_data() |
|
1030 |
{ |
|
1031 |
} |
|
1032 |
||
1033 |
void tst_QTreeWidget::checkState() |
|
1034 |
{ |
|
1035 |
QTreeWidgetItem *item = new QTreeWidgetItem(testWidget); |
|
1036 |
item->setCheckState(0, Qt::Unchecked); |
|
1037 |
QTreeWidgetItem *firstChild = new QTreeWidgetItem(item); |
|
1038 |
firstChild->setCheckState(0, Qt::Unchecked); |
|
1039 |
QTreeWidgetItem *seccondChild = new QTreeWidgetItem(item); |
|
1040 |
seccondChild->setCheckState(0, Qt::Unchecked); |
|
1041 |
||
1042 |
QCOMPARE(item->checkState(0), Qt::Unchecked); |
|
1043 |
QCOMPARE(firstChild->checkState(0), Qt::Unchecked); |
|
1044 |
QCOMPARE(seccondChild->checkState(0), Qt::Unchecked); |
|
1045 |
||
1046 |
firstChild->setCheckState(0, Qt::Checked); |
|
1047 |
QCOMPARE(item->checkState(0), Qt::Unchecked); |
|
1048 |
QCOMPARE(firstChild->checkState(0), Qt::Checked); |
|
1049 |
QCOMPARE(seccondChild->checkState(0), Qt::Unchecked); |
|
1050 |
||
1051 |
item->setFlags(item->flags()|Qt::ItemIsTristate); |
|
1052 |
QCOMPARE(item->checkState(0), Qt::PartiallyChecked); |
|
1053 |
QCOMPARE(firstChild->checkState(0), Qt::Checked); |
|
1054 |
QCOMPARE(seccondChild->checkState(0), Qt::Unchecked); |
|
1055 |
||
1056 |
seccondChild->setCheckState(0, Qt::Checked); |
|
1057 |
QCOMPARE(item->checkState(0), Qt::Checked); |
|
1058 |
QCOMPARE(firstChild->checkState(0), Qt::Checked); |
|
1059 |
QCOMPARE(seccondChild->checkState(0), Qt::Checked); |
|
1060 |
||
1061 |
firstChild->setCheckState(0, Qt::Unchecked); |
|
1062 |
seccondChild->setCheckState(0, Qt::Unchecked); |
|
1063 |
QCOMPARE(item->checkState(0), Qt::Unchecked); |
|
1064 |
QCOMPARE(firstChild->checkState(0), Qt::Unchecked); |
|
1065 |
QCOMPARE(seccondChild->checkState(0), Qt::Unchecked); |
|
1066 |
} |
|
1067 |
||
1068 |
void tst_QTreeWidget::findItems_data() |
|
1069 |
{ |
|
1070 |
QTest::addColumn<int>("column"); |
|
1071 |
QTest::addColumn<QStringList>("topLevelText"); |
|
1072 |
QTest::addColumn<QStringList>("childText"); |
|
1073 |
QTest::addColumn<QString>("pattern"); |
|
1074 |
QTest::addColumn<int>("resultCount"); |
|
1075 |
QTest::addColumn<QStringList>("resultText"); |
|
1076 |
||
1077 |
QTest::newRow("find in toplevel") |
|
1078 |
<< 0 |
|
1079 |
<< (QStringList() << "This is a text" << "This is another" << "This is the one") |
|
1080 |
<< (QStringList() << "A child" << "This is not the one" << "And yet another child") |
|
1081 |
<< "This is the one" |
|
1082 |
<< 1 |
|
1083 |
<< (QStringList() << "This is the one"); |
|
1084 |
||
1085 |
QTest::newRow("find child") |
|
1086 |
<< 0 |
|
1087 |
<< (QStringList() << "This is a text" << "This is another" << "This is the one") |
|
1088 |
<< (QStringList() << "A child" << "This is not the one" << "And yet another child") |
|
1089 |
<< "A child" |
|
1090 |
<< 3 // once for each branch |
|
1091 |
<< (QStringList() << "A child"); |
|
1092 |
||
1093 |
} |
|
1094 |
||
1095 |
void tst_QTreeWidget::findItems() |
|
1096 |
{ |
|
1097 |
QFETCH(int, column); |
|
1098 |
QFETCH(QStringList, topLevelText); |
|
1099 |
QFETCH(QStringList, childText); |
|
1100 |
QFETCH(QString, pattern); |
|
1101 |
QFETCH(int, resultCount); |
|
1102 |
QFETCH(QStringList, resultText); |
|
1103 |
||
1104 |
for (int i = 0; i < topLevelText.count(); ++i) { |
|
1105 |
QTreeWidgetItem *item = new QTreeWidgetItem(testWidget); |
|
1106 |
item->setText(column, topLevelText.at(i)); |
|
1107 |
for (int j = 0; j < childText.count(); ++j) { |
|
1108 |
QTreeWidgetItem *child = new QTreeWidgetItem(item); |
|
1109 |
child->setText(column, childText.at(j)); |
|
1110 |
} |
|
1111 |
} |
|
1112 |
||
1113 |
QList<QTreeWidgetItem*> result = testWidget->findItems(pattern, |
|
1114 |
Qt::MatchExactly|Qt::MatchRecursive); |
|
1115 |
QCOMPARE(result.count(), resultCount); |
|
1116 |
||
1117 |
for (int k = 0; k < result.count() && k < resultText.count(); ++k) |
|
1118 |
QCOMPARE(result.at(k)->text(column), resultText.at(k)); |
|
1119 |
} |
|
1120 |
||
1121 |
void tst_QTreeWidget::findItemsInColumn() |
|
1122 |
{ |
|
1123 |
// Create 5 root items. |
|
1124 |
for (int i = 0; i < 5; i++) |
|
1125 |
new QTreeWidgetItem(testWidget, QStringList() << QString::number(i)); |
|
1126 |
||
1127 |
// Create a child with two columns for each root item. |
|
1128 |
for (int i = 0; i < 5; i++) { |
|
1129 |
QTreeWidgetItem * const parent = testWidget->topLevelItem(i); |
|
1130 |
new QTreeWidgetItem(parent, QStringList() << QString::number(i * 10) << QString::number(i * 100)); |
|
1131 |
} |
|
1132 |
||
1133 |
// Recursively search column one for 400. |
|
1134 |
QList<QTreeWidgetItem*> items = testWidget->findItems("400", Qt::MatchExactly|Qt::MatchRecursive, 1); |
|
1135 |
QCOMPARE(items.count(), 1); |
|
1136 |
} |
|
1137 |
||
1138 |
void tst_QTreeWidget::sortItems_data() |
|
1139 |
{ |
|
1140 |
QTest::addColumn<int>("column"); |
|
1141 |
QTest::addColumn<int>("order"); |
|
1142 |
QTest::addColumn<QStringList>("topLevelText"); |
|
1143 |
QTest::addColumn<QStringList>("childText"); |
|
1144 |
QTest::addColumn<QStringList>("topLevelResult"); |
|
1145 |
QTest::addColumn<QStringList>("childResult"); |
|
1146 |
QTest::addColumn<IntList>("expectedTopRows"); |
|
1147 |
QTest::addColumn<IntList>("expectedChildRows"); |
|
1148 |
||
1149 |
QTest::newRow("ascending order") |
|
1150 |
<< 0 |
|
1151 |
<< static_cast<int>(Qt::AscendingOrder) |
|
1152 |
<< (QStringList() << "c" << "d" << "a" << "b") |
|
1153 |
<< (QStringList() << "e" << "h" << "g" << "f") |
|
1154 |
<< (QStringList() << "a" << "b" << "c" << "d") |
|
1155 |
<< (QStringList() << "e" << "f" << "g" << "h") |
|
1156 |
<< (IntList() << 2 << 3 << 0 << 1) |
|
1157 |
<< (IntList() << 0 << 3 << 2 << 1); |
|
1158 |
||
1159 |
QTest::newRow("descending order") |
|
1160 |
<< 0 |
|
1161 |
<< static_cast<int>(Qt::DescendingOrder) |
|
1162 |
<< (QStringList() << "c" << "d" << "a" << "b") |
|
1163 |
<< (QStringList() << "e" << "h" << "g" << "f") |
|
1164 |
<< (QStringList() << "d" << "c" << "b" << "a") |
|
1165 |
<< (QStringList() << "h" << "g" << "f" << "e") |
|
1166 |
<< (IntList() << 1 << 0 << 3 << 2) |
|
1167 |
<< (IntList() << 3 << 0 << 1 << 2); |
|
1168 |
} |
|
1169 |
||
1170 |
void tst_QTreeWidget::sortItems() |
|
1171 |
{ |
|
1172 |
QFETCH(int, column); |
|
1173 |
QFETCH(int, order); |
|
1174 |
QFETCH(QStringList, topLevelText); |
|
1175 |
QFETCH(QStringList, childText); |
|
1176 |
QFETCH(QStringList, topLevelResult); |
|
1177 |
QFETCH(QStringList, childResult); |
|
1178 |
QFETCH(IntList, expectedTopRows); |
|
1179 |
QFETCH(IntList, expectedChildRows); |
|
1180 |
testWidget->setSortingEnabled(false); |
|
1181 |
||
1182 |
for (int i = 0; i < topLevelText.count(); ++i) { |
|
1183 |
QTreeWidgetItem *item = new QTreeWidgetItem(testWidget); |
|
1184 |
item->setText(column, topLevelText.at(i)); |
|
1185 |
for (int j = 0; j < childText.count(); ++j) { |
|
1186 |
QTreeWidgetItem *child = new QTreeWidgetItem(item); |
|
1187 |
child->setText(column, childText.at(j)); |
|
1188 |
} |
|
1189 |
} |
|
1190 |
||
1191 |
QAbstractItemModel *model = testWidget->model(); |
|
1192 |
QList<QPersistentModelIndex> tops; |
|
1193 |
for (int r = 0; r < model->rowCount(QModelIndex()); ++r) { |
|
1194 |
QPersistentModelIndex p = model->index(r, 0, QModelIndex()); |
|
1195 |
tops << p; |
|
1196 |
} |
|
1197 |
QList<QPersistentModelIndex> children; |
|
1198 |
for (int s = 0; s < model->rowCount(tops.first()); ++s) { |
|
1199 |
QPersistentModelIndex c = model->index(s, 0, tops.first()); |
|
1200 |
children << c; |
|
1201 |
} |
|
1202 |
||
1203 |
testWidget->sortItems(column, static_cast<Qt::SortOrder>(order)); |
|
1204 |
QCOMPARE(testWidget->sortColumn(), column); |
|
1205 |
||
1206 |
for (int k = 0; k < topLevelResult.count(); ++k) { |
|
1207 |
QTreeWidgetItem *item = testWidget->topLevelItem(k); |
|
1208 |
QCOMPARE(item->text(column), topLevelResult.at(k)); |
|
1209 |
for (int l = 0; l < childResult.count(); ++l) |
|
1210 |
QCOMPARE(item->child(l)->text(column), childResult.at(l)); |
|
1211 |
} |
|
1212 |
||
1213 |
for (int m = 0; m < tops.count(); ++m) |
|
1214 |
QCOMPARE(tops.at(m).row(), expectedTopRows.at(m)); |
|
1215 |
for (int n = 0; n < children.count(); ++n) |
|
1216 |
QCOMPARE(children.at(n).row(), expectedChildRows.at(n)); |
|
1217 |
} |
|
1218 |
||
1219 |
void tst_QTreeWidget::deleteItems_data() |
|
1220 |
{ |
|
1221 |
QTest::addColumn<int>("topLevelCount"); |
|
1222 |
QTest::addColumn<int>("childCount"); |
|
1223 |
QTest::addColumn<int>("grandChildCount"); |
|
1224 |
||
1225 |
QTest::addColumn<int>("deleteTopLevelCount"); |
|
1226 |
QTest::addColumn<int>("deleteChildCount"); |
|
1227 |
QTest::addColumn<int>("deleteGrandChildCount"); |
|
1228 |
||
1229 |
QTest::addColumn<int>("expectedTopLevelCount"); |
|
1230 |
QTest::addColumn<int>("expectedChildCount"); |
|
1231 |
QTest::addColumn<int>("expectedGrandChildCount"); |
|
1232 |
||
1233 |
QTest::addColumn<int>("persistentRow"); |
|
1234 |
QTest::addColumn<int>("persistentColumn"); |
|
1235 |
QTest::addColumn<bool>("persistentIsValid"); |
|
1236 |
||
1237 |
QTest::newRow("start with 10, delete 1") |
|
1238 |
<< 10 << 10 << 10 |
|
1239 |
<< 1 << 1 << 1 |
|
1240 |
<< 9 << 9 << 9 |
|
1241 |
<< 0 << 0 << false; |
|
1242 |
QTest::newRow("start with 10, delete 5") |
|
1243 |
<< 10 << 10 << 10 |
|
1244 |
<< 5 << 5 << 5 |
|
1245 |
<< 5 << 5 << 5 |
|
1246 |
<< 0 << 0 << false; |
|
1247 |
QTest::newRow("mixed") |
|
1248 |
<< 10 << 13 << 7 |
|
1249 |
<< 3 << 7 << 4 |
|
1250 |
<< 7 << 6 << 3 |
|
1251 |
<< 0 << 0 << false; |
|
1252 |
QTest::newRow("all") |
|
1253 |
<< 10 << 10 << 10 |
|
1254 |
<< 10 << 10 << 10 |
|
1255 |
<< 0 << 0 << 0 |
|
1256 |
<< 0 << 0 << false; |
|
1257 |
} |
|
1258 |
||
1259 |
void tst_QTreeWidget::deleteItems() |
|
1260 |
{ |
|
1261 |
QFETCH(int, topLevelCount); |
|
1262 |
QFETCH(int, childCount); |
|
1263 |
QFETCH(int, grandChildCount); |
|
1264 |
||
1265 |
QFETCH(int, deleteTopLevelCount); |
|
1266 |
QFETCH(int, deleteChildCount); |
|
1267 |
QFETCH(int, deleteGrandChildCount); |
|
1268 |
||
1269 |
QFETCH(int, expectedTopLevelCount); |
|
1270 |
QFETCH(int, expectedChildCount); |
|
1271 |
QFETCH(int, expectedGrandChildCount); |
|
1272 |
||
1273 |
QFETCH(int, persistentRow); |
|
1274 |
QFETCH(int, persistentColumn); |
|
1275 |
QFETCH(bool, persistentIsValid); |
|
1276 |
||
1277 |
for (int i = 0; i < topLevelCount; ++i) { |
|
1278 |
QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); |
|
1279 |
for (int j = 0; j < childCount; ++j) { |
|
1280 |
QTreeWidgetItem *child = new QTreeWidgetItem(top); |
|
1281 |
for (int k = 0; k < grandChildCount; ++k) { |
|
1282 |
new QTreeWidgetItem(child); |
|
1283 |
} |
|
1284 |
} |
|
1285 |
} |
|
1286 |
||
1287 |
QPersistentModelIndex persistent = testWidget->model()->index(persistentRow, |
|
1288 |
persistentColumn); |
|
1289 |
QVERIFY(persistent.isValid()); |
|
1290 |
||
1291 |
QTreeWidgetItem *top = testWidget->topLevelItem(0); |
|
1292 |
QTreeWidgetItem *child = top->child(0); |
|
1293 |
||
1294 |
for (int n = 0; n < deleteGrandChildCount; ++n) |
|
1295 |
delete child->child(0); |
|
1296 |
QCOMPARE(child->childCount(), expectedGrandChildCount); |
|
1297 |
||
1298 |
for (int m = 0; m < deleteChildCount; ++m) |
|
1299 |
delete top->child(0); |
|
1300 |
QCOMPARE(top->childCount(), expectedChildCount); |
|
1301 |
||
1302 |
for (int l = 0; l < deleteTopLevelCount; ++l) |
|
1303 |
delete testWidget->topLevelItem(0); |
|
1304 |
QCOMPARE(testWidget->topLevelItemCount(), expectedTopLevelCount); |
|
1305 |
||
1306 |
QCOMPARE(persistent.isValid(), persistentIsValid); |
|
1307 |
} |
|
1308 |
||
1309 |
||
1310 |
void tst_QTreeWidget::itemAboveOrBelow() |
|
1311 |
{ |
|
1312 |
QTreeWidget tw; |
|
1313 |
tw.setColumnCount(1); |
|
1314 |
QTreeWidgetItem *twi = new QTreeWidgetItem(&tw, QStringList() << "Test"); |
|
1315 |
QTreeWidgetItem *twi2 = new QTreeWidgetItem(&tw, QStringList() << "Test 2"); |
|
1316 |
QTreeWidgetItem *twi3 = new QTreeWidgetItem(&tw, QStringList() << "Test 3"); |
|
1317 |
tw.show(); |
|
1318 |
QCOMPARE(tw.itemAbove(twi2), twi); |
|
1319 |
QCOMPARE(tw.itemBelow(twi2), twi3); |
|
1320 |
} |
|
1321 |
||
1322 |
void tst_QTreeWidget::itemStreaming_data() |
|
1323 |
{ |
|
1324 |
QTest::addColumn<QString>("text"); |
|
1325 |
QTest::addColumn<QString>("toolTip"); |
|
1326 |
QTest::addColumn<int>("column"); |
|
1327 |
||
1328 |
QTest::newRow("Data") << "item text" << "tool tip text" << 0; |
|
1329 |
} |
|
1330 |
||
1331 |
void tst_QTreeWidget::itemStreaming() |
|
1332 |
{ |
|
1333 |
QFETCH(QString, text); |
|
1334 |
QFETCH(QString, toolTip); |
|
1335 |
QFETCH(int, column); |
|
1336 |
||
1337 |
QTreeWidgetItem item(testWidget); |
|
1338 |
QCOMPARE(item.text(column), QString()); |
|
1339 |
QCOMPARE(item.toolTip(column), QString()); |
|
1340 |
||
1341 |
item.setText(column, text); |
|
1342 |
item.setToolTip(column, toolTip); |
|
1343 |
QCOMPARE(item.text(column), text); |
|
1344 |
QCOMPARE(item.toolTip(column), toolTip); |
|
1345 |
||
1346 |
QByteArray buffer; |
|
1347 |
QDataStream out(&buffer, QIODevice::WriteOnly); |
|
1348 |
out << item; |
|
1349 |
||
1350 |
QTreeWidgetItem item2(testWidget); |
|
1351 |
QCOMPARE(item2.text(column), QString()); |
|
1352 |
QCOMPARE(item2.toolTip(column), QString()); |
|
1353 |
||
1354 |
QVERIFY(!buffer.isEmpty()); |
|
1355 |
||
1356 |
QDataStream in(&buffer, QIODevice::ReadOnly); |
|
1357 |
in >> item2; |
|
1358 |
QCOMPARE(item2.text(column), text); |
|
1359 |
QCOMPARE(item2.toolTip(column), toolTip); |
|
1360 |
} |
|
1361 |
||
1362 |
void tst_QTreeWidget::insertTopLevelItems_data() |
|
1363 |
{ |
|
1364 |
QTest::addColumn<QStringList>("initialText"); |
|
1365 |
QTest::addColumn<QStringList>("insertText"); |
|
1366 |
QTest::addColumn<int>("insertTopLevelIndex"); |
|
1367 |
QTest::addColumn<int>("expectedTopLevelIndex"); |
|
1368 |
QTest::addColumn<int>("insertChildIndex"); |
|
1369 |
QTest::addColumn<int>("expectedChildIndex"); |
|
1370 |
||
1371 |
QStringList initial = (QStringList() << "foo" << "bar"); |
|
1372 |
QStringList insert = (QStringList() << "baz"); |
|
1373 |
||
1374 |
QTest::newRow("Insert at count") << initial << insert |
|
1375 |
<< initial.count() << initial.count() |
|
1376 |
<< initial.count() << initial.count(); |
|
1377 |
QTest::newRow("Insert in the middle") << initial << insert |
|
1378 |
<< (initial.count() / 2) << (initial.count() / 2) |
|
1379 |
<< (initial.count() / 2) << (initial.count() / 2); |
|
1380 |
QTest::newRow("Insert less than 0") << initial << insert |
|
1381 |
<< -1 << -1 |
|
1382 |
<< -1 << -1; |
|
1383 |
QTest::newRow("Insert beyond count") << initial << insert |
|
1384 |
<< initial.count() + 1 << -1 |
|
1385 |
<< initial.count() + 1 << -1; |
|
1386 |
} |
|
1387 |
||
1388 |
void tst_QTreeWidget::insertTopLevelItems() |
|
1389 |
{ |
|
1390 |
QFETCH(QStringList, initialText); |
|
1391 |
QFETCH(QStringList, insertText); |
|
1392 |
QFETCH(int, insertTopLevelIndex); |
|
1393 |
QFETCH(int, expectedTopLevelIndex); |
|
1394 |
QFETCH(int, insertChildIndex); |
|
1395 |
QFETCH(int, expectedChildIndex); |
|
1396 |
testWidget->setSortingEnabled(false); |
|
1397 |
||
1398 |
{ // insert the initial items |
|
1399 |
QCOMPARE(testWidget->topLevelItemCount(), 0); |
|
1400 |
for (int i = 0; i < initialText.count(); ++i) { |
|
1401 |
QTreeWidgetItem *top = new QTreeWidgetItem(QStringList(initialText.at(i))); |
|
1402 |
testWidget->addTopLevelItem(top); |
|
1403 |
QCOMPARE(testWidget->indexOfTopLevelItem(top), i); |
|
1404 |
} |
|
1405 |
QCOMPARE(testWidget->topLevelItemCount(), initialText.count()); |
|
1406 |
} |
|
1407 |
||
1408 |
{ // test adding children |
|
1409 |
QTreeWidgetItem *topLevel = testWidget->topLevelItem(0); |
|
1410 |
for (int i = 0; i < initialText.count(); ++i) |
|
1411 |
topLevel->addChild(new QTreeWidgetItem(QStringList(initialText.at(i)))); |
|
1412 |
QCOMPARE(topLevel->childCount(), initialText.count()); |
|
1413 |
} |
|
1414 |
||
1415 |
{ // test adding more top level items |
|
1416 |
QTreeWidgetItem *topsy = new QTreeWidgetItem(QStringList(insertText.at(0))); |
|
1417 |
testWidget->insertTopLevelItem(insertTopLevelIndex, topsy); |
|
1418 |
if (expectedTopLevelIndex == -1) { |
|
1419 |
QCOMPARE(testWidget->topLevelItemCount(), initialText.count()); |
|
1420 |
delete topsy; |
|
1421 |
} else { |
|
1422 |
QTreeWidgetItem *item = testWidget->topLevelItem(expectedTopLevelIndex); |
|
1423 |
QVERIFY(item != 0); |
|
1424 |
QCOMPARE(item->text(0), insertText.at(0)); |
|
1425 |
QCOMPARE(testWidget->indexOfTopLevelItem(item), expectedTopLevelIndex); |
|
1426 |
} |
|
1427 |
} |
|
1428 |
||
1429 |
{ // test adding more children |
|
1430 |
QTreeWidgetItem *topLevel = testWidget->topLevelItem(0); |
|
1431 |
QVERIFY(topLevel != 0); |
|
1432 |
QTreeWidgetItem *child = new QTreeWidgetItem(QStringList(insertText.at(0))); |
|
1433 |
topLevel->insertChild(insertChildIndex, child); |
|
1434 |
if (expectedChildIndex == -1) { |
|
1435 |
QCOMPARE(topLevel->childCount(), initialText.count()); |
|
1436 |
delete child; |
|
1437 |
} else { |
|
1438 |
QTreeWidgetItem *item = topLevel->child(expectedChildIndex); |
|
1439 |
QVERIFY(item != 0); |
|
1440 |
QCOMPARE(item->text(0), insertText.at(0)); |
|
1441 |
} |
|
1442 |
} |
|
1443 |
} |
|
1444 |
||
1445 |
static void fillTreeWidget(QTreeWidgetItem *parent, int rows) |
|
1446 |
{ |
|
1447 |
const int columns = parent->treeWidget()->columnCount(); |
|
1448 |
for (int r = 0; r < rows; ++r) { |
|
1449 |
QTreeWidgetItem *w = new QTreeWidgetItem(parent); |
|
1450 |
for ( int c = 0; c < columns; ++c ) { |
|
1451 |
QString s = QString("[r:%1,c:%2]").arg(r).arg(c); |
|
1452 |
w->setText(c, s); |
|
1453 |
} |
|
1454 |
fillTreeWidget(w, rows - r - 1); |
|
1455 |
} |
|
1456 |
} |
|
1457 |
||
1458 |
static void fillTreeWidget(QTreeWidget *tree, int rows) |
|
1459 |
{ |
|
1460 |
for (int r = 0; r < rows; ++r) { |
|
1461 |
QTreeWidgetItem *w = new QTreeWidgetItem(); |
|
1462 |
for ( int c = 0; c < tree->columnCount(); ++c ) { |
|
1463 |
QString s = QString("[r:%1,c:%2]").arg(r).arg(c); |
|
1464 |
w->setText(c, s); |
|
1465 |
} |
|
1466 |
tree->insertTopLevelItem(r, w); |
|
1467 |
fillTreeWidget(w, rows - r - 1); |
|
1468 |
} |
|
1469 |
} |
|
1470 |
||
1471 |
void tst_QTreeWidget::keyboardNavigation() |
|
1472 |
{ |
|
1473 |
int rows = 8; |
|
1474 |
||
1475 |
fillTreeWidget(testWidget, rows); |
|
1476 |
||
1477 |
QVector<Qt::Key> keymoves; |
|
1478 |
keymoves << Qt::Key_Down << Qt::Key_Right << Qt::Key_Left |
|
1479 |
<< Qt::Key_Down << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down |
|
1480 |
<< Qt::Key_Right |
|
1481 |
<< Qt::Key_Up << Qt::Key_Left << Qt::Key_Left |
|
1482 |
<< Qt::Key_Up << Qt::Key_Down << Qt::Key_Up << Qt::Key_Up |
|
1483 |
<< Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up |
|
1484 |
<< Qt::Key_Down << Qt::Key_Right << Qt::Key_Down << Qt::Key_Down |
|
1485 |
<< Qt::Key_Down << Qt::Key_Right << Qt::Key_Down << Qt::Key_Down |
|
1486 |
<< Qt::Key_Left << Qt::Key_Left << Qt::Key_Up << Qt::Key_Down |
|
1487 |
<< Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Left |
|
1488 |
<< Qt::Key_Down << Qt::Key_Right << Qt::Key_Right << Qt::Key_Right |
|
1489 |
<< Qt::Key_Left << Qt::Key_Left << Qt::Key_Right << Qt::Key_Left; |
|
1490 |
||
1491 |
int row = 0; |
|
1492 |
QTreeWidgetItem *item = testWidget->topLevelItem(0); |
|
1493 |
testWidget->setCurrentItem(item); |
|
1494 |
QCOMPARE(testWidget->currentItem(), item); |
|
1495 |
QApplication::instance()->processEvents(); |
|
1496 |
||
1497 |
QScrollBar *scrollBar = testWidget->horizontalScrollBar(); |
|
1498 |
bool checkScroll = false; |
|
1499 |
for (int i = 0; i < keymoves.size(); ++i) { |
|
1500 |
Qt::Key key = keymoves.at(i); |
|
1501 |
int valueBeforeClick = scrollBar->value(); |
|
1502 |
if (valueBeforeClick >= scrollBar->singleStep()) |
|
1503 |
checkScroll = true; |
|
1504 |
else |
|
1505 |
checkScroll = false; |
|
1506 |
QTest::keyClick(testWidget, key); |
|
1507 |
QApplication::instance()->processEvents(); |
|
1508 |
||
1509 |
switch (key) { |
|
1510 |
case Qt::Key_Up: |
|
1511 |
if (row > 0) { |
|
1512 |
if (item->parent()) |
|
1513 |
item = item->parent()->child(row - 1); |
|
1514 |
else |
|
1515 |
item = testWidget->topLevelItem(row - 1); |
|
1516 |
row -= 1; |
|
1517 |
} else if (item->parent()) { |
|
1518 |
item = item->parent(); |
|
1519 |
row = item->parent() ? item->parent()->indexOfChild(item) : testWidget->indexOfTopLevelItem(item); |
|
1520 |
} |
|
1521 |
break; |
|
1522 |
case Qt::Key_Down: |
|
1523 |
if (testWidget->isItemExpanded(item)) { |
|
1524 |
row = 0; |
|
1525 |
item = item->child(row); |
|
1526 |
} else { |
|
1527 |
row = qMin(rows - 1, row + 1); |
|
1528 |
if (item->parent()) |
|
1529 |
item = item->parent()->child(row); |
|
1530 |
else |
|
1531 |
item = testWidget->topLevelItem(row); |
|
1532 |
} |
|
1533 |
break; |
|
1534 |
case Qt::Key_Left: |
|
1535 |
if (checkScroll) { |
|
1536 |
QVERIFY(testWidget->isItemExpanded(item)); |
|
1537 |
QCOMPARE(scrollBar->value(), valueBeforeClick - scrollBar->singleStep()); |
|
1538 |
} |
|
1539 |
// windows style right will walk to the parent |
|
1540 |
if (testWidget->currentItem() != item) { |
|
1541 |
QCOMPARE(testWidget->currentItem(), item->parent()); |
|
1542 |
item = testWidget->currentItem(); |
|
1543 |
row = item->parent() ? item->parent()->indexOfChild(item) : testWidget->indexOfTopLevelItem(item);; |
|
1544 |
} |
|
1545 |
break; |
|
1546 |
case Qt::Key_Right: |
|
1547 |
if (checkScroll) |
|
1548 |
QCOMPARE(scrollBar->value(), valueBeforeClick + scrollBar->singleStep()); |
|
1549 |
// windows style right will walk to the first child |
|
1550 |
if (testWidget->currentItem() != item) { |
|
1551 |
QCOMPARE(testWidget->currentItem()->parent(), item); |
|
1552 |
row = item->indexOfChild(testWidget->currentItem()); |
|
1553 |
item = testWidget->currentItem(); |
|
1554 |
QCOMPARE(row, 0); |
|
1555 |
} |
|
1556 |
break; |
|
1557 |
default: |
|
1558 |
QVERIFY(false); |
|
1559 |
} |
|
1560 |
||
1561 |
QTreeWidgetItem *current = testWidget->currentItem(); |
|
1562 |
QCOMPARE(current->text(0), QString("[r:%1,c:0]").arg(row)); |
|
1563 |
if (current->parent()) |
|
1564 |
QCOMPARE(current->parent()->indexOfChild(current), row); |
|
1565 |
else |
|
1566 |
QCOMPARE(testWidget->indexOfTopLevelItem(current), row); |
|
1567 |
} |
|
1568 |
} |
|
1569 |
||
1570 |
void tst_QTreeWidget::scrollToItem() |
|
1571 |
{ |
|
1572 |
// Check if all parent nodes of the item found are expanded. |
|
1573 |
// Reported in task #78761 |
|
1574 |
QTreeWidgetItem *bar; |
|
1575 |
QTreeWidgetItem *search; |
|
1576 |
for (int i=0; i<2; ++i) { |
|
1577 |
bar = new QTreeWidgetItem(testWidget); |
|
1578 |
bar->setText(0, QString::number(i)); |
|
1579 |
||
1580 |
for (int j=0; j<2; ++j) { |
|
1581 |
QTreeWidgetItem *foo = new QTreeWidgetItem(bar); |
|
1582 |
foo->setText(0, bar->text(0) + QString::number(j)); |
|
1583 |
||
1584 |
for (int k=0; k<2; ++k) { |
|
1585 |
QTreeWidgetItem *yo = new QTreeWidgetItem(foo); |
|
1586 |
yo->setText(0, foo->text(0) + QString::number(k)); |
|
1587 |
search = yo; |
|
1588 |
} |
|
1589 |
} |
|
1590 |
} |
|
1591 |
||
1592 |
testWidget->setHeaderLabels(QStringList() << "foo"); |
|
1593 |
testWidget->scrollToItem(search); |
|
1594 |
QVERIFY(search->text(0) == "111"); |
|
1595 |
||
1596 |
bar = search->parent(); |
|
1597 |
QVERIFY(testWidget->isItemExpanded(bar)); |
|
1598 |
bar = bar->parent(); |
|
1599 |
QVERIFY(testWidget->isItemExpanded(bar)); |
|
1600 |
} |
|
1601 |
||
1602 |
// From task #85413 |
|
1603 |
void tst_QTreeWidget::setSortingEnabled() |
|
1604 |
{ |
|
1605 |
QStringList hl; |
|
1606 |
hl << "ID"; |
|
1607 |
testWidget->setColumnCount(hl.count()); |
|
1608 |
testWidget->setHeaderLabels(hl); |
|
1609 |
||
1610 |
QTreeWidgetItem *item1 = new QTreeWidgetItem(testWidget); |
|
1611 |
QTreeWidgetItem *item2 = new QTreeWidgetItem(testWidget); |
|
1612 |
||
1613 |
testWidget->setSortingEnabled(true); |
|
1614 |
QCOMPARE(testWidget->isSortingEnabled(), true); |
|
1615 |
QCOMPARE(testWidget->isSortingEnabled(), testWidget->header()->isSortIndicatorShown()); |
|
1616 |
QCOMPARE(testWidget->topLevelItem(0), item1); |
|
1617 |
QCOMPARE(testWidget->topLevelItem(1), item2); |
|
1618 |
||
1619 |
// Make sure we do it twice |
|
1620 |
testWidget->setSortingEnabled(true); |
|
1621 |
QCOMPARE(testWidget->isSortingEnabled(), true); |
|
1622 |
QCOMPARE(testWidget->isSortingEnabled(), testWidget->header()->isSortIndicatorShown()); |
|
1623 |
||
1624 |
testWidget->setSortingEnabled(false); |
|
1625 |
QCOMPARE(testWidget->isSortingEnabled(), false); |
|
1626 |
QCOMPARE(testWidget->isSortingEnabled(), testWidget->header()->isSortIndicatorShown()); |
|
1627 |
||
1628 |
testWidget->setSortingEnabled(false); |
|
1629 |
QCOMPARE(testWidget->isSortingEnabled(), false); |
|
1630 |
QCOMPARE(testWidget->isSortingEnabled(), testWidget->header()->isSortIndicatorShown()); |
|
1631 |
||
1632 |
// And back again so that we make sure that we test the transition from false to true |
|
1633 |
testWidget->setSortingEnabled(true); |
|
1634 |
QCOMPARE(testWidget->isSortingEnabled(), true); |
|
1635 |
QCOMPARE(testWidget->isSortingEnabled(), testWidget->header()->isSortIndicatorShown()); |
|
1636 |
||
1637 |
testWidget->setSortingEnabled(true); |
|
1638 |
QCOMPARE(testWidget->isSortingEnabled(), true); |
|
1639 |
QCOMPARE(testWidget->isSortingEnabled(), testWidget->header()->isSortIndicatorShown()); |
|
1640 |
||
1641 |
testWidget->setSortingEnabled(false); |
|
1642 |
} |
|
1643 |
||
1644 |
void tst_QTreeWidget::addChild() |
|
1645 |
{ |
|
1646 |
QTreeWidget tree; |
|
1647 |
for (int x = 0; x < 2; ++x) { |
|
1648 |
QTreeWidget *view = x ? &tree : static_cast<QTreeWidget*>(0); |
|
1649 |
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)view); |
|
1650 |
QCOMPARE(item->childCount(), 0); |
|
1651 |
||
1652 |
// try to add 0 |
|
1653 |
item->addChild(0); |
|
1654 |
QCOMPARE(item->childCount(), 0); |
|
1655 |
QCOMPARE(item->indexOfChild(0), -1); |
|
1656 |
||
1657 |
// add one at a time |
|
1658 |
QList<QTreeWidgetItem*> children; |
|
1659 |
for (int i = 0; i < 10; ++i) { |
|
1660 |
QTreeWidgetItem *child = new QTreeWidgetItem(); |
|
1661 |
item->addChild(child); |
|
1662 |
QCOMPARE(item->childCount(), i+1); |
|
1663 |
QCOMPARE(item->child(i), child); |
|
1664 |
QCOMPARE(item->indexOfChild(child), i); |
|
1665 |
QCOMPARE(child->parent(), item); |
|
1666 |
QCOMPARE(child->treeWidget(), view); |
|
1667 |
item->addChild(child); |
|
1668 |
QCOMPARE(item->childCount(), i+1); |
|
1669 |
children.append(child); |
|
1670 |
} |
|
1671 |
||
1672 |
// take them all |
|
1673 |
QList<QTreeWidgetItem*> taken = item->takeChildren(); |
|
1674 |
QCOMPARE(taken, children); |
|
1675 |
QCOMPARE(item->childCount(), 0); |
|
1676 |
for (int i = 0; i < taken.count(); ++i) { |
|
1677 |
QCOMPARE(taken.at(i)->parent(), static_cast<QTreeWidgetItem*>(0)); |
|
1678 |
QCOMPARE(taken.at(i)->treeWidget(), static_cast<QTreeWidget*>(0)); |
|
1679 |
item->addChild(taken.at(i)); // re-add |
|
1680 |
} |
|
1681 |
||
1682 |
// delete one at a time |
|
1683 |
while (!children.isEmpty()) { |
|
1684 |
QTreeWidgetItem *ti = children.takeFirst(); |
|
1685 |
delete ti; |
|
1686 |
QCOMPARE(item->childCount(), children.count()); |
|
1687 |
for (int i = 0; i < children.count(); ++i) |
|
1688 |
QCOMPARE(item->child(i), children.at(i)); |
|
1689 |
} |
|
1690 |
||
1691 |
// add none |
|
1692 |
{ |
|
1693 |
int count = item->childCount(); |
|
1694 |
item->addChildren(QList<QTreeWidgetItem*>()); |
|
1695 |
QCOMPARE(item->childCount(), count); |
|
1696 |
} |
|
1697 |
||
1698 |
// add many at a time |
|
1699 |
const int count = 10; |
|
1700 |
for (int i = 0; i < 100; i += count) { |
|
1701 |
QList<QTreeWidgetItem*> list; |
|
1702 |
for (int j = 0; j < count; ++j) |
|
1703 |
list << new QTreeWidgetItem(QStringList() << QString("%0").arg(j)); |
|
1704 |
item->addChildren(list); |
|
1705 |
QCOMPARE(item->childCount(), count + i); |
|
1706 |
for (int j = 0; j < count; ++j) { |
|
1707 |
QCOMPARE(item->child(i+j), list.at(j)); |
|
1708 |
QCOMPARE(item->child(i+j)->parent(), item); |
|
1709 |
} |
|
1710 |
||
1711 |
item->addChildren(list); |
|
1712 |
QCOMPARE(item->childCount(), count + i); |
|
1713 |
} |
|
1714 |
||
1715 |
if (!view) |
|
1716 |
delete item; |
|
1717 |
} |
|
1718 |
} |
|
1719 |
||
1720 |
void tst_QTreeWidget::setData() |
|
1721 |
{ |
|
1722 |
{ |
|
1723 |
QTreeWidgetItem *headerItem = new QTreeWidgetItem(); |
|
1724 |
headerItem->setText(0, "Item1"); |
|
1725 |
testWidget->setHeaderItem(headerItem); |
|
1726 |
||
1727 |
QSignalSpy headerDataChangedSpy( |
|
1728 |
testWidget->model(), SIGNAL(headerDataChanged(Qt::Orientation, int, int))); |
|
1729 |
QSignalSpy dataChangedSpy( |
|
1730 |
testWidget->model(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &))); |
|
1731 |
QSignalSpy itemChangedSpy( |
|
1732 |
testWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int))); |
|
1733 |
headerItem->setText(0, "test"); |
|
1734 |
QCOMPARE(dataChangedSpy.count(), 0); |
|
1735 |
QCOMPARE(headerDataChangedSpy.count(), 1); |
|
1736 |
QCOMPARE(itemChangedSpy.count(), 0); // no itemChanged() signal for header item |
|
1737 |
||
1738 |
headerItem->setData(-1, -1, QVariant()); |
|
1739 |
} |
|
1740 |
||
1741 |
{ |
|
1742 |
QSignalSpy itemChangedSpy( |
|
1743 |
testWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int))); |
|
1744 |
QTreeWidgetItem *item = new QTreeWidgetItem(); |
|
1745 |
testWidget->addTopLevelItem(item); |
|
1746 |
for (int x = 0; x < 2; ++x) { |
|
1747 |
for (int i = 1; i <= 2; ++i) { |
|
1748 |
for (int j = 0; j < 5; ++j) { |
|
1749 |
QVariantList args; |
|
1750 |
QString text = QString("text %0").arg(i); |
|
1751 |
item->setText(j, text); |
|
1752 |
QCOMPARE(item->text(j), text); |
|
1753 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1754 |
args = itemChangedSpy.takeFirst(); |
|
1755 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1756 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1757 |
item->setText(j, text); |
|
1758 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1759 |
||
1760 |
QPixmap pixmap(32, 32); |
|
1761 |
pixmap.fill((i == 1) ? Qt::red : Qt::green); |
|
1762 |
QIcon icon(pixmap); |
|
1763 |
item->setIcon(j, icon); |
|
1764 |
QCOMPARE(item->icon(j), icon); |
|
1765 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1766 |
args = itemChangedSpy.takeFirst(); |
|
1767 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1768 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1769 |
item->setIcon(j, icon); |
|
1770 |
// #### shouldn't cause dataChanged() |
|
1771 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1772 |
itemChangedSpy.clear(); |
|
1773 |
||
1774 |
QString toolTip = QString("toolTip %0").arg(i); |
|
1775 |
item->setToolTip(j, toolTip); |
|
1776 |
QCOMPARE(item->toolTip(j), toolTip); |
|
1777 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1778 |
args = itemChangedSpy.takeFirst(); |
|
1779 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1780 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1781 |
item->setToolTip(j, toolTip); |
|
1782 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1783 |
||
1784 |
QString statusTip = QString("statusTip %0").arg(i); |
|
1785 |
item->setStatusTip(j, statusTip); |
|
1786 |
QCOMPARE(item->statusTip(j), statusTip); |
|
1787 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1788 |
args = itemChangedSpy.takeFirst(); |
|
1789 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1790 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1791 |
item->setStatusTip(j, statusTip); |
|
1792 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1793 |
||
1794 |
QString whatsThis = QString("whatsThis %0").arg(i); |
|
1795 |
item->setWhatsThis(j, whatsThis); |
|
1796 |
QCOMPARE(item->whatsThis(j), whatsThis); |
|
1797 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1798 |
args = itemChangedSpy.takeFirst(); |
|
1799 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1800 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1801 |
item->setWhatsThis(j, whatsThis); |
|
1802 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1803 |
||
1804 |
QSize sizeHint(64*i, 48*i); |
|
1805 |
item->setSizeHint(j, sizeHint); |
|
1806 |
QCOMPARE(item->sizeHint(j), sizeHint); |
|
1807 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1808 |
args = itemChangedSpy.takeFirst(); |
|
1809 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1810 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1811 |
item->setSizeHint(j, sizeHint); |
|
1812 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1813 |
||
1814 |
QFont font; |
|
1815 |
item->setFont(j, font); |
|
1816 |
QCOMPARE(item->font(j), font); |
|
1817 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1818 |
args = itemChangedSpy.takeFirst(); |
|
1819 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1820 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1821 |
item->setFont(j, font); |
|
1822 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1823 |
||
1824 |
Qt::Alignment textAlignment((i == 1) |
|
1825 |
? Qt::AlignLeft|Qt::AlignVCenter |
|
1826 |
: Qt::AlignRight); |
|
1827 |
item->setTextAlignment(j, textAlignment); |
|
1828 |
QCOMPARE(item->textAlignment(j), int(textAlignment)); |
|
1829 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1830 |
args = itemChangedSpy.takeFirst(); |
|
1831 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1832 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1833 |
item->setTextAlignment(j, textAlignment); |
|
1834 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1835 |
||
1836 |
QColor backgroundColor((i == 1) ? Qt::blue : Qt::yellow); |
|
1837 |
item->setBackground(j, backgroundColor); |
|
1838 |
QCOMPARE(item->background(j).color(), backgroundColor); |
|
1839 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1840 |
args = itemChangedSpy.takeFirst(); |
|
1841 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1842 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1843 |
item->setBackground(j, backgroundColor); |
|
1844 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1845 |
||
1846 |
QColor textColor((i == i) ? Qt::green : Qt::cyan); |
|
1847 |
item->setTextColor(j, textColor); |
|
1848 |
QCOMPARE(item->textColor(j), textColor); |
|
1849 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1850 |
args = itemChangedSpy.takeFirst(); |
|
1851 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1852 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1853 |
item->setTextColor(j, textColor); |
|
1854 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1855 |
||
1856 |
Qt::CheckState checkState((i == 1) ? Qt::PartiallyChecked : Qt::Checked); |
|
1857 |
item->setCheckState(j, checkState); |
|
1858 |
QCOMPARE(item->checkState(j), checkState); |
|
1859 |
QCOMPARE(itemChangedSpy.count(), 1); |
|
1860 |
args = itemChangedSpy.takeFirst(); |
|
1861 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1862 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1863 |
item->setCheckState(j, checkState); |
|
1864 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1865 |
||
1866 |
QCOMPARE(item->text(j), text); |
|
1867 |
QCOMPARE(item->icon(j), icon); |
|
1868 |
QCOMPARE(item->toolTip(j), toolTip); |
|
1869 |
QCOMPARE(item->statusTip(j), statusTip); |
|
1870 |
QCOMPARE(item->whatsThis(j), whatsThis); |
|
1871 |
QCOMPARE(item->sizeHint(j), sizeHint); |
|
1872 |
QCOMPARE(item->font(j), font); |
|
1873 |
QCOMPARE(item->textAlignment(j), int(textAlignment)); |
|
1874 |
QCOMPARE(item->background(j).color(), backgroundColor); |
|
1875 |
QCOMPARE(item->textColor(j), textColor); |
|
1876 |
QCOMPARE(item->checkState(j), checkState); |
|
1877 |
||
1878 |
QCOMPARE(qvariant_cast<QString>(item->data(j, Qt::DisplayRole)), text); |
|
1879 |
QCOMPARE(qvariant_cast<QIcon>(item->data(j, Qt::DecorationRole)), icon); |
|
1880 |
QCOMPARE(qvariant_cast<QString>(item->data(j, Qt::ToolTipRole)), toolTip); |
|
1881 |
QCOMPARE(qvariant_cast<QString>(item->data(j, Qt::StatusTipRole)), statusTip); |
|
1882 |
QCOMPARE(qvariant_cast<QString>(item->data(j, Qt::WhatsThisRole)), whatsThis); |
|
1883 |
QCOMPARE(qvariant_cast<QSize>(item->data(j, Qt::SizeHintRole)), sizeHint); |
|
1884 |
QCOMPARE(qvariant_cast<QFont>(item->data(j, Qt::FontRole)), font); |
|
1885 |
QCOMPARE(qvariant_cast<int>(item->data(j, Qt::TextAlignmentRole)), int(textAlignment)); |
|
1886 |
QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundColorRole)), QBrush(backgroundColor)); |
|
1887 |
QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundRole)), QBrush(backgroundColor)); |
|
1888 |
QCOMPARE(qvariant_cast<QColor>(item->data(j, Qt::TextColorRole)), textColor); |
|
1889 |
QCOMPARE(qvariant_cast<int>(item->data(j, Qt::CheckStateRole)), int(checkState)); |
|
1890 |
||
1891 |
item->setBackground(j, pixmap); |
|
1892 |
QCOMPARE(item->background(j).texture(), pixmap); |
|
1893 |
QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundRole)).texture(), pixmap); |
|
1894 |
args = itemChangedSpy.takeFirst(); |
|
1895 |
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); |
|
1896 |
QCOMPARE(qvariant_cast<int>(args.at(1)), j); |
|
1897 |
item->setBackground(j, pixmap); |
|
1898 |
QCOMPARE(itemChangedSpy.count(), 0); |
|
1899 |
||
1900 |
item->setData(j, Qt::DisplayRole, QVariant()); |
|
1901 |
item->setData(j, Qt::DecorationRole, QVariant()); |
|
1902 |
item->setData(j, Qt::ToolTipRole, QVariant()); |
|
1903 |
item->setData(j, Qt::StatusTipRole, QVariant()); |
|
1904 |
item->setData(j, Qt::WhatsThisRole, QVariant()); |
|
1905 |
item->setData(j, Qt::SizeHintRole, QVariant()); |
|
1906 |
item->setData(j, Qt::FontRole, QVariant()); |
|
1907 |
item->setData(j, Qt::TextAlignmentRole, QVariant()); |
|
1908 |
item->setData(j, Qt::BackgroundColorRole, QVariant()); |
|
1909 |
item->setData(j, Qt::TextColorRole, QVariant()); |
|
1910 |
item->setData(j, Qt::CheckStateRole, QVariant()); |
|
1911 |
QCOMPARE(itemChangedSpy.count(), 11); |
|
1912 |
itemChangedSpy.clear(); |
|
1913 |
||
1914 |
QCOMPARE(item->data(j, Qt::DisplayRole).toString(), QString()); |
|
1915 |
QCOMPARE(item->data(j, Qt::DecorationRole), QVariant()); |
|
1916 |
QCOMPARE(item->data(j, Qt::ToolTipRole), QVariant()); |
|
1917 |
QCOMPARE(item->data(j, Qt::StatusTipRole), QVariant()); |
|
1918 |
QCOMPARE(item->data(j, Qt::WhatsThisRole), QVariant()); |
|
1919 |
QCOMPARE(item->data(j, Qt::SizeHintRole), QVariant()); |
|
1920 |
QCOMPARE(item->data(j, Qt::FontRole), QVariant()); |
|
1921 |
QCOMPARE(item->data(j, Qt::TextAlignmentRole), QVariant()); |
|
1922 |
QCOMPARE(item->data(j, Qt::BackgroundColorRole), QVariant()); |
|
1923 |
QCOMPARE(item->data(j, Qt::BackgroundRole), QVariant()); |
|
1924 |
QCOMPARE(item->data(j, Qt::TextColorRole), QVariant()); |
|
1925 |
QCOMPARE(item->data(j, Qt::CheckStateRole), QVariant()); |
|
1926 |
} |
|
1927 |
} |
|
1928 |
} |
|
1929 |
||
1930 |
// ### add more data types here |
|
1931 |
||
1932 |
item->setData(0, Qt::DisplayRole, 5); |
|
1933 |
QCOMPARE(item->data(0, Qt::DisplayRole).type(), QVariant::Int); |
|
1934 |
||
1935 |
item->setData(0, Qt::DisplayRole, "test"); |
|
1936 |
QCOMPARE(item->data(0, Qt::DisplayRole).type(), QVariant::String); |
|
1937 |
||
1938 |
item->setData(0, Qt::DisplayRole, 0.4); |
|
1939 |
QCOMPARE(item->data(0, Qt::DisplayRole).type(), QVariant::Double); |
|
1940 |
||
1941 |
delete item; |
|
1942 |
} |
|
1943 |
} |
|
1944 |
||
1945 |
void tst_QTreeWidget::itemData() |
|
1946 |
{ |
|
1947 |
QTreeWidget widget; |
|
1948 |
QTreeWidgetItem item(&widget); |
|
1949 |
widget.setColumnCount(2); |
|
1950 |
item.setFlags(item.flags() | Qt::ItemIsEditable); |
|
1951 |
item.setData(0, Qt::DisplayRole, QString("0")); |
|
1952 |
item.setData(0, Qt::CheckStateRole, Qt::PartiallyChecked); |
|
1953 |
item.setData(0, Qt::UserRole + 0, QString("1")); |
|
1954 |
item.setData(0, Qt::UserRole + 1, QString("2")); |
|
1955 |
item.setData(0, Qt::UserRole + 2, QString("3")); |
|
1956 |
item.setData(0, Qt::UserRole + 3, QString("4")); |
|
1957 |
||
1958 |
QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0)); |
|
1959 |
QCOMPARE(flags.count(), 6); |
|
1960 |
QCOMPARE(flags[Qt::UserRole + 0].toString(), QString("1")); |
|
1961 |
||
1962 |
flags = widget.model()->itemData(widget.model()->index(0, 1)); |
|
1963 |
QCOMPARE(flags.count(), 0); |
|
1964 |
} |
|
1965 |
||
1966 |
void tst_QTreeWidget::enableDisable() |
|
1967 |
{ |
|
1968 |
QTreeWidgetItem *itm = new QTreeWidgetItem(); |
|
1969 |
for (int i = 0; i < 10; ++i) |
|
1970 |
new QTreeWidgetItem(itm); |
|
1971 |
||
1972 |
// make sure all items are enabled |
|
1973 |
QVERIFY(itm->flags() & Qt::ItemIsEnabled); |
|
1974 |
for (int j = 0; j < itm->childCount(); ++j) |
|
1975 |
QVERIFY(itm->child(j)->flags() & Qt::ItemIsEnabled); |
|
1976 |
||
1977 |
// disable root and make sure they are all disabled |
|
1978 |
itm->setFlags(itm->flags() & ~Qt::ItemIsEnabled); |
|
1979 |
QVERIFY(!(itm->flags() & Qt::ItemIsEnabled)); |
|
1980 |
for (int k = 0; k < itm->childCount(); ++k) |
|
1981 |
QVERIFY(!(itm->child(k)->flags() & Qt::ItemIsEnabled)); |
|
1982 |
||
1983 |
// disable a child and make sure they are all still disabled |
|
1984 |
itm->child(5)->setFlags(itm->child(5)->flags() & ~Qt::ItemIsEnabled); |
|
1985 |
QVERIFY(!(itm->flags() & Qt::ItemIsEnabled)); |
|
1986 |
for (int l = 0; l < itm->childCount(); ++l) |
|
1987 |
QVERIFY(!(itm->child(l)->flags() & Qt::ItemIsEnabled)); |
|
1988 |
||
1989 |
// enable root and make sure all items except one are enabled |
|
1990 |
itm->setFlags(itm->flags() | Qt::ItemIsEnabled); |
|
1991 |
QVERIFY(itm->flags() & Qt::ItemIsEnabled); |
|
1992 |
for (int m = 0; m < itm->childCount(); ++m) |
|
1993 |
if (m == 5) |
|
1994 |
QVERIFY(!(itm->child(m)->flags() & Qt::ItemIsEnabled)); |
|
1995 |
else |
|
1996 |
QVERIFY(itm->child(m)->flags() & Qt::ItemIsEnabled); |
|
1997 |
} |
|
1998 |
||
1999 |
void tst_QTreeWidget::match() |
|
2000 |
{ |
|
2001 |
QTreeWidget tree; |
|
2002 |
QModelIndexList list = tree.model()->match(QModelIndex(), Qt::DisplayRole, QString()); |
|
2003 |
||
2004 |
QVERIFY(list.isEmpty()); |
|
2005 |
} |
|
2006 |
||
2007 |
void tst_QTreeWidget::columnCount() |
|
2008 |
{ |
|
2009 |
int columnCountBefore = testWidget->columnCount(); |
|
2010 |
testWidget->setColumnCount(-1); |
|
2011 |
QCOMPARE(testWidget->columnCount(), columnCountBefore); |
|
2012 |
} |
|
2013 |
||
2014 |
void tst_QTreeWidget::setHeaderLabels() |
|
2015 |
{ |
|
2016 |
QStringList list = QString("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z").split(","); |
|
2017 |
testWidget->setHeaderLabels(list); |
|
2018 |
QCOMPARE(testWidget->header()->count(), list.count()); |
|
2019 |
} |
|
2020 |
||
2021 |
void tst_QTreeWidget::setHeaderItem() |
|
2022 |
{ |
|
2023 |
testWidget->setHeaderItem(0); |
|
2024 |
QTreeWidgetItem *headerItem = new QTreeWidgetItem(); |
|
2025 |
||
2026 |
testWidget->setColumnCount(0); |
|
2027 |
QCOMPARE(testWidget->header()->count(), 0); |
|
2028 |
QCOMPARE(testWidget->columnCount(), 0); |
|
2029 |
||
2030 |
headerItem->setText(0, "0"); |
|
2031 |
headerItem->setText(1, "1"); |
|
2032 |
testWidget->setHeaderItem(headerItem); |
|
2033 |
QTest::qWait(100); |
|
2034 |
QCOMPARE(testWidget->headerItem(), headerItem); |
|
2035 |
QCOMPARE(headerItem->treeWidget(), static_cast<QTreeWidget *>(testWidget)); |
|
2036 |
||
2037 |
QCOMPARE(testWidget->header()->count(), 2); |
|
2038 |
QCOMPARE(testWidget->columnCount(), 2); |
|
2039 |
||
2040 |
headerItem->setText(2, "2"); |
|
2041 |
QCOMPARE(testWidget->header()->count(), 3); |
|
2042 |
QCOMPARE(testWidget->columnCount(), 3); |
|
2043 |
||
2044 |
delete headerItem; |
|
2045 |
testWidget->setColumnCount(3); |
|
2046 |
testWidget->setColumnCount(5); |
|
2047 |
QCOMPARE(testWidget->model()->headerData(0, Qt::Horizontal, Qt::DisplayRole).toString(), QString("1")); |
|
2048 |
QCOMPARE(testWidget->model()->headerData(1, Qt::Horizontal, Qt::DisplayRole).toString(), QString("2")); |
|
2049 |
QCOMPARE(testWidget->model()->headerData(2, Qt::Horizontal, Qt::DisplayRole).toString(), QString("3")); |
|
2050 |
QCOMPARE(testWidget->model()->headerData(3, Qt::Horizontal, Qt::DisplayRole).toString(), QString("4")); |
|
2051 |
QCOMPARE(testWidget->model()->headerData(4, Qt::Horizontal, Qt::DisplayRole).toString(), QString("5")); |
|
2052 |
||
2053 |
headerItem = new QTreeWidgetItem(); |
|
2054 |
testWidget->setHeaderItem(headerItem); |
|
2055 |
testWidget->model()->insertColumns(0, 5, QModelIndex()); |
|
2056 |
QCOMPARE(testWidget->model()->headerData(0, Qt::Horizontal, Qt::DisplayRole).toString(), QString("1")); |
|
2057 |
QCOMPARE(testWidget->model()->headerData(1, Qt::Horizontal, Qt::DisplayRole).toString(), QString("2")); |
|
2058 |
QCOMPARE(testWidget->model()->headerData(2, Qt::Horizontal, Qt::DisplayRole).toString(), QString("3")); |
|
2059 |
QCOMPARE(testWidget->model()->headerData(3, Qt::Horizontal, Qt::DisplayRole).toString(), QString("4")); |
|
2060 |
QCOMPARE(testWidget->model()->headerData(4, Qt::Horizontal, Qt::DisplayRole).toString(), QString("5")); |
|
2061 |
} |
|
2062 |
||
2063 |
void tst_QTreeWidget::itemWidget_data() |
|
2064 |
{ |
|
2065 |
editItem_data(); |
|
2066 |
} |
|
2067 |
||
2068 |
void tst_QTreeWidget::itemWidget() |
|
2069 |
{ |
|
2070 |
QFETCH(TreeItemList, topLevelItems); |
|
2071 |
||
2072 |
QTreeWidget tree; |
|
2073 |
populate(&tree, topLevelItems, new TreeItem(QStringList() << "1" << "2")); |
|
2074 |
tree.show(); |
|
2075 |
||
2076 |
for (int x = 0; x < 2; ++x) { |
|
2077 |
QTreeWidgetItemIterator it(&tree); |
|
2078 |
while (QTreeWidgetItem *item = (*it++)) { |
|
2079 |
for (int col = 0; col < item->columnCount(); ++col) { |
|
2080 |
if (x == 0) { |
|
2081 |
QCOMPARE(tree.itemWidget(item, col), static_cast<QWidget*>(0)); |
|
2082 |
QWidget *editor = new QLineEdit(); |
|
2083 |
tree.setItemWidget(item, col, editor); |
|
2084 |
QCOMPARE(tree.itemWidget(item, col), editor); |
|
2085 |
tree.removeItemWidget(item, col); |
|
2086 |
QCOMPARE(tree.itemWidget(item, col), static_cast<QWidget*>(0)); |
|
2087 |
} else { |
|
2088 |
// ### should you really be able to open a persistent |
|
2089 |
// editor for an item that isn't editable?? |
|
2090 |
tree.openPersistentEditor(item, col); |
|
2091 |
QWidget *editor = qFindChild<QLineEdit*>(&tree); |
|
2092 |
QVERIFY(editor != 0); |
|
2093 |
tree.closePersistentEditor(item, col); |
|
2094 |
} |
|
2095 |
} |
|
2096 |
} |
|
2097 |
} |
|
2098 |
} |
|
2099 |
||
2100 |
void tst_QTreeWidget::insertItemsWithSorting_data() |
|
2101 |
{ |
|
2102 |
QTest::addColumn<int>("sortOrder"); |
|
2103 |
QTest::addColumn<QStringList>("initialItems"); |
|
2104 |
QTest::addColumn<QStringList>("insertItems"); |
|
2105 |
QTest::addColumn<QStringList>("expectedItems"); |
|
2106 |
QTest::addColumn<IntList>("expectedRows"); |
|
2107 |
||
2108 |
QTest::newRow("() + (a) = (a)") |
|
2109 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2110 |
<< QStringList() |
|
2111 |
<< (QStringList() << "a") |
|
2112 |
<< (QStringList() << "a") |
|
2113 |
<< IntList(); |
|
2114 |
QTest::newRow("() + (c, b, a) = (a, b, c)") |
|
2115 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2116 |
<< QStringList() |
|
2117 |
<< (QStringList() << "c" << "b" << "a") |
|
2118 |
<< (QStringList() << "a" << "b" << "c") |
|
2119 |
<< IntList(); |
|
2120 |
QTest::newRow("() + (a, b, c) = (c, b, a)") |
|
2121 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2122 |
<< QStringList() |
|
2123 |
<< (QStringList() << "a" << "b" << "c") |
|
2124 |
<< (QStringList() << "c" << "b" << "a") |
|
2125 |
<< IntList(); |
|
2126 |
QTest::newRow("(a) + (b) = (a, b)") |
|
2127 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2128 |
<< QStringList("a") |
|
2129 |
<< (QStringList() << "b") |
|
2130 |
<< (QStringList() << "a" << "b") |
|
2131 |
<< (IntList() << 0); |
|
2132 |
QTest::newRow("(a) + (b) = (b, a)") |
|
2133 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2134 |
<< QStringList("a") |
|
2135 |
<< (QStringList() << "b") |
|
2136 |
<< (QStringList() << "b" << "a") |
|
2137 |
<< (IntList() << 1); |
|
2138 |
QTest::newRow("(a, c, b) + (d) = (a, b, c, d)") |
|
2139 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2140 |
<< (QStringList() << "a" << "c" << "b") |
|
2141 |
<< (QStringList() << "d") |
|
2142 |
<< (QStringList() << "a" << "b" << "c" << "d") |
|
2143 |
<< (IntList() << 0 << 1 << 2); |
|
2144 |
QTest::newRow("(b, c, a) + (d) = (d, c, b, a)") |
|
2145 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2146 |
<< (QStringList() << "b" << "c" << "a") |
|
2147 |
<< (QStringList() << "d") |
|
2148 |
<< (QStringList() << "d" << "c" << "b" << "a") |
|
2149 |
<< (IntList() << 1 << 2 << 3); |
|
2150 |
{ |
|
2151 |
IntList ascendingRows; |
|
2152 |
IntList reverseRows; |
|
2153 |
QStringList ascendingItems; |
|
2154 |
QStringList reverseItems; |
|
2155 |
for (int i = 'a'; i <= 'z'; ++i) { |
|
2156 |
ascendingItems << QString("%0").arg(QLatin1Char(i)); |
|
2157 |
reverseItems << QString("%0").arg(QLatin1Char('z' - i + 'a')); |
|
2158 |
ascendingRows << i - 'a'; |
|
2159 |
reverseRows << 'z' - i + 'a'; |
|
2160 |
} |
|
2161 |
QTest::newRow("() + (sorted items) = (sorted items)") |
|
2162 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2163 |
<< QStringList() |
|
2164 |
<< ascendingItems |
|
2165 |
<< ascendingItems |
|
2166 |
<< IntList(); |
|
2167 |
QTest::newRow("(sorted items) + () = (sorted items)") |
|
2168 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2169 |
<< ascendingItems |
|
2170 |
<< QStringList() |
|
2171 |
<< ascendingItems |
|
2172 |
<< ascendingRows; |
|
2173 |
QTest::newRow("() + (ascending items) = (reverse items)") |
|
2174 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2175 |
<< QStringList() |
|
2176 |
<< ascendingItems |
|
2177 |
<< reverseItems |
|
2178 |
<< IntList(); |
|
2179 |
QTest::newRow("(reverse items) + () = (ascending items)") |
|
2180 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2181 |
<< reverseItems |
|
2182 |
<< QStringList() |
|
2183 |
<< ascendingItems |
|
2184 |
<< ascendingRows; |
|
2185 |
QTest::newRow("(reverse items) + () = (reverse items)") |
|
2186 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2187 |
<< reverseItems |
|
2188 |
<< QStringList() |
|
2189 |
<< reverseItems |
|
2190 |
<< ascendingRows; |
|
2191 |
} |
|
2192 |
} |
|
2193 |
||
2194 |
void tst_QTreeWidget::insertItemsWithSorting() |
|
2195 |
{ |
|
2196 |
QFETCH(int, sortOrder); |
|
2197 |
QFETCH(QStringList, initialItems); |
|
2198 |
QFETCH(QStringList, insertItems); |
|
2199 |
QFETCH(QStringList, expectedItems); |
|
2200 |
QFETCH(IntList, expectedRows); |
|
2201 |
||
2202 |
for (int method = 0; method < 5; ++method) { |
|
2203 |
QTreeWidget w; |
|
2204 |
w.setSortingEnabled(true); |
|
2205 |
w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder)); |
|
2206 |
for (int i = 0; i < initialItems.count(); ++i) |
|
2207 |
w.addTopLevelItem(new QTreeWidgetItem(QStringList() << initialItems.at(i))); |
|
2208 |
||
2209 |
QAbstractItemModel *model = w.model(); |
|
2210 |
QList<QPersistentModelIndex> persistent; |
|
2211 |
for (int j = 0; j < model->rowCount(QModelIndex()); ++j) |
|
2212 |
persistent << model->index(j, 0, QModelIndex()); |
|
2213 |
||
2214 |
switch (method) { |
|
2215 |
case 0: |
|
2216 |
// insert using item constructor |
|
2217 |
for (int i = 0; i < insertItems.size(); ++i) |
|
2218 |
new QTreeWidgetItem(&w, QStringList() << insertItems.at(i)); |
|
2219 |
break; |
|
2220 |
case 1: |
|
2221 |
{ |
|
2222 |
// insert using insertTopLevelItems() |
|
2223 |
QList<QTreeWidgetItem*> lst; |
|
2224 |
for (int i = 0; i < insertItems.size(); ++i) |
|
2225 |
lst << new QTreeWidgetItem(QStringList() << insertItems.at(i)); |
|
2226 |
w.insertTopLevelItems(0, lst); |
|
2227 |
break; |
|
2228 |
} |
|
2229 |
case 2: |
|
2230 |
// insert using insertTopLevelItem() |
|
2231 |
for (int i = 0; i < insertItems.size(); ++i) |
|
2232 |
w.insertTopLevelItem(0, new QTreeWidgetItem(QStringList() << insertItems.at(i))); |
|
2233 |
break; |
|
2234 |
case 3: |
|
2235 |
{ |
|
2236 |
// insert using addTopLevelItems() |
|
2237 |
QList<QTreeWidgetItem*> lst; |
|
2238 |
for (int i = 0; i < insertItems.size(); ++i) |
|
2239 |
lst << new QTreeWidgetItem(QStringList() << insertItems.at(i)); |
|
2240 |
w.addTopLevelItems(lst); |
|
2241 |
break; |
|
2242 |
} |
|
2243 |
case 4: |
|
2244 |
// insert using addTopLevelItem() |
|
2245 |
for (int i = 0; i < insertItems.size(); ++i) |
|
2246 |
w.addTopLevelItem(new QTreeWidgetItem(QStringList() << insertItems.at(i))); |
|
2247 |
break; |
|
2248 |
} |
|
2249 |
QCOMPARE(w.topLevelItemCount(), expectedItems.count()); |
|
2250 |
for (int i = 0; i < w.topLevelItemCount(); ++i) |
|
2251 |
QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i)); |
|
2252 |
||
2253 |
for (int k = 0; k < persistent.count(); ++k) |
|
2254 |
QCOMPARE(persistent.at(k).row(), expectedRows.at(k)); |
|
2255 |
} |
|
2256 |
} |
|
2257 |
||
2258 |
void tst_QTreeWidget::insertExpandedItemsWithSorting_data() |
|
2259 |
{ |
|
2260 |
QTest::addColumn<QStringList>("parentText"); |
|
2261 |
QTest::addColumn<QStringList>("childText"); |
|
2262 |
QTest::addColumn<QStringList>("parentResult"); |
|
2263 |
QTest::addColumn<QStringList>("childResult"); |
|
2264 |
QTest::newRow("test 1") |
|
2265 |
<< (QStringList() << "c" << "d" << "a" << "b") |
|
2266 |
<< (QStringList() << "e" << "h" << "g" << "f") |
|
2267 |
<< (QStringList() << "d" << "c" << "b" << "a") |
|
2268 |
<< (QStringList() << "h" << "g" << "f" << "e"); |
|
2269 |
} |
|
2270 |
||
2271 |
// From Task 134978 |
|
2272 |
void tst_QTreeWidget::insertExpandedItemsWithSorting() |
|
2273 |
{ |
|
2274 |
QFETCH(QStringList, parentText); |
|
2275 |
QFETCH(QStringList, childText); |
|
2276 |
QFETCH(QStringList, parentResult); |
|
2277 |
QFETCH(QStringList, childResult); |
|
2278 |
||
2279 |
// create a tree with autosorting enabled |
|
2280 |
CustomTreeWidget tree; |
|
2281 |
tree.setSortingEnabled(true); |
|
2282 |
||
2283 |
// insert expanded items in unsorted order |
|
2284 |
QList<QTreeWidgetItem *> items; |
|
2285 |
for (int i = 0; i < parentText.count(); ++i) { |
|
2286 |
QTreeWidgetItem *parent = new QTreeWidgetItem(&tree, QStringList(parentText.at(i))); |
|
2287 |
parent->setExpanded(true); |
|
2288 |
QVERIFY(parent->isExpanded()); |
|
2289 |
items << parent; |
|
2290 |
for (int j = 0; j < childText.count(); ++j) { |
|
2291 |
QTreeWidgetItem *child = new QTreeWidgetItem(parent, QStringList(childText.at(j))); |
|
2292 |
items << child; |
|
2293 |
} |
|
2294 |
QCOMPARE(parent->childCount(), childText.count()); |
|
2295 |
QVERIFY(parent->isExpanded()); |
|
2296 |
} |
|
2297 |
QVERIFY(tree.model()->rowCount() == parentText.count()); |
|
2298 |
||
2299 |
// verify that the items are still expanded |
|
2300 |
foreach (QTreeWidgetItem *item, items) { |
|
2301 |
if (item->childCount() > 0) |
|
2302 |
QVERIFY(item->isExpanded()); |
|
2303 |
QModelIndex idx = tree.indexFromItem(const_cast<QTreeWidgetItem *>(item)); |
|
2304 |
QVERIFY(idx.isValid()); |
|
2305 |
//QRect rect = tree.visualRect(idx); |
|
2306 |
//QVERIFY(rect.isValid()); |
|
2307 |
// ### it is not guarantied that the index is in the viewport |
|
2308 |
} |
|
2309 |
||
2310 |
// verify that the tree is sorted |
|
2311 |
QAbstractItemModel *model = tree.model(); |
|
2312 |
QList<QPersistentModelIndex> parents; |
|
2313 |
for (int i = 0; i < model->rowCount(QModelIndex()); ++i) { |
|
2314 |
QPersistentModelIndex parent = model->index(i, 0, QModelIndex()); |
|
2315 |
parents << parent; |
|
2316 |
} |
|
2317 |
QList<QPersistentModelIndex> children; |
|
2318 |
for (int i = 0; i < model->rowCount(parents.first()); ++i) { |
|
2319 |
QPersistentModelIndex child = model->index(i, 0, parents.first()); |
|
2320 |
children << child; |
|
2321 |
} |
|
2322 |
for (int i = 0; i < parentResult.count(); ++i) { |
|
2323 |
QTreeWidgetItem *item = tree.topLevelItem(i); |
|
2324 |
QCOMPARE(item->text(0), parentResult.at(i)); |
|
2325 |
for (int j = 0; j < childResult.count(); ++j) |
|
2326 |
QCOMPARE(item->child(j)->text(0), childResult.at(j)); |
|
2327 |
} |
|
2328 |
} |
|
2329 |
||
2330 |
void tst_QTreeWidget::changeDataWithSorting_data() |
|
2331 |
{ |
|
2332 |
QTest::addColumn<int>("sortOrder"); |
|
2333 |
QTest::addColumn<QStringList>("initialItems"); |
|
2334 |
QTest::addColumn<int>("itemIndex"); |
|
2335 |
QTest::addColumn<QString>("newValue"); |
|
2336 |
QTest::addColumn<QStringList>("expectedItems"); |
|
2337 |
QTest::addColumn<IntList>("expectedRows"); |
|
2338 |
QTest::addColumn<bool>("reorderingExpected"); |
|
2339 |
||
2340 |
QTest::newRow("change a to b in (a)") |
|
2341 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2342 |
<< (QStringList() << "a") |
|
2343 |
<< 0 << "b" |
|
2344 |
<< (QStringList() << "b") |
|
2345 |
<< (IntList() << 0) |
|
2346 |
<< false; |
|
2347 |
QTest::newRow("change a to b in (a, c)") |
|
2348 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2349 |
<< (QStringList() << "a" << "c") |
|
2350 |
<< 0 << "b" |
|
2351 |
<< (QStringList() << "b" << "c") |
|
2352 |
<< (IntList() << 0 << 1) |
|
2353 |
<< false; |
|
2354 |
QTest::newRow("change a to c in (a, b)") |
|
2355 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2356 |
<< (QStringList() << "a" << "b") |
|
2357 |
<< 0 << "c" |
|
2358 |
<< (QStringList() << "b" << "c") |
|
2359 |
<< (IntList() << 1 << 0) |
|
2360 |
<< true; |
|
2361 |
QTest::newRow("change c to a in (c, b)") |
|
2362 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2363 |
<< (QStringList() << "c" << "b") |
|
2364 |
<< 0 << "a" |
|
2365 |
<< (QStringList() << "b" << "a") |
|
2366 |
<< (IntList() << 1 << 0) |
|
2367 |
<< true; |
|
2368 |
QTest::newRow("change e to i in (a, c, e, g)") |
|
2369 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2370 |
<< (QStringList() << "a" << "c" << "e" << "g") |
|
2371 |
<< 2 << "i" |
|
2372 |
<< (QStringList() << "a" << "c" << "g" << "i") |
|
2373 |
<< (IntList() << 0 << 1 << 3 << 2) |
|
2374 |
<< true; |
|
2375 |
QTest::newRow("change e to a in (c, e, g, i)") |
|
2376 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2377 |
<< (QStringList() << "c" << "e" << "g" << "i") |
|
2378 |
<< 1 << "a" |
|
2379 |
<< (QStringList() << "a" << "c" << "g" << "i") |
|
2380 |
<< (IntList() << 1 << 0 << 2 << 3) |
|
2381 |
<< true; |
|
2382 |
QTest::newRow("change e to f in (c, e, g, i)") |
|
2383 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2384 |
<< (QStringList() << "c" << "e" << "g" << "i") |
|
2385 |
<< 1 << "f" |
|
2386 |
<< (QStringList() << "c" << "f" << "g" << "i") |
|
2387 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
2388 |
<< false; |
|
2389 |
} |
|
2390 |
||
2391 |
void tst_QTreeWidget::changeDataWithSorting() |
|
2392 |
{ |
|
2393 |
QFETCH(int, sortOrder); |
|
2394 |
QFETCH(QStringList, initialItems); |
|
2395 |
QFETCH(int, itemIndex); |
|
2396 |
QFETCH(QString, newValue); |
|
2397 |
QFETCH(QStringList, expectedItems); |
|
2398 |
QFETCH(IntList, expectedRows); |
|
2399 |
QFETCH(bool, reorderingExpected); |
|
2400 |
||
2401 |
QTreeWidget w; |
|
2402 |
w.setSortingEnabled(true); |
|
2403 |
w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder)); |
|
2404 |
for (int i = 0; i < initialItems.count(); ++i) |
|
2405 |
w.addTopLevelItem(new QTreeWidgetItem(QStringList() << initialItems.at(i))); |
|
2406 |
||
2407 |
QAbstractItemModel *model = w.model(); |
|
2408 |
QList<QPersistentModelIndex> persistent; |
|
2409 |
for (int j = 0; j < model->rowCount(QModelIndex()); ++j) |
|
2410 |
persistent << model->index(j, 0, QModelIndex()); |
|
2411 |
||
2412 |
QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &))); |
|
2413 |
QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged())); |
|
2414 |
||
2415 |
QTreeWidgetItem *item = w.topLevelItem(itemIndex); |
|
2416 |
item->setText(0, newValue); |
|
2417 |
for (int i = 0; i < expectedItems.count(); ++i) { |
|
2418 |
QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i)); |
|
2419 |
for (int j = 0; j < persistent.count(); ++j) { |
|
2420 |
if (persistent.at(j).row() == i) // the same toplevel row |
|
2421 |
QCOMPARE(persistent.at(j).internalPointer(), (void *)w.topLevelItem(i)); |
|
2422 |
} |
|
2423 |
} |
|
2424 |
||
2425 |
for (int k = 0; k < persistent.count(); ++k) |
|
2426 |
QCOMPARE(persistent.at(k).row(), expectedRows.at(k)); |
|
2427 |
||
2428 |
QCOMPARE(dataChangedSpy.count(), 1); |
|
2429 |
QCOMPARE(layoutChangedSpy.count(), reorderingExpected ? 1 : 0); |
|
2430 |
} |
|
2431 |
||
2432 |
void tst_QTreeWidget::changeDataWithStableSorting_data() |
|
2433 |
{ |
|
2434 |
QTest::addColumn<int>("sortOrder"); |
|
2435 |
QTest::addColumn<QStringList>("initialItems"); |
|
2436 |
QTest::addColumn<int>("itemIndex"); |
|
2437 |
QTest::addColumn<QString>("newValue"); |
|
2438 |
QTest::addColumn<QStringList>("expectedItems"); |
|
2439 |
QTest::addColumn<IntList>("expectedRows"); |
|
2440 |
QTest::addColumn<bool>("reorderingExpected"); |
|
2441 |
QTest::addColumn<bool>("forceChange"); |
|
2442 |
||
2443 |
QTest::newRow("change a to c in (a, c, c, c, e)") |
|
2444 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2445 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2446 |
<< 0 << "c" |
|
2447 |
<< (QStringList() << "c" << "c" << "c" << "c" << "e") |
|
2448 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2449 |
<< false |
|
2450 |
<< false; |
|
2451 |
QTest::newRow("change e to c in (a, c, c, c, e)") |
|
2452 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2453 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2454 |
<< 4 << "c" |
|
2455 |
<< (QStringList() << "a" << "c" << "c" << "c" << "c") |
|
2456 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2457 |
<< false |
|
2458 |
<< false; |
|
2459 |
QTest::newRow("change 1st c to c in (a, c, c, c, e)") |
|
2460 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2461 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2462 |
<< 1 << "c" |
|
2463 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2464 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2465 |
<< false |
|
2466 |
<< true; |
|
2467 |
QTest::newRow("change 2nd c to c in (a, c, c, c, e)") |
|
2468 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2469 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2470 |
<< 2 << "c" |
|
2471 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2472 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2473 |
<< false |
|
2474 |
<< true; |
|
2475 |
QTest::newRow("change 3rd c to c in (a, c, c, c, e)") |
|
2476 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2477 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2478 |
<< 3 << "c" |
|
2479 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2480 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2481 |
<< false |
|
2482 |
<< true; |
|
2483 |
QTest::newRow("change 1st c to c in (e, c, c, c, a)") |
|
2484 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2485 |
<< (QStringList() << "e" << "c" << "c" << "c" << "a") |
|
2486 |
<< 1 << "c" |
|
2487 |
<< (QStringList() << "e" << "c" << "c" << "c" << "a") |
|
2488 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2489 |
<< false |
|
2490 |
<< true; |
|
2491 |
QTest::newRow("change 2nd c to c in (e, c, c, c, a)") |
|
2492 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2493 |
<< (QStringList() << "e" << "c" << "c" << "c" << "a") |
|
2494 |
<< 2 << "c" |
|
2495 |
<< (QStringList() << "e" << "c" << "c" << "c" << "a") |
|
2496 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2497 |
<< false |
|
2498 |
<< true; |
|
2499 |
QTest::newRow("change 3rd c to c in (e, c, c, c, a)") |
|
2500 |
<< static_cast<int>(Qt::DescendingOrder) |
|
2501 |
<< (QStringList() << "e" << "c" << "c" << "c" << "a") |
|
2502 |
<< 3 << "c" |
|
2503 |
<< (QStringList() << "e" << "c" << "c" << "c" << "a") |
|
2504 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2505 |
<< false |
|
2506 |
<< true; |
|
2507 |
QTest::newRow("change 1st c to b in (a, c, c, c, e)") |
|
2508 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2509 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2510 |
<< 1 << "b" |
|
2511 |
<< (QStringList() << "a" << "b" << "c" << "c" << "e") |
|
2512 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2513 |
<< false |
|
2514 |
<< false; |
|
2515 |
QTest::newRow("change 2nd c to b in (a, c, c, c, e)") |
|
2516 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2517 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2518 |
<< 2 << "b" |
|
2519 |
<< (QStringList() << "a" << "b" << "c" << "c" << "e") |
|
2520 |
<< (IntList() << 0 << 2 << 1 << 3 << 4) |
|
2521 |
<< true |
|
2522 |
<< false; |
|
2523 |
QTest::newRow("change 3rd c to b in (a, c, c, c, e)") |
|
2524 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2525 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2526 |
<< 3 << "b" |
|
2527 |
<< (QStringList() << "a" << "b" << "c" << "c" << "e") |
|
2528 |
<< (IntList() << 0 << 2 << 3 << 1 << 4) |
|
2529 |
<< true |
|
2530 |
<< false; |
|
2531 |
QTest::newRow("change 1st c to d in (a, c, c, c, e)") |
|
2532 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2533 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2534 |
<< 1 << "d" |
|
2535 |
<< (QStringList() << "a" << "c" << "c" << "d" << "e") |
|
2536 |
<< (IntList() << 0 << 3 << 1 << 2 << 4) |
|
2537 |
<< true |
|
2538 |
<< false; |
|
2539 |
QTest::newRow("change 2nd c to d in (a, c, c, c, e)") |
|
2540 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2541 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2542 |
<< 2 << "d" |
|
2543 |
<< (QStringList() << "a" << "c" << "c" << "d" << "e") |
|
2544 |
<< (IntList() << 0 << 1 << 3 << 2 << 4) |
|
2545 |
<< true |
|
2546 |
<< false; |
|
2547 |
QTest::newRow("change 3rd c to d in (a, c, c, c, e)") |
|
2548 |
<< static_cast<int>(Qt::AscendingOrder) |
|
2549 |
<< (QStringList() << "a" << "c" << "c" << "c" << "e") |
|
2550 |
<< 3 << "d" |
|
2551 |
<< (QStringList() << "a" << "c" << "c" << "d" << "e") |
|
2552 |
<< (IntList() << 0 << 1 << 2 << 3 << 4) |
|
2553 |
<< false |
|
2554 |
<< false; |
|
2555 |
} |
|
2556 |
||
2557 |
void tst_QTreeWidget::changeDataWithStableSorting() |
|
2558 |
{ |
|
2559 |
QFETCH(int, sortOrder); |
|
2560 |
QFETCH(QStringList, initialItems); |
|
2561 |
QFETCH(int, itemIndex); |
|
2562 |
QFETCH(QString, newValue); |
|
2563 |
QFETCH(QStringList, expectedItems); |
|
2564 |
QFETCH(IntList, expectedRows); |
|
2565 |
QFETCH(bool, reorderingExpected); |
|
2566 |
QFETCH(bool, forceChange); |
|
2567 |
||
2568 |
class StableItem : public QTreeWidgetItem |
|
2569 |
{ |
|
2570 |
public: |
|
2571 |
StableItem(const QStringList &strings) : QTreeWidgetItem(strings, QTreeWidgetItem::UserType) {} |
|
2572 |
void forceChangeData() { |
|
2573 |
emitDataChanged(); |
|
2574 |
} |
|
2575 |
}; |
|
2576 |
||
2577 |
QTreeWidget w; |
|
2578 |
w.setSortingEnabled(true); |
|
2579 |
w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder)); |
|
2580 |
for (int i = 0; i < initialItems.count(); ++i) |
|
2581 |
w.addTopLevelItem(new StableItem(QStringList() << initialItems.at(i))); |
|
2582 |
||
2583 |
QAbstractItemModel *model = w.model(); |
|
2584 |
QList<QPersistentModelIndex> persistent; |
|
2585 |
for (int j = 0; j < model->rowCount(QModelIndex()); ++j) |
|
2586 |
persistent << model->index(j, 0, QModelIndex()); |
|
2587 |
||
2588 |
QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &))); |
|
2589 |
QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged())); |
|
2590 |
||
2591 |
StableItem *item = static_cast<StableItem *>(w.topLevelItem(itemIndex)); |
|
2592 |
item->setText(0, newValue); |
|
2593 |
if (forceChange) |
|
2594 |
item->forceChangeData(); |
|
2595 |
for (int i = 0; i < expectedItems.count(); ++i) { |
|
2596 |
QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i)); |
|
2597 |
for (int j = 0; j < persistent.count(); ++j) { |
|
2598 |
if (persistent.at(j).row() == i) // the same toplevel row |
|
2599 |
QCOMPARE(persistent.at(j).internalPointer(), (void *)w.topLevelItem(i)); |
|
2600 |
} |
|
2601 |
} |
|
2602 |
||
2603 |
for (int k = 0; k < persistent.count(); ++k) |
|
2604 |
QCOMPARE(persistent.at(k).row(), expectedRows.at(k)); |
|
2605 |
||
2606 |
QCOMPARE(dataChangedSpy.count(), 1); |
|
2607 |
QCOMPARE(layoutChangedSpy.count(), reorderingExpected ? 1 : 0); |
|
2608 |
} |
|
2609 |
||
2610 |
void tst_QTreeWidget::itemOperatorLessThan() |
|
2611 |
{ |
|
2612 |
QTreeWidget tw; |
|
2613 |
tw.setColumnCount(2); |
|
2614 |
{ |
|
2615 |
QTreeWidgetItem item1(&tw); |
|
2616 |
QTreeWidgetItem item2(&tw); |
|
2617 |
QCOMPARE(item1 < item2, false); |
|
2618 |
item1.setText(1, "a"); |
|
2619 |
item2.setText(1, "b"); |
|
2620 |
QCOMPARE(item1 < item2, false); |
|
2621 |
item1.setText(0, "a"); |
|
2622 |
item2.setText(0, "b"); |
|
2623 |
QCOMPARE(item1 < item2, true); |
|
2624 |
tw.sortItems(1, Qt::AscendingOrder); |
|
2625 |
item1.setText(0, "b"); |
|
2626 |
item2.setText(0, "a"); |
|
2627 |
QCOMPARE(item1 < item2, true); |
|
2628 |
tw.sortItems(0, Qt::AscendingOrder); |
|
2629 |
item1.setData(0, Qt::DisplayRole, 11); |
|
2630 |
item2.setData(0, Qt::DisplayRole, 2); |
|
2631 |
QCOMPARE(item1 < item2, false); |
|
2632 |
} |
|
2633 |
} |
|
2634 |
||
2635 |
void tst_QTreeWidget::sortedIndexOfChild_data() |
|
2636 |
{ |
|
2637 |
QTest::addColumn<int>("sortOrder"); |
|
2638 |
QTest::addColumn<QStringList>("itemTexts"); |
|
2639 |
QTest::addColumn<QList<int> >("expectedIndexes"); |
|
2640 |
||
2641 |
QTest::newRow("three ascending") |
|
2642 |
<< int(Qt::AscendingOrder) |
|
2643 |
<< (QStringList() << "A" << "B" << "C") |
|
2644 |
<< (QList<int>() << 0 << 1 << 2); |
|
2645 |
||
2646 |
||
2647 |
QTest::newRow("three descending") |
|
2648 |
<< int(Qt::DescendingOrder) |
|
2649 |
<< (QStringList() << "A" << "B" << "C") |
|
2650 |
<< (QList<int>() << 2 << 1 << 0); |
|
2651 |
} |
|
2652 |
||
2653 |
void tst_QTreeWidget::sortedIndexOfChild() |
|
2654 |
{ |
|
2655 |
QFETCH(int, sortOrder); |
|
2656 |
QFETCH(QStringList, itemTexts); |
|
2657 |
QFETCH(QList<int>, expectedIndexes); |
|
2658 |
||
2659 |
QTreeWidget tw; |
|
2660 |
QList<QTreeWidgetItem*> itms; |
|
2661 |
QTreeWidgetItem *top = new QTreeWidgetItem(&tw, QStringList() << "top"); |
|
2662 |
||
2663 |
for (int i = 0; i < itemTexts.count(); ++i) |
|
2664 |
itms << new QTreeWidgetItem(top, QStringList() << itemTexts.at(i)); |
|
2665 |
||
2666 |
tw.sortItems(0, (Qt::SortOrder)sortOrder); |
|
2667 |
tw.expandAll(); |
|
2668 |
||
2669 |
QVERIFY(itms.count() == expectedIndexes.count()); |
|
2670 |
for (int j = 0; j < expectedIndexes.count(); ++j) |
|
2671 |
QCOMPARE(top->indexOfChild(itms.at(j)), expectedIndexes.at(j)); |
|
2672 |
} |
|
2673 |
||
2674 |
void tst_QTreeWidget::expandAndCallapse() |
|
2675 |
{ |
|
2676 |
QTreeWidget tw; |
|
2677 |
QTreeWidgetItem *top = new QTreeWidgetItem(&tw, QStringList() << "top"); |
|
2678 |
QTreeWidgetItem *p; |
|
2679 |
for (int i = 0; i < 10; ++i) { |
|
2680 |
p = new QTreeWidgetItem(top, QStringList() << QString("%1").arg(i)); |
|
2681 |
for (int j = 0; j < 10; ++j) |
|
2682 |
new QTreeWidgetItem(p, QStringList() << QString("%1").arg(j)); |
|
2683 |
} |
|
2684 |
QSignalSpy spy0(&tw, SIGNAL(itemExpanded(QTreeWidgetItem *))); |
|
2685 |
QSignalSpy spy1(&tw, SIGNAL(itemCollapsed(QTreeWidgetItem *))); |
|
2686 |
||
2687 |
||
2688 |
tw.expandItem(p); |
|
2689 |
tw.collapseItem(p); |
|
2690 |
tw.expandItem(p); |
|
2691 |
tw.expandItem(top); |
|
2692 |
tw.collapseItem(top); |
|
2693 |
tw.collapseItem(top); |
|
2694 |
||
2695 |
QCOMPARE(spy0.count(), 3); |
|
2696 |
QCOMPARE(spy1.count(), 2); |
|
2697 |
} |
|
2698 |
||
2699 |
void tst_QTreeWidget::setDisabled() |
|
2700 |
{ |
|
2701 |
QTreeWidget w; |
|
2702 |
QTreeWidgetItem *i1 = new QTreeWidgetItem(); |
|
2703 |
QTreeWidgetItem *i2 = new QTreeWidgetItem(i1); |
|
2704 |
QTreeWidgetItem *i3 = new QTreeWidgetItem(i1); |
|
2705 |
||
2706 |
QTreeWidgetItem *top = new QTreeWidgetItem(&w); |
|
2707 |
top->setDisabled(true); |
|
2708 |
top->addChild(i1); |
|
2709 |
QCOMPARE(i1->isDisabled(), true); |
|
2710 |
QCOMPARE(i2->isDisabled(), true); |
|
2711 |
QCOMPARE(i3->isDisabled(), true); |
|
2712 |
||
2713 |
i1 = top->takeChild(0); |
|
2714 |
QCOMPARE(i1->isDisabled(), false); |
|
2715 |
QCOMPARE(i2->isDisabled(), false); |
|
2716 |
QCOMPARE(i3->isDisabled(), false); |
|
2717 |
||
2718 |
top->addChild(i1); |
|
2719 |
QCOMPARE(i1->isDisabled(), true); |
|
2720 |
QCOMPARE(i2->isDisabled(), true); |
|
2721 |
QCOMPARE(i3->isDisabled(), true); |
|
2722 |
||
2723 |
top->setDisabled(false); |
|
2724 |
QCOMPARE(i1->isDisabled(), false); |
|
2725 |
QCOMPARE(i2->isDisabled(), false); |
|
2726 |
QCOMPARE(i3->isDisabled(), false); |
|
2727 |
||
2728 |
||
2729 |
||
2730 |
QList<QTreeWidgetItem*> children; |
|
2731 |
children.append(new QTreeWidgetItem()); |
|
2732 |
children.append(new QTreeWidgetItem()); |
|
2733 |
children.append(new QTreeWidgetItem()); |
|
2734 |
i1 = top->takeChild(0); |
|
2735 |
||
2736 |
top->addChildren(children); |
|
2737 |
QCOMPARE(top->child(0)->isDisabled(), false); |
|
2738 |
QCOMPARE(top->child(1)->isDisabled(), false); |
|
2739 |
QCOMPARE(top->child(1)->isDisabled(), false); |
|
2740 |
||
2741 |
top->setDisabled(true); |
|
2742 |
QCOMPARE(top->child(0)->isDisabled(), true); |
|
2743 |
QCOMPARE(top->child(1)->isDisabled(), true); |
|
2744 |
QCOMPARE(top->child(1)->isDisabled(), true); |
|
2745 |
||
2746 |
children = top->takeChildren(); |
|
2747 |
QCOMPARE(children.at(0)->isDisabled(), false); |
|
2748 |
QCOMPARE(children.at(1)->isDisabled(), false); |
|
2749 |
QCOMPARE(children.at(1)->isDisabled(), false); |
|
2750 |
||
2751 |
} |
|
2752 |
||
2753 |
void tst_QTreeWidget::removeSelectedItem() |
|
2754 |
{ |
|
2755 |
QTreeWidget *w = new QTreeWidget(); |
|
2756 |
w->setSortingEnabled(true); |
|
2757 |
||
2758 |
QTreeWidgetItem *first = new QTreeWidgetItem(); |
|
2759 |
first->setText(0, QLatin1String("D")); |
|
2760 |
w->addTopLevelItem(first); |
|
2761 |
||
2762 |
QTreeWidgetItem *itm = new QTreeWidgetItem(); |
|
2763 |
itm->setText(0, QLatin1String("D")); |
|
2764 |
w->addTopLevelItem(itm); |
|
2765 |
||
2766 |
itm = new QTreeWidgetItem(); |
|
2767 |
itm->setText(0, QLatin1String("C")); |
|
2768 |
w->addTopLevelItem(itm); |
|
2769 |
itm->setSelected(true); |
|
2770 |
||
2771 |
itm = new QTreeWidgetItem(); |
|
2772 |
itm->setText(0, QLatin1String("A")); |
|
2773 |
w->addTopLevelItem(itm); |
|
2774 |
||
2775 |
//w->show(); |
|
2776 |
||
2777 |
QItemSelectionModel *selModel = w->selectionModel(); |
|
2778 |
QCOMPARE(selModel->hasSelection(), true); |
|
2779 |
QCOMPARE(selModel->selectedRows().count(), 1); |
|
2780 |
||
2781 |
QTreeWidgetItem *taken = w->takeTopLevelItem(2); |
|
2782 |
QCOMPARE(taken->text(0), QLatin1String("C")); |
|
2783 |
||
2784 |
QCOMPARE(selModel->hasSelection(), false); |
|
2785 |
QCOMPARE(selModel->selectedRows().count(), 0); |
|
2786 |
QItemSelection sel = selModel->selection(); |
|
2787 |
QCOMPARE(selModel->isSelected(w->model()->index(0,0)), false); |
|
2788 |
||
2789 |
delete w; |
|
2790 |
} |
|
2791 |
||
2792 |
class AnotherTreeWidget : public QTreeWidget |
|
2793 |
{ |
|
2794 |
Q_OBJECT |
|
2795 |
public: |
|
2796 |
AnotherTreeWidget(QWidget *parent = 0) : QTreeWidget(parent) {} |
|
2797 |
void deleteCurrent() { if (currentItem()) delete currentItem(); } |
|
2798 |
}; |
|
2799 |
||
2800 |
void tst_QTreeWidget::removeCurrentItem() |
|
2801 |
{ |
|
2802 |
AnotherTreeWidget widget; |
|
2803 |
QObject::connect(widget.selectionModel(), |
|
2804 |
SIGNAL(currentChanged(QModelIndex,QModelIndex)), |
|
2805 |
&widget, SLOT(clear())); |
|
2806 |
QTreeWidgetItem *item = new QTreeWidgetItem(&widget); |
|
2807 |
widget.setCurrentItem(item); |
|
2808 |
widget.deleteCurrent(); |
|
2809 |
} |
|
2810 |
||
2811 |
void tst_QTreeWidget::removeCurrentItem_task186451() |
|
2812 |
{ |
|
2813 |
AnotherTreeWidget widget; |
|
2814 |
QTreeWidgetItem *item = new QTreeWidgetItem(&widget, QStringList() << "1"); |
|
2815 |
QTreeWidgetItem *item2 = new QTreeWidgetItem(&widget, QStringList() << "2"); |
|
2816 |
widget.setCurrentItem(item); |
|
2817 |
widget.deleteCurrent(); |
|
2818 |
||
2819 |
QVERIFY(item2->isSelected()); |
|
2820 |
QCOMPARE(item2, widget.currentItem()); |
|
2821 |
} |
|
2822 |
||
2823 |
||
2824 |
class TreeWidget : QTreeWidget { |
|
2825 |
||
2826 |
public: |
|
2827 |
QModelIndex indexFromItem(QTreeWidgetItem *item, int column = 0) const { |
|
2828 |
return QTreeWidget::indexFromItem(item, column); |
|
2829 |
} |
|
2830 |
QTreeWidgetItem *itemFromIndex(const QModelIndex &index) const { |
|
2831 |
return QTreeWidget::itemFromIndex(index); |
|
2832 |
} |
|
2833 |
}; |
|
2834 |
||
2835 |
||
2836 |
void tst_QTreeWidget::randomExpand() |
|
2837 |
{ |
|
2838 |
QTreeWidget tree; |
|
2839 |
QTreeWidgetItem *item1 = new QTreeWidgetItem(&tree); |
|
2840 |
QTreeWidgetItem *item3 = new QTreeWidgetItem(&tree, item1); |
|
2841 |
new QTreeWidgetItem(item1); |
|
2842 |
new QTreeWidgetItem(item3); |
|
2843 |
||
2844 |
tree.expandAll(); |
|
2845 |
||
2846 |
/* |
|
2847 |
item1 |
|
2848 |
\- item2 |
|
2849 |
item3 |
|
2850 |
\- item4 |
|
2851 |
*/ |
|
2852 |
||
2853 |
QTreeWidgetItem *newItem1 = 0; |
|
2854 |
for (int i = 0; i < 100; i++) { |
|
2855 |
newItem1 = new QTreeWidgetItem(&tree, item1); |
|
2856 |
tree.setItemExpanded(newItem1, true); |
|
2857 |
QCOMPARE(tree.isItemExpanded(newItem1), true); |
|
2858 |
||
2859 |
QTreeWidgetItem *x = new QTreeWidgetItem(); |
|
2860 |
QCOMPARE(tree.isItemExpanded(newItem1), true); |
|
2861 |
newItem1->addChild(x); |
|
2862 |
||
2863 |
QCOMPARE(tree.isItemExpanded(newItem1), true); |
|
2864 |
} |
|
2865 |
||
2866 |
} |
|
2867 |
||
2868 |
void tst_QTreeWidget::crashTest() |
|
2869 |
{ |
|
2870 |
QTreeWidget *tree = new QTreeWidget(); |
|
2871 |
tree->setColumnCount(1); |
|
2872 |
tree->show(); |
|
2873 |
||
2874 |
QTreeWidgetItem *item1 = new QTreeWidgetItem(tree); |
|
2875 |
item1->setText(0, "item1"); |
|
2876 |
tree->setItemExpanded(item1, true); |
|
2877 |
QTreeWidgetItem *item2 = new QTreeWidgetItem(item1); |
|
2878 |
item2->setText(0, "item2"); |
|
2879 |
||
2880 |
QTreeWidgetItem *item3 = new QTreeWidgetItem(tree, item1); |
|
2881 |
item3->setText(0, "item3"); |
|
2882 |
tree->setItemExpanded(item3, true); |
|
2883 |
QTreeWidgetItem *item4 = new QTreeWidgetItem(item3); |
|
2884 |
item4->setText(0, "item4"); |
|
2885 |
||
2886 |
QTreeWidgetItem *item5 = new QTreeWidgetItem(tree, item3); |
|
2887 |
item5->setText(0, "item5"); |
|
2888 |
tree->setItemExpanded(item5, true); |
|
2889 |
QTreeWidgetItem *item6 = new QTreeWidgetItem(item5); |
|
2890 |
item6->setText(0, "item6"); |
|
2891 |
||
2892 |
for (int i = 0; i < 1000; i++) { |
|
2893 |
QTreeWidgetItem *newItem1 = new QTreeWidgetItem(tree, item1); |
|
2894 |
newItem1->setText(0, "newItem"); |
|
2895 |
QTreeWidgetItem *newItem2 = new QTreeWidgetItem(newItem1); |
|
2896 |
newItem2->setText(0, "subItem1"); |
|
2897 |
QTreeWidgetItem *newItem3 = new QTreeWidgetItem(newItem1, newItem2); |
|
2898 |
newItem3->setText(0, "subItem2"); |
|
2899 |
delete item3; |
|
2900 |
item3 = newItem1; |
|
2901 |
} |
|
2902 |
QApplication::instance()->processEvents(); |
|
2903 |
||
2904 |
delete tree; |
|
2905 |
} |
|
2906 |
||
2907 |
class CrashWidget : public QTreeWidget |
|
2908 |
{ |
|
2909 |
public: |
|
2910 |
CrashWidget(QWidget *parent = 0) : QTreeWidget(parent), i(0) { |
|
2911 |
setSortingEnabled(true); |
|
2912 |
timerId = startTimer(10); |
|
2913 |
} |
|
2914 |
int i; |
|
2915 |
protected: |
|
2916 |
void timerEvent(QTimerEvent * event) { |
|
2917 |
if (event->timerId() == timerId) { |
|
2918 |
QTreeWidgetItem *newItem = new QTreeWidgetItem((QStringList() << QString::number(i++))); |
|
2919 |
m_list.append(newItem); |
|
2920 |
insertTopLevelItem(0, newItem); |
|
2921 |
while (m_list.count() > 10) |
|
2922 |
delete m_list.takeFirst(); |
|
2923 |
} |
|
2924 |
QTreeWidget::timerEvent(event); |
|
2925 |
} |
|
2926 |
private: |
|
2927 |
int timerId; |
|
2928 |
QList<QTreeWidgetItem*> m_list; |
|
2929 |
}; |
|
2930 |
||
2931 |
void tst_QTreeWidget::sortAndSelect() |
|
2932 |
{ |
|
2933 |
CrashWidget w; |
|
2934 |
w.resize(1, 1); |
|
2935 |
w.show(); |
|
2936 |
while (w.i < 100) { |
|
2937 |
QApplication::processEvents(); |
|
2938 |
if (w.i & 16) { |
|
2939 |
QPoint pt = w.viewport()->rect().center(); |
|
2940 |
QTest::mouseClick(w.viewport(), Qt::LeftButton, Qt::NoModifier, pt); |
|
2941 |
} |
|
2942 |
} |
|
2943 |
QVERIFY(true); |
|
2944 |
} |
|
2945 |
||
2946 |
void tst_QTreeWidget::defaultRowSizes() |
|
2947 |
{ |
|
2948 |
QTreeWidget *tw = new QTreeWidget(); |
|
2949 |
tw->setIconSize(QSize(50, 50)); |
|
2950 |
tw->setColumnCount(6); |
|
2951 |
for (int i=0; i<10; ++i) { |
|
2952 |
QTreeWidgetItem *it = new QTreeWidgetItem(tw); |
|
2953 |
for (int j=0; j<tw->columnCount() - 1; ++j) { |
|
2954 |
it->setText(j, "This is a test"); |
|
2955 |
} |
|
2956 |
QPixmap icon = tw->style()->standardPixmap((QStyle::StandardPixmap)(i + QStyle::SP_TitleBarMenuButton)); |
|
2957 |
if (icon.isNull()) |
|
2958 |
QSKIP("No pixmap found on current style, skipping this test.", SkipSingle); |
|
2959 |
it->setIcon(tw->columnCount() - 1, |
|
2960 |
icon.scaled(tw->iconSize())); |
|
2961 |
} |
|
2962 |
tw->resize(100,100); |
|
2963 |
tw->show(); |
|
2964 |
QApplication::processEvents(); |
|
2965 |
||
2966 |
QRect visualRect = tw->visualItemRect(tw->topLevelItem(0)); |
|
2967 |
QVERIFY(visualRect.height() >= 50); |
|
2968 |
} |
|
2969 |
||
2970 |
void tst_QTreeWidget::task191552_rtl() |
|
2971 |
{ |
|
2972 |
Qt::LayoutDirection oldDir = qApp->layoutDirection(); |
|
2973 |
qApp->setLayoutDirection(Qt::RightToLeft); |
|
2974 |
||
2975 |
QTreeWidget tw; |
|
2976 |
tw.setColumnCount(1); |
|
2977 |
QTreeWidgetItem *item = new QTreeWidgetItem(&tw); |
|
2978 |
item->setText(0, "item 1"); |
|
2979 |
item->setCheckState(0, Qt::Checked); |
|
2980 |
QCOMPARE(item->checkState(0), Qt::Checked); |
|
2981 |
tw.show(); |
|
2982 |
QTest::qWait(50); |
|
2983 |
QStyleOptionViewItem opt; |
|
2984 |
opt.initFrom(&tw); |
|
2985 |
opt.rect = tw.visualItemRect(item); |
|
2986 |
const QRect checkRect = tw.style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, &tw); |
|
2987 |
QTest::mouseClick(tw.viewport(), Qt::LeftButton, Qt::NoModifier, checkRect.center()); |
|
2988 |
QTest::qWait(200); |
|
2989 |
QCOMPARE(item->checkState(0), Qt::Unchecked); |
|
2990 |
||
2991 |
qApp->setLayoutDirection(oldDir); |
|
2992 |
} |
|
2993 |
||
2994 |
void tst_QTreeWidget::task203673_selection() |
|
2995 |
{ |
|
2996 |
//we try to change the selection by rightclick + ctrl |
|
2997 |
//it should do anything when using ExtendedSelection |
|
2998 |
||
2999 |
QTreeWidget tw; |
|
3000 |
tw.setColumnCount(1); |
|
3001 |
QTreeWidgetItem *item1 = new QTreeWidgetItem(&tw); |
|
3002 |
item1->setText(0, "item 1"); |
|
3003 |
tw.setSelectionMode(QTreeView::ExtendedSelection); |
|
3004 |
||
3005 |
QPoint center = tw.visualItemRect(item1).center(); |
|
3006 |
QCOMPARE(item1->isSelected(), false); |
|
3007 |
||
3008 |
QTest::mouseClick(tw.viewport(), Qt::RightButton, Qt::ControlModifier, center); |
|
3009 |
QCOMPARE(item1->isSelected(), false); |
|
3010 |
||
3011 |
QTest::mouseClick(tw.viewport(), Qt::LeftButton, Qt::ControlModifier, center); |
|
3012 |
QCOMPARE(item1->isSelected(), true); |
|
3013 |
||
3014 |
QTest::mouseClick(tw.viewport(), Qt::RightButton, Qt::ControlModifier, center); |
|
3015 |
QCOMPARE(item1->isSelected(), true); //it shouldn't change |
|
3016 |
||
3017 |
QTest::mouseClick(tw.viewport(), Qt::LeftButton, Qt::ControlModifier, center); |
|
3018 |
QCOMPARE(item1->isSelected(), false); |
|
3019 |
} |
|
3020 |
||
3021 |
||
3022 |
void tst_QTreeWidget::rootItemFlags() |
|
3023 |
{ |
|
3024 |
QTreeWidget tw; |
|
3025 |
tw.setColumnCount(1); |
|
3026 |
QTreeWidgetItem *item = new QTreeWidgetItem(&tw); |
|
3027 |
item->setText(0, "item 1"); |
|
3028 |
||
3029 |
QVERIFY(tw.invisibleRootItem()->flags() & Qt::ItemIsDropEnabled); |
|
3030 |
||
3031 |
tw.invisibleRootItem()->setFlags(tw.invisibleRootItem()->flags() & ~Qt::ItemIsDropEnabled); |
|
3032 |
||
3033 |
QVERIFY(!(tw.invisibleRootItem()->flags() & Qt::ItemIsDropEnabled)); |
|
3034 |
} |
|
3035 |
||
3036 |
void tst_QTreeWidget::task218661_setHeaderData() |
|
3037 |
{ |
|
3038 |
//We check that setting header data out of bounds returns false |
|
3039 |
//and doesn't increase the size of the model |
|
3040 |
QTreeWidget tw; |
|
3041 |
tw.setColumnCount(1); |
|
3042 |
QCOMPARE(tw.columnCount(), 1); |
|
3043 |
||
3044 |
QCOMPARE(tw.model()->setHeaderData(99999, Qt::Horizontal, QVariant()), false); |
|
3045 |
||
3046 |
QCOMPARE(tw.columnCount(), 1); |
|
3047 |
} |
|
3048 |
||
3049 |
void tst_QTreeWidget::task245280_sortChildren() |
|
3050 |
{ |
|
3051 |
QTreeWidget tw; |
|
3052 |
tw.setColumnCount(2); |
|
3053 |
||
3054 |
QTreeWidgetItem top(&tw); |
|
3055 |
top.setText(0,"Col 0"); |
|
3056 |
top.setText(1,"Col 1"); |
|
3057 |
QTreeWidgetItem item1(&top); |
|
3058 |
item1.setText(0,"X"); |
|
3059 |
item1.setText(1,"0"); |
|
3060 |
QTreeWidgetItem item2(&top); |
|
3061 |
item2.setText(0,"A"); |
|
3062 |
item2.setText(1,"4"); |
|
3063 |
QTreeWidgetItem item3(&top); |
|
3064 |
item3.setText(0,"E"); |
|
3065 |
item3.setText(1,"1"); |
|
3066 |
QTreeWidgetItem item4(&top); |
|
3067 |
item4.setText(0,"Z"); |
|
3068 |
item4.setText(1,"3"); |
|
3069 |
QTreeWidgetItem item5(&top); |
|
3070 |
item5.setText(0,"U"); |
|
3071 |
item5.setText(1,"2"); |
|
3072 |
tw.expandAll(); |
|
3073 |
tw.show(); |
|
3074 |
top.sortChildren(1,Qt::AscendingOrder); |
|
3075 |
||
3076 |
for (int i = 0; i < top.childCount(); ++i) |
|
3077 |
QCOMPARE(top.child(i)->text(1), QString::number(i)); |
|
3078 |
} |
|
3079 |
||
3080 |
void tst_QTreeWidget::task253109_itemHeight() |
|
3081 |
{ |
|
3082 |
QTreeWidget treeWidget; |
|
3083 |
treeWidget.setColumnCount(1); |
|
3084 |
treeWidget.show(); |
|
3085 |
QTest::qWait(200); |
|
3086 |
||
3087 |
QTreeWidgetItem item(&treeWidget); |
|
3088 |
class MyWidget : public QWidget |
|
3089 |
{ |
|
3090 |
virtual QSize sizeHint() const { return QSize(200,100); } |
|
3091 |
} w; |
|
3092 |
treeWidget.setItemWidget(&item, 0, &w); |
|
3093 |
||
3094 |
QTest::qWait(200); |
|
3095 |
QCOMPARE(w.geometry(), treeWidget.visualItemRect(&item)); |
|
3096 |
||
3097 |
} |
|
3098 |
||
3099 |
void tst_QTreeWidget::task206367_duplication() |
|
3100 |
{ |
|
3101 |
QTreeWidget treeWidget; |
|
3102 |
treeWidget.show(); |
|
3103 |
treeWidget.resize(200, 200); |
|
3104 |
||
3105 |
treeWidget.setSortingEnabled(true); |
|
3106 |
QTreeWidgetItem* rootItem = new QTreeWidgetItem( &treeWidget, QStringList("root") ); |
|
3107 |
for (int nFile = 0; nFile < 2; nFile++ ) { |
|
3108 |
QTreeWidgetItem* itemFile = new QTreeWidgetItem(rootItem, QStringList(QString::number(nFile))); |
|
3109 |
for (int nRecord = 0; nRecord < 2; nRecord++) |
|
3110 |
new QTreeWidgetItem(itemFile , QStringList(QString::number(nRecord))); |
|
3111 |
itemFile->setExpanded(true); |
|
3112 |
} |
|
3113 |
rootItem->setExpanded(true); |
|
3114 |
QTest::qWait(2000); |
|
3115 |
||
3116 |
//there should be enough room for 2x2 items. If there is a scrollbar, it means the items are duplicated |
|
3117 |
QVERIFY(!treeWidget.verticalScrollBar()->isVisible()); |
|
3118 |
||
3119 |
} |
|
3120 |
||
3121 |
void tst_QTreeWidget::itemSelectionChanged() |
|
3122 |
{ |
|
3123 |
QVERIFY(testWidget); |
|
3124 |
if(testWidget->topLevelItem(0)) |
|
3125 |
QVERIFY(testWidget->topLevelItem(0)->isSelected()); |
|
3126 |
} |
|
3127 |
||
3128 |
void tst_QTreeWidget::selectionOrder() |
|
3129 |
{ |
|
3130 |
testWidget->setColumnCount(1); |
|
3131 |
QList<QTreeWidgetItem *> items; |
|
3132 |
for (int i = 0; i < 10; ++i) |
|
3133 |
items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)))); |
|
3134 |
testWidget->insertTopLevelItems(0, items); |
|
3135 |
||
3136 |
QModelIndex idx = testWidget->indexFromItem(items[0]); |
|
3137 |
connect(testWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged())); |
|
3138 |
testWidget->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent); |
|
3139 |
disconnect(testWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged())); |
|
3140 |
} |
|
3141 |
||
3142 |
void tst_QTreeWidget::setSelectionModel() |
|
3143 |
{ |
|
3144 |
QTreeWidget tree; |
|
3145 |
for(int i = 0; i < 3; ++i) |
|
3146 |
new QTreeWidgetItem(&tree, QStringList(QString::number(i))); |
|
3147 |
QItemSelectionModel selection(tree.model()); |
|
3148 |
selection.select(tree.model()->index(1,0), QItemSelectionModel::Select); |
|
3149 |
tree.setSelectionModel(&selection); |
|
3150 |
QCOMPARE(tree.topLevelItem(1)->isSelected(), true); |
|
3151 |
} |
|
3152 |
||
3153 |
void tst_QTreeWidget::task217309() |
|
3154 |
{ |
|
3155 |
QTreeWidgetItem item; |
|
3156 |
item.setFlags(item.flags() | Qt::ItemIsTristate); |
|
3157 |
QTreeWidgetItem subitem1; |
|
3158 |
subitem1.setFlags(subitem1.flags() | Qt::ItemIsTristate); |
|
3159 |
QTreeWidgetItem subitem2; |
|
3160 |
subitem2.setFlags(subitem2.flags() | Qt::ItemIsTristate); |
|
3161 |
item.addChild(&subitem1); |
|
3162 |
item.addChild(&subitem2); |
|
3163 |
subitem1.setCheckState(0, Qt::Checked); |
|
3164 |
subitem2.setCheckState(0, Qt::Unchecked); |
|
3165 |
||
3166 |
QVERIFY(item.data(0, Qt::CheckStateRole) == Qt::PartiallyChecked); |
|
3167 |
||
3168 |
subitem2.setCheckState(0, Qt::PartiallyChecked); |
|
3169 |
QVERIFY(item.data(0, Qt::CheckStateRole) == Qt::PartiallyChecked); |
|
3170 |
||
3171 |
subitem2.setCheckState(0, Qt::Checked); |
|
3172 |
QVERIFY(item.data(0, Qt::CheckStateRole) == Qt::Checked); |
|
3173 |
} |
|
3174 |
||
3175 |
class TreeWidgetItem : public QTreeWidgetItem |
|
3176 |
{ |
|
3177 |
||
3178 |
public: |
|
3179 |
void _emitDataChanged() { emitDataChanged(); } |
|
3180 |
||
3181 |
}; |
|
3182 |
||
3183 |
void tst_QTreeWidget::emitDataChanged() |
|
3184 |
{ |
|
3185 |
||
3186 |
QTreeWidget *tree = new QTreeWidget; |
|
3187 |
QSignalSpy spy(tree, SIGNAL(itemChanged(QTreeWidgetItem *, int))); |
|
3188 |
TreeWidgetItem *item = new TreeWidgetItem(); |
|
3189 |
tree->insertTopLevelItem(0, item); |
|
3190 |
item->_emitDataChanged(); |
|
3191 |
QCOMPARE(spy.count(), 1); |
|
3192 |
||
3193 |
} |
|
3194 |
||
3195 |
void tst_QTreeWidget::setCurrentItemExpandsParent() |
|
3196 |
{ |
|
3197 |
QTreeWidget w; |
|
3198 |
w.setColumnCount(1); |
|
3199 |
QTreeWidgetItem *i1 = new QTreeWidgetItem(&w, QStringList() << "parent"); |
|
3200 |
QTreeWidgetItem *i2 = new QTreeWidgetItem(i1, QStringList() << "child"); |
|
3201 |
QVERIFY(!i2->isExpanded()); |
|
3202 |
QVERIFY(w.currentItem() == 0); |
|
3203 |
w.setCurrentItem(i2); |
|
3204 |
QVERIFY(!i2->isExpanded()); |
|
3205 |
QCOMPARE(w.currentItem(), i2); |
|
3206 |
} |
|
3207 |
||
3208 |
void tst_QTreeWidget::task239150_editorWidth() |
|
3209 |
{ |
|
3210 |
//we check that an item with no text will get an editor with a correct size |
|
3211 |
QTreeWidget tree; |
|
3212 |
||
3213 |
QStyleOptionFrameV2 opt; |
|
3214 |
opt.init(&tree); |
|
3215 |
const int minWidth = tree.style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(0, 0). |
|
3216 |
expandedTo(QApplication::globalStrut()), 0).width(); |
|
3217 |
||
3218 |
{ |
|
3219 |
QTreeWidgetItem item; |
|
3220 |
item.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ); |
|
3221 |
tree.addTopLevelItem(&item); |
|
3222 |
QVERIFY(tree.itemWidget(&item, 0) == 0); |
|
3223 |
tree.editItem(&item); |
|
3224 |
QVERIFY(tree.itemWidget(&item, 0)); |
|
3225 |
QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth); |
|
3226 |
} |
|
3227 |
||
3228 |
//now let's test it with an item with a lot of text |
|
3229 |
{ |
|
3230 |
QTreeWidgetItem item; |
|
3231 |
item.setText(0, "foooooooooooooooooooooooo"); |
|
3232 |
item.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ); |
|
3233 |
tree.addTopLevelItem(&item); |
|
3234 |
QVERIFY(tree.itemWidget(&item, 0) == 0); |
|
3235 |
tree.editItem(&item); |
|
3236 |
QVERIFY(tree.itemWidget(&item, 0)); |
|
3237 |
QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth + tree.fontMetrics().width(item.text(0))); |
|
3238 |
} |
|
3239 |
} |
|
3240 |
||
3241 |
||
3242 |
||
3243 |
void tst_QTreeWidget::setTextUpdate() |
|
3244 |
{ |
|
3245 |
QTreeWidget treeWidget; |
|
3246 |
treeWidget.setColumnCount(2); |
|
3247 |
||
3248 |
class MyItemDelegate : public QStyledItemDelegate |
|
3249 |
{ |
|
3250 |
public: |
|
3251 |
MyItemDelegate() : numPaints(0) { } |
|
3252 |
void paint(QPainter *painter, |
|
3253 |
const QStyleOptionViewItem &option, const QModelIndex &index) const |
|
3254 |
{ |
|
3255 |
numPaints++; |
|
3256 |
QStyledItemDelegate::paint(painter, option, index); |
|
3257 |
} |
|
3258 |
||
3259 |
mutable int numPaints; |
|
3260 |
} delegate; |
|
3261 |
||
3262 |
treeWidget.setItemDelegate(&delegate); |
|
3263 |
treeWidget.show(); |
|
3264 |
QStringList strList; |
|
3265 |
strList << "variable1" << "0"; |
|
3266 |
QTreeWidgetItem *item = new QTreeWidgetItem(strList); |
|
3267 |
treeWidget.insertTopLevelItem(0, item); |
|
3268 |
QTest::qWait(50); |
|
3269 |
QTRY_VERIFY(delegate.numPaints > 0); |
|
3270 |
delegate.numPaints = 0; |
|
3271 |
||
3272 |
item->setText(1, "42"); |
|
3273 |
QApplication::processEvents(); |
|
3274 |
QTRY_VERIFY(delegate.numPaints > 0); |
|
3275 |
} |
|
3276 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3277 |
void tst_QTreeWidget::taskQTBUG2844_visualItemRect() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3278 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3279 |
CustomTreeWidget tree; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3280 |
tree.resize(150, 100); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3281 |
tree.setColumnCount(3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3282 |
QTreeWidgetItem item(&tree); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3283 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3284 |
QRect itemRect = tree.visualItemRect(&item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3285 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3286 |
QRect rectCol0 = tree.visualRect(tree.indexFromItem(&item, 0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3287 |
QRect rectCol1 = tree.visualRect(tree.indexFromItem(&item, 1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3288 |
QRect rectCol2 = tree.visualRect(tree.indexFromItem(&item, 2)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3289 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3290 |
QCOMPARE(tree.visualItemRect(&item), rectCol0 | rectCol2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3291 |
tree.setColumnHidden(2, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3292 |
QCOMPARE(tree.visualItemRect(&item), rectCol0 | rectCol1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3293 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3294 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3295 |
void tst_QTreeWidget::setChildIndicatorPolicy() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3296 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3297 |
QTreeWidget treeWidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3298 |
treeWidget.setColumnCount(1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3299 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3300 |
class MyItemDelegate : public QStyledItemDelegate |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3301 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3302 |
public: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3303 |
MyItemDelegate() : numPaints(0), expectChildren(false) { } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3304 |
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3305 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3306 |
numPaints++; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3307 |
QCOMPARE(!(option.state & QStyle::State_Children), !expectChildren); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3308 |
QStyledItemDelegate::paint(painter, option, index); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3309 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3310 |
mutable int numPaints; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3311 |
bool expectChildren; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3312 |
} delegate; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3313 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3314 |
treeWidget.setItemDelegate(&delegate); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3315 |
treeWidget.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3316 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3317 |
QTreeWidgetItem *item = new QTreeWidgetItem(QStringList("Hello")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3318 |
treeWidget.insertTopLevelItem(0, item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3319 |
QTest::qWait(50); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3320 |
QTRY_VERIFY(delegate.numPaints > 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3321 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3322 |
delegate.numPaints = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3323 |
delegate.expectChildren = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3324 |
item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3325 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3326 |
QTRY_COMPARE(delegate.numPaints, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3327 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3328 |
delegate.numPaints = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3329 |
delegate.expectChildren = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3330 |
item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3331 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3332 |
QTRY_COMPARE(delegate.numPaints, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3333 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3334 |
delegate.numPaints = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3335 |
delegate.expectChildren = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3336 |
new QTreeWidgetItem(item); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3337 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3338 |
QTRY_COMPARE(delegate.numPaints, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3339 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3340 |
delegate.numPaints = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3341 |
delegate.expectChildren = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3342 |
item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3343 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3344 |
QTRY_COMPARE(delegate.numPaints, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3345 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3346 |
|
0 | 3347 |
|
3348 |
||
3349 |
QTEST_MAIN(tst_QTreeWidget) |
|
3350 |
#include "tst_qtreewidget.moc" |