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 <qeventloop.h>
|
|
45 |
#include <qlist.h>
|
|
46 |
#include <qpair.h>
|
|
47 |
#include <qheaderview.h>
|
|
48 |
|
|
49 |
#include <qtablewidget.h>
|
|
50 |
|
|
51 |
//TESTED_CLASS=
|
|
52 |
//TESTED_FILES=
|
|
53 |
|
|
54 |
class QObjectTableItem : public QObject, public QTableWidgetItem
|
|
55 |
{
|
|
56 |
Q_OBJECT
|
|
57 |
};
|
|
58 |
|
|
59 |
class tst_QTableWidget : public QObject
|
|
60 |
{
|
|
61 |
Q_OBJECT
|
|
62 |
|
|
63 |
public:
|
|
64 |
tst_QTableWidget();
|
|
65 |
~tst_QTableWidget();
|
|
66 |
|
|
67 |
public slots:
|
|
68 |
void initTestCase();
|
|
69 |
void cleanupTestCase();
|
|
70 |
void init();
|
|
71 |
void cleanup();
|
|
72 |
private slots:
|
|
73 |
void getSetCheck();
|
|
74 |
void clear();
|
|
75 |
void clearContents();
|
|
76 |
void rowCount();
|
|
77 |
void columnCount();
|
|
78 |
void itemAssignment();
|
|
79 |
void item_data();
|
|
80 |
void item();
|
|
81 |
void takeItem_data();
|
|
82 |
void takeItem();
|
|
83 |
void selectedItems_data();
|
|
84 |
void selectedItems();
|
|
85 |
void removeRow_data();
|
|
86 |
void removeRow();
|
|
87 |
void removeColumn_data();
|
|
88 |
void removeColumn();
|
|
89 |
void insertRow_data();
|
|
90 |
void insertRow();
|
|
91 |
void insertColumn_data();
|
|
92 |
void insertColumn();
|
|
93 |
void itemStreaming_data();
|
|
94 |
void itemStreaming();
|
|
95 |
void itemOwnership();
|
|
96 |
void sortItems_data();
|
|
97 |
void sortItems();
|
|
98 |
void setItemWithSorting_data();
|
|
99 |
void setItemWithSorting();
|
|
100 |
void itemData();
|
|
101 |
void setItemData();
|
|
102 |
void cellWidget();
|
|
103 |
void task231094();
|
|
104 |
void task219380_removeLastRow();
|
|
105 |
void task262056_sortDuplicate();
|
|
106 |
|
|
107 |
private:
|
|
108 |
QTableWidget *testWidget;
|
|
109 |
};
|
|
110 |
|
|
111 |
typedef QPair<int, int> IntPair;
|
|
112 |
typedef QList<int> IntList;
|
|
113 |
typedef QList<IntPair> IntIntList;
|
|
114 |
|
|
115 |
Q_DECLARE_METATYPE(IntList)
|
|
116 |
Q_DECLARE_METATYPE(IntIntList)
|
|
117 |
Q_DECLARE_METATYPE(QTableWidgetSelectionRange)
|
|
118 |
Q_DECLARE_METATYPE(QModelIndex)
|
|
119 |
|
|
120 |
|
|
121 |
// Testing get/set functions
|
|
122 |
void tst_QTableWidget::getSetCheck()
|
|
123 |
{
|
|
124 |
QTableWidget obj1;
|
|
125 |
// int QTableWidget::rowCount()
|
|
126 |
// void QTableWidget::setRowCount(int)
|
|
127 |
obj1.setRowCount(0);
|
|
128 |
QCOMPARE(0, obj1.rowCount());
|
|
129 |
obj1.setRowCount(INT_MIN);
|
|
130 |
QCOMPARE(0, obj1.rowCount()); // Row count can never be negative
|
|
131 |
// obj1.setRowCount(INT_MAX);
|
|
132 |
// QCOMPARE(INT_MAX, obj1.rowCount());
|
|
133 |
obj1.setRowCount(100);
|
|
134 |
QCOMPARE(100, obj1.rowCount());
|
|
135 |
|
|
136 |
|
|
137 |
// int QTableWidget::columnCount()
|
|
138 |
// void QTableWidget::setColumnCount(int)
|
|
139 |
obj1.setColumnCount(0);
|
|
140 |
QCOMPARE(0, obj1.columnCount());
|
|
141 |
obj1.setColumnCount(INT_MIN);
|
|
142 |
QCOMPARE(0, obj1.columnCount()); // Column count can never be negative
|
|
143 |
obj1.setColumnCount(1000);
|
|
144 |
QCOMPARE(1000, obj1.columnCount());
|
|
145 |
// obj1.setColumnCount(INT_MAX);
|
|
146 |
// QCOMPARE(INT_MAX, obj1.columnCount());
|
|
147 |
|
|
148 |
// QTableWidgetItem * QTableWidget::currentItem()
|
|
149 |
// void QTableWidget::setCurrentItem(QTableWidgetItem *)
|
|
150 |
QTableWidgetItem *var3 = new QTableWidgetItem("0,0");
|
|
151 |
obj1.setItem(0, 0, var3);
|
|
152 |
obj1.setItem(1, 1, new QTableWidgetItem("1,1"));
|
|
153 |
obj1.setItem(2, 2, new QTableWidgetItem("2,2"));
|
|
154 |
obj1.setItem(3, 3, new QTableWidgetItem("3,3"));
|
|
155 |
obj1.setCurrentItem(var3);
|
|
156 |
QCOMPARE(var3, obj1.currentItem());
|
|
157 |
obj1.setCurrentItem((QTableWidgetItem *)0);
|
|
158 |
QCOMPARE((QTableWidgetItem *)0, obj1.currentItem());
|
|
159 |
obj1.setItem(0, 0, 0);
|
|
160 |
QCOMPARE((QTableWidgetItem *)0, obj1.item(0, 0));
|
|
161 |
|
|
162 |
// const QTableWidgetItem * QTableWidget::itemPrototype()
|
|
163 |
// void QTableWidget::setItemPrototype(const QTableWidgetItem *)
|
|
164 |
const QTableWidgetItem *var4 = new QTableWidgetItem;
|
|
165 |
obj1.setItemPrototype(var4);
|
|
166 |
QCOMPARE(var4, obj1.itemPrototype());
|
|
167 |
obj1.setItemPrototype((QTableWidgetItem *)0);
|
|
168 |
QCOMPARE((const QTableWidgetItem *)0, obj1.itemPrototype());
|
|
169 |
}
|
|
170 |
|
|
171 |
tst_QTableWidget::tst_QTableWidget(): testWidget(0)
|
|
172 |
{
|
|
173 |
}
|
|
174 |
|
|
175 |
tst_QTableWidget::~tst_QTableWidget()
|
|
176 |
{
|
|
177 |
}
|
|
178 |
|
|
179 |
void tst_QTableWidget::initTestCase()
|
|
180 |
{
|
|
181 |
qRegisterMetaType<QModelIndex>("QModelIndex");
|
|
182 |
testWidget = new QTableWidget();
|
|
183 |
testWidget->show();
|
|
184 |
}
|
|
185 |
|
|
186 |
void tst_QTableWidget::cleanupTestCase()
|
|
187 |
{
|
|
188 |
delete testWidget;
|
|
189 |
}
|
|
190 |
|
|
191 |
void tst_QTableWidget::init()
|
|
192 |
{
|
|
193 |
testWidget->clear();
|
|
194 |
testWidget->setRowCount(5);
|
|
195 |
testWidget->setColumnCount(5);
|
|
196 |
|
|
197 |
for (int row=0; row < testWidget->rowCount(); ++row)
|
|
198 |
testWidget->showRow(row);
|
|
199 |
for (int column=0; column < testWidget->columnCount(); ++column)
|
|
200 |
testWidget->showColumn(column);
|
|
201 |
}
|
|
202 |
|
|
203 |
void tst_QTableWidget::cleanup()
|
|
204 |
{
|
|
205 |
|
|
206 |
}
|
|
207 |
|
|
208 |
void tst_QTableWidget::clearContents()
|
|
209 |
{
|
|
210 |
QTableWidgetItem *item = new QTableWidgetItem("test");
|
|
211 |
testWidget->setHorizontalHeaderItem(0, item);
|
|
212 |
QVERIFY(testWidget->horizontalHeaderItem(0) == item);
|
|
213 |
testWidget->clearContents();
|
|
214 |
QVERIFY(testWidget->horizontalHeaderItem(0) == item);
|
|
215 |
}
|
|
216 |
|
|
217 |
void tst_QTableWidget::clear()
|
|
218 |
{
|
|
219 |
QTableWidgetItem *item = new QTableWidgetItem("foo");
|
|
220 |
testWidget->setItem(0, 0, item);
|
|
221 |
testWidget->setItemSelected(item, true);
|
|
222 |
|
|
223 |
QVERIFY(testWidget->item(0, 0) == item);
|
|
224 |
QVERIFY(testWidget->isItemSelected(item));
|
|
225 |
|
|
226 |
|
|
227 |
QPointer<QObjectTableItem> bla = new QObjectTableItem();
|
|
228 |
testWidget->setItem(1, 1, bla);
|
|
229 |
|
|
230 |
testWidget->clear();
|
|
231 |
|
|
232 |
QVERIFY(bla.isNull());
|
|
233 |
|
|
234 |
QVERIFY(!testWidget->item(0,0));
|
|
235 |
QVERIFY(!testWidget->selectedRanges().count());
|
|
236 |
QVERIFY(!testWidget->selectedItems().count());
|
|
237 |
}
|
|
238 |
|
|
239 |
void tst_QTableWidget::rowCount()
|
|
240 |
{
|
|
241 |
int rowCountBefore = 5;
|
|
242 |
int rowCountAfter = 10;
|
|
243 |
|
|
244 |
int rowCount = testWidget->rowCount();
|
|
245 |
QCOMPARE(rowCount, rowCountBefore);
|
|
246 |
|
|
247 |
testWidget->setRowCount(rowCountAfter);
|
|
248 |
rowCount = testWidget->rowCount();
|
|
249 |
QCOMPARE(rowCount, rowCountAfter);
|
|
250 |
|
|
251 |
QPersistentModelIndex index(testWidget->model()->index(rowCountAfter - 1, 0,
|
|
252 |
testWidget->rootIndex()));
|
|
253 |
QCOMPARE(index.row(), rowCountAfter - 1);
|
|
254 |
QCOMPARE(index.column(), 0);
|
|
255 |
QVERIFY(index.isValid());
|
|
256 |
testWidget->setRowCount(rowCountBefore);
|
|
257 |
QCOMPARE(index.row(), -1);
|
|
258 |
QCOMPARE(index.column(), -1);
|
|
259 |
QVERIFY(!index.isValid());
|
|
260 |
|
|
261 |
rowCountBefore = testWidget->rowCount();
|
|
262 |
testWidget->setRowCount(-1);
|
|
263 |
QCOMPARE(testWidget->rowCount(), rowCountBefore);
|
|
264 |
}
|
|
265 |
|
|
266 |
void tst_QTableWidget::columnCount()
|
|
267 |
{
|
|
268 |
int columnCountBefore = 5;
|
|
269 |
int columnCountAfter = 10;
|
|
270 |
|
|
271 |
int columnCount = testWidget->columnCount();
|
|
272 |
QCOMPARE(columnCount, columnCountBefore);
|
|
273 |
|
|
274 |
testWidget->setColumnCount(columnCountAfter);
|
|
275 |
columnCount = testWidget->columnCount();
|
|
276 |
QCOMPARE(columnCount, columnCountAfter);
|
|
277 |
|
|
278 |
QPersistentModelIndex index(testWidget->model()->index(0, columnCountAfter - 1,
|
|
279 |
testWidget->rootIndex()));
|
|
280 |
QCOMPARE(index.row(), 0);
|
|
281 |
QCOMPARE(index.column(), columnCountAfter - 1);
|
|
282 |
QVERIFY(index.isValid());
|
|
283 |
testWidget->setColumnCount(columnCountBefore);
|
|
284 |
QCOMPARE(index.row(), -1);
|
|
285 |
QCOMPARE(index.column(), -1);
|
|
286 |
QVERIFY(!index.isValid());
|
|
287 |
|
|
288 |
columnCountBefore = testWidget->columnCount();
|
|
289 |
testWidget->setColumnCount(-1);
|
|
290 |
QCOMPARE(testWidget->columnCount(), columnCountBefore);
|
|
291 |
}
|
|
292 |
|
|
293 |
void tst_QTableWidget::itemAssignment()
|
|
294 |
{
|
|
295 |
QTableWidgetItem itemInWidget("inWidget");
|
|
296 |
testWidget->setItem(0, 0, &itemInWidget);
|
|
297 |
itemInWidget.setFlags(itemInWidget.flags() | Qt::ItemIsTristate);
|
|
298 |
QTableWidgetItem itemOutsideWidget("outsideWidget");
|
|
299 |
|
|
300 |
QVERIFY(itemInWidget.tableWidget());
|
|
301 |
QCOMPARE(itemInWidget.text(), QString("inWidget"));
|
|
302 |
QVERIFY(itemInWidget.flags() & Qt::ItemIsTristate);
|
|
303 |
|
|
304 |
QVERIFY(!itemOutsideWidget.tableWidget());
|
|
305 |
QCOMPARE(itemOutsideWidget.text(), QString("outsideWidget"));
|
|
306 |
QVERIFY(!(itemOutsideWidget.flags() & Qt::ItemIsTristate));
|
|
307 |
|
|
308 |
itemOutsideWidget = itemInWidget;
|
|
309 |
QVERIFY(!itemOutsideWidget.tableWidget());
|
|
310 |
QCOMPARE(itemOutsideWidget.text(), QString("inWidget"));
|
|
311 |
QVERIFY(itemOutsideWidget.flags() & Qt::ItemIsTristate);
|
|
312 |
}
|
|
313 |
|
|
314 |
void tst_QTableWidget::item_data()
|
|
315 |
{
|
|
316 |
QTest::addColumn<int>("rowCount");
|
|
317 |
QTest::addColumn<int>("columnCount");
|
|
318 |
QTest::addColumn<int>("row");
|
|
319 |
QTest::addColumn<int>("column");
|
|
320 |
QTest::addColumn<bool>("expectItem");
|
|
321 |
|
|
322 |
QTest::newRow("0x0 take [0,0]") << 0 << 0 << 0 << 0 << false;
|
|
323 |
QTest::newRow("0x0 take [4,4]") << 0 << 0 << 4 << 4 << false;
|
|
324 |
QTest::newRow("4x4 take [0,0]") << 4 << 4 << 0 << 0 << true;
|
|
325 |
QTest::newRow("4x4 take [4,4]") << 4 << 4 << 4 << 4 << false;
|
|
326 |
QTest::newRow("4x4 take [2,2]") << 4 << 4 << 2 << 2 << true;
|
|
327 |
}
|
|
328 |
|
|
329 |
void tst_QTableWidget::item()
|
|
330 |
{
|
|
331 |
QFETCH(int, rowCount);
|
|
332 |
QFETCH(int, columnCount);
|
|
333 |
QFETCH(int, row);
|
|
334 |
QFETCH(int, column);
|
|
335 |
QFETCH(bool, expectItem);
|
|
336 |
|
|
337 |
testWidget->setRowCount(rowCount);
|
|
338 |
testWidget->setColumnCount(columnCount);
|
|
339 |
QCOMPARE(testWidget->rowCount(), rowCount);
|
|
340 |
QCOMPARE(testWidget->columnCount(), columnCount);
|
|
341 |
|
|
342 |
for (int r = 0; r < testWidget->rowCount(); ++r)
|
|
343 |
for (int c = 0; c < testWidget->columnCount(); ++c)
|
|
344 |
testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c)));
|
|
345 |
|
|
346 |
for (int r = 0; r < testWidget->rowCount(); ++r)
|
|
347 |
for (int c = 0; c < testWidget->columnCount(); ++c)
|
|
348 |
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
|
|
349 |
|
|
350 |
QTableWidgetItem *item = testWidget->item(row, column);
|
|
351 |
QCOMPARE(!!item, expectItem);
|
|
352 |
if (expectItem)
|
|
353 |
QCOMPARE(item->text(), QString::number(row * column + column));
|
|
354 |
}
|
|
355 |
|
|
356 |
void tst_QTableWidget::takeItem_data()
|
|
357 |
{
|
|
358 |
QTest::addColumn<int>("rowCount");
|
|
359 |
QTest::addColumn<int>("columnCount");
|
|
360 |
QTest::addColumn<int>("row");
|
|
361 |
QTest::addColumn<int>("column");
|
|
362 |
QTest::addColumn<bool>("expectItem");
|
|
363 |
|
|
364 |
QTest::newRow("0x0 take [0,0]") << 0 << 0 << 0 << 0 << false;
|
|
365 |
QTest::newRow("0x0 take [4,4]") << 0 << 0 << 4 << 4 << false;
|
|
366 |
QTest::newRow("4x4 take [0,0]") << 4 << 4 << 0 << 0 << true;
|
|
367 |
QTest::newRow("4x4 take [4,4]") << 4 << 4 << 4 << 4 << false;
|
|
368 |
QTest::newRow("4x4 take [2,2]") << 4 << 4 << 2 << 2 << true;
|
|
369 |
}
|
|
370 |
|
|
371 |
void tst_QTableWidget::takeItem()
|
|
372 |
{
|
|
373 |
QFETCH(int, rowCount);
|
|
374 |
QFETCH(int, columnCount);
|
|
375 |
QFETCH(int, row);
|
|
376 |
QFETCH(int, column);
|
|
377 |
QFETCH(bool, expectItem);
|
|
378 |
|
|
379 |
testWidget->setRowCount(rowCount);
|
|
380 |
testWidget->setColumnCount(columnCount);
|
|
381 |
QCOMPARE(testWidget->rowCount(), rowCount);
|
|
382 |
QCOMPARE(testWidget->columnCount(), columnCount);
|
|
383 |
|
|
384 |
for (int r = 0; r < testWidget->rowCount(); ++r)
|
|
385 |
for (int c = 0; c < testWidget->columnCount(); ++c)
|
|
386 |
testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c)));
|
|
387 |
|
|
388 |
for (int r = 0; r < testWidget->rowCount(); ++r)
|
|
389 |
for (int c = 0; c < testWidget->columnCount(); ++c)
|
|
390 |
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
|
|
391 |
|
|
392 |
QTableWidgetItem *item = testWidget->takeItem(row, column);
|
|
393 |
QCOMPARE(!!item, expectItem);
|
|
394 |
if (expectItem) {
|
|
395 |
QCOMPARE(item->text(), QString::number(row * column + column));
|
|
396 |
delete item;
|
|
397 |
}
|
|
398 |
QVERIFY(!testWidget->takeItem(row, column));
|
|
399 |
}
|
|
400 |
|
|
401 |
void tst_QTableWidget::selectedItems_data()
|
|
402 |
{
|
|
403 |
QTest::addColumn<int>("rowCount");
|
|
404 |
QTest::addColumn<int>("columnCount");
|
|
405 |
QTest::addColumn<IntIntList>("createItems");
|
|
406 |
QTest::addColumn<IntList>("hiddenRows");
|
|
407 |
QTest::addColumn<IntList>("hiddenColumns");
|
|
408 |
QTest::addColumn<QTableWidgetSelectionRange>("selectionRange");
|
|
409 |
QTest::addColumn<IntIntList>("expectedItems");
|
|
410 |
|
|
411 |
QTest::newRow("3x3 empty cells, no hidden rows/columns, none selected")
|
|
412 |
<< 3 << 3
|
|
413 |
<< IntIntList()
|
|
414 |
<< IntList()
|
|
415 |
<< IntList()
|
|
416 |
<< QTableWidgetSelectionRange()
|
|
417 |
<< IntIntList();
|
|
418 |
|
|
419 |
QTest::newRow("3x3 empty cells,no hidden rows/columnms, all selected")
|
|
420 |
<< 3 << 3
|
|
421 |
<< IntIntList()
|
|
422 |
<< IntList()
|
|
423 |
<< IntList()
|
|
424 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
425 |
<< IntIntList();
|
|
426 |
|
|
427 |
QTest::newRow("3x3 (1,1) exists, no hidden rows/columnms, all selected")
|
|
428 |
<< 3 << 3
|
|
429 |
<< (IntIntList() << IntPair(1,1))
|
|
430 |
<< IntList()
|
|
431 |
<< IntList()
|
|
432 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
433 |
<< (IntIntList() << IntPair(1,1));
|
|
434 |
|
|
435 |
QTest::newRow("3x3 (1,1) exists, row 1 hidden, all selected")
|
|
436 |
<< 3 << 3
|
|
437 |
<< (IntIntList() << IntPair(1,1))
|
|
438 |
<< (IntList() << 1)
|
|
439 |
<< IntList()
|
|
440 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
441 |
<< IntIntList();
|
|
442 |
|
|
443 |
QTest::newRow("3x3 (1,1) exists, column 1 hidden, all selected")
|
|
444 |
<< 3 << 3
|
|
445 |
<< (IntIntList() << IntPair(1,1))
|
|
446 |
<< IntList()
|
|
447 |
<< (IntList() << 1)
|
|
448 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
449 |
<< IntIntList();
|
|
450 |
|
|
451 |
QTest::newRow("3x3 all exists, no hidden rows/columns, all selected")
|
|
452 |
<< 3 << 3
|
|
453 |
<< (IntIntList()
|
|
454 |
<< IntPair(0,0) << IntPair(0,1) << IntPair(0,2)
|
|
455 |
<< IntPair(1,0) << IntPair(1,1) << IntPair(1,2)
|
|
456 |
<< IntPair(2,0) << IntPair(2,1) << IntPair(2,2))
|
|
457 |
<< IntList()
|
|
458 |
<< IntList()
|
|
459 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
460 |
<< (IntIntList()
|
|
461 |
<< IntPair(0,0) << IntPair(0,1) << IntPair(0,2)
|
|
462 |
<< IntPair(1,0) << IntPair(1,1) << IntPair(1,2)
|
|
463 |
<< IntPair(2,0) << IntPair(2,1) << IntPair(2,2));
|
|
464 |
|
|
465 |
QTest::newRow("3x3 all exists, row 1 hidden, all selected")
|
|
466 |
<< 3 << 3
|
|
467 |
<< (IntIntList()
|
|
468 |
<< IntPair(0,0) << IntPair(0,1) << IntPair(0,2)
|
|
469 |
<< IntPair(1,0) << IntPair(1,1) << IntPair(1,2)
|
|
470 |
<< IntPair(2,0) << IntPair(2,1) << IntPair(2,2))
|
|
471 |
<< (IntList() << 1)
|
|
472 |
<< IntList()
|
|
473 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
474 |
<< (IntIntList()
|
|
475 |
<< IntPair(0,0) << IntPair(0,1) << IntPair(0,2)
|
|
476 |
<< IntPair(2,0) << IntPair(2,1) << IntPair(2,2));
|
|
477 |
|
|
478 |
QTest::newRow("3x3 all exists, column 1 hidden, all selected")
|
|
479 |
<< 3 << 3
|
|
480 |
<< (IntIntList()
|
|
481 |
<< IntPair(0,0) << IntPair(0,1) << IntPair(0,2)
|
|
482 |
<< IntPair(1,0) << IntPair(1,1) << IntPair(1,2)
|
|
483 |
<< IntPair(2,0) << IntPair(2,1) << IntPair(2,2))
|
|
484 |
<< IntList()
|
|
485 |
<< (IntList() << 1)
|
|
486 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
487 |
<< (IntIntList()
|
|
488 |
<< IntPair(0,0) << IntPair(0,2)
|
|
489 |
<< IntPair(1,0) << IntPair(1,2)
|
|
490 |
<< IntPair(2,0) << IntPair(2,2));
|
|
491 |
|
|
492 |
QTest::newRow("3x3 none exists, no hidden rows/columns, all selected")
|
|
493 |
<< 3 << 3
|
|
494 |
<< IntIntList()
|
|
495 |
<< IntList()
|
|
496 |
<< IntList()
|
|
497 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
498 |
<< IntIntList();
|
|
499 |
// << (IntIntList()
|
|
500 |
// << IntPair(0,0) << IntPair(0,1) << IntPair(0,2)
|
|
501 |
// << IntPair(1,0) << IntPair(1,1) << IntPair(1,2)
|
|
502 |
// << IntPair(2,0) << IntPair(2,1) << IntPair(2,2));
|
|
503 |
|
|
504 |
QTest::newRow("3x3 none exists, row 1 hidden, all selected, filling empty cells")
|
|
505 |
<< 3 << 3
|
|
506 |
<< IntIntList()
|
|
507 |
<< (IntList() << 1)
|
|
508 |
<< IntList()
|
|
509 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
510 |
<< IntIntList();
|
|
511 |
// << (IntIntList()
|
|
512 |
// << IntPair(0,0) << IntPair(0,1) << IntPair(0,2)
|
|
513 |
// << IntPair(2,0) << IntPair(2,1) << IntPair(2,2));
|
|
514 |
|
|
515 |
QTest::newRow("3x3 none exists, column 1 hidden, all selected")
|
|
516 |
<< 3 << 3
|
|
517 |
<< IntIntList()
|
|
518 |
<< IntList()
|
|
519 |
<< (IntList() << 1)
|
|
520 |
<< QTableWidgetSelectionRange(0, 0, 2, 2)
|
|
521 |
<< IntIntList();
|
|
522 |
// << (IntIntList()
|
|
523 |
// << IntPair(0,0) << IntPair(0,2)
|
|
524 |
// << IntPair(1,0) << IntPair(1,2)
|
|
525 |
// << IntPair(2,0) << IntPair(2,2));
|
|
526 |
}
|
|
527 |
|
|
528 |
void tst_QTableWidget::selectedItems()
|
|
529 |
{
|
|
530 |
QFETCH(int, rowCount);
|
|
531 |
QFETCH(int, columnCount);
|
|
532 |
QFETCH(IntIntList, createItems);
|
|
533 |
QFETCH(IntList, hiddenRows);
|
|
534 |
QFETCH(IntList, hiddenColumns);
|
|
535 |
QFETCH(QTableWidgetSelectionRange, selectionRange);
|
|
536 |
QFETCH(IntIntList, expectedItems);
|
|
537 |
|
|
538 |
// set dimensions and test they are ok
|
|
539 |
testWidget->setRowCount(rowCount);
|
|
540 |
testWidget->setColumnCount(columnCount);
|
|
541 |
QCOMPARE(testWidget->rowCount(), rowCount);
|
|
542 |
QCOMPARE(testWidget->columnCount(), columnCount);
|
|
543 |
|
|
544 |
// create and set items
|
|
545 |
foreach (IntPair intPair, createItems) {
|
|
546 |
testWidget->setItem(intPair.first, intPair.second,
|
|
547 |
new QTableWidgetItem(QString("Item %1 %2")
|
|
548 |
.arg(intPair.first).arg(intPair.second)));
|
|
549 |
}
|
|
550 |
// hide rows/columns
|
|
551 |
foreach (int row, hiddenRows)
|
|
552 |
testWidget->setRowHidden(row, true);
|
|
553 |
foreach (int column, hiddenColumns)
|
|
554 |
testWidget->setColumnHidden(column, true);
|
|
555 |
|
|
556 |
// make sure we don't have any previous selections hanging around
|
|
557 |
QVERIFY(!testWidget->selectedRanges().count());
|
|
558 |
QVERIFY(!testWidget->selectedItems().count());
|
|
559 |
|
|
560 |
// select range and check that it is set correctly
|
|
561 |
testWidget->setRangeSelected(selectionRange, true);
|
|
562 |
if (selectionRange.topRow() >= 0) {
|
|
563 |
QCOMPARE(testWidget->selectedRanges().count(), 1);
|
|
564 |
QCOMPARE(testWidget->selectedRanges().at(0).topRow(), selectionRange.topRow());
|
|
565 |
QCOMPARE(testWidget->selectedRanges().at(0).bottomRow(), selectionRange.bottomRow());
|
|
566 |
QCOMPARE(testWidget->selectedRanges().at(0).leftColumn(), selectionRange.leftColumn());
|
|
567 |
QCOMPARE(testWidget->selectedRanges().at(0).rightColumn(), selectionRange.rightColumn());
|
|
568 |
} else {
|
|
569 |
QCOMPARE(testWidget->selectedRanges().count(), 0);
|
|
570 |
}
|
|
571 |
|
|
572 |
// check that the correct number of items and the expected items are there
|
|
573 |
QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems();
|
|
574 |
QCOMPARE(selectedItems.count(), expectedItems.count());
|
|
575 |
foreach (IntPair intPair, expectedItems)
|
|
576 |
QVERIFY(selectedItems.contains(testWidget->item(intPair.first, intPair.second)));
|
|
577 |
|
|
578 |
// check that setItemSelected agrees with selectedItems
|
|
579 |
for (int row = 0; row<testWidget->rowCount(); ++row) {
|
|
580 |
bool hidden = false;
|
|
581 |
foreach (int hiddenRow, hiddenRows){
|
|
582 |
if(hiddenRow == row){
|
|
583 |
hidden = true;
|
|
584 |
break;
|
|
585 |
}
|
|
586 |
}
|
|
587 |
if (hidden)
|
|
588 |
continue;
|
|
589 |
|
|
590 |
for (int column = 0; column<testWidget->columnCount(); ++column) {
|
|
591 |
foreach (int hiddenColumn, hiddenColumns){
|
|
592 |
if(hiddenColumn == column){
|
|
593 |
hidden = true;
|
|
594 |
break;
|
|
595 |
}
|
|
596 |
}
|
|
597 |
if (hidden)
|
|
598 |
continue;
|
|
599 |
|
|
600 |
QTableWidgetItem *item = testWidget->item(row, column);
|
|
601 |
if (item && testWidget->isItemSelected(item))
|
|
602 |
QVERIFY(selectedItems.contains(item));
|
|
603 |
}
|
|
604 |
}
|
|
605 |
}
|
|
606 |
|
|
607 |
void tst_QTableWidget::removeRow_data()
|
|
608 |
{
|
|
609 |
QTest::addColumn<int>("rowCount");
|
|
610 |
QTest::addColumn<int>("columnCount");
|
|
611 |
QTest::addColumn<int>("row");
|
|
612 |
QTest::addColumn<int>("expectedRowCount");
|
|
613 |
QTest::addColumn<int>("expectedColumnCount");
|
|
614 |
|
|
615 |
QTest::newRow("Empty") << 0 << 0 << 0 << 0 << 0;
|
|
616 |
QTest::newRow("1x1:0") << 1 << 1 << 0 << 0 << 1;
|
|
617 |
QTest::newRow("3x3:0") << 3 << 3 << 0 << 2 << 3;
|
|
618 |
QTest::newRow("3x3:1") << 3 << 3 << 1 << 2 << 3;
|
|
619 |
QTest::newRow("3x3:2") << 3 << 3 << 2 << 2 << 3;
|
|
620 |
}
|
|
621 |
|
|
622 |
void tst_QTableWidget::removeRow()
|
|
623 |
{
|
|
624 |
QFETCH(int, rowCount);
|
|
625 |
QFETCH(int, columnCount);
|
|
626 |
QFETCH(int, row);
|
|
627 |
QFETCH(int, expectedRowCount);
|
|
628 |
QFETCH(int, expectedColumnCount);
|
|
629 |
|
|
630 |
// set dimensions and test they are ok
|
|
631 |
testWidget->setRowCount(rowCount);
|
|
632 |
testWidget->setColumnCount(columnCount);
|
|
633 |
QCOMPARE(testWidget->rowCount(), rowCount);
|
|
634 |
QCOMPARE(testWidget->columnCount(), columnCount);
|
|
635 |
|
|
636 |
// fill table with items
|
|
637 |
for (int r = 0; r < rowCount; ++r)
|
|
638 |
for (int c = 0; c < columnCount; ++c)
|
|
639 |
testWidget->setItem(r, c,
|
|
640 |
new QTableWidgetItem(
|
|
641 |
QString::number(r) + ":" + QString::number(c)));
|
|
642 |
|
|
643 |
// remove and compare the results
|
|
644 |
testWidget->removeRow(row);
|
|
645 |
QCOMPARE(testWidget->rowCount(), expectedRowCount);
|
|
646 |
QCOMPARE(testWidget->columnCount(), expectedColumnCount);
|
|
647 |
|
|
648 |
// check if the correct items were removed
|
|
649 |
for (int r = 0; r < expectedRowCount; ++r)
|
|
650 |
for (int c = 0; c < expectedColumnCount; ++c)
|
|
651 |
if (r < row)
|
|
652 |
QCOMPARE(testWidget->item(r, c)->text(),
|
|
653 |
QString::number(r) + ":" + QString::number(c));
|
|
654 |
else
|
|
655 |
QCOMPARE(testWidget->item(r, c)->text(),
|
|
656 |
QString::number(r + 1) + ":" + QString::number(c));
|
|
657 |
}
|
|
658 |
|
|
659 |
void tst_QTableWidget::removeColumn_data()
|
|
660 |
{
|
|
661 |
QTest::addColumn<int>("rowCount");
|
|
662 |
QTest::addColumn<int>("columnCount");
|
|
663 |
QTest::addColumn<int>("column");
|
|
664 |
QTest::addColumn<int>("expectedRowCount");
|
|
665 |
QTest::addColumn<int>("expectedColumnCount");
|
|
666 |
|
|
667 |
QTest::newRow("Empty") << 0 << 0 << 0 << 0 << 0;
|
|
668 |
QTest::newRow("1x1:0") << 1 << 1 << 0 << 1 << 0;
|
|
669 |
QTest::newRow("3x3:0") << 3 << 3 << 0 << 3 << 2;
|
|
670 |
QTest::newRow("3x3:1") << 3 << 3 << 1 << 3 << 2;
|
|
671 |
QTest::newRow("3x3:2") << 3 << 3 << 2 << 3 << 2;
|
|
672 |
}
|
|
673 |
|
|
674 |
void tst_QTableWidget::removeColumn()
|
|
675 |
{
|
|
676 |
QFETCH(int, rowCount);
|
|
677 |
QFETCH(int, columnCount);
|
|
678 |
QFETCH(int, column);
|
|
679 |
QFETCH(int, expectedRowCount);
|
|
680 |
QFETCH(int, expectedColumnCount);
|
|
681 |
|
|
682 |
// set dimensions and test they are ok
|
|
683 |
testWidget->setRowCount(rowCount);
|
|
684 |
testWidget->setColumnCount(columnCount);
|
|
685 |
QCOMPARE(testWidget->rowCount(), rowCount);
|
|
686 |
QCOMPARE(testWidget->columnCount(), columnCount);
|
|
687 |
|
|
688 |
// fill table with items
|
|
689 |
for (int r = 0; r < rowCount; ++r)
|
|
690 |
for (int c = 0; c < columnCount; ++c)
|
|
691 |
testWidget->setItem(r, c,
|
|
692 |
new QTableWidgetItem(
|
|
693 |
QString::number(r) + ":" + QString::number(c)));
|
|
694 |
|
|
695 |
// remove and compare the results
|
|
696 |
testWidget->removeColumn(column);
|
|
697 |
QCOMPARE(testWidget->rowCount(), expectedRowCount);
|
|
698 |
QCOMPARE(testWidget->columnCount(), expectedColumnCount);
|
|
699 |
|
|
700 |
|
|
701 |
// check if the correct items were removed
|
|
702 |
for (int r = 0; r < expectedRowCount; ++r)
|
|
703 |
for (int c = 0; c < expectedColumnCount; ++c)
|
|
704 |
if (c < column)
|
|
705 |
QCOMPARE(testWidget->item(r, c)->text(),
|
|
706 |
QString::number(r) + ":" + QString::number(c));
|
|
707 |
else
|
|
708 |
QCOMPARE(testWidget->item(r, c)->text(),
|
|
709 |
QString::number(r) + ":" + QString::number(c + 1));
|
|
710 |
}
|
|
711 |
|
|
712 |
void tst_QTableWidget::insertRow_data()
|
|
713 |
{
|
|
714 |
QTest::addColumn<int>("rowCount");
|
|
715 |
QTest::addColumn<int>("columnCount");
|
|
716 |
QTest::addColumn<int>("row");
|
|
717 |
QTest::addColumn<int>("expectedRowCount");
|
|
718 |
QTest::addColumn<int>("expectedColumnCount");
|
|
719 |
|
|
720 |
QTest::newRow("Empty") << 0 << 0 << 0 << 1 << 0;
|
|
721 |
QTest::newRow("1x1:0") << 1 << 1 << 0 << 2 << 1;
|
|
722 |
QTest::newRow("3x3:-1") << 3 << 3 << -1 << 3 << 3;
|
|
723 |
QTest::newRow("3x3:0") << 3 << 3 << 0 << 4 << 3;
|
|
724 |
QTest::newRow("3x3:1") << 3 << 3 << 1 << 4 << 3;
|
|
725 |
QTest::newRow("3x3:2") << 3 << 3 << 2 << 4 << 3;
|
|
726 |
QTest::newRow("3x3:3") << 3 << 3 << 3 << 4 << 3;
|
|
727 |
QTest::newRow("3x3:4") << 3 << 3 << 4 << 3 << 3;
|
|
728 |
}
|
|
729 |
|
|
730 |
void tst_QTableWidget::insertRow()
|
|
731 |
{
|
|
732 |
QFETCH(int, rowCount);
|
|
733 |
QFETCH(int, columnCount);
|
|
734 |
QFETCH(int, row);
|
|
735 |
QFETCH(int, expectedRowCount);
|
|
736 |
QFETCH(int, expectedColumnCount);
|
|
737 |
|
|
738 |
// set dimensions and test they are ok
|
|
739 |
testWidget->setRowCount(rowCount);
|
|
740 |
testWidget->setColumnCount(columnCount);
|
|
741 |
QCOMPARE(testWidget->rowCount(), rowCount);
|
|
742 |
QCOMPARE(testWidget->columnCount(), columnCount);
|
|
743 |
|
|
744 |
// insert and compare the results
|
|
745 |
testWidget->insertRow(row);
|
|
746 |
QCOMPARE(testWidget->rowCount(), expectedRowCount);
|
|
747 |
QCOMPARE(testWidget->columnCount(), expectedColumnCount);
|
|
748 |
}
|
|
749 |
|
|
750 |
void tst_QTableWidget::insertColumn_data()
|
|
751 |
{
|
|
752 |
QTest::addColumn<int>("rowCount");
|
|
753 |
QTest::addColumn<int>("columnCount");
|
|
754 |
QTest::addColumn<int>("column");
|
|
755 |
QTest::addColumn<int>("expectedRowCount");
|
|
756 |
QTest::addColumn<int>("expectedColumnCount");
|
|
757 |
|
|
758 |
QTest::newRow("Empty") << 0 << 0 << 0 << 0 << 1;
|
|
759 |
QTest::newRow("1x1:0") << 1 << 1 << 0 << 1 << 2;
|
|
760 |
QTest::newRow("3x3:-1") << 3 << 3 << -1 << 3 << 3;
|
|
761 |
QTest::newRow("3x3:0") << 3 << 3 << 0 << 3 << 4;
|
|
762 |
QTest::newRow("3x3:1") << 3 << 3 << 1 << 3 << 4;
|
|
763 |
QTest::newRow("3x3:2") << 3 << 3 << 2 << 3 << 4;
|
|
764 |
QTest::newRow("3x3:3") << 3 << 3 << 3 << 3 << 4;
|
|
765 |
QTest::newRow("3x3:4") << 3 << 3 << 4 << 3 << 3;
|
|
766 |
}
|
|
767 |
|
|
768 |
void tst_QTableWidget::insertColumn()
|
|
769 |
{
|
|
770 |
QFETCH(int, rowCount);
|
|
771 |
QFETCH(int, columnCount);
|
|
772 |
QFETCH(int, column);
|
|
773 |
QFETCH(int, expectedRowCount);
|
|
774 |
QFETCH(int, expectedColumnCount);
|
|
775 |
|
|
776 |
// set dimensions and test they are ok
|
|
777 |
testWidget->setRowCount(rowCount);
|
|
778 |
testWidget->setColumnCount(columnCount);
|
|
779 |
QCOMPARE(testWidget->rowCount(), rowCount);
|
|
780 |
QCOMPARE(testWidget->columnCount(), columnCount);
|
|
781 |
|
|
782 |
// insert and compare the results
|
|
783 |
testWidget->insertColumn(column);
|
|
784 |
QCOMPARE(testWidget->rowCount(), expectedRowCount);
|
|
785 |
QCOMPARE(testWidget->columnCount(), expectedColumnCount);
|
|
786 |
}
|
|
787 |
|
|
788 |
void tst_QTableWidget::itemStreaming_data()
|
|
789 |
{
|
|
790 |
QTest::addColumn<QString>("text");
|
|
791 |
QTest::addColumn<QString>("toolTip");
|
|
792 |
|
|
793 |
QTest::newRow("Data") << "item text" << "tool tip text";
|
|
794 |
}
|
|
795 |
|
|
796 |
void tst_QTableWidget::itemStreaming()
|
|
797 |
{
|
|
798 |
QFETCH(QString, text);
|
|
799 |
QFETCH(QString, toolTip);
|
|
800 |
|
|
801 |
QTableWidgetItem item;
|
|
802 |
QCOMPARE(item.text(), QString());
|
|
803 |
QCOMPARE(item.toolTip(), QString());
|
|
804 |
|
|
805 |
item.setText(text);
|
|
806 |
item.setToolTip(toolTip);
|
|
807 |
QCOMPARE(item.text(), text);
|
|
808 |
QCOMPARE(item.toolTip(), toolTip);
|
|
809 |
|
|
810 |
QByteArray buffer;
|
|
811 |
QDataStream out(&buffer, QIODevice::WriteOnly);
|
|
812 |
out << item;
|
|
813 |
|
|
814 |
QTableWidgetItem item2;
|
|
815 |
QCOMPARE(item2.text(), QString());
|
|
816 |
QCOMPARE(item2.toolTip(), QString());
|
|
817 |
|
|
818 |
QVERIFY(!buffer.isEmpty());
|
|
819 |
|
|
820 |
QDataStream in(&buffer, QIODevice::ReadOnly);
|
|
821 |
in >> item2;
|
|
822 |
QCOMPARE(item2.text(), text);
|
|
823 |
QCOMPARE(item2.toolTip(), toolTip);
|
|
824 |
}
|
|
825 |
|
|
826 |
void tst_QTableWidget::itemOwnership()
|
|
827 |
{
|
|
828 |
QPointer<QObjectTableItem> item;
|
|
829 |
QPointer<QObjectTableItem> headerItem;
|
|
830 |
|
|
831 |
//delete from outside
|
|
832 |
item = new QObjectTableItem();
|
|
833 |
testWidget->setItem(0, 0, item);
|
|
834 |
delete item;
|
|
835 |
QCOMPARE(testWidget->item(0, 0), (QTableWidgetItem *)0);
|
|
836 |
|
|
837 |
//delete vertical headeritem from outside
|
|
838 |
headerItem = new QObjectTableItem();
|
|
839 |
testWidget->setVerticalHeaderItem(0, headerItem);
|
|
840 |
delete headerItem;
|
|
841 |
QCOMPARE(testWidget->verticalHeaderItem(0), (QTableWidgetItem *)0);
|
|
842 |
|
|
843 |
//delete horizontal headeritem from outside
|
|
844 |
headerItem = new QObjectTableItem();
|
|
845 |
testWidget->setHorizontalHeaderItem(0, headerItem);
|
|
846 |
delete headerItem;
|
|
847 |
QCOMPARE(testWidget->horizontalHeaderItem(0), (QTableWidgetItem *)0);
|
|
848 |
|
|
849 |
//setItem
|
|
850 |
item = new QObjectTableItem();
|
|
851 |
testWidget->setItem(0, 0, item);
|
|
852 |
testWidget->setItem(0, 0, new QTableWidgetItem());
|
|
853 |
QVERIFY(item.isNull());
|
|
854 |
|
|
855 |
//setHorizontalHeaderItem
|
|
856 |
headerItem = new QObjectTableItem();
|
|
857 |
testWidget->setHorizontalHeaderItem(0, headerItem);
|
|
858 |
testWidget->setHorizontalHeaderItem(0, new QTableWidgetItem());
|
|
859 |
QVERIFY(headerItem.isNull());
|
|
860 |
|
|
861 |
//setVerticalHeaderItem
|
|
862 |
headerItem = new QObjectTableItem();
|
|
863 |
testWidget->setVerticalHeaderItem(0, headerItem);
|
|
864 |
testWidget->setVerticalHeaderItem(0, new QTableWidgetItem());
|
|
865 |
QVERIFY(headerItem.isNull());
|
|
866 |
|
|
867 |
//takeItem
|
|
868 |
item = new QObjectTableItem();
|
|
869 |
testWidget->setItem(0, 0, item);
|
|
870 |
testWidget->takeItem(0, 0);
|
|
871 |
QVERIFY(!item.isNull());
|
|
872 |
delete item;
|
|
873 |
|
|
874 |
// removeRow
|
|
875 |
item = new QObjectTableItem();
|
|
876 |
headerItem = new QObjectTableItem();
|
|
877 |
testWidget->setItem(0, 0, item);
|
|
878 |
testWidget->setVerticalHeaderItem(0, headerItem);
|
|
879 |
testWidget->removeRow(0);
|
|
880 |
QVERIFY(item.isNull());
|
|
881 |
QVERIFY(headerItem.isNull());
|
|
882 |
|
|
883 |
// removeColumn
|
|
884 |
item = new QObjectTableItem();
|
|
885 |
headerItem = new QObjectTableItem();
|
|
886 |
testWidget->setItem(0, 0, item);
|
|
887 |
testWidget->setHorizontalHeaderItem(0, headerItem);
|
|
888 |
testWidget->removeColumn(0);
|
|
889 |
QVERIFY(item.isNull());
|
|
890 |
QVERIFY(headerItem.isNull());
|
|
891 |
|
|
892 |
// clear
|
|
893 |
item = new QObjectTableItem();
|
|
894 |
testWidget->setItem(0, 0, item);
|
|
895 |
testWidget->clear();
|
|
896 |
QVERIFY(item.isNull());
|
|
897 |
}
|
|
898 |
|
|
899 |
void tst_QTableWidget::sortItems_data()
|
|
900 |
{
|
|
901 |
QTest::addColumn<int>("rowCount");
|
|
902 |
QTest::addColumn<int>("columnCount");
|
|
903 |
QTest::addColumn<int>("sortOrder");
|
|
904 |
QTest::addColumn<int>("sortColumn");
|
|
905 |
QTest::addColumn<QStringList>("initial");
|
|
906 |
QTest::addColumn<QStringList>("expected");
|
|
907 |
QTest::addColumn<IntList>("rows");
|
|
908 |
QTest::addColumn<IntList>("initialHidden");
|
|
909 |
QTest::addColumn<IntList>("expectedHidden");
|
|
910 |
|
|
911 |
QTest::newRow("ascending")
|
|
912 |
<< 4 << 5
|
|
913 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
914 |
<< 0
|
|
915 |
<< (QStringList()
|
|
916 |
<< "0" << "a" << "o" << "8" << "k"
|
|
917 |
<< "3" << "d" << "k" << "o" << "6"
|
|
918 |
<< "2" << "c" << "9" << "y" << "8"
|
|
919 |
<< "1" << "b" << "7" << "3" << "u")
|
|
920 |
<< (QStringList()
|
|
921 |
<< "0" << "a" << "o" << "8" << "k"
|
|
922 |
<< "1" << "b" << "7" << "3" << "u"
|
|
923 |
<< "2" << "c" << "9" << "y" << "8"
|
|
924 |
<< "3" << "d" << "k" << "o" << "6")
|
|
925 |
<< (IntList() << 0 << 3 << 2 << 1)
|
|
926 |
<< IntList()
|
|
927 |
<< IntList();
|
|
928 |
|
|
929 |
QTest::newRow("descending")
|
|
930 |
<< 4 << 5
|
|
931 |
<< static_cast<int>(Qt::DescendingOrder)
|
|
932 |
<< 0
|
|
933 |
<< (QStringList()
|
|
934 |
<< "0" << "a" << "o" << "8" << "k"
|
|
935 |
<< "3" << "d" << "k" << "o" << "6"
|
|
936 |
<< "2" << "c" << "9" << "y" << "8"
|
|
937 |
<< "1" << "b" << "7" << "3" << "u")
|
|
938 |
<< (QStringList()
|
|
939 |
<< "3" << "d" << "k" << "o" << "6"
|
|
940 |
<< "2" << "c" << "9" << "y" << "8"
|
|
941 |
<< "1" << "b" << "7" << "3" << "u"
|
|
942 |
<< "0" << "a" << "o" << "8" << "k")
|
|
943 |
<< (IntList() << 3 << 0 << 1 << 2)
|
|
944 |
<< IntList()
|
|
945 |
<< IntList();
|
|
946 |
|
|
947 |
QTest::newRow("empty table")
|
|
948 |
<< 4 << 5
|
|
949 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
950 |
<< 0
|
|
951 |
<< (QStringList()
|
|
952 |
<< 0 << 0 << 0 << 0 << 0
|
|
953 |
<< 0 << 0 << 0 << 0 << 0
|
|
954 |
<< 0 << 0 << 0 << 0 << 0
|
|
955 |
<< 0 << 0 << 0 << 0 << 0)
|
|
956 |
<< (QStringList()
|
|
957 |
<< 0 << 0 << 0 << 0 << 0
|
|
958 |
<< 0 << 0 << 0 << 0 << 0
|
|
959 |
<< 0 << 0 << 0 << 0 << 0
|
|
960 |
<< 0 << 0 << 0 << 0 << 0)
|
|
961 |
<< IntList()
|
|
962 |
<< IntList()
|
|
963 |
<< IntList();
|
|
964 |
|
|
965 |
|
|
966 |
QTest::newRow("half-empty table")
|
|
967 |
<< 4 << 5
|
|
968 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
969 |
<< 0
|
|
970 |
<< (QStringList()
|
|
971 |
<< "0" << 0 << 0 << 0 << 0
|
|
972 |
<< "3" << "d" << 0 << 0 << 0
|
|
973 |
<< "2" << "c" << 0 << 0 << 0
|
|
974 |
<< 0 << 0 << 0 << 0 << 0)
|
|
975 |
<< (QStringList()
|
|
976 |
<< "0" << 0 << 0 << 0 << 0
|
|
977 |
<< "2" << "c" << 0 << 0 << 0
|
|
978 |
<< "3" << "d" << 0 << 0 << 0
|
|
979 |
<< 0 << 0 << 0 << 0 << 0)
|
|
980 |
<< (IntList() << 0 << 2 << 1)
|
|
981 |
<< IntList()
|
|
982 |
<< IntList();
|
|
983 |
|
|
984 |
QTest::newRow("empty column, should not sort.")
|
|
985 |
<< 4 << 5
|
|
986 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
987 |
<< 3
|
|
988 |
<< (QStringList()
|
|
989 |
<< "0" << 0 << 0 << 0 << 0
|
|
990 |
<< "3" << "d" << 0 << 0 << 0
|
|
991 |
<< "2" << "c" << 0 << 0 << 0
|
|
992 |
<< 0 << 0 << 0 << 0 << 0)
|
|
993 |
<< (QStringList()
|
|
994 |
<< "0" << 0 << 0 << 0 << 0
|
|
995 |
<< "3" << "d" << 0 << 0 << 0
|
|
996 |
<< "2" << "c" << 0 << 0 << 0
|
|
997 |
<< 0 << 0 << 0 << 0 << 0)
|
|
998 |
<< IntList()
|
|
999 |
<< IntList()
|
|
1000 |
<< IntList();
|
|
1001 |
|
|
1002 |
QTest::newRow("descending with null cell, the null cell should be placed at the bottom")
|
|
1003 |
<< 4 << 5
|
|
1004 |
<< static_cast<int>(Qt::DescendingOrder)
|
|
1005 |
<< 0
|
|
1006 |
<< (QStringList()
|
|
1007 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1008 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1009 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1010 |
<< 0 << "b" << "7" << "3" << "u")
|
|
1011 |
<< (QStringList()
|
|
1012 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1013 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1014 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1015 |
<< 0 << "b" << "7" << "3" << "u")
|
|
1016 |
<< (IntList() << 2 << 0 << 1)
|
|
1017 |
<< IntList()
|
|
1018 |
<< IntList();
|
|
1019 |
|
|
1020 |
QTest::newRow("ascending with null cell, the null cell should be placed at the bottom")
|
|
1021 |
<< 4 << 5
|
|
1022 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
1023 |
<< 0
|
|
1024 |
<< (QStringList()
|
|
1025 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1026 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1027 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1028 |
<< 0 << "b" << "7" << "3" << "u")
|
|
1029 |
<< (QStringList()
|
|
1030 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1031 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1032 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1033 |
<< 0 << "b" << "7" << "3" << "u")
|
|
1034 |
<< (IntList() << 0 << 2 << 1)
|
|
1035 |
<< IntList()
|
|
1036 |
<< IntList();
|
|
1037 |
|
|
1038 |
QTest::newRow("ascending with null cells, the null cells should be placed at the bottom")
|
|
1039 |
<< 4 << 5
|
|
1040 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
1041 |
<< 0
|
|
1042 |
<< (QStringList()
|
|
1043 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1044 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1045 |
<< 0 << "c" << "9" << "y" << "8"
|
|
1046 |
<< 0 << "b" << "7" << "3" << "u")
|
|
1047 |
<< (QStringList()
|
|
1048 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1049 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1050 |
<< 0 << "c" << "9" << "y" << "8"
|
|
1051 |
<< 0 << "b" << "7" << "3" << "u")
|
|
1052 |
<< (IntList() << 1 << 0)
|
|
1053 |
<< IntList()
|
|
1054 |
<< IntList();
|
|
1055 |
|
|
1056 |
QTest::newRow("ascending... Check a bug in PersistentIndexes")
|
|
1057 |
<< 4 << 5
|
|
1058 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
1059 |
<< 0
|
|
1060 |
<< (QStringList()
|
|
1061 |
<< "3" << "c" << "9" << "y" << "8"
|
|
1062 |
<< "2" << "b" << "7" << "3" << "u"
|
|
1063 |
<< "4" << "d" << "k" << "o" << "6"
|
|
1064 |
<< "1" << "a" << "o" << "8" << "k"
|
|
1065 |
)
|
|
1066 |
<< (QStringList()
|
|
1067 |
<< "1" << "a" << "o" << "8" << "k"
|
|
1068 |
<< "2" << "b" << "7" << "3" << "u"
|
|
1069 |
<< "3" << "c" << "9" << "y" << "8"
|
|
1070 |
<< "4" << "d" << "k" << "o" << "6"
|
|
1071 |
)
|
|
1072 |
<< (IntList() << 2 << 1 << 3 << 0)
|
|
1073 |
<< IntList()
|
|
1074 |
<< IntList();
|
|
1075 |
|
|
1076 |
QTest::newRow("ascending with some null cells inbetween")
|
|
1077 |
<< 4 << 5
|
|
1078 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
1079 |
<< 0
|
|
1080 |
<< (QStringList()
|
|
1081 |
<< 0 << "a" << "o" << "8" << "k"
|
|
1082 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1083 |
<< 0 << "d" << "k" << "o" << "6"
|
|
1084 |
<< "1" << "b" << "7" << "3" << "u")
|
|
1085 |
<< (QStringList()
|
|
1086 |
<< "1" << "b" << "7" << "3" << "u"
|
|
1087 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1088 |
<< 0 << "a" << "o" << "8" << "k"
|
|
1089 |
<< 0 << "d" << "k" << "o" << "6")
|
|
1090 |
<< (IntList() << 1 << 0)
|
|
1091 |
<< IntList()
|
|
1092 |
<< IntList();
|
|
1093 |
|
|
1094 |
QTest::newRow("ascending hidden")
|
|
1095 |
<< 4 << 5
|
|
1096 |
<< static_cast<int>(Qt::AscendingOrder)
|
|
1097 |
<< 0
|
|
1098 |
<< (QStringList()
|
|
1099 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1100 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1101 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1102 |
<< "1" << "b" << "7" << "3" << "u")
|
|
1103 |
<< (QStringList()
|
|
1104 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1105 |
<< "1" << "b" << "7" << "3" << "u"
|
|
1106 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1107 |
<< "3" << "d" << "k" << "o" << "6")
|
|
1108 |
<< (IntList() << 0 << 3 << 2 << 1)
|
|
1109 |
<< (IntList() << 0 << 2)
|
|
1110 |
<< (IntList() << 0 << 2);
|
|
1111 |
|
|
1112 |
QTest::newRow("descending hidden")
|
|
1113 |
<< 4 << 5
|
|
1114 |
<< static_cast<int>(Qt::DescendingOrder)
|
|
1115 |
<< 0
|
|
1116 |
<< (QStringList()
|
|
1117 |
<< "0" << "a" << "o" << "8" << "k"
|
|
1118 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1119 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1120 |
<< "1" << "b" << "7" << "3" << "u")
|
|
1121 |
<< (QStringList()
|
|
1122 |
<< "3" << "d" << "k" << "o" << "6"
|
|
1123 |
<< "2" << "c" << "9" << "y" << "8"
|
|
1124 |
<< "1" << "b" << "7" << "3" << "u"
|
|
1125 |
<< "0" << "a" << "o" << "8" << "k")
|
|
1126 |
<< (IntList() << 3 << 0 << 1 << 2)
|
|
1127 |
<< (IntList() << 0 << 2)
|
|
1128 |
<< (IntList() << 3 << 1);
|
|
1129 |
}
|
|
1130 |
|
|
1131 |
void tst_QTableWidget::sortItems()
|
|
1132 |
{
|
|
1133 |
QFETCH(int, rowCount);
|
|
1134 |
QFETCH(int, columnCount);
|
|
1135 |
QFETCH(int, sortOrder);
|
|
1136 |
QFETCH(int, sortColumn);
|
|
1137 |
QFETCH(QStringList, initial);
|
|
1138 |
QFETCH(QStringList, expected);
|
|
1139 |
QFETCH(IntList, rows);
|
|
1140 |
QFETCH(IntList, initialHidden);
|
|
1141 |
QFETCH(IntList, expectedHidden);
|
|
1142 |
|
|
1143 |
testWidget->setRowCount(rowCount);
|
|
1144 |
testWidget->setColumnCount(columnCount);
|
|
1145 |
|
|
1146 |
QAbstractItemModel *model = testWidget->model();
|
|
1147 |
QList<QPersistentModelIndex> persistent;
|
|
1148 |
|
|
1149 |
int ti = 0;
|
|
1150 |
for (int r = 0; r < rowCount; ++r) {
|
|
1151 |
for (int c = 0; c < columnCount; ++c) {
|
|
1152 |
QString str = initial.at(ti++);
|
|
1153 |
if (!str.isNull()) {
|
|
1154 |
testWidget->setItem(r, c, new QTableWidgetItem(str));
|
|
1155 |
}
|
|
1156 |
}
|
|
1157 |
if (testWidget->item(r, sortColumn))
|
|
1158 |
persistent << model->index(r, sortColumn, QModelIndex());
|
|
1159 |
}
|
|
1160 |
|
|
1161 |
for (int h = 0; h < initialHidden.count(); ++h)
|
|
1162 |
testWidget->hideRow(initialHidden.at(h));
|
|
1163 |
|
|
1164 |
QCOMPARE(testWidget->verticalHeader()->hiddenSectionCount(), initialHidden.count());
|
|
1165 |
|
|
1166 |
testWidget->sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder));
|
|
1167 |
|
|
1168 |
int te = 0;
|
|
1169 |
for (int i = 0; i < rows.count(); ++i) {
|
|
1170 |
for (int j = 0; j < columnCount; ++j) {
|
|
1171 |
QString value;
|
|
1172 |
QTableWidgetItem *itm = testWidget->item(i, j);
|
|
1173 |
if (itm) {
|
|
1174 |
value = itm->text();
|
|
1175 |
}
|
|
1176 |
QCOMPARE(value, expected.at(te++));
|
|
1177 |
}
|
|
1178 |
QCOMPARE(persistent.at(i).row(), rows.at(i));
|
|
1179 |
//qDebug() << "persistent" << persistent.at(i).row()
|
|
1180 |
// << "expected" << rows.at(i);
|
|
1181 |
}
|
|
1182 |
|
|
1183 |
for (int k = 0; k < expectedHidden.count(); ++k)
|
|
1184 |
QVERIFY(testWidget->isRowHidden(expectedHidden.at(k)));
|
|
1185 |
}
|
|
1186 |
|
|
1187 |
void tst_QTableWidget::setItemWithSorting_data()
|
|
1188 |
{
|
|
1189 |
QTest::addColumn<int>("rowCount");
|
|
1190 |
QTest::addColumn<int>("columnCount");
|
|
1191 |
QTest::addColumn<int>("sortOrder");
|
|
1192 |
QTest::addColumn<int>("sortColumn");
|
|
1193 |
QTest::addColumn<QStringList>("initialValues");
|
|
1194 |
QTest::addColumn<int>("row");
|
|
1195 |
QTest::addColumn<int>("column");
|
|
1196 |
QTest::addColumn<QString>("newValue");
|
|
1197 |
QTest::addColumn<QStringList>("expectedValues");
|
|
1198 |
QTest::addColumn<IntList>("expectedRows");
|
|
1199 |
QTest::addColumn<bool>("reorderingExpected");
|
|
1200 |
|
|
1201 |
QTest::newRow("2x1 no change (ascending)")
|
|
1202 |
<< 2 << 1
|
|
1203 |
<< static_cast<int>(Qt::AscendingOrder) << 0
|
|
1204 |
<< (QStringList() << "0" << "1")
|
|
1205 |
<< 1 << 0 << "2"
|
|
1206 |
<< (QStringList() << "0" << "2")
|
|
1207 |
<< (IntList() << 0 << 1)
|
|
1208 |
<< false;
|
|
1209 |
QTest::newRow("2x1 no change (descending)")
|
|
1210 |
<< 2 << 1
|
|
1211 |
<< static_cast<int>(Qt::DescendingOrder) << 0
|
|
1212 |
<< (QStringList() << "1" << "0")
|
|
1213 |
<< 0 << 0 << "2"
|
|
1214 |
<< (QStringList() << "2" << "0")
|
|
1215 |
<< (IntList() << 0 << 1)
|
|
1216 |
<< false;
|
|
1217 |
QTest::newRow("2x1 reorder (ascending)")
|
|
1218 |
<< 2 << 1
|
|
1219 |
<< static_cast<int>(Qt::AscendingOrder) << 0
|
|
1220 |
<< (QStringList() << "0" << "1")
|
|
1221 |
<< 0 << 0 << "2"
|
|
1222 |
<< (QStringList() << "1" << "2")
|
|
1223 |
<< (IntList() << 1 << 0)
|
|
1224 |
<< true;
|
|
1225 |
QTest::newRow("2x1 reorder (descending)")
|
|
1226 |
<< 2 << 1
|
|
1227 |
<< static_cast<int>(Qt::DescendingOrder) << 0
|
|
1228 |
<< (QStringList() << "1" << "0")
|
|
1229 |
<< 1 << 0 << "2"
|
|
1230 |
<< (QStringList() << "2" << "1")
|
|
1231 |
<< (IntList() << 1 << 0)
|
|
1232 |
<< true;
|
|
1233 |
QTest::newRow("2x2 no change (ascending)")
|
|
1234 |
<< 2 << 2
|
|
1235 |
<< static_cast<int>(Qt::AscendingOrder) << 0
|
|
1236 |
<< (QStringList()
|
|
1237 |
<< "0" << "00"
|
|
1238 |
<< "1" << "11")
|
|
1239 |
<< 1 << 0 << "2"
|
|
1240 |
<< (QStringList()
|
|
1241 |
<< "0" << "00"
|
|
1242 |
<< "2" << "11")
|
|
1243 |
<< (IntList() << 0 << 1)
|
|
1244 |
<< false;
|
|
1245 |
QTest::newRow("2x2 reorder (ascending)")
|
|
1246 |
<< 2 << 2
|
|
1247 |
<< static_cast<int>(Qt::AscendingOrder) << 0
|
|
1248 |
<< (QStringList()
|
|
1249 |
<< "0" << "00"
|
|
1250 |
<< "1" << "11")
|
|
1251 |
<< 0 << 0 << "2"
|
|
1252 |
<< (QStringList()
|
|
1253 |
<< "1" << "11"
|
|
1254 |
<< "2" << "00")
|
|
1255 |
<< (IntList() << 1 << 0)
|
|
1256 |
<< true;
|
|
1257 |
QTest::newRow("2x2 reorder (ascending, sortColumn = 1)")
|
|
1258 |
<< 2 << 2
|
|
1259 |
<< static_cast<int>(Qt::AscendingOrder) << 1
|
|
1260 |
<< (QStringList()
|
|
1261 |
<< "00" << "0"
|
|
1262 |
<< "11" << "1")
|
|
1263 |
<< 0 << 1 << "2"
|
|
1264 |
<< (QStringList()
|
|
1265 |
<< "11" << "1"
|
|
1266 |
<< "00" << "2")
|
|
1267 |
<< (IntList() << 1 << 0)
|
|
1268 |
<< true;
|
|
1269 |
QTest::newRow("2x2 no change (column != sortColumn)")
|
|
1270 |
<< 2 << 2
|
|
1271 |
<< static_cast<int>(Qt::AscendingOrder) << 1
|
|
1272 |
<< (QStringList()
|
|
1273 |
<< "00" << "0"
|
|
1274 |
<< "11" << "1")
|
|
1275 |
<< 0 << 0 << "22"
|
|
1276 |
<< (QStringList()
|
|
1277 |
<< "22" << "0"
|
|
1278 |
<< "11" << "1")
|
|
1279 |
<< (IntList() << 0 << 1)
|
|
1280 |
<< false;
|
|
1281 |
QTest::newRow("8x4 reorder (ascending, sortColumn = 3)")
|
|
1282 |
<< 8 << 4
|
|
1283 |
<< static_cast<int>(Qt::AscendingOrder) << 3
|
|
1284 |
<< (QStringList()
|
|
1285 |
<< "q" << "v" << "u" << "0"
|
|
1286 |
<< "e" << "j" << "i" << "10"
|
|
1287 |
<< "h" << "d" << "c" << "12"
|
|
1288 |
<< "k" << "g" << "f" << "14"
|
|
1289 |
<< "w" << "y" << "x" << "2"
|
|
1290 |
<< "t" << "s" << "o" << "4"
|
|
1291 |
<< "z" << "p" << "r" << "6"
|
|
1292 |
<< "n" << "m" << "l" << "8")
|
|
1293 |
<< 2 << 3 << "5"
|
|
1294 |
<< (QStringList()
|
|
1295 |
<< "q" << "v" << "u" << "0"
|
|
1296 |
<< "e" << "j" << "i" << "10"
|
|
1297 |
<< "k" << "g" << "f" << "14"
|
|
1298 |
<< "w" << "y" << "x" << "2"
|
|
1299 |
<< "t" << "s" << "o" << "4"
|
|
1300 |
<< "h" << "d" << "c" << "5"
|
|
1301 |
<< "z" << "p" << "r" << "6"
|
|
1302 |
<< "n" << "m" << "l" << "8")
|
|
1303 |
<< (IntList() << 0 << 1 << 5 << 2 << 3 << 4 << 6 << 7)
|
|
1304 |
<< true;
|
|
1305 |
}
|
|
1306 |
|
|
1307 |
void tst_QTableWidget::setItemWithSorting()
|
|
1308 |
{
|
|
1309 |
QFETCH(int, rowCount);
|
|
1310 |
QFETCH(int, columnCount);
|
|
1311 |
QFETCH(int, sortOrder);
|
|
1312 |
QFETCH(int, sortColumn);
|
|
1313 |
QFETCH(QStringList, initialValues);
|
|
1314 |
QFETCH(int, row);
|
|
1315 |
QFETCH(int, column);
|
|
1316 |
QFETCH(QString, newValue);
|
|
1317 |
QFETCH(QStringList, expectedValues);
|
|
1318 |
QFETCH(IntList, expectedRows);
|
|
1319 |
QFETCH(bool, reorderingExpected);
|
|
1320 |
|
|
1321 |
for (int i = 0; i < 2; ++i) {
|
|
1322 |
QTableWidget w(rowCount, columnCount);
|
|
1323 |
|
|
1324 |
QAbstractItemModel *model = w.model();
|
|
1325 |
QList<QPersistentModelIndex> persistent;
|
|
1326 |
|
|
1327 |
int ti = 0;
|
|
1328 |
for (int r = 0; r < rowCount; ++r) {
|
|
1329 |
for (int c = 0; c < columnCount; ++c) {
|
|
1330 |
QString str = initialValues.at(ti++);
|
|
1331 |
w.setItem(r, c, new QTableWidgetItem(str));
|
|
1332 |
}
|
|
1333 |
persistent << model->index(r, sortColumn);
|
|
1334 |
}
|
|
1335 |
|
|
1336 |
w.sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder));
|
|
1337 |
w.setSortingEnabled(true);
|
|
1338 |
|
|
1339 |
QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)));
|
|
1340 |
QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged()));
|
|
1341 |
|
|
1342 |
if (i == 0) {
|
|
1343 |
// set a new item
|
|
1344 |
QTableWidgetItem *item = new QTableWidgetItem(newValue);
|
|
1345 |
w.setItem(row, column, item);
|
|
1346 |
} else {
|
|
1347 |
// change the data of existing item
|
|
1348 |
QTableWidgetItem *item = w.item(row, column);
|
|
1349 |
item->setText(newValue);
|
|
1350 |
}
|
|
1351 |
|
|
1352 |
ti = 0;
|
|
1353 |
for (int r = 0; r < rowCount; ++r) {
|
|
1354 |
for (int c = 0; c < columnCount; ++c) {
|
|
1355 |
QString str = expectedValues.at(ti++);
|
|
1356 |
QCOMPARE(w.item(r, c)->text(), str);
|
|
1357 |
}
|
|
1358 |
}
|
|
1359 |
|
|
1360 |
for (int k = 0; k < persistent.count(); ++k) {
|
|
1361 |
QCOMPARE(persistent.at(k).row(), expectedRows.at(k));
|
|
1362 |
int i = (persistent.at(k).row() * columnCount) + sortColumn;
|
|
1363 |
QCOMPARE(persistent.at(k).data().toString(), expectedValues.at(i));
|
|
1364 |
}
|
|
1365 |
|
|
1366 |
if (i == 0)
|
|
1367 |
QCOMPARE(dataChangedSpy.count(), reorderingExpected ? 0 : 1);
|
|
1368 |
else
|
|
1369 |
QCOMPARE(dataChangedSpy.count(), 1);
|
|
1370 |
|
|
1371 |
QCOMPARE(layoutChangedSpy.count(), reorderingExpected ? 1 : 0);
|
|
1372 |
}
|
|
1373 |
}
|
|
1374 |
|
|
1375 |
void tst_QTableWidget::itemData()
|
|
1376 |
{
|
|
1377 |
QTableWidget widget(2, 2);
|
|
1378 |
widget.setItem(0, 0, new QTableWidgetItem());
|
|
1379 |
QTableWidgetItem *item = widget.item(0, 0);
|
|
1380 |
QVERIFY(item);
|
|
1381 |
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
|
1382 |
item->setData(Qt::DisplayRole, QString("0"));
|
|
1383 |
item->setData(Qt::CheckStateRole, Qt::PartiallyChecked);
|
|
1384 |
item->setData(Qt::UserRole + 0, QString("1"));
|
|
1385 |
item->setData(Qt::UserRole + 1, QString("2"));
|
|
1386 |
item->setData(Qt::UserRole + 2, QString("3"));
|
|
1387 |
item->setData(Qt::UserRole + 3, QString("4"));
|
|
1388 |
QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0));
|
|
1389 |
QCOMPARE(flags.count(), 6);
|
|
1390 |
QCOMPARE(flags[(Qt::UserRole + 0)].toString(), QString("1"));
|
|
1391 |
}
|
|
1392 |
|
|
1393 |
void tst_QTableWidget::setItemData()
|
|
1394 |
{
|
|
1395 |
QTableWidget table(10, 10);
|
|
1396 |
table.setSortingEnabled(false);
|
|
1397 |
QSignalSpy dataChangedSpy(table.model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)));
|
|
1398 |
|
|
1399 |
QTableWidgetItem *item = new QTableWidgetItem;
|
|
1400 |
table.setItem(0, 0, item);
|
|
1401 |
QCOMPARE(dataChangedSpy.count(), 1);
|
|
1402 |
QModelIndex idx = qvariant_cast<QModelIndex>(dataChangedSpy.takeFirst().at(0));
|
|
1403 |
|
|
1404 |
QMap<int, QVariant> data;
|
|
1405 |
data.insert(Qt::DisplayRole, QLatin1String("Display"));
|
|
1406 |
data.insert(Qt::ToolTipRole, QLatin1String("ToolTip"));
|
|
1407 |
table.model()->setItemData(idx, data);
|
|
1408 |
|
|
1409 |
QCOMPARE(table.model()->data(idx, Qt::DisplayRole).toString(), QLatin1String("Display"));
|
|
1410 |
QCOMPARE(table.model()->data(idx, Qt::ToolTipRole).toString(), QLatin1String("ToolTip"));
|
|
1411 |
QCOMPARE(dataChangedSpy.count(), 1);
|
|
1412 |
QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.takeFirst().at(0)));
|
|
1413 |
|
|
1414 |
table.model()->setItemData(idx, data);
|
|
1415 |
QCOMPARE(dataChangedSpy.count(), 0);
|
|
1416 |
|
|
1417 |
data.clear();
|
|
1418 |
data.insert(Qt::DisplayRole, QLatin1String("dizplaye"));
|
|
1419 |
table.model()->setItemData(idx, data);
|
|
1420 |
QCOMPARE(table.model()->data(idx, Qt::DisplayRole).toString(), QLatin1String("dizplaye"));
|
|
1421 |
QCOMPARE(dataChangedSpy.count(), 1);
|
|
1422 |
}
|
|
1423 |
|
|
1424 |
void tst_QTableWidget::cellWidget()
|
|
1425 |
{
|
|
1426 |
QTableWidget table(10, 10);
|
|
1427 |
QWidget widget;
|
|
1428 |
|
|
1429 |
QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
|
|
1430 |
table.setCellWidget(5, 5, &widget);
|
|
1431 |
QCOMPARE(table.cellWidget(5, 5), &widget);
|
|
1432 |
table.removeCellWidget(5, 5);
|
|
1433 |
QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
|
|
1434 |
}
|
|
1435 |
|
|
1436 |
void tst_QTableWidget::task231094()
|
|
1437 |
{
|
|
1438 |
QTableWidget tw(5, 3);
|
|
1439 |
for (int x = 0; x < 3; x++) {
|
|
1440 |
for (int y = 0; y < 5; y++) {
|
|
1441 |
QTableWidgetItem *twi = new QTableWidgetItem(QLatin1String("1"));
|
|
1442 |
if (y == 1)
|
|
1443 |
twi->setFlags(Qt::ItemIsEnabled);
|
|
1444 |
else
|
|
1445 |
twi->setFlags(0);
|
|
1446 |
tw.setItem(y, x, twi);
|
|
1447 |
}
|
|
1448 |
}
|
|
1449 |
|
|
1450 |
tw.setCurrentCell(1, 1);
|
|
1451 |
QCOMPARE(tw.currentRow(), 1);
|
|
1452 |
QCOMPARE(tw.currentColumn(), 1);
|
|
1453 |
|
|
1454 |
//this would provoke a end-less loop
|
|
1455 |
QTest::keyClick(&tw, '1');
|
|
1456 |
|
|
1457 |
//all the items are disabled: the current item shouldn't have changed
|
|
1458 |
QCOMPARE(tw.currentRow(), 1);
|
|
1459 |
QCOMPARE(tw.currentColumn(), 1);
|
|
1460 |
}
|
|
1461 |
|
|
1462 |
void tst_QTableWidget::task219380_removeLastRow()
|
|
1463 |
{
|
|
1464 |
testWidget->setColumnCount(1);
|
|
1465 |
testWidget->setRowCount(20);
|
|
1466 |
QTableWidgetItem item;
|
|
1467 |
testWidget->setItem(18, 0, &item); //we put the item in the the second last row
|
|
1468 |
testWidget->openPersistentEditor(&item);
|
|
1469 |
|
|
1470 |
testWidget->scrollToBottom();
|
|
1471 |
|
|
1472 |
testWidget->removeRow(19); //we remove the last row
|
|
1473 |
|
|
1474 |
//we make sure the editor is at the cell position
|
|
1475 |
QCOMPARE(testWidget->cellWidget(18, 0)->geometry(), testWidget->visualItemRect(&item));
|
|
1476 |
}
|
|
1477 |
|
|
1478 |
void tst_QTableWidget::task262056_sortDuplicate()
|
|
1479 |
{
|
|
1480 |
testWidget->setColumnCount(2);
|
|
1481 |
testWidget->setRowCount(8);
|
|
1482 |
testWidget->setSortingEnabled(true);
|
|
1483 |
QStringList items = (QStringList() << "AAA" << "BBB" << "CCC" << "CCC" << "DDD"\
|
|
1484 |
<< "EEE" << "FFF" << "GGG");
|
|
1485 |
for (int i = 0; i<8; i++ ) {
|
|
1486 |
QTableWidgetItem *twi = new QTableWidgetItem(items.at(i));
|
|
1487 |
testWidget->setItem(i,0,twi);
|
|
1488 |
testWidget->setItem(i,1,new QTableWidgetItem(QString("item %1").arg(i)));
|
|
1489 |
}
|
|
1490 |
testWidget->sortItems(0, Qt::AscendingOrder);
|
|
1491 |
QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged()));
|
|
1492 |
testWidget->item(3,0)->setBackgroundColor(Qt::red);
|
|
1493 |
|
|
1494 |
QCOMPARE(layoutChangedSpy.count(),0);
|
|
1495 |
|
|
1496 |
}
|
|
1497 |
|
|
1498 |
|
|
1499 |
QTEST_MAIN(tst_QTableWidget)
|
|
1500 |
#include "tst_qtablewidget.moc"
|