summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp137
1 files changed, 80 insertions, 57 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 85edd09d44..57efa3e349 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -1,6 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// Copyright (C) 2012 Thorbjørn Lund Martsum - tmartsum[at]gmail.com
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QHeaderView>
#include <QProxyStyle>
@@ -227,6 +227,7 @@ private slots:
void statusTips();
void testRemovingColumnsViaLayoutChanged();
void testModelMovingColumns();
+ void testModelMovingRows();
protected:
void setupTestData(bool use_reset_model = false);
@@ -307,6 +308,12 @@ public:
endRemoveRows();
}
+ void moveRow(int from, int to)
+ {
+ beginMoveRows(QModelIndex(), from, from, QModelIndex(), to);
+ endMoveRows();
+ }
+
void removeOneColumn(int col)
{
beginRemoveColumns(QModelIndex(), col, col);
@@ -475,7 +482,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);
}
@@ -796,10 +803,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));
}
@@ -911,14 +918,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()
@@ -964,9 +971,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);
@@ -974,7 +981,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));
}
@@ -982,7 +989,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()
@@ -1167,14 +1174,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));
}
@@ -1201,7 +1208,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));
}
@@ -1272,21 +1279,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));
}
@@ -1339,19 +1346,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);
@@ -1368,8 +1375,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);
@@ -1613,7 +1620,6 @@ void tst_QHeaderView::focusPolicy()
widget.show();
widget.setFocus(Qt::OtherFocusReason);
- QApplicationPrivate::setActiveWindow(&widget);
widget.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&widget));
QVERIFY(widget.hasFocus());
@@ -1737,7 +1743,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);
@@ -2041,9 +2047,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()
@@ -2063,19 +2069,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()
@@ -2191,6 +2197,9 @@ void tst_QHeaderView::preserveHiddenSectionWidth()
void tst_QHeaderView::invisibleStretchLastSection()
{
+ if (QGuiApplication::platformName().startsWith(QLatin1String("eglfs"), Qt::CaseInsensitive))
+ QSKIP("EGLFS does not allow resizing on top window");
+
int count = 6;
QStandardItemModel model(1, count);
QHeaderView view(Qt::Horizontal);
@@ -2256,7 +2265,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));
@@ -2264,13 +2273,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));
}
@@ -2302,10 +2311,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)
@@ -2396,8 +2405,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);
@@ -2405,8 +2414,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);
@@ -2414,8 +2423,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);
}
@@ -2542,7 +2551,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.
@@ -2558,7 +2567,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:
@@ -2842,10 +2851,6 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
int sum_visual = 0;
int sum_logical = 0;
- int sum_size = 0;
- int sum_hidden_size = 0;
- int sum_lookup_visual = 0;
- int sum_lookup_logical = 0;
int chk_visual = 1;
int chk_logical = 1;
@@ -2865,7 +2870,6 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
sum_visual += visual;
sum_logical += logical;
- sum_size += ssize;
if (visual >= 0) {
chk_visual %= p2;
@@ -2885,7 +2889,6 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
if (view->isSectionHidden(i)) {
view->showSection(i);
int hiddensize = view->sectionSize(i);
- sum_hidden_size += hiddensize;
chk_hidden_size %= p2;
chk_hidden_size += ( (hiddensize + 1) * (i + 1) * p1);
// (hiddensize + 1) in the above to differ between hidden and size 0
@@ -2904,8 +2907,6 @@ void tst_QHeaderView::calculateAndCheck(int cppline, const int precalced_compare
for (int u = 0; u < max_lookup_count; ++u) {
int visu = view->visualIndexAt(u);
int logi = view->logicalIndexAt(u);
- sum_lookup_visual += logi;
- sum_lookup_logical += visu;
chk_lookup_visual %= p2;
chk_lookup_visual *= ( (u + 1) * p1 * (visu + 2));
chk_lookup_logical %= p2;
@@ -3610,7 +3611,6 @@ void tst_QHeaderView::statusTips()
headerView.setGeometry(QRect(QPoint(QGuiApplication::primaryScreen()->geometry().center() - QPoint(250, 250)),
QSize(500, 500)));
headerView.show();
- QApplicationPrivate::setActiveWindow(&headerView);
QVERIFY(QTest::qWaitForWindowActive(&headerView));
// Ensure it is moved away first and then moved to the relevant section
@@ -3652,10 +3652,33 @@ void tst_QHeaderView::testModelMovingColumns()
hv.setModel(&model);
hv.resizeSections(QHeaderView::ResizeToContents);
hv.show();
+ hv.hideSection(3);
+ QVERIFY(!hv.isSectionHidden(1));
+ QVERIFY(hv.isSectionHidden(3));
QPersistentModelIndex index3 = model.index(0, 3);
model.moveColumn(3, 1);
QCOMPARE(index3.column(), 1);
+ QVERIFY(hv.isSectionHidden(1));
+ QVERIFY(!hv.isSectionHidden(3));
+}
+
+void tst_QHeaderView::testModelMovingRows()
+{
+ QtTestModel model(10, 10);
+ QHeaderView hv(Qt::Vertical);
+ hv.setModel(&model);
+ hv.resizeSections(QHeaderView::ResizeToContents);
+ hv.show();
+ hv.hideSection(3);
+ QVERIFY(!hv.isSectionHidden(1));
+ QVERIFY(hv.isSectionHidden(3));
+
+ QPersistentModelIndex index3 = model.index(3, 0);
+ model.moveRow(3, 1);
+ QCOMPARE(index3.row(), 1);
+ QVERIFY(hv.isSectionHidden(1));
+ QVERIFY(!hv.isSectionHidden(3));
}
QTEST_MAIN(tst_QHeaderView)