summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/itemviews')
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp203
-rw-r--r--tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp40
-rw-r--r--tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp18
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp92
-rw-r--r--tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp106
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp41
-rw-r--r--tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp94
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp40
-rw-r--r--tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp48
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp128
-rw-r--r--tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp178
-rw-r--r--tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp2
12 files changed, 571 insertions, 419 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index 6a99772c53..fc984cef6e 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -140,6 +140,7 @@ private slots:
void selectionCommand();
void mouseSelection_data();
void mouseSelection();
+ void keepSingleSelectionOnEmptyAreaClick();
void scrollerSmoothScroll();
void inputMethodOpensEditor_data();
void inputMethodOpensEditor();
@@ -424,12 +425,12 @@ void tst_QAbstractItemView::basic_tests(QAbstractItemView *view)
QVERIFY(spy.isValid());
view->setIconSize(QSize(32, 32));
QCOMPARE(view->iconSize(), QSize(32, 32));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.at(0).at(0).value<QSize>(), QSize(32, 32));
// Should this happen?
view->setIconSize(QSize(-1, -1));
QCOMPARE(view->iconSize(), QSize(-1, -1));
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
QCOMPARE(view->currentIndex(), QModelIndex());
QCOMPARE(view->rootIndex(), QModelIndex());
@@ -663,9 +664,9 @@ void tst_QAbstractItemView::selectAll()
GeometriesTestView view;
view.setModel(&model);
- QCOMPARE(view.selectedIndexes().count(), 0);
+ QCOMPARE(view.selectedIndexes().size(), 0);
view.selectAll();
- QCOMPARE(view.selectedIndexes().count(), 4 * 4);
+ QCOMPARE(view.selectedIndexes().size(), 4 * 4);
}
void tst_QAbstractItemView::ctrlA()
@@ -674,9 +675,9 @@ void tst_QAbstractItemView::ctrlA()
GeometriesTestView view;
view.setModel(&model);
- QCOMPARE(view.selectedIndexes().count(), 0);
+ QCOMPARE(view.selectedIndexes().size(), 0);
QTest::keyClick(&view, Qt::Key_A, Qt::ControlModifier);
- QCOMPARE(view.selectedIndexes().count(), 4 * 4);
+ QCOMPARE(view.selectedIndexes().size(), 4 * 4);
}
void tst_QAbstractItemView::persistentEditorFocus()
@@ -693,7 +694,7 @@ void tst_QAbstractItemView::persistentEditorFocus()
//these are spinboxes because we put numbers inside
const QList<QSpinBox*> list = view.viewport()->findChildren<QSpinBox*>();
- QCOMPARE(list.count(), 2); //these should be the 2 editors
+ QCOMPARE(list.size(), 2); //these should be the 2 editors
view.setCurrentIndex(model.index(0, 0));
QCOMPARE(view.currentIndex(), model.index(0, 0));
@@ -753,22 +754,6 @@ void tst_QAbstractItemView::pressClosesReleaseDoesntOpenEditor()
QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, inChildOutsideEditor); // should not reopen editor
QTest::qWait(QApplication::doubleClickInterval() * 2);
QCOMPARE(view.state(), QAbstractItemView::NoState);
-
- // with multiple items selected, clicking from the currently edited item into another
- // selected item closes the current and reopens a new editor
- view.setSelectionMode(QAbstractItemView::ExtendedSelection);
- const QRect child2Rect = view.visualRect(model.indexFromItem(parent->child(1)));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, child2Rect.center()); // select
- QVERIFY(view.selectionModel()->selectedIndexes().contains(model.indexFromItem(parent->child(0))));
- QVERIFY(view.selectionModel()->selectedIndexes().contains(model.indexFromItem(parent->child(1))));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, child2Rect.center()); // edit
- QTRY_COMPARE(view.state(), QAbstractItemView::EditingState);
- QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, inChildOutsideEditor); // editor closes
- QCOMPARE(view.state(), QAbstractItemView::NoState);
- QTest::qWait(10); // process some events, let the internal timer time out
- QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, inChildOutsideEditor); // should open editor
- QTest::qWait(QApplication::doubleClickInterval() * 2);
- QCOMPARE(view.state(), QAbstractItemView::EditingState);
}
@@ -1354,7 +1339,7 @@ void tst_QAbstractItemView::task200665_itemEntered()
QSignalSpy spy(&view, &QAbstractItemView::entered);
view.verticalScrollBar()->setValue(view.verticalScrollBar()->maximum());
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE(spy.size(), 1);
}
void tst_QAbstractItemView::task257481_emptyEditor()
@@ -1377,17 +1362,17 @@ void tst_QAbstractItemView::task257481_emptyEditor()
treeView.edit(model.index(0, 0));
QList<QLineEdit *> lineEditors = treeView.viewport()->findChildren<QLineEdit *>();
- QCOMPARE(lineEditors.count(), 1);
+ QCOMPARE(lineEditors.size(), 1);
QVERIFY(!lineEditors.constFirst()->size().isEmpty());
treeView.edit(model.index(1, 0));
lineEditors = treeView.viewport()->findChildren<QLineEdit *>();
- QCOMPARE(lineEditors.count(), 1);
+ QCOMPARE(lineEditors.size(), 1);
QVERIFY(!lineEditors.constFirst()->size().isEmpty());
treeView.edit(model.index(2, 0));
lineEditors = treeView.viewport()->findChildren<QLineEdit *>();
- QCOMPARE(lineEditors.count(), 1);
+ QCOMPARE(lineEditors.size(), 1);
QVERIFY(!lineEditors.constFirst()->size().isEmpty());
}
@@ -1421,7 +1406,7 @@ void tst_QAbstractItemView::shiftArrowSelectionAfterScrolling()
QCOMPARE(view.currentIndex(), index1);
QModelIndexList selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 2);
+ QCOMPARE(selected.size(), 2);
QVERIFY(selected.contains(index0));
QVERIFY(selected.contains(index1));
}
@@ -1475,7 +1460,7 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection()
// Verify that the selection worked OK
QModelIndexList selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 2);
+ QCOMPARE(selected.size(), 2);
QVERIFY(selected.contains(index1));
QVERIFY(selected.contains(index2));
@@ -1498,7 +1483,7 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection()
// Verify that the selection worked OK
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 2);
+ QCOMPARE(selected.size(), 2);
QVERIFY(selected.contains(index1));
QVERIFY(selected.contains(index2));
}
@@ -1527,7 +1512,7 @@ void tst_QAbstractItemView::ctrlRubberbandSelection()
// Select item 1
view.setCurrentIndex(index1);
QModelIndexList selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 1);
+ QCOMPARE(selected.size(), 1);
QVERIFY(selected.contains(index1));
// Now press control and draw a rubberband around items 1 and 2.
@@ -1544,7 +1529,7 @@ void tst_QAbstractItemView::ctrlRubberbandSelection()
// Verify that item 2 is selected now
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 1);
+ QCOMPARE(selected.size(), 1);
QVERIFY(selected.contains(index2));
}
@@ -1577,21 +1562,21 @@ void tst_QAbstractItemView::QTBUG6407_extendedSelection()
QVERIFY(view.viewport()->rect().contains(p));
QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, p);
QCOMPARE(view.currentIndex(), index49);
- QCOMPARE(view.selectedItems().count(), 1);
+ QCOMPARE(view.selectedItems().size(), 1);
QModelIndex index47 = view.model()->index(47,0);
p = view.visualRect(index47).center();
QVERIFY(view.viewport()->rect().contains(p));
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, p);
QCOMPARE(view.currentIndex(), index47);
- QCOMPARE(view.selectedItems().count(), 3); //49, 48, 47;
+ QCOMPARE(view.selectedItems().size(), 3); //49, 48, 47;
QModelIndex index44 = view.model()->index(44,0);
p = view.visualRect(index44).center();
QVERIFY(view.viewport()->rect().contains(p));
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, p);
QCOMPARE(view.currentIndex(), index44);
- QCOMPARE(view.selectedItems().count(), 6); //49 .. 44;
+ QCOMPARE(view.selectedItems().size(), 6); //49 .. 44;
}
@@ -1616,7 +1601,7 @@ void tst_QAbstractItemView::QTBUG6753_selectOnSelection()
QTest::mouseMove(table.viewport(), itemRect.center());
QTest::mouseClick(table.viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center());
- QCOMPARE(table.selectedItems().count(), 1);
+ QCOMPARE(table.selectedItems().size(), 1);
QCOMPARE(table.selectedItems().first(), table.item(item.row(), item.column()));
}
@@ -1653,12 +1638,12 @@ void tst_QAbstractItemView::testClickedSignal()
QSignalSpy clickedSpy(&view, &QTableWidget::clicked);
QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, p);
- QCOMPARE(clickedSpy.count(), 1);
+ QCOMPARE(clickedSpy.size(), 1);
QTest::mouseClick(view.viewport(), Qt::RightButton, {}, p);
// We expect that right-clicks do not cause the clicked() signal to
// be emitted.
- QCOMPARE(clickedSpy.count(), 1);
+ QCOMPARE(clickedSpy.size(), 1);
}
@@ -1722,28 +1707,28 @@ void tst_QAbstractItemView::deselectInSingleSelection()
QPoint clickpos = rect22.center();
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, clickpos);
QCOMPARE(view.currentIndex(), index22);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, clickpos);
QCOMPARE(view.currentIndex(), index22);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 0);
// second click with modifier however does select
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, clickpos);
QCOMPARE(view.currentIndex(), index22);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
// keyboard
QTest::keyClick(&view, Qt::Key_Space, Qt::NoModifier);
QCOMPARE(view.currentIndex(), index22);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
QTest::keyClick(&view, Qt::Key_Space, Qt::ControlModifier);
QCOMPARE(view.currentIndex(), index22);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 0);
// second keypress with modifier however does select
QTest::keyClick(&view, Qt::Key_Space, Qt::ControlModifier);
QCOMPARE(view.currentIndex(), index22);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
}
void tst_QAbstractItemView::testNoActivateOnDisabledItem()
@@ -1771,7 +1756,7 @@ void tst_QAbstractItemView::testNoActivateOnDisabledItem()
QPoint clickPos = treeView.visualRect(itemIndex).center();
QTest::mouseClick(treeView.viewport(), Qt::LeftButton, {}, clickPos);
- QCOMPARE(activatedSpy.count(), 0);
+ QCOMPARE(activatedSpy.size(), 0);
}
void tst_QAbstractItemView::testFocusPolicy_data()
@@ -1865,7 +1850,7 @@ void tst_QAbstractItemView::QTBUG31411_noSelection()
QVERIFY(editor2);
QTest::keyClick(editor2, Qt::Key_Escape, Qt::NoModifier);
- QCOMPARE(selectionChangeSpy.count(), 0);
+ QCOMPARE(selectionChangeSpy.size(), 0);
}
void tst_QAbstractItemView::QTBUG39324_settingSameInstanceOfIndexWidget()
@@ -1907,7 +1892,7 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
// Click "C"
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, view.visualRect(indexC).center());
QModelIndexList selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 1);
+ QCOMPARE(selected.size(), 1);
QVERIFY(selected.contains(indexC));
// Insert new item "B1"
@@ -1917,14 +1902,14 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
// Shift-click "D" -> we expect that "C" and "D" are selected
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, view.visualRect(indexD).center());
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 2);
+ QCOMPARE(selected.size(), 2);
QVERIFY(selected.contains(indexC));
QVERIFY(selected.contains(indexD));
// Click "D"
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, view.visualRect(indexD).center());
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 1);
+ QCOMPARE(selected.size(), 1);
QVERIFY(selected.contains(indexD));
// Remove items "B" and "C"
@@ -1936,7 +1921,7 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
// Shift-click "F" -> we expect that "D", "E", and "F" are selected
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, view.visualRect(indexF).center());
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 3);
+ QCOMPARE(selected.size(), 3);
QVERIFY(selected.contains(indexD));
QVERIFY(selected.contains(indexE));
QVERIFY(selected.contains(indexF));
@@ -1945,7 +1930,7 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
while (view.currentIndex() != indexA)
QTest::keyClick(&view, Qt::Key_Up);
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 1);
+ QCOMPARE(selected.size(), 1);
QVERIFY(selected.contains(indexA));
// Change the sort order
@@ -1954,7 +1939,7 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
// Shift-click "F" -> All items should be selected
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, view.visualRect(indexF).center());
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), model.rowCount());
+ QCOMPARE(selected.size(), model.rowCount());
// Restore the old sort order
proxyModel.sort(0, Qt::AscendingOrder);
@@ -1962,7 +1947,7 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
// Click "D"
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, view.visualRect(indexD).center());
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 1);
+ QCOMPARE(selected.size(), 1);
QVERIFY(selected.contains(indexD));
// Insert new item "B2"
@@ -1972,7 +1957,7 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
// Press Shift+Down -> "D" and "E" should be selected.
QTest::keyClick(&view, Qt::Key_Down, Qt::ShiftModifier);
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 2);
+ QCOMPARE(selected.size(), 2);
QVERIFY(selected.contains(indexD));
QVERIFY(selected.contains(indexE));
@@ -1981,7 +1966,7 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, view.visualRect(indexA).center());
view.setCurrentIndex(indexD);
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 1);
+ QCOMPARE(selected.size(), 1);
QVERIFY(selected.contains(indexD));
// Insert new item "B3"
@@ -1991,7 +1976,7 @@ void tst_QAbstractItemView::shiftSelectionAfterChangingModelContents()
// Press Shift+Down -> "D" and "E" should be selected.
QTest::keyClick(&view, Qt::Key_Down, Qt::ShiftModifier);
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 2);
+ QCOMPARE(selected.size(), 2);
QVERIFY(selected.contains(indexD));
QVERIFY(selected.contains(indexE));
}
@@ -2269,14 +2254,14 @@ void tst_QAbstractItemView::testClickToSelect()
// Click the center of the visualRect of item "A"
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, centerA);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.back().front().value<QRect>(), QRect(centerA, QSize(1, 1)));
// Click a point slightly away from the center
const QPoint nearCenterA = centerA + QPoint(1, 1);
QVERIFY(visualRectA.contains(nearCenterA));
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, nearCenterA);
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
QCOMPARE(spy.back().front().value<QRect>(), QRect(nearCenterA, QSize(1, 1)));
}
@@ -2634,7 +2619,7 @@ void tst_QAbstractItemView::dragSelectAfterNewPress()
// Verify that the selection worked OK
QModelIndexList selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 3);
+ QCOMPARE(selected.size(), 3);
for (int i = 0; i < 2; ++i)
QVERIFY(selected.contains(model.index(i, 0)));
@@ -2651,7 +2636,7 @@ void tst_QAbstractItemView::dragSelectAfterNewPress()
// Verify that the selection worked OK
selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 6);
+ QCOMPARE(selected.size(), 6);
for (int i = 0; i < 5; ++i)
QVERIFY(selected.contains(model.index(i, 0)));
}
@@ -2846,32 +2831,40 @@ void tst_QAbstractItemView::mouseSelection_data()
{
QTest::addColumn<QAbstractItemView::SelectionMode>("selectionMode");
QTest::addColumn<bool>("dragEnabled");
+ QTest::addColumn<QAbstractItemView::EditTrigger>("editTrigger");
QTest::addColumn<QList<SelectionEvent>>("selectionEvents");
QTest::addColumn<QList<int>>("selectedRows");
// single selection mode - always one row selected, modifiers ignored
QTest::addRow("Single:Press") << QAbstractItemView::SingleSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1)}
<< QList{1};
QTest::addRow("Single:Click") << QAbstractItemView::SingleSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent{SelectionEvent::Click, 1}}
<< QList{1};
QTest::addRow("Single:Press+Drag") << QAbstractItemView::SingleSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1),
SelectionEvent{SelectionEvent::Move, 2},
SelectionEvent{SelectionEvent::Release}}
<< QList{2};
QTest::addRow("Single:Shift+Click") << QAbstractItemView::SingleSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent{SelectionEvent::Click, Qt::ShiftModifier, 2}}
<< QList{2};
QTest::addRow("Single:Press;Ctrl+Press") << QAbstractItemView::SingleSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent{SelectionEvent::Press, 3},
SelectionEvent{SelectionEvent::Press, Qt::ControlModifier, 3}}
<< QList{3};
QTest::addRow("Single:Ctrl+Click") << QAbstractItemView::SingleSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent{SelectionEvent::Click, Qt::ControlModifier, 3}}
<< QList{3};
QTest::addRow("Single:Click;Ctrl+Click") << QAbstractItemView::SingleSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent{SelectionEvent::Click, 3},
SelectionEvent{SelectionEvent::Click, Qt::ControlModifier, 3}}
<< QList<int>{};
@@ -2879,30 +2872,37 @@ void tst_QAbstractItemView::mouseSelection_data()
// multi selection mode - selection toggles on press, selection can be drag-extended
// modifiers ignored
QTest::addRow("Multi:Press") << QAbstractItemView::MultiSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1)}
<< QList{1};
QTest::addRow("Multi:Press twice") << QAbstractItemView::MultiSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1),
SelectionEvent(SelectionEvent::Press, 1)}
<< QList<int>{};
QTest::addRow("Multi:Press twice with drag enabled") << QAbstractItemView::MultiSelection << true
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Click, 1),
SelectionEvent(SelectionEvent::Press, 1)}
<< QList{1};
QTest::addRow("Multi:Press and click with drag enabled") << QAbstractItemView::MultiSelection << true
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1),
SelectionEvent(SelectionEvent::Click, 1)}
<< QList<int>{};
QTest::addRow("Multi:Press,Press") << QAbstractItemView::MultiSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 2),
SelectionEvent(SelectionEvent::Press, 3)}
<< QList{2, 3};
QTest::addRow("Multi:Press,Drag") << QAbstractItemView::MultiSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1),
SelectionEvent(SelectionEvent::Move, 5),
SelectionEvent(SelectionEvent::Release)}
<< QList{1, 2, 3, 4, 5};
QTest::addRow("Multi:Press,Drag,Deselect") << QAbstractItemView::MultiSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1),
SelectionEvent(SelectionEvent::Move, 5),
SelectionEvent(SelectionEvent::Release),
@@ -2910,6 +2910,7 @@ void tst_QAbstractItemView::mouseSelection_data()
<< QList{1, 2, 4, 5};
// drag-select a few indices; then drag-select a larger area that includes the first
QTest::addRow("Multi:Press,Drag;Surround") << QAbstractItemView::MultiSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 3),
SelectionEvent(SelectionEvent::Move, 5),
SelectionEvent(SelectionEvent::Release),
@@ -2919,6 +2920,7 @@ void tst_QAbstractItemView::mouseSelection_data()
<< QList{1, 2, 3, 4, 5, 6, 7, 8};
// drag-select a few indices; then try to select more starting with the last -> not working
QTest::addRow("Multi:Press,Drag;Expand") << QAbstractItemView::MultiSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 3),
SelectionEvent(SelectionEvent::Move, 5),
SelectionEvent(SelectionEvent::Release),
@@ -2929,6 +2931,7 @@ void tst_QAbstractItemView::mouseSelection_data()
// Multi: Press-dragging a selection should not deselect #QTBUG-59888
QTest::addRow("Multi:Press-Drag selection") << QAbstractItemView::MultiSelection << true
// with drag'n'drop enabled, we cannot drag a selection
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Click, 2),
SelectionEvent(SelectionEvent::Click, 3),
SelectionEvent(SelectionEvent::Click, 4),
@@ -2941,42 +2944,51 @@ void tst_QAbstractItemView::mouseSelection_data()
// Extended selection: Press selects a single item
QTest::addRow("Extended:Press") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 3)}
<< QList{3};
QTest::addRow("Extended:Press twice") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 3),
SelectionEvent(SelectionEvent::Press, 3)}
<< QList{3};
QTest::addRow("Extended:Press,Press") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 2),
SelectionEvent(SelectionEvent::Press, 3)}
<< QList{3};
// Extended selection: press with Ctrl toggles item
QTest::addRow("Extended:Press,Toggle") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 3),
SelectionEvent(SelectionEvent::Click, Qt::ControlModifier, 3)}
<< QList<int>{};
QTest::addRow("Extended:Press,Add") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1),
SelectionEvent(SelectionEvent::Click, Qt::ControlModifier, 3)}
<< QList{1, 3};
// Extended selection: Shift creates a range between first and last pressed
QTest::addRow("Extended:Press,Range") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1),
SelectionEvent(SelectionEvent::Press, Qt::ShiftModifier, 5)}
<< QList{1, 2, 3, 4, 5};
QTest::addRow("Extended:Press,Range,Fix Range") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 1),
SelectionEvent(SelectionEvent::Press, Qt::ShiftModifier, 5),
SelectionEvent(SelectionEvent::Press, Qt::ShiftModifier, 3)}
<< QList{1, 2, 3};
// Extended: dragging extends the selection
QTest::addRow("Extended:Press,Drag") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 2),
SelectionEvent(SelectionEvent::Move, 5)}
<< QList{2, 3, 4, 5};
// Extended: Ctrl+Press-dragging extends the selection
QTest::addRow("Extended:Press,Drag;Ctrl-Press,Drag") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Press, 2),
SelectionEvent(SelectionEvent::Move, 5),
SelectionEvent(SelectionEvent::Release),
@@ -2986,6 +2998,7 @@ void tst_QAbstractItemView::mouseSelection_data()
<< QList{2, 3, 4, 5, 6, 7, 8};
// Extended: Ctrl+Press-dragging in a selection should not deselect #QTBUG-59888
QTest::addRow("Extended:Ctrl-Drag selection") << QAbstractItemView::ExtendedSelection << true
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Click, 2),
SelectionEvent(SelectionEvent::Click, Qt::ShiftModifier, 5),
SelectionEvent(SelectionEvent::Press, Qt::ControlModifier, 3),
@@ -2995,6 +3008,7 @@ void tst_QAbstractItemView::mouseSelection_data()
<< QList{2, 3, 4, 5};
// Extended: Ctrl+Press-dragging with a selection extends, then drags #QTBUG-59888
QTest::addRow("Extended:Ctrl-Drag selection") << QAbstractItemView::ExtendedSelection << true
+ << QAbstractItemView::NoEditTriggers
<< QList{SelectionEvent(SelectionEvent::Click, 2),
SelectionEvent(SelectionEvent::Click, Qt::ShiftModifier, 5),
SelectionEvent(SelectionEvent::Press, Qt::ControlModifier, 6),
@@ -3002,12 +3016,37 @@ void tst_QAbstractItemView::mouseSelection_data()
// two moves needed because of distance and state logic in 7QAbstractItemView
SelectionEvent(SelectionEvent::Move, Qt::ControlModifier, 8)}
<< QList{2, 3, 4, 5, 6};
+ // Extended: when drag is enabled, click with Ctrl toggles item instead of editing # QTBUG-111131
+ QTest::addRow("Extended:Click,Toggle,editable") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::SelectedClicked
+ << QList{SelectionEvent(SelectionEvent::Click, 3),
+ SelectionEvent(SelectionEvent::Click, Qt::ControlModifier, 3)}
+ << QList<int>{};
+ QTest::addRow("Extended:Click,Toggle,dragable,editable") << QAbstractItemView::ExtendedSelection << true
+ << QAbstractItemView::SelectedClicked
+ << QList{SelectionEvent(SelectionEvent::Click, 3),
+ SelectionEvent(SelectionEvent::Click, Qt::ControlModifier, 3)}
+ << QList<int>{};
+ // Extended: when drag is enabled, click on selected without Ctrl clears before editing
+ QTest::addRow("Extended:Range,Click,editable") << QAbstractItemView::ExtendedSelection << false
+ << QAbstractItemView::SelectedClicked
+ << QList{SelectionEvent(SelectionEvent::Click, 1),
+ SelectionEvent(SelectionEvent::Click, Qt::ShiftModifier, 3),
+ SelectionEvent(SelectionEvent::Click, 2)}
+ << QList<int>{2};
+ QTest::addRow("Extended:Range,Click,dragable,editable") << QAbstractItemView::ExtendedSelection << true
+ << QAbstractItemView::SelectedClicked
+ << QList{SelectionEvent(SelectionEvent::Click, 1),
+ SelectionEvent(SelectionEvent::Click, Qt::ShiftModifier, 3),
+ SelectionEvent(SelectionEvent::Click, 2)}
+ << QList<int>{2};
}
void tst_QAbstractItemView::mouseSelection()
{
QFETCH(QAbstractItemView::SelectionMode, selectionMode);
QFETCH(bool, dragEnabled);
+ QFETCH(QAbstractItemView::EditTrigger, editTrigger);
QFETCH(QList<SelectionEvent>, selectionEvents);
QFETCH(QList<int>, selectedRows);
@@ -3016,7 +3055,7 @@ void tst_QAbstractItemView::mouseSelection()
for (int i = 0; i < 10; ++i) {
QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
item->setDragEnabled(dragEnabled);
- item->setEditable(false);
+ item->setEditable(editTrigger != QAbstractItemView::NoEditTriggers);
parentItem->appendRow(item);
}
@@ -3026,13 +3065,14 @@ void tst_QAbstractItemView::mouseSelection()
view->setModel(&model);
view->setDragEnabled(dragEnabled);
view->setSelectionMode(selectionMode);
+ view->setEditTriggers(editTrigger);
view->show();
QVERIFY(QTest::qWaitForWindowActive(view));
Qt::MouseButton buttonDown = Qt::NoButton;
int targetRow = -1;
QModelIndex pressedIndex;
- for (const auto &event : qAsConst(selectionEvents)) {
+ for (const auto &event : std::as_const(selectionEvents)) {
if (event.row != -1)
targetRow = event.row;
const QModelIndex targetIndex = model.index(targetRow, 0);
@@ -3077,6 +3117,37 @@ void tst_QAbstractItemView::mouseSelection()
}
/*!
+ Make sure that when clicking on empty space in the view, we don't
+ unselect the current row.
+ QTBUG-105870
+*/
+void tst_QAbstractItemView::keepSingleSelectionOnEmptyAreaClick()
+{
+ QListWidget view;
+ view.setSelectionMode(QAbstractItemView::SingleSelection);
+ QListWidgetItem *lastItem;
+ for (int i = 0; i < 5; i++)
+ lastItem = new QListWidgetItem("item " + QString::number(i), &view);
+
+ // Make widget large enough so that there is empty area below the last item
+ view.setFixedSize(300, 500);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowActive(&view));
+
+ // Select third row
+ view.setCurrentRow(2);
+
+ // Click below the last row
+ QPoint targetPoint = view.visualItemRect(lastItem).bottomLeft();
+ targetPoint += QPoint(10, 10);
+
+ QTest::mouseClick(view.viewport(), Qt::MouseButton::LeftButton, Qt::NoModifier, targetPoint);
+
+ QCOMPARE(view.currentRow(), 2);
+ QVERIFY(view.currentItem()->isSelected());
+}
+
+/*!
Verify that scrolling an autoScroll enabled itemview with a QScroller
produces a continuous, smooth scroll without any jumping around due to
the currentItem negotiation between QAbstractItemView and QScroller.
@@ -3084,6 +3155,9 @@ void tst_QAbstractItemView::mouseSelection()
*/
void tst_QAbstractItemView::scrollerSmoothScroll()
{
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
+ QSKIP("QWindow::requestActivate() is not supported.");
+
QListWidget view;
view.setAutoScroll(true);
view.setVerticalScrollMode(QListView::ScrollPerPixel);
@@ -3153,6 +3227,9 @@ void tst_QAbstractItemView::inputMethodOpensEditor_data()
void tst_QAbstractItemView::inputMethodOpensEditor()
{
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
+ QSKIP("QWindow::requestActivate() is not supported.");
+
QTableWidget tableWidget(50, 50);
tableWidget.setEditTriggers(QAbstractItemView::AnyKeyPressed);
for (int r = 0; r < 50; ++r) {
@@ -3321,7 +3398,7 @@ void tst_QAbstractItemView::selectionAutoScrolling()
QTRY_COMPARE(scrollBar->value(), 0);
else
QTRY_COMPARE(scrollBar->value(), scrollBar->maximum());
- QVERIFY(listview.selectionModel()->selectedIndexes().count() > 0);
+ QVERIFY(listview.selectionModel()->selectedIndexes().size() > 0);
QTest::mouseRelease(listview.viewport(), Qt::LeftButton, Qt::NoModifier, dragPoint);
}
diff --git a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
index 9c37e0af6d..8bdbc08467 100644
--- a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
+++ b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp
@@ -497,11 +497,11 @@ void tst_QColumnView::selectAll()
view.setModel(&m_fakeDirModel);
view.selectAll();
- QVERIFY(view.selectionModel()->selectedIndexes().count() >= 0);
+ QVERIFY(view.selectionModel()->selectedIndexes().size() >= 0);
view.setCurrentIndex(m_fakeDirHomeIndex);
view.selectAll();
- QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);
+ QVERIFY(view.selectionModel()->selectedIndexes().size() > 0);
QModelIndex file;
for (int i = 0; i < m_fakeDirModel.rowCount(m_fakeDirHomeIndex); ++i) {
@@ -512,10 +512,10 @@ void tst_QColumnView::selectAll()
}
view.setCurrentIndex(file);
view.selectAll();
- QVERIFY(view.selectionModel()->selectedIndexes().count() > 0);
+ QVERIFY(view.selectionModel()->selectedIndexes().size() > 0);
view.setCurrentIndex(QModelIndex());
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 0);
}
void tst_QColumnView::clicked()
@@ -536,13 +536,13 @@ void tst_QColumnView::clicked()
QPoint localPoint = view.visualRect(m_fakeDirHomeIndex).center();
QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, localPoint);
- QCOMPARE(clickedSpy.count(), 1);
+ QCOMPARE(clickedSpy.size(), 1);
QCoreApplication::processEvents();
if (sizeof(qreal) != sizeof(double))
QSKIP("Skipped due to rounding errors");
- for (int i = 0; i < view.createdColumns.count(); ++i) {
+ for (int i = 0; i < view.createdColumns.size(); ++i) {
QAbstractItemView *column = view.createdColumns.at(i);
if (column && column->selectionModel() && (column->rootIndex() == m_fakeDirHomeIndex))
QVERIFY(column->selectionModel()->selectedIndexes().isEmpty());
@@ -560,7 +560,7 @@ void tst_QColumnView::selectedColumns()
QTest::qWait(ANIMATION_DELAY);
- for (int i = 0; i < view.createdColumns.count(); ++i) {
+ for (int i = 0; i < view.createdColumns.size(); ++i) {
QAbstractItemView *column = view.createdColumns.at(i);
if (!column)
continue;
@@ -591,7 +591,7 @@ void tst_QColumnView::setSelectionModel()
view.setSelectionModel(selectionModel);
bool found = false;
- for (int i = 0; i < view.createdColumns.count(); ++i) {
+ for (int i = 0; i < view.createdColumns.size(); ++i) {
if (view.createdColumns.at(i)->selectionModel() == selectionModel) {
found = true;
break;
@@ -631,7 +631,7 @@ void tst_QColumnView::moveGrip_basic()
view.setMinimumWidth(200);
grip->moveGrip(-800);
QCOMPARE(view.width(), 200);
- QCOMPARE(spy.count(), 5);
+ QCOMPARE(spy.size(), 5);
}
void tst_QColumnView::moveGrip_data()
@@ -659,7 +659,7 @@ void tst_QColumnView::moveGrip()
topLevel.show();
QVERIFY(QTest::qWaitForWindowActive(&topLevel));
- int columnNum = view.createdColumns.count() - 2;
+ int columnNum = view.createdColumns.size() - 2;
QVERIFY(columnNum >= 0);
const QObjectList list = view.createdColumns[columnNum]->children();
QColumnViewGrip *grip = nullptr;
@@ -687,7 +687,7 @@ void tst_QColumnView::doubleClick()
QCOMPARE(view.width(), 200);
QTest::mouseDClick(grip, Qt::LeftButton);
QCOMPARE(view.width(), view.sizeHint().width());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QColumnView::gripMoved()
@@ -711,7 +711,7 @@ void tst_QColumnView::gripMoved()
QCoreApplication::processEvents();
QTest::mouseRelease(grip, Qt::LeftButton);
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE(spy.size(), 1);
QCOMPARE(view.width(), oldWidth + 65);
}
@@ -776,7 +776,7 @@ void tst_QColumnView::setPreviewWidget()
void tst_QColumnView::sizes()
{
QColumnView view;
- QCOMPARE(view.columnWidths().count(), 0);
+ QCOMPARE(view.columnWidths().size(), 0);
const QList<int> newSizes{ 10, 4, 50, 6 };
@@ -787,16 +787,16 @@ void tst_QColumnView::sizes()
view.setModel(&m_fakeDirModel);
view.setCurrentIndex(m_fakeDirHomeIndex);
- QList<int> postSizes = view.columnWidths().mid(0, newSizes.count());
- QCOMPARE(postSizes, newSizes.mid(0, postSizes.count()));
+ QList<int> postSizes = view.columnWidths().mid(0, newSizes.size());
+ QCOMPARE(postSizes, newSizes.mid(0, postSizes.size()));
- QVERIFY(view.columnWidths().count() > 1);
+ QVERIFY(view.columnWidths().size() > 1);
QList<int> smallerSizes{ 6 };
view.setColumnWidths(smallerSizes);
QList<int> expectedSizes = newSizes;
expectedSizes[0] = 6;
- postSizes = view.columnWidths().mid(0, newSizes.count());
- QCOMPARE(postSizes, expectedSizes.mid(0, postSizes.count()));
+ postSizes = view.columnWidths().mid(0, newSizes.size());
+ QCOMPARE(postSizes, expectedSizes.mid(0, postSizes.size()));
}
void tst_QColumnView::rowDelegate()
@@ -806,7 +806,7 @@ void tst_QColumnView::rowDelegate()
view.setItemDelegateForRow(3, d);
view.setModel(&m_fakeDirModel);
- for (int i = 0; i < view.createdColumns.count(); ++i) {
+ for (int i = 0; i < view.createdColumns.size(); ++i) {
QAbstractItemView *column = view.createdColumns.at(i);
QCOMPARE(column->itemDelegateForRow(3), d);
}
@@ -956,7 +956,7 @@ void tst_QColumnView::dynamicModelChanges()
model.appendRow(item);
QVERIFY(QTest::qWaitForWindowExposed(&view)); //let the time for painting to occur
- QTRY_COMPARE(delegate.paintedIndexes.count(), 1);
+ QTRY_COMPARE(delegate.paintedIndexes.size(), 1);
QCOMPARE(*delegate.paintedIndexes.begin(), model.index(0,0));
}
diff --git a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
index 41db835f0f..c95d179542 100644
--- a/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
+++ b/tests/auto/widgets/itemviews/qdatawidgetmapper/tst_qdatawidgetmapper.cpp
@@ -252,22 +252,22 @@ void tst_QDataWidgetMapper::currentIndexChanged()
QSignalSpy spy(&mapper, &QDataWidgetMapper::currentIndexChanged);
mapper.toFirst();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.takeFirst().at(0).toInt(), 0);
mapper.toNext();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.takeFirst().at(0).toInt(), 1);
mapper.setCurrentIndex(7);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.takeFirst().at(0).toInt(), 7);
mapper.setCurrentIndex(-1);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
mapper.setCurrentIndex(42);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QDataWidgetMapper::changingValues()
@@ -424,21 +424,21 @@ void tst_QDataWidgetMapper::textEditDoesntChangeFocusOnTab_qtbug3305()
int closeEditorSpyCount = 0;
const QString textEditContents = textEdit->toPlainText();
- QCOMPARE(closeEditorSpy.count(), closeEditorSpyCount);
+ QCOMPARE(closeEditorSpy.size(), closeEditorSpyCount);
QVERIFY(lineEdit->hasFocus());
QVERIFY(!textEdit->hasFocus());
// this will generate a closeEditor for the tab key, and another for the focus out
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Tab);
closeEditorSpyCount += 2;
- QTRY_COMPARE(closeEditorSpy.count(), closeEditorSpyCount);
+ QTRY_COMPARE(closeEditorSpy.size(), closeEditorSpyCount);
QTRY_VERIFY(textEdit->hasFocus());
QVERIFY(!lineEdit->hasFocus());
// now that the text edit is focused, a tab keypress will insert a tab, not change focus
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Tab);
- QTRY_COMPARE(closeEditorSpy.count(), closeEditorSpyCount);
+ QTRY_COMPARE(closeEditorSpy.size(), closeEditorSpyCount);
QVERIFY(!lineEdit->hasFocus());
QVERIFY(textEdit->hasFocus());
@@ -449,7 +449,7 @@ void tst_QDataWidgetMapper::textEditDoesntChangeFocusOnTab_qtbug3305()
QTRY_VERIFY(lineEdit->hasFocus());
QVERIFY(!textEdit->hasFocus());
++closeEditorSpyCount;
- QCOMPARE(closeEditorSpy.count(), closeEditorSpyCount);
+ QCOMPARE(closeEditorSpy.size(), closeEditorSpyCount);
}
QTEST_MAIN(tst_QDataWidgetMapper)
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 93f991b0fe..a0aeb0cc12 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -474,7 +474,7 @@ void tst_QHeaderView::init()
QSignalSpy spy(view, &QHeaderView::sectionCountChanged);
view->setModel(model);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
view->resize(200,200);
}
@@ -795,10 +795,10 @@ void tst_QHeaderView::visualIndexAt()
for (int i : hidden)
view->setSectionHidden(i, true);
- for (int j = 0; j < from.count(); ++j)
+ for (int j = 0; j < from.size(); ++j)
view->moveSection(from.at(j), to.at(j));
- for (int k = 0; k < coordinate.count(); ++k)
+ for (int k = 0; k < coordinate.size(); ++k)
QTRY_COMPARE(view->visualIndexAt(coordinate.at(k)), visual.at(k));
}
@@ -910,14 +910,14 @@ void tst_QHeaderView::swapSections()
QCOMPARE(view->sectionsMoved(), true);
for (int i = 0; i < view->count(); ++i)
QCOMPARE(view->logicalIndex(i), logical.at(i));
- QCOMPARE(spy1.count(), 4);
+ QCOMPARE(spy1.size(), 4);
logical = { 3, 1, 2, 0 };
view->swapSections(3, 0);
QCOMPARE(view->sectionsMoved(), true);
for (int j = 0; j < view->count(); ++j)
QCOMPARE(view->logicalIndex(j), logical.at(j));
- QCOMPARE(spy1.count(), 6);
+ QCOMPARE(spy1.size(), 6);
}
void tst_QHeaderView::moveSection_data()
@@ -963,9 +963,9 @@ void tst_QHeaderView::moveSection()
QFETCH(const IntList, logical);
QFETCH(int, count);
- QCOMPARE(from.count(), to.count());
- QCOMPARE(from.count(), moved.count());
- QCOMPARE(view->count(), logical.count());
+ QCOMPARE(from.size(), to.size());
+ QCOMPARE(from.size(), moved.size());
+ QCOMPARE(view->count(), logical.size());
QSignalSpy spy1(view, &QHeaderView::sectionMoved);
QCOMPARE(view->sectionsMoved(), false);
@@ -973,7 +973,7 @@ void tst_QHeaderView::moveSection()
for (int h : hidden)
view->setSectionHidden(h, true);
- for (int i = 0; i < from.count(); ++i) {
+ for (int i = 0; i < from.size(); ++i) {
view->moveSection(from.at(i), to.at(i));
QCOMPARE(view->sectionsMoved(), moved.at(i));
}
@@ -981,7 +981,7 @@ void tst_QHeaderView::moveSection()
for (int j = 0; j < view->count(); ++j)
QCOMPARE(view->logicalIndex(j), logical.at(j));
- QCOMPARE(spy1.count(), count);
+ QCOMPARE(spy1.size(), count);
}
void tst_QHeaderView::resizeAndMoveSection_data()
@@ -1166,14 +1166,14 @@ void tst_QHeaderView::resizeWithResizeModes()
QFETCH(const IntList, expected);
view->setStretchLastSection(false);
- for (int i = 0; i < sections.count(); ++i) {
+ for (int i = 0; i < sections.size(); ++i) {
view->resizeSection(i, sections.at(i));
view->setSectionResizeMode(i, modes.at(i));
}
topLevel->show();
QVERIFY(QTest::qWaitForWindowExposed(topLevel));
view->resize(size, size);
- for (int j = 0; j < expected.count(); ++j)
+ for (int j = 0; j < expected.size(); ++j)
QCOMPARE(view->sectionSize(j), expected.at(j));
}
@@ -1200,7 +1200,7 @@ void tst_QHeaderView::moveAndInsertSection()
view->moveSection(from, to);
model->insertRow(insert);
- for (int i = 0; i < mapping.count(); ++i)
+ for (int i = 0; i < mapping.size(); ++i)
QCOMPARE(view->logicalIndex(i), mapping.at(i));
}
@@ -1271,21 +1271,21 @@ void tst_QHeaderView::resizeSection()
view->setSectionsMovable(true);
view->setStretchLastSection(false);
- for (int i = 0; i < logical.count(); ++i)
+ for (int i = 0; i < logical.size(); ++i)
if (logical.at(i) > -1 && logical.at(i) < view->count()) // for now
view->setSectionResizeMode(logical.at(i), mode.at(i));
- for (int j = 0; j < logical.count(); ++j)
+ for (int j = 0; j < logical.size(); ++j)
view->resizeSection(logical.at(j), initial);
QSignalSpy spy(view, &QHeaderView::sectionResized);
- for (int k = 0; k < logical.count(); ++k)
+ for (int k = 0; k < logical.size(); ++k)
view->resizeSection(logical.at(k), size.at(k));
- QCOMPARE(spy.count(), resized);
+ QCOMPARE(spy.size(), resized);
- for (int l = 0; l < logical.count(); ++l)
+ for (int l = 0; l < logical.size(); ++l)
QCOMPARE(view->sectionSize(logical.at(l)), expected.at(l));
}
@@ -1338,19 +1338,19 @@ void tst_QHeaderView::clearSectionSorting()
QSignalSpy sectionClickedSpy(&h, &QHeaderView::sectionClicked);
QVERIFY(sectionClickedSpy.isValid());
- QCOMPARE(sectionClickedSpy.count(), 0);
+ QCOMPARE(sectionClickedSpy.size(), 0);
QSignalSpy sortIndicatorChangedSpy(&h, &QHeaderView::sortIndicatorChanged);
QVERIFY(sortIndicatorChangedSpy.isValid());
- QCOMPARE(sortIndicatorChangedSpy.count(), 0);
+ QCOMPARE(sortIndicatorChangedSpy.size(), 0);
enum { Count = 30 };
// normal behavior: clicking multiple times will just toggle the sort indicator
for (int i = 0; i < Count; ++i) {
QTest::mouseClick(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
- QCOMPARE(sectionClickedSpy.count(), i + 1);
- QCOMPARE(sortIndicatorChangedSpy.count(), i + 1);
+ QCOMPARE(sectionClickedSpy.size(), i + 1);
+ QCOMPARE(sortIndicatorChangedSpy.size(), i + 1);
QCOMPARE(h.sortIndicatorSection(), 0);
const auto expectedOrder = (i % 2) == 0 ? Qt::AscendingOrder : Qt::DescendingOrder;
QCOMPARE(h.sortIndicatorOrder(), expectedOrder);
@@ -1367,8 +1367,8 @@ void tst_QHeaderView::clearSectionSorting()
// clearing behavior: clicking multiple times will be tristate (asc, desc, nothing)
for (int i = 0; i < Count; ++i) {
QTest::mouseClick(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
- QCOMPARE(sectionClickedSpy.count(), i + 1);
- QCOMPARE(sortIndicatorChangedSpy.count(), i + 1);
+ QCOMPARE(sectionClickedSpy.size(), i + 1);
+ QCOMPARE(sortIndicatorChangedSpy.size(), i + 1);
switch (i % 3) {
case 0:
QCOMPARE(h.sortIndicatorSection(), 0);
@@ -1736,7 +1736,7 @@ static void saveRestoreImpl(const QByteArray &state, SaveRestoreOption option)
h2.setModel(&m);
QVERIFY(h2.restoreState(state));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.at(0).at(0).toInt(), 2);
QCOMPARE(h2.logicalIndex(0), 2);
@@ -2040,9 +2040,9 @@ void tst_QHeaderView::sectionPressedSignal()
QSignalSpy spy(&h, &QHeaderView::sectionPressed);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
QTest::mousePress(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
- QCOMPARE(spy.count(), count);
+ QCOMPARE(spy.size(), count);
}
void tst_QHeaderView::sectionClickedSignal()
@@ -2062,19 +2062,19 @@ void tst_QHeaderView::sectionClickedSignal()
QSignalSpy spy(&h, &QHeaderView::sectionClicked);
QSignalSpy spy2(&h, &QHeaderView::sortIndicatorChanged);
- QCOMPARE(spy.count(), 0);
- QCOMPARE(spy2.count(), 0);
+ QCOMPARE(spy.size(), 0);
+ QCOMPARE(spy2.size(), 0);
QTest::mouseClick(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
- QCOMPARE(spy.count(), count);
- QCOMPARE(spy2.count(), count);
+ QCOMPARE(spy.size(), count);
+ QCOMPARE(spy2.size(), count);
//now let's try with the sort indicator hidden (the result should be the same
spy.clear();
spy2.clear();
h.setSortIndicatorShown(false);
QTest::mouseClick(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
- QCOMPARE(spy.count(), count);
- QCOMPARE(spy2.count(), count);
+ QCOMPARE(spy.size(), count);
+ QCOMPARE(spy2.size(), count);
}
void tst_QHeaderView::defaultSectionSize_data()
@@ -2255,7 +2255,7 @@ void tst_QHeaderView::task236450_hidden()
for (int i : hide1)
view.hideSection(i);
- QCOMPARE(view.hiddenSectionCount(), hide1.count());
+ QCOMPARE(view.hiddenSectionCount(), hide1.size());
for (int i = 0; i < 6; i++)
QCOMPARE(!view.isSectionHidden(i), !hide1.contains(i));
@@ -2263,13 +2263,13 @@ void tst_QHeaderView::task236450_hidden()
view.scheduleDelayedItemsLayout();
view.executeDelayedItemsLayout(); //force to do a relayout
- QCOMPARE(view.hiddenSectionCount(), hide1.count());
+ QCOMPARE(view.hiddenSectionCount(), hide1.size());
for (int i = 0; i < 6; i++) {
QCOMPARE(!view.isSectionHidden(i), !hide1.contains(i));
view.setSectionHidden(i, hide2.contains(i));
}
- QCOMPARE(view.hiddenSectionCount(), hide2.count());
+ QCOMPARE(view.hiddenSectionCount(), hide2.size());
for (int i = 0; i < 6; i++)
QCOMPARE(!view.isSectionHidden(i), !hide2.contains(i));
}
@@ -2301,10 +2301,10 @@ void tst_QHeaderView::task248050_hideRow()
//returns 0 if everything is fine.
static int checkHeaderViewOrder(const QHeaderView *view, const IntList &expected)
{
- if (view->count() != expected.count())
+ if (view->count() != expected.size())
return 1;
- for (int i = 0; i < expected.count(); i++) {
+ for (int i = 0; i < expected.size(); i++) {
if (view->logicalIndex(i) != expected.at(i))
return i + 10;
if (view->visualIndex(expected.at(i)) != i)
@@ -2395,8 +2395,8 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
QPoint(tv.horizontalHeader()->sectionViewportPosition(11) +
tv.horizontalHeader()->sectionSize(11) / 2, 5));
- QCOMPARE(clickedSpy.count(), 1);
- QCOMPARE(pressedSpy.count(), 1);
+ QCOMPARE(clickedSpy.size(), 1);
+ QCOMPARE(pressedSpy.size(), 1);
QCOMPARE(clickedSpy.at(0).at(0).toInt(), 11);
QCOMPARE(pressedSpy.at(0).at(0).toInt(), 11);
@@ -2404,8 +2404,8 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QPoint(tv.horizontalHeader()->sectionViewportPosition(8) +
tv.horizontalHeader()->sectionSize(0) / 2, 5));
- QCOMPARE(clickedSpy.count(), 2);
- QCOMPARE(pressedSpy.count(), 2);
+ QCOMPARE(clickedSpy.size(), 2);
+ QCOMPARE(pressedSpy.size(), 2);
QCOMPARE(clickedSpy.at(1).at(0).toInt(), 8);
QCOMPARE(pressedSpy.at(1).at(0).toInt(), 8);
@@ -2413,8 +2413,8 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QPoint(tv.horizontalHeader()->sectionViewportPosition(0) +
tv.horizontalHeader()->sectionSize(0) / 2, 5));
- QCOMPARE(clickedSpy.count(), 3);
- QCOMPARE(pressedSpy.count(), 3);
+ QCOMPARE(clickedSpy.size(), 3);
+ QCOMPARE(pressedSpy.size(), 3);
QCOMPARE(clickedSpy.at(2).at(0).toInt(), 0);
QCOMPARE(pressedSpy.at(2).at(0).toInt(), 0);
}
@@ -2541,7 +2541,7 @@ public:
void insertRowAtBeginning()
{
Q_EMIT layoutAboutToBeChanged();
- m_displayNames.insert(0, QStringLiteral("Item %1").arg(m_displayNames.count()));
+ m_displayNames.insert(0, QStringLiteral("Item %1").arg(m_displayNames.size()));
// Rows are always inserted at the beginning, so move all others.
const auto pl = persistentIndexList();
// The vertical header view will have a persistent index stored here on the second call to insertRowAtBeginning.
@@ -2557,7 +2557,7 @@ public:
QModelIndex index(int row, int column, const QModelIndex &) const override { return createIndex(row, column); }
QModelIndex parent(const QModelIndex &) const override { return QModelIndex(); }
- int rowCount(const QModelIndex &) const override { return m_displayNames.count(); }
+ int rowCount(const QModelIndex &) const override { return m_displayNames.size(); }
int columnCount(const QModelIndex &) const override { return 1; }
private:
diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
index 68a7268473..aa17026daf 100644
--- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
+++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp
@@ -205,6 +205,8 @@ private slots:
void dateTextForRole_data();
void dateTextForRole();
+ void reuseEditor();
+
private:
#ifdef QT_BUILD_INTERNAL
struct RoleDelegate : public QItemDelegate
@@ -325,7 +327,7 @@ void tst_QItemDelegate::editorKeyPress()
view.edit(index);
QList<QLineEdit*> lineEditors = view.viewport()->findChildren<QLineEdit *>();
- QCOMPARE(lineEditors.count(), 1);
+ QCOMPARE(lineEditors.size(), 1);
QLineEdit *editor = lineEditors.at(0);
QCOMPARE(editor->selectedText(), initial);
@@ -353,7 +355,7 @@ void tst_QItemDelegate::doubleEditorNegativeInput()
view.edit(index);
QList<QDoubleSpinBox*> editors = view.viewport()->findChildren<QDoubleSpinBox *>();
- QCOMPARE(editors.count(), 1);
+ QCOMPARE(editors.size(), 1);
QDoubleSpinBox *editor = editors.at(0);
QCOMPARE(editor->value(), double(10));
@@ -670,33 +672,33 @@ void tst_QItemDelegate::testEventFilter()
//For each test we send a key event and check if signals were emitted.
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
QVERIFY(delegate.eventFilter(&widget, event));
- QCOMPARE(closeEditorSpy.count(), 1);
- QCOMPARE(commitDataSpy.count(), 1);
+ QCOMPARE(closeEditorSpy.size(), 1);
+ QCOMPARE(commitDataSpy.size(), 1);
delete event;
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Backtab, Qt::NoModifier);
QVERIFY(delegate.eventFilter(&widget, event));
- QCOMPARE(closeEditorSpy.count(), 2);
- QCOMPARE(commitDataSpy.count(), 2);
+ QCOMPARE(closeEditorSpy.size(), 2);
+ QCOMPARE(commitDataSpy.size(), 2);
delete event;
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
QVERIFY(delegate.eventFilter(&widget, event));
- QCOMPARE(closeEditorSpy.count(), 3);
- QCOMPARE(commitDataSpy.count(), 2);
+ QCOMPARE(closeEditorSpy.size(), 3);
+ QCOMPARE(commitDataSpy.size(), 2);
delete event;
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier);
QVERIFY(!delegate.eventFilter(&widget, event));
- QCOMPARE(closeEditorSpy.count(), 3);
- QCOMPARE(commitDataSpy.count(), 2);
+ QCOMPARE(closeEditorSpy.size(), 3);
+ QCOMPARE(commitDataSpy.size(), 2);
delete event;
//Subtest focusEvent
event = new QFocusEvent(QEvent::FocusOut);
QVERIFY(!delegate.eventFilter(&widget, event));
- QCOMPARE(closeEditorSpy.count(), 4);
- QCOMPARE(commitDataSpy.count(), 3);
+ QCOMPARE(closeEditorSpy.size(), 4);
+ QCOMPARE(commitDataSpy.size(), 3);
delete event;
}
@@ -1312,7 +1314,7 @@ void tst_QItemDelegate::enterKey()
view.edit(index);
QList<QWidget*> lineEditors = view.viewport()->findChildren<QWidget *>(QString::fromLatin1("TheEditor"));
- QCOMPARE(lineEditors.count(), 1);
+ QCOMPARE(lineEditors.size(), 1);
QPointer<QWidget> editor = lineEditors.at(0);
QCOMPARE(editor->hasFocus(), true);
@@ -1346,7 +1348,7 @@ void tst_QItemDelegate::task257859_finalizeEdit()
view.edit(index);
QList<QLineEdit *> lineEditors = view.viewport()->findChildren<QLineEdit *>();
- QCOMPARE(lineEditors.count(), 1);
+ QCOMPARE(lineEditors.size(), 1);
QPointer<QWidget> editor = lineEditors.at(0);
QCOMPARE(editor->hasFocus(), true);
@@ -1477,7 +1479,7 @@ void tst_QItemDelegate::testLineEditValidation()
const auto findEditors = [&]() {
return view.findChildren<QLineEdit *>(QStringLiteral("TheEditor"));
};
- QCOMPARE(findEditors().count(), 1);
+ QCOMPARE(findEditors().size(), 1);
editor = findEditors().at(0);
editor->clear();
@@ -1497,7 +1499,7 @@ void tst_QItemDelegate::testLineEditValidation()
view.setCurrentIndex(index);
view.edit(index);
- QTRY_COMPARE(findEditors().count(), 1);
+ QTRY_COMPARE(findEditors().size(), 1);
editor = findEditors().at(0);
editor->clear();
@@ -1519,13 +1521,13 @@ void tst_QItemDelegate::testLineEditValidation()
// reset the view to forcibly close the editor
view.reset();
- QTRY_COMPARE(findEditors().count(), 0);
+ QTRY_COMPARE(findEditors().size(), 0);
// set a valid text again
view.setCurrentIndex(index);
view.edit(index);
- QTRY_COMPARE(findEditors().count(), 1);
+ QTRY_COMPARE(findEditors().size(), 1);
editor = findEditors().at(0);
editor->clear();
@@ -1617,6 +1619,74 @@ void tst_QItemDelegate::dateTextForRole()
#endif
}
+void tst_QItemDelegate::reuseEditor()
+{
+ class ReusingDelegate: public QItemDelegate {
+ public:
+ using QItemDelegate::QItemDelegate;
+ ~ReusingDelegate()
+ {
+ cached->deleteLater();
+ }
+
+ QWidget* createEditor(QWidget* parent,
+ const QStyleOptionViewItem&,
+ const QModelIndex&) const override
+ {
+ auto *cb = new QComboBox(parent);
+ cb->addItem("One");
+ cb->addItem("Two");
+ cb->setEditable(true);
+ return cb;
+ }
+
+ void setEditorData(QWidget* editor, const QModelIndex& index)
+ const override
+ {
+ auto *cb = qobject_cast<QComboBox*>(editor);
+ cb->setCurrentText(index.data(Qt::DisplayRole).toString());
+ }
+
+ void setModelData(QWidget* editor,
+ QAbstractItemModel* model,
+ const QModelIndex& index) const override
+ {
+ auto *cb = qobject_cast<QComboBox*>(editor);
+ model->setData(index, cb->currentText(), Qt::DisplayRole);
+ }
+
+ void destroyEditor(QWidget* editor, const QModelIndex&) const override
+ {
+ auto *cb = qobject_cast<QComboBox*>(editor);
+ cb->setParent(nullptr); // How to completely detach the editor from treeview ?
+ cb->hide();
+ cb->setEnabled(false);
+ cached = cb;
+ }
+
+ private:
+ mutable QComboBox* cached = nullptr;
+ };
+
+ QStandardItemModel model;
+ model.appendRow(new QStandardItem("One"));
+ model.appendRow(new QStandardItem("Two"));
+
+ ReusingDelegate delegate;
+
+ QTreeView tree;
+ tree.setModel(&model);
+ tree.setItemDelegate(&delegate);
+
+ tree.show();
+ QVERIFY(QTest::qWaitForWindowActive(&tree));
+
+ tree.edit(model.index(0, 0));
+ QTRY_VERIFY(qobject_cast<QComboBox *>(tree.focusWidget()));
+
+ tree.close();
+}
+
// ### _not_ covered:
// editing with a custom editor factory
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index ad52e40254..a154baad46 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -718,7 +718,7 @@ void tst_QListView::clicked()
continue;
QSignalSpy spy(&view, &QListView::clicked);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
}
@@ -1147,7 +1147,7 @@ void tst_QListView::selection()
v.setSelection(selectionRect, QItemSelectionModel::ClearAndSelect);
const QModelIndexList selected = v.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), expectedItems.count());
+ QCOMPARE(selected.size(), expectedItems.size());
for (const auto &idx : selected)
QVERIFY(expectedItems.contains(idx.row()));
}
@@ -1557,7 +1557,7 @@ void tst_QListView::task203585_selectAll()
QVERIFY(view.selectionModel()->selectedIndexes().isEmpty());
view.setRowHidden(0, false);
view.selectAll();
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
}
void tst_QListView::task228566_infiniteRelayout()
@@ -1642,7 +1642,7 @@ void tst_QListView::task196118_visualRegionForSelection()
view.selectionModel()->select(top1.index(), QItemSelectionModel::Select);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
QVERIFY(view.getVisualRegionForSelection().isEmpty());
}
@@ -1740,7 +1740,7 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes()
QTRY_COMPARE(view.currentIndex(), model.index(1, 0));
QModelIndexList selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 3);
+ QCOMPARE(selected.size(), 3);
QVERIFY(!selected.contains(model.index(0, 0)));
}
{ // Second test: QListView::TopToBottom flow
@@ -1767,7 +1767,7 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes()
QTRY_COMPARE(view.currentIndex(), model.index(1, 0));
QModelIndexList selected = view.selectionModel()->selectedIndexes();
- QCOMPARE(selected.count(), 3);
+ QCOMPARE(selected.size(), 3);
QVERIFY(!selected.contains(model.index(0, 0)));
}
}
@@ -1829,7 +1829,7 @@ void tst_QListView::clickOnViewportClearsSelection()
view.selectAll();
QModelIndex index = model.index(0);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
QVERIFY(view.selectionModel()->isSelected(index));
//we try to click outside of the index
@@ -1837,7 +1837,7 @@ void tst_QListView::clickOnViewportClearsSelection()
QTest::mousePress(view.viewport(), Qt::LeftButton, {}, point);
//at this point, the selection shouldn't have changed
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
QVERIFY(view.selectionModel()->isSelected(index));
QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, point);
@@ -1946,7 +1946,7 @@ void tst_QListView::taskQTBUG_435_deselectOnViewportClick()
view.setModel(&model);
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
view.selectAll();
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), model.rowCount());
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), model.rowCount());
const QRect itemRect = view.visualRect(model.index(model.rowCount() - 1));
@@ -1956,7 +1956,7 @@ void tst_QListView::taskQTBUG_435_deselectOnViewportClick()
QVERIFY(!view.selectionModel()->hasSelection());
view.selectAll();
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), model.rowCount());
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), model.rowCount());
//and now the right button
QTest::mouseClick(view.viewport(), Qt::RightButton, {}, p);
@@ -2715,9 +2715,9 @@ public:
if (idxPar.isValid()) {
TstMoveItem *parentItem = static_cast<TstMoveItem *>(idxPar.internalPointer());
Q_ASSERT(parentItem);
- cnt = parentItem->childItems.count();
+ cnt = parentItem->childItems.size();
} else {
- cnt = rootItem->childItems.count();
+ cnt = rootItem->childItems.size();
}
return cnt;
}
@@ -2734,9 +2734,9 @@ public:
if (parent.isValid()) {
TstMoveItem *parentItem = static_cast<TstMoveItem *>(parent.internalPointer());
Q_ASSERT(parentItem);
- ret = parentItem->childItems.count() > 0;
+ ret = parentItem->childItems.size() > 0;
} else {
- ret = rootItem->childItems.count() > 0;
+ ret = rootItem->childItems.size() > 0;
}
return ret;
}
@@ -2758,8 +2758,8 @@ public:
TstMoveItem *itmDestParent = itemAt(destinationParent);
if (itmSrcParent && sourceRow >= 0
- && sourceRow + count <= itmSrcParent->childItems.count()
- && itmDestParent && destinationChild <= itmDestParent->childItems.count()) {
+ && sourceRow + count <= itmSrcParent->childItems.size()
+ && itmDestParent && destinationChild <= itmDestParent->childItems.size()) {
beginMoveRows(sourceParent, sourceRow, sourceRow + count - 1,
destinationParent, destinationChild);
QList<TstMoveItem *> itemsToMove;
@@ -2767,7 +2767,7 @@ public:
TstMoveItem *itm = itmSrcParent->childItems.at(sourceRow+i);
itemsToMove.append(itm);
}
- for (int i = itemsToMove.count() -1; i >= 0; --i) {
+ for (int i = itemsToMove.size() -1; i >= 0; --i) {
TstMoveItem *itm = itemsToMove.at(i);
itm->parentItem->childItems.removeAll(itm);
itm->parentItem = itmDestParent;
@@ -3056,6 +3056,11 @@ void tst_QListView::spacingWithWordWrap()
}
};
+ QStyle *oldStyle = QApplication::style();
+ oldStyle->setParent(nullptr);
+ const auto resetStyle = qScopeGuard([oldStyle]{
+ QApplication::setStyle(oldStyle);
+ });
QApplication::setStyle(new MyStyle(scrollBarOverlap));
const int listViewResizeCount = 200;
@@ -3169,7 +3174,7 @@ void tst_QListView::scrollOnRemove()
model.removeRow(25);
// if nothing is selected now, then the view should not have scrolled
- if (!view.selectionModel()->selectedIndexes().count())
+ if (!view.selectionModel()->selectedIndexes().size())
QTRY_COMPARE(view.verticalScrollBar()->value(), item25Position);
}
diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
index 3fe14c682c..9ff0ac91e1 100644
--- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
+++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
@@ -344,7 +344,7 @@ void tst_QListWidget::addItems()
QString::number(testWidget->count() + 3),
label};
testWidget->addItems(stringList);
- QCOMPARE(testWidget->count(), count + stringList.count());
+ QCOMPARE(testWidget->count(), count + stringList.size());
QCOMPARE(testWidget->item(testWidget->count()-1)->text(), label);
}
@@ -356,30 +356,30 @@ void tst_QListWidget::openPersistentEditor()
QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count()));
testWidget->openPersistentEditor(item);
- int childCount = testWidget->viewport()->children().count();
+ int childCount = testWidget->viewport()->children().size();
testWidget->addItem(item);
testWidget->openPersistentEditor(item);
- QCOMPARE(childCount + 1, testWidget->viewport()->children().count());
+ QCOMPARE(childCount + 1, testWidget->viewport()->children().size());
}
void tst_QListWidget::closePersistentEditor()
{
// Boundary checking
- int childCount = testWidget->viewport()->children().count();
+ int childCount = testWidget->viewport()->children().size();
testWidget->closePersistentEditor(nullptr);
QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count()));
testWidget->closePersistentEditor(item);
- QCOMPARE(childCount, testWidget->viewport()->children().count());
+ QCOMPARE(childCount, testWidget->viewport()->children().size());
// Create something
testWidget->addItem(item);
testWidget->openPersistentEditor(item);
// actual test
- childCount = testWidget->viewport()->children().count();
+ childCount = testWidget->viewport()->children().size();
testWidget->closePersistentEditor(item);
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
- QCOMPARE(testWidget->viewport()->children().count(), childCount - 1);
+ QCOMPARE(testWidget->viewport()->children().size(), childCount - 1);
}
void tst_QListWidget::setItemHidden()
@@ -529,7 +529,7 @@ void tst_QListWidget::editItem()
item->setFlags(item->flags() | Qt::ItemIsEditable);
testWidget->addItem(item);
- int childCount = testWidget->viewport()->children().count();
+ int childCount = testWidget->viewport()->children().size();
QWidget *existsAlready = testWidget->indexWidget(testWidget->model()->index(testWidget->row(item), 0));
testWidget->editItem(item);
Qt::ItemFlags flags = item->flags();
@@ -537,7 +537,7 @@ void tst_QListWidget::editItem()
// There doesn't seem to be a way to detect if the item has already been edited...
if (!existsAlready && flags & Qt::ItemIsEditable && flags & Qt::ItemIsEnabled) {
QList<QObject *> children = testWidget->viewport()->children();
- QVERIFY(children.count() > childCount);
+ QVERIFY(children.size() > childCount);
bool found = false;
for (int i = 0; i < children.size(); ++i) {
if (children.at(i)->inherits("QExpandingLineEdit"))
@@ -545,7 +545,7 @@ void tst_QListWidget::editItem()
}
QVERIFY(found);
} else {
- QCOMPARE(testWidget->viewport()->children().count(), childCount);
+ QCOMPARE(testWidget->viewport()->children().size(), childCount);
}
}
@@ -554,12 +554,12 @@ void tst_QListWidget::findItems()
// This really just tests that the items that are returned are converted from index's to items correctly.
// Boundary checking
- QCOMPARE(testWidget->findItems("GirlsCanWearJeansAndCutTheirHairShort", Qt::MatchExactly).count(), 0);
+ QCOMPARE(testWidget->findItems("GirlsCanWearJeansAndCutTheirHairShort", Qt::MatchExactly).size(), 0);
populate();
for (int i = 0; i < testWidget->count(); ++i)
- QCOMPARE(testWidget->findItems(testWidget->item(i)->text(), Qt::MatchExactly).count(), 1);
+ QCOMPARE(testWidget->findItems(testWidget->item(i)->text(), Qt::MatchExactly).size(), 1);
}
@@ -574,8 +574,8 @@ void tst_QListWidget::insertItem_data()
QTest::newRow("Insert less then 0") << initialItems << -1 << "inserted" << 0;
QTest::newRow("Insert at 0") << initialItems << 0 << "inserted" << 0;
- QTest::newRow("Insert beyond count") << initialItems << initialItems.count()+1 << "inserted" << initialItems.count();
- QTest::newRow("Insert at count") << initialItems << initialItems.count() << "inserted" << initialItems.count();
+ QTest::newRow("Insert beyond count") << initialItems << initialItems.size()+1 << "inserted" << initialItems.size();
+ QTest::newRow("Insert at count") << initialItems << initialItems.size() << "inserted" << initialItems.size();
QTest::newRow("Insert in the middle") << initialItems << 1 << "inserted" << 1;
}
@@ -587,7 +587,7 @@ void tst_QListWidget::insertItem()
QFETCH(int, expectedIndex);
testWidget->insertItems(0, initialItems);
- QCOMPARE(testWidget->count(), initialItems.count());
+ QCOMPARE(testWidget->count(), initialItems.size());
testWidget->insertItem(insertIndex, itemLabel);
@@ -596,7 +596,7 @@ void tst_QListWidget::insertItem()
QCOMPARE(rcFirst[RowsInserted], expectedIndex);
QCOMPARE(rcLast[RowsInserted], expectedIndex);
- QCOMPARE(testWidget->count(), initialItems.count() + 1);
+ QCOMPARE(testWidget->count(), initialItems.size() + 1);
QCOMPARE(testWidget->item(expectedIndex)->text(), itemLabel);
}
@@ -669,8 +669,8 @@ void tst_QListWidget::insertItems()
for (int i = 0; i < testWidget->count(); ++i)
QCOMPARE(testWidget->item(i)->listWidget(), testWidget);
- QCOMPARE(itemChangedSpy.count(), 0);
- QCOMPARE(dataChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
+ QCOMPARE(dataChangedSpy.size(), 0);
}
void tst_QListWidget::itemAssignment()
@@ -825,7 +825,7 @@ void tst_QListWidget::selectedItems()
QListWidgetItem *item = testWidget->item(i);
item->setSelected(true);
QVERIFY(item->isSelected());
- QCOMPARE(testWidget->selectedItems().count(), 1);
+ QCOMPARE(testWidget->selectedItems().size(), 1);
}
//let's clear the selection
testWidget->clearSelection();
@@ -843,7 +843,7 @@ void tst_QListWidget::selectedItems()
// check that the correct number of items and the expected items are there
QList<QListWidgetItem *> selectedItems = testWidget->selectedItems();
- QCOMPARE(selectedItems.count(), expectedRows.count());
+ QCOMPARE(selectedItems.size(), expectedRows.size());
for (int row : expectedRows)
QVERIFY(selectedItems.contains(testWidget->item(row)));
@@ -939,20 +939,20 @@ void tst_QListWidget::moveItemsPriv()
else
QCOMPARE(testWidget->item(dstRow)->text(), QString::number(srcRow));
- QCOMPARE(beginMoveSpy.count(), 1);
+ QCOMPARE(beginMoveSpy.size(), 1);
const QList<QVariant> &beginMoveArgs = beginMoveSpy.takeFirst();
QCOMPARE(beginMoveArgs.at(1).toInt(), srcRow);
QCOMPARE(beginMoveArgs.at(2).toInt(), srcRow);
QCOMPARE(beginMoveArgs.at(4).toInt(), dstRow);
- QCOMPARE(movedSpy.count(), 1);
+ QCOMPARE(movedSpy.size(), 1);
const QList<QVariant> &movedArgs = movedSpy.takeFirst();
QCOMPARE(movedArgs.at(1).toInt(), srcRow);
QCOMPARE(movedArgs.at(2).toInt(), srcRow);
QCOMPARE(movedArgs.at(4).toInt(), dstRow);
} else {
- QCOMPARE(beginMoveSpy.count(), 0);
- QCOMPARE(movedSpy.count(), 0);
+ QCOMPARE(beginMoveSpy.size(), 0);
+ QCOMPARE(movedSpy.size(), 0);
}
}
@@ -1045,7 +1045,7 @@ void tst_QListWidget::sortItems()
testWidget->sortItems(order);
- QCOMPARE(testWidget->count(), expectedList.count());
+ QCOMPARE(testWidget->count(), expectedList.size());
for (int i = 0; i < testWidget->count(); ++i)
QCOMPARE(testWidget->item(i)->text(), expectedList.at(i).toString());
@@ -1115,7 +1115,7 @@ void tst_QListWidget::sortHiddenItems()
tw->setSortingEnabled(true);
tw->sortItems(order);
- QCOMPARE(tw->count(), expectedList.count());
+ QCOMPARE(tw->count(), expectedList.size());
for (int i = 0; i < tw->count(); ++i) {
QCOMPARE(tw->item(i)->text(), expectedList.at(i));
QCOMPARE(tw->item(i)->isHidden(), !expectedVisibility.at(i));
@@ -1212,17 +1212,17 @@ void tst_QListWidget::setData()
QFETCH(QVariantList, values);
QFETCH(int, expectedSignalCount);
- QCOMPARE(roles.count(), values.count());
+ QCOMPARE(roles.size(), values.size());
for (int manipulateModel = 0; manipulateModel < 2; ++manipulateModel) {
testWidget->clear();
testWidget->insertItems(0, initialItems);
- QCOMPARE(testWidget->count(), initialItems.count());
+ QCOMPARE(testWidget->count(), initialItems.size());
QSignalSpy itemChanged(testWidget, &QListWidget::itemChanged);
QSignalSpy dataChanged(testWidget->model(), &QAbstractItemModel::dataChanged);
- for (int i = 0; i < roles.count(); ++i) {
+ for (int i = 0; i < roles.size(); ++i) {
if (manipulateModel)
testWidget->model()->setData(
testWidget->model()->index(itemIndex, 0, testWidget->rootIndex()),
@@ -1233,12 +1233,12 @@ void tst_QListWidget::setData()
}
// make sure the data is actually set
- for (int i = 0; i < roles.count(); ++i)
+ for (int i = 0; i < roles.size(); ++i)
QCOMPARE(testWidget->item(itemIndex)->data(roles.at(i)), values.at(i));
// make sure we get the right number of emits
- QCOMPARE(itemChanged.count(), expectedSignalCount);
- QCOMPARE(dataChanged.count(), expectedSignalCount);
+ QCOMPARE(itemChanged.size(), expectedSignalCount);
+ QCOMPARE(dataChanged.size(), expectedSignalCount);
}
}
@@ -1380,11 +1380,11 @@ void tst_QListWidget::insertItemsWithSorting()
w.addItem(str);
break;
}
- QCOMPARE(w.count(), expectedItems.count());
+ QCOMPARE(w.count(), expectedItems.size());
for (int i = 0; i < w.count(); ++i)
QCOMPARE(w.item(i)->text(), expectedItems.at(i));
- for (int k = 0; k < persistent.count(); ++k)
+ for (int k = 0; k < persistent.size(); ++k)
QCOMPARE(persistent.at(k).row(), expectedRows.at(k));
}
}
@@ -1480,7 +1480,7 @@ void tst_QListWidget::itemData()
QCOMPARE(widget.currentRoles, QList<int> { Qt::UserRole + i });
}
QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0));
- QCOMPARE(flags.count(), 6);
+ QCOMPARE(flags.size(), 6);
for (int i = 0; i < 4; ++i)
QCOMPARE(flags[Qt::UserRole + i].toString(), QString::number(i + 1));
@@ -1524,19 +1524,19 @@ void tst_QListWidget::changeDataWithSorting()
QListWidgetItem *item = w.item(itemIndex);
item->setText(newValue);
- for (int i = 0; i < expectedItems.count(); ++i) {
+ for (int i = 0; i < expectedItems.size(); ++i) {
QCOMPARE(w.item(i)->text(), expectedItems.at(i));
- for (int j = 0; j < persistent.count(); ++j) {
+ for (int j = 0; j < persistent.size(); ++j) {
if (persistent.at(j).row() == i) // the same toplevel row
QCOMPARE(persistent.at(j).internalPointer(), static_cast<void *>(w.item(i)));
}
}
- for (int k = 0; k < persistent.count(); ++k)
+ for (int k = 0; k < persistent.size(); ++k)
QCOMPARE(persistent.at(k).row(), expectedRows.at(k));
- QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(layoutChangedSpy.count(), reorderingExpected ? 1 : 0);
+ QCOMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(layoutChangedSpy.size(), reorderingExpected ? 1 : 0);
}
void tst_QListWidget::itemWidget()
@@ -1615,7 +1615,7 @@ void tst_QListWidget::insertUnchanged()
QListWidget w;
QSignalSpy itemChangedSpy(&w, &QListWidget::itemChanged);
QListWidgetItem item("foo", &w);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
}
void tst_QListWidget::setSortingEnabled()
@@ -1706,12 +1706,12 @@ void tst_QListWidget::QTBUG8086_currentItemChangedOnClick()
QVERIFY(QTest::qWaitForWindowExposed(&win));
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
QTest::mouseClick(list.viewport(), Qt::LeftButton, {},
list.visualItemRect(list.item(2)).center());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
@@ -1810,14 +1810,14 @@ void tst_QListWidget::QTBUG50891_ensureSelectionModelSignalConnectionsAreSet()
QSignalSpy currentItemChangedSpy(&list, &QListWidget::currentItemChanged);
QSignalSpy itemSelectionChangedSpy(&list, &QListWidget::itemSelectionChanged);
- QCOMPARE(currentItemChangedSpy.count(), 0);
- QCOMPARE(itemSelectionChangedSpy.count(), 0);
+ QCOMPARE(currentItemChangedSpy.size(), 0);
+ QCOMPARE(itemSelectionChangedSpy.size(), 0);
QTest::mouseClick(list.viewport(), Qt::LeftButton, {},
list.visualItemRect(list.item(2)).center());
- QCOMPARE(currentItemChangedSpy.count(), 1);
- QCOMPARE(itemSelectionChangedSpy.count(), 1);
+ QCOMPARE(currentItemChangedSpy.size(), 1);
+ QCOMPARE(itemSelectionChangedSpy.size(), 1);
}
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index edd5453259..50d22addac 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -503,7 +503,7 @@ void tst_QTableView::emptyModel()
QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
view.setModel(&model);
view.show();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QTableView::removeRows_data()
@@ -528,10 +528,10 @@ void tst_QTableView::removeRows()
view.show();
model.removeLastRow();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
model.removeAllRows();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QTableView::removeColumns_data()
@@ -556,10 +556,10 @@ void tst_QTableView::removeColumns()
view.show();
model.removeLastColumn();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
model.removeAllColumns();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QTableView::keyboardNavigation_data()
@@ -1597,7 +1597,7 @@ void tst_QTableView::selection()
view.setSelection(QRect(x, y, width, height), command);
- QCOMPARE(view.selectedIndexes().count(), selectedCount);
+ QCOMPARE(view.selectedIndexes().size(), selectedCount);
}
void tst_QTableView::selectRow_data()
@@ -1710,12 +1710,12 @@ void tst_QTableView::selectRow()
view.setSelectionMode(mode);
view.setSelectionBehavior(behavior);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 0);
view.selectRow(row);
//test we have 10 items selected
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), selectedItems);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), selectedItems);
//test that all 10 items are in the same row
for (int i = 0; selectedItems > 0 && i < rowCount; ++i)
QCOMPARE(view.selectionModel()->selectedIndexes().at(i).row(), row);
@@ -1831,11 +1831,11 @@ void tst_QTableView::selectColumn()
view.setSelectionMode(mode);
view.setSelectionBehavior(behavior);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 0);
view.selectColumn(column);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), selectedItems);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), selectedItems);
for (int i = 0; selectedItems > 0 && i < columnCount; ++i)
QCOMPARE(view.selectionModel()->selectedIndexes().at(i).column(), column);
}
@@ -1980,22 +1980,22 @@ void tst_QTableView::selectall()
// try slot first
view.clearSelection();
- QCOMPARE(view.selectedIndexes().count(), 0);
+ QCOMPARE(view.selectedIndexes().size(), 0);
view.selectAll();
- QCOMPARE(view.selectedIndexes().count(), selectedCount);
+ QCOMPARE(view.selectedIndexes().size(), selectedCount);
// try by key sequence
view.clearSelection();
- QCOMPARE(view.selectedIndexes().count(), 0);
+ QCOMPARE(view.selectedIndexes().size(), 0);
QTest__keySequence(&view, QKeySequence(QKeySequence::SelectAll));
- QCOMPARE(view.selectedIndexes().count(), selectedCount);
+ QCOMPARE(view.selectedIndexes().size(), selectedCount);
// check again with no selection mode
view.clearSelection();
view.setSelectionMode(QAbstractItemView::NoSelection);
- QCOMPARE(view.selectedIndexes().count(), 0);
+ QCOMPARE(view.selectedIndexes().size(), 0);
QTest__keySequence(&view, QKeySequence(QKeySequence::SelectAll));
- QCOMPARE(view.selectedIndexes().count(), 0);
+ QCOMPARE(view.selectedIndexes().size(), 0);
}
#endif // QT_CONFIG(shortcut)
@@ -2188,7 +2188,7 @@ void tst_QTableView::resizeRowsToContents()
QSignalSpy resizedSpy(view.verticalHeader(), &QHeaderView::sectionResized);
view.resizeRowsToContents();
- QCOMPARE(resizedSpy.count(), model.rowCount());
+ QCOMPARE(resizedSpy.size(), model.rowCount());
for (int r = 0; r < model.rowCount(); ++r)
QCOMPARE(view.rowHeight(r), rowHeight);
}
@@ -2234,7 +2234,7 @@ void tst_QTableView::resizeColumnsToContents()
QSignalSpy resizedSpy(view.horizontalHeader(), &QHeaderView::sectionResized);
view.resizeColumnsToContents();
- QCOMPARE(resizedSpy.count(), model.columnCount());
+ QCOMPARE(resizedSpy.size(), model.columnCount());
for (int c = 0; c < model.columnCount(); ++c)
QCOMPARE(view.columnWidth(c), columnWidth);
}
@@ -2348,7 +2348,7 @@ void tst_QTableView::rowAt()
for (int r = 0; r < rowCount; ++r)
view.setRowHeight(r, rowHeight);
- for (int i = 0; i < hiddenRows.count(); ++i)
+ for (int i = 0; i < hiddenRows.size(); ++i)
view.hideRow(hiddenRows.at(i));
QCOMPARE(view.rowAt(coordinate), row);
@@ -2511,7 +2511,7 @@ void tst_QTableView::columnAt()
for (int c = 0; c < columnCount; ++c)
view.setColumnWidth(c, columnWidth);
- for (int i = 0; i < hiddenColumns.count(); ++i)
+ for (int i = 0; i < hiddenColumns.size(); ++i)
view.hideColumn(hiddenColumns.at(i));
QCOMPARE(view.columnAt(coordinate), column);
diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
index 39cbe0ab66..02d93bd356 100644
--- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
@@ -192,8 +192,8 @@ void tst_QTableWidget::clear()
QVERIFY(bla.isNull());
QVERIFY(!testWidget->item(0,0));
- QVERIFY(!testWidget->selectedRanges().count());
- QVERIFY(!testWidget->selectedItems().count());
+ QVERIFY(!testWidget->selectedRanges().size());
+ QVERIFY(!testWidget->selectedItems().size());
}
void tst_QTableWidget::rowCount()
@@ -360,7 +360,7 @@ void tst_QTableWidget::takeItem()
QCOMPARE(item->text(), QString::number(row * column + column));
delete item;
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE(spy.size(), 1);
const QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(arguments.size(), 2);
QCOMPARE(arguments.at(0).toInt(), row);
@@ -525,24 +525,24 @@ void tst_QTableWidget::selectedItems()
testWidget->setColumnHidden(column, true);
// make sure we don't have any previous selections hanging around
- QVERIFY(!testWidget->selectedRanges().count());
- QVERIFY(!testWidget->selectedItems().count());
+ QVERIFY(!testWidget->selectedRanges().size());
+ QVERIFY(!testWidget->selectedItems().size());
// select range and check that it is set correctly
testWidget->setRangeSelected(selectionRange, true);
if (selectionRange.topRow() >= 0) {
- QCOMPARE(testWidget->selectedRanges().count(), 1);
+ QCOMPARE(testWidget->selectedRanges().size(), 1);
QCOMPARE(testWidget->selectedRanges().at(0).topRow(), selectionRange.topRow());
QCOMPARE(testWidget->selectedRanges().at(0).bottomRow(), selectionRange.bottomRow());
QCOMPARE(testWidget->selectedRanges().at(0).leftColumn(), selectionRange.leftColumn());
QCOMPARE(testWidget->selectedRanges().at(0).rightColumn(), selectionRange.rightColumn());
} else {
- QCOMPARE(testWidget->selectedRanges().count(), 0);
+ QCOMPARE(testWidget->selectedRanges().size(), 0);
}
// check that the correct number of items and the expected items are there
const QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems();
- QCOMPARE(selectedItems.count(), expectedItems.count());
+ QCOMPARE(selectedItems.size(), expectedItems.size());
for (const auto &intPair : expectedItems)
QVERIFY(selectedItems.contains(testWidget->item(intPair.first, intPair.second)));
@@ -627,7 +627,7 @@ void tst_QTableWidget::selectedSpannedCells() // QTBUG-255
testWidget.visualRect(testWidget.model()->index(selectionEndCell.y(), selectionEndCell.x())).center());
auto ranges = testWidget.selectedRanges();
- QCOMPARE(ranges.count(), expectedSelectionRangeCount);
+ QCOMPARE(ranges.size(), expectedSelectionRangeCount);
QCOMPARE(ranges.first(), expectedFirstSelectionRange);
}
@@ -1194,15 +1194,15 @@ void tst_QTableWidget::sortItems()
persistent << model->index(r, sortColumn, QModelIndex());
}
- for (int h = 0; h < initialHidden.count(); ++h)
+ for (int h = 0; h < initialHidden.size(); ++h)
testWidget->hideRow(initialHidden.at(h));
- QCOMPARE(testWidget->verticalHeader()->hiddenSectionCount(), initialHidden.count());
+ QCOMPARE(testWidget->verticalHeader()->hiddenSectionCount(), initialHidden.size());
testWidget->sortItems(sortColumn, sortOrder);
int te = 0;
- for (int i = 0; i < rows.count(); ++i) {
+ for (int i = 0; i < rows.size(); ++i) {
for (int j = 0; j < columnCount; ++j) {
QString value;
QTableWidgetItem *itm = testWidget->item(i, j);
@@ -1216,7 +1216,7 @@ void tst_QTableWidget::sortItems()
// << "expected" << rows.at(i);
}
- for (int k = 0; k < expectedHidden.count(); ++k)
+ for (int k = 0; k < expectedHidden.size(); ++k)
QVERIFY(testWidget->isRowHidden(expectedHidden.at(k)));
}
@@ -1397,18 +1397,18 @@ void tst_QTableWidget::setItemWithSorting()
}
}
- for (int k = 0; k < persistent.count(); ++k) {
+ for (int k = 0; k < persistent.size(); ++k) {
QCOMPARE(persistent.at(k).row(), expectedRows.at(k));
int i = (persistent.at(k).row() * columnCount) + sortColumn;
QCOMPARE(persistent.at(k).data().toString(), expectedValues.at(i));
}
if (i == 0)
- QCOMPARE(dataChangedSpy.count(), reorderingExpected ? 0 : 1);
+ QCOMPARE(dataChangedSpy.size(), reorderingExpected ? 0 : 1);
else
- QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
- QCOMPARE(layoutChangedSpy.count(), reorderingExpected ? 1 : 0);
+ QCOMPARE(layoutChangedSpy.size(), reorderingExpected ? 1 : 0);
}
}
@@ -1444,7 +1444,7 @@ void tst_QTableWidget::itemData()
QCOMPARE(widget.currentRoles, QList<int> { Qt::UserRole + i });
}
QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0));
- QCOMPARE(flags.count(), 6);
+ QCOMPARE(flags.size(), 6);
for (int i = 0; i < 4; ++i)
QCOMPARE(flags[Qt::UserRole + i].toString(), QString::number(i + 1));
}
@@ -1457,7 +1457,7 @@ void tst_QTableWidget::setItemData()
QTableWidgetItem *item = new QTableWidgetItem;
table.setItem(0, 0, item);
- QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
QModelIndex idx = qvariant_cast<QModelIndex>(dataChangedSpy.takeFirst().at(0));
QMap<int, QVariant> data;
@@ -1469,7 +1469,7 @@ void tst_QTableWidget::setItemData()
QCOMPARE(table.model()->data(idx, Qt::DisplayRole).toString(), QLatin1String("Display"));
QCOMPARE(table.model()->data(idx, Qt::EditRole).toString(), QLatin1String("Display"));
QCOMPARE(table.model()->data(idx, Qt::ToolTipRole).toString(), QLatin1String("ToolTip"));
- QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.first().at(0)));
QCOMPARE(idx, qvariant_cast<QModelIndex>(dataChangedSpy.first().at(1)));
const auto roles = qvariant_cast<QList<int>>(dataChangedSpy.first().at(2));
@@ -1480,13 +1480,13 @@ void tst_QTableWidget::setItemData()
dataChangedSpy.clear();
table.model()->setItemData(idx, data);
- QCOMPARE(dataChangedSpy.count(), 0);
+ QCOMPARE(dataChangedSpy.size(), 0);
data.clear();
data.insert(Qt::DisplayRole, QLatin1String("dizplaye"));
table.model()->setItemData(idx, data);
QCOMPARE(table.model()->data(idx, Qt::DisplayRole).toString(), QLatin1String("dizplaye"));
- QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
QCOMPARE(QList<int>({ Qt::DisplayRole, Qt::EditRole }),
qvariant_cast<QList<int>>(dataChangedSpy.first().at(2)));
@@ -1649,7 +1649,7 @@ void tst_QTableWidget::task262056_sortDuplicate()
QSignalSpy layoutChangedSpy(testWidget->model(), &QAbstractItemModel::layoutChanged);
testWidget->item(3,0)->setBackground(Qt::red);
- QCOMPARE(layoutChangedSpy.count(),0);
+ QCOMPARE(layoutChangedSpy.size(),0);
}
@@ -1746,7 +1746,7 @@ void tst_QTableWidget::selectedRowAfterSorting()
table.setProperty("sortingEnabled",true);
table.selectRow(1);
table.item(1,1)->setText("9");
- QCOMPARE(table.selectedItems().count(),3);
+ QCOMPARE(table.selectedItems().size(),3);
const auto selectedItems = table.selectedItems();
for (QTableWidgetItem *item : selectedItems)
QCOMPARE(item->row(), 0);
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 8fa942dd06..2a540feb66 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -1279,7 +1279,7 @@ void tst_QTreeView::setModel()
QCOMPARE(view.header()->model(), model);
QCOMPARE(view.selectionModel() != oldSelectionModel, (i == 0));
}
- QTRY_COMPARE(modelDestroyedSpy.count(), 0);
+ QTRY_COMPARE(modelDestroyedSpy.size(), 0);
view.setModel(nullptr);
QCOMPARE(view.model(), nullptr);
@@ -1334,7 +1334,7 @@ void tst_QTreeView::setHeader()
Qt::Orientation orient = x ? Qt::Vertical : Qt::Horizontal;
QHeaderView *head = new QHeaderView(orient);
view.setHeader(head);
- QCOMPARE(destroyedSpy.count(), 1);
+ QCOMPARE(destroyedSpy.size(), 1);
QCOMPARE(head->parent(), &view);
QCOMPARE(view.header(), head);
view.setHeader(head);
@@ -1517,10 +1517,10 @@ void tst_QTreeView::limitedExpand()
QVERIFY(spy.isValid());
view.expand(model.index(0, 0));
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
view.expand(model.index(1, 0));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
{
QStringListModel model(QStringList() << "one" << "two");
@@ -1531,9 +1531,9 @@ void tst_QTreeView::limitedExpand()
QVERIFY(spy.isValid());
view.expand(model.index(0, 0));
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
view.expandAll();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
}
@@ -1572,58 +1572,58 @@ void tst_QTreeView::expandAndCollapse()
view.expand(QModelIndex());
QCOMPARE(view.isExpanded(QModelIndex()), false);
view.collapse(QModelIndex());
- QCOMPARE(expandedSpy.count(), 0);
- QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.size(), 0);
+ QCOMPARE(collapsedSpy.size(), 0);
// expand a first level item
QVERIFY(!view.isExpanded(a));
view.expand(a);
QVERIFY(view.isExpanded(a));
- QCOMPARE(expandedSpy.count(), 1);
- QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.size(), 1);
+ QCOMPARE(collapsedSpy.size(), 0);
args = expandedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a);
view.expand(a);
QVERIFY(view.isExpanded(a));
- QCOMPARE(expandedSpy.count(), 0);
- QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.size(), 0);
+ QCOMPARE(collapsedSpy.size(), 0);
// expand a second level item
QVERIFY(!view.isExpanded(b));
view.expand(b);
QVERIFY(view.isExpanded(a));
QVERIFY(view.isExpanded(b));
- QCOMPARE(expandedSpy.count(), 1);
- QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.size(), 1);
+ QCOMPARE(collapsedSpy.size(), 0);
args = expandedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), b);
view.expand(b);
QVERIFY(view.isExpanded(b));
- QCOMPARE(expandedSpy.count(), 0);
- QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.size(), 0);
+ QCOMPARE(collapsedSpy.size(), 0);
// collapse the first level item
view.collapse(a);
QVERIFY(!view.isExpanded(a));
QVERIFY(view.isExpanded(b));
- QCOMPARE(expandedSpy.count(), 0);
- QCOMPARE(collapsedSpy.count(), 1);
+ QCOMPARE(expandedSpy.size(), 0);
+ QCOMPARE(collapsedSpy.size(), 1);
args = collapsedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a);
view.collapse(a);
QVERIFY(!view.isExpanded(a));
- QCOMPARE(expandedSpy.count(), 0);
- QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.size(), 0);
+ QCOMPARE(collapsedSpy.size(), 0);
// expand the first level item again
view.expand(a);
QVERIFY(view.isExpanded(a));
QVERIFY(view.isExpanded(b));
- QCOMPARE(expandedSpy.count(), 1);
- QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.size(), 1);
+ QCOMPARE(collapsedSpy.size(), 0);
args = expandedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a);
@@ -1631,8 +1631,8 @@ void tst_QTreeView::expandAndCollapse()
view.collapse(b);
QVERIFY(view.isExpanded(a));
QVERIFY(!view.isExpanded(b));
- QCOMPARE(expandedSpy.count(), 0);
- QCOMPARE(collapsedSpy.count(), 1);
+ QCOMPARE(expandedSpy.size(), 0);
+ QCOMPARE(collapsedSpy.size(), 1);
args = collapsedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), b);
@@ -1640,8 +1640,8 @@ void tst_QTreeView::expandAndCollapse()
view.collapse(a);
QVERIFY(!view.isExpanded(a));
QVERIFY(!view.isExpanded(b));
- QCOMPARE(expandedSpy.count(), 0);
- QCOMPARE(collapsedSpy.count(), 1);
+ QCOMPARE(expandedSpy.size(), 0);
+ QCOMPARE(collapsedSpy.size(), 1);
args = collapsedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a);
@@ -1653,8 +1653,8 @@ void tst_QTreeView::expandAndCollapse()
QVERIFY(view.isExpanded(a));
QVERIFY(view.isExpanded(b));
QVERIFY(!view.isExpanded(c));
- QCOMPARE(expandedSpy.count(), 2);
- QCOMPARE(collapsedSpy.count(), 0);
+ QCOMPARE(expandedSpy.size(), 2);
+ QCOMPARE(collapsedSpy.size(), 0);
args = expandedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a);
args = expandedSpy.takeFirst();
@@ -1665,8 +1665,8 @@ void tst_QTreeView::expandAndCollapse()
QVERIFY(!view.isExpanded(a));
QVERIFY(!view.isExpanded(b));
QVERIFY(!view.isExpanded(c));
- QCOMPARE(expandedSpy.count(), 0);
- QCOMPARE(collapsedSpy.count(), 2);
+ QCOMPARE(expandedSpy.size(), 0);
+ QCOMPARE(collapsedSpy.size(), 2);
args = collapsedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), a);
args = collapsedSpy.takeFirst();
@@ -1728,22 +1728,22 @@ void tst_QTreeView::expandAndCollapseAll()
view.expandAll();
checkExpandState(model, view, QModelIndex(), true, &count);
- QCOMPARE(collapsedSpy.count(), 0);
- QCOMPARE(expandedSpy.count(), 39); // == 3 (first) + 9 (second) + 27 (third level)
+ QCOMPARE(collapsedSpy.size(), 0);
+ QCOMPARE(expandedSpy.size(), 39); // == 3 (first) + 9 (second) + 27 (third level)
QCOMPARE(count, 39);
collapsedSpy.clear();
expandedSpy.clear();
view.collapseAll();
checkExpandState(model, view, QModelIndex(), false, &count);
- QCOMPARE(collapsedSpy.count(), 39);
- QCOMPARE(expandedSpy.count(), 0);
+ QCOMPARE(collapsedSpy.size(), 39);
+ QCOMPARE(expandedSpy.size(), 0);
QCOMPARE(count, 39);
collapsedSpy.clear();
expandedSpy.clear();
view.expandRecursively(model.index(0, 0));
- QCOMPARE(expandedSpy.count(), 13); // 1 + 3 + 9
+ QCOMPARE(expandedSpy.size(), 13); // 1 + 3 + 9
checkExpandState(model, view, model.index(0, 0), true, &count);
QCOMPARE(count, 13);
@@ -1755,9 +1755,9 @@ void tst_QTreeView::expandAndCollapseAll()
expandedSpy.clear();
view.collapseAll();
view.expandRecursively(model.index(0, 0), 1);
- QCOMPARE(expandedSpy.count(), 4); // 1 + 3
+ QCOMPARE(expandedSpy.size(), 4); // 1 + 3
view.expandRecursively(model.index(0, 0), 2);
- QCOMPARE(expandedSpy.count(), 13); // (1 + 3) + 9
+ QCOMPARE(expandedSpy.size(), 13); // (1 + 3) + 9
checkExpandState(model, view, model.index(0, 0), true, &count);
QCOMPARE(count, 13);
@@ -2043,7 +2043,7 @@ void tst_QTreeView::setSelection()
QVERIFY(selectionModel);
const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
- QCOMPARE(selectedIndexes.count(), expectedItems.count());
+ QCOMPARE(selectedIndexes.size(), expectedItems.size());
for (const QModelIndex &idx : selectedIndexes)
QVERIFY(expectedItems.contains(QPoint(idx.column(), idx.row())));
}
@@ -2147,7 +2147,7 @@ void tst_QTreeView::clicked()
continue;
QSignalSpy spy(&view, &QTreeView::clicked);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p);
- QTRY_COMPARE(spy.count(), 1);
+ QTRY_COMPARE(spy.size(), 1);
}
}
@@ -2228,7 +2228,7 @@ void tst_QTreeView::rowsAboutToBeRemoved()
model.removeRows(1,1);
QCOMPARE((view.state()), 0);
// Should not be 5 (or any other number for that sake :)
- QCOMPARE(spy1.count(), 1);
+ QCOMPARE(spy1.size(), 1);
}
@@ -2540,28 +2540,28 @@ void tst_QTreeView::selectionWithHiddenItems()
//child should not be selected as it is hidden (its parent is not expanded)
view.selectAll();
- QCOMPARE(view.selectionModel()->selection().count(), 1); //one range
- QCOMPARE(view.selectionModel()->selectedRows().count(), 4);
+ QCOMPARE(view.selectionModel()->selection().size(), 1); //one range
+ QCOMPARE(view.selectionModel()->selectedRows().size(), 4);
view.expandAll();
QVERIFY(view.isExpanded(item1.index()));
- QCOMPARE(view.selectionModel()->selection().count(), 1);
- QCOMPARE(view.selectionModel()->selectedRows().count(), 4);
+ QCOMPARE(view.selectionModel()->selection().size(), 1);
+ QCOMPARE(view.selectionModel()->selectedRows().size(), 4);
QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&child)));
view.clearSelection();
QVERIFY(view.isExpanded(item1.index()));
//child should be selected as it is visible (its parent is expanded)
view.selectAll();
- QCOMPARE(view.selectionModel()->selection().count(), 2);
- QCOMPARE(view.selectionModel()->selectedRows().count(), 5); //everything is selected
+ QCOMPARE(view.selectionModel()->selection().size(), 2);
+ QCOMPARE(view.selectionModel()->selectedRows().size(), 5); //everything is selected
view.clearSelection();
//we hide the node with a child (there should then be 3 items selected in 2 ranges)
view.setRowHidden(1, QModelIndex(), true);
QVERIFY(view.isExpanded(item1.index()));
view.selectAll();
- QCOMPARE(view.selectionModel()->selection().count(), 2);
- QCOMPARE(view.selectionModel()->selectedRows().count(), 3);
+ QCOMPARE(view.selectionModel()->selection().size(), 2);
+ QCOMPARE(view.selectionModel()->selectedRows().size(), 3);
QVERIFY(!view.selectionModel()->isSelected(model.indexFromItem(&item1)));
QVERIFY(!view.selectionModel()->isSelected(model.indexFromItem(&child)));
@@ -2574,8 +2574,8 @@ void tst_QTreeView::selectionWithHiddenItems()
QVERIFY(view.isExpanded(item1.index()));
view.selectAll();
QVERIFY(view.isExpanded(item1.index()));
- QCOMPARE(view.selectionModel()->selection().count(), 3);
- QCOMPARE(view.selectionModel()->selectedRows().count(), 4);
+ QCOMPARE(view.selectionModel()->selection().size(), 3);
+ QCOMPARE(view.selectionModel()->selectedRows().size(), 4);
QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&item2)));
view.setRowHidden(2, QModelIndex(), false);
QVERIFY(view.isExpanded(item1.index()));
@@ -2590,21 +2590,21 @@ void tst_QTreeView::selectAll()
view2.setSelectionMode(QAbstractItemView::ExtendedSelection);
view2.selectAll(); // Should work with an empty model
//everything should be selected since we are in ExtendedSelection mode
- QCOMPARE(view2.selectedIndexes().count(), model.rowCount() * model.columnCount());
+ QCOMPARE(view2.selectedIndexes().size(), model.rowCount() * model.columnCount());
for (int i = 0; i < model.rowCount(); ++i)
model.setData(model.index(i,0), QLatin1String("row ") + QString::number(i));
QTreeView view;
view.setModel(&model);
- int selectedCount = view.selectedIndexes().count();
+ int selectedCount = view.selectedIndexes().size();
view.selectAll();
- QCOMPARE(view.selectedIndexes().count(), selectedCount);
+ QCOMPARE(view.selectedIndexes().size(), selectedCount);
QTreeView view3;
view3.setModel(&model);
view3.setSelectionMode(QAbstractItemView::NoSelection);
view3.selectAll();
- QCOMPARE(view3.selectedIndexes().count(), 0);
+ QCOMPARE(view3.selectedIndexes().size(), 0);
}
void tst_QTreeView::extendedSelection_data()
@@ -2630,7 +2630,7 @@ void tst_QTreeView::extendedSelection()
topLevel.show();
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
QTest::mousePress(view.viewport(), Qt::LeftButton, {}, mousePressPos);
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), selectedCount);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), selectedCount);
}
void tst_QTreeView::rowSizeHint()
@@ -2870,7 +2870,7 @@ public:
}
void kill()
{
- for (int i = children.count() -1; i >= 0; --i) {
+ for (int i = children.size() -1; i >= 0; --i) {
children.at(i)->kill();
if (parent == nullptr) {
deadChildren.append(children.at(i));
@@ -2912,7 +2912,7 @@ public:
emit layoutAboutToBeChanged();
QModelIndexList oldList = persistentIndexList();
QList<QStack<int>> oldListPath;
- for (int i = 0; i < oldList.count(); ++i) {
+ for (int i = 0; i < oldList.size(); ++i) {
QModelIndex idx = oldList.at(i);
QStack<int> path;
while (idx.isValid()) {
@@ -2924,7 +2924,7 @@ public:
root->kill();
QModelIndexList newList;
- for (auto path : qAsConst(oldListPath)) {
+ for (auto path : std::as_const(oldListPath)) {
QModelIndex idx;
while (!path.isEmpty())
idx = index(path.pop(), 0, idx);
@@ -2943,7 +2943,7 @@ public:
if (parentNode->isDead)
qFatal("%s: parentNode is dead!", Q_FUNC_INFO);
}
- return parentNode->children.count();
+ return parentNode->children.size();
}
int columnCount(const QModelIndex &parent = QModelIndex()) const override
{
@@ -3534,7 +3534,7 @@ void tst_QTreeView::task174627_moveLeftToRoot()
QSignalSpy spy(&view, &task174627_TreeView::signalCurrentChanged);
QTest::keyClick(&view, Qt::Key_Left);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QTreeView::task171902_expandWith1stColHidden()
@@ -4040,7 +4040,7 @@ void tst_QTreeView::task248022_changeSelection()
&view, &TreeView::handleSelectionChanged);
QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
view.visualRect(model.index(1)).center());
- QCOMPARE(view.selectionModel()->selectedIndexes().count(), list.count());
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), list.size());
}
void tst_QTreeView::task245654_changeModelAndExpandAll()
@@ -4089,7 +4089,7 @@ void tst_QTreeView::doubleClickedWithSpans()
QTest::mousePress(view.viewport(), Qt::LeftButton, {}, p);
QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, p);
QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, p);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
//let's click on the 2nd column
p.setX(p.x() + view.header()->sectionSize(0));
@@ -4100,7 +4100,7 @@ void tst_QTreeView::doubleClickedWithSpans()
QTest::mousePress(view.viewport(), Qt::LeftButton, {}, p);
QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, p);
QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, p);
- QTRY_COMPARE(spy.count(), 2);
+ QTRY_COMPARE(spy.size(), 2);
}
void tst_QTreeView::taskQTBUG_6450_selectAllWith1stColumnHidden()
@@ -5117,7 +5117,7 @@ void tst_QTreeView::fetchUntilScreenFull()
TreeItem* parentItem = parent.isValid() ? static_cast<TreeItem*>(parent.internalPointer())
: m_root;
- return parentItem->children.count();
+ return parentItem->children.size();
}
int columnCount(const QModelIndex&) const override { return 2; }
diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
index 652d6f76d9..03c36260c1 100644
--- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
@@ -281,8 +281,8 @@ void tst_QTreeWidget::addTopLevelItem()
while (!tops.isEmpty()) {
TreeItem *ti = tops.takeFirst();
delete ti;
- QCOMPARE(tree.topLevelItemCount(), tops.count());
- for (int i = 0; i < tops.count(); ++i)
+ QCOMPARE(tree.topLevelItemCount(), tops.size());
+ for (int i = 0; i < tops.size(); ++i)
QCOMPARE(tree.topLevelItem(i), tops.at(i));
}
@@ -378,12 +378,12 @@ void tst_QTreeWidget::currentItem()
tree.setCurrentItem(item);
QCOMPARE(tree.currentItem(), item);
- QCOMPARE(currentItemChangedSpy.count(), 1);
+ QCOMPARE(currentItemChangedSpy.size(), 1);
QVariantList args = currentItemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(1)), previous);
- QCOMPARE(itemSelectionChangedSpy.count(), 1);
+ QCOMPARE(itemSelectionChangedSpy.size(), 1);
itemSelectionChangedSpy.clear();
previous = item;
@@ -396,15 +396,15 @@ void tst_QTreeWidget::currentItem()
if (!currentItemChangedSpy.isEmpty()) {
// ### we get a currentItemChanged() when what really
// changed was just currentColumn(). Should it be like this?
- QCOMPARE(currentItemChangedSpy.count(), 1);
+ QCOMPARE(currentItemChangedSpy.size(), 1);
QVariantList args = currentItemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(1)), item);
if (tree.selectionBehavior() == QAbstractItemView::SelectItems) {
- QCOMPARE(itemSelectionChangedSpy.count(), 1);
+ QCOMPARE(itemSelectionChangedSpy.size(), 1);
itemSelectionChangedSpy.clear();
} else {
- QCOMPARE(itemSelectionChangedSpy.count(), 0);
+ QCOMPARE(itemSelectionChangedSpy.size(), 0);
}
}
}
@@ -464,7 +464,7 @@ void tst_QTreeWidget::editItem()
QTest::keyClick(editor, Qt::Key_A);
QTest::keyClick(editor, Qt::Key_Enter);
QCoreApplication::processEvents();
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
QVariantList args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem *>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), col);
@@ -620,7 +620,7 @@ void tst_QTreeWidget::setItemHidden2()
{
// From Task 78587
const QStringList hl({"ID", "Desc"});
- testWidget->setColumnCount(hl.count());
+ testWidget->setColumnCount(hl.size());
testWidget->setHeaderLabels(hl);
testWidget->setSortingEnabled(true);
@@ -821,7 +821,7 @@ void tst_QTreeWidget::selectedItems()
// check selectedItems
const auto sel = testWidget->selectedItems();
- QCOMPARE(sel.count(), expectedItems.count());
+ QCOMPARE(sel.size(), expectedItems.size());
for (const auto &itemPath : expectedItems) {
QTreeWidgetItem *item = nullptr;
for (int index : itemPath) {
@@ -857,7 +857,7 @@ void tst_QTreeWidget::selectedItems()
}
item->setSelected(false);
}
- QCOMPARE(testWidget->selectedItems().count(), 0);
+ QCOMPARE(testWidget->selectedItems().size(), 0);
}
void tst_QTreeWidget::itemAssignment()
@@ -1090,9 +1090,9 @@ void tst_QTreeWidget::findItems()
QList<QTreeWidgetItem*> result = testWidget->findItems(pattern,
Qt::MatchExactly|Qt::MatchRecursive);
- QCOMPARE(result.count(), resultCount);
+ QCOMPARE(result.size(), resultCount);
- for (int k = 0; k < result.count() && k < resultText.count(); ++k)
+ for (int k = 0; k < result.size() && k < resultText.size(); ++k)
QCOMPARE(result.at(k)->text(column), resultText.at(k));
}
@@ -1110,7 +1110,7 @@ void tst_QTreeWidget::findItemsInColumn()
// Recursively search column one for 400.
QList<QTreeWidgetItem*> items = testWidget->findItems("400", Qt::MatchExactly|Qt::MatchRecursive, 1);
- QCOMPARE(items.count(), 1);
+ QCOMPARE(items.size(), 1);
}
void tst_QTreeWidget::sortItems_data()
@@ -1177,16 +1177,16 @@ void tst_QTreeWidget::sortItems()
testWidget->sortItems(column, order);
QCOMPARE(testWidget->sortColumn(), column);
- for (int k = 0; k < topLevelResult.count(); ++k) {
+ for (int k = 0; k < topLevelResult.size(); ++k) {
QTreeWidgetItem *item = testWidget->topLevelItem(k);
QCOMPARE(item->text(column), topLevelResult.at(k));
- for (int l = 0; l < childResult.count(); ++l)
+ for (int l = 0; l < childResult.size(); ++l)
QCOMPARE(item->child(l)->text(column), childResult.at(l));
}
- for (int m = 0; m < tops.count(); ++m)
+ for (int m = 0; m < tops.size(); ++m)
QCOMPARE(tops.at(m).row(), expectedTopRows.at(m));
- for (int n = 0; n < children.count(); ++n)
+ for (int n = 0; n < children.size(); ++n)
QCOMPARE(children.at(n).row(), expectedChildRows.at(n));
}
@@ -1346,17 +1346,17 @@ void tst_QTreeWidget::insertTopLevelItems_data()
const QStringList insert{ "baz" };
QTest::newRow("Insert at count") << initial << insert
- << initial.count() << initial.count()
- << initial.count() << initial.count();
+ << initial.size() << initial.size()
+ << initial.size() << initial.size();
QTest::newRow("Insert in the middle") << initial << insert
- << (initial.count() / 2) << (initial.count() / 2)
- << (initial.count() / 2) << (initial.count() / 2);
+ << (initial.size() / 2) << (initial.size() / 2)
+ << (initial.size() / 2) << (initial.size() / 2);
QTest::newRow("Insert less than 0") << initial << insert
<< -1 << -1
<< -1 << -1;
QTest::newRow("Insert beyond count") << initial << insert
- << initial.count() + 1 << -1
- << initial.count() + 1 << -1;
+ << initial.size() + 1 << -1
+ << initial.size() + 1 << -1;
}
void tst_QTreeWidget::insertTopLevelItems()
@@ -1371,26 +1371,26 @@ void tst_QTreeWidget::insertTopLevelItems()
{ // insert the initial items
QCOMPARE(testWidget->topLevelItemCount(), 0);
- for (int i = 0; i < initialText.count(); ++i) {
+ for (int i = 0; i < initialText.size(); ++i) {
QTreeWidgetItem *top = new QTreeWidgetItem(QStringList(initialText.at(i)));
testWidget->addTopLevelItem(top);
QCOMPARE(testWidget->indexOfTopLevelItem(top), i);
}
- QCOMPARE(testWidget->topLevelItemCount(), initialText.count());
+ QCOMPARE(testWidget->topLevelItemCount(), initialText.size());
}
{ // test adding children
QTreeWidgetItem *topLevel = testWidget->topLevelItem(0);
- for (int i = 0; i < initialText.count(); ++i)
+ for (int i = 0; i < initialText.size(); ++i)
topLevel->addChild(new QTreeWidgetItem(QStringList(initialText.at(i))));
- QCOMPARE(topLevel->childCount(), initialText.count());
+ QCOMPARE(topLevel->childCount(), initialText.size());
}
{ // test adding more top level items
QTreeWidgetItem *topsy = new QTreeWidgetItem(QStringList(insertText.at(0)));
testWidget->insertTopLevelItem(insertTopLevelIndex, topsy);
if (expectedTopLevelIndex == -1) {
- QCOMPARE(testWidget->topLevelItemCount(), initialText.count());
+ QCOMPARE(testWidget->topLevelItemCount(), initialText.size());
delete topsy;
} else {
QTreeWidgetItem *item = testWidget->topLevelItem(expectedTopLevelIndex);
@@ -1406,7 +1406,7 @@ void tst_QTreeWidget::insertTopLevelItems()
QTreeWidgetItem *child = new QTreeWidgetItem(QStringList(insertText.at(0)));
topLevel->insertChild(insertChildIndex, child);
if (expectedChildIndex == -1) {
- QCOMPARE(topLevel->childCount(), initialText.count());
+ QCOMPARE(topLevel->childCount(), initialText.size());
delete child;
} else {
QTreeWidgetItem *item = topLevel->child(expectedChildIndex);
@@ -1592,7 +1592,7 @@ void tst_QTreeWidget::scrollToItem()
void tst_QTreeWidget::setSortingEnabled()
{
const QStringList hl{ "ID" };
- testWidget->setColumnCount(hl.count());
+ testWidget->setColumnCount(hl.size());
testWidget->setHeaderLabels(hl);
QTreeWidgetItem *item1 = new QTreeWidgetItem(testWidget);
@@ -1661,7 +1661,7 @@ void tst_QTreeWidget::addChild()
QList<QTreeWidgetItem*> taken = item->takeChildren();
QCOMPARE(taken, children);
QCOMPARE(item->childCount(), 0);
- for (int i = 0; i < taken.count(); ++i) {
+ for (int i = 0; i < taken.size(); ++i) {
QCOMPARE(taken.at(i)->parent(), nullptr);
QCOMPARE(taken.at(i)->treeWidget(), nullptr);
item->addChild(taken.at(i)); // re-add
@@ -1671,8 +1671,8 @@ void tst_QTreeWidget::addChild()
while (!children.isEmpty()) {
QTreeWidgetItem *ti = children.takeFirst();
delete ti;
- QCOMPARE(item->childCount(), children.count());
- for (int i = 0; i < children.count(); ++i)
+ QCOMPARE(item->childCount(), children.size());
+ for (int i = 0; i < children.size(); ++i)
QCOMPARE(item->child(i), children.at(i));
}
@@ -1719,9 +1719,9 @@ void tst_QTreeWidget::setData()
QSignalSpy itemChangedSpy(
testWidget, &QTreeWidget::itemChanged);
headerItem->setText(0, "test");
- QCOMPARE(dataChangedSpy.count(), 0);
- QCOMPARE(headerDataChangedSpy.count(), 1);
- QCOMPARE(itemChangedSpy.count(), 0); // no itemChanged() signal for header item
+ QCOMPARE(dataChangedSpy.size(), 0);
+ QCOMPARE(headerDataChangedSpy.size(), 1);
+ QCOMPARE(itemChangedSpy.size(), 0); // no itemChanged() signal for header item
headerItem->setData(-1, -1, QVariant());
}
@@ -1739,24 +1739,24 @@ void tst_QTreeWidget::setData()
const QString text = QLatin1String("text ") + iS;
item->setText(j, text);
QCOMPARE(item->text(j), text);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setText(j, text);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
QPixmap pixmap(32, 32);
pixmap.fill((i == 1) ? Qt::red : Qt::green);
QIcon icon(pixmap);
item->setIcon(j, icon);
QCOMPARE(item->icon(j), icon);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setIcon(j, icon);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
@@ -1764,94 +1764,94 @@ void tst_QTreeWidget::setData()
const QString toolTip = QLatin1String("toolTip ") + iS;
item->setToolTip(j, toolTip);
QCOMPARE(item->toolTip(j), toolTip);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setToolTip(j, toolTip);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
const QString statusTip = QLatin1String("statusTip ") + iS;
item->setStatusTip(j, statusTip);
QCOMPARE(item->statusTip(j), statusTip);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setStatusTip(j, statusTip);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
const QString whatsThis = QLatin1String("whatsThis ") + iS;
item->setWhatsThis(j, whatsThis);
QCOMPARE(item->whatsThis(j), whatsThis);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setWhatsThis(j, whatsThis);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
QSize sizeHint(64*i, 48*i);
item->setSizeHint(j, sizeHint);
QCOMPARE(item->sizeHint(j), sizeHint);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setSizeHint(j, sizeHint);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
QFont font;
item->setFont(j, font);
QCOMPARE(item->font(j), font);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setFont(j, font);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
Qt::Alignment textAlignment((i == 1)
? Qt::AlignLeft|Qt::AlignVCenter
: Qt::AlignRight);
item->setTextAlignment(j, textAlignment);
QCOMPARE(item->textAlignment(j), int(textAlignment));
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setTextAlignment(j, textAlignment);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
QColor backgroundColor((i == 1) ? Qt::blue : Qt::yellow);
item->setBackground(j, backgroundColor);
QCOMPARE(item->background(j).color(), backgroundColor);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setBackground(j, backgroundColor);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
const QColor foregroundColor((i == 1) ? Qt::green : Qt::cyan);
item->setForeground(j, foregroundColor);
QCOMPARE(item->foreground(j), foregroundColor);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setForeground(j, foregroundColor);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
Qt::CheckState checkState((i == 1) ? Qt::PartiallyChecked : Qt::Checked);
item->setCheckState(j, checkState);
QCOMPARE(item->checkState(j), checkState);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = itemChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setCheckState(j, checkState);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
QCOMPARE(item->text(j), text);
QCOMPARE(item->icon(j), icon);
@@ -1884,7 +1884,7 @@ void tst_QTreeWidget::setData()
QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item);
QCOMPARE(qvariant_cast<int>(args.at(1)), j);
item->setBackground(j, pixmap);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
item->setData(j, Qt::DisplayRole, QVariant());
item->setData(j, Qt::DecorationRole, QVariant());
@@ -1897,7 +1897,7 @@ void tst_QTreeWidget::setData()
item->setData(j, Qt::BackgroundRole, QVariant());
item->setData(j, Qt::ForegroundRole, QVariant());
item->setData(j, Qt::CheckStateRole, QVariant());
- QCOMPARE(itemChangedSpy.count(), 11);
+ QCOMPARE(itemChangedSpy.size(), 11);
itemChangedSpy.clear();
QCOMPARE(item->data(j, Qt::DisplayRole).toString(), QString());
@@ -1960,11 +1960,11 @@ void tst_QTreeWidget::itemData()
QCOMPARE(widget.currentRoles, QList<int> { Qt::UserRole + i });
}
QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0));
- QCOMPARE(flags.count(), 6);
+ QCOMPARE(flags.size(), 6);
for (int i = 0; i < 4; ++i)
QCOMPARE(flags[Qt::UserRole + i].toString(), QString::number(i + 1));
flags = widget.model()->itemData(widget.model()->index(0, 1));
- QCOMPARE(flags.count(), 0);
+ QCOMPARE(flags.size(), 0);
item.setBackground(0, QBrush(Qt::red));
item.setForeground(0, QBrush(Qt::green));
@@ -2033,7 +2033,7 @@ void tst_QTreeWidget::setHeaderLabels()
{
QStringList list = QString("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z").split(QLatin1Char(','));
testWidget->setHeaderLabels(list);
- QCOMPARE(testWidget->header()->count(), list.count());
+ QCOMPARE(testWidget->header()->count(), list.size());
}
void tst_QTreeWidget::setHeaderItem()
@@ -2263,11 +2263,11 @@ void tst_QTreeWidget::insertItemsWithSorting()
w.addTopLevelItem(new QTreeWidgetItem({ txt }));
break;
}
- QCOMPARE(w.topLevelItemCount(), expectedItems.count());
+ QCOMPARE(w.topLevelItemCount(), expectedItems.size());
for (int i = 0; i < w.topLevelItemCount(); ++i)
QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i));
- for (int k = 0; k < persistent.count(); ++k)
+ for (int k = 0; k < persistent.size(); ++k)
QCOMPARE(persistent.at(k).row(), expectedRows.at(k));
}
}
@@ -2308,13 +2308,13 @@ void tst_QTreeWidget::insertExpandedItemsWithSorting()
QTreeWidgetItem *child = new QTreeWidgetItem(parent, {text});
items << child;
}
- QCOMPARE(parent->childCount(), childTexts.count());
+ QCOMPARE(parent->childCount(), childTexts.size());
QVERIFY(parent->isExpanded());
}
- QCOMPARE(tree.model()->rowCount(), parentTexts.count());
+ QCOMPARE(tree.model()->rowCount(), parentTexts.size());
// verify that the items are still expanded
- for (const QTreeWidgetItem *item : qAsConst(items)) {
+ for (const QTreeWidgetItem *item : std::as_const(items)) {
if (item->childCount() > 0)
QVERIFY(item->isExpanded());
QModelIndex idx = tree.indexFromItem(item);
@@ -2332,10 +2332,10 @@ void tst_QTreeWidget::insertExpandedItemsWithSorting()
PersistentModelIndexVec children;
for (int i = 0; i < model->rowCount(parents.constFirst()); ++i)
children.push_back(model->index(i, 0, parents.constFirst()));
- for (int i = 0; i < parentResult.count(); ++i) {
+ for (int i = 0; i < parentResult.size(); ++i) {
QTreeWidgetItem *item = tree.topLevelItem(i);
QCOMPARE(item->text(0), parentResult.at(i));
- for (int j = 0; j < childResult.count(); ++j)
+ for (int j = 0; j < childResult.size(); ++j)
QCOMPARE(item->child(j)->text(0), childResult.at(j));
}
}
@@ -2427,19 +2427,19 @@ void tst_QTreeWidget::changeDataWithSorting()
QTreeWidgetItem *item = w.topLevelItem(itemIndex);
item->setText(0, newValue);
- for (int i = 0; i < expectedItems.count(); ++i) {
+ for (int i = 0; i < expectedItems.size(); ++i) {
QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i));
- for (const QPersistentModelIndex &p : qAsConst(persistent)) {
+ for (const QPersistentModelIndex &p : std::as_const(persistent)) {
if (p.row() == i) // the same toplevel row
QCOMPARE(p.internalPointer(), static_cast<void *>(w.topLevelItem(i)));
}
}
- for (int k = 0; k < persistent.count(); ++k)
+ for (int k = 0; k < persistent.size(); ++k)
QCOMPARE(persistent.at(k).row(), expectedRows.at(k));
- QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(layoutChangedSpy.count(), reorderingExpected ? 1 : 0);
+ QCOMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(layoutChangedSpy.size(), reorderingExpected ? 1 : 0);
}
void tst_QTreeWidget::changeDataWithStableSorting_data()
@@ -2596,19 +2596,19 @@ void tst_QTreeWidget::changeDataWithStableSorting()
item->setText(0, newValue);
if (forceChange)
item->emitDataChanged();
- for (int i = 0; i < expectedItems.count(); ++i) {
+ for (int i = 0; i < expectedItems.size(); ++i) {
QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i));
- for (const QPersistentModelIndex &p : qAsConst(persistent)) {
+ for (const QPersistentModelIndex &p : std::as_const(persistent)) {
if (p.row() == i) // the same toplevel row
QCOMPARE(p.internalPointer(), static_cast<void *>(w.topLevelItem(i)));
}
}
- for (int k = 0; k < persistent.count(); ++k)
+ for (int k = 0; k < persistent.size(); ++k)
QCOMPARE(persistent.at(k).row(), expectedRows.at(k));
- QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(layoutChangedSpy.count(), reorderingExpected ? 1 : 0);
+ QCOMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(layoutChangedSpy.size(), reorderingExpected ? 1 : 0);
}
void tst_QTreeWidget::sizeHint_data()
@@ -2714,8 +2714,8 @@ void tst_QTreeWidget::sortedIndexOfChild()
tw.sortItems(0, sortOrder);
tw.expandAll();
- QCOMPARE(itms.count(), expectedIndexes.count());
- for (int j = 0; j < expectedIndexes.count(); ++j)
+ QCOMPARE(itms.size(), expectedIndexes.size());
+ for (int j = 0; j < expectedIndexes.size(); ++j)
QCOMPARE(top->indexOfChild(itms.at(j)), expectedIndexes.at(j));
}
@@ -2740,8 +2740,8 @@ void tst_QTreeWidget::expandAndCallapse()
tw.collapseItem(top);
tw.collapseItem(top);
- QCOMPARE(spy0.count(), 3);
- QCOMPARE(spy1.count(), 2);
+ QCOMPARE(spy0.size(), 3);
+ QCOMPARE(spy1.size(), 2);
}
void tst_QTreeWidget::setDisabled()
@@ -2854,13 +2854,13 @@ void tst_QTreeWidget::removeSelectedItem()
QItemSelectionModel *selModel = w->selectionModel();
QCOMPARE(selModel->hasSelection(), true);
- QCOMPARE(selModel->selectedRows().count(), 1);
+ QCOMPARE(selModel->selectedRows().size(), 1);
const QScopedPointer<QTreeWidgetItem> taken(w->takeTopLevelItem(2));
QCOMPARE(taken->text(0), QLatin1String("C"));
QCOMPARE(selModel->hasSelection(), false);
- QCOMPARE(selModel->selectedRows().count(), 0);
+ QCOMPARE(selModel->selectedRows().size(), 0);
QItemSelection sel = selModel->selection();
QCOMPARE(selModel->isSelected(w->model()->index(0,0)), false);
}
@@ -2971,7 +2971,7 @@ protected:
auto newItem = new QTreeWidgetItem({QString::number(i++)});
m_list.append(newItem);
insertTopLevelItem(0, newItem);
- while (m_list.count() > 10)
+ while (m_list.size() > 10)
delete m_list.takeFirst();
}
QTreeWidget::timerEvent(event);
@@ -3285,7 +3285,7 @@ void tst_QTreeWidget::emitDataChanged()
auto item = new PublicTreeItem;
tree.insertTopLevelItem(0, item);
item->emitDataChanged();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QTreeWidget::setCurrentItemExpandsParent()
diff --git a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
index 7c1ce7c426..76ebb499f9 100644
--- a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
+++ b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp
@@ -866,7 +866,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags()
QTreeWidgetItemIterator it(testWidget, iteratorflags);
it += start;
int iMatch = 0;
- while (*it && iMatch < matches.count()) {
+ while (*it && iMatch < matches.size()) {
QTreeWidgetItem *item = *it;
QCOMPARE(item->text(0), matches[iMatch]);
++it;