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