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