author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 5 | d3bac044e0f0 |
child 13 | c0432d11811c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtGui/QtGui> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
44 |
#include <private/qtablewidget_p.h> |
0 | 45 |
#include <QtTest/QtTest> |
46 |
#include "../../shared/util.h" |
|
47 |
#include "private/qapplication_p.h" |
|
48 |
||
49 |
//TESTED_CLASS= |
|
50 |
//TESTED_FILES= |
|
51 |
||
52 |
// Will try to wait for the condition while allowing event processing |
|
53 |
// for a maximum of 2 seconds. |
|
54 |
#define WAIT_FOR_CONDITION(expr, expected) \ |
|
55 |
do { \ |
|
56 |
const int step = 100; \ |
|
57 |
for (int i = 0; i < 2000 && expr != expected; i+=step) { \ |
|
58 |
QTest::qWait(step); \ |
|
59 |
} \ |
|
60 |
} while(0) |
|
61 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
#ifdef QT_BUILD_INTERNAL |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) \ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
QVERIFY(static_cast<QTableViewPrivate*>(QObjectPrivate::get(TEST_VIEW_))->spans.checkConsistency()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) (void)false |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
|
0 | 69 |
typedef QList<int> IntList; |
70 |
Q_DECLARE_METATYPE(IntList) |
|
71 |
||
72 |
typedef QList<bool> BoolList; |
|
73 |
Q_DECLARE_METATYPE(BoolList) |
|
74 |
||
75 |
class tst_QTableView : public QObject |
|
76 |
{ |
|
77 |
Q_OBJECT |
|
78 |
||
79 |
public: |
|
80 |
tst_QTableView(); |
|
81 |
virtual ~tst_QTableView(); |
|
82 |
||
83 |
public slots: |
|
84 |
void initTestCase(); |
|
85 |
void cleanupTestCase(); |
|
86 |
void init(); |
|
87 |
void cleanup(); |
|
88 |
||
89 |
private slots: |
|
90 |
void getSetCheck(); |
|
91 |
||
92 |
void noDelegate(); |
|
93 |
void noModel(); |
|
94 |
void emptyModel(); |
|
95 |
||
96 |
void removeRows_data(); |
|
97 |
void removeRows(); |
|
98 |
||
99 |
void removeColumns_data(); |
|
100 |
void removeColumns(); |
|
101 |
||
102 |
void keyboardNavigation_data(); |
|
103 |
void keyboardNavigation(); |
|
104 |
||
105 |
void headerSections_data(); |
|
106 |
void headerSections(); |
|
107 |
||
108 |
void moveCursor_data(); |
|
109 |
void moveCursor(); |
|
110 |
||
111 |
void moveCursorStrikesBack_data(); |
|
112 |
void moveCursorStrikesBack(); |
|
113 |
||
114 |
void hideRows_data(); |
|
115 |
void hideRows(); |
|
116 |
||
117 |
void hideColumns_data(); |
|
118 |
void hideColumns(); |
|
119 |
||
120 |
void selection_data(); |
|
121 |
void selection(); |
|
122 |
||
123 |
void selectRow_data(); |
|
124 |
void selectRow(); |
|
125 |
||
126 |
void selectColumn_data(); |
|
127 |
void selectColumn(); |
|
128 |
||
129 |
void visualRect_data(); |
|
130 |
void visualRect(); |
|
131 |
||
132 |
void fetchMore(); |
|
133 |
void setHeaders(); |
|
134 |
||
135 |
void resizeRowsToContents_data(); |
|
136 |
void resizeRowsToContents(); |
|
137 |
||
138 |
void resizeColumnsToContents_data(); |
|
139 |
void resizeColumnsToContents(); |
|
140 |
||
141 |
void rowViewportPosition_data(); |
|
142 |
void rowViewportPosition(); |
|
143 |
||
144 |
void rowAt_data(); |
|
145 |
void rowAt(); |
|
146 |
||
147 |
void rowHeight_data(); |
|
148 |
void rowHeight(); |
|
149 |
||
150 |
void columnViewportPosition_data(); |
|
151 |
void columnViewportPosition(); |
|
152 |
||
153 |
void columnAt_data(); |
|
154 |
void columnAt(); |
|
155 |
||
156 |
void columnWidth_data(); |
|
157 |
void columnWidth(); |
|
158 |
||
159 |
void hiddenRow_data(); |
|
160 |
void hiddenRow(); |
|
161 |
||
162 |
void hiddenColumn_data(); |
|
163 |
void hiddenColumn(); |
|
164 |
||
165 |
void sortingEnabled_data(); |
|
166 |
void sortingEnabled(); |
|
167 |
||
168 |
void scrollTo_data(); |
|
169 |
void scrollTo(); |
|
170 |
||
171 |
void indexAt_data(); |
|
172 |
void indexAt(); |
|
173 |
||
174 |
void span_data(); |
|
175 |
void span(); |
|
176 |
void spans(); |
|
177 |
void spans_data(); |
|
178 |
void spansAfterRowInsertion(); |
|
179 |
void spansAfterColumnInsertion(); |
|
180 |
void spansAfterRowRemoval(); |
|
181 |
void spansAfterColumnRemoval(); |
|
182 |
||
183 |
void checkHeaderReset(); |
|
184 |
void checkHeaderMinSize(); |
|
185 |
||
186 |
void resizeToContents(); |
|
187 |
||
188 |
void tabFocus(); |
|
189 |
void bigModel(); |
|
190 |
void selectionSignal(); |
|
191 |
||
192 |
// task-specific tests: |
|
193 |
void task173773_updateVerticalHeader(); |
|
194 |
void task227953_setRootIndex(); |
|
195 |
void task240266_veryBigColumn(); |
|
196 |
void task248688_autoScrollNavigation(); |
|
197 |
void task259308_scrollVerticalHeaderSwappedSections(); |
|
198 |
void task191545_dragSelectRows(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
void taskQTBUG_5062_spansInconsistency(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
void taskQTBUG_4516_clickOnRichTextLabel(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
void taskQTBUG_5237_wheelEventOnHeader(); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
202 |
void taskQTBUG_8585_crashForNoGoodReason(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
203 |
void taskQTBUG_7774_RtoLVisualRegionForSelection(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
204 |
void taskQTBUG_8777_scrollToSpans(); |
0 | 205 |
|
206 |
void mouseWheel_data(); |
|
207 |
void mouseWheel(); |
|
208 |
||
209 |
void addColumnWhileEditing(); |
|
210 |
void task234926_setHeaderSorting(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
void changeHeaderData(); |
0 | 213 |
}; |
214 |
||
215 |
// Testing get/set functions |
|
216 |
void tst_QTableView::getSetCheck() |
|
217 |
{ |
|
218 |
QTableView obj1; |
|
219 |
||
220 |
obj1.setSortingEnabled(false); |
|
221 |
QCOMPARE(false, obj1.isSortingEnabled()); |
|
222 |
obj1.setSortingEnabled(true); |
|
223 |
QCOMPARE(true, obj1.isSortingEnabled()); |
|
224 |
||
225 |
obj1.setShowGrid(false); |
|
226 |
QCOMPARE(false, obj1.showGrid()); |
|
227 |
obj1.setShowGrid(true); |
|
228 |
QCOMPARE(true, obj1.showGrid()); |
|
229 |
||
230 |
obj1.setGridStyle(Qt::NoPen); |
|
231 |
QCOMPARE(Qt::NoPen, obj1.gridStyle()); |
|
232 |
obj1.setGridStyle(Qt::SolidLine); |
|
233 |
QCOMPARE(Qt::SolidLine, obj1.gridStyle()); |
|
234 |
||
235 |
obj1.setRootIndex(QModelIndex()); |
|
236 |
QCOMPARE(QModelIndex(), obj1.rootIndex()); |
|
237 |
QStandardItemModel model(10, 10); |
|
238 |
obj1.setModel(&model); |
|
239 |
QModelIndex index = model.index(0, 0); |
|
240 |
obj1.setRootIndex(index); |
|
241 |
QCOMPARE(index, obj1.rootIndex()); |
|
242 |
||
243 |
QHeaderView *var1 = new QHeaderView(Qt::Horizontal); |
|
244 |
obj1.setHorizontalHeader(var1); |
|
245 |
QCOMPARE(var1, obj1.horizontalHeader()); |
|
246 |
obj1.setHorizontalHeader((QHeaderView *)0); |
|
247 |
QCOMPARE(var1, obj1.horizontalHeader()); |
|
248 |
delete var1; |
|
249 |
||
250 |
QHeaderView *var2 = new QHeaderView(Qt::Vertical); |
|
251 |
obj1.setVerticalHeader(var2); |
|
252 |
QCOMPARE(var2, obj1.verticalHeader()); |
|
253 |
obj1.setVerticalHeader((QHeaderView *)0); |
|
254 |
QCOMPARE(var2, obj1.verticalHeader()); |
|
255 |
delete var2; |
|
256 |
||
257 |
QCOMPARE(obj1.isCornerButtonEnabled(), true); |
|
258 |
obj1.setCornerButtonEnabled(false); |
|
259 |
QCOMPARE(obj1.isCornerButtonEnabled(), false); |
|
260 |
} |
|
261 |
||
262 |
class QtTestTableModel: public QAbstractTableModel |
|
263 |
{ |
|
264 |
Q_OBJECT |
|
265 |
||
266 |
signals: |
|
267 |
void invalidIndexEncountered() const; |
|
268 |
||
269 |
public: |
|
270 |
QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) |
|
271 |
: QAbstractTableModel(parent), |
|
272 |
row_count(rows), |
|
273 |
column_count(columns), |
|
274 |
can_fetch_more(false), |
|
275 |
fetch_more_count(0), |
|
276 |
disabled_rows(), |
|
277 |
disabled_columns() {} |
|
278 |
||
279 |
int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } |
|
280 |
int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } |
|
281 |
bool isEditable(const QModelIndex &) const { return true; } |
|
282 |
||
283 |
Qt::ItemFlags flags(const QModelIndex &index) const |
|
284 |
{ |
|
285 |
Qt::ItemFlags index_flags = QAbstractTableModel::flags(index); |
|
286 |
if (disabled_rows.contains(index.row()) |
|
287 |
|| disabled_columns.contains(index.column())) |
|
288 |
index_flags &= ~Qt::ItemIsEnabled; |
|
289 |
return index_flags; |
|
290 |
} |
|
291 |
||
292 |
void disableRow(int row) |
|
293 |
{ |
|
294 |
disabled_rows.insert(row); |
|
295 |
} |
|
296 |
||
297 |
void enableRow(int row) |
|
298 |
{ |
|
299 |
disabled_rows.remove(row); |
|
300 |
} |
|
301 |
||
302 |
void disableColumn(int column) |
|
303 |
{ |
|
304 |
disabled_columns.insert(column); |
|
305 |
} |
|
306 |
||
307 |
void enableColumn(int column) |
|
308 |
{ |
|
309 |
disabled_columns.remove(column); |
|
310 |
} |
|
311 |
||
312 |
QVariant data(const QModelIndex &idx, int role) const |
|
313 |
{ |
|
314 |
if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { |
|
315 |
qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx; |
|
316 |
emit invalidIndexEncountered(); |
|
317 |
return QVariant(); |
|
318 |
} |
|
319 |
||
320 |
if (role == Qt::DisplayRole || role == Qt::EditRole) |
|
321 |
return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(0); |
|
322 |
||
323 |
return QVariant(); |
|
324 |
} |
|
325 |
||
326 |
bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex()) |
|
327 |
{ |
|
328 |
if (start < 0 || start > row_count) |
|
329 |
return false; |
|
330 |
||
331 |
beginInsertRows(parent, start, start + count - 1); |
|
332 |
row_count += count; |
|
333 |
endInsertRows(); |
|
334 |
return true; |
|
335 |
} |
|
336 |
||
337 |
bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex()) |
|
338 |
{ |
|
339 |
if (start < 0 || start >= row_count || row_count < count) |
|
340 |
return false; |
|
341 |
||
342 |
beginRemoveRows(parent, start, start + count - 1); |
|
343 |
row_count -= count; |
|
344 |
endRemoveRows(); |
|
345 |
return true; |
|
346 |
} |
|
347 |
||
348 |
void removeLastRow() |
|
349 |
{ |
|
350 |
beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1); |
|
351 |
--row_count; |
|
352 |
endRemoveRows(); |
|
353 |
} |
|
354 |
||
355 |
void removeAllRows() |
|
356 |
{ |
|
357 |
beginRemoveRows(QModelIndex(), 0, row_count - 1); |
|
358 |
row_count = 0; |
|
359 |
endRemoveRows(); |
|
360 |
} |
|
361 |
||
362 |
bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex()) |
|
363 |
{ |
|
364 |
if (start < 0 || start > column_count) |
|
365 |
return false; |
|
366 |
||
367 |
beginInsertColumns(parent, start, start + count - 1); |
|
368 |
column_count += count; |
|
369 |
endInsertColumns(); |
|
370 |
return true; |
|
371 |
} |
|
372 |
||
373 |
bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex()) |
|
374 |
{ |
|
375 |
if (start < 0 || start >= column_count || column_count < count) |
|
376 |
return false; |
|
377 |
||
378 |
beginRemoveColumns(parent, start, start + count - 1); |
|
379 |
column_count -= count; |
|
380 |
endRemoveColumns(); |
|
381 |
return true; |
|
382 |
} |
|
383 |
||
384 |
void removeLastColumn() |
|
385 |
{ |
|
386 |
beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1); |
|
387 |
--column_count; |
|
388 |
endRemoveColumns(); |
|
389 |
} |
|
390 |
||
391 |
void removeAllColumns() |
|
392 |
{ |
|
393 |
beginRemoveColumns(QModelIndex(), 0, column_count - 1); |
|
394 |
column_count = 0; |
|
395 |
endRemoveColumns(); |
|
396 |
} |
|
397 |
||
398 |
bool canFetchMore(const QModelIndex &) const |
|
399 |
{ |
|
400 |
return can_fetch_more; |
|
401 |
} |
|
402 |
||
403 |
void fetchMore(const QModelIndex &) |
|
404 |
{ |
|
405 |
++fetch_more_count; |
|
406 |
} |
|
407 |
||
408 |
void reset() |
|
409 |
{ |
|
410 |
QAbstractTableModel::reset(); |
|
411 |
} |
|
412 |
||
413 |
int row_count; |
|
414 |
int column_count; |
|
415 |
bool can_fetch_more; |
|
416 |
int fetch_more_count; |
|
417 |
QSet<int> disabled_rows; |
|
418 |
QSet<int> disabled_columns; |
|
419 |
}; |
|
420 |
||
421 |
class QtTestTableView : public QTableView |
|
422 |
{ |
|
423 |
Q_OBJECT |
|
424 |
||
425 |
public: |
|
426 |
QtTestTableView(QWidget *parent = 0) : QTableView(parent), checkSignalOrder(false), hasCurrentChanged(0), hasSelectionChanged(0) {} |
|
427 |
||
428 |
void setModel(QAbstractItemModel *model) |
|
429 |
{ |
|
430 |
QTableView::setModel(model); |
|
431 |
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), |
|
432 |
this, SLOT(currentChanged(QModelIndex,QModelIndex))); |
|
433 |
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), |
|
434 |
this, SLOT(itemSelectionChanged(QItemSelection,QItemSelection))); |
|
435 |
} |
|
436 |
||
437 |
enum CursorAction { |
|
438 |
MoveUp = QAbstractItemView::MoveUp, |
|
439 |
MoveDown = QAbstractItemView::MoveDown, |
|
440 |
MoveLeft = QAbstractItemView::MoveLeft, |
|
441 |
MoveRight = QAbstractItemView::MoveRight, |
|
442 |
MoveHome = QAbstractItemView::MoveHome, |
|
443 |
MoveEnd = QAbstractItemView::MoveEnd, |
|
444 |
MovePageUp = QAbstractItemView::MovePageUp, |
|
445 |
MovePageDown = QAbstractItemView::MovePageDown, |
|
446 |
MoveNext = QAbstractItemView::MoveNext, |
|
447 |
MovePrevious = QAbstractItemView::MovePrevious |
|
448 |
}; |
|
449 |
||
450 |
QModelIndex moveCursor(QtTestTableView::CursorAction cursorAction, |
|
451 |
Qt::KeyboardModifiers modifiers) |
|
452 |
{ |
|
453 |
return QTableView::moveCursor((QAbstractItemView::CursorAction)cursorAction, modifiers); |
|
454 |
} |
|
455 |
||
456 |
int columnWidthHint(int column) const |
|
457 |
{ |
|
458 |
return sizeHintForColumn(column); |
|
459 |
} |
|
460 |
||
461 |
int rowHeightHint(int row) const |
|
462 |
{ |
|
463 |
return sizeHintForRow(row); |
|
464 |
} |
|
465 |
||
466 |
bool isIndexHidden(const QModelIndex &index) const |
|
467 |
{ |
|
468 |
return QTableView::isIndexHidden(index); |
|
469 |
} |
|
470 |
||
471 |
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) |
|
472 |
{ |
|
473 |
QTableView::setSelection(rect, command); |
|
474 |
} |
|
475 |
||
476 |
QModelIndexList selectedIndexes() const |
|
477 |
{ |
|
478 |
return QTableView::selectedIndexes(); |
|
479 |
} |
|
480 |
||
481 |
bool checkSignalOrder; |
|
482 |
public slots: |
|
483 |
void currentChanged(QModelIndex , QModelIndex ) { |
|
484 |
hasCurrentChanged++; |
|
485 |
if (checkSignalOrder) |
|
486 |
QVERIFY(hasCurrentChanged > hasSelectionChanged); |
|
487 |
} |
|
488 |
||
489 |
void itemSelectionChanged(QItemSelection , QItemSelection ) { |
|
490 |
hasSelectionChanged++; |
|
491 |
if (checkSignalOrder) |
|
492 |
QVERIFY(hasCurrentChanged >= hasSelectionChanged); |
|
493 |
} |
|
494 |
private: |
|
495 |
int hasCurrentChanged; |
|
496 |
int hasSelectionChanged; |
|
497 |
||
498 |
}; |
|
499 |
||
500 |
class QtTestItemDelegate : public QItemDelegate |
|
501 |
{ |
|
502 |
public: |
|
503 |
QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const |
|
504 |
{ |
|
505 |
return hint; |
|
506 |
} |
|
507 |
||
508 |
QSize hint; |
|
509 |
}; |
|
510 |
||
511 |
tst_QTableView::tst_QTableView() |
|
512 |
{ |
|
513 |
} |
|
514 |
||
515 |
tst_QTableView::~tst_QTableView() |
|
516 |
{ |
|
517 |
} |
|
518 |
||
519 |
void tst_QTableView::initTestCase() |
|
520 |
{ |
|
521 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
522 |
qApp->setAutoMaximizeThreshold(-1); |
|
523 |
#endif |
|
524 |
} |
|
525 |
||
526 |
void tst_QTableView::cleanupTestCase() |
|
527 |
{ |
|
528 |
} |
|
529 |
||
530 |
void tst_QTableView::init() |
|
531 |
{ |
|
532 |
} |
|
533 |
||
534 |
void tst_QTableView::cleanup() |
|
535 |
{ |
|
536 |
} |
|
537 |
||
538 |
void tst_QTableView::noDelegate() |
|
539 |
{ |
|
540 |
QtTestTableModel model(3, 3); |
|
541 |
QTableView view; |
|
542 |
view.setModel(&model); |
|
543 |
view.setItemDelegate(0); |
|
544 |
view.show(); |
|
545 |
} |
|
546 |
||
547 |
void tst_QTableView::noModel() |
|
548 |
{ |
|
549 |
QTableView view; |
|
550 |
view.show(); |
|
551 |
} |
|
552 |
||
553 |
void tst_QTableView::emptyModel() |
|
554 |
{ |
|
555 |
QtTestTableModel model; |
|
556 |
QTableView view; |
|
557 |
QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); |
|
558 |
view.setModel(&model); |
|
559 |
view.show(); |
|
560 |
QCOMPARE(spy.count(), 0); |
|
561 |
} |
|
562 |
||
563 |
void tst_QTableView::removeRows_data() |
|
564 |
{ |
|
565 |
QTest::addColumn<int>("rowCount"); |
|
566 |
QTest::addColumn<int>("columnCount"); |
|
567 |
||
568 |
QTest::newRow("2x2") << 2 << 2; |
|
569 |
QTest::newRow("10x10") << 10 << 10; |
|
570 |
} |
|
571 |
||
572 |
void tst_QTableView::removeRows() |
|
573 |
{ |
|
574 |
QFETCH(int, rowCount); |
|
575 |
QFETCH(int, columnCount); |
|
576 |
||
577 |
QtTestTableModel model(rowCount, columnCount); |
|
578 |
QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); |
|
579 |
||
580 |
QTableView view; |
|
581 |
view.setModel(&model); |
|
582 |
view.show(); |
|
583 |
||
584 |
model.removeLastRow(); |
|
585 |
QCOMPARE(spy.count(), 0); |
|
586 |
||
587 |
model.removeAllRows(); |
|
588 |
QCOMPARE(spy.count(), 0); |
|
589 |
} |
|
590 |
||
591 |
void tst_QTableView::removeColumns_data() |
|
592 |
{ |
|
593 |
QTest::addColumn<int>("rowCount"); |
|
594 |
QTest::addColumn<int>("columnCount"); |
|
595 |
||
596 |
QTest::newRow("2x2") << 2 << 2; |
|
597 |
QTest::newRow("10x10") << 10 << 10; |
|
598 |
} |
|
599 |
||
600 |
void tst_QTableView::removeColumns() |
|
601 |
{ |
|
602 |
QFETCH(int, rowCount); |
|
603 |
QFETCH(int, columnCount); |
|
604 |
||
605 |
QtTestTableModel model(rowCount, columnCount); |
|
606 |
QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); |
|
607 |
||
608 |
QTableView view; |
|
609 |
view.setModel(&model); |
|
610 |
view.show(); |
|
611 |
||
612 |
model.removeLastColumn(); |
|
613 |
QCOMPARE(spy.count(), 0); |
|
614 |
||
615 |
model.removeAllColumns(); |
|
616 |
QCOMPARE(spy.count(), 0); |
|
617 |
} |
|
618 |
||
619 |
void tst_QTableView::keyboardNavigation_data() |
|
620 |
{ |
|
621 |
QTest::addColumn<int>("rowCount"); |
|
622 |
QTest::addColumn<int>("columnCount"); |
|
623 |
QTest::addColumn<bool>("tabKeyNavigation"); |
|
624 |
QTest::addColumn<IntList>("keyPresses"); |
|
625 |
||
626 |
QTest::newRow("16x16 model") << 16 << 16 << true |
|
627 |
<< (IntList() |
|
628 |
<< Qt::Key_Up |
|
629 |
<< Qt::Key_Up |
|
630 |
<< Qt::Key_Right |
|
631 |
<< Qt::Key_Right |
|
632 |
<< Qt::Key_Up |
|
633 |
<< Qt::Key_Left |
|
634 |
<< Qt::Key_Left |
|
635 |
<< Qt::Key_Up |
|
636 |
<< Qt::Key_Down |
|
637 |
<< Qt::Key_Up |
|
638 |
<< Qt::Key_Up |
|
639 |
<< Qt::Key_Up |
|
640 |
<< Qt::Key_Up |
|
641 |
<< Qt::Key_Up |
|
642 |
<< Qt::Key_Up |
|
643 |
<< Qt::Key_Left |
|
644 |
<< Qt::Key_Left |
|
645 |
<< Qt::Key_Up |
|
646 |
<< Qt::Key_Down |
|
647 |
<< Qt::Key_Down |
|
648 |
<< Qt::Key_Tab |
|
649 |
<< Qt::Key_Backtab); |
|
650 |
||
651 |
||
652 |
QTest::newRow("no tab") << 8 << 8 << false |
|
653 |
<< (IntList() |
|
654 |
<< Qt::Key_Up |
|
655 |
<< Qt::Key_Up |
|
656 |
<< Qt::Key_Right |
|
657 |
<< Qt::Key_Right |
|
658 |
<< Qt::Key_Up |
|
659 |
<< Qt::Key_Left |
|
660 |
<< Qt::Key_Left |
|
661 |
<< Qt::Key_Up |
|
662 |
<< Qt::Key_Down |
|
663 |
<< Qt::Key_Up |
|
664 |
<< Qt::Key_Up |
|
665 |
<< Qt::Key_Up |
|
666 |
<< Qt::Key_Up |
|
667 |
<< Qt::Key_Up |
|
668 |
<< Qt::Key_Up |
|
669 |
<< Qt::Key_Left |
|
670 |
<< Qt::Key_Left |
|
671 |
<< Qt::Key_Up |
|
672 |
<< Qt::Key_Down |
|
673 |
<< Qt::Key_Down |
|
674 |
<< Qt::Key_Tab |
|
675 |
<< Qt::Key_Backtab); |
|
676 |
} |
|
677 |
||
678 |
void tst_QTableView::keyboardNavigation() |
|
679 |
{ |
|
680 |
QFETCH(int, rowCount); |
|
681 |
QFETCH(int, columnCount); |
|
682 |
QFETCH(bool, tabKeyNavigation); |
|
683 |
QFETCH(IntList, keyPresses); |
|
684 |
||
685 |
QtTestTableModel model(rowCount, columnCount); |
|
686 |
QTableView view; |
|
687 |
view.setModel(&model); |
|
688 |
||
689 |
view.setTabKeyNavigation(tabKeyNavigation); |
|
690 |
QModelIndex index = model.index(rowCount - 1, columnCount - 1); |
|
691 |
view.setCurrentIndex(index); |
|
692 |
||
693 |
view.show(); |
|
694 |
QTest::qWaitForWindowShown(&view); |
|
695 |
qApp->setActiveWindow(&view); |
|
696 |
||
697 |
int row = rowCount - 1; |
|
698 |
int column = columnCount - 1; |
|
699 |
for (int i = 0; i < keyPresses.count(); ++i) { |
|
700 |
||
701 |
Qt::Key key = (Qt::Key)keyPresses.at(i); |
|
702 |
||
703 |
switch (key) { |
|
704 |
case Qt::Key_Up: |
|
705 |
row = qMax(0, row - 1); |
|
706 |
break; |
|
707 |
case Qt::Key_Down: |
|
708 |
row = qMin(rowCount - 1, row + 1); |
|
709 |
break; |
|
710 |
case Qt::Key_Backtab: |
|
711 |
if (!tabKeyNavigation) |
|
712 |
break; |
|
713 |
case Qt::Key_Left: |
|
714 |
column = qMax(0, column - 1); |
|
715 |
break; |
|
716 |
case Qt::Key_Tab: |
|
717 |
if (!tabKeyNavigation) |
|
718 |
break; |
|
719 |
case Qt::Key_Right: |
|
720 |
column = qMin(columnCount - 1, column + 1); |
|
721 |
break; |
|
722 |
default: |
|
723 |
break; |
|
724 |
} |
|
725 |
||
726 |
QTest::keyClick(&view, key); |
|
727 |
QApplication::processEvents(); |
|
728 |
||
729 |
QModelIndex index = model.index(row, column); |
|
730 |
QCOMPARE(view.currentIndex(), index); |
|
731 |
} |
|
732 |
} |
|
733 |
||
734 |
void tst_QTableView::headerSections_data() |
|
735 |
{ |
|
736 |
QTest::addColumn<int>("rowCount"); |
|
737 |
QTest::addColumn<int>("columnCount"); |
|
738 |
QTest::addColumn<int>("row"); |
|
739 |
QTest::addColumn<int>("column"); |
|
740 |
QTest::addColumn<int>("rowHeight"); |
|
741 |
QTest::addColumn<int>("columnWidth"); |
|
742 |
||
743 |
QTest::newRow("") << 10 << 10 << 5 << 5 << 30 << 30; |
|
744 |
} |
|
745 |
||
746 |
void tst_QTableView::headerSections() |
|
747 |
{ |
|
748 |
QFETCH(int, rowCount); |
|
749 |
QFETCH(int, columnCount); |
|
750 |
QFETCH(int, row); |
|
751 |
QFETCH(int, column); |
|
752 |
QFETCH(int, rowHeight); |
|
753 |
QFETCH(int, columnWidth); |
|
754 |
||
755 |
QtTestTableModel model(rowCount, columnCount); |
|
756 |
||
757 |
QTableView view; |
|
758 |
QHeaderView *hheader = view.horizontalHeader(); |
|
759 |
QHeaderView *vheader = view.verticalHeader(); |
|
760 |
||
761 |
view.setModel(&model); |
|
762 |
view.show(); |
|
763 |
||
764 |
hheader->doItemsLayout(); |
|
765 |
vheader->doItemsLayout(); |
|
766 |
||
767 |
QCOMPARE(hheader->count(), model.columnCount()); |
|
768 |
QCOMPARE(vheader->count(), model.rowCount()); |
|
769 |
||
770 |
view.setRowHeight(row, rowHeight); |
|
771 |
QCOMPARE(view.rowHeight(row), rowHeight); |
|
772 |
view.hideRow(row); |
|
773 |
QCOMPARE(view.rowHeight(row), 0); |
|
774 |
view.showRow(row); |
|
775 |
QCOMPARE(view.rowHeight(row), rowHeight); |
|
776 |
||
777 |
view.setColumnWidth(column, columnWidth); |
|
778 |
QCOMPARE(view.columnWidth(column), columnWidth); |
|
779 |
view.hideColumn(column); |
|
780 |
QCOMPARE(view.columnWidth(column), 0); |
|
781 |
view.showColumn(column); |
|
782 |
QCOMPARE(view.columnWidth(column), columnWidth); |
|
783 |
} |
|
784 |
||
785 |
typedef QPair<int,int> IntPair; |
|
786 |
Q_DECLARE_METATYPE(IntPair) |
|
787 |
||
788 |
void tst_QTableView::moveCursor_data() |
|
789 |
{ |
|
790 |
QTest::addColumn<int>("rowCount"); |
|
791 |
QTest::addColumn<int>("columnCount"); |
|
792 |
QTest::addColumn<int>("hideRow"); |
|
793 |
QTest::addColumn<int>("hideColumn"); |
|
794 |
||
795 |
QTest::addColumn<int>("startRow"); |
|
796 |
QTest::addColumn<int>("startColumn"); |
|
797 |
||
798 |
QTest::addColumn<int>("cursorMoveAction"); |
|
799 |
QTest::addColumn<int>("modifier"); |
|
800 |
||
801 |
QTest::addColumn<int>("expectedRow"); |
|
802 |
QTest::addColumn<int>("expectedColumn"); |
|
803 |
QTest::addColumn<IntPair>("moveRow"); |
|
804 |
QTest::addColumn<IntPair>("moveColumn"); |
|
805 |
||
806 |
// MoveRight |
|
807 |
QTest::newRow("MoveRight (0,0)") |
|
808 |
<< 4 << 4 << -1 << -1 |
|
809 |
<< 0 << 0 |
|
810 |
<< int(QtTestTableView::MoveRight) << int(Qt::NoModifier) |
|
811 |
<< 0 << 1 << IntPair(0,0) << IntPair(0,0); |
|
812 |
||
813 |
QTest::newRow("MoveRight (3,0)") |
|
814 |
<< 4 << 4 << -1 << -1 |
|
815 |
<< 3 << 0 |
|
816 |
<< int(QtTestTableView::MoveRight) << int(Qt::NoModifier) |
|
817 |
<< 3 << 1 << IntPair(0,0) << IntPair(0,0); |
|
818 |
||
819 |
QTest::newRow("MoveRight (3,3)") |
|
820 |
<< 4 << 4 << -1 << -1 |
|
821 |
<< 3 << 3 |
|
822 |
<< int(QtTestTableView::MoveRight) << int(Qt::NoModifier) |
|
823 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); // ### |
|
824 |
||
825 |
QTest::newRow("MoveRight, hidden column 1 (0,0)") |
|
826 |
<< 4 << 4 << -1 << 1 |
|
827 |
<< 0 << 0 |
|
828 |
<< int(QtTestTableView::MoveRight) << int(Qt::NoModifier) |
|
829 |
<< 0 << 2 << IntPair(0,0) << IntPair(0,0); |
|
830 |
||
831 |
QTest::newRow("MoveRight, hidden column 3 (0,2)") |
|
832 |
<< 4 << 4 << -1 << 3 |
|
833 |
<< 0 << 2 |
|
834 |
<< int(QtTestTableView::MoveRight) << int(Qt::NoModifier) |
|
835 |
<< 0 << 2 << IntPair(0,0) << IntPair(0,0); // ### |
|
836 |
||
837 |
// MoveNext should in addition wrap |
|
838 |
QTest::newRow("MoveNext (0,0)") |
|
839 |
<< 4 << 4 << -1 << -1 |
|
840 |
<< 0 << 0 |
|
841 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
842 |
<< 0 << 1 << IntPair(0,0) << IntPair(0,0); |
|
843 |
||
844 |
QTest::newRow("MoveNext (0,2)") |
|
845 |
<< 4 << 4 << -1 << -1 |
|
846 |
<< 0 << 2 |
|
847 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
848 |
<< 0 << 3 << IntPair(0,0) << IntPair(0,0); |
|
849 |
||
850 |
QTest::newRow("MoveNext, wrap (0,3)") |
|
851 |
<< 4 << 4 << -1 << -1 |
|
852 |
<< 0 << 3 |
|
853 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
854 |
<< 1 << 0 << IntPair(0,0) << IntPair(0,0); |
|
855 |
||
856 |
QTest::newRow("MoveNext, wrap (3,3)") |
|
857 |
<< 4 << 4 << -1 << -1 |
|
858 |
<< 3 << 3 |
|
859 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
860 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
861 |
||
862 |
QTest::newRow("MoveNext, hidden column 1 (0,0)") |
|
863 |
<< 4 << 4 << -1 << 1 |
|
864 |
<< 0 << 0 |
|
865 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
866 |
<< 0 << 2 << IntPair(0,0) << IntPair(0,0); |
|
867 |
||
868 |
QTest::newRow("MoveNext, wrap, hidden column 3 (0,2)") |
|
869 |
<< 4 << 4 << -1 << 3 |
|
870 |
<< 0 << 2 |
|
871 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
872 |
<< 1 << 0 << IntPair(0,0) << IntPair(0,0); |
|
873 |
||
874 |
QTest::newRow("MoveNext, wrap, hidden column 3 (3,2)") |
|
875 |
<< 4 << 4 << -1 << 3 |
|
876 |
<< 3 << 2 |
|
877 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
878 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
879 |
||
880 |
QTest::newRow("MoveNext, wrapy, wrapx, hidden column 3, hidden row 3 (2,2)") |
|
881 |
<< 4 << 4 << 3 << 3 |
|
882 |
<< 2 << 2 |
|
883 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
884 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
885 |
||
886 |
QTest::newRow("MoveNext, wrap, hidden column 2, moved column from 3 to 0. (0,2)") |
|
887 |
<< 4 << 4 << -1 << 2 |
|
888 |
<< 0 << 2 |
|
889 |
<< int(QtTestTableView::MoveNext) << int(Qt::NoModifier) |
|
890 |
<< 1 << 3 << IntPair(0,0) << IntPair(3,0); |
|
891 |
||
892 |
// MoveLeft |
|
893 |
QTest::newRow("MoveLeft (0,0)") |
|
894 |
<< 4 << 4 << -1 << -1 |
|
895 |
<< 0 << 0 |
|
896 |
<< int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) |
|
897 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
898 |
||
899 |
QTest::newRow("MoveLeft (0,3)") |
|
900 |
<< 4 << 4 << -1 << -1 |
|
901 |
<< 0 << 3 |
|
902 |
<< int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) |
|
903 |
<< 0 << 2 << IntPair(0,0) << IntPair(0,0); |
|
904 |
||
905 |
QTest::newRow("MoveLeft (1,0)") |
|
906 |
<< 4 << 4 << -1 << -1 |
|
907 |
<< 1 << 0 |
|
908 |
<< int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) |
|
909 |
<< 1 << 0 << IntPair(0,0) << IntPair(0,0); |
|
910 |
||
911 |
QTest::newRow("MoveLeft, hidden column 0 (0,2)") |
|
912 |
<< 4 << 4 << -1 << 1 |
|
913 |
<< 0 << 2 |
|
914 |
<< int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) |
|
915 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
916 |
||
917 |
QTest::newRow("MoveLeft, hidden column 0 (0,1)") |
|
918 |
<< 4 << 4 << -1 << 0 |
|
919 |
<< 0 << 1 |
|
920 |
<< int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) |
|
921 |
<< 0 << 1 << IntPair(0,0) << IntPair(0,0); |
|
922 |
||
923 |
// MovePrevious should in addition wrap |
|
924 |
QTest::newRow("MovePrevious (0,3)") |
|
925 |
<< 4 << 4 << -1 << -1 |
|
926 |
<< 0 << 3 |
|
927 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
928 |
<< 0 << 2 << IntPair(0,0) << IntPair(0,0); |
|
929 |
||
930 |
QTest::newRow("MovePrevious (0,1)") |
|
931 |
<< 4 << 4 << -1 << -1 |
|
932 |
<< 0 << 1 |
|
933 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
934 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
935 |
||
936 |
QTest::newRow("MovePrevious, wrap (1,0)") |
|
937 |
<< 4 << 4 << -1 << -1 |
|
938 |
<< 1 << 0 |
|
939 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
940 |
<< 0 << 3 << IntPair(0,0) << IntPair(0,0); |
|
941 |
||
942 |
QTest::newRow("MovePrevious, wrap, (0,0)") |
|
943 |
<< 4 << 4 << -1 << -1 |
|
944 |
<< 0 << 0 |
|
945 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
946 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
947 |
||
948 |
QTest::newRow("MovePrevious, hidden column 1 (0,2)") |
|
949 |
<< 4 << 4 << -1 << 1 |
|
950 |
<< 0 << 2 |
|
951 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
952 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
953 |
||
954 |
QTest::newRow("MovePrevious, wrap, hidden column 3 (0,2)") |
|
955 |
<< 4 << 4 << -1 << 3 |
|
956 |
<< 0 << 2 |
|
957 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
958 |
<< 0 << 1 << IntPair(0,0) << IntPair(0,0); |
|
959 |
||
960 |
QTest::newRow("MovePrevious, wrapy, hidden column 0 (0,1)") |
|
961 |
<< 4 << 4 << -1 << 0 |
|
962 |
<< 0 << 1 |
|
963 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
964 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
965 |
||
966 |
QTest::newRow("MovePrevious, wrap, hidden column 0, hidden row 0 (1,1)") |
|
967 |
<< 4 << 4 << 0 << 0 |
|
968 |
<< 1 << 1 |
|
969 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
970 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
971 |
||
972 |
QTest::newRow("MovePrevious, wrap, hidden column 1, moved column from 0 to 3. (1,2)") |
|
973 |
<< 4 << 4 << -1 << 1 |
|
974 |
<< 1 << 2 |
|
975 |
<< int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) |
|
976 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,3); |
|
977 |
||
978 |
// MoveDown |
|
979 |
QTest::newRow("MoveDown (0,0)") |
|
980 |
<< 4 << 4 << -1 << -1 |
|
981 |
<< 0 << 0 |
|
982 |
<< int(QtTestTableView::MoveDown) << int(Qt::NoModifier) |
|
983 |
<< 1 << 0 << IntPair(0,0) << IntPair(0,0); |
|
984 |
||
985 |
QTest::newRow("MoveDown (3,0)") |
|
986 |
<< 4 << 4 << -1 << -1 |
|
987 |
<< 3 << 0 |
|
988 |
<< int(QtTestTableView::MoveDown) << int(Qt::NoModifier) |
|
989 |
<< 3 << 0 << IntPair(0,0) << IntPair(0,0); |
|
990 |
||
991 |
QTest::newRow("MoveDown (3,3)") |
|
992 |
<< 4 << 4 << -1 << -1 |
|
993 |
<< 3 << 3 |
|
994 |
<< int(QtTestTableView::MoveDown) << int(Qt::NoModifier) |
|
995 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
996 |
||
997 |
QTest::newRow("MoveDown, hidden row 1 (0,0)") |
|
998 |
<< 4 << 4 << 1 << -1 |
|
999 |
<< 0 << 0 |
|
1000 |
<< int(QtTestTableView::MoveDown) << int(Qt::NoModifier) |
|
1001 |
<< 2 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1002 |
||
1003 |
QTest::newRow("MoveDown, hidden row 3 (2,0)") |
|
1004 |
<< 4 << 4 << 3 << -1 |
|
1005 |
<< 2 << 0 |
|
1006 |
<< int(QtTestTableView::MoveDown) << int(Qt::NoModifier) |
|
1007 |
<< 2 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1008 |
||
1009 |
QTest::newRow("MoveDown, hidden row 0 hidden column 0 (0,0)") |
|
1010 |
<< 4 << 4 << 0 << 0 |
|
1011 |
<< 0 << 0 |
|
1012 |
<< int(QtTestTableView::MoveDown) << int(Qt::NoModifier) |
|
1013 |
<< 1 << 1 << IntPair(0,0) << IntPair(0,0); |
|
1014 |
||
1015 |
// MoveUp |
|
1016 |
QTest::newRow("MoveUp (0,0)") |
|
1017 |
<< 4 << 4 << -1 << -1 |
|
1018 |
<< 0 << 0 |
|
1019 |
<< int(QtTestTableView::MoveUp) << int(Qt::NoModifier) |
|
1020 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1021 |
||
1022 |
QTest::newRow("MoveUp (3, 0)") |
|
1023 |
<< 4 << 4 << -1 << -1 |
|
1024 |
<< 3 << 0 |
|
1025 |
<< int(QtTestTableView::MoveUp) << int(Qt::NoModifier) |
|
1026 |
<< 2 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1027 |
||
1028 |
QTest::newRow("MoveUp (0,1)") |
|
1029 |
<< 4 << 4 << -1 << -1 |
|
1030 |
<< 0 << 1 |
|
1031 |
<< int(QtTestTableView::MoveUp) << int(Qt::NoModifier) |
|
1032 |
<< 0 << 1 << IntPair(0,0) << IntPair(0,0); |
|
1033 |
||
1034 |
QTest::newRow("MoveUp, hidden row 1 (2,0)") |
|
1035 |
<< 4 << 4 << 1 << -1 |
|
1036 |
<< 2 << 0 |
|
1037 |
<< int(QtTestTableView::MoveUp) << int(Qt::NoModifier) |
|
1038 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1039 |
||
1040 |
QTest::newRow("MoveUp, hidden row (1,0)") |
|
1041 |
<< 4 << 4 << 0 << -1 |
|
1042 |
<< 1 << 0 |
|
1043 |
<< int(QtTestTableView::MoveUp) << int(Qt::NoModifier) |
|
1044 |
<< 1 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1045 |
||
1046 |
// MoveHome |
|
1047 |
QTest::newRow("MoveHome (0,0)") |
|
1048 |
<< 4 << 4 << -1 << -1 |
|
1049 |
<< 0 << 0 |
|
1050 |
<< int(QtTestTableView::MoveHome) << int(Qt::NoModifier) |
|
1051 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1052 |
||
1053 |
QTest::newRow("MoveHome (3,3)") |
|
1054 |
<< 4 << 4 << -1 << -1 |
|
1055 |
<< 3 << 3 |
|
1056 |
<< int(QtTestTableView::MoveHome) << int(Qt::NoModifier) |
|
1057 |
<< 3 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1058 |
||
1059 |
QTest::newRow("MoveHome, hidden column 0 (3,3)") |
|
1060 |
<< 4 << 4 << -1 << 0 |
|
1061 |
<< 3 << 3 |
|
1062 |
<< int(QtTestTableView::MoveHome) << int(Qt::NoModifier) |
|
1063 |
<< 3 << 1 << IntPair(0,0) << IntPair(0,0); |
|
1064 |
||
1065 |
// Use Ctrl modifier |
|
1066 |
QTest::newRow("MoveHome + Ctrl (0,0)") |
|
1067 |
<< 4 << 4 << -1 << -1 |
|
1068 |
<< 0 << 0 |
|
1069 |
<< int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) |
|
1070 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1071 |
||
1072 |
QTest::newRow("MoveHome + Ctrl (3,3)") |
|
1073 |
<< 4 << 4 << -1 << -1 |
|
1074 |
<< 3 << 3 |
|
1075 |
<< int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) |
|
1076 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1077 |
||
1078 |
QTest::newRow("MoveHome + Ctrl, hidden column 0, hidden row 0 (3,3)") |
|
1079 |
<< 4 << 4 << 0 << 0 |
|
1080 |
<< 3 << 3 |
|
1081 |
<< int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) |
|
1082 |
<< 1 << 1 << IntPair(0,0) << IntPair(0,0); |
|
1083 |
||
1084 |
// MoveEnd |
|
1085 |
QTest::newRow("MoveEnd (0,0)") |
|
1086 |
<< 4 << 4 << -1 << -1 |
|
1087 |
<< 0 << 0 |
|
1088 |
<< int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) |
|
1089 |
<< 0 << 3 << IntPair(0,0) << IntPair(0,0); |
|
1090 |
||
1091 |
QTest::newRow("MoveEnd (3,3)") |
|
1092 |
<< 4 << 4 << -1 << -1 |
|
1093 |
<< 3 << 3 |
|
1094 |
<< int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) |
|
1095 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
1096 |
||
1097 |
QTest::newRow("MoveEnd, hidden column (0,0)") |
|
1098 |
<< 4 << 4 << -1 << 3 |
|
1099 |
<< 0 << 0 |
|
1100 |
<< int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) |
|
1101 |
<< 0<< 2 << IntPair(0,0) << IntPair(0,0); |
|
1102 |
||
1103 |
// Use Ctrl modifier |
|
1104 |
QTest::newRow("MoveEnd + Ctrl (0,0)") |
|
1105 |
<< 4 << 4 << -1 << -1 |
|
1106 |
<< 0 << 0 |
|
1107 |
<< int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) |
|
1108 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
1109 |
||
1110 |
QTest::newRow("MoveEnd + Ctrl (3,3)") |
|
1111 |
<< 4 << 4 << -1 << -1 |
|
1112 |
<< 3 << 3 |
|
1113 |
<< int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) |
|
1114 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
1115 |
||
1116 |
QTest::newRow("MoveEnd + Ctrl, hidden column 3 (0,0)") |
|
1117 |
<< 4 << 4 << -1 << 3 |
|
1118 |
<< 0 << 0 |
|
1119 |
<< int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) |
|
1120 |
<< 3 << 2 << IntPair(0,0) << IntPair(0,0); |
|
1121 |
||
1122 |
QTest::newRow("MoveEnd + Ctrl, hidden column 3, hidden row 3 (0,0)") |
|
1123 |
<< 4 << 4 << 3 << 3 |
|
1124 |
<< 0 << 0 |
|
1125 |
<< int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) |
|
1126 |
<< 2 << 2 << IntPair(0,0) << IntPair(0,0); |
|
1127 |
||
1128 |
QTest::newRow("MovePageUp (0,0)") |
|
1129 |
<< 4 << 4 << -1 << -1 |
|
1130 |
<< 0 << 0 |
|
1131 |
<< int(QtTestTableView::MovePageUp) << 0 |
|
1132 |
<< 0 << 0 << IntPair(0,0) << IntPair(0,0); |
|
1133 |
||
1134 |
QTest::newRow("MovePageUp (3,3)") |
|
1135 |
<< 4 << 4 << -1 << -1 |
|
1136 |
<< 3 << 3 |
|
1137 |
<< int(QtTestTableView::MovePageUp) << 0 |
|
1138 |
<< 0 << 3 << IntPair(0,0) << IntPair(0,0); |
|
1139 |
||
1140 |
QTest::newRow("MovePageDown (3, 3)") |
|
1141 |
<< 4 << 4 << -1 << -1 |
|
1142 |
<< 3 << 3 |
|
1143 |
<< int(QtTestTableView::MovePageDown) << 0 |
|
1144 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
1145 |
||
1146 |
QTest::newRow("MovePageDown (0, 3)") |
|
1147 |
<< 4 << 4 << -1 << -1 |
|
1148 |
<< 0 << 3 |
|
1149 |
<< int(QtTestTableView::MovePageDown) << 0 |
|
1150 |
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); |
|
1151 |
} |
|
1152 |
||
1153 |
void tst_QTableView::moveCursor() |
|
1154 |
{ |
|
1155 |
QFETCH(int, rowCount); |
|
1156 |
QFETCH(int, columnCount); |
|
1157 |
QFETCH(int, hideRow); |
|
1158 |
QFETCH(int, hideColumn); |
|
1159 |
QFETCH(int, startRow); |
|
1160 |
QFETCH(int, startColumn); |
|
1161 |
QFETCH(int, cursorMoveAction); |
|
1162 |
QFETCH(int, modifier); |
|
1163 |
QFETCH(int, expectedRow); |
|
1164 |
QFETCH(int, expectedColumn); |
|
1165 |
QFETCH(IntPair, moveRow); |
|
1166 |
QFETCH(IntPair, moveColumn); |
|
1167 |
||
1168 |
QtTestTableModel model(rowCount, columnCount); |
|
1169 |
QtTestTableView view; |
|
1170 |
||
1171 |
view.setModel(&model); |
|
1172 |
view.hideRow(hideRow); |
|
1173 |
view.hideColumn(hideColumn); |
|
1174 |
if (moveColumn.first != moveColumn.second) |
|
1175 |
view.horizontalHeader()->moveSection(moveColumn.first, moveColumn.second); |
|
1176 |
if (moveRow.first != moveRow.second) |
|
1177 |
view.verticalHeader()->moveSection(moveRow.first, moveRow.second); |
|
1178 |
||
1179 |
view.show(); |
|
1180 |
||
1181 |
QModelIndex index = model.index(startRow, startColumn); |
|
1182 |
view.setCurrentIndex(index); |
|
1183 |
||
1184 |
QModelIndex newIndex = view.moveCursor((QtTestTableView::CursorAction)cursorMoveAction, |
|
1185 |
(Qt::KeyboardModifiers)modifier); |
|
1186 |
// expected fails, task 119433 |
|
1187 |
if(newIndex.row() == -1) |
|
1188 |
return; |
|
1189 |
QCOMPARE(newIndex.row(), expectedRow); |
|
1190 |
QCOMPARE(newIndex.column(), expectedColumn); |
|
1191 |
} |
|
1192 |
||
1193 |
void tst_QTableView::moveCursorStrikesBack_data() |
|
1194 |
{ |
|
1195 |
QTest::addColumn<int>("hideRow"); |
|
1196 |
QTest::addColumn<int>("hideColumn"); |
|
1197 |
QTest::addColumn<IntList>("disableRows"); |
|
1198 |
QTest::addColumn<IntList>("disableColumns"); |
|
1199 |
QTest::addColumn<QRect>("span"); |
|
1200 |
||
1201 |
QTest::addColumn<int>("startRow"); |
|
1202 |
QTest::addColumn<int>("startColumn"); |
|
1203 |
QTest::addColumn<IntList>("cursorMoveActions"); |
|
1204 |
QTest::addColumn<int>("expectedRow"); |
|
1205 |
QTest::addColumn<int>("expectedColumn"); |
|
1206 |
||
1207 |
QTest::newRow("Last column disabled. Task QTBUG-3878") << -1 << -1 |
|
1208 |
<< IntList() |
|
1209 |
<< (IntList() << 6) |
|
1210 |
<< QRect() |
|
1211 |
<< 0 << 5 << (IntList() << int(QtTestTableView::MoveNext)) |
|
1212 |
<< 1 << 0; |
|
1213 |
||
1214 |
QTest::newRow("Last column disabled. Task QTBUG-3878") << -1 << -1 |
|
1215 |
<< IntList() |
|
1216 |
<< (IntList() << 6) |
|
1217 |
<< QRect() |
|
1218 |
<< 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious)) |
|
1219 |
<< 0 << 5; |
|
1220 |
||
1221 |
QTest::newRow("Span, anchor column hidden") << -1 << 1 |
|
1222 |
<< IntList() |
|
1223 |
<< IntList() |
|
1224 |
<< QRect(1, 2, 2, 3) |
|
1225 |
<< 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) |
|
1226 |
<< 2 << 2; |
|
1227 |
||
1228 |
QTest::newRow("Span, anchor column disabled") << -1 << -1 |
|
1229 |
<< IntList() |
|
1230 |
<< (IntList() << 1) |
|
1231 |
<< QRect(1, 2, 2, 3) |
|
1232 |
<< 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) |
|
1233 |
<< 2 << 2; |
|
1234 |
||
1235 |
QTest::newRow("Span, anchor row hidden") << 2 << -1 |
|
1236 |
<< IntList() |
|
1237 |
<< IntList() |
|
1238 |
<< QRect(1, 2, 2, 3) |
|
1239 |
<< 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) |
|
1240 |
<< 3 << 2; |
|
1241 |
||
1242 |
QTest::newRow("Span, anchor row disabled") << -1 << -1 |
|
1243 |
<< (IntList() << 2) |
|
1244 |
<< IntList() |
|
1245 |
<< QRect(1, 2, 2, 3) |
|
1246 |
<< 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) |
|
1247 |
<< 3 << 2; |
|
1248 |
||
1249 |
QTest::newRow("Move through span right") << -1 << -1 |
|
1250 |
<< IntList() |
|
1251 |
<< IntList() |
|
1252 |
<< QRect(1, 2, 2, 3) |
|
1253 |
<< 3 << 0 << (IntList() << int(QtTestTableView::MoveRight) << int(QtTestTableView::MoveRight)) |
|
1254 |
<< 3 << 3; |
|
1255 |
||
1256 |
QTest::newRow("Move through span left") << -1 << -1 |
|
1257 |
<< IntList() |
|
1258 |
<< IntList() |
|
1259 |
<< QRect(1, 2, 2, 3) |
|
1260 |
<< 3 << 3 << (IntList() << int(QtTestTableView::MoveLeft) << int(QtTestTableView::MoveLeft)) |
|
1261 |
<< 3 << 0; |
|
1262 |
||
1263 |
QTest::newRow("Move through span down") << -1 << -1 |
|
1264 |
<< IntList() |
|
1265 |
<< IntList() |
|
1266 |
<< QRect(1, 2, 2, 3) |
|
1267 |
<< 1 << 2 << (IntList() << int(QtTestTableView::MoveDown) << int(QtTestTableView::MoveDown)) |
|
1268 |
<< 5 << 2; |
|
1269 |
||
1270 |
QTest::newRow("Move through span up") << -1 << -1 |
|
1271 |
<< IntList() |
|
1272 |
<< IntList() |
|
1273 |
<< QRect(1, 2, 2, 3) |
|
1274 |
<< 5 << 2 << (IntList() << int(QtTestTableView::MoveUp) << int(QtTestTableView::MoveUp)) |
|
1275 |
<< 1 << 2; |
|
1276 |
||
1277 |
IntList fullList; |
|
1278 |
for (int i = 0; i < 7; ++i) |
|
1279 |
fullList << i; |
|
1280 |
||
1281 |
QTest::newRow("All disabled, wrap forward. Timeout => FAIL") << -1 << -1 |
|
1282 |
<< fullList |
|
1283 |
<< fullList |
|
1284 |
<< QRect() |
|
1285 |
<< 1 << 0 << (IntList() << int(QtTestTableView::MoveNext)) |
|
1286 |
<< 1 << 0; |
|
1287 |
||
1288 |
QTest::newRow("All disabled, wrap backwards. Timeout => FAIL") << -1 << -1 |
|
1289 |
<< fullList |
|
1290 |
<< fullList |
|
1291 |
<< QRect() |
|
1292 |
<< 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious)) |
|
1293 |
<< 1 << 0; |
|
1294 |
} |
|
1295 |
||
1296 |
void tst_QTableView::moveCursorStrikesBack() |
|
1297 |
{ |
|
1298 |
QFETCH(int, hideRow); |
|
1299 |
QFETCH(int, hideColumn); |
|
1300 |
QFETCH(IntList, disableRows); |
|
1301 |
QFETCH(IntList, disableColumns); |
|
1302 |
QFETCH(QRect, span); |
|
1303 |
||
1304 |
QFETCH(int, startRow); |
|
1305 |
QFETCH(int, startColumn); |
|
1306 |
QFETCH(IntList, cursorMoveActions); |
|
1307 |
QFETCH(int, expectedRow); |
|
1308 |
QFETCH(int, expectedColumn); |
|
1309 |
||
1310 |
QtTestTableModel model(7, 7); |
|
1311 |
QtTestTableView view; |
|
1312 |
view.setModel(&model); |
|
1313 |
view.hideRow(hideRow); |
|
1314 |
view.hideColumn(hideColumn); |
|
1315 |
||
1316 |
if (span.height() && span.width()) |
|
1317 |
view.setSpan(span.top(), span.left(), span.height(), span.width()); |
|
1318 |
view.show(); |
|
1319 |
||
1320 |
QModelIndex index = model.index(startRow, startColumn); |
|
1321 |
view.setCurrentIndex(index); |
|
1322 |
||
1323 |
foreach (int row, disableRows) |
|
1324 |
model.disableRow(row); |
|
1325 |
foreach (int column, disableColumns) |
|
1326 |
model.disableColumn(column); |
|
1327 |
||
1328 |
int newRow = -1; |
|
1329 |
int newColumn = -1; |
|
1330 |
foreach (int cursorMoveAction, cursorMoveActions) { |
|
1331 |
QModelIndex newIndex = view.moveCursor((QtTestTableView::CursorAction)cursorMoveAction, 0); |
|
1332 |
view.setCurrentIndex(newIndex); |
|
1333 |
newRow = newIndex.row(); |
|
1334 |
newColumn = newIndex.column(); |
|
1335 |
} |
|
1336 |
||
1337 |
// expected fails, task 119433 |
|
1338 |
if(newRow == -1) |
|
1339 |
return; |
|
1340 |
QCOMPARE(newRow, expectedRow); |
|
1341 |
QCOMPARE(newColumn, expectedColumn); |
|
1342 |
} |
|
1343 |
||
1344 |
void tst_QTableView::hideRows_data() |
|
1345 |
{ |
|
1346 |
QTest::addColumn<int>("rowCount"); |
|
1347 |
QTest::addColumn<int>("columnCount"); |
|
1348 |
QTest::addColumn<int>("showRow"); // hide, then show |
|
1349 |
QTest::addColumn<int>("hideRow"); // hide only |
|
1350 |
QTest::addColumn<int>("row"); |
|
1351 |
QTest::addColumn<int>("column"); |
|
1352 |
QTest::addColumn<int>("rowSpan"); |
|
1353 |
QTest::addColumn<int>("columnSpan"); |
|
1354 |
||
1355 |
QTest::newRow("show row 0, hide row 3, no span") |
|
1356 |
<< 10 << 10 |
|
1357 |
<< 0 |
|
1358 |
<< 3 |
|
1359 |
<< -1 << -1 |
|
1360 |
<< 1 << 1; |
|
1361 |
||
1362 |
QTest::newRow("show row 0, hide row 3, span") |
|
1363 |
<< 10 << 10 |
|
1364 |
<< 0 |
|
1365 |
<< 3 |
|
1366 |
<< 0 << 0 |
|
1367 |
<< 3 << 2; |
|
1368 |
} |
|
1369 |
||
1370 |
void tst_QTableView::hideRows() |
|
1371 |
{ |
|
1372 |
QFETCH(int, rowCount); |
|
1373 |
QFETCH(int, columnCount); |
|
1374 |
QFETCH(int, showRow); |
|
1375 |
QFETCH(int, hideRow); |
|
1376 |
QFETCH(int, row); |
|
1377 |
QFETCH(int, column); |
|
1378 |
QFETCH(int, rowSpan); |
|
1379 |
QFETCH(int, columnSpan); |
|
1380 |
||
1381 |
QtTestTableModel model(rowCount, columnCount); |
|
1382 |
QTableView view; |
|
1383 |
||
1384 |
view.setModel(&model); |
|
1385 |
view.setSpan(row, column, rowSpan, columnSpan); |
|
1386 |
||
1387 |
view.hideRow(showRow); |
|
1388 |
QVERIFY(view.isRowHidden(showRow)); |
|
1389 |
||
1390 |
view.hideRow(hideRow); |
|
1391 |
QVERIFY(view.isRowHidden(hideRow)); |
|
1392 |
||
1393 |
view.showRow(showRow); |
|
1394 |
QVERIFY(!view.isRowHidden(showRow)); |
|
1395 |
QVERIFY(view.isRowHidden(hideRow)); |
|
1396 |
} |
|
1397 |
||
1398 |
void tst_QTableView::hideColumns_data() |
|
1399 |
{ |
|
1400 |
QTest::addColumn<int>("rowCount"); |
|
1401 |
QTest::addColumn<int>("columnCount"); |
|
1402 |
QTest::addColumn<int>("showColumn"); // hide, then show |
|
1403 |
QTest::addColumn<int>("hideColumn"); // hide only |
|
1404 |
QTest::addColumn<int>("row"); |
|
1405 |
QTest::addColumn<int>("column"); |
|
1406 |
QTest::addColumn<int>("rowSpan"); |
|
1407 |
QTest::addColumn<int>("columnSpan"); |
|
1408 |
||
1409 |
QTest::newRow("show col 0, hide col 3, no span") |
|
1410 |
<< 10 << 10 |
|
1411 |
<< 0 |
|
1412 |
<< 3 |
|
1413 |
<< -1 << -1 |
|
1414 |
<< 1 << 1; |
|
1415 |
||
1416 |
QTest::newRow("show col 0, hide col 3, span") |
|
1417 |
<< 10 << 10 |
|
1418 |
<< 0 |
|
1419 |
<< 3 |
|
1420 |
<< 0 << 0 |
|
1421 |
<< 3 << 2; |
|
1422 |
} |
|
1423 |
||
1424 |
void tst_QTableView::hideColumns() |
|
1425 |
{ |
|
1426 |
QFETCH(int, rowCount); |
|
1427 |
QFETCH(int, columnCount); |
|
1428 |
QFETCH(int, showColumn); |
|
1429 |
QFETCH(int, hideColumn); |
|
1430 |
QFETCH(int, row); |
|
1431 |
QFETCH(int, column); |
|
1432 |
QFETCH(int, rowSpan); |
|
1433 |
QFETCH(int, columnSpan); |
|
1434 |
||
1435 |
QtTestTableModel model(rowCount, columnCount); |
|
1436 |
||
1437 |
QTableView view; |
|
1438 |
view.setModel(&model); |
|
1439 |
view.setSpan(row, column, rowSpan, columnSpan); |
|
1440 |
||
1441 |
view.hideColumn(showColumn); |
|
1442 |
QVERIFY(view.isColumnHidden(showColumn)); |
|
1443 |
||
1444 |
view.hideColumn(hideColumn); |
|
1445 |
QVERIFY(view.isColumnHidden(hideColumn)); |
|
1446 |
||
1447 |
view.showColumn(showColumn); |
|
1448 |
QVERIFY(!view.isColumnHidden(showColumn)); |
|
1449 |
QVERIFY(view.isColumnHidden(hideColumn)); |
|
1450 |
} |
|
1451 |
||
1452 |
void tst_QTableView::selection_data() |
|
1453 |
{ |
|
1454 |
QTest::addColumn<int>("rowCount"); |
|
1455 |
QTest::addColumn<int>("columnCount"); |
|
1456 |
QTest::addColumn<int>("row"); |
|
1457 |
QTest::addColumn<int>("column"); |
|
1458 |
QTest::addColumn<int>("rowSpan"); |
|
1459 |
QTest::addColumn<int>("columnSpan"); |
|
1460 |
QTest::addColumn<int>("hideRow"); |
|
1461 |
QTest::addColumn<int>("hideColumn"); |
|
1462 |
QTest::addColumn<int>("moveRowFrom"); |
|
1463 |
QTest::addColumn<int>("moveRowTo"); |
|
1464 |
QTest::addColumn<int>("moveColumnFrom"); |
|
1465 |
QTest::addColumn<int>("moveColumnTo"); |
|
1466 |
QTest::addColumn<int>("rowHeight"); |
|
1467 |
QTest::addColumn<int>("columnWidth"); |
|
1468 |
QTest::addColumn<int>("x"); |
|
1469 |
QTest::addColumn<int>("y"); |
|
1470 |
QTest::addColumn<int>("width"); |
|
1471 |
QTest::addColumn<int>("height"); |
|
1472 |
QTest::addColumn<int>("command"); |
|
1473 |
QTest::addColumn<int>("selectedCount"); // ### make this more detailed |
|
1474 |
||
1475 |
QTest::newRow("no span, no hidden, no moved, 3x3 select") |
|
1476 |
<< 10 << 10 // dim |
|
1477 |
<< -1 << -1 // pos |
|
1478 |
<< 1 << 1 // span |
|
1479 |
<< -1 << -1 // hide |
|
1480 |
<< -1 << -1 // move row |
|
1481 |
<< -1 << -1 // move col |
|
1482 |
<< 40 << 40 // cell size |
|
1483 |
<< 20 << 20 << 80 << 80 // rect |
|
1484 |
<< int(QItemSelectionModel::Select) // command |
|
1485 |
<< 9; // selected count |
|
1486 |
||
1487 |
QTest::newRow("row span, no hidden, no moved, 3x3 select") |
|
1488 |
<< 10 << 10 // dim |
|
1489 |
<< 1 << 1 // pos |
|
1490 |
<< 2 << 1 // span |
|
1491 |
<< -1 << -1 // hide |
|
1492 |
<< -1 << -1 // move row |
|
1493 |
<< -1 << -1 // move col |
|
1494 |
<< 40 << 40 // cell size |
|
1495 |
<< 20 << 20 << 80 << 80 // rect |
|
1496 |
<< int(QItemSelectionModel::Select) // command |
|
1497 |
<< 8; // selected count |
|
1498 |
||
1499 |
QTest::newRow("col span, no hidden, no moved, 3x3 select") |
|
1500 |
<< 10 << 10 // dim |
|
1501 |
<< 1 << 1 // pos |
|
1502 |
<< 1 << 2 // span |
|
1503 |
<< -1 << -1 // hide |
|
1504 |
<< -1 << -1 // move row |
|
1505 |
<< -1 << -1 // move col |
|
1506 |
<< 40 << 40 // cell size |
|
1507 |
<< 20 << 20 << 80 << 80 // rect |
|
1508 |
<< int(QItemSelectionModel::Select) // command |
|
1509 |
<< 8; // selected count |
|
1510 |
||
1511 |
QTest::newRow("no span, row hidden, no moved, 3x3 select") |
|
1512 |
<< 10 << 10 // dim |
|
1513 |
<< -1 << -1 // pos |
|
1514 |
<< 1 << 1 // span |
|
1515 |
<< 1 << -1 // hide |
|
1516 |
<< -1 << -1 // move row |
|
1517 |
<< -1 << -1 // move col |
|
1518 |
<< 40 << 40 // cell size |
|
1519 |
<< 20 << 20 << 80 << 80 // rect |
|
1520 |
<< int(QItemSelectionModel::Select) // command |
|
1521 |
<< 9; // selected count |
|
1522 |
||
1523 |
QTest::newRow("no span, col hidden, no moved, 3x3 select") |
|
1524 |
<< 10 << 10 // dim |
|
1525 |
<< -1 << -1 // pos |
|
1526 |
<< 1 << 1 // span |
|
1527 |
<< -1 << 1 // hide |
|
1528 |
<< -1 << -1 // move row |
|
1529 |
<< -1 << -1 // move col |
|
1530 |
<< 40 << 40 // cell size |
|
1531 |
<< 20 << 20 << 80 << 80 // rect |
|
1532 |
<< int(QItemSelectionModel::Select) // command |
|
1533 |
<< 9; // selected count |
|
1534 |
||
1535 |
QTest::newRow("no span, no hidden, row moved, 3x3 select") |
|
1536 |
<< 10 << 10 // dim |
|
1537 |
<< -1 << -1 // pos |
|
1538 |
<< 1 << 1 // span |
|
1539 |
<< -1 << -1 // hide |
|
1540 |
<< 1 << 3 // move row |
|
1541 |
<< -1 << -1 // move col |
|
1542 |
<< 40 << 40 // cell size |
|
1543 |
<< 20 << 20 << 80 << 80 // rect |
|
1544 |
<< int(QItemSelectionModel::Select) // command |
|
1545 |
<< 9; // selected count |
|
1546 |
||
1547 |
QTest::newRow("no span, no hidden, col moved, 3x3 select") |
|
1548 |
<< 10 << 10 // dim |
|
1549 |
<< -1 << -1 // pos |
|
1550 |
<< 1 << 1 // span |
|
1551 |
<< -1 << -1 // hide |
|
1552 |
<< -1 << -1 // move row |
|
1553 |
<< 1 << 3 // move col |
|
1554 |
<< 40 << 40 // cell size |
|
1555 |
<< 20 << 20 << 80 << 80 // rect |
|
1556 |
<< int(QItemSelectionModel::Select) // command |
|
1557 |
<< 9; // selected count |
|
1558 |
} |
|
1559 |
||
1560 |
void tst_QTableView::selection() |
|
1561 |
{ |
|
1562 |
QFETCH(int, rowCount); |
|
1563 |
QFETCH(int, columnCount); |
|
1564 |
QFETCH(int, row); |
|
1565 |
QFETCH(int, column); |
|
1566 |
QFETCH(int, rowSpan); |
|
1567 |
QFETCH(int, columnSpan); |
|
1568 |
QFETCH(int, hideRow); |
|
1569 |
QFETCH(int, hideColumn); |
|
1570 |
QFETCH(int, moveRowFrom); |
|
1571 |
QFETCH(int, moveRowTo); |
|
1572 |
QFETCH(int, moveColumnFrom); |
|
1573 |
QFETCH(int, moveColumnTo); |
|
1574 |
QFETCH(int, rowHeight); |
|
1575 |
QFETCH(int, columnWidth); |
|
1576 |
QFETCH(int, x); |
|
1577 |
QFETCH(int, y); |
|
1578 |
QFETCH(int, width); |
|
1579 |
QFETCH(int, height); |
|
1580 |
QFETCH(int, command); |
|
1581 |
QFETCH(int, selectedCount); |
|
1582 |
||
1583 |
QtTestTableModel model(rowCount, columnCount); |
|
1584 |
||
1585 |
QtTestTableView view; |
|
1586 |
view.show(); |
|
1587 |
view.setModel(&model); |
|
1588 |
||
1589 |
view.setSpan(row, column, rowSpan, columnSpan); |
|
1590 |
||
1591 |
view.hideRow(hideRow); |
|
1592 |
view.hideColumn(hideColumn); |
|
1593 |
||
1594 |
view.verticalHeader()->moveSection(moveRowFrom, moveRowTo); |
|
1595 |
view.horizontalHeader()->moveSection(moveColumnFrom, moveColumnTo); |
|
1596 |
||
1597 |
for (int r = 0; r < rowCount; ++r) |
|
1598 |
view.setRowHeight(r, rowHeight); |
|
1599 |
for (int c = 0; c < columnCount; ++c) |
|
1600 |
view.setColumnWidth(c, columnWidth); |
|
1601 |
||
1602 |
view.setSelection(QRect(x, y, width, height), |
|
1603 |
QItemSelectionModel::SelectionFlags(command)); |
|
1604 |
||
1605 |
QCOMPARE(view.selectedIndexes().count(), selectedCount); |
|
1606 |
} |
|
1607 |
||
1608 |
void tst_QTableView::selectRow_data() |
|
1609 |
{ |
|
1610 |
QTest::addColumn<int>("rowCount"); |
|
1611 |
QTest::addColumn<int>("columnCount"); |
|
1612 |
QTest::addColumn<int>("row"); |
|
1613 |
QTest::addColumn<int>("mode"); |
|
1614 |
QTest::addColumn<int>("behavior"); |
|
1615 |
QTest::addColumn<int>("selectedItems"); |
|
1616 |
||
1617 |
QTest::newRow("SingleSelection and SelectItems") |
|
1618 |
<< 10 << 10 |
|
1619 |
<< 0 |
|
1620 |
<< (int)QAbstractItemView::SingleSelection |
|
1621 |
<< (int)QAbstractItemView::SelectItems |
|
1622 |
<< 0; |
|
1623 |
||
1624 |
QTest::newRow("SingleSelection and SelectRows") |
|
1625 |
<< 10 << 10 |
|
1626 |
<< 0 |
|
1627 |
<< (int)QAbstractItemView::SingleSelection |
|
1628 |
<< (int)QAbstractItemView::SelectRows |
|
1629 |
<< 10; |
|
1630 |
||
1631 |
QTest::newRow("SingleSelection and SelectColumns") |
|
1632 |
<< 10 << 10 |
|
1633 |
<< 0 |
|
1634 |
<< (int)QAbstractItemView::SingleSelection |
|
1635 |
<< (int)QAbstractItemView::SelectColumns |
|
1636 |
<< 0; |
|
1637 |
||
1638 |
QTest::newRow("MultiSelection and SelectItems") |
|
1639 |
<< 10 << 10 |
|
1640 |
<< 0 |
|
1641 |
<< (int)QAbstractItemView::MultiSelection |
|
1642 |
<< (int)QAbstractItemView::SelectItems |
|
1643 |
<< 10; |
|
1644 |
||
1645 |
QTest::newRow("MultiSelection and SelectRows") |
|
1646 |
<< 10 << 10 |
|
1647 |
<< 0 |
|
1648 |
<< (int)QAbstractItemView::MultiSelection |
|
1649 |
<< (int)QAbstractItemView::SelectRows |
|
1650 |
<< 10; |
|
1651 |
||
1652 |
QTest::newRow("MultiSelection and SelectColumns") |
|
1653 |
<< 10 << 10 |
|
1654 |
<< 0 |
|
1655 |
<< (int)QAbstractItemView::MultiSelection |
|
1656 |
<< (int)QAbstractItemView::SelectColumns |
|
1657 |
<< 0; |
|
1658 |
||
1659 |
QTest::newRow("ExtendedSelection and SelectItems") |
|
1660 |
<< 10 << 10 |
|
1661 |
<< 0 |
|
1662 |
<< (int)QAbstractItemView::ExtendedSelection |
|
1663 |
<< (int)QAbstractItemView::SelectItems |
|
1664 |
<< 10; |
|
1665 |
||
1666 |
QTest::newRow("ExtendedSelection and SelectRows") |
|
1667 |
<< 10 << 10 |
|
1668 |
<< 0 |
|
1669 |
<< (int)QAbstractItemView::ExtendedSelection |
|
1670 |
<< (int)QAbstractItemView::SelectRows |
|
1671 |
<< 10; |
|
1672 |
||
1673 |
QTest::newRow("ExtendedSelection and SelectColumns") |
|
1674 |
<< 10 << 10 |
|
1675 |
<< 0 |
|
1676 |
<< (int)QAbstractItemView::ExtendedSelection |
|
1677 |
<< (int)QAbstractItemView::SelectColumns |
|
1678 |
<< 0; |
|
1679 |
||
1680 |
QTest::newRow("ContiguousSelection and SelectItems") |
|
1681 |
<< 10 << 10 |
|
1682 |
<< 0 |
|
1683 |
<< (int)QAbstractItemView::ContiguousSelection |
|
1684 |
<< (int)QAbstractItemView::SelectItems |
|
1685 |
<< 10; |
|
1686 |
||
1687 |
QTest::newRow("ContiguousSelection and SelectRows") |
|
1688 |
<< 10 << 10 |
|
1689 |
<< 0 |
|
1690 |
<< (int)QAbstractItemView::ContiguousSelection |
|
1691 |
<< (int)QAbstractItemView::SelectRows |
|
1692 |
<< 10; |
|
1693 |
||
1694 |
QTest::newRow("ContiguousSelection and SelectColumns") |
|
1695 |
<< 10 << 10 |
|
1696 |
<< 0 |
|
1697 |
<< (int)QAbstractItemView::ContiguousSelection |
|
1698 |
<< (int)QAbstractItemView::SelectColumns |
|
1699 |
<< 0; |
|
1700 |
} |
|
1701 |
||
1702 |
void tst_QTableView::selectRow() |
|
1703 |
{ |
|
1704 |
QFETCH(int, rowCount); |
|
1705 |
QFETCH(int, columnCount); |
|
1706 |
QFETCH(int, row); |
|
1707 |
QFETCH(int, mode); |
|
1708 |
QFETCH(int, behavior); |
|
1709 |
QFETCH(int, selectedItems); |
|
1710 |
||
1711 |
QtTestTableModel model(rowCount, columnCount); |
|
1712 |
QTableView view; |
|
1713 |
||
1714 |
view.setModel(&model); |
|
1715 |
view.setSelectionMode((QAbstractItemView::SelectionMode)mode); |
|
1716 |
view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior); |
|
1717 |
||
1718 |
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0); |
|
1719 |
||
1720 |
view.selectRow(row); |
|
1721 |
||
1722 |
//test we have 10 items selected |
|
1723 |
QCOMPARE(view.selectionModel()->selectedIndexes().count(), selectedItems); |
|
1724 |
//test that all 10 items are in the same row |
|
1725 |
for (int i = 0; selectedItems > 0 && i < rowCount; ++i) |
|
1726 |
QCOMPARE(view.selectionModel()->selectedIndexes().at(i).row(), row); |
|
1727 |
} |
|
1728 |
||
1729 |
void tst_QTableView::selectColumn_data() |
|
1730 |
{ |
|
1731 |
QTest::addColumn<int>("rowCount"); |
|
1732 |
QTest::addColumn<int>("columnCount"); |
|
1733 |
QTest::addColumn<int>("column"); |
|
1734 |
QTest::addColumn<int>("mode"); |
|
1735 |
QTest::addColumn<int>("behavior"); |
|
1736 |
QTest::addColumn<int>("selectedItems"); |
|
1737 |
||
1738 |
QTest::newRow("SingleSelection and SelectItems") |
|
1739 |
<< 10 << 10 |
|
1740 |
<< 0 |
|
1741 |
<< (int)QAbstractItemView::SingleSelection |
|
1742 |
<< (int)QAbstractItemView::SelectItems |
|
1743 |
<< 0; |
|
1744 |
||
1745 |
QTest::newRow("SingleSelection and SelectRows") |
|
1746 |
<< 10 << 10 |
|
1747 |
<< 0 |
|
1748 |
<< (int)QAbstractItemView::SingleSelection |
|
1749 |
<< (int)QAbstractItemView::SelectRows |
|
1750 |
<< 0; |
|
1751 |
||
1752 |
QTest::newRow("SingleSelection and SelectColumns") |
|
1753 |
<< 10 << 10 |
|
1754 |
<< 0 |
|
1755 |
<< (int)QAbstractItemView::SingleSelection |
|
1756 |
<< (int)QAbstractItemView::SelectColumns |
|
1757 |
<< 10; |
|
1758 |
||
1759 |
QTest::newRow("MultiSelection and SelectItems") |
|
1760 |
<< 10 << 10 |
|
1761 |
<< 0 |
|
1762 |
<< (int)QAbstractItemView::MultiSelection |
|
1763 |
<< (int)QAbstractItemView::SelectItems |
|
1764 |
<< 10; |
|
1765 |
||
1766 |
QTest::newRow("MultiSelection and SelectRows") |
|
1767 |
<< 10 << 10 |
|
1768 |
<< 0 |
|
1769 |
<< (int)QAbstractItemView::MultiSelection |
|
1770 |
<< (int)QAbstractItemView::SelectRows |
|
1771 |
<< 0; |
|
1772 |
||
1773 |
QTest::newRow("MultiSelection and SelectColumns") |
|
1774 |
<< 10 << 10 |
|
1775 |
<< 0 |
|
1776 |
<< (int)QAbstractItemView::MultiSelection |
|
1777 |
<< (int)QAbstractItemView::SelectColumns |
|
1778 |
<< 10; |
|
1779 |
||
1780 |
QTest::newRow("ExtendedSelection and SelectItems") |
|
1781 |
<< 10 << 10 |
|
1782 |
<< 0 |
|
1783 |
<< (int)QAbstractItemView::ExtendedSelection |
|
1784 |
<< (int)QAbstractItemView::SelectItems |
|
1785 |
<< 10; |
|
1786 |
||
1787 |
QTest::newRow("ExtendedSelection and SelectRows") |
|
1788 |
<< 10 << 10 |
|
1789 |
<< 0 |
|
1790 |
<< (int)QAbstractItemView::ExtendedSelection |
|
1791 |
<< (int)QAbstractItemView::SelectRows |
|
1792 |
<< 0; |
|
1793 |
||
1794 |
QTest::newRow("ExtendedSelection and SelectColumns") |
|
1795 |
<< 10 << 10 |
|
1796 |
<< 0 |
|
1797 |
<< (int)QAbstractItemView::ExtendedSelection |
|
1798 |
<< (int)QAbstractItemView::SelectColumns |
|
1799 |
<< 10; |
|
1800 |
||
1801 |
QTest::newRow("ContiguousSelection and SelectItems") |
|
1802 |
<< 10 << 10 |
|
1803 |
<< 0 |
|
1804 |
<< (int)QAbstractItemView::ContiguousSelection |
|
1805 |
<< (int)QAbstractItemView::SelectItems |
|
1806 |
<< 10; |
|
1807 |
||
1808 |
QTest::newRow("ContiguousSelection and SelectRows") |
|
1809 |
<< 10 << 10 |
|
1810 |
<< 0 |
|
1811 |
<< (int)QAbstractItemView::ContiguousSelection |
|
1812 |
<< (int)QAbstractItemView::SelectRows |
|
1813 |
<< 0; |
|
1814 |
||
1815 |
QTest::newRow("ContiguousSelection and SelectColumns") |
|
1816 |
<< 10 << 10 |
|
1817 |
<< 0 |
|
1818 |
<< (int)QAbstractItemView::ContiguousSelection |
|
1819 |
<< (int)QAbstractItemView::SelectColumns |
|
1820 |
<< 10; |
|
1821 |
} |
|
1822 |
||
1823 |
void tst_QTableView::selectColumn() |
|
1824 |
{ |
|
1825 |
QFETCH(int, rowCount); |
|
1826 |
QFETCH(int, columnCount); |
|
1827 |
QFETCH(int, column); |
|
1828 |
QFETCH(int, mode); |
|
1829 |
QFETCH(int, behavior); |
|
1830 |
QFETCH(int, selectedItems); |
|
1831 |
||
1832 |
QtTestTableModel model(rowCount, columnCount); |
|
1833 |
||
1834 |
QTableView view; |
|
1835 |
view.setModel(&model); |
|
1836 |
view.setSelectionMode((QAbstractItemView::SelectionMode)mode); |
|
1837 |
view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior); |
|
1838 |
||
1839 |
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0); |
|
1840 |
||
1841 |
view.selectColumn(column); |
|
1842 |
||
1843 |
QCOMPARE(view.selectionModel()->selectedIndexes().count(), selectedItems); |
|
1844 |
for (int i = 0; selectedItems > 0 && i < columnCount; ++i) |
|
1845 |
QCOMPARE(view.selectionModel()->selectedIndexes().at(i).column(), column); |
|
1846 |
} |
|
1847 |
||
1848 |
Q_DECLARE_METATYPE(QRect) |
|
1849 |
void tst_QTableView::visualRect_data() |
|
1850 |
{ |
|
1851 |
QTest::addColumn<int>("rowCount"); |
|
1852 |
QTest::addColumn<int>("columnCount"); |
|
1853 |
QTest::addColumn<int>("hideRow"); |
|
1854 |
QTest::addColumn<int>("hideColumn"); |
|
1855 |
QTest::addColumn<int>("row"); |
|
1856 |
QTest::addColumn<int>("column"); |
|
1857 |
QTest::addColumn<int>("rowHeight"); |
|
1858 |
QTest::addColumn<int>("columnWidth"); |
|
1859 |
QTest::addColumn<QRect>("expectedRect"); |
|
1860 |
||
1861 |
QTest::newRow("(0,0)") |
|
1862 |
<< 10 << 10 |
|
1863 |
<< -1 << -1 |
|
1864 |
<< 0 << 0 |
|
1865 |
<< 20 << 30 |
|
1866 |
<< QRect(0, 0, 29, 19); |
|
1867 |
||
1868 |
QTest::newRow("(0,0) hidden row") |
|
1869 |
<< 10 << 10 |
|
1870 |
<< 0 << -1 |
|
1871 |
<< 0 << 0 |
|
1872 |
<< 20 << 30 |
|
1873 |
<< QRect(); |
|
1874 |
||
1875 |
QTest::newRow("(0,0) hidden column") |
|
1876 |
<< 10 << 10 |
|
1877 |
<< -1 << 0 |
|
1878 |
<< 0 << 0 |
|
1879 |
<< 20 << 30 |
|
1880 |
<< QRect(); |
|
1881 |
||
1882 |
QTest::newRow("(0,0) hidden row and column") |
|
1883 |
<< 10 << 10 |
|
1884 |
<< 0 << 0 |
|
1885 |
<< 0 << 0 |
|
1886 |
<< 20 << 30 |
|
1887 |
<< QRect(); |
|
1888 |
||
1889 |
QTest::newRow("(0,0) out of bounds") |
|
1890 |
<< 10 << 10 |
|
1891 |
<< -1 << -1 |
|
1892 |
<< 20 << 20 |
|
1893 |
<< 20 << 30 |
|
1894 |
<< QRect(); |
|
1895 |
||
1896 |
QTest::newRow("(5,5), hidden row") |
|
1897 |
<< 10 << 10 |
|
1898 |
<< 5 << -1 |
|
1899 |
<< 5 << 5 |
|
1900 |
<< 20 << 30 |
|
1901 |
<< QRect(); |
|
1902 |
||
1903 |
QTest::newRow("(9,9)") |
|
1904 |
<< 10 << 10 |
|
1905 |
<< -1 << -1 |
|
1906 |
<< 9 << 9 |
|
1907 |
<< 20 << 30 |
|
1908 |
<< QRect(30*9, 20*9, 29, 19); |
|
1909 |
} |
|
1910 |
||
1911 |
void tst_QTableView::visualRect() |
|
1912 |
{ |
|
1913 |
QFETCH(int, rowCount); |
|
1914 |
QFETCH(int, columnCount); |
|
1915 |
QFETCH(int, hideRow); |
|
1916 |
QFETCH(int, hideColumn); |
|
1917 |
QFETCH(int, row); |
|
1918 |
QFETCH(int, column); |
|
1919 |
QFETCH(int, rowHeight); |
|
1920 |
QFETCH(int, columnWidth); |
|
1921 |
QFETCH(QRect, expectedRect); |
|
1922 |
||
1923 |
QtTestTableModel model(rowCount, columnCount); |
|
1924 |
||
1925 |
QTableView view; |
|
1926 |
view.setModel(&model); |
|
1927 |
// Make sure that it has 1 pixel between each cell. |
|
1928 |
view.setGridStyle(Qt::SolidLine); |
|
1929 |
for (int i = 0; i < view.verticalHeader()->count(); ++i) |
|
1930 |
view.verticalHeader()->resizeSection(i, rowHeight); |
|
1931 |
for (int i = 0; i < view.horizontalHeader()->count(); ++i) |
|
1932 |
view.horizontalHeader()->resizeSection(i, columnWidth); |
|
1933 |
||
1934 |
view.hideRow(hideRow); |
|
1935 |
view.hideColumn(hideColumn); |
|
1936 |
||
1937 |
QRect rect = view.visualRect(model.index(row, column)); |
|
1938 |
QCOMPARE(rect, expectedRect); |
|
1939 |
} |
|
1940 |
||
1941 |
void tst_QTableView::fetchMore() |
|
1942 |
{ |
|
1943 |
QtTestTableModel model(64, 64); |
|
1944 |
||
1945 |
model.can_fetch_more = true; |
|
1946 |
||
1947 |
QTableView view; |
|
1948 |
view.setModel(&model); |
|
1949 |
view.show(); |
|
1950 |
||
1951 |
QCOMPARE(model.fetch_more_count, 0); |
|
1952 |
view.verticalScrollBar()->setValue(view.verticalScrollBar()->maximum()); |
|
1953 |
QVERIFY(model.fetch_more_count > 0); |
|
1954 |
||
1955 |
model.fetch_more_count = 0; //reset |
|
1956 |
view.scrollToTop(); |
|
1957 |
QCOMPARE(model.fetch_more_count, 0); |
|
1958 |
||
1959 |
view.scrollToBottom(); |
|
1960 |
QVERIFY(model.fetch_more_count > 0); |
|
1961 |
||
1962 |
model.fetch_more_count = 0; //reset |
|
1963 |
view.scrollToTop(); |
|
1964 |
view.setCurrentIndex(model.index(0, 0)); |
|
1965 |
QCOMPARE(model.fetch_more_count, 0); |
|
1966 |
||
1967 |
for (int i = 0; i < 64; ++i) |
|
1968 |
QTest::keyClick(&view, Qt::Key_Down); |
|
1969 |
QCOMPARE(view.currentIndex(), model.index(63, 0)); |
|
1970 |
QVERIFY(model.fetch_more_count > 0); |
|
1971 |
} |
|
1972 |
||
1973 |
void tst_QTableView::setHeaders() |
|
1974 |
{ |
|
1975 |
QTableView view; |
|
1976 |
||
1977 |
// Make sure we don't delete ourselves |
|
1978 |
view.setVerticalHeader(view.verticalHeader()); |
|
1979 |
view.verticalHeader()->count(); |
|
1980 |
view.setHorizontalHeader(view.horizontalHeader()); |
|
1981 |
view.horizontalHeader()->count(); |
|
1982 |
||
1983 |
// Try passing around a header without it being deleted |
|
1984 |
QTableView view2; |
|
1985 |
view2.setVerticalHeader(view.verticalHeader()); |
|
1986 |
view2.setHorizontalHeader(view.horizontalHeader()); |
|
1987 |
view.setHorizontalHeader(new QHeaderView(Qt::Horizontal)); |
|
1988 |
view.setVerticalHeader(new QHeaderView(Qt::Vertical)); |
|
1989 |
view2.verticalHeader()->count(); |
|
1990 |
view2.horizontalHeader()->count(); |
|
1991 |
||
1992 |
} |
|
1993 |
||
1994 |
void tst_QTableView::resizeRowsToContents_data() |
|
1995 |
{ |
|
1996 |
QTest::addColumn<int>("rowCount"); |
|
1997 |
QTest::addColumn<int>("columnCount"); |
|
1998 |
QTest::addColumn<bool>("showGrid"); |
|
1999 |
QTest::addColumn<int>("cellWidth"); |
|
2000 |
QTest::addColumn<int>("cellHeight"); |
|
2001 |
QTest::addColumn<int>("rowHeight"); |
|
2002 |
QTest::addColumn<int>("columnWidth"); |
|
2003 |
||
2004 |
QTest::newRow("10x10 grid shown 40x40") |
|
2005 |
<< 10 << 10 << false << 40 << 40 << 40 << 40; |
|
2006 |
||
2007 |
QTest::newRow("10x10 grid not shown 40x40") |
|
2008 |
<< 10 << 10 << true << 40 << 40 << 41 << 41; |
|
2009 |
} |
|
2010 |
||
2011 |
void tst_QTableView::resizeRowsToContents() |
|
2012 |
{ |
|
2013 |
QFETCH(int, rowCount); |
|
2014 |
QFETCH(int, columnCount); |
|
2015 |
QFETCH(bool, showGrid); |
|
2016 |
QFETCH(int, cellWidth); |
|
2017 |
QFETCH(int, cellHeight); |
|
2018 |
QFETCH(int, rowHeight); |
|
2019 |
QFETCH(int, columnWidth); |
|
2020 |
Q_UNUSED(columnWidth); |
|
2021 |
||
2022 |
QtTestTableModel model(rowCount, columnCount); |
|
2023 |
QtTestTableView view; |
|
2024 |
QtTestItemDelegate delegate; |
|
2025 |
||
2026 |
view.setModel(&model); |
|
2027 |
view.setItemDelegate(&delegate); |
|
2028 |
view.setShowGrid(showGrid); // the grid will add to the row height |
|
2029 |
||
2030 |
delegate.hint = QSize(cellWidth, cellHeight); |
|
2031 |
||
2032 |
QSignalSpy resizedSpy(view.verticalHeader(), SIGNAL(sectionResized(int, int, int))); |
|
2033 |
view.resizeRowsToContents(); |
|
2034 |
||
2035 |
QCOMPARE(resizedSpy.count(), model.rowCount()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2036 |
for (int r = 0; r < model.rowCount(); ++r) { |
0 | 2037 |
QCOMPARE(view.rowHeight(r), rowHeight); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2038 |
} |
0 | 2039 |
} |
2040 |
||
2041 |
void tst_QTableView::resizeColumnsToContents_data() |
|
2042 |
{ |
|
2043 |
QTest::addColumn<int>("rowCount"); |
|
2044 |
QTest::addColumn<int>("columnCount"); |
|
2045 |
QTest::addColumn<bool>("showGrid"); |
|
2046 |
QTest::addColumn<int>("cellWidth"); |
|
2047 |
QTest::addColumn<int>("cellHeight"); |
|
2048 |
QTest::addColumn<int>("rowHeight"); |
|
2049 |
QTest::addColumn<int>("columnWidth"); |
|
2050 |
||
2051 |
QTest::newRow("10x10 grid shown 40x40") |
|
2052 |
<< 10 << 10 << false << 40 << 40 << 40 << 40; |
|
2053 |
||
2054 |
QTest::newRow("10x10 grid not shown 40x40") |
|
2055 |
<< 10 << 10 << true << 40 << 40 << 41 << 41; |
|
2056 |
} |
|
2057 |
||
2058 |
void tst_QTableView::resizeColumnsToContents() |
|
2059 |
{ |
|
2060 |
QFETCH(int, rowCount); |
|
2061 |
QFETCH(int, columnCount); |
|
2062 |
QFETCH(bool, showGrid); |
|
2063 |
QFETCH(int, cellWidth); |
|
2064 |
QFETCH(int, cellHeight); |
|
2065 |
QFETCH(int, rowHeight); |
|
2066 |
QFETCH(int, columnWidth); |
|
2067 |
Q_UNUSED(rowHeight); |
|
2068 |
||
2069 |
QtTestTableModel model(rowCount, columnCount); |
|
2070 |
QtTestTableView view; |
|
2071 |
QtTestItemDelegate delegate; |
|
2072 |
||
2073 |
view.setModel(&model); |
|
2074 |
view.setItemDelegate(&delegate); |
|
2075 |
view.setShowGrid(showGrid); // the grid will add to the row height |
|
2076 |
||
2077 |
delegate.hint = QSize(cellWidth, cellHeight); |
|
2078 |
||
2079 |
QSignalSpy resizedSpy(view.horizontalHeader(), SIGNAL(sectionResized(int, int, int))); |
|
2080 |
view.resizeColumnsToContents(); |
|
2081 |
||
2082 |
QCOMPARE(resizedSpy.count(), model.columnCount()); |
|
2083 |
for (int c = 0; c < model.columnCount(); ++c) |
|
2084 |
QCOMPARE(view.columnWidth(c), columnWidth); |
|
2085 |
} |
|
2086 |
||
2087 |
void tst_QTableView::rowViewportPosition_data() |
|
2088 |
{ |
|
2089 |
QTest::addColumn<int>("rowCount"); |
|
2090 |
QTest::addColumn<int>("rowHeight"); |
|
2091 |
QTest::addColumn<int>("row"); |
|
2092 |
QTest::addColumn<int>("verticalScrollMode"); |
|
2093 |
QTest::addColumn<int>("verticalScrollValue"); |
|
2094 |
QTest::addColumn<int>("rowViewportPosition"); |
|
2095 |
||
2096 |
QTest::newRow("row 0, scroll per item 0") |
|
2097 |
<< 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0; |
|
2098 |
||
2099 |
QTest::newRow("row 1, scroll per item, 0") |
|
2100 |
<< 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40; |
|
2101 |
||
2102 |
QTest::newRow("row 1, scroll per item, 1") |
|
2103 |
<< 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0; |
|
2104 |
||
2105 |
QTest::newRow("row 5, scroll per item, 0") |
|
2106 |
<< 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40; |
|
2107 |
||
2108 |
QTest::newRow("row 5, scroll per item, 5") |
|
2109 |
<< 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0; |
|
2110 |
||
2111 |
QTest::newRow("row 9, scroll per item, 0") |
|
2112 |
<< 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40; |
|
2113 |
||
2114 |
QTest::newRow("row 9, scroll per item, 5") |
|
2115 |
<< 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40; |
|
2116 |
||
2117 |
QTest::newRow("row 0, scroll per pixel 0") |
|
2118 |
<< 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0; |
|
2119 |
||
2120 |
QTest::newRow("row 1, scroll per pixel, 0") |
|
2121 |
<< 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40; |
|
2122 |
||
2123 |
QTest::newRow("row 1, scroll per pixel, 1") |
|
2124 |
<< 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0; |
|
2125 |
||
2126 |
QTest::newRow("row 5, scroll per pixel, 0") |
|
2127 |
<< 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40; |
|
2128 |
||
2129 |
QTest::newRow("row 5, scroll per pixel, 5") |
|
2130 |
<< 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0; |
|
2131 |
||
2132 |
QTest::newRow("row 9, scroll per pixel, 0") |
|
2133 |
<< 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40; |
|
2134 |
||
2135 |
QTest::newRow("row 9, scroll per pixel, 5") |
|
2136 |
<< 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40; |
|
2137 |
} |
|
2138 |
||
2139 |
void tst_QTableView::rowViewportPosition() |
|
2140 |
{ |
|
2141 |
QFETCH(int, rowCount); |
|
2142 |
QFETCH(int, rowHeight); |
|
2143 |
QFETCH(int, row); |
|
2144 |
QFETCH(int, verticalScrollMode); |
|
2145 |
QFETCH(int, verticalScrollValue); |
|
2146 |
QFETCH(int, rowViewportPosition); |
|
2147 |
||
2148 |
QtTestTableModel model(rowCount, 1); |
|
2149 |
QtTestTableView view; |
|
2150 |
view.resize(100, 2 * rowHeight); |
|
2151 |
view.show(); |
|
2152 |
||
2153 |
view.setModel(&model); |
|
2154 |
for (int r = 0; r < rowCount; ++r) |
|
2155 |
view.setRowHeight(r, rowHeight); |
|
2156 |
||
2157 |
view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode); |
|
2158 |
view.verticalScrollBar()->setValue(verticalScrollValue); |
|
2159 |
||
2160 |
QCOMPARE(view.rowViewportPosition(row), rowViewportPosition); |
|
2161 |
} |
|
2162 |
||
2163 |
void tst_QTableView::rowAt_data() |
|
2164 |
{ |
|
2165 |
QTest::addColumn<int>("rowCount"); |
|
2166 |
QTest::addColumn<int>("rowHeight"); |
|
2167 |
QTest::addColumn<IntList>("hiddenRows"); |
|
2168 |
QTest::addColumn<int>("coordinate"); |
|
2169 |
QTest::addColumn<int>("row"); |
|
2170 |
||
2171 |
QTest::newRow("row at 100") << 5 << 40 << IntList() << 100 << 2; |
|
2172 |
QTest::newRow("row at 180") << 5 << 40 << IntList() << 180 << 4; |
|
2173 |
QTest::newRow("row at 20") << 5 << 40 << IntList() << 20 << 0; |
|
2174 |
||
2175 |
// ### expand the dataset to include hidden rows |
|
2176 |
} |
|
2177 |
||
2178 |
void tst_QTableView::rowAt() |
|
2179 |
{ |
|
2180 |
QFETCH(int, rowCount); |
|
2181 |
QFETCH(int, rowHeight); |
|
2182 |
QFETCH(IntList, hiddenRows); |
|
2183 |
QFETCH(int, coordinate); |
|
2184 |
QFETCH(int, row); |
|
2185 |
||
2186 |
QtTestTableModel model(rowCount, 1); |
|
2187 |
QtTestTableView view; |
|
2188 |
view.resize(100, 2 * rowHeight); |
|
2189 |
||
2190 |
view.setModel(&model); |
|
2191 |
||
2192 |
for (int r = 0; r < rowCount; ++r) |
|
2193 |
view.setRowHeight(r, rowHeight); |
|
2194 |
||
2195 |
for (int i = 0; i < hiddenRows.count(); ++i) |
|
2196 |
view.hideRow(hiddenRows.at(i)); |
|
2197 |
||
2198 |
QCOMPARE(view.rowAt(coordinate), row); |
|
2199 |
} |
|
2200 |
||
2201 |
void tst_QTableView::rowHeight_data() |
|
2202 |
{ |
|
2203 |
QTest::addColumn<int>("rowCount"); |
|
2204 |
QTest::addColumn<IntList>("rowHeights"); |
|
2205 |
QTest::addColumn<BoolList>("hiddenRows"); |
|
2206 |
||
2207 |
QTest::newRow("increasing") |
|
2208 |
<< 5 |
|
2209 |
<< (IntList() << 20 << 30 << 40 << 50 << 60) |
|
2210 |
<< (BoolList() << false << false << false << false << false); |
|
2211 |
||
2212 |
QTest::newRow("decreasing") |
|
2213 |
<< 5 |
|
2214 |
<< (IntList() << 60 << 50 << 40 << 30 << 20) |
|
2215 |
<< (BoolList() << false << false << false << false << false); |
|
2216 |
||
2217 |
QTest::newRow("random") |
|
2218 |
<< 5 |
|
2219 |
<< (IntList() << 87 << 34 << 68 << 91 << 27) |
|
2220 |
<< (BoolList() << false << false << false << false << false); |
|
2221 |
||
2222 |
// ### expand the dataset to include hidden rows |
|
2223 |
} |
|
2224 |
||
2225 |
void tst_QTableView::rowHeight() |
|
2226 |
{ |
|
2227 |
QFETCH(int, rowCount); |
|
2228 |
QFETCH(IntList, rowHeights); |
|
2229 |
QFETCH(BoolList, hiddenRows); |
|
2230 |
||
2231 |
QtTestTableModel model(rowCount, 1); |
|
2232 |
QtTestTableView view; |
|
2233 |
||
2234 |
view.setModel(&model); |
|
2235 |
||
2236 |
for (int r = 0; r < rowCount; ++r) { |
|
2237 |
view.setRowHeight(r, rowHeights.at(r)); |
|
2238 |
view.setRowHidden(r, hiddenRows.at(r)); |
|
2239 |
} |
|
2240 |
||
2241 |
for (int r = 0; r < rowCount; ++r) { |
|
2242 |
if (hiddenRows.at(r)) |
|
2243 |
QCOMPARE(view.rowHeight(r), 0); |
|
2244 |
else |
|
2245 |
QCOMPARE(view.rowHeight(r), rowHeights.at(r)); |
|
2246 |
} |
|
2247 |
} |
|
2248 |
||
2249 |
void tst_QTableView::columnViewportPosition_data() |
|
2250 |
{ |
|
2251 |
QTest::addColumn<int>("columnCount"); |
|
2252 |
QTest::addColumn<int>("columnWidth"); |
|
2253 |
QTest::addColumn<int>("column"); |
|
2254 |
QTest::addColumn<int>("horizontalScrollMode"); |
|
2255 |
QTest::addColumn<int>("horizontalScrollValue"); |
|
2256 |
QTest::addColumn<int>("columnViewportPosition"); |
|
2257 |
||
2258 |
QTest::newRow("column 0, scroll per item 0") |
|
2259 |
<< 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0; |
|
2260 |
||
2261 |
QTest::newRow("column 1, scroll per item, 0") |
|
2262 |
<< 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40; |
|
2263 |
||
2264 |
QTest::newRow("column 1, scroll per item, 1") |
|
2265 |
<< 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0; |
|
2266 |
||
2267 |
QTest::newRow("column 5, scroll per item, 0") |
|
2268 |
<< 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40; |
|
2269 |
||
2270 |
QTest::newRow("column 5, scroll per item, 5") |
|
2271 |
<< 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0; |
|
2272 |
||
2273 |
QTest::newRow("column 9, scroll per item, 0") |
|
2274 |
<< 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40; |
|
2275 |
||
2276 |
QTest::newRow("column 9, scroll per item, 5") |
|
2277 |
<< 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40; |
|
2278 |
||
2279 |
QTest::newRow("column 0, scroll per pixel 0") |
|
2280 |
<< 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0; |
|
2281 |
||
2282 |
QTest::newRow("column 1, scroll per pixel 0") |
|
2283 |
<< 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40; |
|
2284 |
||
2285 |
QTest::newRow("column 1, scroll per pixel 1") |
|
2286 |
<< 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0; |
|
2287 |
||
2288 |
QTest::newRow("column 5, scroll per pixel 0") |
|
2289 |
<< 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40; |
|
2290 |
||
2291 |
QTest::newRow("column 5, scroll per pixel 5") |
|
2292 |
<< 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0; |
|
2293 |
||
2294 |
QTest::newRow("column 9, scroll per pixel 0") |
|
2295 |
<< 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40; |
|
2296 |
||
2297 |
QTest::newRow("column 9, scroll per pixel 5") |
|
2298 |
<< 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40; |
|
2299 |
} |
|
2300 |
||
2301 |
void tst_QTableView::columnViewportPosition() |
|
2302 |
{ |
|
2303 |
QFETCH(int, columnCount); |
|
2304 |
QFETCH(int, columnWidth); |
|
2305 |
QFETCH(int, column); |
|
2306 |
QFETCH(int, horizontalScrollMode); |
|
2307 |
QFETCH(int, horizontalScrollValue); |
|
2308 |
QFETCH(int, columnViewportPosition); |
|
2309 |
||
2310 |
QtTestTableModel model(1, columnCount); |
|
2311 |
QtTestTableView view; |
|
2312 |
view.resize(2 * columnWidth, 100); |
|
2313 |
view.show(); |
|
2314 |
||
2315 |
view.setModel(&model); |
|
2316 |
for (int c = 0; c < columnCount; ++c) |
|
2317 |
view.setColumnWidth(c, columnWidth); |
|
2318 |
||
2319 |
view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode); |
|
2320 |
view.horizontalScrollBar()->setValue(horizontalScrollValue); |
|
2321 |
||
2322 |
QCOMPARE(view.columnViewportPosition(column), columnViewportPosition); |
|
2323 |
} |
|
2324 |
||
2325 |
void tst_QTableView::columnAt_data() |
|
2326 |
{ |
|
2327 |
QTest::addColumn<int>("columnCount"); |
|
2328 |
QTest::addColumn<int>("columnWidth"); |
|
2329 |
QTest::addColumn<IntList>("hiddenColumns"); |
|
2330 |
QTest::addColumn<int>("coordinate"); |
|
2331 |
QTest::addColumn<int>("column"); |
|
2332 |
||
2333 |
QTest::newRow("column at 100") << 5 << 40 << IntList() << 100 << 2; |
|
2334 |
QTest::newRow("column at 180") << 5 << 40 << IntList() << 180 << 4; |
|
2335 |
QTest::newRow("column at 20") << 5 << 40 << IntList() << 20 << 0; |
|
2336 |
||
2337 |
// ### expand the dataset to include hidden coumns |
|
2338 |
} |
|
2339 |
||
2340 |
void tst_QTableView::columnAt() |
|
2341 |
{ |
|
2342 |
QFETCH(int, columnCount); |
|
2343 |
QFETCH(int, columnWidth); |
|
2344 |
QFETCH(IntList, hiddenColumns); |
|
2345 |
QFETCH(int, coordinate); |
|
2346 |
QFETCH(int, column); |
|
2347 |
||
2348 |
QtTestTableModel model(1, columnCount); |
|
2349 |
QtTestTableView view; |
|
2350 |
view.resize(2 * columnWidth, 100); |
|
2351 |
||
2352 |
view.setModel(&model); |
|
2353 |
||
2354 |
for (int c = 0; c < columnCount; ++c) |
|
2355 |
view.setColumnWidth(c, columnWidth); |
|
2356 |
||
2357 |
for (int i = 0; i < hiddenColumns.count(); ++i) |
|
2358 |
view.hideColumn(hiddenColumns.at(i)); |
|
2359 |
||
2360 |
QCOMPARE(view.columnAt(coordinate), column); |
|
2361 |
} |
|
2362 |
||
2363 |
void tst_QTableView::columnWidth_data() |
|
2364 |
{ |
|
2365 |
QTest::addColumn<int>("columnCount"); |
|
2366 |
QTest::addColumn<IntList>("columnWidths"); |
|
2367 |
QTest::addColumn<BoolList>("hiddenColumns"); |
|
2368 |
||
2369 |
QTest::newRow("increasing") |
|
2370 |
<< 5 |
|
2371 |
<< (IntList() << 20 << 30 << 40 << 50 << 60) |
|
2372 |
<< (BoolList() << false << false << false << false << false); |
|
2373 |
||
2374 |
QTest::newRow("decreasing") |
|
2375 |
<< 5 |
|
2376 |
<< (IntList() << 60 << 50 << 40 << 30 << 20) |
|
2377 |
<< (BoolList() << false << false << false << false << false); |
|
2378 |
||
2379 |
QTest::newRow("random") |
|
2380 |
<< 5 |
|
2381 |
<< (IntList() << 87 << 34 << 68 << 91 << 27) |
|
2382 |
<< (BoolList() << false << false << false << false << false); |
|
2383 |
||
2384 |
// ### expand the dataset to include hidden columns |
|
2385 |
} |
|
2386 |
||
2387 |
void tst_QTableView::columnWidth() |
|
2388 |
{ |
|
2389 |
QFETCH(int, columnCount); |
|
2390 |
QFETCH(IntList, columnWidths); |
|
2391 |
QFETCH(BoolList, hiddenColumns); |
|
2392 |
||
2393 |
QtTestTableModel model(1, columnCount); |
|
2394 |
QtTestTableView view; |
|
2395 |
||
2396 |
view.setModel(&model); |
|
2397 |
||
2398 |
for (int c = 0; c < columnCount; ++c) { |
|
2399 |
view.setColumnWidth(c, columnWidths.at(c)); |
|
2400 |
view.setColumnHidden(c, hiddenColumns.at(c)); |
|
2401 |
} |
|
2402 |
||
2403 |
for (int c = 0; c < columnCount; ++c) { |
|
2404 |
if (hiddenColumns.at(c)) |
|
2405 |
QCOMPARE(view.columnWidth(c), 0); |
|
2406 |
else |
|
2407 |
QCOMPARE(view.columnWidth(c), columnWidths.at(c)); |
|
2408 |
} |
|
2409 |
} |
|
2410 |
||
2411 |
void tst_QTableView::hiddenRow_data() |
|
2412 |
{ |
|
2413 |
QTest::addColumn<int>("rowCount"); |
|
2414 |
QTest::addColumn<BoolList>("hiddenRows"); |
|
2415 |
||
2416 |
QTest::newRow("first hidden") |
|
2417 |
<< 5 << (BoolList() << true << false << false << false << false); |
|
2418 |
||
2419 |
QTest::newRow("last hidden") |
|
2420 |
<< 5 << (BoolList() << false << false << false << false << true); |
|
2421 |
||
2422 |
QTest::newRow("none hidden") |
|
2423 |
<< 5 << (BoolList() << false << false << false << false << false); |
|
2424 |
||
2425 |
QTest::newRow("all hidden") |
|
2426 |
<< 5 << (BoolList() << true << true << true << true << true); |
|
2427 |
} |
|
2428 |
||
2429 |
void tst_QTableView::hiddenRow() |
|
2430 |
{ |
|
2431 |
QFETCH(int, rowCount); |
|
2432 |
QFETCH(BoolList, hiddenRows); |
|
2433 |
||
2434 |
||
2435 |
QtTestTableModel model(rowCount, 1); |
|
2436 |
QtTestTableView view; |
|
2437 |
||
2438 |
view.setModel(&model); |
|
2439 |
||
2440 |
for (int r = 0; r < rowCount; ++r) |
|
2441 |
QVERIFY(!view.isRowHidden(r)); |
|
2442 |
||
2443 |
for (int r = 0; r < rowCount; ++r) |
|
2444 |
view.setRowHidden(r, hiddenRows.at(r)); |
|
2445 |
||
2446 |
for (int r = 0; r < rowCount; ++r) |
|
2447 |
QCOMPARE(view.isRowHidden(r), hiddenRows.at(r)); |
|
2448 |
||
2449 |
for (int r = 0; r < rowCount; ++r) |
|
2450 |
view.setRowHidden(r, false); |
|
2451 |
||
2452 |
for (int r = 0; r < rowCount; ++r) |
|
2453 |
QVERIFY(!view.isRowHidden(r)); |
|
2454 |
} |
|
2455 |
||
2456 |
void tst_QTableView::hiddenColumn_data() |
|
2457 |
{ |
|
2458 |
QTest::addColumn<int>("columnCount"); |
|
2459 |
QTest::addColumn<BoolList>("hiddenColumns"); |
|
2460 |
||
2461 |
QTest::newRow("first hidden") |
|
2462 |
<< 5 << (BoolList() << true << false << false << false << false); |
|
2463 |
||
2464 |
QTest::newRow("last hidden") |
|
2465 |
<< 5 << (BoolList() << false << false << false << false << true); |
|
2466 |
||
2467 |
QTest::newRow("none hidden") |
|
2468 |
<< 5 << (BoolList() << false << false << false << false << false); |
|
2469 |
||
2470 |
QTest::newRow("all hidden") |
|
2471 |
<< 5 << (BoolList() << true << true << true << true << true); |
|
2472 |
} |
|
2473 |
||
2474 |
void tst_QTableView::hiddenColumn() |
|
2475 |
{ |
|
2476 |
QFETCH(int, columnCount); |
|
2477 |
QFETCH(BoolList, hiddenColumns); |
|
2478 |
||
2479 |
QtTestTableModel model(1, columnCount); |
|
2480 |
QtTestTableView view; |
|
2481 |
||
2482 |
view.setModel(&model); |
|
2483 |
||
2484 |
for (int c = 0; c < columnCount; ++c) |
|
2485 |
QVERIFY(!view.isColumnHidden(c)); |
|
2486 |
||
2487 |
for (int c = 0; c < columnCount; ++c) |
|
2488 |
view.setColumnHidden(c, hiddenColumns.at(c)); |
|
2489 |
||
2490 |
for (int c = 0; c < columnCount; ++c) |
|
2491 |
QCOMPARE(view.isColumnHidden(c), hiddenColumns.at(c)); |
|
2492 |
||
2493 |
for (int c = 0; c < columnCount; ++c) |
|
2494 |
view.setColumnHidden(c, false); |
|
2495 |
||
2496 |
for (int c = 0; c < columnCount; ++c) |
|
2497 |
QVERIFY(!view.isColumnHidden(c)); |
|
2498 |
} |
|
2499 |
||
2500 |
void tst_QTableView::sortingEnabled_data() |
|
2501 |
{ |
|
2502 |
// QTest::addColumn<int>("columnCount"); |
|
2503 |
} |
|
2504 |
||
2505 |
void tst_QTableView::sortingEnabled() |
|
2506 |
{ |
|
2507 |
// QFETCH(int, columnCount); |
|
2508 |
} |
|
2509 |
||
2510 |
void tst_QTableView::scrollTo_data() |
|
2511 |
{ |
|
2512 |
QTest::addColumn<int>("verticalScrollMode"); |
|
2513 |
QTest::addColumn<int>("horizontalScrollMode"); |
|
2514 |
QTest::addColumn<int>("rowCount"); |
|
2515 |
QTest::addColumn<int>("columnCount"); |
|
2516 |
QTest::addColumn<int>("rowHeight"); |
|
2517 |
QTest::addColumn<int>("columnWidth"); |
|
2518 |
QTest::addColumn<int>("hiddenRow"); |
|
2519 |
QTest::addColumn<int>("hiddenColumn"); |
|
2520 |
QTest::addColumn<int>("row"); |
|
2521 |
QTest::addColumn<int>("column"); |
|
2522 |
QTest::addColumn<int>("rowSpan"); |
|
2523 |
QTest::addColumn<int>("columnSpan"); |
|
2524 |
QTest::addColumn<int>("horizontalScroll"); |
|
2525 |
QTest::addColumn<int>("verticalScroll"); |
|
2526 |
QTest::addColumn<int>("scrollHint"); |
|
2527 |
QTest::addColumn<int>("expectedHorizontalScroll"); |
|
2528 |
QTest::addColumn<int>("expectedVerticalScroll"); |
|
2529 |
||
2530 |
QTest::newRow("no hidden, no span, no scroll, per item") |
|
2531 |
<< (int)QAbstractItemView::ScrollPerItem |
|
2532 |
<< (int)QAbstractItemView::ScrollPerItem |
|
2533 |
<< 10 << 10 // table |
|
2534 |
<< 80 << 80 // size |
|
2535 |
<< -1 << -1 // hide |
|
2536 |
<< 0 << 0 // cell |
|
2537 |
<< 1 << 1 // span |
|
2538 |
<< 0 << 0 // scroll |
|
2539 |
<< (int)QAbstractItemView::PositionAtTop |
|
2540 |
<< 0 << 0; // expected |
|
2541 |
||
2542 |
QTest::newRow("no hidden, no span, no scroll, per pixel") |
|
2543 |
<< (int)QAbstractItemView::ScrollPerPixel |
|
2544 |
<< (int)QAbstractItemView::ScrollPerPixel |
|
2545 |
<< 10 << 10 // table |
|
2546 |
<< 80 << 80 // size |
|
2547 |
<< -1 << -1 // hide |
|
2548 |
<< 0 << 0 // cell |
|
2549 |
<< 1 << 1 // span |
|
2550 |
<< 0 << 0 // scroll |
|
2551 |
<< (int)QAbstractItemView::PositionAtTop |
|
2552 |
<< 0 << 0; // expected |
|
2553 |
||
2554 |
QTest::newRow("hidden, no span, no scroll, per item") |
|
2555 |
<< (int)QAbstractItemView::ScrollPerItem |
|
2556 |
<< (int)QAbstractItemView::ScrollPerItem |
|
2557 |
<< 10 << 10 // table |
|
2558 |
<< 80 << 80 // size |
|
2559 |
<< 3 << 3 // hide |
|
2560 |
<< 5 << 5 // cell |
|
2561 |
<< 1 << 1 // span |
|
2562 |
<< 0 << 0 // scroll |
|
2563 |
<< (int)QAbstractItemView::PositionAtTop |
|
2564 |
<< 4 << 4; // expected |
|
2565 |
} |
|
2566 |
||
2567 |
void tst_QTableView::scrollTo() |
|
2568 |
{ |
|
2569 |
QFETCH(int, horizontalScrollMode); |
|
2570 |
QFETCH(int, verticalScrollMode); |
|
2571 |
QFETCH(int, rowCount); |
|
2572 |
QFETCH(int, columnCount); |
|
2573 |
QFETCH(int, rowHeight); |
|
2574 |
QFETCH(int, columnWidth); |
|
2575 |
QFETCH(int, hiddenRow); |
|
2576 |
QFETCH(int, hiddenColumn); |
|
2577 |
QFETCH(int, row); |
|
2578 |
QFETCH(int, column); |
|
2579 |
QFETCH(int, rowSpan); |
|
2580 |
QFETCH(int, columnSpan); |
|
2581 |
QFETCH(int, horizontalScroll); |
|
2582 |
QFETCH(int, verticalScroll); |
|
2583 |
QFETCH(int, scrollHint); |
|
2584 |
QFETCH(int, expectedHorizontalScroll); |
|
2585 |
QFETCH(int, expectedVerticalScroll); |
|
2586 |
||
2587 |
QtTestTableModel model(rowCount, columnCount); |
|
2588 |
QtTestTableView view; |
|
2589 |
||
2590 |
view.show(); |
|
2591 |
// resizing to this size will ensure that there can ONLY_BE_ONE_CELL inside the view. |
|
2592 |
QSize forcedSize(columnWidth * 2, rowHeight * 2); |
|
2593 |
view.resize(forcedSize); |
|
2594 |
QTest::qWaitForWindowShown(&view); |
|
2595 |
QTest::qWait(50); |
|
2596 |
QTRY_COMPARE(view.size(), forcedSize); |
|
2597 |
||
2598 |
view.setModel(&model); |
|
2599 |
view.setSpan(row, column, rowSpan, columnSpan); |
|
2600 |
view.hideRow(hiddenRow); |
|
2601 |
view.hideColumn(hiddenColumn); |
|
2602 |
view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode); |
|
2603 |
view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode); |
|
2604 |
||
2605 |
for (int r = 0; r < rowCount; ++r) |
|
2606 |
view.setRowHeight(r, rowHeight); |
|
2607 |
for (int c = 0; c < columnCount; ++c) |
|
2608 |
view.setColumnWidth(c, columnWidth); |
|
2609 |
||
2610 |
QTest::qWait(150); // ### needed to pass the test |
|
2611 |
view.horizontalScrollBar()->setValue(horizontalScroll); |
|
2612 |
view.verticalScrollBar()->setValue(verticalScroll); |
|
2613 |
||
2614 |
QModelIndex index = model.index(row, column); |
|
2615 |
QVERIFY(index.isValid()); |
|
2616 |
view.scrollTo(index, (QAbstractItemView::ScrollHint)scrollHint); |
|
2617 |
QCOMPARE(view.verticalScrollBar()->value(), expectedVerticalScroll); |
|
2618 |
QCOMPARE(view.horizontalScrollBar()->value(), expectedHorizontalScroll); |
|
2619 |
} |
|
2620 |
||
2621 |
void tst_QTableView::indexAt_data() |
|
2622 |
{ |
|
2623 |
QTest::addColumn<int>("rowCount"); |
|
2624 |
QTest::addColumn<int>("columnCount"); |
|
2625 |
||
2626 |
QTest::addColumn<int>("rowHeight"); |
|
2627 |
QTest::addColumn<int>("columnWidth"); |
|
2628 |
||
2629 |
QTest::addColumn<int>("hiddenRow"); |
|
2630 |
QTest::addColumn<int>("hiddenColumn"); |
|
2631 |
||
2632 |
QTest::addColumn<int>("row"); |
|
2633 |
QTest::addColumn<int>("column"); |
|
2634 |
QTest::addColumn<int>("rowSpan"); |
|
2635 |
QTest::addColumn<int>("columnSpan"); |
|
2636 |
QTest::addColumn<int>("horizontalScroll"); |
|
2637 |
QTest::addColumn<int>("verticalScroll"); |
|
2638 |
QTest::addColumn<int>("x"); |
|
2639 |
QTest::addColumn<int>("y"); |
|
2640 |
QTest::addColumn<int>("expectedRow"); |
|
2641 |
QTest::addColumn<int>("expectedColumn"); |
|
2642 |
||
2643 |
QTest::newRow("no hidden, no span, no scroll, (20,20)") |
|
2644 |
<< 10 << 10 // dim |
|
2645 |
<< 40 << 40 // size |
|
2646 |
<< -1 << -1 // hide |
|
2647 |
<< -1 << -1 // pos |
|
2648 |
<< 1 << 1 // span |
|
2649 |
<< 0 << 0 // scroll |
|
2650 |
<< 20 << 20 // point |
|
2651 |
<< 0 << 0; // expected |
|
2652 |
||
2653 |
QTest::newRow("row hidden, no span, no scroll, at (20,20)") |
|
2654 |
<< 10 << 10 // dim |
|
2655 |
<< 40 << 40 // size |
|
2656 |
<< 0 << -1 // hide |
|
2657 |
<< -1 << -1 // pos |
|
2658 |
<< 1 << 1 // span |
|
2659 |
<< 0 << 0 // scroll |
|
2660 |
<< 20 << 20 // point |
|
2661 |
<< 1 << 0; // expected |
|
2662 |
||
2663 |
QTest::newRow("col hidden, no span, no scroll, at (20,20)") |
|
2664 |
<< 10 << 10 // dim |
|
2665 |
<< 40 << 40 // size |
|
2666 |
<< -1 << 0 // hide |
|
2667 |
<< -1 << -1 // pos |
|
2668 |
<< 1 << 1 // span |
|
2669 |
<< 0 << 0 // scroll |
|
2670 |
<< 20 << 20 // point |
|
2671 |
<< 0 << 1; // expected |
|
2672 |
||
2673 |
QTest::newRow("no hidden, row span, no scroll, at (60,20)") |
|
2674 |
<< 10 << 10 // dim |
|
2675 |
<< 40 << 40 // size |
|
2676 |
<< -1 << -1 // hide |
|
2677 |
<< 0 << 0 // pos |
|
2678 |
<< 2 << 1 // span |
|
2679 |
<< 0 << 0 // scroll |
|
2680 |
<< 20 << 60 // point |
|
2681 |
<< 0 << 0; // expected |
|
2682 |
||
2683 |
||
2684 |
QTest::newRow("no hidden, col span, no scroll, at (60,20)") |
|
2685 |
<< 10 << 10 // dim |
|
2686 |
<< 40 << 40 // size |
|
2687 |
<< -1 << -1 // hide |
|
2688 |
<< 0 << 0 // pos |
|
2689 |
<< 1 << 2 // span |
|
2690 |
<< 0 << 0 // scroll |
|
2691 |
<< 60 << 20 // point |
|
2692 |
<< 0 << 0; // expected |
|
2693 |
||
2694 |
QTest::newRow("no hidden, no span, scroll (5,0), at (20,20)") |
|
2695 |
<< 10 << 10 // dim |
|
2696 |
<< 40 << 40 // size |
|
2697 |
<< -1 << -1 // hide |
|
2698 |
<< -1 << -1 // pos |
|
2699 |
<< 1 << 1 // span |
|
2700 |
<< 5 << 0 // scroll |
|
2701 |
<< 20 << 20 // point |
|
2702 |
<< 0 << 5; // expected |
|
2703 |
||
2704 |
QTest::newRow("no hidden, no span, scroll (0,5), at (20,20)") |
|
2705 |
<< 10 << 10 // dim |
|
2706 |
<< 40 << 40 // size |
|
2707 |
<< -1 << -1 // hide |
|
2708 |
<< -1 << -1 // pos |
|
2709 |
<< 1 << 1 // span |
|
2710 |
<< 0 << 5 // scroll |
|
2711 |
<< 20 << 20 // point |
|
2712 |
<< 5 << 0; // expected |
|
2713 |
||
2714 |
QTest::newRow("no hidden, no span, scroll (5,5), at (20,20)") |
|
2715 |
<< 10 << 10 // dim |
|
2716 |
<< 40 << 40 // size |
|
2717 |
<< -1 << -1 // hide |
|
2718 |
<< -1 << -1 // pos |
|
2719 |
<< 1 << 1 // span |
|
2720 |
<< 5 << 5 // scroll |
|
2721 |
<< 20 << 20 // point |
|
2722 |
<< 5 << 5; // expected |
|
2723 |
} |
|
2724 |
||
2725 |
void tst_QTableView::indexAt() |
|
2726 |
{ |
|
2727 |
QFETCH(int, rowCount); |
|
2728 |
QFETCH(int, columnCount); |
|
2729 |
QFETCH(int, rowHeight); |
|
2730 |
QFETCH(int, columnWidth); |
|
2731 |
QFETCH(int, hiddenRow); |
|
2732 |
QFETCH(int, hiddenColumn); |
|
2733 |
QFETCH(int, row); |
|
2734 |
QFETCH(int, column); |
|
2735 |
QFETCH(int, rowSpan); |
|
2736 |
QFETCH(int, columnSpan); |
|
2737 |
QFETCH(int, horizontalScroll); |
|
2738 |
QFETCH(int, verticalScroll); |
|
2739 |
QFETCH(int, x); |
|
2740 |
QFETCH(int, y); |
|
2741 |
QFETCH(int, expectedRow); |
|
2742 |
QFETCH(int, expectedColumn); |
|
2743 |
||
2744 |
QtTestTableModel model(rowCount, columnCount); |
|
2745 |
QtTestTableView view; |
|
2746 |
||
2747 |
view.show(); |
|
2748 |
QTest::qWaitForWindowShown(&view); |
|
2749 |
||
2750 |
//some styles change the scroll mode in their polish |
|
2751 |
view.setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
|
2752 |
view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
|
2753 |
||
2754 |
view.setModel(&model); |
|
2755 |
view.setSpan(row, column, rowSpan, columnSpan); |
|
2756 |
view.hideRow(hiddenRow); |
|
2757 |
view.hideColumn(hiddenColumn); |
|
2758 |
||
2759 |
for (int r = 0; r < rowCount; ++r) |
|
2760 |
view.setRowHeight(r, rowHeight); |
|
2761 |
for (int c = 0; c < columnCount; ++c) |
|
2762 |
view.setColumnWidth(c, columnWidth); |
|
2763 |
||
2764 |
QTest::qWait(20); |
|
2765 |
view.horizontalScrollBar()->setValue(horizontalScroll); |
|
2766 |
view.verticalScrollBar()->setValue(verticalScroll); |
|
2767 |
QTest::qWait(20); |
|
2768 |
||
2769 |
QModelIndex index = view.indexAt(QPoint(x, y)); |
|
2770 |
QCOMPARE(index.row(), expectedRow); |
|
2771 |
QCOMPARE(index.column(), expectedColumn); |
|
2772 |
} |
|
2773 |
||
2774 |
void tst_QTableView::span_data() |
|
2775 |
{ |
|
2776 |
QTest::addColumn<int>("rowCount"); |
|
2777 |
QTest::addColumn<int>("columnCount"); |
|
2778 |
QTest::addColumn<int>("hiddenRow"); |
|
2779 |
QTest::addColumn<int>("hiddenColumn"); |
|
2780 |
QTest::addColumn<int>("row"); |
|
2781 |
QTest::addColumn<int>("column"); |
|
2782 |
QTest::addColumn<int>("rowSpan"); |
|
2783 |
QTest::addColumn<int>("columnSpan"); |
|
2784 |
QTest::addColumn<int>("expectedRowSpan"); |
|
2785 |
QTest::addColumn<int>("expectedColumnSpan"); |
|
2786 |
QTest::addColumn<bool>("clear"); |
|
2787 |
||
2788 |
QTest::newRow("top left 2x2") |
|
2789 |
<< 10 << 10 |
|
2790 |
<< -1 << -1 |
|
2791 |
<< 0 << 0 |
|
2792 |
<< 2 << 2 |
|
2793 |
<< 2 << 2 |
|
2794 |
<< false; |
|
2795 |
||
2796 |
QTest::newRow("top left 1x2") |
|
2797 |
<< 10 << 10 |
|
2798 |
<< 3 << 3 |
|
2799 |
<< 0 << 0 |
|
2800 |
<< 1 << 2 |
|
2801 |
<< 1 << 2 |
|
2802 |
<< false; |
|
2803 |
||
2804 |
QTest::newRow("top left 2x1") |
|
2805 |
<< 10 << 10 |
|
2806 |
<< -1 << -1 |
|
2807 |
<< 0 << 0 |
|
2808 |
<< 2 << 1 |
|
2809 |
<< 2 << 1 |
|
2810 |
<< false; |
|
2811 |
||
2812 |
/* This makes no sens. |
|
2813 |
QTest::newRow("top left 2x0") |
|
2814 |
<< 10 << 10 |
|
2815 |
<< -1 << -1 |
|
2816 |
<< 0 << 0 |
|
2817 |
<< 2 << 0 |
|
2818 |
<< 2 << 0 |
|
2819 |
<< false; |
|
2820 |
||
2821 |
QTest::newRow("top left 0x2") |
|
2822 |
<< 10 << 10 |
|
2823 |
<< -1 << -1 |
|
2824 |
<< 0 << 0 |
|
2825 |
<< 0 << 2 |
|
2826 |
<< 0 << 2 |
|
2827 |
<< false;*/ |
|
2828 |
||
2829 |
QTest::newRow("invalid 2x2") |
|
2830 |
<< 10 << 10 |
|
2831 |
<< -1 << -1 |
|
2832 |
<< -1 << -1 |
|
2833 |
<< 2 << 2 |
|
2834 |
<< 1 << 1 |
|
2835 |
<< false; |
|
2836 |
||
2837 |
QTest::newRow("top left 2x2") |
|
2838 |
<< 10 << 10 |
|
2839 |
<< -1 << -1 |
|
2840 |
<< 0 << 0 |
|
2841 |
<< 2 << 2 |
|
2842 |
<< 2 << 2 |
|
2843 |
<< false; |
|
2844 |
||
2845 |
QTest::newRow("bottom right 2x2") |
|
2846 |
<< 10 << 10 |
|
2847 |
<< -1 << -1 |
|
2848 |
<< 8 << 8 |
|
2849 |
<< 2 << 2 |
|
2850 |
<< 2 << 2 |
|
2851 |
<< false; |
|
2852 |
||
2853 |
QTest::newRow("invalid span 2x2") |
|
2854 |
<< 10 << 10 |
|
2855 |
<< -1 << -1 |
|
2856 |
<< 8 << 8 |
|
2857 |
<< 2 << 2 |
|
2858 |
<< 2 << 2 |
|
2859 |
<< false; |
|
2860 |
||
2861 |
QTest::newRow("invalid span 3x3") |
|
2862 |
<< 10 << 10 |
|
2863 |
<< -1 << -1 |
|
2864 |
<< 6 << 6 |
|
2865 |
<< 3 << 3 |
|
2866 |
<< 2 << 3 |
|
2867 |
<< true; |
|
2868 |
||
2869 |
} |
|
2870 |
||
2871 |
void tst_QTableView::span() |
|
2872 |
{ |
|
2873 |
QFETCH(int, rowCount); |
|
2874 |
QFETCH(int, columnCount); |
|
2875 |
QFETCH(int, hiddenRow); |
|
2876 |
QFETCH(int, hiddenColumn); |
|
2877 |
QFETCH(int, row); |
|
2878 |
QFETCH(int, column); |
|
2879 |
QFETCH(int, rowSpan); |
|
2880 |
QFETCH(int, columnSpan); |
|
2881 |
QFETCH(int, expectedRowSpan); |
|
2882 |
QFETCH(int, expectedColumnSpan); |
|
2883 |
QFETCH(bool, clear); |
|
2884 |
||
2885 |
QtTestTableModel model(rowCount, columnCount); |
|
2886 |
QtTestTableView view; |
|
2887 |
||
2888 |
view.setModel(&model); |
|
2889 |
view.show(); |
|
2890 |
||
2891 |
view.setSpan(row, column, rowSpan, columnSpan); |
|
2892 |
if (clear) { |
|
2893 |
model.removeLastRow(); |
|
2894 |
model.removeLastRow(); |
|
2895 |
view.update(); |
|
2896 |
} |
|
2897 |
||
2898 |
view.hideRow(hiddenRow); |
|
2899 |
view.hideColumn(hiddenColumn); |
|
2900 |
view.show(); |
|
2901 |
||
2902 |
QCOMPARE(view.rowSpan(row, column), expectedRowSpan); |
|
2903 |
QCOMPARE(view.columnSpan(row, column), expectedColumnSpan); |
|
2904 |
||
2905 |
if (hiddenRow > -1) { |
|
2906 |
QModelIndex hidden = model.index(hiddenRow, columnCount - 1); |
|
2907 |
QVERIFY(view.isIndexHidden(hidden)); |
|
2908 |
} |
|
2909 |
||
2910 |
if (hiddenColumn > -1) { |
|
2911 |
QModelIndex hidden = model.index(rowCount - 1, hiddenColumn); |
|
2912 |
QVERIFY(view.isIndexHidden(hidden)); |
|
2913 |
} |
|
2914 |
||
2915 |
view.clearSpans(); |
|
2916 |
QCOMPARE(view.rowSpan(row, column), 1); |
|
2917 |
QCOMPARE(view.columnSpan(row, column), 1); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2918 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2919 |
VERIFY_SPANS_CONSISTENCY(&view); |
0 | 2920 |
} |
2921 |
||
2922 |
typedef QVector<QRect> SpanList; |
|
2923 |
Q_DECLARE_METATYPE(SpanList) |
|
2924 |
||
2925 |
void tst_QTableView::spans_data() |
|
2926 |
{ |
|
2927 |
QTest::addColumn<int>("rows"); |
|
2928 |
QTest::addColumn<int>("columns"); |
|
2929 |
QTest::addColumn<SpanList>("spans"); |
|
2930 |
QTest::addColumn<bool>("hideRowLastRowOfFirstSpan"); |
|
2931 |
QTest::addColumn<QPoint>("pos"); |
|
2932 |
QTest::addColumn<int>("expectedRowSpan"); |
|
2933 |
QTest::addColumn<int>("expectedColumnSpan"); |
|
2934 |
||
2935 |
QTest::newRow("1x3 span, query 3,0") |
|
2936 |
<< 5 << 5 |
|
2937 |
<< (SpanList() << QRect(3, 0, 1, 3)) |
|
2938 |
<< false //no hidden row |
|
2939 |
<< QPoint(3, 0) |
|
2940 |
<< 1 |
|
2941 |
<< 3; |
|
2942 |
||
2943 |
QTest::newRow("1x3 span, query 3,1") |
|
2944 |
<< 5 << 5 |
|
2945 |
<< (SpanList() << QRect(3, 0, 1, 3)) |
|
2946 |
<< false //no hidden row |
|
2947 |
<< QPoint(3, 1) |
|
2948 |
<< 1 |
|
2949 |
<< 3; |
|
2950 |
||
2951 |
QTest::newRow("1x3 span, query 3,2") |
|
2952 |
<< 5 << 5 |
|
2953 |
<< (SpanList() << QRect(3, 0, 1, 3)) |
|
2954 |
<< false //no hidden row |
|
2955 |
<< QPoint(3, 2) |
|
2956 |
<< 1 |
|
2957 |
<< 3; |
|
2958 |
||
2959 |
QTest::newRow("two 1x2 spans at the same column, query at 3,0") |
|
2960 |
<< 5 << 5 |
|
2961 |
<< (SpanList() << QRect(3, 0, 1, 2) << QRect(4, 0, 1, 2)) |
|
2962 |
<< false //no hidden row |
|
2963 |
<< QPoint(3, 0) |
|
2964 |
<< 1 |
|
2965 |
<< 2; |
|
2966 |
||
2967 |
QTest::newRow("two 1x2 spans at the same column, query at 4,0") |
|
2968 |
<< 5 << 5 |
|
2969 |
<< (SpanList() << QRect(3, 0, 1, 2) << QRect(4, 0, 1, 2)) |
|
2970 |
<< false //no hidden row |
|
2971 |
<< QPoint(4, 0) |
|
2972 |
<< 1 |
|
2973 |
<< 2; |
|
2974 |
||
2975 |
QTest::newRow("how to order spans (1,1)") |
|
2976 |
<< 5 << 5 |
|
2977 |
<< (SpanList() << QRect(1, 1, 3, 1) << QRect(1, 2, 2, 1)) |
|
2978 |
<< false //no hidden row |
|
2979 |
<< QPoint(1, 1) |
|
2980 |
<< 3 |
|
2981 |
<< 1; |
|
2982 |
||
2983 |
QTest::newRow("how to order spans (2,1)") |
|
2984 |
<< 5 << 5 |
|
2985 |
<< (SpanList() << QRect(1, 1, 3, 1) << QRect(1, 2, 2, 1)) |
|
2986 |
<< false //no hidden row |
|
2987 |
<< QPoint(2, 1) |
|
2988 |
<< 3 |
|
2989 |
<< 1; |
|
2990 |
||
2991 |
QTest::newRow("how to order spans (3,1)") |
|
2992 |
<< 5 << 5 |
|
2993 |
<< (SpanList() << QRect(1, 1, 3, 1) << QRect(1, 2, 2, 1)) |
|
2994 |
<< false //no hidden row |
|
2995 |
<< QPoint(3, 1) |
|
2996 |
<< 3 |
|
2997 |
<< 1; |
|
2998 |
||
2999 |
QTest::newRow("how to order spans (1,2)") |
|
3000 |
<< 5 << 5 |
|
3001 |
<< (SpanList() << QRect(1, 1, 3, 1) << QRect(1, 2, 2, 1)) |
|
3002 |
<< false //no hidden row |
|
3003 |
<< QPoint(1, 2) |
|
3004 |
<< 2 |
|
3005 |
<< 1; |
|
3006 |
||
3007 |
QTest::newRow("how to order spans (2,2)") |
|
3008 |
<< 5 << 5 |
|
3009 |
<< (SpanList() << QRect(1, 1, 3, 1) << QRect(1, 2, 2, 1)) |
|
3010 |
<< false //no hidden row |
|
3011 |
<< QPoint(2, 2) |
|
3012 |
<< 2 |
|
3013 |
<< 1; |
|
3014 |
||
3015 |
QTest::newRow("spans with hidden rows") |
|
3016 |
<< 3 << 2 |
|
3017 |
<< (SpanList() << QRect(0, 0, 2, 2) << QRect(2, 0, 1, 2)) |
|
3018 |
<< true //we hide the last row of the first span |
|
3019 |
<< QPoint(2, 0) |
|
3020 |
<< 1 |
|
3021 |
<< 2; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3022 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3023 |
QTest::newRow("QTBUG-6004: No failing Q_ASSERT, then it passes.") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3024 |
<< 5 << 5 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3025 |
<< (SpanList() << QRect(0, 0, 2, 2) << QRect(0, 0, 1, 1)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3026 |
<< false |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3027 |
<< QPoint(0, 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3028 |
<< 1 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3029 |
<< 1; |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3030 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3031 |
QTest::newRow("QTBUG-6004 (follow-up): No failing Q_ASSERT, then it passes.") |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3032 |
<< 10 << 10 |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3033 |
<< (SpanList() << QRect(2, 2, 1, 3) << QRect(2, 2, 1, 1)) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3034 |
<< false |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3035 |
<< QPoint(0, 0) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3036 |
<< 1 |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
3037 |
<< 1; |
0 | 3038 |
} |
3039 |
||
3040 |
void tst_QTableView::spans() |
|
3041 |
{ |
|
3042 |
QFETCH(int, rows); |
|
3043 |
QFETCH(int, columns); |
|
3044 |
QFETCH(SpanList, spans); |
|
3045 |
QFETCH(bool, hideRowLastRowOfFirstSpan); |
|
3046 |
QFETCH(QPoint, pos); |
|
3047 |
QFETCH(int, expectedRowSpan); |
|
3048 |
QFETCH(int, expectedColumnSpan); |
|
3049 |
||
3050 |
QtTestTableModel model(rows, columns); |
|
3051 |
QtTestTableView view; |
|
3052 |
||
3053 |
view.setModel(&model); |
|
3054 |
view.show(); |
|
3055 |
||
3056 |
for (int i = 0; i < spans.count(); ++i) { |
|
3057 |
QRect sp = spans.at(i); |
|
3058 |
view.setSpan(sp.x(), sp.y(), sp.width(), sp.height()); |
|
3059 |
} |
|
3060 |
||
3061 |
if (hideRowLastRowOfFirstSpan) { |
|
3062 |
view.setRowHidden(spans.at(0).bottom(), true); |
|
3063 |
//we check that the span didn't break the visual rects of the model indexes |
|
3064 |
QRect first = view.visualRect( model.index(spans.at(0).top(), 0)); |
|
3065 |
QRect next = view.visualRect( model.index(spans.at(0).bottom() + 1, 0)); |
|
3066 |
QVERIFY(first.intersected(next).isEmpty()); |
|
3067 |
} |
|
3068 |
||
3069 |
QCOMPARE(view.columnSpan(pos.x(), pos.y()), expectedColumnSpan); |
|
3070 |
QCOMPARE(view.rowSpan(pos.x(), pos.y()), expectedRowSpan); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3071 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3072 |
VERIFY_SPANS_CONSISTENCY(&view); |
0 | 3073 |
} |
3074 |
||
3075 |
void tst_QTableView::spansAfterRowInsertion() |
|
3076 |
{ |
|
3077 |
QtTestTableModel model(10, 10); |
|
3078 |
QtTestTableView view; |
|
3079 |
view.setModel(&model); |
|
3080 |
view.setSpan(3, 3, 3, 3); |
|
3081 |
view.show(); |
|
3082 |
QTest::qWait(50); |
|
3083 |
||
3084 |
// Insertion before the span only shifts the span. |
|
3085 |
view.model()->insertRows(0, 2); |
|
3086 |
QCOMPARE(view.rowSpan(3, 3), 1); |
|
3087 |
QCOMPARE(view.columnSpan(3, 3), 1); |
|
3088 |
QCOMPARE(view.rowSpan(5, 3), 3); |
|
3089 |
QCOMPARE(view.columnSpan(5, 3), 3); |
|
3090 |
||
3091 |
// Insertion happens before the given row, so it only shifts the span also. |
|
3092 |
view.model()->insertRows(5, 2); |
|
3093 |
QCOMPARE(view.rowSpan(5, 3), 1); |
|
3094 |
QCOMPARE(view.columnSpan(5, 3), 1); |
|
3095 |
QCOMPARE(view.rowSpan(7, 3), 3); |
|
3096 |
QCOMPARE(view.columnSpan(7, 3), 3); |
|
3097 |
||
3098 |
// Insertion inside the span expands it. |
|
3099 |
view.model()->insertRows(8, 2); |
|
3100 |
QCOMPARE(view.rowSpan(7, 3), 5); |
|
3101 |
QCOMPARE(view.columnSpan(7, 3), 3); |
|
3102 |
||
3103 |
// Insertion after the span does nothing to it. |
|
3104 |
view.model()->insertRows(12, 2); |
|
3105 |
QCOMPARE(view.rowSpan(7, 3), 5); |
|
3106 |
QCOMPARE(view.columnSpan(7, 3), 3); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3107 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3108 |
VERIFY_SPANS_CONSISTENCY(&view); |
0 | 3109 |
} |
3110 |
||
3111 |
void tst_QTableView::spansAfterColumnInsertion() |
|
3112 |
{ |
|
3113 |
QtTestTableModel model(10, 10); |
|
3114 |
QtTestTableView view; |
|
3115 |
view.setModel(&model); |
|
3116 |
view.setSpan(3, 3, 3, 3); |
|
3117 |
view.show(); |
|
3118 |
QTest::qWait(50); |
|
3119 |
||
3120 |
// Insertion before the span only shifts the span. |
|
3121 |
view.model()->insertColumns(0, 2); |
|
3122 |
QCOMPARE(view.rowSpan(3, 3), 1); |
|
3123 |
QCOMPARE(view.columnSpan(3, 3), 1); |
|
3124 |
QCOMPARE(view.rowSpan(3, 5), 3); |
|
3125 |
QCOMPARE(view.columnSpan(3, 5), 3); |
|
3126 |
||
3127 |
// Insertion happens before the given column, so it only shifts the span also. |
|
3128 |
view.model()->insertColumns(5, 2); |
|
3129 |
QCOMPARE(view.rowSpan(3, 5), 1); |
|
3130 |
QCOMPARE(view.columnSpan(3, 5), 1); |
|
3131 |
QCOMPARE(view.rowSpan(3, 7), 3); |
|
3132 |
QCOMPARE(view.columnSpan(3, 7), 3); |
|
3133 |
||
3134 |
// Insertion inside the span expands it. |
|
3135 |
view.model()->insertColumns(8, 2); |
|
3136 |
QCOMPARE(view.rowSpan(3, 7), 3); |
|
3137 |
QCOMPARE(view.columnSpan(3, 7), 5); |
|
3138 |
||
3139 |
// Insertion after the span does nothing to it. |
|
3140 |
view.model()->insertColumns(12, 2); |
|
3141 |
QCOMPARE(view.rowSpan(3, 7), 3); |
|
3142 |
QCOMPARE(view.columnSpan(3, 7), 5); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3143 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3144 |
VERIFY_SPANS_CONSISTENCY(&view); |
0 | 3145 |
} |
3146 |
||
3147 |
void tst_QTableView::spansAfterRowRemoval() |
|
3148 |
{ |
|
3149 |
QtTestTableModel model(10, 10); |
|
3150 |
QtTestTableView view; |
|
3151 |
view.setModel(&model); |
|
3152 |
||
3153 |
QList<QRect> spans; |
|
3154 |
spans << QRect(0, 1, 1, 2) |
|
3155 |
<< QRect(1, 2, 1, 2) |
|
3156 |
<< QRect(2, 2, 1, 5) |
|
3157 |
<< QRect(2, 8, 1, 2) |
|
3158 |
<< QRect(3, 4, 1, 2) |
|
3159 |
<< QRect(4, 4, 1, 4) |
|
3160 |
<< QRect(5, 6, 1, 3) |
|
3161 |
<< QRect(6, 7, 1, 3); |
|
3162 |
foreach (QRect span, spans) |
|
3163 |
view.setSpan(span.top(), span.left(), span.height(), span.width()); |
|
3164 |
||
3165 |
view.show(); |
|
3166 |
QTest::qWait(100); |
|
3167 |
view.model()->removeRows(3, 3); |
|
3168 |
||
3169 |
QList<QRect> expectedSpans; |
|
3170 |
expectedSpans << QRect(0, 1, 1, 2) |
|
3171 |
<< QRect(1, 2, 1, 1) |
|
3172 |
<< QRect(2, 2, 1, 2) |
|
3173 |
<< QRect(2, 5, 1, 2) |
|
3174 |
<< QRect(3, 4, 1, 1) |
|
3175 |
<< QRect(4, 3, 1, 2) |
|
3176 |
<< QRect(5, 3, 1, 3) |
|
3177 |
<< QRect(6, 4, 1, 3); |
|
3178 |
foreach (QRect span, expectedSpans) { |
|
3179 |
QCOMPARE(view.columnSpan(span.top(), span.left()), span.width()); |
|
3180 |
QCOMPARE(view.rowSpan(span.top(), span.left()), span.height()); |
|
3181 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3182 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3183 |
VERIFY_SPANS_CONSISTENCY(&view); |
0 | 3184 |
} |
3185 |
||
3186 |
void tst_QTableView::spansAfterColumnRemoval() |
|
3187 |
{ |
|
3188 |
QtTestTableModel model(10, 10); |
|
3189 |
QtTestTableView view; |
|
3190 |
view.setModel(&model); |
|
3191 |
||
3192 |
// Same set as above just swapping columns and rows. |
|
3193 |
QList<QRect> spans; |
|
3194 |
spans << QRect(0, 1, 1, 2) |
|
3195 |
<< QRect(1, 2, 1, 2) |
|
3196 |
<< QRect(2, 2, 1, 5) |
|
3197 |
<< QRect(2, 8, 1, 2) |
|
3198 |
<< QRect(3, 4, 1, 2) |
|
3199 |
<< QRect(4, 4, 1, 4) |
|
3200 |
<< QRect(5, 6, 1, 3) |
|
3201 |
<< QRect(6, 7, 1, 3); |
|
3202 |
foreach (QRect span, spans) |
|
3203 |
view.setSpan(span.left(), span.top(), span.width(), span.height()); |
|
3204 |
||
3205 |
view.show(); |
|
3206 |
QTest::qWait(100); |
|
3207 |
view.model()->removeColumns(3, 3); |
|
3208 |
||
3209 |
QList<QRect> expectedSpans; |
|
3210 |
expectedSpans << QRect(0, 1, 1, 2) |
|
3211 |
<< QRect(1, 2, 1, 1) |
|
3212 |
<< QRect(2, 2, 1, 2) |
|
3213 |
<< QRect(2, 5, 1, 2) |
|
3214 |
<< QRect(3, 4, 1, 1) |
|
3215 |
<< QRect(4, 3, 1, 2) |
|
3216 |
<< QRect(5, 3, 1, 3) |
|
3217 |
<< QRect(6, 4, 1, 3); |
|
3218 |
foreach (QRect span, expectedSpans) { |
|
3219 |
QCOMPARE(view.columnSpan(span.left(), span.top()), span.height()); |
|
3220 |
QCOMPARE(view.rowSpan(span.left(), span.top()), span.width()); |
|
3221 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3222 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3223 |
VERIFY_SPANS_CONSISTENCY(&view); |
0 | 3224 |
} |
3225 |
||
3226 |
class Model : public QAbstractTableModel { |
|
3227 |
||
3228 |
Q_OBJECT |
|
3229 |
||
3230 |
public: |
|
3231 |
Model(QObject * parent = 0) : QAbstractTableModel(parent) { |
|
3232 |
} |
|
3233 |
||
3234 |
int rowCount(const QModelIndex &) const { |
|
3235 |
return rows; |
|
3236 |
} |
|
3237 |
int columnCount(const QModelIndex &) const { |
|
3238 |
return columns; |
|
3239 |
} |
|
3240 |
QVariant data(const QModelIndex &, int) const |
|
3241 |
{ |
|
3242 |
return QVariant(); |
|
3243 |
} |
|
3244 |
void res() { reset(); } |
|
3245 |
||
3246 |
int rows; |
|
3247 |
int columns; |
|
3248 |
}; |
|
3249 |
||
3250 |
void tst_QTableView::checkHeaderReset() |
|
3251 |
{ |
|
3252 |
QTableView view; |
|
3253 |
Model m; |
|
3254 |
m.rows = 3; |
|
3255 |
m.columns = 3; |
|
3256 |
view.setModel(&m); |
|
3257 |
||
3258 |
m.rows = 4; |
|
3259 |
m.columns = 4; |
|
3260 |
m.res(); |
|
3261 |
QCOMPARE(view.horizontalHeader()->count(), 4); |
|
3262 |
} |
|
3263 |
||
3264 |
void tst_QTableView::checkHeaderMinSize() |
|
3265 |
{ |
|
3266 |
//tests if the minimumsize is of a header is taken into account |
|
3267 |
//while computing QTableView geometry. For that we test the position of the |
|
3268 |
//viewport. |
|
3269 |
QTableView view; |
|
3270 |
QStringListModel m; |
|
3271 |
m.setStringList( QStringList() << QLatin1String("one cell is enough")); |
|
3272 |
view.setModel(&m); |
|
3273 |
||
3274 |
//setting the minimum height on the horizontal header |
|
3275 |
//and the minimum width on the vertical header |
|
3276 |
view.horizontalHeader()->setMinimumHeight(50); |
|
3277 |
view.verticalHeader()->setMinimumWidth(100); |
|
3278 |
||
3279 |
view.show(); |
|
3280 |
||
3281 |
QVERIFY( view.verticalHeader()->y() >= view.horizontalHeader()->minimumHeight()); |
|
3282 |
QVERIFY( view.horizontalHeader()->x() >= view.verticalHeader()->minimumWidth()); |
|
3283 |
} |
|
3284 |
||
3285 |
void tst_QTableView::resizeToContents() |
|
3286 |
{ |
|
3287 |
//checks that the resize to contents is consistent |
|
3288 |
QTableWidget table(2,3); |
|
3289 |
QTableWidget table2(2,3); |
|
3290 |
QTableWidget table3(2,3); |
|
3291 |
||
3292 |
||
3293 |
table.setHorizontalHeaderItem(0, new QTableWidgetItem("A Lot of text here: BLA BLA BLA")); |
|
3294 |
table2.setHorizontalHeaderItem(0, new QTableWidgetItem("A Lot of text here: BLA BLA BLA")); |
|
3295 |
table3.setHorizontalHeaderItem(0, new QTableWidgetItem("A Lot of text here: BLA BLA BLA")); |
|
3296 |
table.horizontalHeader()->setVisible(false); |
|
3297 |
table2.horizontalHeader()->setVisible(false); |
|
3298 |
table.verticalHeader()->setVisible(false); |
|
3299 |
table2.verticalHeader()->setVisible(false); |
|
3300 |
||
3301 |
||
3302 |
for(int i = 0;i<table.columnCount();i++) { |
|
3303 |
table.resizeColumnToContents(i); |
|
3304 |
} |
|
3305 |
for(int i = 0;i<table.rowCount();i++) { |
|
3306 |
table.resizeRowToContents(i); |
|
3307 |
} |
|
3308 |
table2.resizeColumnsToContents(); |
|
3309 |
table2.resizeRowsToContents(); |
|
3310 |
table3.resizeColumnsToContents(); |
|
3311 |
table3.resizeRowsToContents(); |
|
3312 |
||
3313 |
//now let's check the row/col sizes |
|
3314 |
for(int i = 0;i<table.columnCount();i++) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3315 |
QCOMPARE( table.columnWidth(i), table2.columnWidth(i)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3316 |
QCOMPARE( table2.columnWidth(i), table3.columnWidth(i)); |
0 | 3317 |
} |
3318 |
for(int i = 0;i<table.rowCount();i++) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3319 |
QCOMPARE( table.rowHeight(i), table2.rowHeight(i)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3320 |
QCOMPARE( table2.rowHeight(i), table3.rowHeight(i)); |
0 | 3321 |
} |
3322 |
||
3323 |
} |
|
3324 |
||
3325 |
QT_BEGIN_NAMESPACE |
|
3326 |
extern bool Q_GUI_EXPORT qt_tab_all_widgets; // qapplication.cpp |
|
3327 |
QT_END_NAMESPACE |
|
3328 |
||
3329 |
void tst_QTableView::tabFocus() |
|
3330 |
{ |
|
3331 |
if (!qt_tab_all_widgets) |
|
3332 |
QSKIP("This test requires full keyboard control to be enabled.", SkipAll); |
|
3333 |
||
3334 |
// QTableView enables tabKeyNavigation by default, but you should be able |
|
3335 |
// to change focus on an empty table view, or on a table view that doesn't |
|
3336 |
// have this property set. |
|
3337 |
QWidget window; |
|
3338 |
||
3339 |
QTableView *view = new QTableView(&window); |
|
3340 |
QLineEdit *edit = new QLineEdit(&window); |
|
3341 |
||
3342 |
window.show(); |
|
3343 |
QApplication::setActiveWindow(&window); |
|
3344 |
QTest::qWaitForWindowShown(&window); |
|
3345 |
window.setFocus(); |
|
3346 |
QTest::qWait(100); |
|
3347 |
window.activateWindow(); |
|
3348 |
QTest::qWait(100); |
|
3349 |
||
3350 |
qApp->processEvents(); |
|
3351 |
||
3352 |
WAIT_FOR_CONDITION(window.hasFocus(), true); |
|
3353 |
||
3354 |
qApp->processEvents(); |
|
3355 |
||
3356 |
// window |
|
3357 |
QVERIFY(window.hasFocus()); |
|
3358 |
QVERIFY(!view->hasFocus()); |
|
3359 |
QVERIFY(!edit->hasFocus()); |
|
3360 |
||
3361 |
for (int i = 0; i < 2; ++i) { |
|
3362 |
// tab to view |
|
3363 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); |
|
3364 |
QTRY_VERIFY(!window.hasFocus()); |
|
3365 |
QVERIFY(view->hasFocus()); |
|
3366 |
QVERIFY(!edit->hasFocus()); |
|
3367 |
||
3368 |
// tab to edit |
|
3369 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); |
|
3370 |
QTRY_VERIFY(edit->hasFocus()); |
|
3371 |
QVERIFY(!window.hasFocus()); |
|
3372 |
QVERIFY(!view->hasFocus()); |
|
3373 |
} |
|
3374 |
||
3375 |
// backtab to view |
|
3376 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); |
|
3377 |
QTRY_VERIFY(view->hasFocus()); |
|
3378 |
QVERIFY(!window.hasFocus()); |
|
3379 |
QVERIFY(!edit->hasFocus()); |
|
3380 |
||
3381 |
// backtab to edit |
|
3382 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); |
|
3383 |
QTRY_VERIFY(edit->hasFocus()); |
|
3384 |
QVERIFY(!window.hasFocus()); |
|
3385 |
QVERIFY(!view->hasFocus()); |
|
3386 |
||
3387 |
QStandardItemModel *model = new QStandardItemModel; |
|
3388 |
view->setModel(model); |
|
3389 |
||
3390 |
// backtab to view |
|
3391 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); |
|
3392 |
QTRY_VERIFY(view->hasFocus()); |
|
3393 |
QVERIFY(!window.hasFocus()); |
|
3394 |
QVERIFY(!edit->hasFocus()); |
|
3395 |
||
3396 |
// backtab to edit |
|
3397 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); |
|
3398 |
QTRY_VERIFY(edit->hasFocus()); |
|
3399 |
QVERIFY(!window.hasFocus()); |
|
3400 |
QVERIFY(!view->hasFocus()); |
|
3401 |
||
3402 |
model->insertRow(0, new QStandardItem("Hei")); |
|
3403 |
model->insertRow(0, new QStandardItem("Hei")); |
|
3404 |
model->insertRow(0, new QStandardItem("Hei")); |
|
3405 |
||
3406 |
// backtab to view |
|
3407 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); |
|
3408 |
QTRY_VERIFY(view->hasFocus()); |
|
3409 |
QVERIFY(!window.hasFocus()); |
|
3410 |
QVERIFY(!edit->hasFocus()); |
|
3411 |
||
3412 |
// backtab to edit doesn't work |
|
3413 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); |
|
3414 |
QVERIFY(!window.hasFocus()); |
|
3415 |
QVERIFY(view->hasFocus()); |
|
3416 |
QVERIFY(!edit->hasFocus()); |
|
3417 |
||
3418 |
view->setTabKeyNavigation(false); |
|
3419 |
||
3420 |
// backtab to edit |
|
3421 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); |
|
3422 |
QTRY_VERIFY(edit->hasFocus()); |
|
3423 |
QVERIFY(!window.hasFocus()); |
|
3424 |
QVERIFY(!view->hasFocus()); |
|
3425 |
||
3426 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); |
|
3427 |
QTRY_VERIFY(view->hasFocus()); |
|
3428 |
QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); |
|
3429 |
QTRY_VERIFY(edit->hasFocus()); |
|
3430 |
||
3431 |
delete model; |
|
3432 |
} |
|
3433 |
||
3434 |
class BigModel : public QAbstractTableModel |
|
3435 |
{ |
|
3436 |
Q_OBJECT |
|
3437 |
public: |
|
3438 |
virtual QVariant data(const QModelIndex &index, |
|
3439 |
int role = Qt::DisplayRole) const |
|
3440 |
{ |
|
3441 |
if (role == Qt::DisplayRole) |
|
3442 |
return QString("%1 - %2").arg(index.column()).arg(index.row()); |
|
3443 |
return QVariant(); |
|
3444 |
} |
|
3445 |
||
3446 |
||
3447 |
int rowCount(const QModelIndex & parent = QModelIndex()) const |
|
3448 |
{ |
|
3449 |
Q_UNUSED(parent); |
|
3450 |
return 10000000; |
|
3451 |
} |
|
3452 |
||
3453 |
int columnCount(const QModelIndex & parent = QModelIndex()) const |
|
3454 |
{ |
|
3455 |
Q_UNUSED(parent); |
|
3456 |
return 20000000; |
|
3457 |
} |
|
3458 |
}; |
|
3459 |
||
3460 |
void tst_QTableView::bigModel() |
|
3461 |
{ |
|
3462 |
//should not crash |
|
3463 |
QTableView view; |
|
3464 |
BigModel model; |
|
3465 |
view.setModel(&model); |
|
3466 |
view.show(); |
|
3467 |
view.setSpan(10002,10002,6,6); |
|
3468 |
QTest::qWait(100); |
|
3469 |
view.resize(1000,1000); |
|
3470 |
QTest::qWait(100); |
|
3471 |
view.scrollTo(model.index(10010,10010)); |
|
3472 |
QTest::qWait(100); |
|
3473 |
} |
|
3474 |
||
3475 |
void tst_QTableView::selectionSignal() |
|
3476 |
{ |
|
3477 |
QtTestTableModel model(10, 10); |
|
3478 |
QtTestTableView view; |
|
3479 |
view.checkSignalOrder = true; |
|
3480 |
view.setModel(&model); |
|
3481 |
view.resize(200, 200); |
|
3482 |
view.show(); |
|
3483 |
QTest::qWaitForWindowShown(&view); |
|
3484 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center()); |
|
3485 |
} |
|
3486 |
||
3487 |
class task173773_EventFilter : public QObject |
|
3488 |
{ |
|
3489 |
int paintEventCount_; |
|
3490 |
public: |
|
3491 |
task173773_EventFilter() : paintEventCount_(0) {} |
|
3492 |
int paintEventCount() const { return paintEventCount_; } |
|
3493 |
private: |
|
3494 |
bool eventFilter(QObject *obj, QEvent *e) |
|
3495 |
{ |
|
3496 |
Q_UNUSED(obj); |
|
3497 |
if (e->type() == QEvent::Paint) |
|
3498 |
++paintEventCount_; |
|
3499 |
return false; |
|
3500 |
} |
|
3501 |
}; |
|
3502 |
||
3503 |
void tst_QTableView::task173773_updateVerticalHeader() |
|
3504 |
{ |
|
3505 |
QStandardItemModel model(2, 1); |
|
3506 |
model.setData(model.index(0, 0), 0); |
|
3507 |
model.setData(model.index(1, 0), 1); |
|
3508 |
||
3509 |
QSortFilterProxyModel proxyModel; |
|
3510 |
proxyModel.setSourceModel(&model); |
|
3511 |
||
3512 |
QTableView view; |
|
3513 |
view.setModel(&proxyModel); |
|
3514 |
view.setSortingEnabled(true); |
|
3515 |
view.show(); |
|
3516 |
QTest::qWaitForWindowShown(&view); |
|
3517 |
||
3518 |
view.sortByColumn(0, Qt::AscendingOrder); |
|
3519 |
QTest::qWait(100); |
|
3520 |
||
3521 |
task173773_EventFilter eventFilter; |
|
3522 |
view.verticalHeader()->viewport()->installEventFilter(&eventFilter); |
|
3523 |
||
3524 |
view.sortByColumn(0, Qt::DescendingOrder); |
|
3525 |
QTest::qWait(100); |
|
3526 |
||
3527 |
// ### note: this test may occasionally pass even if the bug is present! |
|
3528 |
QVERIFY(eventFilter.paintEventCount() > 0); |
|
3529 |
} |
|
3530 |
||
3531 |
void tst_QTableView::task227953_setRootIndex() |
|
3532 |
{ |
|
3533 |
QTableView tableView; |
|
3534 |
||
3535 |
//model = tree with two items with tables as children |
|
3536 |
QStandardItemModel model; |
|
3537 |
QStandardItem item1, item2; |
|
3538 |
model.appendColumn(QList<QStandardItem*>() << &item1 << &item2); |
|
3539 |
||
3540 |
||
3541 |
//setup the first table as a child of the first item |
|
3542 |
for ( int row = 0; row < 40; ++row ) { |
|
3543 |
item1.appendRow(QList<QStandardItem*>() << new QStandardItem(QString("row %0").arg(row))); |
|
3544 |
} |
|
3545 |
||
3546 |
//setup the second table as a child of the second item |
|
3547 |
for ( int row = 0; row < 10; ++row ) { |
|
3548 |
item2.appendRow(QList<QStandardItem*>() << new QStandardItem(QString("row %0").arg(row))); |
|
3549 |
} |
|
3550 |
||
3551 |
tableView.setModel(&model); |
|
3552 |
||
3553 |
//show the first 10 rows of the first table |
|
3554 |
QModelIndex root = model.indexFromItem(&item1); |
|
3555 |
tableView.setRootIndex(root); |
|
3556 |
for (int i = 10; i != 40; ++i) { |
|
3557 |
tableView.setRowHidden(i, true); |
|
3558 |
} |
|
3559 |
||
3560 |
QCOMPARE(tableView.verticalHeader()->count(), 40); |
|
3561 |
QCOMPARE(tableView.verticalHeader()->hiddenSectionCount(), 30); |
|
3562 |
||
3563 |
//show the first 10 rows of the second table |
|
3564 |
tableView.setRootIndex(model.indexFromItem(&item2)); |
|
3565 |
||
3566 |
QCOMPARE(tableView.verticalHeader()->count(), 10); |
|
3567 |
QCOMPARE(tableView.verticalHeader()->hiddenSectionCount(), 0); |
|
3568 |
QVERIFY(!tableView.verticalHeader()->isHidden()); |
|
3569 |
} |
|
3570 |
||
3571 |
void tst_QTableView::task240266_veryBigColumn() |
|
3572 |
{ |
|
3573 |
QTableView table; |
|
3574 |
table.setFixedSize(500, 300); //just to make sure we have the 2 first columns visible |
|
3575 |
QStandardItemModel model(1, 3); |
|
3576 |
table.setModel(&model); |
|
3577 |
table.setColumnWidth(0, 100); //normal column |
|
3578 |
table.setColumnWidth(1, 100); //normal column |
|
3579 |
table.setColumnWidth(2, 9000); //very big column |
|
3580 |
table.show(); |
|
3581 |
QTest::qWaitForWindowShown(&table); |
|
3582 |
||
3583 |
//some styles change the scroll mode in their polish |
|
3584 |
table.setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); |
|
3585 |
table.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
|
3586 |
||
3587 |
QScrollBar *scroll = table.horizontalScrollBar(); |
|
3588 |
QCOMPARE(scroll->minimum(), 0); |
|
3589 |
QCOMPARE(scroll->maximum(), model.columnCount() - 1); |
|
3590 |
QCOMPARE(scroll->singleStep(), 1); |
|
3591 |
||
3592 |
//1 is not always a very correct value for pageStep. Ideally this should be dynamic. |
|
3593 |
//Maybe something for Qt 5 ;-) |
|
3594 |
QCOMPARE(scroll->pageStep(), 1); |
|
3595 |
||
3596 |
} |
|
3597 |
||
3598 |
void tst_QTableView::task248688_autoScrollNavigation() |
|
3599 |
{ |
|
3600 |
//we make sure that when navigating with the keyboard the view is correctly scrolled |
|
3601 |
//to the current item |
|
3602 |
QStandardItemModel model(16, 16); |
|
3603 |
QTableView view; |
|
3604 |
view.setModel(&model); |
|
3605 |
||
3606 |
view.hideColumn(8); |
|
3607 |
view.hideRow(8); |
|
3608 |
view.show(); |
|
3609 |
for (int r = 0; r < model.rowCount(); ++r) { |
|
3610 |
if (view.isRowHidden(r)) |
|
3611 |
continue; |
|
3612 |
for (int c = 0; c < model.columnCount(); ++c) { |
|
3613 |
if (view.isColumnHidden(c)) |
|
3614 |
continue; |
|
3615 |
QModelIndex index = model.index(r, c); |
|
3616 |
view.setCurrentIndex(index); |
|
3617 |
QVERIFY(view.viewport()->rect().contains(view.visualRect(index))); |
|
3618 |
} |
|
3619 |
} |
|
3620 |
} |
|
3621 |
||
3622 |
||
3623 |
void tst_QTableView::mouseWheel_data() |
|
3624 |
{ |
|
3625 |
QTest::addColumn<int>("scrollMode"); |
|
3626 |
QTest::addColumn<int>("delta"); |
|
3627 |
QTest::addColumn<int>("horizontalPositon"); |
|
3628 |
QTest::addColumn<int>("verticalPosition"); |
|
3629 |
||
3630 |
QTest::newRow("scroll up per item") |
|
3631 |
<< int(QAbstractItemView::ScrollPerItem) << 120 |
|
3632 |
<< 10 - qApp->wheelScrollLines() << 10 - qApp->wheelScrollLines(); |
|
3633 |
QTest::newRow("scroll down per item") |
|
3634 |
<< int(QAbstractItemView::ScrollPerItem) << -120 |
|
3635 |
<< 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines(); |
|
3636 |
QTest::newRow("scroll down per pixel") |
|
3637 |
<< int(QAbstractItemView::ScrollPerPixel) << -120 |
|
3638 |
<< 10 + qApp->wheelScrollLines() * 89 << 10 + qApp->wheelScrollLines() * 28; |
|
3639 |
} |
|
3640 |
||
3641 |
void tst_QTableView::mouseWheel() |
|
3642 |
{ |
|
3643 |
#ifdef Q_OS_WINCE |
|
3644 |
QSKIP("Since different Windows CE versions sport different taskbars, we skip this test", SkipAll); |
|
3645 |
#endif |
|
3646 |
QFETCH(int, scrollMode); |
|
3647 |
QFETCH(int, delta); |
|
3648 |
QFETCH(int, horizontalPositon); |
|
3649 |
QFETCH(int, verticalPosition); |
|
3650 |
||
3651 |
QtTestTableModel model(100, 100); |
|
3652 |
QtTestTableView view; |
|
3653 |
view.resize(500, 500); |
|
3654 |
for (int r = 0; r < 100; ++r) |
|
3655 |
view.setRowHeight(r, 50); |
|
3656 |
for (int c = 0; c < 100; ++c) |
|
3657 |
view.setColumnWidth(c, 100); |
|
3658 |
view.show(); |
|
3659 |
QTest::qWaitForWindowShown(&view); |
|
3660 |
||
3661 |
view.setModel(&model); |
|
3662 |
||
3663 |
view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)scrollMode); |
|
3664 |
view.setVerticalScrollMode((QAbstractItemView::ScrollMode)scrollMode); |
|
3665 |
view.horizontalScrollBar()->setValue(10); |
|
3666 |
view.verticalScrollBar()->setValue(10); |
|
3667 |
||
3668 |
QPoint pos = view.viewport()->geometry().center(); |
|
3669 |
QWheelEvent verticalEvent(pos, delta, 0, 0, Qt::Vertical); |
|
3670 |
QWheelEvent horizontalEvent(pos, delta, 0, 0, Qt::Horizontal); |
|
3671 |
QApplication::sendEvent(view.viewport(), &horizontalEvent); |
|
3672 |
QVERIFY(qAbs(view.horizontalScrollBar()->value() - horizontalPositon) < 10); |
|
3673 |
QApplication::sendEvent(view.viewport(), &verticalEvent); |
|
3674 |
QVERIFY(qAbs(view.verticalScrollBar()->value() - verticalPosition) < 10); |
|
3675 |
} |
|
3676 |
||
3677 |
void tst_QTableView::addColumnWhileEditing() |
|
3678 |
{ |
|
3679 |
QTableView view; |
|
3680 |
QStandardItemModel model(1, 10); |
|
3681 |
view.setModel(&model); |
|
3682 |
QModelIndex last = model.index(0,9); |
|
3683 |
view.show(); |
|
3684 |
||
3685 |
view.openPersistentEditor(last); |
|
3686 |
view.scrollTo(last); |
|
3687 |
||
3688 |
//let's see if the editor is moved to the right location |
|
3689 |
//after adding a column |
|
3690 |
model.setColumnCount(model.columnCount() + 1); |
|
3691 |
QPointer<QLineEdit> editor = qFindChild<QLineEdit*>(&view); |
|
3692 |
QVERIFY(editor); |
|
3693 |
QCOMPARE(editor->geometry(), view.visualRect(last)); |
|
3694 |
||
3695 |
//let's see if the editor is moved to the right location |
|
3696 |
//after removing a column |
|
3697 |
view.scrollTo(model.index(0, model.columnCount()-1)); |
|
3698 |
model.setColumnCount(model.columnCount() - 1); |
|
3699 |
QVERIFY(editor); |
|
3700 |
QCOMPARE(editor->geometry(), view.visualRect(last)); |
|
3701 |
} |
|
3702 |
||
3703 |
void tst_QTableView::task259308_scrollVerticalHeaderSwappedSections() |
|
3704 |
{ |
|
3705 |
QStandardItemModel model; |
|
3706 |
model.setRowCount(50); |
|
3707 |
model.setColumnCount(2); |
|
3708 |
for (int row = 0; row < model.rowCount(); ++row) |
|
3709 |
for (int col = 0; col < model.columnCount(); ++col) { |
|
3710 |
const QModelIndex &idx = model.index(row, col); |
|
3711 |
model.setData(idx, QVariant(row), Qt::EditRole); |
|
3712 |
} |
|
3713 |
||
3714 |
QTableView tv; |
|
3715 |
tv.setModel(&model); |
|
3716 |
tv.show(); |
|
3717 |
tv.verticalHeader()->swapSections(0, model.rowCount() - 1); |
|
3718 |
tv.setCurrentIndex(model.index(model.rowCount() - 1, 0)); |
|
3719 |
||
3720 |
QTest::qWaitForWindowShown(&tv); |
|
3721 |
QTest::keyClick(&tv, Qt::Key_PageUp); // PageUp won't scroll when at top |
|
3722 |
QTRY_COMPARE(tv.rowAt(0), tv.verticalHeader()->logicalIndex(0)); |
|
3723 |
||
3724 |
int newRow = tv.rowAt(tv.viewport()->height()); |
|
3725 |
if (newRow == tv.rowAt(tv.viewport()->height() - 1)) // Overlapping row |
|
3726 |
newRow++; |
|
3727 |
QTest::keyClick(&tv, Qt::Key_PageDown); // Scroll down and check current |
|
3728 |
QTRY_COMPARE(tv.currentIndex().row(), newRow); |
|
3729 |
||
3730 |
tv.setCurrentIndex(model.index(0, 0)); |
|
3731 |
QTest::qWait(60); |
|
3732 |
QTest::keyClick(&tv, Qt::Key_PageDown); // PageDown won't scroll when at the bottom |
|
3733 |
QTRY_COMPARE(tv.rowAt(tv.viewport()->height() - 1), tv.verticalHeader()->logicalIndex(model.rowCount() - 1)); |
|
3734 |
} |
|
3735 |
||
3736 |
template <typename T> |
|
3737 |
struct ValueSaver { |
|
3738 |
T &var, value; |
|
3739 |
ValueSaver(T &v) : var(v), value(v) { } |
|
3740 |
~ValueSaver() { var = value; } |
|
3741 |
}; |
|
3742 |
||
3743 |
void tst_QTableView::task191545_dragSelectRows() |
|
3744 |
{ |
|
3745 |
QStandardItemModel model(10, 10); |
|
3746 |
QTableView table; |
|
3747 |
table.setModel(&model); |
|
3748 |
table.setSelectionBehavior(QAbstractItemView::SelectItems); |
|
3749 |
table.setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
3750 |
table.setMinimumSize(1000, 400); |
|
3751 |
table.show(); |
|
3752 |
QTest::qWait(200); |
|
3753 |
||
3754 |
ValueSaver<Qt::KeyboardModifiers> saver(QApplicationPrivate::modifier_buttons); |
|
3755 |
QApplicationPrivate::modifier_buttons = Qt::ControlModifier; |
|
3756 |
||
3757 |
{ |
|
3758 |
QRect cellRect = table.visualRect(model.index(3, 0)); |
|
3759 |
QHeaderView *vHeader = table.verticalHeader(); |
|
3760 |
QWidget *vHeaderVp = vHeader->viewport(); |
|
3761 |
QPoint rowPos(5, (cellRect.top() + cellRect.bottom()) / 2); |
|
3762 |
QMouseEvent rowPressEvent(QEvent::MouseButtonPress, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); |
|
3763 |
qApp->sendEvent(vHeaderVp, &rowPressEvent); |
|
3764 |
||
3765 |
for (int i = 0; i < 4; ++i) { |
|
3766 |
rowPos.setY(rowPos.y() + cellRect.height()); |
|
3767 |
QMouseEvent moveEvent(QEvent::MouseMove, rowPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); |
|
3768 |
qApp->sendEvent(vHeaderVp, &moveEvent); |
|
3769 |
} |
|
3770 |
QMouseEvent rowReleaseEvent(QEvent::MouseButtonRelease, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); |
|
3771 |
qApp->sendEvent(vHeaderVp, &rowReleaseEvent); |
|
3772 |
||
3773 |
for (int i = 0; i < 4; ++i) { |
|
3774 |
QModelIndex index = model.index(3 + i, 0, table.rootIndex()); |
|
3775 |
QVERIFY(vHeader->selectionModel()->selectedRows().contains(index)); |
|
3776 |
} |
|
3777 |
} |
|
3778 |
||
3779 |
{ |
|
3780 |
QRect cellRect = table.visualRect(model.index(0, 3)); |
|
3781 |
QHeaderView *hHeader = table.horizontalHeader(); |
|
3782 |
QWidget *hHeaderVp = hHeader->viewport(); |
|
3783 |
QPoint colPos((cellRect.left() + cellRect.right()) / 2, 5); |
|
3784 |
QMouseEvent colPressEvent(QEvent::MouseButtonPress, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); |
|
3785 |
qApp->sendEvent(hHeaderVp, &colPressEvent); |
|
3786 |
||
3787 |
for (int i = 0; i < 4; ++i) { |
|
3788 |
colPos.setX(colPos.x() + cellRect.width()); |
|
3789 |
QMouseEvent moveEvent(QEvent::MouseMove, colPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); |
|
3790 |
qApp->sendEvent(hHeaderVp, &moveEvent); |
|
3791 |
} |
|
3792 |
QMouseEvent colReleaseEvent(QEvent::MouseButtonRelease, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); |
|
3793 |
qApp->sendEvent(hHeaderVp, &colReleaseEvent); |
|
3794 |
||
3795 |
for (int i = 0; i < 4; ++i) { |
|
3796 |
QModelIndex index = model.index(0, 3 + i, table.rootIndex()); |
|
3797 |
QVERIFY(hHeader->selectionModel()->selectedColumns().contains(index)); |
|
3798 |
} |
|
3799 |
} |
|
3800 |
||
3801 |
{ |
|
3802 |
QRect cellRect = table.visualRect(model.index(2, 2)); |
|
3803 |
QWidget *tableVp = table.viewport(); |
|
3804 |
QPoint cellPos = cellRect.center(); |
|
3805 |
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); |
|
3806 |
qApp->sendEvent(tableVp, &cellPressEvent); |
|
3807 |
||
3808 |
for (int i = 0; i < 6; ++i) { |
|
3809 |
cellPos.setX(cellPos.x() + cellRect.width()); |
|
3810 |
cellPos.setY(cellPos.y() + cellRect.height()); |
|
3811 |
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); |
|
3812 |
qApp->sendEvent(tableVp, &moveEvent); |
|
3813 |
} |
|
3814 |
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); |
|
3815 |
qApp->sendEvent(tableVp, &cellReleaseEvent); |
|
3816 |
||
3817 |
for (int i = 0; i < 6; ++i) |
|
3818 |
for (int j = 0; j < 6; ++j) { |
|
3819 |
QModelIndex index = model.index(2 + i, 2 + j, table.rootIndex()); |
|
3820 |
QVERIFY(table.selectionModel()->isSelected(index)); |
|
3821 |
} |
|
3822 |
} |
|
3823 |
||
3824 |
{ |
|
3825 |
QRect cellRect = table.visualRect(model.index(3, 3)); |
|
3826 |
QWidget *tableVp = table.viewport(); |
|
3827 |
QPoint cellPos = cellRect.center(); |
|
3828 |
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); |
|
3829 |
qApp->sendEvent(tableVp, &cellPressEvent); |
|
3830 |
||
3831 |
for (int i = 0; i < 6; ++i) { |
|
3832 |
cellPos.setX(cellPos.x() + cellRect.width()); |
|
3833 |
cellPos.setY(cellPos.y() + cellRect.height()); |
|
3834 |
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); |
|
3835 |
qApp->sendEvent(tableVp, &moveEvent); |
|
3836 |
} |
|
3837 |
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); |
|
3838 |
qApp->sendEvent(tableVp, &cellReleaseEvent); |
|
3839 |
||
3840 |
for (int i = 0; i < 6; ++i) |
|
3841 |
for (int j = 0; j < 6; ++j) { |
|
3842 |
QModelIndex index = model.index(3 + i, 3 + j, table.rootIndex()); |
|
3843 |
QVERIFY(!table.selectionModel()->isSelected(index)); |
|
3844 |
} |
|
3845 |
} |
|
3846 |
} |
|
3847 |
||
3848 |
void tst_QTableView::task234926_setHeaderSorting() |
|
3849 |
{ |
|
3850 |
QStringListModel model; |
|
3851 |
QStringList data; |
|
3852 |
data << "orange" << "apple" << "banana" << "lemon" << "pumpkin"; |
|
3853 |
QStringList sortedDataA = data; |
|
3854 |
QStringList sortedDataD = data; |
|
3855 |
qSort(sortedDataA); |
|
3856 |
qSort(sortedDataD.begin(), sortedDataD.end(), qGreater<QString>()); |
|
3857 |
model.setStringList(data); |
|
3858 |
QTableView view; |
|
3859 |
view.setModel(&model); |
|
3860 |
// view.show(); |
|
3861 |
QTest::qWait(20); |
|
3862 |
QCOMPARE(model.stringList(), data); |
|
3863 |
view.setSortingEnabled(true); |
|
3864 |
view.sortByColumn(0, Qt::AscendingOrder); |
|
3865 |
QApplication::processEvents(); |
|
3866 |
QCOMPARE(model.stringList() , sortedDataA); |
|
3867 |
||
3868 |
view.horizontalHeader()->setSortIndicator(0, Qt::DescendingOrder); |
|
3869 |
QApplication::processEvents(); |
|
3870 |
QCOMPARE(model.stringList() , sortedDataD); |
|
3871 |
||
3872 |
QHeaderView *h = new QHeaderView(Qt::Horizontal); |
|
3873 |
h->setModel(&model); |
|
3874 |
view.setHorizontalHeader(h); |
|
3875 |
h->setSortIndicator(0, Qt::AscendingOrder); |
|
3876 |
QApplication::processEvents(); |
|
3877 |
QCOMPARE(model.stringList() , sortedDataA); |
|
3878 |
||
3879 |
h->setSortIndicator(0, Qt::DescendingOrder); |
|
3880 |
QApplication::processEvents(); |
|
3881 |
QCOMPARE(model.stringList() , sortedDataD); |
|
3882 |
} |
|
3883 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3884 |
void tst_QTableView::taskQTBUG_5062_spansInconsistency() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3885 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3886 |
const int nRows = 5; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3887 |
const int nColumns = 5; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3888 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3889 |
QtTestTableModel model(nRows, nColumns); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3890 |
QtTestTableView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3891 |
view.setModel(&model); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3892 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3893 |
for (int i = 0; i < nRows; ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3894 |
view.setSpan(i, 0, 1, nColumns); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3895 |
view.setSpan(2, 0, 1, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3896 |
view.setSpan(3, 0, 1, 1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3897 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3898 |
VERIFY_SPANS_CONSISTENCY(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3899 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3900 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3901 |
void tst_QTableView::taskQTBUG_4516_clickOnRichTextLabel() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3902 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3903 |
QTableView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3904 |
QStandardItemModel model(5,5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3905 |
view.setModel(&model); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3906 |
QLabel label("rich text"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3907 |
label.setTextFormat(Qt::RichText); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3908 |
view.setIndexWidget(model.index(1,1), &label); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3909 |
view.setCurrentIndex(model.index(0,0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3910 |
QCOMPARE(view.currentIndex(), model.index(0,0)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3911 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3912 |
QTest::mouseClick(&label, Qt::LeftButton); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3913 |
QCOMPARE(view.currentIndex(), model.index(1,1)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3914 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3915 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3916 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3917 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3918 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3919 |
void tst_QTableView::changeHeaderData() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3920 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3921 |
QTableView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3922 |
QStandardItemModel model(5,5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3923 |
view.setModel(&model); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3924 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3925 |
QTest::qWaitForWindowShown(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3926 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3927 |
QString text = "long long long text"; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3928 |
const int textWidth = view.verticalHeader()->fontMetrics().width(text); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3929 |
QVERIFY(view.verticalHeader()->width() < textWidth); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3930 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3931 |
model.setHeaderData(2, Qt::Vertical, text); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3932 |
QTest::qWait(100); //leave time for layout |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3933 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3934 |
QVERIFY(view.verticalHeader()->width() > textWidth); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3935 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3936 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3937 |
void tst_QTableView::taskQTBUG_5237_wheelEventOnHeader() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3938 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3939 |
QTableView view; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3940 |
QStandardItemModel model(500,5); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3941 |
view.setModel(&model); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3942 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3943 |
QTest::qWaitForWindowShown(&view); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3944 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3945 |
int sbValueBefore = view.verticalScrollBar()->value(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3946 |
QHeaderView *header = view.verticalHeader(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3947 |
QTest::mouseMove(header); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3948 |
QWheelEvent wheelEvent(header->geometry().center(), -720, 0, 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3949 |
QApplication::sendEvent(header->viewport(), &wheelEvent); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3950 |
int sbValueAfter = view.verticalScrollBar()->value(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3951 |
QVERIFY(sbValueBefore != sbValueAfter); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3952 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3953 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3954 |
class TestTableView : public QTableView { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3955 |
Q_OBJECT |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3956 |
public: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3957 |
TestTableView(QWidget *parent = 0) : QTableView(parent) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3958 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3959 |
connect(this, SIGNAL(entered(const QModelIndex&)), this, SLOT(openEditor(const QModelIndex&))); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3960 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3961 |
~TestTableView(){} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3962 |
public slots: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3963 |
void onDataChanged() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3964 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3965 |
for (int i = 0; i < model()->rowCount(); i++) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3966 |
setRowHidden(i, model()->data(model()->index(i, 0)).toBool()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3967 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3968 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3969 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3970 |
void openEditor(const QModelIndex& index) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3971 |
{ openPersistentEditor(index); } |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3972 |
}; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3973 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3974 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3975 |
void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3976 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3977 |
QStandardItemModel model; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3978 |
model.insertColumn(0, QModelIndex()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3979 |
for(int i = 0; i < 20; i++) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3980 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3981 |
model.insertRow(i); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3982 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3983 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3984 |
TestTableView w; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3985 |
w.setMouseTracking(true); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3986 |
w.setModel(&model); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3987 |
connect(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), &w, SLOT(onDataChanged())); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3988 |
w.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3989 |
QTest::qWaitForWindowShown(&w); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3990 |
for (int i = 0; i < 10; i++) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3991 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3992 |
QTest::mouseMove(w.viewport(), QPoint(50, 20)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3993 |
w.model()->setData(w.indexAt(QPoint(50, 20)), true); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3994 |
QTest::mouseMove(w.viewport(), QPoint(50, 25)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3995 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3996 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3997 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3998 |
class TableView7774 : public QTableView |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
3999 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4000 |
public: |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4001 |
QRegion visualRegionForSelection(const QItemSelection &selection) const |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4002 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4003 |
return QTableView::visualRegionForSelection(selection); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4004 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4005 |
}; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4006 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4007 |
void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4008 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4009 |
TableView7774 view; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4010 |
QStandardItemModel model(5,5); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4011 |
view.setModel(&model); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4012 |
view.setLayoutDirection(Qt::RightToLeft); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4013 |
view.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4014 |
QTest::qWaitForWindowShown(&view); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4015 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4016 |
QItemSelectionRange range(model.index(2, 0), model.index(2, model.columnCount() - 1)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4017 |
QItemSelection selection; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4018 |
selection << range; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4019 |
QRegion region = view.visualRegionForSelection(selection); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4020 |
QCOMPARE(region.rects().at(0), view.visualRect(range.topLeft()) | view.visualRect(range.bottomRight())); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4021 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4022 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4023 |
void tst_QTableView::taskQTBUG_8777_scrollToSpans() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4024 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4025 |
QTableWidget table(75,5); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4026 |
for (int i=0; i<50; i++) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4027 |
table.setSpan(2+i, 0, 1, 5); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4028 |
table.setCurrentCell(0,2); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4029 |
table.show(); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4030 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4031 |
for (int i = 0; i < 45; ++i) |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4032 |
QTest::keyClick(&table, Qt::Key_Down); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4033 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4034 |
QVERIFY(table.verticalScrollBar()->value() > 10); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4035 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
4036 |
|
0 | 4037 |
QTEST_MAIN(tst_QTableView) |
4038 |
#include "tst_qtableview.moc" |