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