author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
child 7 | 3f74d0d4af4c |
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 |
||
44 |
#include <qabstractitemview.h> |
|
45 |
||
46 |
#include <QtTest/QtTest> |
|
47 |
#include <QtGui/QtGui> |
|
48 |
#include "../../shared/util.h" |
|
49 |
||
50 |
//TESTED_CLASS= |
|
51 |
//TESTED_FILES= |
|
52 |
||
53 |
Q_DECLARE_METATYPE(QModelIndex) |
|
54 |
#ifndef QT_NO_DRAGANDDROP |
|
55 |
Q_DECLARE_METATYPE(QAbstractItemView::DragDropMode) |
|
56 |
#endif |
|
57 |
Q_DECLARE_METATYPE(QAbstractItemView::EditTriggers) |
|
58 |
Q_DECLARE_METATYPE(QAbstractItemView::EditTrigger) |
|
59 |
||
60 |
static void initStandardTreeModel(QStandardItemModel *model) |
|
61 |
{ |
|
62 |
QStandardItem *item; |
|
63 |
item = new QStandardItem(QLatin1String("Row 1 Item")); |
|
64 |
model->insertRow(0, item); |
|
65 |
||
66 |
item = new QStandardItem(QLatin1String("Row 2 Item")); |
|
67 |
item->setCheckable(true); |
|
68 |
model->insertRow(1, item); |
|
69 |
||
70 |
QStandardItem *childItem = new QStandardItem(QLatin1String("Row 2 Child Item")); |
|
71 |
item->setChild(0, childItem); |
|
72 |
||
73 |
item = new QStandardItem(QLatin1String("Row 3 Item")); |
|
74 |
item->setIcon(QIcon()); |
|
75 |
model->insertRow(2, item); |
|
76 |
} |
|
77 |
||
78 |
struct PublicView : public QTreeView |
|
79 |
{ |
|
80 |
inline void executeDelayedItemsLayout() |
|
81 |
{ QTreeView::executeDelayedItemsLayout(); } |
|
82 |
||
83 |
enum PublicCursorAction { |
|
84 |
MoveUp = QAbstractItemView::MoveUp, |
|
85 |
MoveDown = QAbstractItemView::MoveDown, |
|
86 |
MoveLeft = QAbstractItemView::MoveLeft, |
|
87 |
MoveRight = QAbstractItemView::MoveRight, |
|
88 |
MoveHome = QAbstractItemView::MoveHome, |
|
89 |
MoveEnd = QAbstractItemView::MoveEnd, |
|
90 |
MovePageUp = QAbstractItemView::MovePageUp, |
|
91 |
MovePageDown = QAbstractItemView::MovePageDown, |
|
92 |
MoveNext = QAbstractItemView::MoveNext, |
|
93 |
MovePrevious = QAbstractItemView::MovePrevious |
|
94 |
}; |
|
95 |
||
96 |
inline QModelIndex moveCursor(PublicCursorAction ca, Qt::KeyboardModifiers kbm) |
|
97 |
{ return QTreeView::moveCursor((CursorAction)ca, kbm); } |
|
98 |
||
99 |
inline void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) |
|
100 |
{ |
|
101 |
QTreeView::setSelection(rect, command); |
|
102 |
} |
|
103 |
inline int state() |
|
104 |
{ |
|
105 |
return QTreeView::state(); |
|
106 |
} |
|
107 |
||
108 |
inline int rowHeight(QModelIndex idx) { return QTreeView::rowHeight(idx); } |
|
109 |
inline int indexRowSizeHint(const QModelIndex &index) const { return QTreeView::indexRowSizeHint(index); } |
|
110 |
||
111 |
inline QModelIndexList selectedIndexes() const { return QTreeView::selectedIndexes(); } |
|
112 |
||
113 |
inline QStyleOptionViewItem viewOptions() const { return QTreeView::viewOptions(); } |
|
114 |
inline int sizeHintForColumn(int column) const { return QTreeView::sizeHintForColumn(column); } |
|
115 |
}; |
|
116 |
||
117 |
class tst_QTreeView : public QObject |
|
118 |
{ |
|
119 |
Q_OBJECT |
|
120 |
||
121 |
public: |
|
122 |
tst_QTreeView(); |
|
123 |
virtual ~tst_QTreeView(); |
|
124 |
||
125 |
||
126 |
public slots: |
|
127 |
void initTestCase(); |
|
128 |
void cleanupTestCase(); |
|
129 |
void init(); |
|
130 |
void cleanup(); |
|
131 |
||
132 |
void selectionOrderTest(); |
|
133 |
||
134 |
private slots: |
|
135 |
void getSetCheck(); |
|
136 |
||
137 |
// one test per QTreeView property |
|
138 |
void construction(); |
|
139 |
void alternatingRowColors(); |
|
140 |
void currentIndex_data(); |
|
141 |
void currentIndex(); |
|
142 |
#ifndef QT_NO_DRAGANDDROP |
|
143 |
void dragDropMode_data(); |
|
144 |
void dragDropMode(); |
|
145 |
void dragDropModeFromDragEnabledAndAcceptDrops_data(); |
|
146 |
void dragDropModeFromDragEnabledAndAcceptDrops(); |
|
147 |
void dragDropOverwriteMode(); |
|
148 |
#endif |
|
149 |
void editTriggers_data(); |
|
150 |
void editTriggers(); |
|
151 |
void hasAutoScroll(); |
|
152 |
void horizontalScrollMode(); |
|
153 |
void iconSize(); |
|
154 |
void indexAt(); |
|
155 |
void indexWidget(); |
|
156 |
void itemDelegate(); |
|
157 |
void itemDelegateForColumnOrRow(); |
|
158 |
void keyboardSearch(); |
|
159 |
void setModel(); |
|
160 |
void openPersistentEditor(); |
|
161 |
void rootIndex(); |
|
162 |
||
163 |
// specialized tests below |
|
164 |
void setHeader(); |
|
165 |
void columnHidden(); |
|
166 |
void rowHidden(); |
|
167 |
void noDelegate(); |
|
168 |
void noModel(); |
|
169 |
void emptyModel(); |
|
170 |
void removeRows(); |
|
171 |
void removeCols(); |
|
172 |
void expandAndCollapse_data(); |
|
173 |
void expandAndCollapse(); |
|
174 |
void expandAndCollapseAll(); |
|
175 |
void expandWithNoChildren(); |
|
176 |
void keyboardNavigation(); |
|
177 |
void headerSections(); |
|
178 |
void moveCursor_data(); |
|
179 |
void moveCursor(); |
|
180 |
void setSelection_data(); |
|
181 |
void setSelection(); |
|
182 |
void extendedSelection_data(); |
|
183 |
void extendedSelection(); |
|
184 |
void indexAbove(); |
|
185 |
void indexBelow(); |
|
186 |
void clicked(); |
|
187 |
void mouseDoubleClick(); |
|
188 |
void rowsAboutToBeRemoved(); |
|
189 |
void headerSections_unhideSection(); |
|
190 |
void columnAt(); |
|
191 |
void scrollTo(); |
|
192 |
void rowsAboutToBeRemoved_move(); |
|
193 |
void resizeColumnToContents(); |
|
194 |
void insertAfterSelect(); |
|
195 |
void removeAfterSelect(); |
|
196 |
void hiddenItems(); |
|
197 |
void spanningItems(); |
|
198 |
void rowSizeHint(); |
|
199 |
void setSortingEnabled(); |
|
200 |
void headerHidden(); |
|
201 |
||
202 |
void selection(); |
|
203 |
void removeAndInsertExpandedCol0(); |
|
204 |
void selectionWithHiddenItems(); |
|
205 |
void selectAll(); |
|
206 |
||
207 |
void disabledButCheckable(); |
|
208 |
void sortByColumn_data(); |
|
209 |
void sortByColumn(); |
|
210 |
||
211 |
void evilModel_data(); |
|
212 |
void evilModel(); |
|
213 |
||
214 |
void indexRowSizeHint(); |
|
215 |
void addRowsWhileSectionsAreHidden(); |
|
216 |
void filterProxyModelCrash(); |
|
217 |
void styleOptionViewItem(); |
|
218 |
||
219 |
// task-specific tests: |
|
220 |
void task174627_moveLeftToRoot(); |
|
221 |
void task171902_expandWith1stColHidden(); |
|
222 |
void task203696_hidingColumnsAndRowsn(); |
|
223 |
void task211293_removeRootIndex(); |
|
224 |
void task216717_updateChildren(); |
|
225 |
void task220298_selectColumns(); |
|
226 |
void task224091_appendColumns(); |
|
227 |
void task225539_deleteModel(); |
|
228 |
void task230123_setItemsExpandable(); |
|
229 |
void task202039_closePersistentEditor(); |
|
230 |
void task238873_avoidAutoReopening(); |
|
231 |
void task244304_clickOnDecoration(); |
|
232 |
void task246536_scrollbarsNotWorking(); |
|
233 |
void task250683_wrongSectionSize(); |
|
234 |
void task239271_addRowsWithFirstColumnHidden(); |
|
235 |
void task254234_proxySort(); |
|
236 |
void task248022_changeSelection(); |
|
237 |
void task245654_changeModelAndExpandAll(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
238 |
void doubleClickedWithSpans(); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
239 |
void taskQTBUG_6450_selectAllWith1stColumnHidden(); |
0 | 240 |
}; |
241 |
||
242 |
class QtTestModel: public QAbstractItemModel |
|
243 |
{ |
|
244 |
public: |
|
245 |
QtTestModel(QObject *parent = 0): QAbstractItemModel(parent), |
|
246 |
fetched(false), rows(0), cols(0), levels(INT_MAX), wrongIndex(false) { init(); } |
|
247 |
||
248 |
QtTestModel(int _rows, int _cols, QObject *parent = 0): QAbstractItemModel(parent), |
|
249 |
rows(_rows), cols(_cols), levels(INT_MAX), wrongIndex(false) { init(); } |
|
250 |
||
251 |
void init() { |
|
252 |
decorationsEnabled = false; |
|
253 |
} |
|
254 |
||
255 |
inline qint32 level(const QModelIndex &index) const { |
|
256 |
return index.isValid() ? qint32(index.internalId()) : qint32(-1); |
|
257 |
} |
|
258 |
||
259 |
bool canFetchMore(const QModelIndex &) const { |
|
260 |
return !fetched; |
|
261 |
} |
|
262 |
||
263 |
void fetchMore(const QModelIndex &) { |
|
264 |
fetched = true; |
|
265 |
} |
|
266 |
||
267 |
bool hasChildren(const QModelIndex &parent = QModelIndex()) const { |
|
268 |
bool hasFetched = fetched; |
|
269 |
fetched = true; |
|
270 |
bool r = QAbstractItemModel::hasChildren(parent); |
|
271 |
fetched = hasFetched; |
|
272 |
return r; |
|
273 |
} |
|
274 |
||
275 |
int rowCount(const QModelIndex& parent = QModelIndex()) const { |
|
276 |
Q_ASSERT(fetched); |
|
277 |
if ((parent.column() > 0) || (level(parent) > levels)) |
|
278 |
return 0; |
|
279 |
return rows; |
|
280 |
} |
|
281 |
int columnCount(const QModelIndex& parent = QModelIndex()) const { |
|
282 |
if ((parent.column() > 0) || (level(parent) > levels)) |
|
283 |
return 0; |
|
284 |
return cols; |
|
285 |
} |
|
286 |
||
287 |
bool isEditable(const QModelIndex &index) const { |
|
288 |
if (index.isValid()) |
|
289 |
return true; |
|
290 |
return false; |
|
291 |
} |
|
292 |
||
293 |
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const |
|
294 |
{ |
|
295 |
if (row < 0 || column < 0 || (level(parent) > levels) || column >= cols || row >= rows) { |
|
296 |
return QModelIndex(); |
|
297 |
} |
|
298 |
QModelIndex i = createIndex(row, column, level(parent) + 1); |
|
299 |
parentHash[i] = parent; |
|
300 |
return i; |
|
301 |
} |
|
302 |
||
303 |
QModelIndex parent(const QModelIndex &index) const |
|
304 |
{ |
|
305 |
if (!parentHash.contains(index)) |
|
306 |
return QModelIndex(); |
|
307 |
return parentHash[index]; |
|
308 |
} |
|
309 |
||
310 |
QVariant data(const QModelIndex &idx, int role) const |
|
311 |
{ |
|
312 |
if (!idx.isValid()) |
|
313 |
return QVariant(); |
|
314 |
||
315 |
if (role == Qt::DisplayRole) { |
|
316 |
if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) { |
|
317 |
wrongIndex = true; |
|
318 |
qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), |
|
319 |
idx.internalPointer()); |
|
320 |
} |
|
321 |
if (idx.row() & 1) |
|
322 |
return QString("[%1,%2,%3] - this item is extra wide").arg(idx.row()).arg(idx.column()).arg(level(idx)); |
|
323 |
return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(level(idx)); |
|
324 |
} |
|
325 |
if (decorationsEnabled && role == Qt::DecorationRole) { |
|
326 |
QPixmap pm(16,16); |
|
327 |
pm.fill(QColor::fromHsv((idx.column() % 16)*8 + 64, 254, (idx.row() % 16)*8 + 32)); |
|
328 |
return pm; |
|
329 |
} |
|
330 |
return QVariant(); |
|
331 |
} |
|
332 |
||
333 |
void removeLastRow() |
|
334 |
{ |
|
335 |
beginRemoveRows(QModelIndex(), rows - 1, rows - 1); |
|
336 |
--rows; |
|
337 |
endRemoveRows(); |
|
338 |
} |
|
339 |
||
340 |
void removeAllRows() |
|
341 |
{ |
|
342 |
beginRemoveRows(QModelIndex(), 0, rows - 1); |
|
343 |
rows = 0; |
|
344 |
endRemoveRows(); |
|
345 |
} |
|
346 |
||
347 |
void removeLastColumn() |
|
348 |
{ |
|
349 |
beginRemoveColumns(QModelIndex(), cols - 1, cols - 1); |
|
350 |
--cols; |
|
351 |
endRemoveColumns(); |
|
352 |
} |
|
353 |
||
354 |
void removeAllColumns() |
|
355 |
{ |
|
356 |
beginRemoveColumns(QModelIndex(), 0, cols - 1); |
|
357 |
cols = 0; |
|
358 |
endRemoveColumns(); |
|
359 |
} |
|
360 |
||
361 |
void insertNewRow() |
|
362 |
{ |
|
363 |
beginInsertRows(QModelIndex(), rows - 1, rows - 1); |
|
364 |
++rows; |
|
365 |
endInsertRows(); |
|
366 |
} |
|
367 |
||
368 |
void setDecorationsEnabled(bool enable) |
|
369 |
{ |
|
370 |
decorationsEnabled = enable; |
|
371 |
} |
|
372 |
||
373 |
mutable bool fetched; |
|
374 |
bool decorationsEnabled; |
|
375 |
int rows, cols; |
|
376 |
int levels; |
|
377 |
mutable bool wrongIndex; |
|
378 |
mutable QMap<QModelIndex,QModelIndex> parentHash; |
|
379 |
}; |
|
380 |
||
381 |
tst_QTreeView::tst_QTreeView() |
|
382 |
{ |
|
383 |
} |
|
384 |
||
385 |
tst_QTreeView::~tst_QTreeView() |
|
386 |
{ |
|
387 |
} |
|
388 |
||
389 |
void tst_QTreeView::initTestCase() |
|
390 |
{ |
|
391 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
392 |
qApp->setAutoMaximizeThreshold(-1); |
|
393 |
#endif |
|
394 |
qRegisterMetaType<QModelIndex>("QModelIndex"); |
|
395 |
} |
|
396 |
||
397 |
void tst_QTreeView::cleanupTestCase() |
|
398 |
{ |
|
399 |
} |
|
400 |
||
401 |
void tst_QTreeView::init() |
|
402 |
{ |
|
403 |
} |
|
404 |
||
405 |
void tst_QTreeView::cleanup() |
|
406 |
{ |
|
407 |
} |
|
408 |
||
409 |
// Testing get/set functions |
|
410 |
void tst_QTreeView::getSetCheck() |
|
411 |
{ |
|
412 |
QTreeView obj1; |
|
413 |
||
414 |
// int QTreeView::indentation() |
|
415 |
// void QTreeView::setIndentation(int) |
|
416 |
QCOMPARE(obj1.indentation(), 20); |
|
417 |
obj1.setIndentation(0); |
|
418 |
QCOMPARE(obj1.indentation(), 0); |
|
419 |
obj1.setIndentation(INT_MIN); |
|
420 |
QCOMPARE(obj1.indentation(), INT_MIN); |
|
421 |
obj1.setIndentation(INT_MAX); |
|
422 |
QCOMPARE(obj1.indentation(), INT_MAX); |
|
423 |
||
424 |
// bool QTreeView::rootIsDecorated() |
|
425 |
// void QTreeView::setRootIsDecorated(bool) |
|
426 |
QCOMPARE(obj1.rootIsDecorated(), true); |
|
427 |
obj1.setRootIsDecorated(false); |
|
428 |
QCOMPARE(obj1.rootIsDecorated(), false); |
|
429 |
obj1.setRootIsDecorated(true); |
|
430 |
QCOMPARE(obj1.rootIsDecorated(), true); |
|
431 |
||
432 |
// bool QTreeView::uniformRowHeights() |
|
433 |
// void QTreeView::setUniformRowHeights(bool) |
|
434 |
QCOMPARE(obj1.uniformRowHeights(), false); |
|
435 |
obj1.setUniformRowHeights(false); |
|
436 |
QCOMPARE(obj1.uniformRowHeights(), false); |
|
437 |
obj1.setUniformRowHeights(true); |
|
438 |
QCOMPARE(obj1.uniformRowHeights(), true); |
|
439 |
||
440 |
// bool QTreeView::itemsExpandable() |
|
441 |
// void QTreeView::setItemsExpandable(bool) |
|
442 |
QCOMPARE(obj1.itemsExpandable(), true); |
|
443 |
obj1.setItemsExpandable(false); |
|
444 |
QCOMPARE(obj1.itemsExpandable(), false); |
|
445 |
obj1.setItemsExpandable(true); |
|
446 |
QCOMPARE(obj1.itemsExpandable(), true); |
|
447 |
||
448 |
// bool QTreeView::allColumnsShowFocus |
|
449 |
// void QTreeView::setAllColumnsShowFocus |
|
450 |
QCOMPARE(obj1.allColumnsShowFocus(), false); |
|
451 |
obj1.setAllColumnsShowFocus(false); |
|
452 |
QCOMPARE(obj1.allColumnsShowFocus(), false); |
|
453 |
obj1.setAllColumnsShowFocus(true); |
|
454 |
QCOMPARE(obj1.allColumnsShowFocus(), true); |
|
455 |
||
456 |
// bool QTreeView::isAnimated |
|
457 |
// void QTreeView::setAnimated |
|
458 |
QCOMPARE(obj1.isAnimated(), false); |
|
459 |
obj1.setAnimated(false); |
|
460 |
QCOMPARE(obj1.isAnimated(), false); |
|
461 |
obj1.setAnimated(true); |
|
462 |
QCOMPARE(obj1.isAnimated(), true); |
|
463 |
||
464 |
// bool QTreeView::setSortingEnabled |
|
465 |
// void QTreeView::isSortingEnabled |
|
466 |
QCOMPARE(obj1.isSortingEnabled(), false); |
|
467 |
obj1.setSortingEnabled(false); |
|
468 |
QCOMPARE(obj1.isSortingEnabled(), false); |
|
469 |
obj1.setSortingEnabled(true); |
|
470 |
QCOMPARE(obj1.isSortingEnabled(), true); |
|
471 |
} |
|
472 |
||
473 |
void tst_QTreeView::construction() |
|
474 |
{ |
|
475 |
QTreeView view; |
|
476 |
||
477 |
// QAbstractItemView properties |
|
478 |
QVERIFY(!view.alternatingRowColors()); |
|
479 |
QCOMPARE(view.currentIndex(), QModelIndex()); |
|
480 |
#ifndef QT_NO_DRAGANDDROP |
|
481 |
QCOMPARE(view.dragDropMode(), QAbstractItemView::NoDragDrop); |
|
482 |
QVERIFY(!view.dragDropOverwriteMode()); |
|
483 |
QVERIFY(!view.dragEnabled()); |
|
484 |
#endif |
|
485 |
QCOMPARE(view.editTriggers(), QAbstractItemView::EditKeyPressed | QAbstractItemView::DoubleClicked); |
|
486 |
QVERIFY(view.hasAutoScroll()); |
|
487 |
QCOMPARE(view.horizontalScrollMode(), QAbstractItemView::ScrollPerPixel); |
|
488 |
QCOMPARE(view.iconSize(), QSize()); |
|
489 |
QCOMPARE(view.indexAt(QPoint()), QModelIndex()); |
|
490 |
QVERIFY(!view.indexWidget(QModelIndex())); |
|
491 |
QVERIFY(qobject_cast<QStyledItemDelegate *>(view.itemDelegate())); |
|
492 |
QVERIFY(!view.itemDelegateForColumn(-1)); |
|
493 |
QVERIFY(!view.itemDelegateForColumn(0)); |
|
494 |
QVERIFY(!view.itemDelegateForColumn(1)); |
|
495 |
QVERIFY(!view.itemDelegateForRow(-1)); |
|
496 |
QVERIFY(!view.itemDelegateForRow(0)); |
|
497 |
QVERIFY(!view.itemDelegateForRow(1)); |
|
498 |
QVERIFY(!view.model()); |
|
499 |
QCOMPARE(view.rootIndex(), QModelIndex()); |
|
500 |
QCOMPARE(view.selectionBehavior(), QAbstractItemView::SelectRows); |
|
501 |
QCOMPARE(view.selectionMode(), QAbstractItemView::SingleSelection); |
|
502 |
QVERIFY(!view.selectionModel()); |
|
503 |
#ifndef QT_NO_DRAGANDDROP |
|
504 |
QVERIFY(view.showDropIndicator()); |
|
505 |
#endif |
|
506 |
QCOMPARE(view.QAbstractItemView::sizeHintForColumn(-1), -1); // <- protected in QTreeView |
|
507 |
QCOMPARE(view.QAbstractItemView::sizeHintForColumn(0), -1); // <- protected in QTreeView |
|
508 |
QCOMPARE(view.QAbstractItemView::sizeHintForColumn(1), -1); // <- protected in QTreeView |
|
509 |
QCOMPARE(view.sizeHintForIndex(QModelIndex()), QSize()); |
|
510 |
QCOMPARE(view.sizeHintForRow(-1), -1); |
|
511 |
QCOMPARE(view.sizeHintForRow(0), -1); |
|
512 |
QCOMPARE(view.sizeHintForRow(1), -1); |
|
513 |
QVERIFY(!view.tabKeyNavigation()); |
|
514 |
QCOMPARE(view.textElideMode(), Qt::ElideRight); |
|
515 |
QCOMPARE(view.verticalScrollMode(), QAbstractItemView::ScrollPerItem); |
|
516 |
QCOMPARE(view.visualRect(QModelIndex()), QRect()); |
|
517 |
||
518 |
// QTreeView properties |
|
519 |
QVERIFY(!view.allColumnsShowFocus()); |
|
520 |
QCOMPARE(view.autoExpandDelay(), -1); |
|
521 |
QCOMPARE(view.columnAt(-1), -1); |
|
522 |
QCOMPARE(view.columnAt(0), -1); |
|
523 |
QCOMPARE(view.columnAt(1), -1); |
|
524 |
QCOMPARE(view.columnViewportPosition(-1), -1); |
|
525 |
QCOMPARE(view.columnViewportPosition(0), -1); |
|
526 |
QCOMPARE(view.columnViewportPosition(1), -1); |
|
527 |
QCOMPARE(view.columnWidth(-1), 0); |
|
528 |
QCOMPARE(view.columnWidth(0), 0); |
|
529 |
QCOMPARE(view.columnWidth(1), 0); |
|
530 |
QVERIFY(view.header()); |
|
531 |
QCOMPARE(view.indentation(), 20); |
|
532 |
QCOMPARE(view.indexAbove(QModelIndex()), QModelIndex()); |
|
533 |
QCOMPARE(view.indexBelow(QModelIndex()), QModelIndex()); |
|
534 |
QVERIFY(!view.isAnimated()); |
|
535 |
QVERIFY(!view.isColumnHidden(-1)); |
|
536 |
QVERIFY(!view.isColumnHidden(0)); |
|
537 |
QVERIFY(!view.isColumnHidden(1)); |
|
538 |
QVERIFY(!view.isExpanded(QModelIndex())); |
|
539 |
QVERIFY(!view.isRowHidden(-1, QModelIndex())); |
|
540 |
QVERIFY(!view.isRowHidden(0, QModelIndex())); |
|
541 |
QVERIFY(!view.isRowHidden(1, QModelIndex())); |
|
542 |
QVERIFY(!view.isFirstColumnSpanned(-1, QModelIndex())); |
|
543 |
QVERIFY(!view.isFirstColumnSpanned(0, QModelIndex())); |
|
544 |
QVERIFY(!view.isFirstColumnSpanned(1, QModelIndex())); |
|
545 |
QVERIFY(!view.isSortingEnabled()); |
|
546 |
QVERIFY(view.itemsExpandable()); |
|
547 |
QVERIFY(view.rootIsDecorated()); |
|
548 |
QVERIFY(!view.uniformRowHeights()); |
|
549 |
QCOMPARE(view.visualRect(QModelIndex()), QRect()); |
|
550 |
QVERIFY(!view.wordWrap()); |
|
551 |
} |
|
552 |
||
553 |
void tst_QTreeView::alternatingRowColors() |
|
554 |
{ |
|
555 |
QTreeView view; |
|
556 |
QVERIFY(!view.alternatingRowColors()); |
|
557 |
view.setAlternatingRowColors(true); |
|
558 |
QVERIFY(view.alternatingRowColors()); |
|
559 |
view.setAlternatingRowColors(false); |
|
560 |
QVERIFY(!view.alternatingRowColors()); |
|
561 |
||
562 |
// ### Test visual effect. |
|
563 |
} |
|
564 |
||
565 |
void tst_QTreeView::currentIndex_data() |
|
566 |
{ |
|
567 |
QTest::addColumn<int>("row"); |
|
568 |
QTest::addColumn<int>("column"); |
|
569 |
QTest::addColumn<int>("indexRow"); |
|
570 |
QTest::addColumn<int>("indexColumn"); |
|
571 |
QTest::addColumn<int>("parentIndexRow"); |
|
572 |
QTest::addColumn<int>("parentIndexColumn"); |
|
573 |
||
574 |
QTest::newRow("-1, -1") << -1 << -1 << -1 << -1 << -1 << -1; |
|
575 |
QTest::newRow("-1, 0") << -1 << 0 << -1 << -1 << -1 << -1; |
|
576 |
QTest::newRow("0, -1") << 0 << -1 << -1 << -1 << -1 << -1; |
|
577 |
QTest::newRow("0, 0") << 0 << 0 << 0 << 0 << -1 << -1; |
|
578 |
QTest::newRow("0, 1") << 0 << 0 << 0 << 0 << -1 << -1; |
|
579 |
QTest::newRow("1, 0") << 1 << 0 << 1 << 0 << -1 << -1; |
|
580 |
QTest::newRow("1, 1") << 1 << 1 << -1 << -1 << -1 << -1; |
|
581 |
QTest::newRow("2, 0") << 2 << 0 << 2 << 0 << -1 << -1; |
|
582 |
QTest::newRow("2, 1") << 2 << 1 << -1 << -1 << -1 << -1; |
|
583 |
QTest::newRow("3, -1") << 3 << -1 << -1 << -1 << -1 << -1; |
|
584 |
QTest::newRow("3, 0") << 3 << 0 << -1 << -1 << -1 << -1; |
|
585 |
QTest::newRow("3, 1") << 3 << 1 << -1 << -1 << -1 << -1; |
|
586 |
} |
|
587 |
||
588 |
void tst_QTreeView::currentIndex() |
|
589 |
{ |
|
590 |
QFETCH(int, row); |
|
591 |
QFETCH(int, column); |
|
592 |
QFETCH(int, indexRow); |
|
593 |
QFETCH(int, indexColumn); |
|
594 |
QFETCH(int, parentIndexRow); |
|
595 |
QFETCH(int, parentIndexColumn); |
|
596 |
||
597 |
QTreeView view; |
|
598 |
QStandardItemModel treeModel; |
|
599 |
initStandardTreeModel(&treeModel); |
|
600 |
view.setModel(&treeModel); |
|
601 |
||
602 |
QCOMPARE(view.currentIndex(), QModelIndex()); |
|
603 |
view.setCurrentIndex(view.model()->index(row, column)); |
|
604 |
QCOMPARE(view.currentIndex().row(), indexRow); |
|
605 |
QCOMPARE(view.currentIndex().column(), indexColumn); |
|
606 |
QCOMPARE(view.currentIndex().parent().row(), parentIndexRow); |
|
607 |
QCOMPARE(view.currentIndex().parent().column(), parentIndexColumn); |
|
608 |
||
609 |
// ### Test child and grandChild indexes. |
|
610 |
} |
|
611 |
||
612 |
#ifndef QT_NO_DRAGANDDROP |
|
613 |
||
614 |
void tst_QTreeView::dragDropMode_data() |
|
615 |
{ |
|
616 |
QTest::addColumn<QAbstractItemView::DragDropMode>("dragDropMode"); |
|
617 |
QTest::addColumn<bool>("acceptDrops"); |
|
618 |
QTest::addColumn<bool>("dragEnabled"); |
|
619 |
QTest::newRow("NoDragDrop") << QAbstractItemView::NoDragDrop << false << false; |
|
620 |
QTest::newRow("DragOnly") << QAbstractItemView::DragOnly << false << true; |
|
621 |
QTest::newRow("DropOnly") << QAbstractItemView::DropOnly << true << false; |
|
622 |
QTest::newRow("DragDrop") << QAbstractItemView::DragDrop << true << true; |
|
623 |
QTest::newRow("InternalMove") << QAbstractItemView::InternalMove << true << true; |
|
624 |
} |
|
625 |
||
626 |
void tst_QTreeView::dragDropMode() |
|
627 |
{ |
|
628 |
QFETCH(QAbstractItemView::DragDropMode, dragDropMode); |
|
629 |
QFETCH(bool, acceptDrops); |
|
630 |
QFETCH(bool, dragEnabled); |
|
631 |
||
632 |
QTreeView view; |
|
633 |
QCOMPARE(view.dragDropMode(), QAbstractItemView::NoDragDrop); |
|
634 |
QVERIFY(!view.acceptDrops()); |
|
635 |
QVERIFY(!view.dragEnabled()); |
|
636 |
||
637 |
view.setDragDropMode(dragDropMode); |
|
638 |
QCOMPARE(view.dragDropMode(), dragDropMode); |
|
639 |
QCOMPARE(view.acceptDrops(), acceptDrops); |
|
640 |
QCOMPARE(view.dragEnabled(), dragEnabled); |
|
641 |
||
642 |
// ### Test effects of this mode |
|
643 |
} |
|
644 |
||
645 |
void tst_QTreeView::dragDropModeFromDragEnabledAndAcceptDrops_data() |
|
646 |
{ |
|
647 |
QTest::addColumn<bool>("dragEnabled"); |
|
648 |
QTest::addColumn<bool>("acceptDrops"); |
|
649 |
QTest::addColumn<QAbstractItemView::DragDropMode>("dragDropMode"); |
|
650 |
QTest::addColumn<QAbstractItemView::DragDropMode>("setBehavior"); |
|
651 |
||
652 |
QTest::newRow("NoDragDrop -1") << false << false << QAbstractItemView::NoDragDrop << QAbstractItemView::DragDropMode(-1); |
|
653 |
QTest::newRow("NoDragDrop 0") << false << false << QAbstractItemView::NoDragDrop << QAbstractItemView::NoDragDrop; |
|
654 |
QTest::newRow("NoDragDrop 1") << false << false << QAbstractItemView::NoDragDrop << QAbstractItemView::DragOnly; |
|
655 |
QTest::newRow("NoDragDrop 2") << false << false << QAbstractItemView::NoDragDrop << QAbstractItemView::DropOnly; |
|
656 |
QTest::newRow("NoDragDrop 3") << false << false << QAbstractItemView::NoDragDrop << QAbstractItemView::DragDrop; |
|
657 |
QTest::newRow("NoDragDrop 4") << false << false << QAbstractItemView::NoDragDrop << QAbstractItemView::InternalMove; |
|
658 |
QTest::newRow("DragOnly -1") << true << false << QAbstractItemView::DragOnly << QAbstractItemView::DragDropMode(-1); |
|
659 |
QTest::newRow("DragOnly 0") << true << false << QAbstractItemView::DragOnly << QAbstractItemView::NoDragDrop; |
|
660 |
QTest::newRow("DragOnly 1") << true << false << QAbstractItemView::DragOnly << QAbstractItemView::DragOnly; |
|
661 |
QTest::newRow("DragOnly 2") << true << false << QAbstractItemView::DragOnly << QAbstractItemView::DropOnly; |
|
662 |
QTest::newRow("DragOnly 3") << true << false << QAbstractItemView::DragOnly << QAbstractItemView::DragDrop; |
|
663 |
QTest::newRow("DragOnly 4") << true << false << QAbstractItemView::DragOnly << QAbstractItemView::InternalMove; |
|
664 |
QTest::newRow("DropOnly -1") << false << true << QAbstractItemView::DropOnly << QAbstractItemView::DragDropMode(-1); |
|
665 |
QTest::newRow("DropOnly 0") << false << true << QAbstractItemView::DropOnly << QAbstractItemView::NoDragDrop; |
|
666 |
QTest::newRow("DropOnly 1") << false << true << QAbstractItemView::DropOnly << QAbstractItemView::DragOnly; |
|
667 |
QTest::newRow("DropOnly 2") << false << true << QAbstractItemView::DropOnly << QAbstractItemView::DropOnly; |
|
668 |
QTest::newRow("DropOnly 3") << false << true << QAbstractItemView::DropOnly << QAbstractItemView::DragDrop; |
|
669 |
QTest::newRow("DropOnly 4") << false << true << QAbstractItemView::DropOnly << QAbstractItemView::InternalMove; |
|
670 |
QTest::newRow("DragDrop -1") << true << true << QAbstractItemView::DragDrop << QAbstractItemView::DragDropMode(-1); |
|
671 |
QTest::newRow("DragDrop 0") << true << true << QAbstractItemView::DragDrop << QAbstractItemView::DragDropMode(-1); |
|
672 |
QTest::newRow("DragDrop 1") << true << true << QAbstractItemView::DragDrop << QAbstractItemView::NoDragDrop; |
|
673 |
QTest::newRow("DragDrop 2") << true << true << QAbstractItemView::DragDrop << QAbstractItemView::DragOnly; |
|
674 |
QTest::newRow("DragDrop 3") << true << true << QAbstractItemView::DragDrop << QAbstractItemView::DropOnly; |
|
675 |
QTest::newRow("DragDrop 4") << true << true << QAbstractItemView::DragDrop << QAbstractItemView::DragDrop; |
|
676 |
QTest::newRow("DragDrop 5") << true << true << QAbstractItemView::InternalMove << QAbstractItemView::InternalMove; |
|
677 |
} |
|
678 |
||
679 |
void tst_QTreeView::dragDropModeFromDragEnabledAndAcceptDrops() |
|
680 |
{ |
|
681 |
QFETCH(bool, acceptDrops); |
|
682 |
QFETCH(bool, dragEnabled); |
|
683 |
QFETCH(QAbstractItemView::DragDropMode, dragDropMode); |
|
684 |
QFETCH(QAbstractItemView::DragDropMode, setBehavior); |
|
685 |
||
686 |
QTreeView view; |
|
687 |
QCOMPARE(view.dragDropMode(), QAbstractItemView::NoDragDrop); |
|
688 |
||
689 |
if (setBehavior != QAbstractItemView::DragDropMode(-1)) |
|
690 |
view.setDragDropMode(setBehavior); |
|
691 |
||
692 |
view.setAcceptDrops(acceptDrops); |
|
693 |
view.setDragEnabled(dragEnabled); |
|
694 |
QCOMPARE(view.dragDropMode(), dragDropMode); |
|
695 |
||
696 |
// ### Test effects of this mode |
|
697 |
} |
|
698 |
||
699 |
void tst_QTreeView::dragDropOverwriteMode() |
|
700 |
{ |
|
701 |
QTreeView view; |
|
702 |
QVERIFY(!view.dragDropOverwriteMode()); |
|
703 |
view.setDragDropOverwriteMode(true); |
|
704 |
QVERIFY(view.dragDropOverwriteMode()); |
|
705 |
view.setDragDropOverwriteMode(false); |
|
706 |
QVERIFY(!view.dragDropOverwriteMode()); |
|
707 |
||
708 |
// ### This property changes the behavior of dropIndicatorPosition(), |
|
709 |
// which is protected and called only from within QListWidget and |
|
710 |
// QTableWidget, from their reimplementations of dropMimeData(). Hard to |
|
711 |
// test. |
|
712 |
} |
|
713 |
#endif |
|
714 |
||
715 |
void tst_QTreeView::editTriggers_data() |
|
716 |
{ |
|
717 |
QTest::addColumn<QAbstractItemView::EditTriggers>("editTriggers"); |
|
718 |
QTest::addColumn<QAbstractItemView::EditTrigger>("triggeredTrigger"); |
|
719 |
QTest::addColumn<bool>("editorOpened"); |
|
720 |
||
721 |
// NoEditTriggers |
|
722 |
QTest::newRow("NoEditTriggers 0") << QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers) |
|
723 |
<< QAbstractItemView::NoEditTriggers << false; |
|
724 |
QTest::newRow("NoEditTriggers 1") << QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers) |
|
725 |
<< QAbstractItemView::CurrentChanged << false; |
|
726 |
QTest::newRow("NoEditTriggers 2") << QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers) |
|
727 |
<< QAbstractItemView::DoubleClicked << false; |
|
728 |
QTest::newRow("NoEditTriggers 3") << QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers) |
|
729 |
<< QAbstractItemView::SelectedClicked << false; |
|
730 |
QTest::newRow("NoEditTriggers 4") << QAbstractItemView::EditTriggers(QAbstractItemView::NoEditTriggers) |
|
731 |
<< QAbstractItemView::EditKeyPressed << false; |
|
732 |
||
733 |
// CurrentChanged |
|
734 |
QTest::newRow("CurrentChanged 0") << QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged) |
|
735 |
<< QAbstractItemView::NoEditTriggers << false; |
|
736 |
QTest::newRow("CurrentChanged 1") << QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged) |
|
737 |
<< QAbstractItemView::CurrentChanged << true; |
|
738 |
QTest::newRow("CurrentChanged 2") << QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged) |
|
739 |
<< QAbstractItemView::DoubleClicked << false; |
|
740 |
QTest::newRow("CurrentChanged 3") << QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged) |
|
741 |
<< QAbstractItemView::SelectedClicked << false; |
|
742 |
QTest::newRow("CurrentChanged 4") << QAbstractItemView::EditTriggers(QAbstractItemView::CurrentChanged) |
|
743 |
<< QAbstractItemView::EditKeyPressed << false; |
|
744 |
||
745 |
// DoubleClicked |
|
746 |
QTest::newRow("DoubleClicked 0") << QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked) |
|
747 |
<< QAbstractItemView::NoEditTriggers << false; |
|
748 |
QTest::newRow("DoubleClicked 1") << QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked) |
|
749 |
<< QAbstractItemView::CurrentChanged << false; |
|
750 |
QTest::newRow("DoubleClicked 2") << QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked) |
|
751 |
<< QAbstractItemView::DoubleClicked << true; |
|
752 |
QTest::newRow("DoubleClicked 3") << QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked) |
|
753 |
<< QAbstractItemView::SelectedClicked << false; |
|
754 |
QTest::newRow("DoubleClicked 4") << QAbstractItemView::EditTriggers(QAbstractItemView::DoubleClicked) |
|
755 |
<< QAbstractItemView::EditKeyPressed << false; |
|
756 |
||
757 |
// SelectedClicked |
|
758 |
QTest::newRow("SelectedClicked 0") << QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked) |
|
759 |
<< QAbstractItemView::NoEditTriggers << false; |
|
760 |
QTest::newRow("SelectedClicked 1") << QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked) |
|
761 |
<< QAbstractItemView::CurrentChanged << false; |
|
762 |
QTest::newRow("SelectedClicked 2") << QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked) |
|
763 |
<< QAbstractItemView::DoubleClicked << false; |
|
764 |
QTest::newRow("SelectedClicked 3") << QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked) |
|
765 |
<< QAbstractItemView::SelectedClicked << true; |
|
766 |
QTest::newRow("SelectedClicked 4") << QAbstractItemView::EditTriggers(QAbstractItemView::SelectedClicked) |
|
767 |
<< QAbstractItemView::EditKeyPressed << false; |
|
768 |
||
769 |
// EditKeyPressed |
|
770 |
QTest::newRow("EditKeyPressed 0") << QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed) |
|
771 |
<< QAbstractItemView::NoEditTriggers << false; |
|
772 |
QTest::newRow("EditKeyPressed 1") << QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed) |
|
773 |
<< QAbstractItemView::CurrentChanged << false; |
|
774 |
QTest::newRow("EditKeyPressed 2") << QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed) |
|
775 |
<< QAbstractItemView::DoubleClicked << false; |
|
776 |
QTest::newRow("EditKeyPressed 3") << QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed) |
|
777 |
<< QAbstractItemView::SelectedClicked << false; |
|
778 |
QTest::newRow("EditKeyPressed 4") << QAbstractItemView::EditTriggers(QAbstractItemView::EditKeyPressed) |
|
779 |
<< QAbstractItemView::EditKeyPressed << true; |
|
780 |
} |
|
781 |
||
782 |
void tst_QTreeView::editTriggers() |
|
783 |
{ |
|
784 |
QFETCH(QAbstractItemView::EditTriggers, editTriggers); |
|
785 |
QFETCH(QAbstractItemView::EditTrigger, triggeredTrigger); |
|
786 |
QFETCH(bool, editorOpened); |
|
787 |
||
788 |
QTreeView view; |
|
789 |
QStandardItemModel treeModel; |
|
790 |
initStandardTreeModel(&treeModel); |
|
791 |
view.setModel(&treeModel); |
|
792 |
view.show(); |
|
793 |
||
794 |
QCOMPARE(view.editTriggers(), QAbstractItemView::EditKeyPressed | QAbstractItemView::DoubleClicked); |
|
795 |
||
796 |
// Initialize the first index |
|
797 |
view.setCurrentIndex(view.model()->index(0, 0)); |
|
798 |
||
799 |
// Verify that we don't have any editor initially |
|
800 |
QVERIFY(!qFindChild<QLineEdit *>(&view, QString())); |
|
801 |
||
802 |
// Set the triggers |
|
803 |
view.setEditTriggers(editTriggers); |
|
804 |
||
805 |
// Interact with the view |
|
806 |
switch (triggeredTrigger) { |
|
807 |
case QAbstractItemView::NoEditTriggers: |
|
808 |
// Do nothing, the editor shouldn't be there |
|
809 |
break; |
|
810 |
case QAbstractItemView::CurrentChanged: |
|
811 |
// Change the index to open an editor |
|
812 |
view.setCurrentIndex(view.model()->index(1, 0)); |
|
813 |
break; |
|
814 |
case QAbstractItemView::DoubleClicked: |
|
815 |
// Doubleclick the center of the current cell |
|
816 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, |
|
817 |
view.visualRect(view.model()->index(0, 0)).center()); |
|
818 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, |
|
819 |
view.visualRect(view.model()->index(0, 0)).center()); |
|
820 |
break; |
|
821 |
case QAbstractItemView::SelectedClicked: |
|
822 |
// Click the center of the current cell |
|
823 |
view.selectionModel()->select(view.model()->index(0, 0), QItemSelectionModel::Select); |
|
824 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, |
|
825 |
view.visualRect(view.model()->index(0, 0)).center()); |
|
826 |
QTest::qWait(int(QApplication::doubleClickInterval() * 1.5)); |
|
827 |
break; |
|
828 |
case QAbstractItemView::EditKeyPressed: |
|
829 |
view.setFocus(); |
|
830 |
#ifdef Q_OS_MAC |
|
831 |
// Mac OS X uses Enter for editing |
|
832 |
QTest::keyPress(&view, Qt::Key_Enter); |
|
833 |
#else |
|
834 |
// All other platforms use F2 |
|
835 |
QTest::keyPress(&view, Qt::Key_F2); |
|
836 |
#endif |
|
837 |
break; |
|
838 |
default: |
|
839 |
break; |
|
840 |
} |
|
841 |
||
842 |
// Check if we got an editor |
|
843 |
QTRY_COMPARE(qFindChild<QLineEdit *>(&view, QString()) != 0, editorOpened); |
|
844 |
} |
|
845 |
||
846 |
void tst_QTreeView::hasAutoScroll() |
|
847 |
{ |
|
848 |
QTreeView view; |
|
849 |
QVERIFY(view.hasAutoScroll()); |
|
850 |
view.setAutoScroll(false); |
|
851 |
QVERIFY(!view.hasAutoScroll()); |
|
852 |
view.setAutoScroll(true); |
|
853 |
QVERIFY(view.hasAutoScroll()); |
|
854 |
} |
|
855 |
||
856 |
void tst_QTreeView::horizontalScrollMode() |
|
857 |
{ |
|
858 |
QStandardItemModel model; |
|
859 |
for (int i = 0; i < 100; ++i) { |
|
860 |
model.appendRow(QList<QStandardItem *>() |
|
861 |
<< new QStandardItem("An item that has very long text and should" |
|
862 |
" cause the horizontal scroll bar to appear.") |
|
863 |
<< new QStandardItem("An item that has very long text and should" |
|
864 |
" cause the horizontal scroll bar to appear.")); |
|
865 |
} |
|
866 |
||
867 |
QTreeView view; |
|
868 |
view.setModel(&model); |
|
869 |
view.setFixedSize(100, 100); |
|
870 |
view.header()->resizeSection(0, 200); |
|
871 |
view.show(); |
|
872 |
||
873 |
QCOMPARE(view.horizontalScrollMode(), QAbstractItemView::ScrollPerPixel); |
|
874 |
QCOMPARE(view.horizontalScrollBar()->minimum(), 0); |
|
875 |
QVERIFY(view.horizontalScrollBar()->maximum() > 2); |
|
876 |
||
877 |
view.setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
|
878 |
QCOMPARE(view.horizontalScrollMode(), QAbstractItemView::ScrollPerItem); |
|
879 |
QCOMPARE(view.horizontalScrollBar()->minimum(), 0); |
|
880 |
QCOMPARE(view.horizontalScrollBar()->maximum(), 1); |
|
881 |
||
882 |
view.setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); |
|
883 |
QCOMPARE(view.horizontalScrollMode(), QAbstractItemView::ScrollPerPixel); |
|
884 |
QCOMPARE(view.horizontalScrollBar()->minimum(), 0); |
|
885 |
QVERIFY(view.horizontalScrollBar()->maximum() > 2); |
|
886 |
} |
|
887 |
||
888 |
class RepaintTreeView : public QTreeView |
|
889 |
{ |
|
890 |
public: |
|
891 |
RepaintTreeView() : repainted(false) { } |
|
892 |
bool repainted; |
|
893 |
||
894 |
protected: |
|
895 |
void paintEvent(QPaintEvent *event) |
|
896 |
{ repainted = true; QTreeView::paintEvent(event); } |
|
897 |
}; |
|
898 |
||
899 |
void tst_QTreeView::iconSize() |
|
900 |
{ |
|
901 |
RepaintTreeView view; |
|
902 |
QCOMPARE(view.iconSize(), QSize()); |
|
903 |
||
904 |
QStandardItemModel treeModel; |
|
905 |
initStandardTreeModel(&treeModel); |
|
906 |
view.setModel(&treeModel); |
|
907 |
QCOMPARE(view.iconSize(), QSize()); |
|
908 |
QVERIFY(!view.repainted); |
|
909 |
||
910 |
view.show(); |
|
911 |
view.update(); |
|
912 |
QTest::qWaitForWindowShown(&view); |
|
913 |
QTRY_VERIFY(view.repainted); |
|
914 |
QCOMPARE(view.iconSize(), QSize()); |
|
915 |
||
916 |
view.repainted = false; |
|
917 |
view.setIconSize(QSize()); |
|
918 |
QTRY_VERIFY(!view.repainted); |
|
919 |
QCOMPARE(view.iconSize(), QSize()); |
|
920 |
||
921 |
view.setIconSize(QSize(10, 10)); |
|
922 |
QTRY_VERIFY(view.repainted); |
|
923 |
QCOMPARE(view.iconSize(), QSize(10, 10)); |
|
924 |
||
925 |
view.repainted = false; |
|
926 |
view.setIconSize(QSize(10000, 10000)); |
|
927 |
QTRY_VERIFY(view.repainted); |
|
928 |
QCOMPARE(view.iconSize(), QSize(10000, 10000)); |
|
929 |
} |
|
930 |
||
931 |
void tst_QTreeView::indexAt() |
|
932 |
{ |
|
933 |
QtTestModel model; |
|
934 |
model.rows = model.cols = 5; |
|
935 |
||
936 |
QTreeView view; |
|
937 |
QCOMPARE(view.indexAt(QPoint()), QModelIndex()); |
|
938 |
view.setModel(&model); |
|
939 |
QVERIFY(view.indexAt(QPoint()) != QModelIndex()); |
|
940 |
||
941 |
QSize itemSize = view.visualRect(model.index(0, 0)).size(); |
|
942 |
for (int i = 0; i < model.rowCount(); ++i) { |
|
943 |
QPoint pos(itemSize.width() / 2, (i * itemSize.height()) + (itemSize.height() / 2)); |
|
944 |
QModelIndex index = view.indexAt(pos); |
|
945 |
QCOMPARE(index, model.index(i, 0)); |
|
946 |
} |
|
947 |
||
948 |
/* |
|
949 |
// ### this is wrong; the widget _will_ affect the item size |
|
950 |
for (int j = 0; j < model.rowCount(); ++j) |
|
951 |
view.setIndexWidget(model.index(j, 0), new QPushButton); |
|
952 |
*/ |
|
953 |
||
954 |
for (int k = 0; k < model.rowCount(); ++k) { |
|
955 |
QPoint pos(itemSize.width() / 2, (k * itemSize.height()) + (itemSize.height() / 2)); |
|
956 |
QModelIndex index = view.indexAt(pos); |
|
957 |
QCOMPARE(index, model.index(k, 0)); |
|
958 |
} |
|
959 |
||
960 |
view.show(); |
|
961 |
view.resize(600, 600); |
|
962 |
view.header()->setStretchLastSection(false); |
|
963 |
QCOMPARE(view.indexAt(QPoint(550, 20)), QModelIndex()); |
|
964 |
} |
|
965 |
||
966 |
void tst_QTreeView::indexWidget() |
|
967 |
{ |
|
968 |
QTreeView view; |
|
969 |
QStandardItemModel treeModel; |
|
970 |
initStandardTreeModel(&treeModel); |
|
971 |
view.setModel(&treeModel); |
|
972 |
||
973 |
QModelIndex index = view.model()->index(0, 0); |
|
974 |
||
975 |
QVERIFY(!view.indexWidget(QModelIndex())); |
|
976 |
QVERIFY(!view.indexWidget(index)); |
|
977 |
||
978 |
QString text = QLatin1String("TestLabel"); |
|
979 |
||
980 |
QWidget *label = new QLabel(text); |
|
981 |
view.setIndexWidget(QModelIndex(), label); |
|
982 |
QVERIFY(!view.indexWidget(QModelIndex())); |
|
983 |
QVERIFY(!label->parent()); |
|
984 |
view.setIndexWidget(index, label); |
|
985 |
QCOMPARE(view.indexWidget(index), label); |
|
986 |
QCOMPARE(label->parentWidget(), view.viewport()); |
|
987 |
||
988 |
||
989 |
QTextEdit *widget = new QTextEdit(text); |
|
990 |
widget->setFixedSize(200,100); |
|
991 |
view.setIndexWidget(index, widget); |
|
992 |
QCOMPARE(view.indexWidget(index), static_cast<QWidget *>(widget)); |
|
993 |
||
994 |
QCOMPARE(widget->parentWidget(), view.viewport()); |
|
995 |
QCOMPARE(widget->geometry(), view.visualRect(index).intersected(widget->geometry())); |
|
996 |
QCOMPARE(widget->toPlainText(), text); |
|
997 |
||
998 |
//now let's try to do that later when the widget is already shown |
|
999 |
view.show(); |
|
1000 |
index = view.model()->index(1, 0); |
|
1001 |
QVERIFY(!view.indexWidget(index)); |
|
1002 |
||
1003 |
widget = new QTextEdit(text); |
|
1004 |
widget->setFixedSize(200,100); |
|
1005 |
view.setIndexWidget(index, widget); |
|
1006 |
QCOMPARE(view.indexWidget(index), static_cast<QWidget *>(widget)); |
|
1007 |
||
1008 |
QCOMPARE(widget->parentWidget(), view.viewport()); |
|
1009 |
QCOMPARE(widget->geometry(), view.visualRect(index).intersect(widget->geometry())); |
|
1010 |
QCOMPARE(widget->toPlainText(), text); |
|
1011 |
} |
|
1012 |
||
1013 |
void tst_QTreeView::itemDelegate() |
|
1014 |
{ |
|
1015 |
QPointer<QAbstractItemDelegate> oldDelegate; |
|
1016 |
QPointer<QItemDelegate> otherItemDelegate; |
|
1017 |
||
1018 |
{ |
|
1019 |
QTreeView view; |
|
1020 |
QVERIFY(qobject_cast<QStyledItemDelegate *>(view.itemDelegate())); |
|
1021 |
QPointer<QAbstractItemDelegate> oldDelegate = view.itemDelegate(); |
|
1022 |
||
1023 |
otherItemDelegate = new QItemDelegate; |
|
1024 |
view.setItemDelegate(otherItemDelegate); |
|
1025 |
QVERIFY(!otherItemDelegate->parent()); |
|
1026 |
QVERIFY(oldDelegate); |
|
1027 |
||
1028 |
QCOMPARE(view.itemDelegate(), (QAbstractItemDelegate *)otherItemDelegate); |
|
1029 |
||
1030 |
view.setItemDelegate(0); |
|
1031 |
QVERIFY(!view.itemDelegate()); // <- view does its own drawing? |
|
1032 |
QVERIFY(otherItemDelegate); |
|
1033 |
} |
|
1034 |
||
1035 |
// This is strange. Why doesn't setItemDelegate() reparent the delegate? |
|
1036 |
QVERIFY(!oldDelegate); |
|
1037 |
QVERIFY(otherItemDelegate); |
|
1038 |
||
1039 |
delete otherItemDelegate; |
|
1040 |
} |
|
1041 |
||
1042 |
void tst_QTreeView::itemDelegateForColumnOrRow() |
|
1043 |
{ |
|
1044 |
QTreeView view; |
|
1045 |
QAbstractItemDelegate *defaultDelegate = view.itemDelegate(); |
|
1046 |
QVERIFY(defaultDelegate); |
|
1047 |
||
1048 |
QVERIFY(!view.itemDelegateForRow(0)); |
|
1049 |
QVERIFY(!view.itemDelegateForColumn(0)); |
|
1050 |
QCOMPARE(view.itemDelegate(QModelIndex()), defaultDelegate); |
|
1051 |
||
1052 |
QStandardItemModel model; |
|
1053 |
for (int i = 0; i < 100; ++i) { |
|
1054 |
model.appendRow(QList<QStandardItem *>() |
|
1055 |
<< new QStandardItem("An item that has very long text and should" |
|
1056 |
" cause the horizontal scroll bar to appear.") |
|
1057 |
<< new QStandardItem("An item that has very long text and should" |
|
1058 |
" cause the horizontal scroll bar to appear.") |
|
1059 |
<< new QStandardItem("An item that has very long text and should" |
|
1060 |
" cause the horizontal scroll bar to appear.")); |
|
1061 |
} |
|
1062 |
view.setModel(&model); |
|
1063 |
||
1064 |
QVERIFY(!view.itemDelegateForRow(0)); |
|
1065 |
QVERIFY(!view.itemDelegateForColumn(0)); |
|
1066 |
QCOMPARE(view.itemDelegate(QModelIndex()), defaultDelegate); |
|
1067 |
QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), defaultDelegate); |
|
1068 |
||
1069 |
QPointer<QAbstractItemDelegate> rowDelegate = new QItemDelegate; |
|
1070 |
view.setItemDelegateForRow(0, rowDelegate); |
|
1071 |
QVERIFY(!rowDelegate->parent()); |
|
1072 |
QCOMPARE(view.itemDelegateForRow(0), (QAbstractItemDelegate *)rowDelegate); |
|
1073 |
QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), (QAbstractItemDelegate *)rowDelegate); |
|
1074 |
QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), (QAbstractItemDelegate *)rowDelegate); |
|
1075 |
QCOMPARE(view.itemDelegate(view.model()->index(1, 0)), defaultDelegate); |
|
1076 |
QCOMPARE(view.itemDelegate(view.model()->index(1, 1)), defaultDelegate); |
|
1077 |
||
1078 |
QPointer<QAbstractItemDelegate> columnDelegate = new QItemDelegate; |
|
1079 |
view.setItemDelegateForColumn(1, columnDelegate); |
|
1080 |
QVERIFY(!columnDelegate->parent()); |
|
1081 |
QCOMPARE(view.itemDelegateForColumn(1), (QAbstractItemDelegate *)columnDelegate); |
|
1082 |
QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), (QAbstractItemDelegate *)rowDelegate); |
|
1083 |
QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), (QAbstractItemDelegate *)rowDelegate); // row wins |
|
1084 |
QCOMPARE(view.itemDelegate(view.model()->index(1, 0)), defaultDelegate); |
|
1085 |
QCOMPARE(view.itemDelegate(view.model()->index(1, 1)), (QAbstractItemDelegate *)columnDelegate); |
|
1086 |
||
1087 |
view.setItemDelegateForRow(0, 0); |
|
1088 |
QVERIFY(!view.itemDelegateForRow(0)); |
|
1089 |
QVERIFY(rowDelegate); // <- wasn't deleted |
|
1090 |
||
1091 |
view.setItemDelegateForColumn(1, 0); |
|
1092 |
QVERIFY(!view.itemDelegateForColumn(1)); |
|
1093 |
QVERIFY(columnDelegate); // <- wasn't deleted |
|
1094 |
||
1095 |
delete rowDelegate; |
|
1096 |
delete columnDelegate; |
|
1097 |
} |
|
1098 |
||
1099 |
void tst_QTreeView::keyboardSearch() |
|
1100 |
{ |
|
1101 |
QTreeView view; |
|
1102 |
QStandardItemModel model; |
|
1103 |
model.appendRow(new QStandardItem("Andreas")); |
|
1104 |
model.appendRow(new QStandardItem("Baldrian")); |
|
1105 |
model.appendRow(new QStandardItem("Cecilie")); |
|
1106 |
view.setModel(&model); |
|
1107 |
view.show(); |
|
1108 |
||
1109 |
// Nothing is selected |
|
1110 |
QVERIFY(!view.selectionModel()->hasSelection()); |
|
1111 |
QVERIFY(!view.selectionModel()->isSelected(model.index(0, 0))); |
|
1112 |
||
1113 |
// First item is selected |
|
1114 |
view.keyboardSearch(QLatin1String("A")); |
|
1115 |
QTRY_VERIFY(view.selectionModel()->isSelected(model.index(0, 0))); |
|
1116 |
||
1117 |
// First item is still selected |
|
1118 |
view.keyboardSearch(QLatin1String("n")); |
|
1119 |
QVERIFY(view.selectionModel()->isSelected(model.index(0, 0))); |
|
1120 |
||
1121 |
// No "AnB" item - keep the same selection. |
|
1122 |
view.keyboardSearch(QLatin1String("B")); |
|
1123 |
QVERIFY(view.selectionModel()->isSelected(model.index(0, 0))); |
|
1124 |
||
1125 |
// Wait a bit. |
|
1126 |
QTest::qWait(QApplication::keyboardInputInterval() * 2); |
|
1127 |
||
1128 |
// The item that starts with B is selected. |
|
1129 |
view.keyboardSearch(QLatin1String("B")); |
|
1130 |
QVERIFY(view.selectionModel()->isSelected(model.index(1, 0))); |
|
1131 |
} |
|
1132 |
||
1133 |
void tst_QTreeView::setModel() |
|
1134 |
{ |
|
1135 |
QTreeView view; |
|
1136 |
view.show(); |
|
1137 |
QCOMPARE(view.model(), (QAbstractItemModel*)0); |
|
1138 |
QCOMPARE(view.selectionModel(), (QItemSelectionModel*)0); |
|
1139 |
QCOMPARE(view.header()->model(), (QAbstractItemModel*)0); |
|
1140 |
QCOMPARE(view.header()->selectionModel(), (QItemSelectionModel*)0); |
|
1141 |
||
1142 |
for (int x = 0; x < 2; ++x) { |
|
1143 |
QtTestModel *model = new QtTestModel(10, 8); |
|
1144 |
QAbstractItemModel *oldModel = view.model(); |
|
1145 |
QSignalSpy modelDestroyedSpy(oldModel ? oldModel : model, SIGNAL(destroyed())); |
|
1146 |
// set the same model twice |
|
1147 |
for (int i = 0; i < 2; ++i) { |
|
1148 |
QItemSelectionModel *oldSelectionModel = view.selectionModel(); |
|
1149 |
QItemSelectionModel *dummy = new QItemSelectionModel(model); |
|
1150 |
QSignalSpy selectionModelDestroyedSpy( |
|
1151 |
oldSelectionModel ? oldSelectionModel : dummy, SIGNAL(destroyed())); |
|
1152 |
view.setModel(model); |
|
1153 |
// QCOMPARE(selectionModelDestroyedSpy.count(), (x == 0 || i == 1) ? 0 : 1); |
|
1154 |
QCOMPARE(view.model(), (QAbstractItemModel *)model); |
|
1155 |
QCOMPARE(view.header()->model(), (QAbstractItemModel *)model); |
|
1156 |
QCOMPARE(view.selectionModel() != oldSelectionModel, (i == 0)); |
|
1157 |
} |
|
1158 |
QTRY_COMPARE(modelDestroyedSpy.count(), 0); |
|
1159 |
||
1160 |
view.setModel(0); |
|
1161 |
QCOMPARE(view.model(), (QAbstractItemModel*)0); |
|
1162 |
// ### shouldn't selectionModel also be 0 now? |
|
1163 |
// QCOMPARE(view.selectionModel(), (QItemSelectionModel*)0); |
|
1164 |
delete model; |
|
1165 |
} |
|
1166 |
} |
|
1167 |
||
1168 |
void tst_QTreeView::openPersistentEditor() |
|
1169 |
{ |
|
1170 |
QTreeView view; |
|
1171 |
QStandardItemModel treeModel; |
|
1172 |
initStandardTreeModel(&treeModel); |
|
1173 |
view.setModel(&treeModel); |
|
1174 |
view.show(); |
|
1175 |
||
1176 |
QVERIFY(!qFindChild<QLineEdit *>(view.viewport())); |
|
1177 |
view.openPersistentEditor(view.model()->index(0, 0)); |
|
1178 |
QVERIFY(qFindChild<QLineEdit *>(view.viewport())); |
|
1179 |
||
1180 |
view.closePersistentEditor(view.model()->index(0, 0)); |
|
1181 |
QVERIFY(!qFindChild<QLineEdit *>(view.viewport())->isVisible()); |
|
1182 |
||
1183 |
qApp->sendPostedEvents(0, QEvent::DeferredDelete); |
|
1184 |
QVERIFY(!qFindChild<QLineEdit *>(view.viewport())); |
|
1185 |
} |
|
1186 |
||
1187 |
void tst_QTreeView::rootIndex() |
|
1188 |
{ |
|
1189 |
QTreeView view; |
|
1190 |
QCOMPARE(view.rootIndex(), QModelIndex()); |
|
1191 |
QStandardItemModel treeModel; |
|
1192 |
initStandardTreeModel(&treeModel); |
|
1193 |
view.setModel(&treeModel); |
|
1194 |
QCOMPARE(view.rootIndex(), QModelIndex()); |
|
1195 |
||
1196 |
view.setRootIndex(view.model()->index(1, 0)); |
|
1197 |
||
1198 |
QCOMPARE(view.model()->data(view.model()->index(0, view.header()->visualIndex(0), view.rootIndex()), Qt::DisplayRole) |
|
1199 |
.toString(), QString("Row 2 Child Item")); |
|
1200 |
} |
|
1201 |
||
1202 |
void tst_QTreeView::setHeader() |
|
1203 |
{ |
|
1204 |
QTreeView view; |
|
1205 |
QVERIFY(view.header() != 0); |
|
1206 |
QCOMPARE(view.header()->orientation(), Qt::Horizontal); |
|
1207 |
QCOMPARE(view.header()->parent(), (QObject *)&view); |
|
1208 |
for (int x = 0; x < 2; ++x) { |
|
1209 |
QSignalSpy destroyedSpy(view.header(), SIGNAL(destroyed())); |
|
1210 |
Qt::Orientation orient = x ? Qt::Vertical : Qt::Horizontal; |
|
1211 |
QHeaderView *head = new QHeaderView(orient); |
|
1212 |
view.setHeader(head); |
|
1213 |
QCOMPARE(destroyedSpy.count(), 1); |
|
1214 |
QCOMPARE(head->parent(), (QObject *)&view); |
|
1215 |
QCOMPARE(view.header(), head); |
|
1216 |
view.setHeader(head); |
|
1217 |
QCOMPARE(view.header(), head); |
|
1218 |
// Itemviews in Qt < 4.2 have asserts for this. Qt >= 4.2 should handle this gracefully |
|
1219 |
view.setHeader((QHeaderView *)0); |
|
1220 |
QCOMPARE(view.header(), head); |
|
1221 |
} |
|
1222 |
} |
|
1223 |
||
1224 |
void tst_QTreeView::columnHidden() |
|
1225 |
{ |
|
1226 |
QTreeView view; |
|
1227 |
QtTestModel model(10, 8); |
|
1228 |
view.setModel(&model); |
|
1229 |
view.show(); |
|
1230 |
for (int c = 0; c < model.columnCount(); ++c) |
|
1231 |
QCOMPARE(view.isColumnHidden(c), false); |
|
1232 |
// hide even columns |
|
1233 |
for (int c = 0; c < model.columnCount(); c+=2) |
|
1234 |
view.setColumnHidden(c, true); |
|
1235 |
for (int c = 0; c < model.columnCount(); ++c) |
|
1236 |
QCOMPARE(view.isColumnHidden(c), (c & 1) == 0); |
|
1237 |
view.update(); |
|
1238 |
// hide odd columns too |
|
1239 |
for (int c = 1; c < model.columnCount(); c+=2) |
|
1240 |
view.setColumnHidden(c, true); |
|
1241 |
for (int c = 0; c < model.columnCount(); ++c) |
|
1242 |
QCOMPARE(view.isColumnHidden(c), true); |
|
1243 |
view.update(); |
|
1244 |
} |
|
1245 |
||
1246 |
void tst_QTreeView::rowHidden() |
|
1247 |
{ |
|
1248 |
QtTestModel model(4, 6); |
|
1249 |
model.levels = 3; |
|
1250 |
QTreeView view; |
|
1251 |
view.resize(500,500); |
|
1252 |
view.setModel(&model); |
|
1253 |
view.show(); |
|
1254 |
||
1255 |
QCOMPARE(view.isRowHidden(-1, QModelIndex()), false); |
|
1256 |
QCOMPARE(view.isRowHidden(999999, QModelIndex()), false); |
|
1257 |
view.setRowHidden(-1, QModelIndex(), true); |
|
1258 |
view.setRowHidden(999999, QModelIndex(), true); |
|
1259 |
QCOMPARE(view.isRowHidden(-1, QModelIndex()), false); |
|
1260 |
QCOMPARE(view.isRowHidden(999999, QModelIndex()), false); |
|
1261 |
||
1262 |
view.setRowHidden(0, QModelIndex(), true); |
|
1263 |
QCOMPARE(view.isRowHidden(0, QModelIndex()), true); |
|
1264 |
view.setRowHidden(0, QModelIndex(), false); |
|
1265 |
QCOMPARE(view.isRowHidden(0, QModelIndex()), false); |
|
1266 |
||
1267 |
QStack<QModelIndex> parents; |
|
1268 |
parents.push(QModelIndex()); |
|
1269 |
while (!parents.isEmpty()) { |
|
1270 |
QModelIndex p = parents.pop(); |
|
1271 |
if (model.canFetchMore(p)) |
|
1272 |
model.fetchMore(p); |
|
1273 |
int rows = model.rowCount(p); |
|
1274 |
// hide all |
|
1275 |
for (int r = 0; r < rows; ++r) { |
|
1276 |
view.setRowHidden(r, p, true); |
|
1277 |
QCOMPARE(view.isRowHidden(r, p), true); |
|
1278 |
} |
|
1279 |
// hide none |
|
1280 |
for (int r = 0; r < rows; ++r) { |
|
1281 |
view.setRowHidden(r, p, false); |
|
1282 |
QCOMPARE(view.isRowHidden(r, p), false); |
|
1283 |
} |
|
1284 |
// hide only even rows |
|
1285 |
for (int r = 0; r < rows; ++r) { |
|
1286 |
bool hide = (r & 1) == 0; |
|
1287 |
view.setRowHidden(r, p, hide); |
|
1288 |
QCOMPARE(view.isRowHidden(r, p), hide); |
|
1289 |
} |
|
1290 |
for (int r = 0; r < rows; ++r) |
|
1291 |
parents.push(model.index(r, 0, p)); |
|
1292 |
} |
|
1293 |
||
1294 |
parents.push(QModelIndex()); |
|
1295 |
while (!parents.isEmpty()) { |
|
1296 |
QModelIndex p = parents.pop(); |
|
1297 |
// all even rows should still be hidden |
|
1298 |
for (int r = 0; r < model.rowCount(p); ++r) |
|
1299 |
QCOMPARE(view.isRowHidden(r, p), (r & 1) == 0); |
|
1300 |
if (model.rowCount(p) > 0) { |
|
1301 |
for (int r = 0; r < model.rowCount(p); ++r) |
|
1302 |
parents.push(model.index(r, 0, p)); |
|
1303 |
} |
|
1304 |
} |
|
1305 |
} |
|
1306 |
||
1307 |
void tst_QTreeView::noDelegate() |
|
1308 |
{ |
|
1309 |
QtTestModel model(10, 7); |
|
1310 |
QTreeView view; |
|
1311 |
view.setModel(&model); |
|
1312 |
view.setItemDelegate(0); |
|
1313 |
QCOMPARE(view.itemDelegate(), (QAbstractItemDelegate *)0); |
|
1314 |
} |
|
1315 |
||
1316 |
void tst_QTreeView::noModel() |
|
1317 |
{ |
|
1318 |
QTreeView view; |
|
1319 |
view.show(); |
|
1320 |
view.setRowHidden(0, QModelIndex(), true); |
|
1321 |
} |
|
1322 |
||
1323 |
void tst_QTreeView::emptyModel() |
|
1324 |
{ |
|
1325 |
QtTestModel model; |
|
1326 |
QTreeView view; |
|
1327 |
view.setModel(&model); |
|
1328 |
view.show(); |
|
1329 |
QVERIFY(!model.wrongIndex); |
|
1330 |
} |
|
1331 |
||
1332 |
void tst_QTreeView::removeRows() |
|
1333 |
{ |
|
1334 |
QtTestModel model(7, 10); |
|
1335 |
||
1336 |
QTreeView view; |
|
1337 |
||
1338 |
view.setModel(&model); |
|
1339 |
view.show(); |
|
1340 |
||
1341 |
model.removeLastRow(); |
|
1342 |
QVERIFY(!model.wrongIndex); |
|
1343 |
||
1344 |
model.removeAllRows(); |
|
1345 |
QVERIFY(!model.wrongIndex); |
|
1346 |
} |
|
1347 |
||
1348 |
void tst_QTreeView::removeCols() |
|
1349 |
{ |
|
1350 |
QtTestModel model(5, 8); |
|
1351 |
||
1352 |
QTreeView view; |
|
1353 |
view.setModel(&model); |
|
1354 |
view.show(); |
|
1355 |
model.fetched = true; |
|
1356 |
model.removeLastColumn(); |
|
1357 |
QVERIFY(!model.wrongIndex); |
|
1358 |
QCOMPARE(view.header()->count(), model.cols); |
|
1359 |
||
1360 |
model.removeAllColumns(); |
|
1361 |
QVERIFY(!model.wrongIndex); |
|
1362 |
QCOMPARE(view.header()->count(), model.cols); |
|
1363 |
} |
|
1364 |
||
1365 |
void tst_QTreeView::expandAndCollapse_data() |
|
1366 |
{ |
|
1367 |
QTest::addColumn<bool>("animationEnabled"); |
|
1368 |
QTest::newRow("normal") << false; |
|
1369 |
QTest::newRow("animated") << true; |
|
1370 |
||
1371 |
} |
|
1372 |
||
1373 |
void tst_QTreeView::expandAndCollapse() |
|
1374 |
{ |
|
1375 |
QFETCH(bool, animationEnabled); |
|
1376 |
||
1377 |
QtTestModel model(10, 9); |
|
1378 |
||
1379 |
QTreeView view; |
|
1380 |
view.setUniformRowHeights(true); |
|
1381 |
view.setModel(&model); |
|
1382 |
view.setAnimated(animationEnabled); |
|
1383 |
view.show(); |
|
1384 |
||
1385 |
QModelIndex a = model.index(0, 0, QModelIndex()); |
|
1386 |
QModelIndex b = model.index(0, 0, a); |
|
1387 |
||
1388 |
QSignalSpy expandedSpy(&view, SIGNAL(expanded(const QModelIndex&))); |
|
1389 |
QSignalSpy collapsedSpy(&view, SIGNAL(collapsed(const QModelIndex&))); |
|
1390 |
QVariantList args; |
|
1391 |
||
1392 |
for (int y = 0; y < 2; ++y) { |
|
1393 |
view.setVisible(y == 0); |
|
1394 |
for (int x = 0; x < 2; ++x) { |
|
1395 |
view.setItemsExpandable(x == 0); |
|
1396 |
||
1397 |
// Test bad args |
|
1398 |
view.expand(QModelIndex()); |
|
1399 |
QCOMPARE(view.isExpanded(QModelIndex()), false); |
|
1400 |
view.collapse(QModelIndex()); |
|
1401 |
QCOMPARE(expandedSpy.count(), 0); |
|
1402 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1403 |
||
1404 |
// expand a first level item |
|
1405 |
QVERIFY(!view.isExpanded(a)); |
|
1406 |
view.expand(a); |
|
1407 |
QVERIFY(view.isExpanded(a)); |
|
1408 |
QCOMPARE(expandedSpy.count(), 1); |
|
1409 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1410 |
args = expandedSpy.takeFirst(); |
|
1411 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a); |
|
1412 |
||
1413 |
view.expand(a); |
|
1414 |
QVERIFY(view.isExpanded(a)); |
|
1415 |
QCOMPARE(expandedSpy.count(), 0); |
|
1416 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1417 |
||
1418 |
// expand a second level item |
|
1419 |
QVERIFY(!view.isExpanded(b)); |
|
1420 |
view.expand(b); |
|
1421 |
QVERIFY(view.isExpanded(a)); |
|
1422 |
QVERIFY(view.isExpanded(b)); |
|
1423 |
QCOMPARE(expandedSpy.count(), 1); |
|
1424 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1425 |
args = expandedSpy.takeFirst(); |
|
1426 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), b); |
|
1427 |
||
1428 |
view.expand(b); |
|
1429 |
QVERIFY(view.isExpanded(b)); |
|
1430 |
QCOMPARE(expandedSpy.count(), 0); |
|
1431 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1432 |
||
1433 |
// collapse the first level item |
|
1434 |
view.collapse(a); |
|
1435 |
QVERIFY(!view.isExpanded(a)); |
|
1436 |
QVERIFY(view.isExpanded(b)); |
|
1437 |
QCOMPARE(expandedSpy.count(), 0); |
|
1438 |
QCOMPARE(collapsedSpy.count(), 1); |
|
1439 |
args = collapsedSpy.takeFirst(); |
|
1440 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a); |
|
1441 |
||
1442 |
view.collapse(a); |
|
1443 |
QVERIFY(!view.isExpanded(a)); |
|
1444 |
QCOMPARE(expandedSpy.count(), 0); |
|
1445 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1446 |
||
1447 |
// expand the first level item again |
|
1448 |
view.expand(a); |
|
1449 |
QVERIFY(view.isExpanded(a)); |
|
1450 |
QVERIFY(view.isExpanded(b)); |
|
1451 |
QCOMPARE(expandedSpy.count(), 1); |
|
1452 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1453 |
args = expandedSpy.takeFirst(); |
|
1454 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a); |
|
1455 |
||
1456 |
// collapse the second level item |
|
1457 |
view.collapse(b); |
|
1458 |
QVERIFY(view.isExpanded(a)); |
|
1459 |
QVERIFY(!view.isExpanded(b)); |
|
1460 |
QCOMPARE(expandedSpy.count(), 0); |
|
1461 |
QCOMPARE(collapsedSpy.count(), 1); |
|
1462 |
args = collapsedSpy.takeFirst(); |
|
1463 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), b); |
|
1464 |
||
1465 |
// collapse the first level item |
|
1466 |
view.collapse(a); |
|
1467 |
QVERIFY(!view.isExpanded(a)); |
|
1468 |
QVERIFY(!view.isExpanded(b)); |
|
1469 |
QCOMPARE(expandedSpy.count(), 0); |
|
1470 |
QCOMPARE(collapsedSpy.count(), 1); |
|
1471 |
args = collapsedSpy.takeFirst(); |
|
1472 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a); |
|
1473 |
||
1474 |
// expand and remove row |
|
1475 |
QPersistentModelIndex c = model.index(9, 0, b); |
|
1476 |
view.expand(a); |
|
1477 |
view.expand(b); |
|
1478 |
model.removeLastRow(); // remove c |
|
1479 |
QVERIFY(view.isExpanded(a)); |
|
1480 |
QVERIFY(view.isExpanded(b)); |
|
1481 |
QVERIFY(!view.isExpanded(c)); |
|
1482 |
QCOMPARE(expandedSpy.count(), 2); |
|
1483 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1484 |
args = expandedSpy.takeFirst(); |
|
1485 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a); |
|
1486 |
args = expandedSpy.takeFirst(); |
|
1487 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), b); |
|
1488 |
||
1489 |
view.collapse(a); |
|
1490 |
view.collapse(b); |
|
1491 |
QVERIFY(!view.isExpanded(a)); |
|
1492 |
QVERIFY(!view.isExpanded(b)); |
|
1493 |
QVERIFY(!view.isExpanded(c)); |
|
1494 |
QCOMPARE(expandedSpy.count(), 0); |
|
1495 |
QCOMPARE(collapsedSpy.count(), 2); |
|
1496 |
args = collapsedSpy.takeFirst(); |
|
1497 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a); |
|
1498 |
args = collapsedSpy.takeFirst(); |
|
1499 |
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), b); |
|
1500 |
} |
|
1501 |
} |
|
1502 |
} |
|
1503 |
||
1504 |
void tst_QTreeView::expandAndCollapseAll() |
|
1505 |
{ |
|
1506 |
QtTestModel model(3, 2); |
|
1507 |
model.levels = 2; |
|
1508 |
QTreeView view; |
|
1509 |
view.setUniformRowHeights(true); |
|
1510 |
view.setModel(&model); |
|
1511 |
||
1512 |
QSignalSpy expandedSpy(&view, SIGNAL(expanded(const QModelIndex&))); |
|
1513 |
QSignalSpy collapsedSpy(&view, SIGNAL(collapsed(const QModelIndex&))); |
|
1514 |
||
1515 |
view.expandAll(); |
|
1516 |
view.show(); |
|
1517 |
||
1518 |
QCOMPARE(collapsedSpy.count(), 0); |
|
1519 |
||
1520 |
QStack<QModelIndex> parents; |
|
1521 |
parents.push(QModelIndex()); |
|
1522 |
int count = 0; |
|
1523 |
while (!parents.isEmpty()) { |
|
1524 |
QModelIndex p = parents.pop(); |
|
1525 |
int rows = model.rowCount(p); |
|
1526 |
for (int r = 0; r < rows; ++r) |
|
1527 |
QVERIFY(view.isExpanded(model.index(r, 0, p))); |
|
1528 |
count += rows; |
|
1529 |
for (int r = 0; r < rows; ++r) |
|
1530 |
parents.push(model.index(r, 0, p)); |
|
1531 |
} |
|
1532 |
// ### why is expanded() signal not emitted? |
|
1533 |
// QCOMPARE(expandedSpy.count(), count); |
|
1534 |
||
1535 |
view.collapseAll(); |
|
1536 |
||
1537 |
QCOMPARE(expandedSpy.count(), 0); |
|
1538 |
||
1539 |
parents.push(QModelIndex()); |
|
1540 |
count = 0; |
|
1541 |
while (!parents.isEmpty()) { |
|
1542 |
QModelIndex p = parents.pop(); |
|
1543 |
int rows = model.rowCount(p); |
|
1544 |
for (int r = 0; r < rows; ++r) |
|
1545 |
QVERIFY(!view.isExpanded(model.index(r, 0, p))); |
|
1546 |
count += rows; |
|
1547 |
for (int r = 0; r < rows; ++r) |
|
1548 |
parents.push(model.index(r, 0, p)); |
|
1549 |
} |
|
1550 |
// ### why is collapsed() signal not emitted? |
|
1551 |
// QCOMPARE(collapsedSpy.count(), count); |
|
1552 |
} |
|
1553 |
||
1554 |
void tst_QTreeView::expandWithNoChildren() |
|
1555 |
{ |
|
1556 |
QTreeView tree; |
|
1557 |
QStandardItemModel model(1,1); |
|
1558 |
tree.setModel(&model); |
|
1559 |
tree.setAnimated(true); |
|
1560 |
tree.doItemsLayout(); |
|
1561 |
//this test should not output warnings |
|
1562 |
tree.expand(model.index(0,0)); |
|
1563 |
} |
|
1564 |
||
1565 |
||
1566 |
||
1567 |
void tst_QTreeView::keyboardNavigation() |
|
1568 |
{ |
|
1569 |
const int rows = 10; |
|
1570 |
const int columns = 7; |
|
1571 |
||
1572 |
QtTestModel model(rows, columns); |
|
1573 |
||
1574 |
QTreeView view; |
|
1575 |
view.setModel(&model); |
|
1576 |
view.show(); |
|
1577 |
||
1578 |
QVector<Qt::Key> keymoves; |
|
1579 |
keymoves << Qt::Key_Down << Qt::Key_Right << Qt::Key_Right << Qt::Key_Right |
|
1580 |
<< Qt::Key_Down << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down |
|
1581 |
<< Qt::Key_Right << Qt::Key_Right << Qt::Key_Right |
|
1582 |
<< Qt::Key_Left << Qt::Key_Up << Qt::Key_Left << Qt::Key_Left |
|
1583 |
<< Qt::Key_Up << Qt::Key_Down << Qt::Key_Up << Qt::Key_Up |
|
1584 |
<< Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up |
|
1585 |
<< Qt::Key_Left << Qt::Key_Left << Qt::Key_Up << Qt::Key_Down; |
|
1586 |
||
1587 |
int row = 0; |
|
1588 |
int column = 0; |
|
1589 |
QModelIndex index = model.index(row, column, QModelIndex()); |
|
1590 |
view.setCurrentIndex(index); |
|
1591 |
QCOMPARE(view.currentIndex(), index); |
|
1592 |
||
1593 |
for (int i = 0; i < keymoves.size(); ++i) { |
|
1594 |
Qt::Key key = keymoves.at(i); |
|
1595 |
QTest::keyClick(&view, key); |
|
1596 |
||
1597 |
switch (key) { |
|
1598 |
case Qt::Key_Up: |
|
1599 |
if (row > 0) { |
|
1600 |
index = index.sibling(row - 1, column); |
|
1601 |
row -= 1; |
|
1602 |
} else if (index.parent() != QModelIndex()) { |
|
1603 |
index = index.parent(); |
|
1604 |
row = index.row(); |
|
1605 |
} |
|
1606 |
break; |
|
1607 |
case Qt::Key_Down: |
|
1608 |
if (view.isExpanded(index)) { |
|
1609 |
row = 0; |
|
1610 |
index = index.child(row, column); |
|
1611 |
} else { |
|
1612 |
row = qMin(rows - 1, row + 1); |
|
1613 |
index = index.sibling(row, column); |
|
1614 |
} |
|
1615 |
break; |
|
1616 |
case Qt::Key_Left: { |
|
1617 |
QScrollBar *b = view.horizontalScrollBar(); |
|
1618 |
if (b->value() == b->minimum()) |
|
1619 |
QVERIFY(!view.isExpanded(index)); |
|
1620 |
// windows style right will walk to the parent |
|
1621 |
if (view.currentIndex() != index) { |
|
1622 |
QCOMPARE(view.currentIndex(), index.parent()); |
|
1623 |
index = view.currentIndex(); |
|
1624 |
row = index.row(); |
|
1625 |
column = index.column(); |
|
1626 |
} |
|
1627 |
break; |
|
1628 |
} |
|
1629 |
case Qt::Key_Right: |
|
1630 |
QVERIFY(view.isExpanded(index)); |
|
1631 |
// windows style right will walk to the first child |
|
1632 |
if (view.currentIndex() != index) { |
|
1633 |
QCOMPARE(view.currentIndex().parent(), index); |
|
1634 |
row = view.currentIndex().row(); |
|
1635 |
column = view.currentIndex().column(); |
|
1636 |
index = view.currentIndex(); |
|
1637 |
} |
|
1638 |
break; |
|
1639 |
default: |
|
1640 |
QVERIFY(false); |
|
1641 |
} |
|
1642 |
||
1643 |
QCOMPARE(view.currentIndex().row(), row); |
|
1644 |
QCOMPARE(view.currentIndex().column(), column); |
|
1645 |
QCOMPARE(view.currentIndex(), index); |
|
1646 |
} |
|
1647 |
} |
|
1648 |
||
1649 |
class Dmodel : public QtTestModel |
|
1650 |
{ |
|
1651 |
public: |
|
1652 |
Dmodel() : QtTestModel(10, 10){} |
|
1653 |
||
1654 |
int columnCount(const QModelIndex &parent) const |
|
1655 |
{ |
|
1656 |
if (parent.row() == 5) |
|
1657 |
return 1; |
|
1658 |
return QtTestModel::columnCount(parent); |
|
1659 |
} |
|
1660 |
}; |
|
1661 |
||
1662 |
void tst_QTreeView::headerSections() |
|
1663 |
{ |
|
1664 |
Dmodel model; |
|
1665 |
||
1666 |
QTreeView view; |
|
1667 |
QHeaderView *header = view.header(); |
|
1668 |
||
1669 |
view.setModel(&model); |
|
1670 |
QModelIndex index = model.index(5, 0); |
|
1671 |
view.setRootIndex(index); |
|
1672 |
QCOMPARE(model.columnCount(QModelIndex()), 10); |
|
1673 |
QCOMPARE(model.columnCount(index), 1); |
|
1674 |
QCOMPARE(header->count(), model.columnCount(index)); |
|
1675 |
} |
|
1676 |
||
1677 |
void tst_QTreeView::moveCursor_data() |
|
1678 |
{ |
|
1679 |
QTest::addColumn<bool>("uniformRowHeights"); |
|
1680 |
QTest::addColumn<bool>("scrollPerPixel"); |
|
1681 |
QTest::newRow("uniformRowHeights = false, scrollPerPixel = false") |
|
1682 |
<< false << false; |
|
1683 |
QTest::newRow("uniformRowHeights = true, scrollPerPixel = false") |
|
1684 |
<< true << false; |
|
1685 |
QTest::newRow("uniformRowHeights = false, scrollPerPixel = true") |
|
1686 |
<< false << true; |
|
1687 |
QTest::newRow("uniformRowHeights = true, scrollPerPixel = true") |
|
1688 |
<< true << true; |
|
1689 |
} |
|
1690 |
||
1691 |
void tst_QTreeView::moveCursor() |
|
1692 |
{ |
|
1693 |
QFETCH(bool, uniformRowHeights); |
|
1694 |
QFETCH(bool, scrollPerPixel); |
|
1695 |
QtTestModel model(8, 6); |
|
1696 |
||
1697 |
PublicView view; |
|
1698 |
view.setUniformRowHeights(uniformRowHeights); |
|
1699 |
view.setModel(&model); |
|
1700 |
view.setRowHidden(0, QModelIndex(), true); |
|
1701 |
view.setVerticalScrollMode(scrollPerPixel ? |
|
1702 |
QAbstractItemView::ScrollPerPixel : |
|
1703 |
QAbstractItemView::ScrollPerItem); |
|
1704 |
QVERIFY(view.isRowHidden(0, QModelIndex())); |
|
1705 |
view.setColumnHidden(0, true); |
|
1706 |
QVERIFY(view.isColumnHidden(0)); |
|
1707 |
view.show(); |
|
1708 |
qApp->setActiveWindow(&view); |
|
1709 |
||
1710 |
//here the first visible index should be selected |
|
1711 |
//because the view got the focus |
|
1712 |
QModelIndex expected = model.index(1, 1, QModelIndex()); |
|
1713 |
QCOMPARE(view.currentIndex(), expected); |
|
1714 |
||
1715 |
//then pressing down should go to the next line |
|
1716 |
QModelIndex actual = view.moveCursor(PublicView::MoveDown, Qt::NoModifier); |
|
1717 |
expected = model.index(2, 1, QModelIndex()); |
|
1718 |
QCOMPARE(actual, expected); |
|
1719 |
||
1720 |
view.setRowHidden(0, QModelIndex(), false); |
|
1721 |
view.setColumnHidden(0, false); |
|
1722 |
||
1723 |
// PageUp was broken with uniform row heights turned on |
|
1724 |
view.setCurrentIndex(model.index(1, 0)); |
|
1725 |
actual = view.moveCursor(PublicView::MovePageUp, Qt::NoModifier); |
|
1726 |
expected = model.index(0, 0, QModelIndex()); |
|
1727 |
QCOMPARE(actual, expected); |
|
1728 |
||
1729 |
//let's try another column |
|
1730 |
view.setCurrentIndex(model.index(1, 1)); |
|
1731 |
view.setSelectionBehavior(QAbstractItemView::SelectItems); |
|
1732 |
QTest::keyClick(view.viewport(), Qt::Key_Up); |
|
1733 |
expected = model.index(0, 1, QModelIndex()); |
|
1734 |
QCOMPARE(view.currentIndex(), expected); |
|
1735 |
QTest::keyClick(view.viewport(), Qt::Key_Down); |
|
1736 |
expected = model.index(1, 1, QModelIndex()); |
|
1737 |
QCOMPARE(view.currentIndex(), expected); |
|
1738 |
QTest::keyClick(view.viewport(), Qt::Key_Up); |
|
1739 |
expected = model.index(0, 1, QModelIndex()); |
|
1740 |
QCOMPARE(view.currentIndex(), expected); |
|
1741 |
view.setColumnHidden(0, true); |
|
1742 |
QTest::keyClick(view.viewport(), Qt::Key_Left); |
|
1743 |
expected = model.index(0, 1, QModelIndex()); //it shouldn't have changed |
|
1744 |
QCOMPARE(view.currentIndex(), expected); |
|
1745 |
view.setColumnHidden(0, false); |
|
1746 |
QTest::keyClick(view.viewport(), Qt::Key_Left); |
|
1747 |
expected = model.index(0, 0, QModelIndex()); |
|
1748 |
QCOMPARE(view.currentIndex(), expected); |
|
1749 |
} |
|
1750 |
||
1751 |
class TestDelegate : public QItemDelegate |
|
1752 |
{ |
|
1753 |
public: |
|
1754 |
TestDelegate(QObject *parent) : QItemDelegate(parent) {} |
|
1755 |
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return QSize(200, 50); } |
|
1756 |
}; |
|
1757 |
||
1758 |
typedef QList<QPoint> PointList; |
|
1759 |
Q_DECLARE_METATYPE(PointList) |
|
1760 |
||
1761 |
void tst_QTreeView::setSelection_data() |
|
1762 |
{ |
|
1763 |
QTest::addColumn<QRect>("selectionRect"); |
|
1764 |
QTest::addColumn<int>("selectionMode"); |
|
1765 |
QTest::addColumn<int>("selectionCommand"); |
|
1766 |
QTest::addColumn<PointList>("expectedItems"); |
|
1767 |
QTest::addColumn<int>("verticalOffset"); |
|
1768 |
||
1769 |
QTest::newRow("(0,0,50,20),rows") << QRect(0,0,50,20) |
|
1770 |
<< int(QAbstractItemView::SingleSelection) |
|
1771 |
<< int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) |
|
1772 |
<< (PointList() |
|
1773 |
<< QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) |
|
1774 |
) |
|
1775 |
<< 0; |
|
1776 |
||
1777 |
QTest::newRow("(0,0,50,90),rows") << QRect(0,0,50,90) |
|
1778 |
<< int(QAbstractItemView::ExtendedSelection) |
|
1779 |
<< int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) |
|
1780 |
<< (PointList() |
|
1781 |
<< QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) |
|
1782 |
<< QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1) |
|
1783 |
) |
|
1784 |
<< 0; |
|
1785 |
||
1786 |
QTest::newRow("(50,0,0,90),rows,invalid rect") << QRect(QPoint(50, 0), QPoint(0, 90)) |
|
1787 |
<< int(QAbstractItemView::ExtendedSelection) |
|
1788 |
<< int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) |
|
1789 |
<< (PointList() |
|
1790 |
<< QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) |
|
1791 |
<< QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1) |
|
1792 |
) |
|
1793 |
<< 0; |
|
1794 |
||
1795 |
QTest::newRow("(0,-20,20,50),rows") << QRect(0,-20,20,50) |
|
1796 |
<< int(QAbstractItemView::ExtendedSelection) |
|
1797 |
<< int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) |
|
1798 |
<< (PointList() |
|
1799 |
<< QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) |
|
1800 |
<< QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1) |
|
1801 |
) |
|
1802 |
<< 1; |
|
1803 |
QTest::newRow("(0,-50,20,90),rows") << QRect(0,-50,20,90) |
|
1804 |
<< int(QAbstractItemView::ExtendedSelection) |
|
1805 |
<< int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) |
|
1806 |
<< (PointList() |
|
1807 |
<< QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) |
|
1808 |
<< QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1) |
|
1809 |
) |
|
1810 |
<< 1; |
|
1811 |
||
1812 |
} |
|
1813 |
||
1814 |
void tst_QTreeView::setSelection() |
|
1815 |
{ |
|
1816 |
QFETCH(QRect, selectionRect); |
|
1817 |
QFETCH(int, selectionMode); |
|
1818 |
QFETCH(int, selectionCommand); |
|
1819 |
QFETCH(PointList, expectedItems); |
|
1820 |
QFETCH(int, verticalOffset); |
|
1821 |
||
1822 |
QtTestModel model(10, 5); |
|
1823 |
model.levels = 1; |
|
1824 |
model.setDecorationsEnabled(true); |
|
1825 |
PublicView view; |
|
1826 |
view.resize(400, 300); |
|
1827 |
view.show(); |
|
1828 |
view.setRootIsDecorated(false); |
|
1829 |
view.setItemDelegate(new TestDelegate(&view)); |
|
1830 |
view.setSelectionMode(QAbstractItemView::SelectionMode(selectionMode)); |
|
1831 |
view.setModel(&model); |
|
1832 |
view.setUniformRowHeights(true); |
|
1833 |
view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
|
1834 |
view.scrollTo(model.index(verticalOffset, 0), QAbstractItemView::PositionAtTop); |
|
1835 |
view.setSelection(selectionRect, QItemSelectionModel::SelectionFlags(selectionCommand)); |
|
1836 |
QItemSelectionModel *selectionModel = view.selectionModel(); |
|
1837 |
QVERIFY(selectionModel); |
|
1838 |
||
1839 |
QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); |
|
1840 |
QCOMPARE(selectedIndexes.count(), expectedItems.count()); |
|
1841 |
for (int i = 0; i < selectedIndexes.count(); ++i) { |
|
1842 |
QModelIndex idx = selectedIndexes.at(i); |
|
1843 |
QVERIFY(expectedItems.contains(QPoint(idx.column(), idx.row()))); |
|
1844 |
} |
|
1845 |
} |
|
1846 |
||
1847 |
void tst_QTreeView::indexAbove() |
|
1848 |
{ |
|
1849 |
QtTestModel model(6, 7); |
|
1850 |
model.levels = 2; |
|
1851 |
QTreeView view; |
|
1852 |
||
1853 |
QCOMPARE(view.indexAbove(QModelIndex()), QModelIndex()); |
|
1854 |
view.setModel(&model); |
|
1855 |
QCOMPARE(view.indexAbove(QModelIndex()), QModelIndex()); |
|
1856 |
||
1857 |
QStack<QModelIndex> parents; |
|
1858 |
parents.push(QModelIndex()); |
|
1859 |
while (!parents.isEmpty()) { |
|
1860 |
QModelIndex p = parents.pop(); |
|
1861 |
if (model.canFetchMore(p)) |
|
1862 |
model.fetchMore(p); |
|
1863 |
int rows = model.rowCount(p); |
|
1864 |
for (int r = rows - 1; r > 0; --r) { |
|
1865 |
QModelIndex idx = model.index(r, 0, p); |
|
1866 |
QModelIndex expected = model.index(r - 1, 0, p); |
|
1867 |
QCOMPARE(view.indexAbove(idx), expected); |
|
1868 |
} |
|
1869 |
// hide even rows |
|
1870 |
for (int r = 0; r < rows; r+=2) |
|
1871 |
view.setRowHidden(r, p, true); |
|
1872 |
for (int r = rows - 1; r > 0; r-=2) { |
|
1873 |
QModelIndex idx = model.index(r, 0, p); |
|
1874 |
QModelIndex expected = model.index(r - 2, 0, p); |
|
1875 |
QCOMPARE(view.indexAbove(idx), expected); |
|
1876 |
} |
|
1877 |
// for (int r = 0; r < rows; ++r) |
|
1878 |
// parents.push(model.index(r, 0, p)); |
|
1879 |
} |
|
1880 |
} |
|
1881 |
||
1882 |
void tst_QTreeView::indexBelow() |
|
1883 |
{ |
|
1884 |
QtTestModel model(2, 1); |
|
1885 |
||
1886 |
QTreeView view; |
|
1887 |
view.setModel(&model); |
|
1888 |
view.show(); |
|
1889 |
||
1890 |
QModelIndex i = model.index(0, 0, view.rootIndex()); |
|
1891 |
QVERIFY(i.isValid()); |
|
1892 |
QCOMPARE(i.row(), 0); |
|
1893 |
||
1894 |
i = view.indexBelow(i); |
|
1895 |
QVERIFY(i.isValid()); |
|
1896 |
QCOMPARE(i.row(), 1); |
|
1897 |
i = view.indexBelow(i); |
|
1898 |
QVERIFY(!i.isValid()); |
|
1899 |
} |
|
1900 |
||
1901 |
void tst_QTreeView::clicked() |
|
1902 |
{ |
|
1903 |
QtTestModel model(10, 2); |
|
1904 |
||
1905 |
QTreeView view; |
|
1906 |
view.setModel(&model); |
|
1907 |
view.show(); |
|
1908 |
||
1909 |
QModelIndex firstIndex = model.index(0, 0, QModelIndex()); |
|
1910 |
QVERIFY(firstIndex.isValid()); |
|
1911 |
int itemHeight = view.visualRect(firstIndex).height(); |
|
1912 |
int itemOffset = view.visualRect(firstIndex).width() / 2; |
|
1913 |
view.resize(200, itemHeight * (model.rows + 2)); |
|
1914 |
||
1915 |
for (int i = 0; i < model.rowCount(); ++i) { |
|
1916 |
QPoint p(itemOffset, 1 + itemHeight * i); |
|
1917 |
QModelIndex index = view.indexAt(p); |
|
1918 |
if (!index.isValid()) |
|
1919 |
continue; |
|
1920 |
QSignalSpy spy(&view, SIGNAL(clicked(const QModelIndex&))); |
|
1921 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); |
|
1922 |
QTRY_COMPARE(spy.count(), 1); |
|
1923 |
} |
|
1924 |
} |
|
1925 |
||
1926 |
void tst_QTreeView::mouseDoubleClick() |
|
1927 |
{ |
|
1928 |
// Test double clicks outside the viewport. |
|
1929 |
// (Should be a no-op and should not expand any item.) |
|
1930 |
||
1931 |
QStandardItemModel model(20, 2); |
|
1932 |
for (int i = 0; i < model.rowCount(); i++) { |
|
1933 |
QModelIndex index = model.index(i, 0, QModelIndex()); |
|
1934 |
model.insertRows(0, 20, index); |
|
1935 |
model.insertColumns(0,2,index); |
|
1936 |
for (int i1 = 0; i1 < model.rowCount(index); i1++) { |
|
1937 |
QModelIndex index2 = model.index(i1, 0, index); |
|
1938 |
} |
|
1939 |
} |
|
1940 |
||
1941 |
QTreeView view; |
|
1942 |
view.setModel(&model); |
|
1943 |
||
1944 |
// make sure the viewport height is smaller than the contents height. |
|
1945 |
view.resize(200,200); |
|
1946 |
view.move(0,0); |
|
1947 |
view.show(); |
|
1948 |
QModelIndex index = model.index(0, 0, QModelIndex()); |
|
1949 |
view.setCurrentIndex(index); |
|
1950 |
||
1951 |
view.setExpanded(model.index(0,0, QModelIndex()), true); |
|
1952 |
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); |
|
1953 |
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); |
|
1954 |
||
1955 |
// Make sure all items are collapsed |
|
1956 |
for (int i = 0; i < model.rowCount(QModelIndex()); i++) { |
|
1957 |
view.setExpanded(model.index(i,0, QModelIndex()), false); |
|
1958 |
} |
|
1959 |
||
1960 |
int maximum = view.verticalScrollBar()->maximum(); |
|
1961 |
||
1962 |
// Doubleclick in the bottom right corner, in the unused area between the vertical and horizontal scrollbar. |
|
1963 |
int vsw = view.verticalScrollBar()->width(); |
|
1964 |
int hsh = view.horizontalScrollBar()->height(); |
|
1965 |
QTest::mouseDClick(&view, Qt::LeftButton, Qt::NoModifier, QPoint(view.width() - vsw + 1, view.height() - hsh + 1)); |
|
1966 |
// Should not have expanded, thus maximum() should have the same value. |
|
1967 |
QCOMPARE(maximum, view.verticalScrollBar()->maximum()); |
|
1968 |
||
1969 |
view.setExpandsOnDoubleClick(false); |
|
1970 |
QTest::mouseDClick(&view, Qt::LeftButton, Qt::NoModifier, view.visualRect(index).center()); |
|
1971 |
QVERIFY(!view.isExpanded(index)); |
|
1972 |
} |
|
1973 |
||
1974 |
void tst_QTreeView::rowsAboutToBeRemoved() |
|
1975 |
{ |
|
1976 |
QStandardItemModel model(3, 1); |
|
1977 |
for (int i = 0; i < model.rowCount(); i++) { |
|
1978 |
QModelIndex index = model.index(i, 0, QModelIndex()); |
|
1979 |
model.setData(index, QString("%1").arg(i)); |
|
1980 |
model.insertRows(0, 4, index); |
|
1981 |
model.insertColumns(0,1,index); |
|
1982 |
for (int i1 = 0; i1 < model.rowCount(index); i1++) { |
|
1983 |
QModelIndex index2 = model.index(i1, 0, index); |
|
1984 |
model.setData(index2, QString("%1%2").arg(i).arg(i1)); |
|
1985 |
} |
|
1986 |
} |
|
1987 |
||
1988 |
PublicView view; |
|
1989 |
view.setModel(&model); |
|
1990 |
view.show(); |
|
1991 |
QModelIndex index = model.index(0,0, QModelIndex()); |
|
1992 |
view.setCurrentIndex(index); |
|
1993 |
view.setExpanded(model.index(0,0, QModelIndex()), true); |
|
1994 |
||
1995 |
for (int i = 0; i < model.rowCount(QModelIndex()); i++) { |
|
1996 |
view.setExpanded(model.index(i,0, QModelIndex()), true); |
|
1997 |
} |
|
1998 |
||
1999 |
QSignalSpy spy1(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
2000 |
||
2001 |
model.removeRows(1,1); |
|
2002 |
QCOMPARE(view.state(), 0); |
|
2003 |
// Should not be 5 (or any other number for that sake :) |
|
2004 |
QCOMPARE(spy1.count(), 1); |
|
2005 |
||
2006 |
} |
|
2007 |
||
2008 |
void tst_QTreeView::headerSections_unhideSection() |
|
2009 |
{ |
|
2010 |
QtTestModel model(10, 7); |
|
2011 |
||
2012 |
QTreeView view; |
|
2013 |
||
2014 |
view.setModel(&model); |
|
2015 |
view.show(); |
|
2016 |
int size = view.header()->sectionSize(0); |
|
2017 |
view.setColumnHidden(0, true); |
|
2018 |
||
2019 |
// should go back to old size |
|
2020 |
view.setColumnHidden(0, false); |
|
2021 |
QCOMPARE(size, view.header()->sectionSize(0)); |
|
2022 |
} |
|
2023 |
||
2024 |
void tst_QTreeView::columnAt() |
|
2025 |
{ |
|
2026 |
QtTestModel model; |
|
2027 |
model.rows = model.cols = 10; |
|
2028 |
QTreeView view; |
|
2029 |
view.resize(500,500); |
|
2030 |
view.setModel(&model); |
|
2031 |
||
2032 |
QCOMPARE(view.columnAt(0), 0); |
|
2033 |
// really this is testing the header... so not much more should be needed if the header is working... |
|
2034 |
} |
|
2035 |
||
2036 |
void tst_QTreeView::scrollTo() |
|
2037 |
{ |
|
2038 |
#define CHECK_VISIBLE(ROW,COL) QVERIFY(QRect(QPoint(),view.viewport()->size()).contains(\ |
|
2039 |
view.visualRect(model.index((ROW),(COL),QModelIndex())))) |
|
2040 |
||
2041 |
QtTestModel model; |
|
2042 |
model.rows = model.cols = 100; |
|
2043 |
QTreeView view; |
|
2044 |
view.setUniformRowHeights(true); |
|
2045 |
view.scrollTo(QModelIndex(), QTreeView::PositionAtTop); |
|
2046 |
view.setModel(&model); |
|
2047 |
||
2048 |
// ### check the scrollbar values an make sure it actually scrolls to the item |
|
2049 |
// ### check for bot item based and pixel based scrolling |
|
2050 |
// ### create a data function for this test |
|
2051 |
||
2052 |
view.scrollTo(QModelIndex()); |
|
2053 |
view.scrollTo(model.index(0,0,QModelIndex())); |
|
2054 |
view.scrollTo(model.index(0,0,QModelIndex()), QTreeView::PositionAtTop); |
|
2055 |
view.scrollTo(model.index(0,0,QModelIndex()), QTreeView::PositionAtBottom); |
|
2056 |
||
2057 |
// |
|
2058 |
||
2059 |
view.show(); |
|
2060 |
view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); //some styles change that in Polish |
|
2061 |
||
2062 |
view.resize(300, 200); |
|
2063 |
//view.verticalScrollBar()->setValue(0); |
|
2064 |
||
2065 |
view.scrollTo(model.index(0,0,QModelIndex())); |
|
2066 |
CHECK_VISIBLE(0,0); |
|
2067 |
QCOMPARE(view.verticalScrollBar()->value(), 0); |
|
2068 |
||
2069 |
view.header()->resizeSection(0, 5); // now we only see the branches |
|
2070 |
view.scrollTo(model.index(5, 0, QModelIndex()), QTreeView::PositionAtTop); |
|
2071 |
QCOMPARE(view.verticalScrollBar()->value(), 5); |
|
2072 |
||
2073 |
view.scrollTo(model.index(60, 60, QModelIndex())); |
|
2074 |
||
2075 |
CHECK_VISIBLE(60,60); |
|
2076 |
view.scrollTo(model.index(60, 30, QModelIndex())); |
|
2077 |
CHECK_VISIBLE(60,30); |
|
2078 |
view.scrollTo(model.index(30, 30, QModelIndex())); |
|
2079 |
CHECK_VISIBLE(30,30); |
|
2080 |
||
2081 |
// TODO force it to move to the left and then the right |
|
2082 |
} |
|
2083 |
||
2084 |
void tst_QTreeView::rowsAboutToBeRemoved_move() |
|
2085 |
{ |
|
2086 |
QStandardItemModel model(3,1); |
|
2087 |
QTreeView view; |
|
2088 |
view.setModel(&model); |
|
2089 |
QModelIndex indexThatWantsToLiveButWillDieDieITellYou; |
|
2090 |
QModelIndex parent = model.index(2, 0 ); |
|
2091 |
view.expand(parent); |
|
2092 |
for (int i = 0; i < 6; ++i) { |
|
2093 |
model.insertRows(0, 1, parent); |
|
2094 |
model.insertColumns(0, 1, parent); |
|
2095 |
QModelIndex index = model.index(0, 0, parent); |
|
2096 |
view.expand(index); |
|
2097 |
if ( i == 3 ) |
|
2098 |
indexThatWantsToLiveButWillDieDieITellYou = index; |
|
2099 |
model.setData(index, i); |
|
2100 |
parent = index; |
|
2101 |
} |
|
2102 |
view.resize(600,800); |
|
2103 |
view.show(); |
|
2104 |
view.doItemsLayout(); |
|
2105 |
static_cast<PublicView *>(&view)->executeDelayedItemsLayout(); |
|
2106 |
parent = indexThatWantsToLiveButWillDieDieITellYou.parent(); |
|
2107 |
QCOMPARE(view.isExpanded(indexThatWantsToLiveButWillDieDieITellYou), true); |
|
2108 |
QCOMPARE(parent.isValid(), true); |
|
2109 |
QCOMPARE(parent.parent().isValid(), true); |
|
2110 |
view.expand(parent); |
|
2111 |
QCOMPARE(view.isExpanded(parent), true); |
|
2112 |
QCOMPARE(view.isExpanded(indexThatWantsToLiveButWillDieDieITellYou), true); |
|
2113 |
model.removeRow(0, indexThatWantsToLiveButWillDieDieITellYou); |
|
2114 |
QCOMPARE(view.isExpanded(parent), true); |
|
2115 |
QCOMPARE(view.isExpanded(indexThatWantsToLiveButWillDieDieITellYou), true); |
|
2116 |
} |
|
2117 |
||
2118 |
void tst_QTreeView::resizeColumnToContents() |
|
2119 |
{ |
|
2120 |
QStandardItemModel model(50,2); |
|
2121 |
for (int r = 0; r < model.rowCount(); ++r) { |
|
2122 |
for (int c = 0; c < model.columnCount(); ++c) { |
|
2123 |
QModelIndex idx = model.index(r, c); |
|
2124 |
model.setData(idx, QString::fromAscii("%1,%2").arg(r).arg(c) ); |
|
2125 |
model.insertColumns(0, 2, idx); |
|
2126 |
model.insertRows(0, 6, idx); |
|
2127 |
for (int i = 0; i < 6; ++i) { |
|
2128 |
for (int j = 0; j < 2 ; ++j) { |
|
2129 |
model.setData(model.index(i, j, idx), QString::fromAscii("child%1%2").arg(i).arg(j)); |
|
2130 |
} |
|
2131 |
} |
|
2132 |
} |
|
2133 |
} |
|
2134 |
QTreeView view; |
|
2135 |
view.setModel(&model); |
|
2136 |
view.show(); |
|
2137 |
qApp->processEvents(); //must have this, or else it will not scroll |
|
2138 |
view.scrollToBottom(); |
|
2139 |
view.resizeColumnToContents(0); |
|
2140 |
int oldColumnSize = view.header()->sectionSize(0); |
|
2141 |
view.setRootIndex(model.index(0, 0)); |
|
2142 |
view.resizeColumnToContents(0); //Earlier, this gave an assert |
|
2143 |
QVERIFY(view.header()->sectionSize(0) > oldColumnSize); |
|
2144 |
} |
|
2145 |
||
2146 |
void tst_QTreeView::insertAfterSelect() |
|
2147 |
{ |
|
2148 |
QtTestModel model; |
|
2149 |
model.rows = model.cols = 10; |
|
2150 |
QTreeView view; |
|
2151 |
view.setModel(&model); |
|
2152 |
view.show(); |
|
2153 |
QModelIndex firstIndex = model.index(0, 0, QModelIndex()); |
|
2154 |
QVERIFY(firstIndex.isValid()); |
|
2155 |
int itemOffset = view.visualRect(firstIndex).width() / 2; |
|
2156 |
QPoint p(itemOffset, 1); |
|
2157 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); |
|
2158 |
QVERIFY(view.selectionModel()->isSelected(firstIndex)); |
|
2159 |
model.insertNewRow(); |
|
2160 |
QVERIFY(view.selectionModel()->isSelected(firstIndex)); // Should still be selected |
|
2161 |
} |
|
2162 |
||
2163 |
void tst_QTreeView::removeAfterSelect() |
|
2164 |
{ |
|
2165 |
QtTestModel model; |
|
2166 |
model.rows = model.cols = 10; |
|
2167 |
QTreeView view; |
|
2168 |
view.setModel(&model); |
|
2169 |
view.show(); |
|
2170 |
QModelIndex firstIndex = model.index(0, 0, QModelIndex()); |
|
2171 |
QVERIFY(firstIndex.isValid()); |
|
2172 |
int itemOffset = view.visualRect(firstIndex).width() / 2; |
|
2173 |
QPoint p(itemOffset, 1); |
|
2174 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); |
|
2175 |
QVERIFY(view.selectionModel()->isSelected(firstIndex)); |
|
2176 |
model.removeLastRow(); |
|
2177 |
QVERIFY(view.selectionModel()->isSelected(firstIndex)); // Should still be selected |
|
2178 |
} |
|
2179 |
||
2180 |
void tst_QTreeView::hiddenItems() |
|
2181 |
{ |
|
2182 |
QtTestModel model; |
|
2183 |
model.rows = model.cols = 10; |
|
2184 |
QTreeView view; |
|
2185 |
view.setModel(&model); |
|
2186 |
view.show(); |
|
2187 |
||
2188 |
QModelIndex firstIndex = model.index(1, 0, QModelIndex()); |
|
2189 |
QVERIFY(firstIndex.isValid()); |
|
2190 |
if (model.canFetchMore(firstIndex)) |
|
2191 |
model.fetchMore(firstIndex); |
|
2192 |
for (int i=0; i < model.rowCount(firstIndex); i++) |
|
2193 |
view.setRowHidden(i , firstIndex, true ); |
|
2194 |
||
2195 |
int itemOffset = view.visualRect(firstIndex).width() / 2; |
|
2196 |
int itemHeight = view.visualRect(firstIndex).height(); |
|
2197 |
QPoint p(itemOffset, itemHeight + 1); |
|
2198 |
view.setExpanded(firstIndex, false); |
|
2199 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); |
|
2200 |
QCOMPARE(view.isExpanded(firstIndex), false); |
|
2201 |
||
2202 |
p.setX( 5 ); |
|
2203 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); |
|
2204 |
QCOMPARE(view.isExpanded(firstIndex), false); |
|
2205 |
} |
|
2206 |
||
2207 |
void tst_QTreeView::spanningItems() |
|
2208 |
{ |
|
2209 |
QtTestModel model; |
|
2210 |
model.rows = model.cols = 10; |
|
2211 |
PublicView view; |
|
2212 |
view.setModel(&model); |
|
2213 |
view.show(); |
|
2214 |
||
2215 |
int itemWidth = view.header()->sectionSize(0); |
|
2216 |
int itemHeight = view.visualRect(model.index(0, 0, QModelIndex())).height(); |
|
2217 |
||
2218 |
// every second row is spanning |
|
2219 |
for (int i = 1; i < model.rowCount(QModelIndex()); i += 2) |
|
2220 |
view.setFirstColumnSpanned(i , QModelIndex(), true); |
|
2221 |
||
2222 |
// non-spanning item |
|
2223 |
QPoint p(itemWidth / 2, itemHeight / 2); // column 0, row 0 |
|
2224 |
view.setCurrentIndex(QModelIndex()); |
|
2225 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); |
|
2226 |
QCOMPARE(view.currentIndex(), model.index(0, 0, QModelIndex())); |
|
2227 |
QCOMPARE(view.header()->sectionSize(0) - view.indentation(), |
|
2228 |
view.visualRect(model.index(0, 0, QModelIndex())).width()); |
|
2229 |
||
2230 |
// spanning item |
|
2231 |
p.setX(itemWidth + (itemWidth / 2)); // column 1 |
|
2232 |
p.setY(itemHeight + (itemHeight / 2)); // row 1 |
|
2233 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); |
|
2234 |
QCOMPARE(view.currentIndex(), model.index(1, 0, QModelIndex())); |
|
2235 |
QCOMPARE(view.header()->length() - view.indentation(), |
|
2236 |
view.visualRect(model.index(1, 0, QModelIndex())).width()); |
|
2237 |
||
2238 |
// size hint |
|
2239 |
// every second row is un-spanned |
|
2240 |
QStyleOptionViewItem option = view.viewOptions(); |
|
2241 |
int w = view.header()->sectionSizeHint(0); |
|
2242 |
for (int i = 0; i < model.rowCount(QModelIndex()); ++i) { |
|
2243 |
if (!view.isFirstColumnSpanned(i, QModelIndex())) { |
|
2244 |
QModelIndex index = model.index(i, 0, QModelIndex()); |
|
2245 |
w = qMax(w, view.itemDelegate(index)->sizeHint(option, index).width() + view.indentation()); |
|
2246 |
} |
|
2247 |
} |
|
2248 |
QCOMPARE(view.sizeHintForColumn(0), w); |
|
2249 |
} |
|
2250 |
||
2251 |
void tst_QTreeView::selectionOrderTest() |
|
2252 |
{ |
|
2253 |
QVERIFY(((QItemSelectionModel*)sender())->currentIndex().row() != -1); |
|
2254 |
} |
|
2255 |
||
2256 |
void tst_QTreeView::selection() |
|
2257 |
{ |
|
2258 |
QTreeView treeView; |
|
2259 |
QStandardItemModel m(10, 2); |
|
2260 |
for (int i = 0;i < 10; ++i) |
|
2261 |
m.setData(m.index(i, 0), i); |
|
2262 |
treeView.setModel(&m); |
|
2263 |
||
2264 |
treeView.setSelectionBehavior(QAbstractItemView::SelectRows); |
|
2265 |
treeView.setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
2266 |
||
2267 |
connect(treeView.selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), |
|
2268 |
this, SLOT(selectionOrderTest())); |
|
2269 |
||
2270 |
treeView.show(); |
|
2271 |
||
2272 |
QTest::mousePress(treeView.viewport(), Qt::LeftButton, 0, treeView.visualRect(m.index(1, 0)).center()); |
|
2273 |
QTest::keyPress(treeView.viewport(), Qt::Key_Down); |
|
2274 |
} |
|
2275 |
||
2276 |
//From task 151686 QTreeView ExtendedSelection selects hidden rows |
|
2277 |
void tst_QTreeView::selectionWithHiddenItems() |
|
2278 |
{ |
|
2279 |
QStandardItemModel model; |
|
2280 |
for (int i = 0; i < model.rowCount(); ++i) |
|
2281 |
model.setData(model.index(i,0), QString("row %1").arg(i)); |
|
2282 |
||
2283 |
QStandardItem item0("row 0"); |
|
2284 |
QStandardItem item1("row 1"); |
|
2285 |
QStandardItem item2("row 2"); |
|
2286 |
QStandardItem item3("row 3"); |
|
2287 |
model.appendColumn( QList<QStandardItem*>() << &item0 << &item1 << &item2 << &item3); |
|
2288 |
||
2289 |
QStandardItem child("child"); |
|
2290 |
item1.appendRow( &child); |
|
2291 |
||
2292 |
QTreeView view; |
|
2293 |
view.setModel(&model); |
|
2294 |
view.setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
2295 |
view.show(); |
|
2296 |
qApp->processEvents(); |
|
2297 |
||
2298 |
//child should not be selected as it is hidden (its parent is not expanded) |
|
2299 |
view.selectAll(); |
|
2300 |
QCOMPARE(view.selectionModel()->selection().count(), 1); //one range |
|
2301 |
QCOMPARE(view.selectionModel()->selectedRows().count(), 4); |
|
2302 |
view.expandAll(); |
|
2303 |
QVERIFY(view.isExpanded(item1.index())); |
|
2304 |
QCOMPARE(view.selectionModel()->selection().count(), 1); |
|
2305 |
QCOMPARE(view.selectionModel()->selectedRows().count(), 4); |
|
2306 |
QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&child))); |
|
2307 |
view.clearSelection(); |
|
2308 |
QVERIFY(view.isExpanded(item1.index())); |
|
2309 |
||
2310 |
//child should be selected as it is visible (its parent is expanded) |
|
2311 |
view.selectAll(); |
|
2312 |
QCOMPARE(view.selectionModel()->selection().count(), 2); |
|
2313 |
QCOMPARE(view.selectionModel()->selectedRows().count(), 5); //everything is selected |
|
2314 |
view.clearSelection(); |
|
2315 |
||
2316 |
//we hide the node with a child (there should then be 3 items selected in 2 ranges) |
|
2317 |
view.setRowHidden(1, QModelIndex(), true); |
|
2318 |
QVERIFY(view.isExpanded(item1.index())); |
|
2319 |
qApp->processEvents(); |
|
2320 |
view.selectAll(); |
|
2321 |
QCOMPARE(view.selectionModel()->selection().count(), 2); |
|
2322 |
QCOMPARE(view.selectionModel()->selectedRows().count(), 3); |
|
2323 |
QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&item1))); |
|
2324 |
QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&child))); |
|
2325 |
||
2326 |
view.setRowHidden(1, QModelIndex(), false); |
|
2327 |
QVERIFY(view.isExpanded(item1.index())); |
|
2328 |
view.clearSelection(); |
|
2329 |
||
2330 |
//we hide a node without children (there should then be 4 items selected in 3 ranges) |
|
2331 |
view.setRowHidden(2, QModelIndex(), true); |
|
2332 |
qApp->processEvents(); |
|
2333 |
QVERIFY(view.isExpanded(item1.index())); |
|
2334 |
view.selectAll(); |
|
2335 |
QVERIFY(view.isExpanded(item1.index())); |
|
2336 |
QCOMPARE(view.selectionModel()->selection().count(), 3); |
|
2337 |
QCOMPARE(view.selectionModel()->selectedRows().count(), 4); |
|
2338 |
QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&item2))); |
|
2339 |
view.setRowHidden(2, QModelIndex(), false); |
|
2340 |
QVERIFY(view.isExpanded(item1.index())); |
|
2341 |
view.clearSelection(); |
|
2342 |
} |
|
2343 |
||
2344 |
void tst_QTreeView::selectAll() |
|
2345 |
{ |
|
2346 |
QStandardItemModel model(4,4); |
|
2347 |
PublicView view2; |
|
2348 |
view2.setModel(&model); |
|
2349 |
view2.setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
2350 |
view2.selectAll(); // Should work with an empty model |
|
2351 |
//everything should be selected since we are in ExtendedSelection mode |
|
2352 |
QCOMPARE(view2.selectedIndexes().count(), model.rowCount() * model.columnCount()); |
|
2353 |
||
2354 |
for (int i = 0; i < model.rowCount(); ++i) |
|
2355 |
model.setData(model.index(i,0), QString("row %1").arg(i)); |
|
2356 |
PublicView view; |
|
2357 |
view.setModel(&model); |
|
2358 |
int selectedCount = view.selectedIndexes().count(); |
|
2359 |
view.selectAll(); |
|
2360 |
QCOMPARE(view.selectedIndexes().count(), selectedCount); |
|
2361 |
} |
|
2362 |
||
2363 |
void tst_QTreeView::extendedSelection_data() |
|
2364 |
{ |
|
2365 |
QTest::addColumn<QPoint>("mousePressPos"); |
|
2366 |
QTest::addColumn<int>("selectedCount"); |
|
2367 |
||
2368 |
QTest::newRow("select") << QPoint(10, 10) << 2; |
|
2369 |
QTest::newRow("unselect") << QPoint(10, 150) << 0; |
|
2370 |
} |
|
2371 |
||
2372 |
void tst_QTreeView::extendedSelection() |
|
2373 |
{ |
|
2374 |
QFETCH(QPoint, mousePressPos); |
|
2375 |
QFETCH(int, selectedCount); |
|
2376 |
||
2377 |
QStandardItemModel model(5, 2); |
|
2378 |
QTreeView view; |
|
2379 |
view.resize(qMax(mousePressPos.x() * 2, 200), qMax(mousePressPos.y() * 2, 200)); |
|
2380 |
view.setModel(&model); |
|
2381 |
view.setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
2382 |
view.show(); |
|
2383 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, mousePressPos); |
|
2384 |
QCOMPARE(view.selectionModel()->selectedIndexes().count(), selectedCount); |
|
2385 |
} |
|
2386 |
||
2387 |
void tst_QTreeView::rowSizeHint() |
|
2388 |
{ |
|
2389 |
//tests whether the correct visible columns are taken into account when |
|
2390 |
//calculating the height of a line |
|
2391 |
QStandardItemModel model(1,3); |
|
2392 |
model.setData( model.index(0,0), QSize(20,40), Qt::SizeHintRole); |
|
2393 |
model.setData( model.index(0,1), QSize(20,10), Qt::SizeHintRole); |
|
2394 |
model.setData( model.index(0,2), QSize(20,10), Qt::SizeHintRole); |
|
2395 |
QTreeView view; |
|
2396 |
view.setModel(&model); |
|
2397 |
||
2398 |
view.header()->moveSection(1, 0); //the 2nd column goes to the 1st place |
|
2399 |
||
2400 |
view.show(); |
|
2401 |
||
2402 |
//it must be 40 since the tallest item that defines the height of a line |
|
2403 |
QCOMPARE( view.visualRect(model.index(0,0)).height(), 40); |
|
2404 |
QCOMPARE( view.visualRect(model.index(0,1)).height(), 40); |
|
2405 |
QCOMPARE( view.visualRect(model.index(0,2)).height(), 40); |
|
2406 |
} |
|
2407 |
||
2408 |
||
2409 |
//From task 155449 (QTreeWidget has a large width for the first section when sorting |
|
2410 |
//is turned on before items are added) |
|
2411 |
void tst_QTreeView::setSortingEnabled() |
|
2412 |
{ |
|
2413 |
//1st the treeview is a top-level |
|
2414 |
{ |
|
2415 |
QTreeView view; |
|
2416 |
QStandardItemModel model(1,1); |
|
2417 |
view.setModel(&model); |
|
2418 |
const int size = view.header()->sectionSize(0); |
|
2419 |
view.setSortingEnabled(true); |
|
2420 |
model.setColumnCount(3); |
|
2421 |
//we test that changing the column count doesn't change the 1st column size |
|
2422 |
QCOMPARE(view.header()->sectionSize(0), size); |
|
2423 |
} |
|
2424 |
||
2425 |
//then it is no more a top-level |
|
2426 |
{ |
|
2427 |
QMainWindow win; |
|
2428 |
QTreeView view; |
|
2429 |
QStandardItemModel model(1,1); |
|
2430 |
view.setModel(&model); |
|
2431 |
win.setCentralWidget(&view); |
|
2432 |
const int size = view.header()->sectionSize(0); |
|
2433 |
view.setSortingEnabled(true); |
|
2434 |
model.setColumnCount(3); |
|
2435 |
//we test that changing the column count doesn't change the 1st column size |
|
2436 |
QCOMPARE(view.header()->sectionSize(0), size); |
|
2437 |
} |
|
2438 |
} |
|
2439 |
||
2440 |
void tst_QTreeView::headerHidden() |
|
2441 |
{ |
|
2442 |
QTreeView view; |
|
2443 |
QStandardItemModel model; |
|
2444 |
view.setModel(&model); |
|
2445 |
QCOMPARE(view.isHeaderHidden(), false); |
|
2446 |
QCOMPARE(view.header()->isHidden(), false); |
|
2447 |
view.setHeaderHidden(true); |
|
2448 |
QCOMPARE(view.isHeaderHidden(), true); |
|
2449 |
QCOMPARE(view.header()->isHidden(), true); |
|
2450 |
} |
|
2451 |
||
2452 |
// From Task 145199 (crash when column 0 having at least one expanded item is removed and then |
|
2453 |
// inserted). The test passes simply if it doesn't crash, hence there are no calls |
|
2454 |
// to QCOMPARE() or QVERIFY(). |
|
2455 |
void tst_QTreeView::removeAndInsertExpandedCol0() |
|
2456 |
{ |
|
2457 |
QTreeView view; |
|
2458 |
QStandardItemModel model; |
|
2459 |
view.setModel(&model); |
|
2460 |
||
2461 |
model.setColumnCount(1); |
|
2462 |
||
2463 |
QStandardItem *item0 = new QStandardItem(QString("item 0")); |
|
2464 |
model.invisibleRootItem()->appendRow(item0); |
|
2465 |
view.expand(item0->index()); |
|
2466 |
QStandardItem *item1 = new QStandardItem(QString("item 1")); |
|
2467 |
item0->appendRow(item1); |
|
2468 |
||
2469 |
model.removeColumns(0, 1); |
|
2470 |
model.insertColumns(0, 1); |
|
2471 |
||
2472 |
view.show(); |
|
2473 |
qApp->processEvents(); |
|
2474 |
} |
|
2475 |
||
2476 |
void tst_QTreeView::disabledButCheckable() |
|
2477 |
{ |
|
2478 |
QTreeView view; |
|
2479 |
QStandardItemModel model; |
|
2480 |
QStandardItem *item; |
|
2481 |
item = new QStandardItem(QLatin1String("Row 1 Item")); |
|
2482 |
model.insertRow(0, item); |
|
2483 |
||
2484 |
item = new QStandardItem(QLatin1String("Row 2 Item")); |
|
2485 |
item->setCheckable(true); |
|
2486 |
item->setEnabled(false); |
|
2487 |
model.insertRow(1, item); |
|
2488 |
||
2489 |
view.setModel(&model); |
|
2490 |
view.setCurrentIndex(model.index(1,0)); |
|
2491 |
QCOMPARE(item->checkState(), Qt::Unchecked); |
|
2492 |
view.show(); |
|
2493 |
||
2494 |
QTest::keyClick(&view, Qt::Key_Space); |
|
2495 |
QCOMPARE(item->checkState(), Qt::Unchecked); |
|
2496 |
} |
|
2497 |
||
2498 |
void tst_QTreeView::sortByColumn_data() |
|
2499 |
{ |
|
2500 |
QTest::addColumn<bool>("sortingEnabled"); |
|
2501 |
QTest::newRow("sorting enabled") << true; |
|
2502 |
QTest::newRow("sorting disabled") << false; |
|
2503 |
} |
|
2504 |
||
2505 |
// Checks sorting and that sortByColumn also sets the sortIndicator |
|
2506 |
void tst_QTreeView::sortByColumn() |
|
2507 |
{ |
|
2508 |
QFETCH(bool, sortingEnabled); |
|
2509 |
QTreeView view; |
|
2510 |
QStandardItemModel model(4,2); |
|
2511 |
model.setItem(0,0,new QStandardItem("b")); |
|
2512 |
model.setItem(1,0,new QStandardItem("d")); |
|
2513 |
model.setItem(2,0,new QStandardItem("c")); |
|
2514 |
model.setItem(3,0,new QStandardItem("a")); |
|
2515 |
model.setItem(0,1,new QStandardItem("e")); |
|
2516 |
model.setItem(1,1,new QStandardItem("g")); |
|
2517 |
model.setItem(2,1,new QStandardItem("h")); |
|
2518 |
model.setItem(3,1,new QStandardItem("f")); |
|
2519 |
||
2520 |
view.setSortingEnabled(sortingEnabled); |
|
2521 |
view.setModel(&model); |
|
2522 |
view.sortByColumn(1); |
|
2523 |
QCOMPARE(view.header()->sortIndicatorSection(), 1); |
|
2524 |
QCOMPARE(view.model()->data(view.model()->index(0,1)).toString(), QString::fromLatin1("h")); |
|
2525 |
QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g")); |
|
2526 |
view.sortByColumn(0, Qt::AscendingOrder); |
|
2527 |
QCOMPARE(view.header()->sortIndicatorSection(), 0); |
|
2528 |
QCOMPARE(view.model()->data(view.model()->index(0,0)).toString(), QString::fromLatin1("a")); |
|
2529 |
QCOMPARE(view.model()->data(view.model()->index(1,0)).toString(), QString::fromLatin1("b")); |
|
2530 |
} |
|
2531 |
||
2532 |
/* |
|
2533 |
This is a model that every time kill() is called it will completely change |
|
2534 |
all of its nodes for new nodes. It then asserts if you later use a dead node. |
|
2535 |
*/ |
|
2536 |
class EvilModel: public QAbstractItemModel |
|
2537 |
{ |
|
2538 |
||
2539 |
public: |
|
2540 |
class Node { |
|
2541 |
public: |
|
2542 |
Node(Node *p = 0, int level = 0) : parent(p), isDead(false) { |
|
2543 |
populate(level); |
|
2544 |
} |
|
2545 |
~Node() |
|
2546 |
{ |
|
2547 |
qDeleteAll(children.begin(), children.end()); |
|
2548 |
qDeleteAll(deadChildren.begin(), deadChildren.end()); |
|
2549 |
} |
|
2550 |
||
2551 |
void populate(int level = 0) { |
|
2552 |
if (level < 4) |
|
2553 |
for (int i = 0; i < 5; ++i) |
|
2554 |
children.append(new Node(this, level + 1)); |
|
2555 |
} |
|
2556 |
void kill() { |
|
2557 |
for (int i = children.count() -1; i >= 0; --i) { |
|
2558 |
children.at(i)->kill(); |
|
2559 |
if (parent == 0) { |
|
2560 |
deadChildren.append(children.at(i)); |
|
2561 |
children.removeAt(i); |
|
2562 |
} |
|
2563 |
} |
|
2564 |
if (parent == 0) { |
|
2565 |
Q_ASSERT(children.isEmpty()); |
|
2566 |
populate(); |
|
2567 |
} else { |
|
2568 |
isDead = true; |
|
2569 |
} |
|
2570 |
} |
|
2571 |
||
2572 |
QList<Node*> children; |
|
2573 |
QList<Node*> deadChildren; |
|
2574 |
Node *parent; |
|
2575 |
bool isDead; |
|
2576 |
}; |
|
2577 |
||
2578 |
Node *root; |
|
2579 |
||
2580 |
EvilModel(QObject *parent = 0): QAbstractItemModel(parent), root(new Node) |
|
2581 |
{ |
|
2582 |
} |
|
2583 |
~EvilModel() |
|
2584 |
{ |
|
2585 |
delete root; |
|
2586 |
} |
|
2587 |
||
2588 |
void change() |
|
2589 |
{ |
|
2590 |
emit layoutAboutToBeChanged(); |
|
2591 |
QModelIndexList oldList = persistentIndexList(); |
|
2592 |
QList<QStack<int> > oldListPath; |
|
2593 |
for (int i = 0; i < oldList.count(); ++i) { |
|
2594 |
QModelIndex idx = oldList.at(i); |
|
2595 |
QStack<int> path; |
|
2596 |
while (idx.isValid()) { |
|
2597 |
path.push(idx.row()); |
|
2598 |
idx = idx.parent(); |
|
2599 |
} |
|
2600 |
oldListPath.append(path); |
|
2601 |
} |
|
2602 |
root->kill(); |
|
2603 |
||
2604 |
QModelIndexList newList; |
|
2605 |
for (int i = 0; i < oldListPath.count(); ++i) { |
|
2606 |
QStack<int> path = oldListPath[i]; |
|
2607 |
QModelIndex idx; |
|
2608 |
while(!path.isEmpty()) { |
|
2609 |
idx = index(path.pop(), 0, idx); |
|
2610 |
} |
|
2611 |
newList.append(idx); |
|
2612 |
} |
|
2613 |
||
2614 |
changePersistentIndexList(oldList, newList); |
|
2615 |
emit layoutChanged(); |
|
2616 |
} |
|
2617 |
||
2618 |
int rowCount(const QModelIndex& parent = QModelIndex()) const { |
|
2619 |
Node *parentNode = root; |
|
2620 |
if (parent.isValid()) { |
|
2621 |
parentNode = static_cast<Node*>(parent.internalPointer()); |
|
2622 |
Q_ASSERT(!parentNode->isDead); |
|
2623 |
} |
|
2624 |
return parentNode->children.count(); |
|
2625 |
} |
|
2626 |
int columnCount(const QModelIndex& parent = QModelIndex()) const { |
|
2627 |
if (parent.column() > 0) |
|
2628 |
return 0; |
|
2629 |
return 1; |
|
2630 |
} |
|
2631 |
||
2632 |
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const |
|
2633 |
{ |
|
2634 |
Node *grandparentNode = static_cast<Node*>(parent.internalPointer()); |
|
2635 |
Node *parentNode = root; |
|
2636 |
if (parent.isValid()) { |
|
2637 |
Q_ASSERT(!grandparentNode->isDead); |
|
2638 |
parentNode = grandparentNode->children[parent.row()]; |
|
2639 |
Q_ASSERT(!parentNode->isDead); |
|
2640 |
} |
|
2641 |
return createIndex(row, column, parentNode); |
|
2642 |
} |
|
2643 |
||
2644 |
QModelIndex parent(const QModelIndex &index) const |
|
2645 |
{ |
|
2646 |
Node *parent = static_cast<Node*>(index.internalPointer()); |
|
2647 |
Node *grandparent = parent->parent; |
|
2648 |
if (!grandparent) |
|
2649 |
return QModelIndex(); |
|
2650 |
return createIndex(grandparent->children.indexOf(parent), 0, grandparent); |
|
2651 |
} |
|
2652 |
||
2653 |
QVariant data(const QModelIndex &idx, int role) const |
|
2654 |
{ |
|
2655 |
if (idx.isValid() && role == Qt::DisplayRole) { |
|
2656 |
Node *parentNode = root; |
|
2657 |
if (idx.isValid()) { |
|
2658 |
parentNode = static_cast<Node*>(idx.internalPointer()); |
|
2659 |
Q_ASSERT(!parentNode->isDead); |
|
2660 |
} |
|
2661 |
return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()) |
|
2662 |
.arg(parentNode->isDead ? "dead" : "alive"); |
|
2663 |
} |
|
2664 |
return QVariant(); |
|
2665 |
} |
|
2666 |
}; |
|
2667 |
||
2668 |
void tst_QTreeView::evilModel_data() |
|
2669 |
{ |
|
2670 |
QTest::addColumn<bool>("visible"); |
|
2671 |
QTest::newRow("visible") << false; |
|
2672 |
} |
|
2673 |
||
2674 |
void tst_QTreeView::evilModel() |
|
2675 |
{ |
|
2676 |
QFETCH(bool, visible); |
|
2677 |
// init |
|
2678 |
PublicView view; |
|
2679 |
EvilModel model; |
|
2680 |
view.setModel(&model); |
|
2681 |
view.setVisible(visible); |
|
2682 |
QPersistentModelIndex firstLevel = model.index(0, 0); |
|
2683 |
QPersistentModelIndex secondLevel = model.index(1, 0, firstLevel); |
|
2684 |
QPersistentModelIndex thirdLevel = model.index(2, 0, secondLevel); |
|
2685 |
view.setExpanded(firstLevel, true); |
|
2686 |
view.setExpanded(secondLevel, true); |
|
2687 |
view.setExpanded(thirdLevel, true); |
|
2688 |
model.change(); |
|
2689 |
||
2690 |
// tests |
|
2691 |
view.setRowHidden(0, firstLevel, true); |
|
2692 |
model.change(); |
|
2693 |
||
2694 |
return; |
|
2695 |
view.setFirstColumnSpanned(1, QModelIndex(), true); |
|
2696 |
model.change(); |
|
2697 |
||
2698 |
view.expand(secondLevel); |
|
2699 |
model.change(); |
|
2700 |
||
2701 |
view.collapse(secondLevel); |
|
2702 |
model.change(); |
|
2703 |
||
2704 |
view.isExpanded(secondLevel); |
|
2705 |
view.setCurrentIndex(firstLevel); |
|
2706 |
model.change(); |
|
2707 |
||
2708 |
view.keyboardSearch("foo"); |
|
2709 |
model.change(); |
|
2710 |
||
2711 |
view.visualRect(secondLevel); |
|
2712 |
model.change(); |
|
2713 |
||
2714 |
view.scrollTo(thirdLevel); |
|
2715 |
model.change(); |
|
2716 |
||
2717 |
view.repaint(); |
|
2718 |
model.change(); |
|
2719 |
||
2720 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton); |
|
2721 |
model.change(); |
|
2722 |
||
2723 |
view.indexAt(QPoint(10, 10)); |
|
2724 |
model.change(); |
|
2725 |
||
2726 |
view.indexAbove(model.index(2, 0)); |
|
2727 |
model.change(); |
|
2728 |
||
2729 |
view.indexBelow(model.index(1, 0)); |
|
2730 |
model.change(); |
|
2731 |
||
2732 |
QRect rect(0, 0, 10, 10); |
|
2733 |
view.setSelection(rect, QItemSelectionModel::Select); |
|
2734 |
model.change(); |
|
2735 |
||
2736 |
view.moveCursor(PublicView::MoveDown, Qt::NoModifier); |
|
2737 |
model.change(); |
|
2738 |
||
2739 |
view.resizeColumnToContents(1); |
|
2740 |
model.change(); |
|
2741 |
||
2742 |
view.QAbstractItemView::sizeHintForColumn(1); |
|
2743 |
model.change(); |
|
2744 |
||
2745 |
view.rowHeight(secondLevel); |
|
2746 |
model.change(); |
|
2747 |
||
2748 |
view.setRootIsDecorated(true); |
|
2749 |
model.change(); |
|
2750 |
||
2751 |
view.setItemsExpandable(false); |
|
2752 |
model.change(); |
|
2753 |
||
2754 |
view.columnViewportPosition(0); |
|
2755 |
model.change(); |
|
2756 |
||
2757 |
view.columnWidth(0); |
|
2758 |
model.change(); |
|
2759 |
||
2760 |
view.setColumnWidth(0, 30); |
|
2761 |
model.change(); |
|
2762 |
||
2763 |
view.columnAt(15); |
|
2764 |
model.change(); |
|
2765 |
||
2766 |
view.isColumnHidden(1); |
|
2767 |
model.change(); |
|
2768 |
||
2769 |
view.setColumnHidden(2, true); |
|
2770 |
model.change(); |
|
2771 |
||
2772 |
view.isHeaderHidden(); |
|
2773 |
model.change(); |
|
2774 |
||
2775 |
view.setHeaderHidden(true); |
|
2776 |
model.change(); |
|
2777 |
||
2778 |
view.isRowHidden(2, secondLevel); |
|
2779 |
model.change(); |
|
2780 |
||
2781 |
view.setRowHidden(3, secondLevel, true); |
|
2782 |
model.change(); |
|
2783 |
||
2784 |
view.isFirstColumnSpanned(3, thirdLevel); |
|
2785 |
model.change(); |
|
2786 |
||
2787 |
view.setSortingEnabled(true); |
|
2788 |
model.change(); |
|
2789 |
||
2790 |
view.isSortingEnabled(); |
|
2791 |
model.change(); |
|
2792 |
||
2793 |
view.setAnimated(true); |
|
2794 |
model.change(); |
|
2795 |
||
2796 |
view.isAnimated(); |
|
2797 |
model.change(); |
|
2798 |
||
2799 |
view.setAllColumnsShowFocus(true); |
|
2800 |
model.change(); |
|
2801 |
||
2802 |
view.allColumnsShowFocus(); |
|
2803 |
model.change(); |
|
2804 |
||
2805 |
view.doItemsLayout(); |
|
2806 |
model.change(); |
|
2807 |
||
2808 |
view.reset(); |
|
2809 |
model.change(); |
|
2810 |
||
2811 |
view.sortByColumn(1, Qt::AscendingOrder); |
|
2812 |
model.change(); |
|
2813 |
||
2814 |
view.dataChanged(secondLevel, secondLevel); |
|
2815 |
model.change(); |
|
2816 |
||
2817 |
view.hideColumn(1); |
|
2818 |
model.change(); |
|
2819 |
||
2820 |
view.showColumn(1); |
|
2821 |
model.change(); |
|
2822 |
||
2823 |
view.resizeColumnToContents(1); |
|
2824 |
model.change(); |
|
2825 |
||
2826 |
view.sortByColumn(1); |
|
2827 |
model.change(); |
|
2828 |
||
2829 |
view.selectAll(); |
|
2830 |
model.change(); |
|
2831 |
||
2832 |
view.expandAll(); |
|
2833 |
model.change(); |
|
2834 |
||
2835 |
view.collapseAll(); |
|
2836 |
model.change(); |
|
2837 |
||
2838 |
view.expandToDepth(3); |
|
2839 |
model.change(); |
|
2840 |
||
2841 |
view.setRootIndex(secondLevel); |
|
2842 |
} |
|
2843 |
||
2844 |
void tst_QTreeView::indexRowSizeHint() |
|
2845 |
{ |
|
2846 |
QStandardItemModel model(10, 1); |
|
2847 |
PublicView view; |
|
2848 |
||
2849 |
view.setModel(&model); |
|
2850 |
||
2851 |
QModelIndex index = model.index(5, 0); |
|
2852 |
QPushButton *w = new QPushButton("Test"); |
|
2853 |
view.setIndexWidget(index, w); |
|
2854 |
||
2855 |
view.show(); |
|
2856 |
||
2857 |
QCOMPARE(view.indexRowSizeHint(index), w->sizeHint().height()); |
|
2858 |
} |
|
2859 |
||
2860 |
void tst_QTreeView::filterProxyModelCrash() |
|
2861 |
{ |
|
2862 |
QStandardItemModel model; |
|
2863 |
QList<QStandardItem *> items; |
|
2864 |
for (int i = 0; i < 100; i++) |
|
2865 |
items << new QStandardItem(QString::fromLatin1("item %1").arg(i)); |
|
2866 |
model.appendColumn(items); |
|
2867 |
||
2868 |
QSortFilterProxyModel proxy; |
|
2869 |
proxy.setSourceModel(&model); |
|
2870 |
||
2871 |
QTreeView view; |
|
2872 |
view.setModel(&proxy); |
|
2873 |
view.show(); |
|
2874 |
QTest::qWait(30); |
|
2875 |
proxy.invalidate(); |
|
2876 |
view.verticalScrollBar()->setValue(15); |
|
2877 |
QTest::qWait(20); |
|
2878 |
||
2879 |
proxy.invalidate(); |
|
2880 |
view.repaint(); //used to crash |
|
2881 |
} |
|
2882 |
||
2883 |
void tst_QTreeView::styleOptionViewItem() |
|
2884 |
{ |
|
2885 |
class MyDelegate : public QStyledItemDelegate |
|
2886 |
{ |
|
2887 |
public: |
|
2888 |
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const |
|
2889 |
{ |
|
2890 |
QVERIFY(qstyleoption_cast<const QStyleOptionViewItemV4 *>(&option)); |
|
2891 |
QStyleOptionViewItemV4 opt(option); |
|
2892 |
initStyleOption(&opt, index); |
|
2893 |
||
2894 |
QVERIFY(!opt.text.isEmpty()); |
|
2895 |
QCOMPARE(opt.index, index); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2896 |
//qDebug() << index << opt.text; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2897 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2898 |
if (allCollapsed) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2899 |
QCOMPARE(!(opt.features & QStyleOptionViewItemV2::Alternate), !(index.row() % 2)); |
0 | 2900 |
QCOMPARE(!(opt.features & QStyleOptionViewItemV2::HasCheckIndicator), !opt.text.contains("Checkable")); |
2901 |
||
2902 |
if (opt.text.contains("Beginning")) |
|
2903 |
QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::Beginning); |
|
2904 |
||
2905 |
if (opt.text.contains("Middle")) |
|
2906 |
QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::Middle); |
|
2907 |
||
2908 |
if (opt.text.contains("End")) |
|
2909 |
QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::End); |
|
2910 |
||
2911 |
if (opt.text.contains("OnlyOne")) |
|
2912 |
QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::OnlyOne); |
|
2913 |
||
2914 |
if (opt.text.contains("Checked")) |
|
2915 |
QCOMPARE(opt.checkState, Qt::Checked); |
|
2916 |
else |
|
2917 |
QCOMPARE(opt.checkState, Qt::Unchecked); |
|
2918 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2919 |
QCOMPARE(!(opt.state & QStyle::State_Children) , !opt.text.contains("HasChildren")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2920 |
QCOMPARE(!!(opt.state & QStyle::State_Sibling) , !opt.text.contains("Last")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2921 |
|
0 | 2922 |
QVERIFY(!opt.text.contains("Assert")); |
2923 |
||
2924 |
QStyledItemDelegate::paint(painter, option, index); |
|
2925 |
count++; |
|
2926 |
} |
|
2927 |
mutable int count; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2928 |
bool allCollapsed; |
0 | 2929 |
}; |
2930 |
||
2931 |
QTreeView view; |
|
2932 |
QStandardItemModel model; |
|
2933 |
view.setModel(&model); |
|
2934 |
MyDelegate delegate; |
|
2935 |
view.setItemDelegate(&delegate); |
|
2936 |
model.appendRow(QList<QStandardItem*>() |
|
2937 |
<< new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2938 |
QStandardItem *par1 = new QStandardItem("Beginning HasChildren"); |
0 | 2939 |
model.appendRow(QList<QStandardItem*>() |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2940 |
<< par1 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") ); |
0 | 2941 |
model.appendRow(QList<QStandardItem*>() |
2942 |
<< new QStandardItem("OnlyOne") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") ); |
|
2943 |
QStandardItem *checkable = new QStandardItem("Checkable"); |
|
2944 |
checkable->setCheckable(true); |
|
2945 |
QStandardItem *checked = new QStandardItem("Checkable Checked"); |
|
2946 |
checkable->setCheckable(true); |
|
2947 |
checked->setCheckState(Qt::Checked); |
|
2948 |
model.appendRow(QList<QStandardItem*>() |
|
2949 |
<< new QStandardItem("Beginning") << checkable << checked << new QStandardItem("End") ); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2950 |
model.appendRow(QList<QStandardItem*>() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2951 |
<< new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2952 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2953 |
par1->appendRow(QList<QStandardItem*>() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2954 |
<< new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2955 |
QStandardItem *par2 = new QStandardItem("Beginning HasChildren"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2956 |
par1->appendRow(QList<QStandardItem*>() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2957 |
<< par2 << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2958 |
par2->appendRow(QList<QStandardItem*>() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2959 |
<< new QStandardItem("Beginning Last") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2960 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2961 |
QStandardItem *par3 = new QStandardItem("Beginning Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2962 |
par1->appendRow(QList<QStandardItem*>() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2963 |
<< par3 << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2964 |
par3->appendRow(QList<QStandardItem*>() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2965 |
<< new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2966 |
view.setRowHidden(0, par3->index(), true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2967 |
par1->appendRow(QList<QStandardItem*>() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2968 |
<< new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2969 |
view.setRowHidden(3, par1->index(), true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2970 |
|
0 | 2971 |
|
2972 |
view.setFirstColumnSpanned(2, QModelIndex(), true); |
|
2973 |
view.setAlternatingRowColors(true); |
|
2974 |
||
2975 |
delegate.count = 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2976 |
delegate.allCollapsed = true; |
0 | 2977 |
view.showMaximized(); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2978 |
QApplication::processEvents(); |
0 | 2979 |
QTRY_VERIFY(delegate.count >= 13); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2980 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2981 |
delegate.allCollapsed = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2982 |
view.expandAll(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2983 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2984 |
QTRY_VERIFY(delegate.count >= 13); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2985 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2986 |
view.collapse(par2->index()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2987 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2988 |
QTRY_VERIFY(delegate.count >= 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2989 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2990 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2991 |
//test dynamic models |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2992 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2993 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2994 |
QStandardItemModel model2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2995 |
QStandardItem *item0 = new QStandardItem("OnlyOne Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2996 |
model2.appendRow(QList<QStandardItem*>() << item0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2997 |
view.setModel(&model2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2998 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2999 |
QTRY_VERIFY(delegate.count >= 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3000 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3001 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3002 |
QStandardItem *item00 = new QStandardItem("OnlyOne Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3003 |
item0->appendRow(QList<QStandardItem*>() << item00); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3004 |
item0->setText("OnlyOne Last HasChildren"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3005 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3006 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3007 |
view.expandAll(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3008 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3009 |
QTRY_VERIFY(delegate.count >= 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3010 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3011 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3012 |
QStandardItem *item1 = new QStandardItem("OnlyOne Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3013 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3014 |
item0->setText("OnlyOne HasChildren"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3015 |
model2.appendRow(QList<QStandardItem*>() << item1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3016 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3017 |
QTRY_VERIFY(delegate.count >= 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3018 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3019 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3020 |
QStandardItem *item01 = new QStandardItem("OnlyOne Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3021 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3022 |
item00->setText("OnlyOne"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3023 |
item0->appendRow(QList<QStandardItem*>() << item01); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3024 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3025 |
QTRY_VERIFY(delegate.count >= 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3026 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3027 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3028 |
QStandardItem *item000 = new QStandardItem("OnlyOne Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3029 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3030 |
item00->setText("OnlyOne HasChildren"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3031 |
item00->appendRow(QList<QStandardItem*>() << item000); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3032 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3033 |
QTRY_VERIFY(delegate.count >= 5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3034 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3035 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3036 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3037 |
item0->removeRow(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3038 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3039 |
QTRY_VERIFY(delegate.count >= 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3040 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3041 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3042 |
item00 = new QStandardItem("OnlyOne"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3043 |
item0->insertRow(0, QList<QStandardItem*>() << item00); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3044 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3045 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3046 |
view.expandAll(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3047 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3048 |
QTRY_VERIFY(delegate.count >= 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3049 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3050 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3051 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3052 |
item0->removeRow(1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3053 |
item00->setText("OnlyOne Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3054 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3055 |
QTRY_VERIFY(delegate.count >= 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3056 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3057 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3058 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3059 |
item0->removeRow(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3060 |
item0->setText("OnlyOne"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3061 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3062 |
QTRY_VERIFY(delegate.count >= 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3063 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3064 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3065 |
//with hidden items |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3066 |
item0->setText("OnlyOne HasChildren"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3067 |
item00 = new QStandardItem("OnlyOne"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3068 |
item0->appendRow(QList<QStandardItem*>() << item00); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3069 |
item01 = new QStandardItem("Assert"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3070 |
item0->appendRow(QList<QStandardItem*>() << item01); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3071 |
view.setRowHidden(1, item0->index(), true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3072 |
view.expandAll(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3073 |
QStandardItem *item02 = new QStandardItem("OnlyOne Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3074 |
item0->appendRow(QList<QStandardItem*>() << item02); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3075 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3076 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3077 |
QTRY_VERIFY(delegate.count >= 4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3078 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3079 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3080 |
item0->removeRow(2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3081 |
item00->setText("OnlyOne Last"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3082 |
delegate.count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3083 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3084 |
QTRY_VERIFY(delegate.count >= 3); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3085 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3086 |
} |
0 | 3087 |
} |
3088 |
||
3089 |
class task174627_TreeView : public QTreeView |
|
3090 |
{ |
|
3091 |
Q_OBJECT |
|
3092 |
protected slots: |
|
3093 |
void currentChanged(const QModelIndex ¤t, const QModelIndex &) |
|
3094 |
{ emit currentChanged(current); } |
|
3095 |
signals: |
|
3096 |
void currentChanged(const QModelIndex &); |
|
3097 |
}; |
|
3098 |
||
3099 |
void tst_QTreeView::task174627_moveLeftToRoot() |
|
3100 |
{ |
|
3101 |
QStandardItemModel model; |
|
3102 |
QStandardItem *item1 = new QStandardItem(QString("item 1")); |
|
3103 |
model.invisibleRootItem()->appendRow(item1); |
|
3104 |
QStandardItem *item2 = new QStandardItem(QString("item 2")); |
|
3105 |
item1->appendRow(item2); |
|
3106 |
||
3107 |
task174627_TreeView view; |
|
3108 |
view.setModel(&model); |
|
3109 |
view.setRootIndex(item1->index()); |
|
3110 |
view.setCurrentIndex(item2->index()); |
|
3111 |
||
3112 |
QSignalSpy spy(&view, SIGNAL(currentChanged(QModelIndex))); |
|
3113 |
QTest::keyClick(&view, Qt::Key_Left); |
|
3114 |
QCOMPARE(spy.count(), 0); |
|
3115 |
} |
|
3116 |
||
3117 |
void tst_QTreeView::task171902_expandWith1stColHidden() |
|
3118 |
{ |
|
3119 |
//the task was: if the first column of a treeview is hidden, the expanded state is not correctly restored |
|
3120 |
QStandardItemModel model; |
|
3121 |
QStandardItem root("root"), root2("root"), |
|
3122 |
subitem("subitem"), subitem2("subitem"), |
|
3123 |
subsubitem("subsubitem"), subsubitem2("subsubitem"); |
|
3124 |
||
3125 |
model.appendRow( QList<QStandardItem *>() << &root << &root2); |
|
3126 |
root.appendRow( QList<QStandardItem *>() << &subitem << &subitem2); |
|
3127 |
subitem.appendRow( QList<QStandardItem *>() << &subsubitem << &subsubitem2); |
|
3128 |
||
3129 |
QTreeView view; |
|
3130 |
view.setModel(&model); |
|
3131 |
||
3132 |
view.setColumnHidden(0, true); |
|
3133 |
view.expandAll(); |
|
3134 |
view.collapse(root.index()); |
|
3135 |
view.expand(root.index()); |
|
3136 |
||
3137 |
QCOMPARE(view.isExpanded(root.index()), true); |
|
3138 |
QCOMPARE(view.isExpanded(subitem.index()), true); |
|
3139 |
||
3140 |
} |
|
3141 |
||
3142 |
void tst_QTreeView::task203696_hidingColumnsAndRowsn() |
|
3143 |
{ |
|
3144 |
QTreeView view; |
|
3145 |
QStandardItemModel *model = new QStandardItemModel(0, 3, &view); |
|
3146 |
for (int i = 0; i < 3; ++i) |
|
3147 |
{ |
|
3148 |
model->insertRow(model->rowCount()); |
|
3149 |
for (int j = 0; j < model->columnCount(); ++j) |
|
3150 |
model->setData(model->index(i, j), QString("row %1 col %2").arg(i).arg(j)); |
|
3151 |
} |
|
3152 |
view.setModel(model); |
|
3153 |
view.show(); |
|
3154 |
view.setColumnHidden(0, true); |
|
3155 |
view.setRowHidden(0, QModelIndex(), true); |
|
3156 |
QCOMPARE(view.indexAt(QPoint(0, 0)), model->index(1, 1)); |
|
3157 |
} |
|
3158 |
||
3159 |
||
3160 |
void tst_QTreeView::addRowsWhileSectionsAreHidden() |
|
3161 |
{ |
|
3162 |
QTreeView view; |
|
3163 |
for (int pass = 1; pass <= 2; ++pass) { |
|
3164 |
QStandardItemModel *model = new QStandardItemModel(6, pass, &view); |
|
3165 |
view.setModel(model); |
|
3166 |
view.show(); |
|
3167 |
||
3168 |
int i; |
|
3169 |
for (i = 0; i < 3; ++i) |
|
3170 |
{ |
|
3171 |
model->insertRow(model->rowCount()); |
|
3172 |
for (int j = 0; j < model->columnCount(); ++j) { |
|
3173 |
model->setData(model->index(i, j), QString("row %1 col %2").arg(i).arg(j)); |
|
3174 |
} |
|
3175 |
} |
|
3176 |
int col; |
|
3177 |
for (col = 0; col < pass; ++col) |
|
3178 |
view.setColumnHidden(col, true); |
|
3179 |
for (i = 3; i < 6; ++i) |
|
3180 |
{ |
|
3181 |
model->insertRow(model->rowCount()); |
|
3182 |
for (int j = 0; j < model->columnCount(); ++j) { |
|
3183 |
model->setData(model->index(i, j), QString("row %1 col %2").arg(i).arg(j)); |
|
3184 |
} |
|
3185 |
} |
|
3186 |
for (col = 0; col < pass; ++col) |
|
3187 |
view.setColumnHidden(col, false); |
|
3188 |
QTest::qWait(250); |
|
3189 |
||
3190 |
for (i = 0; i < 6; ++i) { |
|
3191 |
QRect rect = view.visualRect(model->index(i, 0)); |
|
3192 |
QCOMPARE(rect.isValid(), true); |
|
3193 |
} |
|
3194 |
||
3195 |
delete model; |
|
3196 |
} |
|
3197 |
} |
|
3198 |
||
3199 |
void tst_QTreeView::task216717_updateChildren() |
|
3200 |
{ |
|
3201 |
class Tree : public QTreeWidget { |
|
3202 |
protected: |
|
3203 |
void paintEvent(QPaintEvent *e) |
|
3204 |
{ |
|
3205 |
QTreeWidget::paintEvent(e); |
|
3206 |
refreshed=true; |
|
3207 |
} |
|
3208 |
public: |
|
3209 |
bool refreshed; |
|
3210 |
} tree; |
|
3211 |
tree.show(); |
|
3212 |
QTest::qWaitForWindowShown(&tree); |
|
3213 |
tree.refreshed = false; |
|
3214 |
QTreeWidgetItem *parent = new QTreeWidgetItem(QStringList() << "parent"); |
|
3215 |
tree.addTopLevelItem(parent); |
|
3216 |
QTest::qWait(10); |
|
3217 |
QTRY_VERIFY(tree.refreshed); |
|
3218 |
tree.refreshed = false; |
|
3219 |
parent->addChild(new QTreeWidgetItem(QStringList() << "child")); |
|
3220 |
QTest::qWait(10); |
|
3221 |
QTRY_VERIFY(tree.refreshed); |
|
3222 |
||
3223 |
} |
|
3224 |
||
3225 |
void tst_QTreeView::task220298_selectColumns() |
|
3226 |
{ |
|
3227 |
//this is a very simple 3x3 model where the internalId of the index are different for each cell |
|
3228 |
class Model : public QAbstractTableModel |
|
3229 |
{ public: |
|
3230 |
virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const |
|
3231 |
{ return parent.isValid() ? 0 : 3; } |
|
3232 |
virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const |
|
3233 |
{ return parent.isValid() ? 0 : 3; } |
|
3234 |
||
3235 |
virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const |
|
3236 |
{ |
|
3237 |
if(role == Qt::DisplayRole) |
|
3238 |
return QVariant(QString("%1-%2").arg(index.column()).arg(index.row())); |
|
3239 |
return QVariant(); |
|
3240 |
} |
|
3241 |
||
3242 |
virtual QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const |
|
3243 |
{ |
|
3244 |
return hasIndex(row, column, parent) ? createIndex(row, column, column*10+row) : QModelIndex(); |
|
3245 |
} |
|
3246 |
}; |
|
3247 |
||
3248 |
class TreeView : public QTreeView { public: QModelIndexList selectedIndexes () const { return QTreeView::selectedIndexes(); } } view; |
|
3249 |
Model model; |
|
3250 |
view.setModel(&model); |
|
3251 |
view.show(); |
|
3252 |
QTest::qWait(50); |
|
3253 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, |
|
3254 |
view.visualRect(view.model()->index(1, 1)).center()); |
|
3255 |
QTest::qWait(50); |
|
3256 |
QVERIFY(view.selectedIndexes().contains(view.model()->index(1, 2))); |
|
3257 |
QVERIFY(view.selectedIndexes().contains(view.model()->index(1, 1))); |
|
3258 |
QVERIFY(view.selectedIndexes().contains(view.model()->index(1, 0))); |
|
3259 |
} |
|
3260 |
||
3261 |
||
3262 |
void tst_QTreeView::task224091_appendColumns() |
|
3263 |
{ |
|
3264 |
QStandardItemModel *model = new QStandardItemModel(); |
|
3265 |
QTreeView *treeView = new QTreeView(); |
|
3266 |
treeView->setModel(model); |
|
3267 |
treeView->show(); |
|
3268 |
treeView->resize(50,50); |
|
3269 |
||
3270 |
QTest::qWaitForWindowShown(treeView); |
|
3271 |
qApp->processEvents(); |
|
3272 |
||
3273 |
QList<QStandardItem *> projlist; |
|
3274 |
for (int k = 0; k < 10; ++k) |
|
3275 |
projlist.append(new QStandardItem(QString("Top Level %0").arg(k))); |
|
3276 |
model->appendColumn(projlist); |
|
3277 |
model->invisibleRootItem()->appendRow(new QStandardItem("end")); |
|
3278 |
||
3279 |
QTest::qWait(50); |
|
3280 |
qApp->processEvents(); |
|
3281 |
||
3282 |
QTRY_VERIFY(treeView->verticalScrollBar()->isVisible()); |
|
3283 |
||
3284 |
delete treeView; |
|
3285 |
delete model; |
|
3286 |
} |
|
3287 |
||
3288 |
void tst_QTreeView::task211293_removeRootIndex() |
|
3289 |
{ |
|
3290 |
QTreeView view; |
|
3291 |
QStandardItemModel model; |
|
3292 |
QStandardItem *A1 = new QStandardItem("A1"); |
|
3293 |
QStandardItem *B11 = new QStandardItem("B1.1"); |
|
3294 |
QStandardItem *C111 = new QStandardItem("C1.1.1"); |
|
3295 |
QStandardItem *C112 = new QStandardItem("C1.1.2"); |
|
3296 |
QStandardItem *C113 = new QStandardItem("C1.1.3"); |
|
3297 |
QStandardItem *D1131 = new QStandardItem("D1.1.3.1"); |
|
3298 |
QStandardItem *E11311 = new QStandardItem("E1.1.3.1.1"); |
|
3299 |
QStandardItem *E11312 = new QStandardItem("E1.1.3.1.2"); |
|
3300 |
QStandardItem *E11313 = new QStandardItem("E1.1.3.1.3"); |
|
3301 |
QStandardItem *E11314 = new QStandardItem("E1.1.3.1.4"); |
|
3302 |
QStandardItem *D1132 = new QStandardItem("D1.1.3.2"); |
|
3303 |
QStandardItem *E11321 = new QStandardItem("E1.1.3.2.1"); |
|
3304 |
D1132->appendRow(E11321); |
|
3305 |
D1131->appendRow(E11311); |
|
3306 |
D1131->appendRow(E11312); |
|
3307 |
D1131->appendRow(E11313); |
|
3308 |
D1131->appendRow(E11314); |
|
3309 |
C113->appendRow(D1131); |
|
3310 |
C113->appendRow(D1132); |
|
3311 |
B11->appendRow(C111); |
|
3312 |
B11->appendRow(C112); |
|
3313 |
B11->appendRow(C113); |
|
3314 |
A1->appendRow(B11); |
|
3315 |
model.appendRow(A1); |
|
3316 |
view.setModel(&model); |
|
3317 |
view.setRootIndex(model.indexFromItem(B11)); |
|
3318 |
view.setExpanded(model.indexFromItem(B11), true); |
|
3319 |
view.setCurrentIndex(model.indexFromItem(E11314)); |
|
3320 |
view.setExpanded(model.indexFromItem(E11314), true); |
|
3321 |
view.show(); |
|
3322 |
qApp->processEvents(); |
|
3323 |
model.removeRows(0, 1); |
|
3324 |
qApp->processEvents(); |
|
3325 |
} |
|
3326 |
||
3327 |
void tst_QTreeView::task225539_deleteModel() |
|
3328 |
{ |
|
3329 |
QTreeView treeView; |
|
3330 |
treeView.show(); |
|
3331 |
QStandardItemModel *model = new QStandardItemModel(&treeView); |
|
3332 |
||
3333 |
QStandardItem* parentItem = model->invisibleRootItem(); |
|
3334 |
QStandardItem* item = new QStandardItem(QString("item")); |
|
3335 |
parentItem->appendRow(item); |
|
3336 |
||
3337 |
treeView.setModel(model); |
|
3338 |
||
3339 |
QCOMPARE(item->index(), treeView.indexAt(QPoint())); |
|
3340 |
||
3341 |
delete model; |
|
3342 |
||
3343 |
QVERIFY(!treeView.indexAt(QPoint()).isValid()); |
|
3344 |
} |
|
3345 |
||
3346 |
void tst_QTreeView::task230123_setItemsExpandable() |
|
3347 |
{ |
|
3348 |
//let's check that we prevent the expansion inside a treeview |
|
3349 |
//when the property is set. |
|
3350 |
QTreeWidget tree; |
|
3351 |
||
3352 |
QTreeWidgetItem root; |
|
3353 |
QTreeWidgetItem child; |
|
3354 |
root.addChild(&child); |
|
3355 |
tree.addTopLevelItem(&root); |
|
3356 |
||
3357 |
tree.setCurrentItem(&root); |
|
3358 |
||
3359 |
tree.setItemsExpandable(false); |
|
3360 |
||
3361 |
QTest::keyClick(&tree, Qt::Key_Plus); |
|
3362 |
QVERIFY(!root.isExpanded()); |
|
3363 |
||
3364 |
QTest::keyClick(&tree, Qt::Key_Right); |
|
3365 |
QVERIFY(!root.isExpanded()); |
|
3366 |
||
3367 |
tree.setItemsExpandable(true); |
|
3368 |
||
3369 |
QTest::keyClick(&tree, Qt::Key_Plus); |
|
3370 |
QVERIFY(root.isExpanded()); |
|
3371 |
||
3372 |
QTest::keyClick(&tree, Qt::Key_Minus); |
|
3373 |
QVERIFY(!root.isExpanded()); |
|
3374 |
||
3375 |
QTest::keyClick(&tree, Qt::Key_Right); |
|
3376 |
QVERIFY(root.isExpanded()); |
|
3377 |
||
3378 |
QTest::keyClick(&tree, Qt::Key_Left); |
|
3379 |
QVERIFY(!root.isExpanded()); |
|
3380 |
||
3381 |
QTest::keyClick(&tree, Qt::Key_Right); |
|
3382 |
QVERIFY(root.isExpanded()); |
|
3383 |
||
3384 |
const bool navToChild = tree.style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, &tree); |
|
3385 |
QTest::keyClick(&tree, Qt::Key_Right); |
|
3386 |
QCOMPARE(tree.currentItem(), navToChild ? &child : &root); |
|
3387 |
||
3388 |
QTest::keyClick(&tree, Qt::Key_Right); |
|
3389 |
//it should not be expanded: it has no leaf |
|
3390 |
QCOMPARE(child.isExpanded(), false); |
|
3391 |
||
3392 |
QTest::keyClick(&tree, Qt::Key_Left); |
|
3393 |
QCOMPARE(tree.currentItem(), &root); |
|
3394 |
||
3395 |
QTest::keyClick(&tree, Qt::Key_Left); |
|
3396 |
QVERIFY(!root.isExpanded()); |
|
3397 |
||
3398 |
||
3399 |
} |
|
3400 |
||
3401 |
void tst_QTreeView::task202039_closePersistentEditor() |
|
3402 |
{ |
|
3403 |
QStandardItemModel model(1,1); |
|
3404 |
QTreeView view; |
|
3405 |
view.setModel(&model); |
|
3406 |
||
3407 |
QModelIndex current = model.index(0,0); |
|
3408 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center()); |
|
3409 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center()); |
|
3410 |
QCOMPARE(view.currentIndex(), current); |
|
3411 |
QVERIFY(view.indexWidget(current)); |
|
3412 |
||
3413 |
view.closePersistentEditor(current); |
|
3414 |
QVERIFY(view.indexWidget(current) == 0); |
|
3415 |
||
3416 |
//here was the bug: closing the persistent editor would not reset the state |
|
3417 |
//and it was impossible to go into editinon again |
|
3418 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center()); |
|
3419 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center()); |
|
3420 |
QCOMPARE(view.currentIndex(), current); |
|
3421 |
QVERIFY(view.indexWidget(current)); |
|
3422 |
} |
|
3423 |
||
3424 |
void tst_QTreeView::task238873_avoidAutoReopening() |
|
3425 |
{ |
|
3426 |
QStandardItemModel model; |
|
3427 |
||
3428 |
QStandardItem item0("row 0"); |
|
3429 |
QStandardItem item1("row 1"); |
|
3430 |
QStandardItem item2("row 2"); |
|
3431 |
QStandardItem item3("row 3"); |
|
3432 |
model.appendColumn( QList<QStandardItem*>() << &item0 << &item1 << &item2 << &item3); |
|
3433 |
||
3434 |
QStandardItem child("child"); |
|
3435 |
item1.appendRow( &child); |
|
3436 |
||
3437 |
QTreeView view; |
|
3438 |
view.setModel(&model); |
|
3439 |
view.show(); |
|
3440 |
view.expandAll(); |
|
3441 |
QTest::qWait(100); |
|
3442 |
||
3443 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(child.index()).center()); |
|
3444 |
QTest::qWait(20); |
|
3445 |
QCOMPARE(view.currentIndex(), child.index()); |
|
3446 |
||
3447 |
view.setExpanded(item1.index(), false); |
|
3448 |
||
3449 |
QTest::qWait(500); //enough to trigger the delayedAutoScroll timer |
|
3450 |
QVERIFY(!view.isExpanded(item1.index())); |
|
3451 |
} |
|
3452 |
||
3453 |
void tst_QTreeView::task244304_clickOnDecoration() |
|
3454 |
{ |
|
3455 |
QTreeView view; |
|
3456 |
QStandardItemModel model; |
|
3457 |
QStandardItem item0("row 0"); |
|
3458 |
QStandardItem item00("row 0"); |
|
3459 |
item0.appendRow(&item00); |
|
3460 |
QStandardItem item1("row 1"); |
|
3461 |
model.appendColumn(QList<QStandardItem*>() << &item0 << &item1); |
|
3462 |
view.setModel(&model); |
|
3463 |
||
3464 |
QVERIFY(!view.currentIndex().isValid()); |
|
3465 |
QRect rect = view.visualRect(item0.index()); |
|
3466 |
//we click on the decoration |
|
3467 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, rect.topLeft()+QPoint(-rect.left()/2,rect.height()/2)); |
|
3468 |
QVERIFY(!view.currentIndex().isValid()); |
|
3469 |
QVERIFY(view.isExpanded(item0.index())); |
|
3470 |
||
3471 |
rect = view.visualRect(item1.index()); |
|
3472 |
//the item has no decoration, it should get selected |
|
3473 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, rect.topLeft()+QPoint(-rect.left()/2,rect.height()/2)); |
|
3474 |
QCOMPARE(view.currentIndex(), item1.index()); |
|
3475 |
} |
|
3476 |
||
3477 |
void tst_QTreeView::task246536_scrollbarsNotWorking() |
|
3478 |
{ |
|
3479 |
struct MyObject : public QObject |
|
3480 |
{ |
|
3481 |
MyObject() : count(0) |
|
3482 |
{ |
|
3483 |
} |
|
3484 |
||
3485 |
bool eventFilter(QObject*, QEvent *e) |
|
3486 |
{ |
|
3487 |
if (e->type() == QEvent::Paint) |
|
3488 |
count++; |
|
3489 |
||
3490 |
return false; |
|
3491 |
} |
|
3492 |
||
3493 |
int count; |
|
3494 |
}; |
|
3495 |
QTreeView tree; |
|
3496 |
MyObject o; |
|
3497 |
tree.viewport()->installEventFilter(&o); |
|
3498 |
QStandardItemModel model; |
|
3499 |
tree.setModel(&model); |
|
3500 |
tree.show(); |
|
3501 |
QTest::qWaitForWindowShown(&tree); |
|
3502 |
QList<QStandardItem *> items; |
|
3503 |
for(int i=0; i<100; ++i){ |
|
3504 |
items << new QStandardItem(QString::fromLatin1("item %1").arg(i)); |
|
3505 |
} |
|
3506 |
model.invisibleRootItem()->appendColumn(items); |
|
3507 |
QTest::qWait(100); |
|
3508 |
o.count = 0; |
|
3509 |
tree.verticalScrollBar()->setValue(50); |
|
3510 |
QTest::qWait(100); |
|
3511 |
QTRY_VERIFY(o.count > 0); |
|
3512 |
} |
|
3513 |
||
3514 |
void tst_QTreeView::task250683_wrongSectionSize() |
|
3515 |
{ |
|
3516 |
QDirModel model; |
|
3517 |
QTreeView treeView; |
|
3518 |
treeView.header()->setResizeMode(QHeaderView::ResizeToContents); |
|
3519 |
treeView.setModel(&model); |
|
3520 |
treeView.setColumnHidden(2, true); |
|
3521 |
treeView.setColumnHidden(3, true); |
|
3522 |
||
3523 |
treeView.show(); |
|
3524 |
QTest::qWait(100); |
|
3525 |
||
3526 |
QCOMPARE(treeView.header()->sectionSize(0) + treeView.header()->sectionSize(1), treeView.viewport()->width()); |
|
3527 |
} |
|
3528 |
||
3529 |
void tst_QTreeView::task239271_addRowsWithFirstColumnHidden() |
|
3530 |
{ |
|
3531 |
class MyDelegate : public QStyledItemDelegate |
|
3532 |
{ |
|
3533 |
public: |
|
3534 |
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const |
|
3535 |
{ |
|
3536 |
paintedIndexes << index; |
|
3537 |
QStyledItemDelegate::paint(painter, option, index); |
|
3538 |
} |
|
3539 |
||
3540 |
mutable QSet<QModelIndex> paintedIndexes; |
|
3541 |
}; |
|
3542 |
||
3543 |
QTreeView view; |
|
3544 |
QStandardItemModel model; |
|
3545 |
view.setModel(&model); |
|
3546 |
MyDelegate delegate; |
|
3547 |
view.setItemDelegate(&delegate); |
|
3548 |
QStandardItem root0("root0"), root1("root1"); |
|
3549 |
model.invisibleRootItem()->appendRow(QList<QStandardItem*>() << &root0 << &root1); |
|
3550 |
QStandardItem sub0("sub0"), sub00("sub00"); |
|
3551 |
root0.appendRow(QList<QStandardItem*>() << &sub0 << &sub00); |
|
3552 |
view.expand(root0.index()); |
|
3553 |
||
3554 |
view.hideColumn(0); |
|
3555 |
view.show(); |
|
3556 |
QTest::qWaitForWindowShown(&view); |
|
3557 |
delegate.paintedIndexes.clear(); |
|
3558 |
QStandardItem sub1("sub1"), sub11("sub11"); |
|
3559 |
root0.appendRow(QList<QStandardItem*>() << &sub1 << &sub11); |
|
3560 |
||
3561 |
QTest::qWait(20); |
|
3562 |
//items in the 2nd column should have been painted |
|
3563 |
QTRY_VERIFY(!delegate.paintedIndexes.isEmpty()); |
|
3564 |
QVERIFY(delegate.paintedIndexes.contains(sub00.index())); |
|
3565 |
QVERIFY(delegate.paintedIndexes.contains(sub11.index())); |
|
3566 |
} |
|
3567 |
||
3568 |
void tst_QTreeView::task254234_proxySort() |
|
3569 |
{ |
|
3570 |
//based on tst_QTreeView::sortByColumn |
|
3571 |
// it used not to work when setting the source of a proxy after enabling sorting |
|
3572 |
QTreeView view; |
|
3573 |
QStandardItemModel model(4,2); |
|
3574 |
model.setItem(0,0,new QStandardItem("b")); |
|
3575 |
model.setItem(1,0,new QStandardItem("d")); |
|
3576 |
model.setItem(2,0,new QStandardItem("c")); |
|
3577 |
model.setItem(3,0,new QStandardItem("a")); |
|
3578 |
model.setItem(0,1,new QStandardItem("e")); |
|
3579 |
model.setItem(1,1,new QStandardItem("g")); |
|
3580 |
model.setItem(2,1,new QStandardItem("h")); |
|
3581 |
model.setItem(3,1,new QStandardItem("f")); |
|
3582 |
||
3583 |
view.sortByColumn(1); |
|
3584 |
view.setSortingEnabled(true); |
|
3585 |
||
3586 |
QSortFilterProxyModel proxy; |
|
3587 |
proxy.setDynamicSortFilter(true); |
|
3588 |
view.setModel(&proxy); |
|
3589 |
proxy.setSourceModel(&model); |
|
3590 |
QCOMPARE(view.header()->sortIndicatorSection(), 1); |
|
3591 |
QCOMPARE(view.model()->data(view.model()->index(0,1)).toString(), QString::fromLatin1("h")); |
|
3592 |
QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g")); |
|
3593 |
} |
|
3594 |
||
3595 |
class TreeView : public QTreeView |
|
3596 |
{ |
|
3597 |
Q_OBJECT |
|
3598 |
public slots: |
|
3599 |
void handleSelectionChanged() |
|
3600 |
{ |
|
3601 |
//let's select the last item |
|
3602 |
QModelIndex idx = model()->index(0, 0); |
|
3603 |
selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select); |
|
3604 |
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(handleSelectionChanged())); |
|
3605 |
} |
|
3606 |
}; |
|
3607 |
||
3608 |
void tst_QTreeView::task248022_changeSelection() |
|
3609 |
{ |
|
3610 |
//we check that changing the selection between the mouse press and the mouse release |
|
3611 |
//works correctly |
|
3612 |
TreeView view; |
|
3613 |
QStringList list = QStringList() << "1" << "2"; |
|
3614 |
QStringListModel model(list); |
|
3615 |
view.setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
3616 |
view.setModel(&model); |
|
3617 |
view.connect(view.selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), SLOT(handleSelectionChanged())); |
|
3618 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(1)).center()); |
|
3619 |
QCOMPARE(view.selectionModel()->selectedIndexes().count(), list.count()); |
|
3620 |
} |
|
3621 |
||
3622 |
void tst_QTreeView::task245654_changeModelAndExpandAll() |
|
3623 |
{ |
|
3624 |
QTreeView view; |
|
3625 |
QStandardItemModel *model = new QStandardItemModel; |
|
3626 |
QStandardItem *top = new QStandardItem("top"); |
|
3627 |
QStandardItem *sub = new QStandardItem("sub"); |
|
3628 |
top->appendRow(sub); |
|
3629 |
model->appendRow(top); |
|
3630 |
view.setModel(model); |
|
3631 |
view.expandAll(); |
|
3632 |
QApplication::processEvents(); |
|
3633 |
QVERIFY(view.isExpanded(top->index())); |
|
3634 |
||
3635 |
//now let's try to delete the model |
|
3636 |
//then repopulate and expand again |
|
3637 |
delete model; |
|
3638 |
model = new QStandardItemModel; |
|
3639 |
top = new QStandardItem("top"); |
|
3640 |
sub = new QStandardItem("sub"); |
|
3641 |
top->appendRow(sub); |
|
3642 |
model->appendRow(top); |
|
3643 |
view.setModel(model); |
|
3644 |
view.expandAll(); |
|
3645 |
QApplication::processEvents(); |
|
3646 |
QVERIFY(view.isExpanded(top->index())); |
|
3647 |
||
3648 |
} |
|
3649 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3650 |
void tst_QTreeView::doubleClickedWithSpans() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3651 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3652 |
QTreeView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3653 |
QStandardItemModel model(1, 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3654 |
view.setModel(&model); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3655 |
view.setFirstColumnSpanned(0, QModelIndex(), true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3656 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3657 |
QApplication::setActiveWindow(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3658 |
QTest::qWaitForWindowShown(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3659 |
QTRY_VERIFY(view.isActiveWindow()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3660 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3661 |
QPoint p(10, 10); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3662 |
QCOMPARE(view.indexAt(p), model.index(0, 0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3663 |
QSignalSpy spy(&view, SIGNAL(doubleClicked(QModelIndex))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3664 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3665 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3666 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3667 |
QCOMPARE(spy.count(), 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3668 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3669 |
//let's click on the 2nd column |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3670 |
p.setX(p.x() + view.header()->sectionSize(0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3671 |
QCOMPARE(view.indexAt(p), model.index(0, 0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3672 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3673 |
//end the previous edition |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3674 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3675 |
QTest::qWait(150); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3676 |
QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3677 |
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3678 |
QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3679 |
QTRY_COMPARE(spy.count(), 2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3680 |
} |
0 | 3681 |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3682 |
void tst_QTreeView::taskQTBUG_6450_selectAllWith1stColumnHidden() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3683 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3684 |
QTreeWidget tree; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3685 |
tree.setSelectionMode(QAbstractItemView::MultiSelection); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3686 |
tree.setColumnCount(2); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3687 |
QList<QTreeWidgetItem *> items; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3688 |
const int nrRows = 10; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3689 |
for (int i = 0; i < nrRows; ++i) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3690 |
items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)))); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3691 |
items.last()->setText(1, QString("is an item")); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3692 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3693 |
tree.insertTopLevelItems(0, items); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3694 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3695 |
tree.hideColumn(0); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3696 |
tree.selectAll(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3697 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3698 |
QVERIFY(tree.selectionModel()->hasSelection()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3699 |
for (int i = 0; i < nrRows; ++i) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3700 |
QVERIFY(tree.selectionModel()->isRowSelected(i, QModelIndex())); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3701 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3702 |
|
0 | 3703 |
QTEST_MAIN(tst_QTreeView) |
3704 |
#include "tst_qtreeview.moc" |