Debian Codegraph @

tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
5 #include <QTest>
6 #include <QSignalSpy>
7
8 #include <QStandardItem>
9
10 class tst_QStandardItem : public QObject
11 {
12 Q_OBJECT
13
14 private slots:
15 void ctor();
16 void textCtor();
17 void iconTextCtor();
18 void rowsColumnsCtor();
19 void getSetData();
20 void getSetFlags();
21 void getSetRowAndColumnCount();
22 void getSetChild_data();
23 void getSetChild();
24 void parent();
25 void insertColumn_data();
26 void insertColumn();
27 void insertRow_data();
28 void insertRow();
29 void insertRows_data();
30 void insertRows();
31 void appendColumn_data();
32 void appendColumn();
33 void appendRow_data();
34 void appendRow();
35 void takeChild();
36 void takeColumn_data();
37 void takeColumn();
38 void takeRow_data();
39 void takeRow();
40 void streamItem();
41 void deleteItem();
42 void clone();
43 void sortChildren();
44 void subclassing();
45 void lessThan();
46 void clearData();
47 };
48
49 void tst_QStandardItem::clearData()
50 {
51 QStandardItem item;
52 item.setData(QStringLiteral("Test"), Qt::EditRole);
53 item.setData(5, Qt::UserRole);
54 item.clearData();
55 QCOMPARE(item.data(Qt::EditRole), QVariant());
56 QCOMPARE(item.data(Qt::UserRole), QVariant());
57 QCOMPARE(item.data(Qt::DisplayRole), QVariant());
58 }
59
60 void tst_QStandardItem::ctor()
61 {
62 QStandardItem item;
63 QVERIFY(!item.hasChildren());
64 }
65
66 void tst_QStandardItem::textCtor()
67 {
68 QLatin1String text("text");
69 QStandardItem item(text);
70 QCOMPARE(item.text(), text);
71 QVERIFY(!item.hasChildren());
72 }
73
74 void tst_QStandardItem::iconTextCtor()
75 {
76 QPixmap pixmap(32, 32);
77 pixmap.fill(Qt::red);
78 QIcon icon(pixmap);
79 QLatin1String text("text");
80 QStandardItem item(icon, text);
81 QCOMPARE(item.icon(), icon);
82 QCOMPARE(item.text(), text);
83 QVERIFY(!item.hasChildren());
84 }
85
86 void tst_QStandardItem::rowsColumnsCtor()
87 {
88 const int rows = 5;
89 const int columns = 12;
90 QStandardItem item(rows, columns);
91 QCOMPARE(item.rowCount(), rows);
92 QCOMPARE(item.columnCount(), columns);
93 }
94
95 void tst_QStandardItem::getSetData()
96 {
97 QStandardItem item;
98 for (int x = 0; x < 2; ++x) {
99 for (int i = 1; i <= 2; ++i) {
100 const QString iS = QString::number(i);
101 QString text = QLatin1String("text ") + iS;
102 item.setText(text);
103 QCOMPARE(item.text(), text);
104
105 QPixmap pixmap(32, 32);
106 pixmap.fill((i == 1) ? Qt::red : Qt::green);
107 QIcon icon(pixmap);
108 item.setIcon(icon);
109 QCOMPARE(item.icon(), icon);
110
111 QString toolTip = QLatin1String("toolTip ") + iS;
112 item.setToolTip(toolTip);
113 QCOMPARE(item.toolTip(), toolTip);
114
115 #ifndef QT_NO_STATUSTIP
116 QString statusTip = QLatin1String("statusTip ") + iS;
117 item.setStatusTip(statusTip);
118 QCOMPARE(item.statusTip(), statusTip);
119 #endif
120
121 #if QT_CONFIG(whatsthis)
122 QString whatsThis = QLatin1String("whatsThis ") + iS;
123 item.setWhatsThis(whatsThis);
124 QCOMPARE(item.whatsThis(), whatsThis);
125 #endif
126
127 QSize sizeHint(64*i, 48*i);
128 item.setSizeHint(sizeHint);
129 QCOMPARE(item.sizeHint(), sizeHint);
130
131 QFont font;
132 item.setFont(font);
133 QCOMPARE(item.font(), font);
134
135 Qt::Alignment textAlignment((i == 1)
136 ? Qt::AlignLeft|Qt::AlignVCenter
137 : Qt::AlignRight);
138 item.setTextAlignment(textAlignment);
139 QCOMPARE(item.textAlignment(), textAlignment);
140
141 QColor backgroundColor((i == 1) ? Qt::blue : Qt::yellow);
142 item.setBackground(backgroundColor);
143 QCOMPARE(item.background().color(), backgroundColor);
144
145 QColor textColor((i == 1) ? Qt::green : Qt::cyan);
146 item.setForeground(textColor);
147 QCOMPARE(item.foreground().color(), textColor);
148
149 Qt::CheckState checkState((i == 1) ? Qt::PartiallyChecked : Qt::Checked);
150 item.setCheckState(checkState);
151 QCOMPARE(item.checkState(), checkState);
152
153 QString accessibleText = QLatin1String("accessibleText ") + iS;
154 item.setAccessibleText(accessibleText);
155 QCOMPARE(item.accessibleText(), accessibleText);
156
157 QString accessibleDescription = QLatin1String("accessibleDescription ") + iS;
158 item.setAccessibleDescription(accessibleDescription);
159 QCOMPARE(item.accessibleDescription(), accessibleDescription);
160
161 QCOMPARE(item.text(), text);
162 QCOMPARE(item.icon(), icon);
163 QCOMPARE(item.toolTip(), toolTip);
164 #ifndef QT_NO_STATUSTIP
165 QCOMPARE(item.statusTip(), statusTip);
166 #endif
167 #if QT_CONFIG(whatsthis)
168 QCOMPARE(item.whatsThis(), whatsThis);
169 #endif
170 QCOMPARE(item.sizeHint(), sizeHint);
171 QCOMPARE(item.font(), font);
172 QCOMPARE(item.textAlignment(), textAlignment);
173 QCOMPARE(item.background().color(), backgroundColor);
174 QCOMPARE(item.foreground().color(), textColor);
175 QCOMPARE(item.checkState(), checkState);
176 QCOMPARE(item.accessibleText(), accessibleText);
177 QCOMPARE(item.accessibleDescription(), accessibleDescription);
178
179 QCOMPARE(qvariant_cast<QString>(item.data(Qt::DisplayRole)), text);
180 QCOMPARE(qvariant_cast<QIcon>(item.data(Qt::DecorationRole)), icon);
181 QCOMPARE(qvariant_cast<QString>(item.data(Qt::ToolTipRole)), toolTip);
182 #ifndef QT_NO_STATUSTIP
183 QCOMPARE(qvariant_cast<QString>(item.data(Qt::StatusTipRole)), statusTip);
184 #endif
185 #if QT_CONFIG(whatsthis)
186 QCOMPARE(qvariant_cast<QString>(item.data(Qt::WhatsThisRole)), whatsThis);
187 #endif
188 QCOMPARE(qvariant_cast<QSize>(item.data(Qt::SizeHintRole)), sizeHint);
189 QCOMPARE(qvariant_cast<QFont>(item.data(Qt::FontRole)), font);
190 QCOMPARE(qvariant_cast<int>(item.data(Qt::TextAlignmentRole)), int(textAlignment));
191 QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)), QBrush(backgroundColor));
192 QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::ForegroundRole)), QBrush(textColor));
193 QCOMPARE(qvariant_cast<int>(item.data(Qt::CheckStateRole)), int(checkState));
194 QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleTextRole)), accessibleText);
195 QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleDescriptionRole)), accessibleDescription);
196
197 item.setBackground(pixmap);
198 QCOMPARE(item.background().texture(), pixmap);
199 QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)).texture(), pixmap);
200 }
201 item.setData(QVariant(), Qt::DisplayRole);
202 item.setData(QVariant(), Qt::DecorationRole);
203 item.setData(QVariant(), Qt::ToolTipRole);
204 item.setData(QVariant(), Qt::StatusTipRole);
205 item.setData(QVariant(), Qt::WhatsThisRole);
206 item.setData(QVariant(), Qt::SizeHintRole);
207 item.setData(QVariant(), Qt::FontRole);
208 item.setData(QVariant(), Qt::TextAlignmentRole);
209 item.setData(QVariant(), Qt::BackgroundRole);
210 item.setData(QVariant(), Qt::ForegroundRole);
211 item.setData(QVariant(), Qt::CheckStateRole);
212 item.setData(QVariant(), Qt::AccessibleTextRole);
213 item.setData(QVariant(), Qt::AccessibleDescriptionRole);
214
215 QCOMPARE(item.data(Qt::DisplayRole), QVariant());
216 QCOMPARE(item.data(Qt::DecorationRole), QVariant());
217 QCOMPARE(item.data(Qt::ToolTipRole), QVariant());
218 QCOMPARE(item.data(Qt::StatusTipRole), QVariant());
219 QCOMPARE(item.data(Qt::WhatsThisRole), QVariant());
220 QCOMPARE(item.data(Qt::SizeHintRole), QVariant());
221 QCOMPARE(item.data(Qt::FontRole), QVariant());
222 QCOMPARE(item.data(Qt::TextAlignmentRole), QVariant());
223 QCOMPARE(item.data(Qt::BackgroundRole), QVariant());
224 QCOMPARE(item.data(Qt::ForegroundRole), QVariant());
225 QCOMPARE(item.data(Qt::CheckStateRole), QVariant());
226 QCOMPARE(item.data(Qt::AccessibleTextRole), QVariant());
227 QCOMPARE(item.data(Qt::AccessibleDescriptionRole), QVariant());
228 }
229 }
230
231 void tst_QStandardItem::getSetFlags()
232 {
233 QStandardItem item;
234 item.setEnabled(true);
235 QVERIFY(item.isEnabled());
236 QVERIFY(item.flags() & Qt::ItemIsEnabled);
237 item.setEditable(true);
238 QVERIFY(item.isEditable());
239 QVERIFY(item.flags() & Qt::ItemIsEditable);
240 item.setSelectable(true);
241 QVERIFY(item.isSelectable());
242 QVERIFY(item.flags() & Qt::ItemIsSelectable);
243 item.setCheckable(true);
244 QVERIFY(item.isCheckable());
245 QCOMPARE(item.checkState(), Qt::Unchecked);
246 QVERIFY(item.flags() & Qt::ItemIsUserCheckable);
247 item.setUserTristate(true);
248 QVERIFY(item.isUserTristate());
249 QVERIFY(item.flags() & Qt::ItemIsUserTristate);
250 item.setAutoTristate(true);
251 QVERIFY(item.isAutoTristate());
252 QVERIFY(item.flags() & Qt::ItemIsAutoTristate);
253 #if QT_CONFIG(draganddrop)
254 item.setDragEnabled(true);
255 QVERIFY(item.isDragEnabled());
256 QVERIFY(item.flags() & Qt::ItemIsDragEnabled);
257 item.setDropEnabled(true);
258 QVERIFY(item.isDropEnabled());
259 QVERIFY(item.flags() & Qt::ItemIsDropEnabled);
260 #endif
261
262 QVERIFY(item.isEnabled());
263 item.setEnabled(false);
264 QVERIFY(!item.isEnabled());
265 QVERIFY(!(item.flags() & Qt::ItemIsEnabled));
266 QVERIFY(item.isEditable());
267 item.setEditable(false);
268 QVERIFY(!item.isEditable());
269 QVERIFY(!(item.flags() & Qt::ItemIsEditable));
270 QVERIFY(item.isSelectable());
271 item.setSelectable(false);
272 QVERIFY(!item.isSelectable());
273 QVERIFY(!(item.flags() & Qt::ItemIsSelectable));
274 QVERIFY(item.isCheckable());
275 item.setCheckable(false);
276 QVERIFY(!item.isCheckable());
277 QVERIFY(!(item.flags() & Qt::ItemIsUserCheckable));
278 item.setUserTristate(false);
279 QVERIFY(!item.isUserTristate());
280 QVERIFY(!(item.flags() & Qt::ItemIsUserTristate));
281 item.setAutoTristate(false);
282 QVERIFY(!item.isAutoTristate());
283 QVERIFY(!(item.flags() & Qt::ItemIsAutoTristate));
284 #if QT_CONFIG(draganddrop)
285 QVERIFY(item.isDragEnabled());
286 item.setDragEnabled(false);
287 QVERIFY(!item.isDragEnabled());
288 QVERIFY(!(item.flags() & Qt::ItemIsDragEnabled));
289 QVERIFY(item.isDropEnabled());
290 item.setDropEnabled(false);
291 QVERIFY(!item.isDropEnabled());
292 QVERIFY(!(item.flags() & Qt::ItemIsDropEnabled));
293 #endif
294
295 item.setCheckable(false);
296 item.setCheckState(Qt::Checked);
297 item.setCheckable(true);
298 QCOMPARE(item.checkState(), Qt::Checked);
299 }
300
301 void tst_QStandardItem::getSetRowAndColumnCount()
302 {
303 QStandardItem item;
304
305 item.setRowCount(-1);
306 QCOMPARE(item.rowCount(), 0);
307
308 item.setColumnCount(-1);
309 QCOMPARE(item.columnCount(), 0);
310
311 item.setRowCount(1);
312 QCOMPARE(item.rowCount(), 1);
313 QCOMPARE(item.columnCount(), 0);
314
315 item.setColumnCount(1);
316 QCOMPARE(item.columnCount(), 1);
317 QCOMPARE(item.rowCount(), 1);
318
319 item.setColumnCount(10);
320 QCOMPARE(item.columnCount(), 10);
321 QCOMPARE(item.rowCount(), 1);
322
323 item.setRowCount(20);
324 QCOMPARE(item.rowCount(), 20);
325 QCOMPARE(item.columnCount(), 10);
326
327 item.setRowCount(-1);
328 QCOMPARE(item.rowCount(), 20);
329
330 item.setColumnCount(-1);
331 QCOMPARE(item.columnCount(), 10);
332
333 item.setColumnCount(0);
334 QCOMPARE(item.columnCount(), 0);
335 QCOMPARE(item.rowCount(), 20);
336
337 item.setRowCount(0);
338 QCOMPARE(item.rowCount(), 0);
339 }
340
341 void tst_QStandardItem::getSetChild_data()
342 {
343 QTest::addColumn<int>("rows");
344 QTest::addColumn<int>("columns");
345 QTest::addColumn<int>("row");
346 QTest::addColumn<int>("column");
347
348 QTest::newRow("0x0 children, child at (-1,-1)") << 0 << 0 << -1 << -1;
349 QTest::newRow("0x0 children, child at (0,0)") << 0 << 0 << 0 << 0;
350 }
351
352 void tst_QStandardItem::getSetChild()
353 {
354 QFETCH(int, rows);
355 QFETCH(int, columns);
356 QFETCH(int, row);
357 QFETCH(int, column);
358
359 QStandardItem item(rows, columns);
360 bool shouldHaveChildren = (rows > 0) && (columns > 0);
361 QCOMPARE(item.hasChildren(), shouldHaveChildren);
362 QCOMPARE(item.child(row, column), nullptr);
363
364 QStandardItem *child = new QStandardItem;
365 item.setChild(row, column, child);
366 if ((row >= 0) && (column >= 0)) {
367 QCOMPARE(item.rowCount(), qMax(rows, row + 1));
368 QCOMPARE(item.columnCount(), qMax(columns, column + 1));
369
370 QCOMPARE(item.child(row, column), child);
371 QCOMPARE(child->row(), row);
372 QCOMPARE(child->column(), column);
373
374 QStandardItem *anotherChild = new QStandardItem;
375 item.setChild(row, column, anotherChild);
376 QCOMPARE(item.child(row, column), anotherChild);
377 QCOMPARE(anotherChild->row(), row);
378 QCOMPARE(anotherChild->column(), column);
379 item.setChild(row, column, nullptr);
380 } else {
381 delete child;
382 }
383 QCOMPARE(item.child(row, column), nullptr);
384 }
385
386 void tst_QStandardItem::parent()
387 {
388 {
389 QStandardItem item;
390 QStandardItem *child = new QStandardItem;
391 QCOMPARE(child->parent(), nullptr);
392 item.setChild(0, 0, child);
393 QCOMPARE(child->parent(), &item);
394
395 QStandardItem *childOfChild = new QStandardItem;
396 child->setChild(0, 0, childOfChild);
397 QCOMPARE(childOfChild->parent(), child);
398 }
399
400 {
401 QStandardItemModel model;
402 QStandardItem *item = new QStandardItem;
403 model.appendRow(item);
404 // parent of a top-level item should be 0
405 QCOMPARE(item->parent(), nullptr);
406 }
407 }
408
409 void tst_QStandardItem::insertColumn_data()
410 {
411 QTest::addColumn<int>("rows");
412 QTest::addColumn<int>("columns");
413 QTest::addColumn<int>("column");
414 QTest::addColumn<int>("count");
415
416 QTest::newRow("insert 0 at -1 in 0x0") << 0 << 0 << -1 << 0;
417 QTest::newRow("insert 0 at 0 in 0x0") << 0 << 0 << 0 << 0;
418 QTest::newRow("insert 0 at 0 in 1x0") << 1 << 0 << 0 << 0;
419 QTest::newRow("insert 0 at 0 in 0x1") << 0 << 1 << 0 << 0;
420 QTest::newRow("insert 0 at 0 in 1x1") << 1 << 1 << 0 << 0;
421 QTest::newRow("insert 1 at -1 in 0x0") << 0 << 0 << -1 << 1;
422 QTest::newRow("insert 1 at 0 in 0x0") << 0 << 0 << 0 << 1;
423 QTest::newRow("insert 1 at 0 in 1x0") << 1 << 0 << 0 << 1;
424 QTest::newRow("insert 1 at 0 in 0x1") << 0 << 1 << 0 << 1;
425 QTest::newRow("insert 1 at 0 in 1x1") << 1 << 1 << 0 << 1;
426 QTest::newRow("insert 1 at 1 in 1x1") << 1 << 1 << 1 << 1;
427 QTest::newRow("insert 1 at 0 in 2x1") << 2 << 1 << 0 << 1;
428 QTest::newRow("insert 1 at 1 in 2x1") << 2 << 1 << 1 << 1;
429 QTest::newRow("insert 1 at 0 in 1x2") << 1 << 2 << 0 << 1;
430 QTest::newRow("insert 1 at 1 in 1x2") << 1 << 2 << 1 << 1;
431 QTest::newRow("insert 1 at 0 in 8x4") << 8 << 4 << 0 << 1;
432 QTest::newRow("insert 1 at 1 in 8x4") << 8 << 4 << 1 << 1;
433 QTest::newRow("insert 1 at 2 in 8x4") << 8 << 4 << 2 << 1;
434 QTest::newRow("insert 1 at 3 in 8x4") << 8 << 4 << 3 << 1;
435 QTest::newRow("insert 1 at 4 in 8x4") << 8 << 4 << 4 << 1;
436 QTest::newRow("insert 4 at 0 in 8x4") << 8 << 4 << 0 << 4;
437 QTest::newRow("insert 4 at 4 in 8x4") << 8 << 4 << 4 << 4;
438 QTest::newRow("insert 6 at 0 in 8x4") << 8 << 4 << 0 << 6;
439 QTest::newRow("insert 6 at 4 in 8x4") << 8 << 4 << 4 << 6;
440 }
441
442 void tst_QStandardItem::insertColumn()
443 {
444 QFETCH(int, rows);
445 QFETCH(int, columns);
446 QFETCH(int, column);
447 QFETCH(int, count);
448
449 QStandardItem item(rows, columns);
450
451 // make items for a new column
452 QList<QStandardItem*> columnItems;
453 for (int i = 0; i < count; ++i)
454 columnItems.append(new QStandardItem);
455
456 item.insertColumn(column, columnItems);
457
458 if (column >= 0) {
459 QCOMPARE(item.columnCount(), columns + 1);
460 QCOMPARE(item.rowCount(), qMax(rows, count));
461 // check to make sure items were inserted in correct place
462 for (int i = 0; i < count; ++i)
463 QCOMPARE(item.child(i, column), columnItems.at(i));
464 for (int i = count; i < item.rowCount(); ++i)
465 QCOMPARE(item.child(i, column), nullptr);
466 } else {
467 QCOMPARE(item.columnCount(), columns);
468 QCOMPARE(item.rowCount(), rows);
469 qDeleteAll(columnItems);
470 }
471 }
472
473 void tst_QStandardItem::insertRow_data()
474 {
475 QTest::addColumn<int>("rows");
476 QTest::addColumn<int>("columns");
477 QTest::addColumn<int>("row");
478 QTest::addColumn<int>("count");
479
480 QTest::newRow("insert 0 at -1 in 0x0") << 0 << 0 << -1 << 0;
481 QTest::newRow("insert 0 at 0 in 0x0") << 0 << 0 << 0 << 0;
482 QTest::newRow("insert 0 at 0 in 1x0") << 1 << 0 << 0 << 0;
483 QTest::newRow("insert 0 at 0 in 0x1") << 0 << 1 << 0 << 0;
484 QTest::newRow("insert 0 at 0 in 1x1") << 1 << 1 << 0 << 0;
485 QTest::newRow("insert 1 at -1 in 0x0") << 0 << 0 << -1 << 1;
486 QTest::newRow("insert 1 at 0 in 0x0") << 0 << 0 << 0 << 1;
487 QTest::newRow("insert 1 at 0 in 1x0") << 1 << 0 << 0 << 1;
488 QTest::newRow("insert 1 at 0 in 0x1") << 0 << 1 << 0 << 1;
489 QTest::newRow("insert 1 at 0 in 1x1") << 1 << 1 << 0 << 1;
490 QTest::newRow("insert 1 at 1 in 1x1") << 1 << 1 << 1 << 1;
491 QTest::newRow("insert 1 at 0 in 2x1") << 2 << 1 << 0 << 1;
492 QTest::newRow("insert 1 at 1 in 2x1") << 2 << 1 << 1 << 1;
493 QTest::newRow("insert 1 at 0 in 1x2") << 1 << 2 << 0 << 1;
494 QTest::newRow("insert 1 at 1 in 1x2") << 1 << 2 << 1 << 1;
495 QTest::newRow("insert 1 at 0 in 4x8") << 4 << 8 << 0 << 1;
496 QTest::newRow("insert 1 at 1 in 4x8") << 4 << 8 << 1 << 1;
497 QTest::newRow("insert 1 at 2 in 4x8") << 4 << 8 << 2 << 1;
498 QTest::newRow("insert 1 at 3 in 4x8") << 4 << 8 << 3 << 1;
499 QTest::newRow("insert 1 at 4 in 4x8") << 4 << 8 << 4 << 1;
500 QTest::newRow("insert 4 at 0 in 4x8") << 4 << 8 << 0 << 4;
501 QTest::newRow("insert 4 at 4 in 4x8") << 4 << 8 << 4 << 4;
502 QTest::newRow("insert 6 at 0 in 4x8") << 4 << 8 << 0 << 6;
503 QTest::newRow("insert 6 at 4 in 4x8") << 4 << 8 << 4 << 6;
504 }
505
506 void tst_QStandardItem::insertRow()
507 {
508 QFETCH(int, rows);
509 QFETCH(int, columns);
510 QFETCH(int, row);
511 QFETCH(int, count);
512
513 QStandardItem item(rows, columns);
514
515 // make items for a new column
516 QList<QStandardItem*> rowItems;
517 for (int i = 0; i < count; ++i)
518 rowItems.append(new QStandardItem);
519
520 item.insertRow(row, rowItems);
521
522 if (row >= 0) {
523 QCOMPARE(item.columnCount(), qMax(columns, count));
524 QCOMPARE(item.rowCount(), rows + 1);
525 // check to make sure items were inserted in correct place
526 for (int i = 0; i < count; ++i)
527 QCOMPARE(item.child(row, i), rowItems.at(i));
528 for (int i = count; i < item.columnCount(); ++i)
529 QCOMPARE(item.child(row, i), nullptr);
530 } else {
531 QCOMPARE(item.columnCount(), columns);
532 QCOMPARE(item.rowCount(), rows);
533 qDeleteAll(rowItems);
534 }
535 }
536
537 void tst_QStandardItem::insertRows_data()
538 {
539 QTest::addColumn<int>("rows");
540 QTest::addColumn<int>("columns");
541 QTest::addColumn<int>("insertAt");
542 QTest::addColumn<int>("insertCount");
543
544 QTest::newRow("insert {0,1} at 0 in 0x0") << 0 << 0 << 0 << 2;
545 }
546
547 void tst_QStandardItem::insertRows()
548 {
549 QFETCH(int, rows);
550 QFETCH(int, columns);
551 QFETCH(int, insertAt);
552 QFETCH(int, insertCount);
553
554 QStandardItem item(rows, columns);
555
556 QList<QStandardItem*> items;
557 for (int i = 0; i < insertCount; ++i)
558 items.append(new QStandardItem());
559 item.insertRows(insertAt, items);
560
561 QCOMPARE(item.rowCount(), rows + insertCount);
562 }
563
564 void tst_QStandardItem::appendColumn_data()
565 {
566 QTest::addColumn<int>("rows");
567 QTest::addColumn<int>("columns");
568 QTest::addColumn<int>("count");
569
570 QTest::newRow("append 0 to 0x0") << 0 << 0 << 0;
571 QTest::newRow("append 1 to 0x0") << 0 << 0 << 1;
572 QTest::newRow("append 1 to 1x0") << 1 << 0 << 1;
573 QTest::newRow("append 1 to 0x1") << 0 << 1 << 1;
574 QTest::newRow("append 1 to 1x1") << 1 << 1 << 1;
575 QTest::newRow("append 1 to 2x0") << 2 << 0 << 1;
576 QTest::newRow("append 1 to 0x2") << 0 << 2 << 1;
577 QTest::newRow("append 1 to 2x1") << 2 << 1 << 1;
578 QTest::newRow("append 1 to 1x2") << 1 << 2 << 1;
579 QTest::newRow("append 1 to 2x2") << 2 << 2 << 1;
580 QTest::newRow("append 2 to 0x0") << 0 << 0 << 2;
581 QTest::newRow("append 2 to 1x0") << 1 << 0 << 2;
582 QTest::newRow("append 2 to 0x1") << 0 << 1 << 2;
583 QTest::newRow("append 2 to 1x1") << 1 << 1 << 2;
584 QTest::newRow("append 2 to 2x0") << 2 << 0 << 2;
585 QTest::newRow("append 2 to 0x2") << 0 << 2 << 2;
586 QTest::newRow("append 2 to 2x1") << 2 << 1 << 2;
587 QTest::newRow("append 2 to 1x2") << 1 << 2 << 2;
588 QTest::newRow("append 2 to 2x2") << 2 << 2 << 2;
589 QTest::newRow("append 3 to 2x1") << 2 << 1 << 3;
590 QTest::newRow("append 3 to 1x2") << 1 << 2 << 3;
591 QTest::newRow("append 3 to 2x2") << 2 << 2 << 3;
592 QTest::newRow("append 3 to 4x2") << 4 << 2 << 3;
593 QTest::newRow("append 3 to 2x4") << 2 << 4 << 3;
594 QTest::newRow("append 3 to 4x4") << 4 << 4 << 3;
595 QTest::newRow("append 7 to 4x2") << 4 << 2 << 7;
596 QTest::newRow("append 7 to 2x4") << 2 << 4 << 7;
597 QTest::newRow("append 7 to 4x4") << 4 << 4 << 7;
598 }
599
600 void tst_QStandardItem::appendColumn()
601 {
602 QFETCH(int, rows);
603 QFETCH(int, columns);
604 QFETCH(int, count);
605
606 QStandardItem item(rows, columns);
607 QList<QStandardItem*> originalChildren;
608 // initialize children
609 for (int i = 0; i < rows; ++i) {
610 for (int j = 0; j < columns; ++j) {
611 QStandardItem *child = new QStandardItem;
612 originalChildren.append(child);
613 item.setChild(i, j, child);
614 }
615 }
616
617 // make items for a new column
618 QList<QStandardItem*> columnItems;
619 for (int i = 0; i < count; ++i)
620 columnItems.append(new QStandardItem);
621
622 item.appendColumn(columnItems);
623
624 QCOMPARE(item.columnCount(), columns + 1);
625 QCOMPARE(item.rowCount(), qMax(rows, count));
626 // check to make sure items were inserted in correct place
627 for (int i = 0; i < count; ++i)
628 QCOMPARE(item.child(i, columns), columnItems.at(i));
629 for (int i = count; i < item.rowCount(); ++i)
630 QCOMPARE(item.child(i, columns), nullptr);
631
632 // make sure original children remained unchanged
633 for (int i = 0; i < rows; ++i) {
634 for (int j = 0; j < columns; ++j)
635 QCOMPARE(item.child(i, j), originalChildren.at(i*columns+j));
636 }
637 }
638
639 void tst_QStandardItem::appendRow_data()
640 {
641 QTest::addColumn<int>("rows");
642 QTest::addColumn<int>("columns");
643 QTest::addColumn<int>("count");
644
645 QTest::newRow("append 0 to 0x0") << 0 << 0 << 0;
646 QTest::newRow("append 1 to 0x0") << 0 << 0 << 1;
647 QTest::newRow("append 1 to 1x0") << 1 << 0 << 1;
648 QTest::newRow("append 1 to 0x1") << 0 << 1 << 1;
649 QTest::newRow("append 1 to 1x1") << 1 << 1 << 1;
650 QTest::newRow("append 1 to 2x0") << 2 << 0 << 1;
651 QTest::newRow("append 1 to 0x2") << 0 << 2 << 1;
652 QTest::newRow("append 1 to 2x1") << 2 << 1 << 1;
653 QTest::newRow("append 1 to 1x2") << 1 << 2 << 1;
654 QTest::newRow("append 1 to 2x2") << 2 << 2 << 1;
655 QTest::newRow("append 2 to 0x0") << 0 << 0 << 2;
656 QTest::newRow("append 2 to 1x0") << 1 << 0 << 2;
657 QTest::newRow("append 2 to 0x1") << 0 << 1 << 2;
658 QTest::newRow("append 2 to 1x1") << 1 << 1 << 2;
659 QTest::newRow("append 2 to 2x0") << 2 << 0 << 2;
660 QTest::newRow("append 2 to 0x2") << 0 << 2 << 2;
661 QTest::newRow("append 2 to 2x1") << 2 << 1 << 2;
662 QTest::newRow("append 2 to 1x2") << 1 << 2 << 2;
663 QTest::newRow("append 2 to 2x2") << 2 << 2 << 2;
664 QTest::newRow("append 3 to 2x1") << 2 << 1 << 3;
665 QTest::newRow("append 3 to 1x2") << 1 << 2 << 3;
666 QTest::newRow("append 3 to 2x2") << 2 << 2 << 3;
667 QTest::newRow("append 3 to 4x2") << 4 << 2 << 3;
668 QTest::newRow("append 3 to 2x4") << 2 << 4 << 3;
669 QTest::newRow("append 3 to 4x4") << 4 << 4 << 3;
670 QTest::newRow("append 7 to 4x2") << 4 << 2 << 7;
671 QTest::newRow("append 7 to 2x4") << 2 << 4 << 7;
672 QTest::newRow("append 7 to 4x4") << 4 << 4 << 7;
673 }
674
675 void tst_QStandardItem::appendRow()
676 {
677 QFETCH(int, rows);
678 QFETCH(int, columns);
679 QFETCH(int, count);
680
681 QStandardItem item(rows, columns);
682 QList<QStandardItem*> originalChildren;
683 // initialize children
684 for (int i = 0; i < rows; ++i) {
685 for (int j = 0; j < columns; ++j) {
686 QStandardItem *child = new QStandardItem;
687 originalChildren.append(child);
688 item.setChild(i, j, child);
689 }
690 }
691
692 // make items for a new row
693 QList<QStandardItem*> rowItems;
694 for (int i = 0; i < count; ++i)
695 rowItems.append(new QStandardItem);
696
697 item.appendRow(rowItems);
698
699 QCOMPARE(item.rowCount(), rows + 1);
700 QCOMPARE(item.columnCount(), qMax(columns, count));
701 // check to make sure items were inserted in correct place
702 for (int i = 0; i < count; ++i)
703 QCOMPARE(item.child(rows, i), rowItems.at(i));
704 for (int i = count; i < item.columnCount(); ++i)
705 QCOMPARE(item.child(rows, i), nullptr);
706
707 // make sure original children remained unchanged
708 for (int i = 0; i < rows; ++i) {
709 for (int j = 0; j < columns; ++j)
710 QCOMPARE(item.child(i, j), originalChildren.at(i*columns+j));
711 }
712 }
713
714 void tst_QStandardItem::takeChild()
715 {
716 QList<QStandardItem*> itemList;
717 for (int i = 0; i < 10; ++i)
718 itemList.append(new QStandardItem);
719 QStandardItem item;
720 item.appendColumn(itemList);
721
722 for (int i = 0; i < item.rowCount(); ++i) {
723 QCOMPARE(item.takeChild(i), itemList.at(i));
724 QCOMPARE(item.takeChild(0, 0), nullptr);
725 for (int j = i + 1; j < item.rowCount(); ++j)
726 QCOMPARE(item.child(j), itemList.at(j));
727 }
728 qDeleteAll(itemList);
729 }
730
731 void tst_QStandardItem::takeColumn_data()
732 {
733 QTest::addColumn<int>("rows");
734 QTest::addColumn<int>("columns");
735 QTest::addColumn<int>("column");
736 QTest::addColumn<bool>("expectSuccess");
737
738 QTest::newRow("take -1 from 0x0") << 0 << 0 << -1 << false;
739 QTest::newRow("take 0 from 0x0") << 0 << 0 << 0 << false;
740 QTest::newRow("take 0 from 1x0") << 1 << 0 << 0 << false;
741 QTest::newRow("take 0 from 0x1") << 0 << 1 << 0 << true;
742 QTest::newRow("take 1 from 0x1") << 0 << 1 << 1 << false;
743 QTest::newRow("take 0 from 1x1") << 1 << 1 << 0 << true;
744 QTest::newRow("take 1 from 1x1") << 0 << 1 << 1 << false;
745 QTest::newRow("take 0 from 4x1") << 4 << 1 << 0 << true;
746 QTest::newRow("take 1 from 4x1") << 4 << 1 << 1 << false;
747 QTest::newRow("take 0 from 4x8") << 4 << 8 << 0 << true;
748 QTest::newRow("take 7 from 4x8") << 4 << 8 << 7 << true;
749 QTest::newRow("take 8 from 4x8") << 4 << 8 << 8 << false;
750 }
751
752 void tst_QStandardItem::takeColumn()
753 {
754 QFETCH(int, rows);
755 QFETCH(int, columns);
756 QFETCH(int, column);
757 QFETCH(bool, expectSuccess);
758
759 QStandardItem item(rows, columns);
760 QList<QStandardItem*> originalChildren;
761 // initialize children
762 for (int i = 0; i < rows; ++i) {
763 for (int j = 0; j < columns; ++j) {
764 QStandardItem *child = new QStandardItem;
765 originalChildren.append(child);
766 item.setChild(i, j, child);
767 }
768 }
769
770 QList<QStandardItem *> taken = item.takeColumn(column);
771 if (expectSuccess) {
772 QCOMPARE(taken.size(), item.rowCount());
773 QCOMPARE(item.columnCount(), columns - 1);
774 int index = column;
775 for (int i = 0; i < taken.size(); ++i) {
776 QCOMPARE(taken.at(i), originalChildren.takeAt(index));
777 index += item.columnCount();
778 }
779 index = 0;
780 for (int i = 0; i < item.rowCount(); ++i) {
781 for (int j = 0; j < item.columnCount(); ++j) {
782 QCOMPARE(item.child(i, j), originalChildren.at(index));
783 ++index;
784 }
785 }
786 } else {
787 QVERIFY(taken.isEmpty());
788 }
789 qDeleteAll(taken);
790 }
791
792 void tst_QStandardItem::takeRow_data()
793 {
794 QTest::addColumn<int>("rows");
795 QTest::addColumn<int>("columns");
796 QTest::addColumn<int>("row");
797 QTest::addColumn<bool>("expectSuccess");
798
799 QTest::newRow("take -1 from 0x0") << 0 << 0 << -1 << false;
800 QTest::newRow("take 0 from 0x0") << 0 << 0 << 0 << false;
801 QTest::newRow("take 0 from 1x0") << 1 << 0 << 0 << true;
802 QTest::newRow("take 0 from 0x1") << 0 << 1 << 0 << false;
803 QTest::newRow("take 1 from 0x1") << 0 << 1 << 1 << false;
804 QTest::newRow("take 0 from 1x1") << 1 << 1 << 0 << true;
805 QTest::newRow("take 1 from 1x1") << 0 << 1 << 1 << false;
806 QTest::newRow("take 0 from 1x4") << 1 << 4 << 0 << true;
807 QTest::newRow("take 1 from 1x4") << 1 << 4 << 1 << false;
808 QTest::newRow("take 0 from 8x4") << 8 << 4 << 0 << true;
809 QTest::newRow("take 7 from 8x4") << 8 << 4 << 7 << true;
810 QTest::newRow("take 8 from 8x4") << 8 << 4 << 8 << false;
811 }
812
813 void tst_QStandardItem::takeRow()
814 {
815 QFETCH(int, rows);
816 QFETCH(int, columns);
817 QFETCH(int, row);
818 QFETCH(bool, expectSuccess);
819
820 QStandardItem item(rows, columns);
821 QList<QStandardItem*> originalChildren;
822 // initialize children
823 for (int i = 0; i < rows; ++i) {
824 for (int j = 0; j < columns; ++j) {
825 QStandardItem *child = new QStandardItem;
826 originalChildren.append(child);
827 item.setChild(i, j, child);
828 }
829 }
830
831 QList<QStandardItem *> taken = item.takeRow(row);
832 if (expectSuccess) {
833 QCOMPARE(taken.size(), item.columnCount());
834 QCOMPARE(item.rowCount(), rows - 1);
835 int index = row * columns;
836 for (int i = 0; i < taken.size(); ++i) {
837 QCOMPARE(taken.at(i), originalChildren.takeAt(index));
838 }
839 index = 0;
840 for (int i = 0; i < item.rowCount(); ++i) {
841 for (int j = 0; j < item.columnCount(); ++j) {
842 QCOMPARE(item.child(i, j), originalChildren.at(index));
843 ++index;
844 }
845 }
846 } else {
847 QVERIFY(taken.isEmpty());
848 }
849 qDeleteAll(taken);
850 }
851
852 void tst_QStandardItem::streamItem()
853 {
854 QStandardItem item;
855
856 item.setText(QLatin1String("text"));
857 item.setToolTip(QLatin1String("toolTip"));
858 item.setStatusTip(QLatin1String("statusTip"));
859 #if QT_CONFIG(whatsthis)
860 item.setWhatsThis(QLatin1String("whatsThis"));
861 #endif
862 item.setSizeHint(QSize(64, 48));
863 item.setFont(QFont());
864 item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
865 item.setBackground(QColor(Qt::blue));
866 item.setForeground(QColor(Qt::green));
867 item.setCheckState(Qt::PartiallyChecked);
868 item.setAccessibleText(QLatin1String("accessibleText"));
869 item.setAccessibleDescription(QLatin1String("accessibleDescription"));
870
871 QByteArray ba;
872 {
873 QDataStream ds(&ba, QIODevice::WriteOnly);
874 ds << item;
875 }
876 {
877 QStandardItem streamedItem;
878 QDataStream ds(&ba, QIODevice::ReadOnly);
879 ds >> streamedItem;
880 QCOMPARE(streamedItem.text(), item.text());
881 QCOMPARE(streamedItem.toolTip(), item.toolTip());
882 QCOMPARE(streamedItem.statusTip(), item.statusTip());
883 #if QT_CONFIG(whatsthis)
884 QCOMPARE(streamedItem.whatsThis(), item.whatsThis());
885 #endif
886 QCOMPARE(streamedItem.sizeHint(), item.sizeHint());
887 QCOMPARE(streamedItem.font(), item.font());
888 QCOMPARE(streamedItem.textAlignment(), item.textAlignment());
889 QCOMPARE(streamedItem.background(), item.background());
890 QCOMPARE(streamedItem.foreground(), item.foreground());
891 QCOMPARE(streamedItem.checkState(), item.checkState());
892 QCOMPARE(streamedItem.accessibleText(), item.accessibleText());
893 QCOMPARE(streamedItem.accessibleDescription(), item.accessibleDescription());
894 QCOMPARE(streamedItem.flags(), item.flags());
895 }
896 }
897
898 void tst_QStandardItem::deleteItem()
899 {
900 QStandardItemModel model(4, 6);
901 // initialize items
902 for (int i = 0; i < model.rowCount(); ++i) {
903 for (int j = 0; j < model.columnCount(); ++j) {
904 QStandardItem *item = new QStandardItem();
905 model.setItem(i, j, item);
906 }
907 }
908 // delete items
909 for (int i = 0; i < model.rowCount(); ++i) {
910 for (int j = 0; j < model.columnCount(); ++j) {
911 QStandardItem *item = model.item(i, j);
912 delete item;
913 QCOMPARE(model.item(i, j), nullptr);
914 }
915 }
916 }
917
918 void tst_QStandardItem::clone()
919 {
920 QStandardItem item;
921 item.setText(QLatin1String("text"));
922 item.setToolTip(QLatin1String("toolTip"));
923 item.setStatusTip(QLatin1String("statusTip"));
924 #if QT_CONFIG(whatsthis)
925 item.setWhatsThis(QLatin1String("whatsThis"));
926 #endif
927 item.setSizeHint(QSize(64, 48));
928 item.setFont(QFont());
929 item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
930 item.setBackground(QColor(Qt::blue));
931 item.setForeground(QColor(Qt::green));
932 item.setCheckState(Qt::PartiallyChecked);
933 item.setAccessibleText(QLatin1String("accessibleText"));
934 item.setAccessibleDescription(QLatin1String("accessibleDescription"));
935 item.setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
936
937 QStandardItem *clone = item.clone();
938 QCOMPARE(clone->text(), item.text());
939 QCOMPARE(clone->toolTip(), item.toolTip());
940 QCOMPARE(clone->statusTip(), item.statusTip());
941 #if QT_CONFIG(whatsthis)
942 QCOMPARE(clone->whatsThis(), item.whatsThis());
943 #endif
944 QCOMPARE(clone->sizeHint(), item.sizeHint());
945 QCOMPARE(clone->font(), item.font());
946 QCOMPARE(clone->textAlignment(), item.textAlignment());
947 QCOMPARE(clone->background(), item.background());
948 QCOMPARE(clone->foreground(), item.foreground());
949 QCOMPARE(clone->checkState(), item.checkState());
950 QCOMPARE(clone->accessibleText(), item.accessibleText());
951 QCOMPARE(clone->accessibleDescription(), item.accessibleDescription());
952 QCOMPARE(clone->flags(), item.flags());
953 QVERIFY(!(*clone < item));
954 delete clone;
955 }
956
957 void tst_QStandardItem::sortChildren()
958 {
959 for (int x = 0; x < 2; ++x) {
960 QStandardItemModel *model = new QStandardItemModel;
961 QStandardItem *item = (x == 0) ? new QStandardItem : model->invisibleRootItem();
962 QStandardItem *one = new QStandardItem;
963 one->appendRow(new QStandardItem(QLatin1String("a")));
964 one->appendRow(new QStandardItem(QLatin1String("b")));
965 one->appendRow(new QStandardItem(QLatin1String("c")));
966 QStandardItem *two = new QStandardItem;
967 two->appendRow(new QStandardItem(QLatin1String("f")));
968 two->appendRow(new QStandardItem(QLatin1String("d")));
969 two->appendRow(new QStandardItem(QLatin1String("e")));
970 item->appendRow(one);
971 item->appendRow(two);
972
973 QSignalSpy layoutAboutToBeChangedSpy(
974 model, &QAbstractItemModel::layoutAboutToBeChanged);
975 QSignalSpy layoutChangedSpy(
976 model, &QAbstractItemModel::layoutChanged);
977
978 one->sortChildren(0, Qt::DescendingOrder);
979 // verify sorted
980 QCOMPARE(one->child(0)->text(), QLatin1String("c"));
981 QCOMPARE(one->child(1)->text(), QLatin1String("b"));
982 QCOMPARE(one->child(2)->text(), QLatin1String("a"));
983 // verify siblings unaffected
984 QCOMPARE(two->child(0)->text(), QLatin1String("f"));
985 QCOMPARE(two->child(1)->text(), QLatin1String("d"));
986 QCOMPARE(two->child(2)->text(), QLatin1String("e"));
987
988 two->sortChildren(0, Qt::AscendingOrder);
989 // verify sorted
990 QCOMPARE(two->child(0)->text(), QLatin1String("d"));
991 QCOMPARE(two->child(1)->text(), QLatin1String("e"));
992 QCOMPARE(two->child(2)->text(), QLatin1String("f"));
993 // verify siblings unaffected
994 QCOMPARE(one->child(0)->text(), QLatin1String("c"));
995 QCOMPARE(one->child(1)->text(), QLatin1String("b"));
996 QCOMPARE(one->child(2)->text(), QLatin1String("a"));
997
998 item->sortChildren(0, Qt::AscendingOrder);
999 // verify everything sorted
1000 QCOMPARE(one->child(0)->text(), QLatin1String("a"));
1001 QCOMPARE(one->child(1)->text(), QLatin1String("b"));
1002 QCOMPARE(one->child(2)->text(), QLatin1String("c"));
1003 QCOMPARE(two->child(0)->text(), QLatin1String("d"));
1004 QCOMPARE(two->child(1)->text(), QLatin1String("e"));
1005 QCOMPARE(two->child(2)->text(), QLatin1String("f"));
1006
1007 QCOMPARE(layoutAboutToBeChangedSpy.size(), (x == 0) ? 0 : 3);
1008 QCOMPARE(layoutChangedSpy.size(), (x == 0) ? 0 : 3);
1009
1010 if (x == 0)
1011 delete item;
1012 delete model;
1013 }
1014 }
1015
1016 class CustomItem : public QStandardItem
1017 {
1018 public:
1019 using QStandardItem::QStandardItem;
1020
1021 int type() const override { return QStandardItem::UserType + 1; }
1022
1023 bool operator<(const QStandardItem &other) const override {
1024 return text().size() < other.text().size();
1025 }
1026
1027 using QStandardItem::clone;
1028 using QStandardItem::emitDataChanged;
1029
1030 void setData(const QVariant &value, int role) override
1031 {
1032 switch (role) {
1033 case Qt::DisplayRole:
1034 QStandardItem::setData(value, role);
1035 break;
1036 default:
1037 // setFlags() uses Qt::StandardItemFlagsRole to store the flags,
1038 // which is an implementation detail not exposed in the docs.
1039 QStandardItem::setData(value, role);
1040 break;
1041 }
1042 }
1043
1044 QVariant data(int role) const override
1045 {
1046 switch (role) {
1047 case Qt::DisplayRole:
1048 return QStandardItem::data(role);
1049 default:
1050 // flags() uses Qt::StandardItemFlagsRole to get the flags, which is
1051 // an implementation detail not exposed in the docs.
1052 return QStandardItem::data(role);
1053 }
1054 }
1055 };
1056
1057 Q_DECLARE_METATYPE(QStandardItem*)
1058
1059 void tst_QStandardItem::subclassing()
1060 {
1061 qMetaTypeId<QStandardItem*>();
1062
1063 CustomItem *item = new CustomItem;
1064 QCOMPARE(item->type(), int(QStandardItem::UserType + 1));
1065
1066 item->setText(QString::fromLatin1("foo"));
1067 QCOMPARE(item->text(), QString::fromLatin1("foo"));
1068
1069 item->emitDataChanged(); // does nothing
1070
1071 QStandardItemModel model;
1072 model.appendRow(item);
1073
1074 QSignalSpy itemChangedSpy(&model, &QStandardItemModel::itemChanged);
1075 item->emitDataChanged();
1076 QCOMPARE(itemChangedSpy.size(), 1);
1077 QCOMPARE(itemChangedSpy.at(0).size(), 1);
1078 QCOMPARE(qvariant_cast<QStandardItem*>(itemChangedSpy.at(0).at(0)), item);
1079
1080 CustomItem *child0 = new CustomItem("cc");
1081 CustomItem *child1 = new CustomItem("bbb");
1082 CustomItem *child2 = new CustomItem("a");
1083 item->appendRow(child0);
1084 item->appendRow(child1);
1085 item->appendRow(child2);
1086 item->sortChildren(0);
1087 QCOMPARE(item->child(0), child2);
1088 QCOMPARE(item->child(1), child0);
1089 QCOMPARE(item->child(2), child1);
1090
1091 item->setFlags(Qt::ItemFlags{0});
1092 QCOMPARE(item->flags(), Qt::ItemFlags{0});
1093
1094 item->setFlags(Qt::ItemFlags{Qt::ItemIsEditable | Qt::ItemIsSelectable});
1095 QCOMPARE(item->flags(), Qt::ItemFlags{Qt::ItemIsEditable | Qt::ItemIsSelectable});
1096 }
1097
1098 void tst_QStandardItem::lessThan()
1099 {
1100 QStandardItem stringA("A");
1101 QStandardItem stringB("B");
1102 QStandardItem invalid1;
1103 QStandardItem invalid2;
1104 QVERIFY(stringA < stringB);
1105 QVERIFY(!(stringB < stringA));
1106 // Items with invalid data go to the end.
1107 QVERIFY(stringA < invalid1);
1108 QVERIFY(!(invalid1 < stringA));
1109 QVERIFY(!(invalid1 < invalid2));
1110 }
1111
1112 QTEST_MAIN(tst_QStandardItem)
1113 #include "tst_qstandarditem.moc"