author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QStandardItemModel> |
|
45 |
#include <QStringListModel> |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
46 |
#include <QSortFilterProxyModel> |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
47 |
#include <QTableView> |
0 | 48 |
|
49 |
#include <qabstractitemmodel.h> |
|
50 |
#include <qapplication.h> |
|
51 |
#include <qheaderview.h> |
|
52 |
#include <private/qheaderview_p.h> |
|
53 |
#include <qitemdelegate.h> |
|
54 |
#include <qtreewidget.h> |
|
55 |
#include <qdebug.h> |
|
56 |
||
57 |
typedef QList<int> IntList; |
|
58 |
Q_DECLARE_METATYPE(IntList) |
|
59 |
||
60 |
typedef QList<bool> BoolList; |
|
61 |
Q_DECLARE_METATYPE(BoolList) |
|
62 |
||
63 |
//TESTED_CLASS= |
|
64 |
//TESTED_FILES= |
|
65 |
||
66 |
// Will try to wait for the condition while allowing event processing |
|
67 |
// for a maximum of 2 seconds. |
|
68 |
#define WAIT_FOR_CONDITION(expr, expected) \ |
|
69 |
do { \ |
|
70 |
const int step = 100; \ |
|
71 |
for (int i = 0; i < 2000 && expr != expected; i+=step) { \ |
|
72 |
QTest::qWait(step); \ |
|
73 |
} \ |
|
74 |
} while(0) |
|
75 |
||
76 |
class protected_QHeaderView : public QHeaderView |
|
77 |
{ |
|
78 |
Q_OBJECT |
|
79 |
public: |
|
80 |
protected_QHeaderView(Qt::Orientation orientation) : QHeaderView(orientation) { |
|
81 |
resizeSections(); |
|
82 |
}; |
|
83 |
||
84 |
void testEvent(); |
|
85 |
void testhorizontalOffset(); |
|
86 |
void testverticalOffset(); |
|
87 |
friend class tst_QHeaderView; |
|
88 |
}; |
|
89 |
||
90 |
class tst_QHeaderView : public QObject |
|
91 |
{ |
|
92 |
Q_OBJECT |
|
93 |
||
94 |
public: |
|
95 |
tst_QHeaderView(); |
|
96 |
virtual ~tst_QHeaderView(); |
|
97 |
||
98 |
public slots: |
|
99 |
void initTestCase(); |
|
100 |
void cleanupTestCase(); |
|
101 |
void init(); |
|
102 |
void cleanup(); |
|
103 |
||
104 |
private slots: |
|
105 |
void getSetCheck(); |
|
106 |
void visualIndex(); |
|
107 |
||
108 |
void visualIndexAt_data(); |
|
109 |
void visualIndexAt(); |
|
110 |
||
111 |
void noModel(); |
|
112 |
void emptyModel(); |
|
113 |
void removeRows(); |
|
114 |
void removeCols(); |
|
115 |
||
116 |
void clickable(); |
|
117 |
void movable(); |
|
118 |
void hidden(); |
|
119 |
void stretch(); |
|
120 |
||
121 |
void sectionSize_data(); |
|
122 |
void sectionSize(); |
|
123 |
||
124 |
void length(); |
|
125 |
void offset(); |
|
126 |
void sectionSizeHint(); |
|
127 |
void logicalIndex(); |
|
128 |
void logicalIndexAt(); |
|
129 |
void swapSections(); |
|
130 |
||
131 |
void moveSection_data(); |
|
132 |
void moveSection(); |
|
133 |
||
134 |
void resizeMode(); |
|
135 |
||
136 |
void resizeSection_data(); |
|
137 |
void resizeSection(); |
|
138 |
||
139 |
void resizeAndMoveSection_data(); |
|
140 |
void resizeAndMoveSection(); |
|
141 |
void resizeHiddenSection_data(); |
|
142 |
void resizeHiddenSection(); |
|
143 |
void resizeAndInsertSection_data(); |
|
144 |
void resizeAndInsertSection(); |
|
145 |
void resizeWithResizeModes_data(); |
|
146 |
void resizeWithResizeModes(); |
|
147 |
void moveAndInsertSection_data(); |
|
148 |
void moveAndInsertSection(); |
|
149 |
void highlightSections(); |
|
150 |
void showSortIndicator(); |
|
151 |
void sortIndicatorTracking(); |
|
152 |
void removeAndInsertRow(); |
|
153 |
void unhideSection(); |
|
154 |
void event(); |
|
155 |
void headerDataChanged(); |
|
156 |
void currentChanged(); |
|
157 |
void horizontalOffset(); |
|
158 |
void verticalOffset(); |
|
159 |
void stretchSectionCount(); |
|
160 |
void hiddenSectionCount(); |
|
161 |
void focusPolicy(); |
|
162 |
void moveSectionAndReset(); |
|
163 |
void moveSectionAndRemove(); |
|
164 |
void saveRestore(); |
|
165 |
||
166 |
void defaultAlignment_data(); |
|
167 |
void defaultAlignment(); |
|
168 |
||
169 |
void globalResizeMode_data(); |
|
170 |
void globalResizeMode(); |
|
171 |
||
172 |
void sectionPressedSignal_data(); |
|
173 |
void sectionPressedSignal(); |
|
174 |
void sectionClickedSignal_data() { sectionPressedSignal_data(); } |
|
175 |
void sectionClickedSignal(); |
|
176 |
||
177 |
void defaultSectionSize_data(); |
|
178 |
void defaultSectionSize(); |
|
179 |
||
180 |
void oneSectionSize(); |
|
181 |
||
182 |
void hideAndInsert_data(); |
|
183 |
void hideAndInsert(); |
|
184 |
||
185 |
void removeSection(); |
|
186 |
void preserveHiddenSectionWidth(); |
|
187 |
void invisibleStretchLastSection(); |
|
188 |
||
189 |
void emptySectionSpan(); |
|
190 |
void task236450_hidden_data(); |
|
191 |
void task236450_hidden(); |
|
192 |
void task248050_hideRow(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
void QTBUG6058_reset(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
194 |
void QTBUG7833_sectionClicked(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
195 |
void QTBUG8650_crashOnInsertSections(); |
0 | 196 |
|
197 |
protected: |
|
198 |
QHeaderView *view; |
|
199 |
QStandardItemModel *model; |
|
200 |
}; |
|
201 |
||
202 |
class QtTestModel: public QAbstractTableModel |
|
203 |
{ |
|
204 |
||
205 |
Q_OBJECT |
|
206 |
||
207 |
public: |
|
208 |
QtTestModel(QObject *parent = 0): QAbstractTableModel(parent), |
|
209 |
cols(0), rows(0), wrongIndex(false) {} |
|
210 |
int rowCount(const QModelIndex&) const { return rows; } |
|
211 |
int columnCount(const QModelIndex&) const { return cols; } |
|
212 |
bool isEditable(const QModelIndex &) const { return true; } |
|
213 |
||
214 |
QVariant data(const QModelIndex &idx, int) const |
|
215 |
{ |
|
216 |
if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) { |
|
217 |
wrongIndex = true; |
|
218 |
qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), idx.internalPointer()); |
|
219 |
} |
|
220 |
return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(0);//idx.data()); |
|
221 |
} |
|
222 |
||
223 |
void insertOneColumn(int col) |
|
224 |
{ |
|
225 |
beginInsertColumns(QModelIndex(), col, col); |
|
226 |
--cols; |
|
227 |
endInsertColumns(); |
|
228 |
} |
|
229 |
||
230 |
void removeLastRow() |
|
231 |
{ |
|
232 |
beginRemoveRows(QModelIndex(), rows - 1, rows - 1); |
|
233 |
--rows; |
|
234 |
endRemoveRows(); |
|
235 |
} |
|
236 |
||
237 |
void removeAllRows() |
|
238 |
{ |
|
239 |
beginRemoveRows(QModelIndex(), 0, rows - 1); |
|
240 |
rows = 0; |
|
241 |
endRemoveRows(); |
|
242 |
} |
|
243 |
||
244 |
void removeOneColumn(int col) |
|
245 |
{ |
|
246 |
beginRemoveColumns(QModelIndex(), col, col); |
|
247 |
--cols; |
|
248 |
endRemoveColumns(); |
|
249 |
} |
|
250 |
||
251 |
void removeLastColumn() |
|
252 |
{ |
|
253 |
beginRemoveColumns(QModelIndex(), cols - 1, cols - 1); |
|
254 |
--cols; |
|
255 |
endRemoveColumns(); |
|
256 |
} |
|
257 |
||
258 |
void removeAllColumns() |
|
259 |
{ |
|
260 |
beginRemoveColumns(QModelIndex(), 0, cols - 1); |
|
261 |
cols = 0; |
|
262 |
endRemoveColumns(); |
|
263 |
} |
|
264 |
||
265 |
void cleanup() |
|
266 |
{ |
|
267 |
cols = 3; |
|
268 |
rows = 3; |
|
269 |
emit layoutChanged(); |
|
270 |
} |
|
271 |
||
272 |
int cols, rows; |
|
273 |
mutable bool wrongIndex; |
|
274 |
}; |
|
275 |
||
276 |
// Testing get/set functions |
|
277 |
void tst_QHeaderView::getSetCheck() |
|
278 |
{ |
|
279 |
protected_QHeaderView obj1(Qt::Horizontal); |
|
280 |
// bool QHeaderView::highlightSections() |
|
281 |
// void QHeaderView::setHighlightSections(bool) |
|
282 |
obj1.setHighlightSections(false); |
|
283 |
QCOMPARE(false, obj1.highlightSections()); |
|
284 |
obj1.setHighlightSections(true); |
|
285 |
QCOMPARE(true, obj1.highlightSections()); |
|
286 |
||
287 |
// bool QHeaderView::stretchLastSection() |
|
288 |
// void QHeaderView::setStretchLastSection(bool) |
|
289 |
obj1.setStretchLastSection(false); |
|
290 |
QCOMPARE(false, obj1.stretchLastSection()); |
|
291 |
obj1.setStretchLastSection(true); |
|
292 |
QCOMPARE(true, obj1.stretchLastSection()); |
|
293 |
||
294 |
// int QHeaderView::defaultSectionSize() |
|
295 |
// void QHeaderView::setDefaultSectionSize(int) |
|
296 |
obj1.setDefaultSectionSize(0); |
|
297 |
QCOMPARE(0, obj1.defaultSectionSize()); |
|
298 |
obj1.setDefaultSectionSize(INT_MIN); |
|
299 |
QCOMPARE(INT_MIN, obj1.defaultSectionSize()); |
|
300 |
obj1.setDefaultSectionSize(INT_MAX); |
|
301 |
QCOMPARE(INT_MAX, obj1.defaultSectionSize()); |
|
302 |
// ### the test above does not make sense for values below 0 |
|
303 |
||
304 |
// int QHeaderView::minimumSectionSize() |
|
305 |
// void QHeaderView::setMinimumSectionSize(int) |
|
306 |
obj1.setMinimumSectionSize(0); |
|
307 |
QCOMPARE(0, obj1.minimumSectionSize()); |
|
308 |
obj1.setMinimumSectionSize(INT_MIN); |
|
309 |
QCOMPARE(INT_MIN, obj1.minimumSectionSize()); |
|
310 |
obj1.setMinimumSectionSize(INT_MAX); |
|
311 |
QCOMPARE(INT_MAX, obj1.minimumSectionSize()); |
|
312 |
// ### the test above does not make sense for values below 0 |
|
313 |
||
314 |
// int QHeaderView::offset() |
|
315 |
// void QHeaderView::setOffset(int) |
|
316 |
obj1.setOffset(0); |
|
317 |
QCOMPARE(0, obj1.offset()); |
|
318 |
obj1.setOffset(INT_MIN); |
|
319 |
QCOMPARE(INT_MIN, obj1.offset()); |
|
320 |
obj1.setOffset(INT_MAX); |
|
321 |
QCOMPARE(INT_MAX, obj1.offset()); |
|
322 |
||
323 |
} |
|
324 |
||
325 |
tst_QHeaderView::tst_QHeaderView() |
|
326 |
{ |
|
327 |
qRegisterMetaType<int>("Qt::SortOrder"); |
|
328 |
} |
|
329 |
||
330 |
tst_QHeaderView::~tst_QHeaderView() |
|
331 |
{ |
|
332 |
} |
|
333 |
||
334 |
void tst_QHeaderView::initTestCase() |
|
335 |
{ |
|
336 |
#ifdef Q_OS_WINCE //disable magic for WindowsCE |
|
337 |
qApp->setAutoMaximizeThreshold(-1); |
|
338 |
#endif |
|
339 |
} |
|
340 |
||
341 |
void tst_QHeaderView::cleanupTestCase() |
|
342 |
{ |
|
343 |
} |
|
344 |
||
345 |
void tst_QHeaderView::init() |
|
346 |
{ |
|
347 |
view = new QHeaderView(Qt::Vertical); |
|
348 |
// Some initial value tests before a model is added |
|
349 |
QCOMPARE(view->length(), 0); |
|
350 |
QVERIFY(view->sizeHint() == QSize(0,0)); |
|
351 |
QCOMPARE(view->sectionSizeHint(0), -1); |
|
352 |
||
353 |
/* |
|
354 |
model = new QStandardItemModel(1, 1); |
|
355 |
view->setModel(model); |
|
356 |
//qDebug() << view->count(); |
|
357 |
view->sizeHint(); |
|
358 |
*/ |
|
359 |
||
360 |
int rows = 4; |
|
361 |
int columns = 4; |
|
362 |
model = new QStandardItemModel(rows, columns); |
|
363 |
/* |
|
364 |
for (int row = 0; row < rows; ++row) { |
|
365 |
for (int column = 0; column < columns; ++column) { |
|
366 |
QModelIndex index = model->index(row, column, QModelIndex()); |
|
367 |
model->setData(index, QVariant((row+1) * (column+1))); |
|
368 |
} |
|
369 |
} |
|
370 |
*/ |
|
371 |
||
372 |
QSignalSpy spy(view, SIGNAL(sectionCountChanged(int, int))); |
|
373 |
view->setModel(model); |
|
374 |
QCOMPARE(spy.count(), 1); |
|
375 |
view->show(); |
|
376 |
} |
|
377 |
||
378 |
void tst_QHeaderView::cleanup() |
|
379 |
{ |
|
380 |
delete view; |
|
381 |
view = 0; |
|
382 |
delete model; |
|
383 |
model = 0; |
|
384 |
} |
|
385 |
||
386 |
void tst_QHeaderView::noModel() |
|
387 |
{ |
|
388 |
QHeaderView emptyView(Qt::Vertical); |
|
389 |
QCOMPARE(emptyView.count(), 0); |
|
390 |
} |
|
391 |
||
392 |
void tst_QHeaderView::emptyModel() |
|
393 |
{ |
|
394 |
QtTestModel testmodel; |
|
395 |
view->setModel(&testmodel); |
|
396 |
QVERIFY(!testmodel.wrongIndex); |
|
397 |
QCOMPARE(view->count(), testmodel.rows); |
|
398 |
view->setModel(model); |
|
399 |
} |
|
400 |
||
401 |
void tst_QHeaderView::removeRows() |
|
402 |
{ |
|
403 |
QtTestModel model; |
|
404 |
model.rows = model.cols = 10; |
|
405 |
||
406 |
QHeaderView vertical(Qt::Vertical); |
|
407 |
QHeaderView horizontal(Qt::Horizontal); |
|
408 |
||
409 |
vertical.setModel(&model); |
|
410 |
horizontal.setModel(&model); |
|
411 |
vertical.show(); |
|
412 |
horizontal.show(); |
|
413 |
QCOMPARE(vertical.count(), model.rows); |
|
414 |
QCOMPARE(horizontal.count(), model.cols); |
|
415 |
||
416 |
model.removeLastRow(); |
|
417 |
QVERIFY(!model.wrongIndex); |
|
418 |
QCOMPARE(vertical.count(), model.rows); |
|
419 |
QCOMPARE(horizontal.count(), model.cols); |
|
420 |
||
421 |
model.removeAllRows(); |
|
422 |
QVERIFY(!model.wrongIndex); |
|
423 |
QCOMPARE(vertical.count(), model.rows); |
|
424 |
QCOMPARE(horizontal.count(), model.cols); |
|
425 |
} |
|
426 |
||
427 |
||
428 |
void tst_QHeaderView::removeCols() |
|
429 |
{ |
|
430 |
QtTestModel model; |
|
431 |
model.rows = model.cols = 10; |
|
432 |
||
433 |
QHeaderView vertical(Qt::Vertical); |
|
434 |
QHeaderView horizontal(Qt::Horizontal); |
|
435 |
vertical.setModel(&model); |
|
436 |
horizontal.setModel(&model); |
|
437 |
vertical.show(); |
|
438 |
horizontal.show(); |
|
439 |
QCOMPARE(vertical.count(), model.rows); |
|
440 |
QCOMPARE(horizontal.count(), model.cols); |
|
441 |
||
442 |
model.removeLastColumn(); |
|
443 |
QVERIFY(!model.wrongIndex); |
|
444 |
QCOMPARE(vertical.count(), model.rows); |
|
445 |
QCOMPARE(horizontal.count(), model.cols); |
|
446 |
||
447 |
model.removeAllColumns(); |
|
448 |
QVERIFY(!model.wrongIndex); |
|
449 |
QCOMPARE(vertical.count(), model.rows); |
|
450 |
QCOMPARE(horizontal.count(), model.cols); |
|
451 |
} |
|
452 |
||
453 |
void tst_QHeaderView::movable() |
|
454 |
{ |
|
455 |
QCOMPARE(view->isMovable(), false); |
|
456 |
view->setMovable(false); |
|
457 |
QCOMPARE(view->isMovable(), false); |
|
458 |
view->setMovable(true); |
|
459 |
QCOMPARE(view->isMovable(), true); |
|
460 |
} |
|
461 |
||
462 |
void tst_QHeaderView::clickable() |
|
463 |
{ |
|
464 |
QCOMPARE(view->isClickable(), false); |
|
465 |
view->setClickable(false); |
|
466 |
QCOMPARE(view->isClickable(), false); |
|
467 |
view->setClickable(true); |
|
468 |
QCOMPARE(view->isClickable(), true); |
|
469 |
} |
|
470 |
||
471 |
void tst_QHeaderView::hidden() |
|
472 |
{ |
|
473 |
//hideSection() & showSection call setSectionHidden |
|
474 |
// Test bad arguments |
|
475 |
QCOMPARE(view->isSectionHidden(-1), false); |
|
476 |
QCOMPARE(view->isSectionHidden(view->count()), false); |
|
477 |
QCOMPARE(view->isSectionHidden(999999), false); |
|
478 |
||
479 |
view->setSectionHidden(-1, true); |
|
480 |
view->setSectionHidden(view->count(), true); |
|
481 |
view->setSectionHidden(999999, true); |
|
482 |
view->setSectionHidden(-1, false); |
|
483 |
view->setSectionHidden(view->count(), false); |
|
484 |
view->setSectionHidden(999999, false); |
|
485 |
||
486 |
// Hidden sections shouldn't have visual properties (except position) |
|
487 |
int pos = view->defaultSectionSize(); |
|
488 |
view->setSectionHidden(1, true); |
|
489 |
QCOMPARE(view->sectionSize(1), 0); |
|
490 |
QCOMPARE(view->sectionPosition(1), pos); |
|
491 |
view->resizeSection(1, 100); |
|
492 |
QCOMPARE(view->sectionViewportPosition(1), pos); |
|
493 |
QCOMPARE(view->sectionSize(1), 0); |
|
494 |
view->setSectionHidden(1, false); |
|
495 |
QCOMPARE(view->isSectionHidden(0), false); |
|
496 |
QCOMPARE(view->sectionSize(0), view->defaultSectionSize()); |
|
497 |
} |
|
498 |
||
499 |
void tst_QHeaderView::stretch() |
|
500 |
{ |
|
501 |
// Show before resize and setStrechLastSection |
|
502 |
#if defined(Q_OS_WINCE) |
|
503 |
QSize viewSize(200,300); |
|
504 |
#else |
|
505 |
QSize viewSize(500, 500); |
|
506 |
#endif |
|
507 |
view->resize(viewSize); |
|
508 |
view->setStretchLastSection(true); |
|
509 |
QCOMPARE(view->stretchLastSection(), true); |
|
510 |
view->show(); |
|
511 |
QCOMPARE(view->width(), viewSize.width()); |
|
512 |
QCOMPARE(view->visualIndexAt(view->viewport()->height() - 5), 3); |
|
513 |
||
514 |
view->setSectionHidden(3, true); |
|
515 |
QCOMPARE(view->visualIndexAt(view->viewport()->height() - 5), 2); |
|
516 |
||
517 |
view->setStretchLastSection(false); |
|
518 |
QCOMPARE(view->stretchLastSection(), false); |
|
519 |
} |
|
520 |
||
521 |
void tst_QHeaderView::oneSectionSize() |
|
522 |
{ |
|
523 |
//this ensures that if there is only one section, it gets a correct width (more than 0) |
|
524 |
QHeaderView view (Qt::Vertical); |
|
525 |
QtTestModel model; |
|
526 |
model.cols = 1; |
|
527 |
model.rows = 1; |
|
528 |
||
529 |
view.setResizeMode(QHeaderView::Interactive); |
|
530 |
view.setModel(&model); |
|
531 |
||
532 |
view.show(); |
|
533 |
||
534 |
QVERIFY(view.sectionSize(0) > 0); |
|
535 |
} |
|
536 |
||
537 |
||
538 |
void tst_QHeaderView::sectionSize_data() |
|
539 |
{ |
|
540 |
QTest::addColumn<QList<int> >("boundsCheck"); |
|
541 |
QTest::addColumn<QList<int> >("defaultSizes"); |
|
542 |
QTest::addColumn<int>("initialDefaultSize"); |
|
543 |
QTest::addColumn<int>("lastVisibleSectionSize"); |
|
544 |
QTest::addColumn<int>("persistentSectionSize"); |
|
545 |
||
546 |
QTest::newRow("data set one") |
|
547 |
<< (QList<int>() << -1 << 0 << 4 << 9999) |
|
548 |
<< (QList<int>() << 10 << 30 << 30) |
|
549 |
<< 30 |
|
550 |
<< 300 |
|
551 |
<< 20; |
|
552 |
} |
|
553 |
||
554 |
void tst_QHeaderView::sectionSize() |
|
555 |
{ |
|
556 |
QFETCH(QList<int>, boundsCheck); |
|
557 |
QFETCH(QList<int>, defaultSizes); |
|
558 |
QFETCH(int, initialDefaultSize); |
|
559 |
QFETCH(int, lastVisibleSectionSize); |
|
560 |
QFETCH(int, persistentSectionSize); |
|
561 |
||
562 |
#ifdef Q_OS_WINCE |
|
563 |
// We test on a device with doubled pixels. Therefore we need to specify |
|
564 |
// different boundaries. |
|
565 |
initialDefaultSize = qMax(view->minimumSectionSize(), 30); |
|
566 |
#endif |
|
567 |
||
568 |
// bounds check |
|
569 |
foreach (int val, boundsCheck) |
|
570 |
view->sectionSize(val); |
|
571 |
||
572 |
// default size |
|
573 |
QCOMPARE(view->defaultSectionSize(), initialDefaultSize); |
|
574 |
foreach (int def, defaultSizes) { |
|
575 |
view->setDefaultSectionSize(def); |
|
576 |
QCOMPARE(view->defaultSectionSize(), def); |
|
577 |
} |
|
578 |
||
579 |
view->setDefaultSectionSize(initialDefaultSize); |
|
580 |
for (int s = 0; s < view->count(); ++s) |
|
581 |
QCOMPARE(view->sectionSize(s), initialDefaultSize); |
|
582 |
view->doItemsLayout(); |
|
583 |
||
584 |
// stretch last section |
|
585 |
view->setStretchLastSection(true); |
|
586 |
int lastSection = view->count() - 1; |
|
587 |
||
588 |
//test that when hiding the last column, |
|
589 |
//resizing the new last visible columns still works |
|
590 |
view->hideSection(lastSection); |
|
591 |
view->resizeSection(lastSection - 1, lastVisibleSectionSize); |
|
592 |
QCOMPARE(view->sectionSize(lastSection - 1), lastVisibleSectionSize); |
|
593 |
view->showSection(lastSection); |
|
594 |
||
595 |
// turn off stretching |
|
596 |
view->setStretchLastSection(false); |
|
597 |
QCOMPARE(view->sectionSize(lastSection), initialDefaultSize); |
|
598 |
||
599 |
// test persistence |
|
600 |
int sectionCount = view->count(); |
|
601 |
for (int i = 0; i < sectionCount; ++i) |
|
602 |
view->resizeSection(i, persistentSectionSize); |
|
603 |
QtTestModel model; |
|
604 |
model.cols = sectionCount * 2; |
|
605 |
model.rows = sectionCount * 2; |
|
606 |
view->setModel(&model); |
|
607 |
for (int j = 0; j < sectionCount; ++j) |
|
608 |
QCOMPARE(view->sectionSize(j), persistentSectionSize); |
|
609 |
for (int k = sectionCount; k < view->count(); ++k) |
|
610 |
QCOMPARE(view->sectionSize(k), initialDefaultSize); |
|
611 |
} |
|
612 |
||
613 |
void tst_QHeaderView::visualIndex() |
|
614 |
{ |
|
615 |
// Test bad arguments |
|
616 |
QCOMPARE(view->visualIndex(999999), -1); |
|
617 |
QCOMPARE(view->visualIndex(-1), -1); |
|
618 |
QCOMPARE(view->visualIndex(1), 1); |
|
619 |
view->setSectionHidden(1, true); |
|
620 |
QCOMPARE(view->visualIndex(1), 1); |
|
621 |
QCOMPARE(view->visualIndex(2), 2); |
|
622 |
||
623 |
view->setSectionHidden(1, false); |
|
624 |
QCOMPARE(view->visualIndex(1), 1); |
|
625 |
QCOMPARE(view->visualIndex(2), 2); |
|
626 |
} |
|
627 |
||
628 |
void tst_QHeaderView::visualIndexAt_data() |
|
629 |
{ |
|
630 |
QTest::addColumn<QList<int> >("hidden"); |
|
631 |
QTest::addColumn<QList<int> >("from"); |
|
632 |
QTest::addColumn<QList<int> >("to"); |
|
633 |
QTest::addColumn<QList<int> >("coordinate"); |
|
634 |
QTest::addColumn<QList<int> >("visual"); |
|
635 |
||
636 |
QList<int> coordinateList; |
|
637 |
#ifndef Q_OS_WINCE |
|
638 |
coordinateList << -1 << 0 << 31 << 91 << 99999; |
|
639 |
#else |
|
640 |
// We test on a device with doubled pixels. Therefore we need to specify |
|
641 |
// different boundaries. |
|
642 |
coordinateList << -1 << 0 << 33 << 97 << 99999; |
|
643 |
#endif |
|
644 |
||
645 |
QTest::newRow("no hidden, no moved sections") |
|
646 |
<< QList<int>() |
|
647 |
<< QList<int>() |
|
648 |
<< QList<int>() |
|
649 |
<< coordinateList |
|
650 |
<< (QList<int>() << -1 << 0 << 1 << 3 << -1); |
|
651 |
||
652 |
QTest::newRow("no hidden, moved sections") |
|
653 |
<< QList<int>() |
|
654 |
<< (QList<int>() << 0) |
|
655 |
<< (QList<int>() << 1) |
|
656 |
<< coordinateList |
|
657 |
<< (QList<int>() << -1 << 0 << 1 << 3 << -1); |
|
658 |
||
659 |
QTest::newRow("hidden, no moved sections") |
|
660 |
<< (QList<int>() << 0) |
|
661 |
<< QList<int>() |
|
662 |
<< QList<int>() |
|
663 |
<< coordinateList |
|
664 |
<< (QList<int>() << -1 << 1 << 2 << 3 << -1); |
|
665 |
} |
|
666 |
||
667 |
void tst_QHeaderView::visualIndexAt() |
|
668 |
{ |
|
669 |
QFETCH(QList<int>, hidden); |
|
670 |
QFETCH(QList<int>, from); |
|
671 |
QFETCH(QList<int>, to); |
|
672 |
QFETCH(QList<int>, coordinate); |
|
673 |
QFETCH(QList<int>, visual); |
|
674 |
||
675 |
view->setStretchLastSection(true); |
|
676 |
view->show(); |
|
677 |
||
678 |
for (int i = 0; i < hidden.count(); ++i) |
|
679 |
view->setSectionHidden(hidden.at(i), true); |
|
680 |
||
681 |
for (int j = 0; j < from.count(); ++j) |
|
682 |
view->moveSection(from.at(j), to.at(j)); |
|
683 |
||
684 |
for (int k = 0; k < coordinate.count(); ++k) |
|
685 |
QCOMPARE(view->visualIndexAt(coordinate.at(k)), visual.at(k)); |
|
686 |
} |
|
687 |
||
688 |
void tst_QHeaderView::length() |
|
689 |
{ |
|
690 |
#if defined(Q_OS_WINCE) |
|
691 |
QFont font(QLatin1String("Tahoma"), 7); |
|
692 |
view->setFont(font); |
|
693 |
#elif defined(Q_OS_SYMBIAN) |
|
694 |
QFont font(QLatin1String("Series 60 Sans"), 6); |
|
695 |
view->setFont(font); |
|
696 |
#endif |
|
697 |
view->setStretchLastSection(true); |
|
698 |
view->show(); |
|
699 |
||
700 |
//minimumSectionSize should be the size of the last section of the widget is not tall enough |
|
701 |
int length = view->minimumSectionSize(); |
|
702 |
for (int i=0; i < view->count()-1; i++) { |
|
703 |
length += view->sectionSize(i); |
|
704 |
} |
|
705 |
||
706 |
length = qMax(length, view->viewport()->height()); |
|
707 |
QCOMPARE(length, view->length()); |
|
708 |
||
709 |
view->setStretchLastSection(false); |
|
710 |
view->show(); |
|
711 |
||
712 |
QVERIFY(length != view->length()); |
|
713 |
||
714 |
// layoutChanged might mean rows have been removed |
|
715 |
QtTestModel model; |
|
716 |
model.cols = 10; |
|
717 |
model.rows = 10; |
|
718 |
view->setModel(&model); |
|
719 |
int oldLength = view->length(); |
|
720 |
model.cleanup(); |
|
721 |
QCOMPARE(model.rows, view->count()); |
|
722 |
QVERIFY(oldLength != view->length()); |
|
723 |
} |
|
724 |
||
725 |
void tst_QHeaderView::offset() |
|
726 |
{ |
|
727 |
QCOMPARE(view->offset(), 0); |
|
728 |
view->setOffset(10); |
|
729 |
QCOMPARE(view->offset(), 10); |
|
730 |
view->setOffset(0); |
|
731 |
QCOMPARE(view->offset(), 0); |
|
732 |
||
733 |
// Test odd arguments |
|
734 |
view->setOffset(-1); |
|
735 |
} |
|
736 |
||
737 |
void tst_QHeaderView::sectionSizeHint() |
|
738 |
{ |
|
739 |
// Test bad arguments |
|
740 |
view->sectionSizeHint(-1); |
|
741 |
view->sectionSizeHint(99999); |
|
742 |
||
743 |
// TODO how to test the return value? |
|
744 |
} |
|
745 |
||
746 |
void tst_QHeaderView::logicalIndex() |
|
747 |
{ |
|
748 |
// Test bad arguments |
|
749 |
QCOMPARE(view->logicalIndex(-1), -1); |
|
750 |
QCOMPARE(view->logicalIndex(99999), -1); |
|
751 |
} |
|
752 |
||
753 |
void tst_QHeaderView::logicalIndexAt() |
|
754 |
{ |
|
755 |
// Test bad arguments |
|
756 |
view->logicalIndexAt(-1); |
|
757 |
view->logicalIndexAt(99999); |
|
758 |
QCOMPARE(view->logicalIndexAt(0), 0); |
|
759 |
QCOMPARE(view->logicalIndexAt(1), 0); |
|
760 |
||
761 |
view->show(); |
|
762 |
view->setStretchLastSection(true); |
|
763 |
// First item |
|
764 |
QCOMPARE(view->logicalIndexAt(0), 0); |
|
765 |
QCOMPARE(view->logicalIndexAt(view->sectionSize(0)-1), 0); |
|
766 |
QCOMPARE(view->logicalIndexAt(view->sectionSize(0)+1), 1); |
|
767 |
// Last item |
|
768 |
int last = view->length() - 1;//view->viewport()->height() - 10; |
|
769 |
QCOMPARE(view->logicalIndexAt(last), 3); |
|
770 |
// Not in widget |
|
771 |
int outofbounds = view->length() + 1;//view->viewport()->height() + 1; |
|
772 |
QCOMPARE(view->logicalIndexAt(outofbounds), -1); |
|
773 |
||
774 |
view->moveSection(0,1); |
|
775 |
// First item |
|
776 |
QCOMPARE(view->logicalIndexAt(0), 1); |
|
777 |
QCOMPARE(view->logicalIndexAt(view->sectionSize(0)-1), 1); |
|
778 |
QCOMPARE(view->logicalIndexAt(view->sectionSize(0)+1), 0); |
|
779 |
// Last item |
|
780 |
QCOMPARE(view->logicalIndexAt(last), 3); |
|
781 |
view->moveSection(1,0); |
|
782 |
||
783 |
} |
|
784 |
||
785 |
void tst_QHeaderView::swapSections() |
|
786 |
{ |
|
787 |
view->swapSections(-1, 1); |
|
788 |
view->swapSections(99999, 1); |
|
789 |
view->swapSections(1, -1); |
|
790 |
view->swapSections(1, 99999); |
|
791 |
||
792 |
QVector<int> logical = (QVector<int>() << 0 << 1 << 2 << 3); |
|
793 |
||
794 |
QSignalSpy spy1(view, SIGNAL(sectionMoved(int, int, int))); |
|
795 |
||
796 |
QCOMPARE(view->sectionsMoved(), false); |
|
797 |
view->swapSections(1, 1); |
|
798 |
QCOMPARE(view->sectionsMoved(), false); |
|
799 |
view->swapSections(1, 2); |
|
800 |
QCOMPARE(view->sectionsMoved(), true); |
|
801 |
view->swapSections(2, 1); |
|
802 |
QCOMPARE(view->sectionsMoved(), true); |
|
803 |
for (int i = 0; i < view->count(); ++i) |
|
804 |
QCOMPARE(view->logicalIndex(i), logical.at(i)); |
|
805 |
QCOMPARE(spy1.count(), 4); |
|
806 |
||
807 |
logical = (QVector<int>() << 3 << 1 << 2 << 0); |
|
808 |
view->swapSections(3, 0); |
|
809 |
QCOMPARE(view->sectionsMoved(), true); |
|
810 |
for (int j = 0; j < view->count(); ++j) |
|
811 |
QCOMPARE(view->logicalIndex(j), logical.at(j)); |
|
812 |
QCOMPARE(spy1.count(), 6); |
|
813 |
} |
|
814 |
||
815 |
void tst_QHeaderView::moveSection_data() |
|
816 |
{ |
|
817 |
QTest::addColumn<QList<int> >("hidden"); |
|
818 |
QTest::addColumn<QList<int> >("from"); |
|
819 |
QTest::addColumn<QList<int> >("to"); |
|
820 |
QTest::addColumn<QList<bool> >("moved"); |
|
821 |
QTest::addColumn<QList<int> >("logical"); |
|
822 |
QTest::addColumn<int>("count"); |
|
823 |
||
824 |
QTest::newRow("bad args, no hidden") |
|
825 |
<< QList<int>() |
|
826 |
<< (QList<int>() << -1 << 1 << 99999 << 1) |
|
827 |
<< (QList<int>() << 1 << -1 << 1 << 99999) |
|
828 |
<< (QList<bool>() << false << false << false << false) |
|
829 |
<< (QList<int>() << 0 << 1 << 2 << 3) |
|
830 |
<< 0; |
|
831 |
||
832 |
QTest::newRow("good args, no hidden") |
|
833 |
<< QList<int>() |
|
834 |
<< (QList<int>() << 1 << 1 << 2 << 1) |
|
835 |
<< (QList<int>() << 1 << 2 << 1 << 2) |
|
836 |
<< (QList<bool>() << false << true << true << true) |
|
837 |
<< (QList<int>() << 0 << 2 << 1 << 3) |
|
838 |
<< 3; |
|
839 |
||
840 |
QTest::newRow("hidden sections") |
|
841 |
<< (QList<int>() << 0 << 3) |
|
842 |
<< (QList<int>() << 1 << 1 << 2 << 1) |
|
843 |
<< (QList<int>() << 1 << 2 << 1 << 2) |
|
844 |
<< (QList<bool>() << false << true << true << true) |
|
845 |
<< (QList<int>() << 0 << 2 << 1 << 3) |
|
846 |
<< 3; |
|
847 |
} |
|
848 |
||
849 |
void tst_QHeaderView::moveSection() |
|
850 |
{ |
|
851 |
QFETCH(QList<int>, hidden); |
|
852 |
QFETCH(QList<int>, from); |
|
853 |
QFETCH(QList<int>, to); |
|
854 |
QFETCH(QList<bool>, moved); |
|
855 |
QFETCH(QList<int>, logical); |
|
856 |
QFETCH(int, count); |
|
857 |
||
858 |
QVERIFY(from.count() == to.count()); |
|
859 |
QVERIFY(from.count() == moved.count()); |
|
860 |
QVERIFY(view->count() == logical.count()); |
|
861 |
||
862 |
QSignalSpy spy1(view, SIGNAL(sectionMoved(int, int, int))); |
|
863 |
QCOMPARE(view->sectionsMoved(), false); |
|
864 |
||
865 |
for (int h = 0; h < hidden.count(); ++h) |
|
866 |
view->setSectionHidden(hidden.at(h), true); |
|
867 |
||
868 |
for (int i = 0; i < from.count(); ++i) { |
|
869 |
view->moveSection(from.at(i), to.at(i)); |
|
870 |
QCOMPARE(view->sectionsMoved(), moved.at(i)); |
|
871 |
} |
|
872 |
||
873 |
for (int j = 0; j < view->count(); ++j) |
|
874 |
QCOMPARE(view->logicalIndex(j), logical.at(j)); |
|
875 |
||
876 |
QCOMPARE(spy1.count(), count); |
|
877 |
} |
|
878 |
||
879 |
void tst_QHeaderView::resizeAndMoveSection_data() |
|
880 |
{ |
|
881 |
QTest::addColumn<IntList>("logicalIndexes"); |
|
882 |
QTest::addColumn<IntList>("sizes"); |
|
883 |
QTest::addColumn<int>("logicalFrom"); |
|
884 |
QTest::addColumn<int>("logicalTo"); |
|
885 |
||
886 |
QTest::newRow("resizeAndMove-1") |
|
887 |
<< (IntList() << 0 << 1) |
|
888 |
<< (IntList() << 20 << 40) |
|
889 |
<< 0 << 1; |
|
890 |
||
891 |
QTest::newRow("resizeAndMove-2") |
|
892 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
893 |
<< (IntList() << 20 << 60 << 10 << 80) |
|
894 |
<< 0 << 2; |
|
895 |
||
896 |
QTest::newRow("resizeAndMove-3") |
|
897 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
898 |
<< (IntList() << 100 << 60 << 40 << 10) |
|
899 |
<< 0 << 3; |
|
900 |
||
901 |
QTest::newRow("resizeAndMove-4") |
|
902 |
<< (IntList() << 0 << 1 << 2 << 3) |
|
903 |
<< (IntList() << 10 << 40 << 80 << 30) |
|
904 |
<< 1 << 2; |
|
905 |
||
906 |
QTest::newRow("resizeAndMove-5") |
|
907 |
<< (IntList() << 2 << 3) |
|
908 |
<< (IntList() << 100 << 200) |
|
909 |
<< 3 << 2; |
|
910 |
} |
|
911 |
||
912 |
void tst_QHeaderView::resizeAndMoveSection() |
|
913 |
{ |
|
914 |
QFETCH(IntList, logicalIndexes); |
|
915 |
QFETCH(IntList, sizes); |
|
916 |
QFETCH(int, logicalFrom); |
|
917 |
QFETCH(int, logicalTo); |
|
918 |
||
919 |
// Save old visual indexes and sizes |
|
920 |
IntList oldVisualIndexes; |
|
921 |
IntList oldSizes; |
|
922 |
foreach (int logical, logicalIndexes) { |
|
923 |
oldVisualIndexes.append(view->visualIndex(logical)); |
|
924 |
oldSizes.append(view->sectionSize(logical)); |
|
925 |
} |
|
926 |
||
927 |
// Resize sections |
|
928 |
for (int i = 0; i < logicalIndexes.size(); ++i) { |
|
929 |
int logical = logicalIndexes.at(i); |
|
930 |
view->resizeSection(logical, sizes.at(i)); |
|
931 |
} |
|
932 |
||
933 |
// Move sections |
|
934 |
int visualFrom = view->visualIndex(logicalFrom); |
|
935 |
int visualTo = view->visualIndex(logicalTo); |
|
936 |
view->moveSection(visualFrom, visualTo); |
|
937 |
QCOMPARE(view->visualIndex(logicalFrom), visualTo); |
|
938 |
||
939 |
// Check that sizes are still correct |
|
940 |
for (int i = 0; i < logicalIndexes.size(); ++i) { |
|
941 |
int logical = logicalIndexes.at(i); |
|
942 |
QCOMPARE(view->sectionSize(logical), sizes.at(i)); |
|
943 |
} |
|
944 |
||
945 |
// Move sections back |
|
946 |
view->moveSection(visualTo, visualFrom); |
|
947 |
||
948 |
// Check that sizes are still correct |
|
949 |
for (int i = 0; i < logicalIndexes.size(); ++i) { |
|
950 |
int logical = logicalIndexes.at(i); |
|
951 |
QCOMPARE(view->sectionSize(logical), sizes.at(i)); |
|
952 |
} |
|
953 |
||
954 |
// Put everything back as it was |
|
955 |
for (int i = 0; i < logicalIndexes.size(); ++i) { |
|
956 |
int logical = logicalIndexes.at(i); |
|
957 |
view->resizeSection(logical, oldSizes.at(i)); |
|
958 |
QCOMPARE(view->visualIndex(logical), oldVisualIndexes.at(i)); |
|
959 |
} |
|
960 |
} |
|
961 |
||
962 |
void tst_QHeaderView::resizeHiddenSection_data() |
|
963 |
{ |
|
964 |
QTest::addColumn<int>("section"); |
|
965 |
QTest::addColumn<int>("initialSize"); |
|
966 |
QTest::addColumn<int>("finalSize"); |
|
967 |
||
968 |
QTest::newRow("section 0 resize 50 to 20") |
|
969 |
<< 0 << 50 << 20; |
|
970 |
||
971 |
QTest::newRow("section 1 resize 50 to 20") |
|
972 |
<< 1 << 50 << 20; |
|
973 |
||
974 |
QTest::newRow("section 2 resize 50 to 20") |
|
975 |
<< 2 << 50 << 20; |
|
976 |
||
977 |
QTest::newRow("section 3 resize 50 to 20") |
|
978 |
<< 3 << 50 << 20; |
|
979 |
} |
|
980 |
||
981 |
void tst_QHeaderView::resizeHiddenSection() |
|
982 |
{ |
|
983 |
QFETCH(int, section); |
|
984 |
QFETCH(int, initialSize); |
|
985 |
QFETCH(int, finalSize); |
|
986 |
||
987 |
view->resizeSection(section, initialSize); |
|
988 |
view->setSectionHidden(section, true); |
|
989 |
QCOMPARE(view->sectionSize(section), 0); |
|
990 |
||
991 |
view->resizeSection(section, finalSize); |
|
992 |
QCOMPARE(view->sectionSize(section), 0); |
|
993 |
||
994 |
view->setSectionHidden(section, false); |
|
995 |
QCOMPARE(view->sectionSize(section), finalSize); |
|
996 |
} |
|
997 |
||
998 |
void tst_QHeaderView::resizeAndInsertSection_data() |
|
999 |
{ |
|
1000 |
QTest::addColumn<int>("section"); |
|
1001 |
QTest::addColumn<int>("size"); |
|
1002 |
QTest::addColumn<int>("insert"); |
|
1003 |
QTest::addColumn<int>("compare"); |
|
1004 |
QTest::addColumn<int>("expected"); |
|
1005 |
||
1006 |
QTest::newRow("section 0 size 50 insert 0") |
|
1007 |
<< 0 << 50 << 0 << 1 << 50; |
|
1008 |
||
1009 |
QTest::newRow("section 1 size 50 insert 1") |
|
1010 |
<< 0 << 50 << 1 << 0 << 50; |
|
1011 |
||
1012 |
QTest::newRow("section 1 size 50 insert 0") |
|
1013 |
<< 1 << 50 << 0 << 2 << 50; |
|
1014 |
||
1015 |
} |
|
1016 |
||
1017 |
void tst_QHeaderView::resizeAndInsertSection() |
|
1018 |
{ |
|
1019 |
QFETCH(int, section); |
|
1020 |
QFETCH(int, size); |
|
1021 |
QFETCH(int, insert); |
|
1022 |
QFETCH(int, compare); |
|
1023 |
QFETCH(int, expected); |
|
1024 |
||
1025 |
view->setStretchLastSection(false); |
|
1026 |
||
1027 |
view->resizeSection(section, size); |
|
1028 |
QCOMPARE(view->sectionSize(section), size); |
|
1029 |
||
1030 |
model->insertRow(insert); |
|
1031 |
||
1032 |
QCOMPARE(view->sectionSize(compare), expected); |
|
1033 |
} |
|
1034 |
||
1035 |
void tst_QHeaderView::resizeWithResizeModes_data() |
|
1036 |
{ |
|
1037 |
QTest::addColumn<int>("size"); |
|
1038 |
QTest::addColumn<QList<int> >("sections"); |
|
1039 |
QTest::addColumn<QList<int> >("modes"); |
|
1040 |
QTest::addColumn<QList<int> >("expected"); |
|
1041 |
||
1042 |
QTest::newRow("stretch first section") |
|
1043 |
<< 600 |
|
1044 |
<< (QList<int>() << 100 << 100 << 100 << 100) |
|
1045 |
<< (QList<int>() << ((int)QHeaderView::Stretch) |
|
1046 |
<< ((int)QHeaderView::Interactive) |
|
1047 |
<< ((int)QHeaderView::Interactive) |
|
1048 |
<< ((int)QHeaderView::Interactive)) |
|
1049 |
<< (QList<int>() << 300 << 100 << 100 << 100); |
|
1050 |
} |
|
1051 |
||
1052 |
void tst_QHeaderView::resizeWithResizeModes() |
|
1053 |
{ |
|
1054 |
QFETCH(int, size); |
|
1055 |
QFETCH(QList<int>, sections); |
|
1056 |
QFETCH(QList<int>, modes); |
|
1057 |
QFETCH(QList<int>, expected); |
|
1058 |
||
1059 |
view->setStretchLastSection(false); |
|
1060 |
for (int i = 0; i < sections.count(); ++i) { |
|
1061 |
view->resizeSection(i, sections.at(i)); |
|
1062 |
view->setResizeMode(i, (QHeaderView::ResizeMode)modes.at(i)); |
|
1063 |
} |
|
1064 |
view->show(); |
|
1065 |
view->resize(size, size); |
|
1066 |
for (int j = 0; j < expected.count(); ++j) |
|
1067 |
QCOMPARE(view->sectionSize(j), expected.at(j)); |
|
1068 |
} |
|
1069 |
||
1070 |
void tst_QHeaderView::moveAndInsertSection_data() |
|
1071 |
{ |
|
1072 |
QTest::addColumn<int>("from"); |
|
1073 |
QTest::addColumn<int>("to"); |
|
1074 |
QTest::addColumn<int>("insert"); |
|
1075 |
QTest::addColumn<QList<int> >("mapping"); |
|
1076 |
||
1077 |
QTest::newRow("move from 1 to 3, insert 0") |
|
1078 |
<< 1 << 3 << 0 <<(QList<int>() << 0 << 1 << 3 << 4 << 2); |
|
1079 |
||
1080 |
} |
|
1081 |
||
1082 |
void tst_QHeaderView::moveAndInsertSection() |
|
1083 |
{ |
|
1084 |
QFETCH(int, from); |
|
1085 |
QFETCH(int, to); |
|
1086 |
QFETCH(int, insert); |
|
1087 |
QFETCH(QList<int>, mapping); |
|
1088 |
||
1089 |
view->setStretchLastSection(false); |
|
1090 |
||
1091 |
view->moveSection(from, to); |
|
1092 |
||
1093 |
model->insertRow(insert); |
|
1094 |
||
1095 |
for (int i = 0; i < mapping.count(); ++i) |
|
1096 |
QCOMPARE(view->logicalIndex(i), mapping.at(i)); |
|
1097 |
} |
|
1098 |
||
1099 |
void tst_QHeaderView::resizeMode() |
|
1100 |
{ |
|
1101 |
// Q_ASSERT's when resizeMode is called with an invalid index |
|
1102 |
int last = view->count() - 1; |
|
1103 |
view->setResizeMode(QHeaderView::Interactive); |
|
1104 |
QCOMPARE(view->resizeMode(last), QHeaderView::Interactive); |
|
1105 |
QCOMPARE(view->resizeMode(1), QHeaderView::Interactive); |
|
1106 |
view->setResizeMode(QHeaderView::Stretch); |
|
1107 |
QCOMPARE(view->resizeMode(last), QHeaderView::Stretch); |
|
1108 |
QCOMPARE(view->resizeMode(1), QHeaderView::Stretch); |
|
1109 |
view->setResizeMode(QHeaderView::Custom); |
|
1110 |
QCOMPARE(view->resizeMode(last), QHeaderView::Custom); |
|
1111 |
QCOMPARE(view->resizeMode(1), QHeaderView::Custom); |
|
1112 |
||
1113 |
// test when sections have been moved |
|
1114 |
view->setStretchLastSection(false); |
|
1115 |
for (int i=0; i < (view->count() - 1); ++i) |
|
1116 |
view->setResizeMode(i, QHeaderView::Interactive); |
|
1117 |
int logicalIndex = view->count() / 2; |
|
1118 |
view->setResizeMode(logicalIndex, QHeaderView::Stretch); |
|
1119 |
view->moveSection(view->visualIndex(logicalIndex), 0); |
|
1120 |
for (int i=0; i < (view->count() - 1); ++i) { |
|
1121 |
if (i == logicalIndex) |
|
1122 |
QCOMPARE(view->resizeMode(i), QHeaderView::Stretch); |
|
1123 |
else |
|
1124 |
QCOMPARE(view->resizeMode(i), QHeaderView::Interactive); |
|
1125 |
} |
|
1126 |
} |
|
1127 |
||
1128 |
void tst_QHeaderView::resizeSection_data() |
|
1129 |
{ |
|
1130 |
QTest::addColumn<int>("initial"); |
|
1131 |
QTest::addColumn<QList<int> >("logical"); |
|
1132 |
QTest::addColumn<QList<int> >("size"); |
|
1133 |
QTest::addColumn<QList<int> >("mode"); |
|
1134 |
QTest::addColumn<int>("resized"); |
|
1135 |
QTest::addColumn<QList<int> >("expected"); |
|
1136 |
||
1137 |
QTest::newRow("bad args") |
|
1138 |
<< 100 |
|
1139 |
<< (QList<int>() << -1 << -1 << 99999 << 99999 << 4) |
|
1140 |
<< (QList<int>() << -1 << 0 << 99999 << -1 << -1) |
|
1141 |
<< (QList<int>() |
|
1142 |
<< int(QHeaderView::Interactive) |
|
1143 |
<< int(QHeaderView::Interactive) |
|
1144 |
<< int(QHeaderView::Interactive) |
|
1145 |
<< int(QHeaderView::Interactive)) |
|
1146 |
<< 0 |
|
1147 |
<< (QList<int>() << 0 << 0 << 0 << 0 << 0); |
|
1148 |
} |
|
1149 |
||
1150 |
void tst_QHeaderView::resizeSection() |
|
1151 |
{ |
|
1152 |
||
1153 |
QFETCH(int, initial); |
|
1154 |
QFETCH(QList<int>, logical); |
|
1155 |
QFETCH(QList<int>, size); |
|
1156 |
QFETCH(QList<int>, mode); |
|
1157 |
QFETCH(int, resized); |
|
1158 |
QFETCH(QList<int>, expected); |
|
1159 |
||
1160 |
view->resize(400, 400); |
|
1161 |
||
1162 |
view->show(); |
|
1163 |
view->setMovable(true); |
|
1164 |
view->setStretchLastSection(false); |
|
1165 |
||
1166 |
for (int i = 0; i < logical.count(); ++i) |
|
1167 |
if (logical.at(i) > -1 && logical.at(i) < view->count()) // for now |
|
1168 |
view->setResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i)); |
|
1169 |
||
1170 |
for (int j = 0; j < logical.count(); ++j) |
|
1171 |
view->resizeSection(logical.at(j), initial); |
|
1172 |
||
1173 |
QSignalSpy spy(view, SIGNAL(sectionResized(int, int, int))); |
|
1174 |
||
1175 |
for (int k = 0; k < logical.count(); ++k) |
|
1176 |
view->resizeSection(logical.at(k), size.at(k)); |
|
1177 |
||
1178 |
QCOMPARE(spy.count(), resized); |
|
1179 |
||
1180 |
for (int l = 0; l < logical.count(); ++l) |
|
1181 |
QCOMPARE(view->sectionSize(logical.at(l)), expected.at(l)); |
|
1182 |
} |
|
1183 |
||
1184 |
void tst_QHeaderView::highlightSections() |
|
1185 |
{ |
|
1186 |
view->setHighlightSections(true); |
|
1187 |
QCOMPARE(view->highlightSections(), true); |
|
1188 |
view->setHighlightSections(false); |
|
1189 |
QCOMPARE(view->highlightSections(), false); |
|
1190 |
} |
|
1191 |
||
1192 |
void tst_QHeaderView::showSortIndicator() |
|
1193 |
{ |
|
1194 |
view->setSortIndicatorShown(true); |
|
1195 |
QCOMPARE(view->isSortIndicatorShown(), true); |
|
1196 |
QCOMPARE(view->sortIndicatorOrder(), Qt::DescendingOrder); |
|
1197 |
view->setSortIndicator(1, Qt::AscendingOrder); |
|
1198 |
QCOMPARE(view->sortIndicatorOrder(), Qt::AscendingOrder); |
|
1199 |
view->setSortIndicator(1, Qt::DescendingOrder); |
|
1200 |
QCOMPARE(view->sortIndicatorOrder(), Qt::DescendingOrder); |
|
1201 |
view->setSortIndicatorShown(false); |
|
1202 |
QCOMPARE(view->isSortIndicatorShown(), false); |
|
1203 |
||
1204 |
view->setSortIndicator(999999, Qt::DescendingOrder); |
|
1205 |
// Don't segfault baby :) |
|
1206 |
view->setSortIndicatorShown(true); |
|
1207 |
||
1208 |
view->setSortIndicator(0, Qt::DescendingOrder); |
|
1209 |
// Don't assert baby :) |
|
1210 |
} |
|
1211 |
||
1212 |
void tst_QHeaderView::sortIndicatorTracking() |
|
1213 |
{ |
|
1214 |
QtTestModel model; |
|
1215 |
model.rows = model.cols = 10; |
|
1216 |
||
1217 |
QHeaderView hv(Qt::Horizontal); |
|
1218 |
||
1219 |
hv.setModel(&model); |
|
1220 |
hv.show(); |
|
1221 |
hv.setSortIndicatorShown(true); |
|
1222 |
hv.setSortIndicator(1, Qt::DescendingOrder); |
|
1223 |
||
1224 |
model.removeOneColumn(8); |
|
1225 |
QCOMPARE(hv.sortIndicatorSection(), 1); |
|
1226 |
||
1227 |
model.removeOneColumn(2); |
|
1228 |
QCOMPARE(hv.sortIndicatorSection(), 1); |
|
1229 |
||
1230 |
model.insertOneColumn(2); |
|
1231 |
QCOMPARE(hv.sortIndicatorSection(), 1); |
|
1232 |
||
1233 |
model.insertOneColumn(1); |
|
1234 |
QCOMPARE(hv.sortIndicatorSection(), 2); |
|
1235 |
||
1236 |
model.removeOneColumn(0); |
|
1237 |
QCOMPARE(hv.sortIndicatorSection(), 1); |
|
1238 |
||
1239 |
model.removeOneColumn(1); |
|
1240 |
QCOMPARE(hv.sortIndicatorSection(), -1); |
|
1241 |
} |
|
1242 |
||
1243 |
void tst_QHeaderView::removeAndInsertRow() |
|
1244 |
{ |
|
1245 |
// Check if logicalIndex returns the correct value after we have removed a row |
|
1246 |
// we might as well te |
|
1247 |
for (int i = 0; i < model->rowCount(); ++i) { |
|
1248 |
QCOMPARE(i, view->logicalIndex(i)); |
|
1249 |
} |
|
1250 |
||
1251 |
while (model->removeRow(0)) { |
|
1252 |
for (int i = 0; i < model->rowCount(); ++i) { |
|
1253 |
QCOMPARE(i, view->logicalIndex(i)); |
|
1254 |
} |
|
1255 |
} |
|
1256 |
||
1257 |
int pass = 0; |
|
1258 |
for (pass = 0; pass < 5; pass++) { |
|
1259 |
for (int i = 0; i < model->rowCount(); ++i) { |
|
1260 |
QCOMPARE(i, view->logicalIndex(i)); |
|
1261 |
} |
|
1262 |
model->insertRow(0); |
|
1263 |
} |
|
1264 |
||
1265 |
while (model->removeRows(0, 2)) { |
|
1266 |
for (int i = 0; i < model->rowCount(); ++i) { |
|
1267 |
QCOMPARE(i, view->logicalIndex(i)); |
|
1268 |
} |
|
1269 |
} |
|
1270 |
||
1271 |
for (pass = 0; pass < 3; pass++) { |
|
1272 |
model->insertRows(0, 2); |
|
1273 |
for (int i = 0; i < model->rowCount(); ++i) { |
|
1274 |
QCOMPARE(i, view->logicalIndex(i)); |
|
1275 |
} |
|
1276 |
} |
|
1277 |
||
1278 |
for (pass = 0; pass < 3; pass++) { |
|
1279 |
model->insertRows(3, 2); |
|
1280 |
for (int i = 0; i < model->rowCount(); ++i) { |
|
1281 |
QCOMPARE(i, view->logicalIndex(i)); |
|
1282 |
} |
|
1283 |
} |
|
1284 |
||
1285 |
// Insert at end |
|
1286 |
for (pass = 0; pass < 3; pass++) { |
|
1287 |
int rowCount = model->rowCount(); |
|
1288 |
model->insertRows(rowCount, 1); |
|
1289 |
for (int i = 0; i < rowCount; ++i) { |
|
1290 |
QCOMPARE(i, view->logicalIndex(i)); |
|
1291 |
} |
|
1292 |
} |
|
1293 |
||
1294 |
} |
|
1295 |
void tst_QHeaderView::unhideSection() |
|
1296 |
{ |
|
1297 |
// You should not necessarily expect the same size back again, so the best test we can do is to test if it is larger than 0 after a unhide. |
|
1298 |
QCOMPARE(view->sectionsHidden(), false); |
|
1299 |
view->setSectionHidden(0, true); |
|
1300 |
QCOMPARE(view->sectionsHidden(), true); |
|
1301 |
QVERIFY(view->sectionSize(0) == 0); |
|
1302 |
view->setResizeMode(QHeaderView::Interactive); |
|
1303 |
view->setSectionHidden(0, false); |
|
1304 |
QVERIFY(view->sectionSize(0) > 0); |
|
1305 |
||
1306 |
view->setSectionHidden(0, true); |
|
1307 |
QVERIFY(view->sectionSize(0) == 0); |
|
1308 |
view->setSectionHidden(0, true); |
|
1309 |
QVERIFY(view->sectionSize(0) == 0); |
|
1310 |
view->setResizeMode(QHeaderView::Stretch); |
|
1311 |
view->setSectionHidden(0, false); |
|
1312 |
QVERIFY(view->sectionSize(0) > 0); |
|
1313 |
||
1314 |
} |
|
1315 |
||
1316 |
void tst_QHeaderView::event() |
|
1317 |
{ |
|
1318 |
protected_QHeaderView x(Qt::Vertical); |
|
1319 |
x.testEvent(); |
|
1320 |
protected_QHeaderView y(Qt::Horizontal); |
|
1321 |
y.testEvent(); |
|
1322 |
} |
|
1323 |
||
1324 |
||
1325 |
void protected_QHeaderView::testEvent() |
|
1326 |
{ |
|
1327 |
// No crashy please |
|
1328 |
QHoverEvent enterEvent(QEvent::HoverEnter, QPoint(), QPoint()); |
|
1329 |
event(&enterEvent); |
|
1330 |
QHoverEvent eventLeave(QEvent::HoverLeave, QPoint(), QPoint()); |
|
1331 |
event(&eventLeave); |
|
1332 |
QHoverEvent eventMove(QEvent::HoverMove, QPoint(), QPoint()); |
|
1333 |
event(&eventMove); |
|
1334 |
} |
|
1335 |
||
1336 |
void tst_QHeaderView::headerDataChanged() |
|
1337 |
{ |
|
1338 |
// This shouldn't asserver because view is Vertical |
|
1339 |
view->headerDataChanged(Qt::Horizontal, -1, -1); |
|
1340 |
#if 0 |
|
1341 |
// This will assert |
|
1342 |
view->headerDataChanged(Qt::Vertical, -1, -1); |
|
1343 |
#endif |
|
1344 |
||
1345 |
// No crashing please |
|
1346 |
view->headerDataChanged(Qt::Horizontal, 0, 1); |
|
1347 |
view->headerDataChanged(Qt::Vertical, 0, 1); |
|
1348 |
} |
|
1349 |
||
1350 |
void tst_QHeaderView::currentChanged() |
|
1351 |
{ |
|
1352 |
view->setCurrentIndex(QModelIndex()); |
|
1353 |
} |
|
1354 |
||
1355 |
void tst_QHeaderView::horizontalOffset() |
|
1356 |
{ |
|
1357 |
protected_QHeaderView x(Qt::Vertical); |
|
1358 |
x.testhorizontalOffset(); |
|
1359 |
protected_QHeaderView y(Qt::Horizontal); |
|
1360 |
y.testhorizontalOffset(); |
|
1361 |
} |
|
1362 |
||
1363 |
void tst_QHeaderView::verticalOffset() |
|
1364 |
{ |
|
1365 |
protected_QHeaderView x(Qt::Vertical); |
|
1366 |
x.testverticalOffset(); |
|
1367 |
protected_QHeaderView y(Qt::Horizontal); |
|
1368 |
y.testverticalOffset(); |
|
1369 |
} |
|
1370 |
||
1371 |
void protected_QHeaderView::testhorizontalOffset() |
|
1372 |
{ |
|
1373 |
if(orientation() == Qt::Horizontal){ |
|
1374 |
QCOMPARE(horizontalOffset(), 0); |
|
1375 |
setOffset(10); |
|
1376 |
QCOMPARE(horizontalOffset(), 10); |
|
1377 |
} |
|
1378 |
else |
|
1379 |
QCOMPARE(horizontalOffset(), 0); |
|
1380 |
||
1381 |
} |
|
1382 |
||
1383 |
void protected_QHeaderView::testverticalOffset() |
|
1384 |
{ |
|
1385 |
if(orientation() == Qt::Vertical){ |
|
1386 |
QCOMPARE(verticalOffset(), 0); |
|
1387 |
setOffset(10); |
|
1388 |
QCOMPARE(verticalOffset(), 10); |
|
1389 |
} |
|
1390 |
else |
|
1391 |
QCOMPARE(verticalOffset(), 0); |
|
1392 |
} |
|
1393 |
||
1394 |
void tst_QHeaderView::stretchSectionCount() |
|
1395 |
{ |
|
1396 |
view->setStretchLastSection(false); |
|
1397 |
QCOMPARE(view->stretchSectionCount(), 0); |
|
1398 |
view->setStretchLastSection(true); |
|
1399 |
QCOMPARE(view->stretchSectionCount(), 0); |
|
1400 |
||
1401 |
view->setResizeMode(0, QHeaderView::Stretch); |
|
1402 |
QCOMPARE(view->stretchSectionCount(), 1); |
|
1403 |
} |
|
1404 |
||
1405 |
void tst_QHeaderView::hiddenSectionCount() |
|
1406 |
{ |
|
1407 |
model->clear(); |
|
1408 |
model->insertRows(0, 10); |
|
1409 |
// Hide every other one |
|
1410 |
for (int i=0; i<10; i++) |
|
1411 |
view->setSectionHidden(i, (i & 1) == 0); |
|
1412 |
||
1413 |
QCOMPARE(view->hiddenSectionCount(), 5); |
|
1414 |
||
1415 |
view->setResizeMode(QHeaderView::Stretch); |
|
1416 |
QCOMPARE(view->hiddenSectionCount(), 5); |
|
1417 |
||
1418 |
// Remove some rows and make sure they are now still counted |
|
1419 |
model->removeRow(9); |
|
1420 |
model->removeRow(8); |
|
1421 |
model->removeRow(7); |
|
1422 |
model->removeRow(6); |
|
1423 |
QCOMPARE(view->count(), 6); |
|
1424 |
QCOMPARE(view->hiddenSectionCount(), 3); |
|
1425 |
model->removeRows(0,5); |
|
1426 |
QCOMPARE(view->count(), 1); |
|
1427 |
QCOMPARE(view->hiddenSectionCount(), 0); |
|
1428 |
QVERIFY(view->count() >= view->hiddenSectionCount()); |
|
1429 |
} |
|
1430 |
||
1431 |
void tst_QHeaderView::focusPolicy() |
|
1432 |
{ |
|
1433 |
QHeaderView view(Qt::Horizontal); |
|
1434 |
QCOMPARE(view.focusPolicy(), Qt::NoFocus); |
|
1435 |
||
1436 |
QTreeWidget widget; |
|
1437 |
QCOMPARE(widget.header()->focusPolicy(), Qt::NoFocus); |
|
1438 |
QVERIFY(!widget.focusProxy()); |
|
1439 |
QVERIFY(!widget.hasFocus()); |
|
1440 |
QVERIFY(!widget.header()->focusProxy()); |
|
1441 |
QVERIFY(!widget.header()->hasFocus()); |
|
1442 |
||
1443 |
widget.show(); |
|
1444 |
widget.setFocus(Qt::OtherFocusReason); |
|
1445 |
QApplication::setActiveWindow(&widget); |
|
1446 |
QTest::qWaitForWindowShown(&widget); |
|
1447 |
widget.activateWindow(); |
|
1448 |
QTest::qWait(100); |
|
1449 |
||
1450 |
qApp->processEvents(); |
|
1451 |
||
1452 |
WAIT_FOR_CONDITION(widget.hasFocus(), true); |
|
1453 |
||
1454 |
QVERIFY(widget.hasFocus()); |
|
1455 |
QVERIFY(!widget.header()->hasFocus()); |
|
1456 |
||
1457 |
widget.setFocusPolicy(Qt::NoFocus); |
|
1458 |
widget.clearFocus(); |
|
1459 |
||
1460 |
qApp->processEvents(); |
|
1461 |
qApp->processEvents(); |
|
1462 |
||
1463 |
WAIT_FOR_CONDITION(widget.hasFocus(), false); |
|
1464 |
QVERIFY(!widget.hasFocus()); |
|
1465 |
QVERIFY(!widget.header()->hasFocus()); |
|
1466 |
||
1467 |
QTest::keyPress(&widget, Qt::Key_Tab); |
|
1468 |
||
1469 |
qApp->processEvents(); |
|
1470 |
qApp->processEvents(); |
|
1471 |
||
1472 |
QVERIFY(!widget.hasFocus()); |
|
1473 |
QVERIFY(!widget.header()->hasFocus()); |
|
1474 |
} |
|
1475 |
||
1476 |
class SimpleModel : public QAbstractItemModel |
|
1477 |
{ |
|
1478 |
Q_OBJECT |
|
1479 |
public: |
|
1480 |
||
1481 |
SimpleModel( QObject* parent=0) |
|
1482 |
: QAbstractItemModel(parent), |
|
1483 |
m_col_count(3) {} |
|
1484 |
||
1485 |
QModelIndex parent(const QModelIndex &/*child*/) const |
|
1486 |
{ |
|
1487 |
return QModelIndex(); |
|
1488 |
} |
|
1489 |
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const |
|
1490 |
{ |
|
1491 |
return hasIndex(row, column, parent) ? createIndex(row, column, 0) : QModelIndex(); |
|
1492 |
} |
|
1493 |
int rowCount(const QModelIndex & /* parent */) const |
|
1494 |
{ |
|
1495 |
return 8; |
|
1496 |
} |
|
1497 |
int columnCount(const QModelIndex &/*parent= QModelIndex()*/) const |
|
1498 |
{ |
|
1499 |
return m_col_count; |
|
1500 |
} |
|
1501 |
||
1502 |
QVariant data(const QModelIndex &index, int role) const |
|
1503 |
{ |
|
1504 |
if (!index.isValid()) |
|
1505 |
{ |
|
1506 |
return QVariant(); |
|
1507 |
} |
|
1508 |
if (role == Qt::DisplayRole) { |
|
1509 |
return QString::fromAscii("%1,%2").arg(index.row()).arg(index.column()); |
|
1510 |
} |
|
1511 |
return QVariant(); |
|
1512 |
} |
|
1513 |
||
1514 |
void setColumnCount( int c ) |
|
1515 |
{ |
|
1516 |
m_col_count = c; |
|
1517 |
} |
|
1518 |
||
1519 |
private: |
|
1520 |
int m_col_count; |
|
1521 |
}; |
|
1522 |
||
1523 |
void tst_QHeaderView::moveSectionAndReset() |
|
1524 |
{ |
|
1525 |
SimpleModel m; |
|
1526 |
QHeaderView v(Qt::Horizontal); |
|
1527 |
v.setModel(&m); |
|
1528 |
int cc = 2; |
|
1529 |
for (cc = 2; cc < 4; ++cc) { |
|
1530 |
m.setColumnCount(cc); |
|
1531 |
int movefrom = 0; |
|
1532 |
int moveto; |
|
1533 |
for (moveto = 1; moveto < cc; ++moveto) { |
|
1534 |
v.moveSection(movefrom, moveto); |
|
1535 |
m.setColumnCount(cc - 1); |
|
1536 |
v.reset(); |
|
1537 |
for (int i = 0; i < cc - 1; ++i) { |
|
1538 |
QCOMPARE(v.logicalIndex(v.visualIndex(i)), i); |
|
1539 |
} |
|
1540 |
} |
|
1541 |
} |
|
1542 |
} |
|
1543 |
||
1544 |
void tst_QHeaderView::moveSectionAndRemove() |
|
1545 |
{ |
|
1546 |
QStandardItemModel m; |
|
1547 |
QHeaderView v(Qt::Horizontal); |
|
1548 |
||
1549 |
v.setModel(&m); |
|
1550 |
v.model()->insertColumns(0, 3); |
|
1551 |
v.moveSection(0, 1); |
|
1552 |
||
1553 |
QCOMPARE(v.count(), 3); |
|
1554 |
v.model()->removeColumns(0, v.model()->columnCount()); |
|
1555 |
QCOMPARE(v.count(), 0); |
|
1556 |
} |
|
1557 |
||
1558 |
void tst_QHeaderView::saveRestore() |
|
1559 |
{ |
|
1560 |
SimpleModel m; |
|
1561 |
QHeaderView h1(Qt::Horizontal); |
|
1562 |
h1.setModel(&m); |
|
1563 |
h1.swapSections(0, 2); |
|
1564 |
h1.resizeSection(1, 10); |
|
1565 |
h1.setSortIndicatorShown(true); |
|
1566 |
h1.setSortIndicator(1,Qt::DescendingOrder); |
|
1567 |
QByteArray s1 = h1.saveState(); |
|
1568 |
||
1569 |
QHeaderView h2(Qt::Vertical); |
|
1570 |
QSignalSpy spy(&h2, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder))); |
|
1571 |
||
1572 |
h2.setModel(&m); |
|
1573 |
h2.restoreState(s1); |
|
1574 |
||
1575 |
QCOMPARE(spy.count(), 1); |
|
1576 |
QCOMPARE(spy.at(0).at(0).toInt(), 1); |
|
1577 |
||
1578 |
QCOMPARE(h2.logicalIndex(0), 2); |
|
1579 |
QCOMPARE(h2.logicalIndex(2), 0); |
|
1580 |
QCOMPARE(h2.sectionSize(1), 10); |
|
1581 |
QCOMPARE(h2.sortIndicatorSection(), 1); |
|
1582 |
QCOMPARE(h2.sortIndicatorOrder(), Qt::DescendingOrder); |
|
1583 |
QCOMPARE(h2.isSortIndicatorShown(), true); |
|
1584 |
||
1585 |
QByteArray s2 = h2.saveState(); |
|
1586 |
||
1587 |
QVERIFY(s1 == s2); |
|
1588 |
} |
|
1589 |
||
1590 |
void tst_QHeaderView::defaultAlignment_data() |
|
1591 |
{ |
|
1592 |
QTest::addColumn<int>("direction"); |
|
1593 |
QTest::addColumn<int>("initial"); |
|
1594 |
QTest::addColumn<int>("alignment"); |
|
1595 |
||
1596 |
QTest::newRow("horizontal right aligned") |
|
1597 |
<< int(Qt::Horizontal) |
|
1598 |
<< int(Qt::AlignCenter) |
|
1599 |
<< int(Qt::AlignRight); |
|
1600 |
||
1601 |
QTest::newRow("horizontal left aligned") |
|
1602 |
<< int(Qt::Horizontal) |
|
1603 |
<< int(Qt::AlignCenter) |
|
1604 |
<< int(Qt::AlignLeft); |
|
1605 |
||
1606 |
QTest::newRow("vertical right aligned") |
|
1607 |
<< int(Qt::Vertical) |
|
1608 |
<< int(Qt::AlignLeft|Qt::AlignVCenter) |
|
1609 |
<< int(Qt::AlignRight); |
|
1610 |
||
1611 |
QTest::newRow("vertical left aligned") |
|
1612 |
<< int(Qt::Vertical) |
|
1613 |
<< int(Qt::AlignLeft|Qt::AlignVCenter) |
|
1614 |
<< int(Qt::AlignLeft); |
|
1615 |
} |
|
1616 |
||
1617 |
void tst_QHeaderView::defaultAlignment() |
|
1618 |
{ |
|
1619 |
QFETCH(int, direction); |
|
1620 |
QFETCH(int, initial); |
|
1621 |
QFETCH(int, alignment); |
|
1622 |
||
1623 |
SimpleModel m; |
|
1624 |
||
1625 |
QHeaderView header((Qt::Orientation)direction); |
|
1626 |
header.setModel(&m); |
|
1627 |
||
1628 |
QCOMPARE(header.defaultAlignment(), (Qt::Alignment)initial); |
|
1629 |
header.setDefaultAlignment((Qt::Alignment)alignment); |
|
1630 |
QCOMPARE(header.defaultAlignment(), (Qt::Alignment)alignment); |
|
1631 |
} |
|
1632 |
||
1633 |
void tst_QHeaderView::globalResizeMode_data() |
|
1634 |
{ |
|
1635 |
QTest::addColumn<int>("direction"); |
|
1636 |
QTest::addColumn<int>("mode"); |
|
1637 |
QTest::addColumn<int>("insert"); |
|
1638 |
||
1639 |
QTest::newRow("horizontal ResizeToContents 0") |
|
1640 |
<< int(Qt::Horizontal) |
|
1641 |
<< int(QHeaderView::ResizeToContents) |
|
1642 |
<< 0; |
|
1643 |
} |
|
1644 |
||
1645 |
void tst_QHeaderView::globalResizeMode() |
|
1646 |
{ |
|
1647 |
QFETCH(int, direction); |
|
1648 |
QFETCH(int, mode); |
|
1649 |
QFETCH(int, insert); |
|
1650 |
||
1651 |
QStandardItemModel m(4, 4); |
|
1652 |
QHeaderView h((Qt::Orientation)direction); |
|
1653 |
h.setModel(&m); |
|
1654 |
||
1655 |
h.setResizeMode((QHeaderView::ResizeMode)mode); |
|
1656 |
m.insertRow(insert); |
|
1657 |
for (int i = 0; i < h.count(); ++i) |
|
1658 |
QCOMPARE(h.resizeMode(i), (QHeaderView::ResizeMode)mode); |
|
1659 |
} |
|
1660 |
||
1661 |
||
1662 |
void tst_QHeaderView::sectionPressedSignal_data() |
|
1663 |
{ |
|
1664 |
QTest::addColumn<int>("direction"); |
|
1665 |
QTest::addColumn<bool>("clickable"); |
|
1666 |
QTest::addColumn<int>("count"); |
|
1667 |
||
1668 |
QTest::newRow("horizontal unclickable 0") |
|
1669 |
<< int(Qt::Horizontal) |
|
1670 |
<< false |
|
1671 |
<< 0; |
|
1672 |
||
1673 |
QTest::newRow("horizontal clickable 1") |
|
1674 |
<< int(Qt::Horizontal) |
|
1675 |
<< true |
|
1676 |
<< 1; |
|
1677 |
} |
|
1678 |
||
1679 |
void tst_QHeaderView::sectionPressedSignal() |
|
1680 |
{ |
|
1681 |
QFETCH(int, direction); |
|
1682 |
QFETCH(bool, clickable); |
|
1683 |
QFETCH(int, count); |
|
1684 |
||
1685 |
QStandardItemModel m(4, 4); |
|
1686 |
QHeaderView h((Qt::Orientation)direction); |
|
1687 |
||
1688 |
h.setModel(&m); |
|
1689 |
h.show(); |
|
1690 |
h.setClickable(clickable); |
|
1691 |
||
1692 |
QSignalSpy spy(&h, SIGNAL(sectionPressed(int))); |
|
1693 |
||
1694 |
QCOMPARE(spy.count(), 0); |
|
1695 |
QTest::mousePress(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
1696 |
QCOMPARE(spy.count(), count); |
|
1697 |
} |
|
1698 |
||
1699 |
void tst_QHeaderView::sectionClickedSignal() |
|
1700 |
{ |
|
1701 |
QFETCH(int, direction); |
|
1702 |
QFETCH(bool, clickable); |
|
1703 |
QFETCH(int, count); |
|
1704 |
||
1705 |
QStandardItemModel m(4, 4); |
|
1706 |
QHeaderView h((Qt::Orientation)direction); |
|
1707 |
||
1708 |
h.setModel(&m); |
|
1709 |
h.show(); |
|
1710 |
h.setClickable(clickable); |
|
1711 |
h.setSortIndicatorShown(true); |
|
1712 |
||
1713 |
QSignalSpy spy(&h, SIGNAL(sectionClicked(int))); |
|
1714 |
QSignalSpy spy2(&h, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder))); |
|
1715 |
||
1716 |
QCOMPARE(spy.count(), 0); |
|
1717 |
QCOMPARE(spy2.count(), 0); |
|
1718 |
QTest::mouseClick(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
1719 |
QCOMPARE(spy.count(), count); |
|
1720 |
QCOMPARE(spy2.count(), count); |
|
1721 |
||
1722 |
//now let's try with the sort indicator hidden (the result should be the same |
|
1723 |
spy.clear(); |
|
1724 |
spy2.clear(); |
|
1725 |
h.setSortIndicatorShown(false); |
|
1726 |
QTest::mouseClick(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); |
|
1727 |
QCOMPARE(spy.count(), count); |
|
1728 |
QCOMPARE(spy2.count(), count); |
|
1729 |
} |
|
1730 |
||
1731 |
void tst_QHeaderView::defaultSectionSize_data() |
|
1732 |
{ |
|
1733 |
QTest::addColumn<int>("direction"); |
|
1734 |
QTest::addColumn<int>("oldDefaultSize"); |
|
1735 |
QTest::addColumn<int>("newDefaultSize"); |
|
1736 |
||
1737 |
//QTest::newRow("horizontal,-5") << int(Qt::Horizontal) << 100 << -5; |
|
1738 |
QTest::newRow("horizontal, 0") << int(Qt::Horizontal) << 100 << 0; |
|
1739 |
QTest::newRow("horizontal, 5") << int(Qt::Horizontal) << 100 << 5; |
|
1740 |
QTest::newRow("horizontal,25") << int(Qt::Horizontal) << 100 << 5; |
|
1741 |
} |
|
1742 |
||
1743 |
void tst_QHeaderView::defaultSectionSize() |
|
1744 |
{ |
|
1745 |
QFETCH(int, direction); |
|
1746 |
QFETCH(int, oldDefaultSize); |
|
1747 |
QFETCH(int, newDefaultSize); |
|
1748 |
||
1749 |
QStandardItemModel m(4, 4); |
|
1750 |
QHeaderView h((Qt::Orientation)direction); |
|
1751 |
||
1752 |
h.setModel(&m); |
|
1753 |
||
1754 |
QCOMPARE(h.defaultSectionSize(), oldDefaultSize); |
|
1755 |
h.setDefaultSectionSize(newDefaultSize); |
|
1756 |
QCOMPARE(h.defaultSectionSize(), newDefaultSize); |
|
1757 |
h.reset(); |
|
1758 |
for (int i = 0; i < h.count(); ++i) |
|
1759 |
QCOMPARE(h.sectionSize(i), newDefaultSize); |
|
1760 |
} |
|
1761 |
||
1762 |
void tst_QHeaderView::hideAndInsert_data() |
|
1763 |
{ |
|
1764 |
QTest::addColumn<int>("direction"); |
|
1765 |
QTest::addColumn<int>("hide"); |
|
1766 |
QTest::addColumn<int>("insert"); |
|
1767 |
QTest::addColumn<int>("hidden"); |
|
1768 |
||
1769 |
QTest::newRow("horizontal, 0, 0") << int(Qt::Horizontal) << 0 << 0 << 1; |
|
1770 |
} |
|
1771 |
||
1772 |
void tst_QHeaderView::hideAndInsert() |
|
1773 |
{ |
|
1774 |
QFETCH(int, direction); |
|
1775 |
QFETCH(int, hide); |
|
1776 |
QFETCH(int, insert); |
|
1777 |
QFETCH(int, hidden); |
|
1778 |
||
1779 |
QStandardItemModel m(4, 4); |
|
1780 |
QHeaderView h((Qt::Orientation)direction); |
|
1781 |
||
1782 |
h.setModel(&m); |
|
1783 |
||
1784 |
h.setSectionHidden(hide, true); |
|
1785 |
||
1786 |
if (direction == Qt::Vertical) |
|
1787 |
m.insertRow(insert); |
|
1788 |
else |
|
1789 |
m.insertColumn(insert); |
|
1790 |
||
1791 |
for (int i = 0; i < h.count(); ++i) |
|
1792 |
if (i != hidden) |
|
1793 |
QCOMPARE(h.isSectionHidden(i), false); |
|
1794 |
else |
|
1795 |
QCOMPARE(h.isSectionHidden(i), true); |
|
1796 |
} |
|
1797 |
||
1798 |
void tst_QHeaderView::removeSection() |
|
1799 |
{ |
|
1800 |
//test that removing a hidden section gives the expected result: the next row should be hidden |
|
1801 |
//(see task |
|
1802 |
const int hidden = 3; //section that will be hidden |
|
1803 |
const QStringList list = QStringList() << "0" << "1" << "2" << "3" << "4" << "5" << "6"; |
|
1804 |
||
1805 |
QStringListModel model( list ); |
|
1806 |
QHeaderView view(Qt::Vertical); |
|
1807 |
view.setModel(&model); |
|
1808 |
view.hideSection(hidden); |
|
1809 |
view.hideSection(1); |
|
1810 |
model.removeRow(1); |
|
1811 |
view.show(); |
|
1812 |
||
1813 |
for(int i = 0; i < view.count(); i++) { |
|
1814 |
if (i == (hidden-1)) { //-1 because we removed a row in the meantime |
|
1815 |
QCOMPARE(view.sectionSize(i), 0); |
|
1816 |
QVERIFY(view.isSectionHidden(i)); |
|
1817 |
} else { |
|
1818 |
QCOMPARE(view.sectionSize(i), view.defaultSectionSize() ); |
|
1819 |
QVERIFY(!view.isSectionHidden(i)); |
|
1820 |
} |
|
1821 |
} |
|
1822 |
} |
|
1823 |
||
1824 |
void tst_QHeaderView::preserveHiddenSectionWidth() |
|
1825 |
{ |
|
1826 |
const QStringList list = QStringList() << "0" << "1" << "2" << "3"; |
|
1827 |
||
1828 |
QStringListModel model( list ); |
|
1829 |
QHeaderView view(Qt::Vertical); |
|
1830 |
view.setModel(&model); |
|
1831 |
view.resizeSection(0, 100); |
|
1832 |
view.resizeSection(1, 10); |
|
1833 |
view.resizeSection(2, 50); |
|
1834 |
view.setResizeMode(3, QHeaderView::Stretch); |
|
1835 |
view.show(); |
|
1836 |
||
1837 |
view.hideSection(2); |
|
1838 |
model.removeRow(1); |
|
1839 |
view.showSection(1); |
|
1840 |
QCOMPARE(view.sectionSize(0), 100); |
|
1841 |
QCOMPARE(view.sectionSize(1), 50); |
|
1842 |
||
1843 |
view.hideSection(1); |
|
1844 |
model.insertRow(1); |
|
1845 |
view.showSection(2); |
|
1846 |
QCOMPARE(view.sectionSize(0), 100); |
|
1847 |
QCOMPARE(view.sectionSize(1), view.defaultSectionSize()); |
|
1848 |
QCOMPARE(view.sectionSize(2), 50); |
|
1849 |
} |
|
1850 |
||
1851 |
void tst_QHeaderView::invisibleStretchLastSection() |
|
1852 |
{ |
|
1853 |
int count = 6; |
|
1854 |
QStandardItemModel model(1, count); |
|
1855 |
QHeaderView view(Qt::Horizontal); |
|
1856 |
view.setModel(&model); |
|
1857 |
int height = view.height(); |
|
1858 |
||
1859 |
view.resize(view.defaultSectionSize() * (count / 2), height); // don't show all sections |
|
1860 |
view.show(); |
|
1861 |
view.setStretchLastSection(true); |
|
1862 |
// stretch section is not visible; it should not be stretched |
|
1863 |
for (int i = 0; i < count; ++i) |
|
1864 |
QCOMPARE(view.sectionSize(i), view.defaultSectionSize()); |
|
1865 |
||
1866 |
view.resize(view.defaultSectionSize() * (count + 1), height); // give room to stretch |
|
1867 |
||
1868 |
// stretch section is visible; it should be stretched |
|
1869 |
for (int i = 0; i < count - 1; ++i) |
|
1870 |
QCOMPARE(view.sectionSize(i), view.defaultSectionSize()); |
|
1871 |
QCOMPARE(view.sectionSize(count - 1), view.defaultSectionSize() * 2); |
|
1872 |
} |
|
1873 |
||
1874 |
void tst_QHeaderView::emptySectionSpan() |
|
1875 |
{ |
|
1876 |
QHeaderViewPrivate::SectionSpan span; |
|
1877 |
QCOMPARE(span.sectionSize(), 0); |
|
1878 |
} |
|
1879 |
||
1880 |
void tst_QHeaderView::task236450_hidden_data() |
|
1881 |
{ |
|
1882 |
QTest::addColumn<QList<int> >("hide1"); |
|
1883 |
QTest::addColumn<QList<int> >("hide2"); |
|
1884 |
||
1885 |
QTest::newRow("set 1") << (QList<int>() << 1 << 3) |
|
1886 |
<< (QList<int>() << 1 << 5); |
|
1887 |
||
1888 |
QTest::newRow("set 2") << (QList<int>() << 2 << 3) |
|
1889 |
<< (QList<int>() << 1 << 5); |
|
1890 |
||
1891 |
QTest::newRow("set 3") << (QList<int>() << 0 << 2 << 4) |
|
1892 |
<< (QList<int>() << 2 << 3 << 5); |
|
1893 |
||
1894 |
} |
|
1895 |
||
1896 |
void tst_QHeaderView::task236450_hidden() |
|
1897 |
{ |
|
1898 |
QFETCH(QList<int>, hide1); |
|
1899 |
QFETCH(QList<int>, hide2); |
|
1900 |
const QStringList list = QStringList() << "0" << "1" << "2" << "3" << "4" << "5"; |
|
1901 |
||
1902 |
QStringListModel model( list ); |
|
1903 |
protected_QHeaderView view(Qt::Vertical); |
|
1904 |
view.setModel(&model); |
|
1905 |
view.show(); |
|
1906 |
||
1907 |
foreach (int i, hide1) |
|
1908 |
view.hideSection(i); |
|
1909 |
||
1910 |
QCOMPARE(view.hiddenSectionCount(), hide1.count()); |
|
1911 |
for (int i = 0; i < 6; i++) { |
|
1912 |
QCOMPARE(!view.isSectionHidden(i), !hide1.contains(i)); |
|
1913 |
} |
|
1914 |
||
1915 |
view.setDefaultSectionSize(2); |
|
1916 |
view.scheduleDelayedItemsLayout(); |
|
1917 |
view.executeDelayedItemsLayout(); //force to do a relayout |
|
1918 |
||
1919 |
QCOMPARE(view.hiddenSectionCount(), hide1.count()); |
|
1920 |
for (int i = 0; i < 6; i++) { |
|
1921 |
QCOMPARE(!view.isSectionHidden(i), !hide1.contains(i)); |
|
1922 |
view.setSectionHidden(i, hide2.contains(i)); |
|
1923 |
} |
|
1924 |
||
1925 |
QCOMPARE(view.hiddenSectionCount(), hide2.count()); |
|
1926 |
for (int i = 0; i < 6; i++) { |
|
1927 |
QCOMPARE(!view.isSectionHidden(i), !hide2.contains(i)); |
|
1928 |
} |
|
1929 |
||
1930 |
} |
|
1931 |
||
1932 |
void tst_QHeaderView::task248050_hideRow() |
|
1933 |
{ |
|
1934 |
//this is the sequence of events that make the task fail |
|
1935 |
protected_QHeaderView header(Qt::Vertical); |
|
1936 |
QStandardItemModel model(0, 1); |
|
1937 |
header.setStretchLastSection(false); |
|
1938 |
header.setDefaultSectionSize(17); |
|
1939 |
header.setModel(&model); |
|
1940 |
header.doItemsLayout(); |
|
1941 |
||
1942 |
model.setRowCount(3); |
|
1943 |
||
1944 |
QCOMPARE(header.sectionPosition(2), 17*2); |
|
1945 |
||
1946 |
header.hideSection(1); |
|
1947 |
QCOMPARE(header.sectionPosition(2), 17); |
|
1948 |
||
1949 |
QTest::qWait(100); |
|
1950 |
//the size of the section shouldn't have changed |
|
1951 |
QCOMPARE(header.sectionPosition(2), 17); |
|
1952 |
} |
|
1953 |
||
1954 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1955 |
//returns 0 if everything is fine. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1956 |
static int checkHeaderViewOrder(QHeaderView *view, const QVector<int> &expected) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1957 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1958 |
if (view->count() != expected.count()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1959 |
return 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1960 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1961 |
for (int i = 0; i < expected.count(); i++) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1962 |
if (view->logicalIndex(i) != expected.at(i)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1963 |
return i + 10; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1964 |
if (view->visualIndex(expected.at(i)) != i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1965 |
return i + 100; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1966 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1967 |
return 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1968 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1969 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1970 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1971 |
void tst_QHeaderView::QTBUG6058_reset() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1972 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1973 |
QStringListModel model1( QStringList() << "0" << "1" << "2" << "3" << "4" << "5" ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1974 |
QStringListModel model2( QStringList() << "a" << "b" << "c" ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1975 |
QSortFilterProxyModel proxy; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1976 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1977 |
QHeaderView view(Qt::Vertical); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1978 |
view.setModel(&proxy); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1979 |
view.show(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1980 |
QTest::qWait(20); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1981 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1982 |
proxy.setSourceModel(&model1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1983 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1984 |
view.swapSections(0,2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1985 |
view.swapSections(1,4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1986 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1987 |
QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 4 << 0 << 3 << 1 << 5) , 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1988 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1989 |
proxy.setSourceModel(&model2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1990 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1991 |
QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 ) , 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1992 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1993 |
proxy.setSourceModel(&model1); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1994 |
QApplication::processEvents(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1995 |
QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 << 3 << 4 << 5 ) , 0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1996 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1997 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1998 |
void tst_QHeaderView::QTBUG7833_sectionClicked() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1999 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2000 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2001 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2002 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2003 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2004 |
QTableView tv; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2005 |
QStandardItemModel *sim = new QStandardItemModel(&tv); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2006 |
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(&tv); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2007 |
proxyModel->setSourceModel(sim); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2008 |
proxyModel->setDynamicSortFilter(true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2009 |
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2010 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2011 |
QList<QStandardItem *> row; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2012 |
for (int i = 0; i < 12; i++) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2013 |
row.append(new QStandardItem(QString(QLatin1Char('A' + i)))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2014 |
sim->appendRow(row); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2015 |
row.clear(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2016 |
for (int i = 12; i > 0; i--) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2017 |
row.append(new QStandardItem(QString(QLatin1Char('A' + i)))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2018 |
sim->appendRow(row); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2019 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2020 |
tv.setSortingEnabled(true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2021 |
tv.horizontalHeader()->setSortIndicatorShown(true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2022 |
tv.horizontalHeader()->setClickable(true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2023 |
tv.horizontalHeader()->setStretchLastSection(true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2024 |
tv.horizontalHeader()->setResizeMode(QHeaderView::Interactive); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2025 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2026 |
tv.setModel(proxyModel); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2027 |
tv.setColumnHidden(5, true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2028 |
tv.setColumnHidden(6, true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2029 |
tv.horizontalHeader()->swapSections(8, 10); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2030 |
tv.sortByColumn(1, Qt::AscendingOrder); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2031 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2032 |
QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2033 |
QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int))); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2034 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2035 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2036 |
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2037 |
QPoint(tv.horizontalHeader()->sectionViewportPosition(11) + 5, 5)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2038 |
QCOMPARE(clickedSpy.count(), 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2039 |
QCOMPARE(pressedSpy.count(), 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2040 |
QCOMPARE(clickedSpy.at(0).at(0).toInt(), 11); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2041 |
QCOMPARE(pressedSpy.at(0).at(0).toInt(), 11); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2042 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2043 |
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2044 |
QPoint(tv.horizontalHeader()->sectionViewportPosition(8) + 5, 5)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2045 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2046 |
QCOMPARE(clickedSpy.count(), 2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2047 |
QCOMPARE(pressedSpy.count(), 2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2048 |
QCOMPARE(clickedSpy.at(1).at(0).toInt(), 8); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2049 |
QCOMPARE(pressedSpy.at(1).at(0).toInt(), 8); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2050 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2051 |
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2052 |
QPoint(tv.horizontalHeader()->sectionViewportPosition(0) + 5, 5)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2053 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2054 |
QCOMPARE(clickedSpy.count(), 3); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2055 |
QCOMPARE(pressedSpy.count(), 3); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2056 |
QCOMPARE(clickedSpy.at(2).at(0).toInt(), 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2057 |
QCOMPARE(pressedSpy.at(2).at(0).toInt(), 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2058 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2059 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2060 |
void tst_QHeaderView::QTBUG8650_crashOnInsertSections() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2061 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2062 |
QStringList headerLabels; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2063 |
QHeaderView view(Qt::Horizontal); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2064 |
QStandardItemModel model(2,2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2065 |
view.setModel(&model); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2066 |
view.moveSection(1, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2067 |
view.hideSection(0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2068 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2069 |
QList<QStandardItem *> items; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2070 |
items << new QStandardItem("c"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2071 |
model.insertColumn(0, items); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2072 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2073 |
|
0 | 2074 |
QTEST_MAIN(tst_QHeaderView) |
2075 |
#include "tst_qheaderview.moc" |