diff options
Diffstat (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp')
-rw-r--r-- | tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index d5813d64ff..88c09de8e0 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -218,6 +218,7 @@ private slots: void QTBUG75615_sizeHintWithStylesheet(); void ensureNoIndexAtLength(); void offsetConsistent(); + void sectionsDontSortWhenNotClickingInThem(); void initialSortOrderRole(); @@ -250,6 +251,7 @@ private slots: void testResetCachedSizeHint(); void statusTips(); void testRemovingColumnsViaLayoutChanged(); + void testModelMovingColumns(); protected: void setupTestData(bool use_reset_model = false); @@ -359,6 +361,12 @@ public: endRemoveColumns(); } + void moveColumn(int from, int to) + { + beginMoveColumns(QModelIndex(), from, from, QModelIndex(), to); + endMoveColumns(); + } + void cleanup() { emit layoutAboutToBeChanged(); @@ -2628,6 +2636,140 @@ void tst_QHeaderView::offsetConsistent() QVERIFY(offset2 > offset1); } +void tst_QHeaderView::sectionsDontSortWhenNotClickingInThem() +{ + QTableView qtv; + QStandardItemModel amodel(1000, 4); + qtv.setModel(&amodel); + QHeaderView *hv = qtv.horizontalHeader(); + hv->setSectionsClickable(true); + hv->setFirstSectionMovable(true); + hv->setSectionsMovable(false); + + enum { DefaultYOffset = 5, OutOfRangeYOffset = 10000 }; + + const auto pressOnSection = [&](int section, int yOffset = DefaultYOffset) + { + QTest::mousePress(hv->viewport(), Qt::LeftButton, Qt::NoModifier, + QPoint(hv->sectionViewportPosition(section) + hv->sectionSize(section) / 2, yOffset)); + }; + const auto moveOntoSection = [&](int section, int yOffset = DefaultYOffset) + { + QTest::mouseMove(hv->viewport(), + QPoint(hv->sectionViewportPosition(section) + hv->sectionSize(section) / 2, yOffset)); + }; + const auto releaseOnSection = [&](int section, int yOffset = DefaultYOffset) + { + QTest::mouseRelease(hv->viewport(), Qt::LeftButton, Qt::NoModifier, + QPoint(hv->sectionViewportPosition(section) + hv->sectionSize(section) / 2, yOffset)); + }; + + hv->setSortIndicator(-1, Qt::AscendingOrder); + QCOMPARE(hv->sortIndicatorSection(), -1); + + pressOnSection(0); + releaseOnSection(0); + // RESULT: sorting + QCOMPARE(hv->sortIndicatorSection(), 0); + + hv->setSortIndicator(-1, Qt::AscendingOrder); + QCOMPARE(hv->sortIndicatorSection(), -1); + + pressOnSection(0); + moveOntoSection(1); + releaseOnSection(1); + // RESULT: no sorting + QCOMPARE(hv->sortIndicatorSection(), -1); + + pressOnSection(0); + moveOntoSection(1); + moveOntoSection(2); + releaseOnSection(2); + // RESULT: no sorting + QCOMPARE(hv->sortIndicatorSection(), -1); + + pressOnSection(0); + moveOntoSection(1); + moveOntoSection(0); + releaseOnSection(0); + // RESULT: sorting by 0 + QCOMPARE(hv->sortIndicatorSection(), 0); + + pressOnSection(0); + moveOntoSection(1); + releaseOnSection(1); + // RESULT: no change, still sorting by 0 + QCOMPARE(hv->sortIndicatorSection(), 0); + + auto sortOrder = hv->sortIndicatorOrder(); + pressOnSection(1); + moveOntoSection(0); + releaseOnSection(0); + // RESULT: no change, still sorting by 0 + QCOMPARE(hv->sortIndicatorSection(), 0); + QCOMPARE(hv->sortIndicatorOrder(), sortOrder); + + pressOnSection(1); + moveOntoSection(0); + moveOntoSection(1); + releaseOnSection(1); + // RESULT: sorting by 1 + QCOMPARE(hv->sortIndicatorSection(), 1); + + pressOnSection(1); + moveOntoSection(0); + releaseOnSection(0); + // RESULT: no change, still sorting by 1 + QCOMPARE(hv->sortIndicatorSection(), 1); + + hv->setSortIndicator(-1, Qt::AscendingOrder); + QCOMPARE(hv->sortIndicatorSection(), -1); + + pressOnSection(0); + releaseOnSection(0, OutOfRangeYOffset); + // RESULT: no sorting + QCOMPARE(hv->sortIndicatorSection(), -1); + + pressOnSection(0); + moveOntoSection(0, OutOfRangeYOffset); + releaseOnSection(0, OutOfRangeYOffset); + // RESULT: no sorting + QCOMPARE(hv->sortIndicatorSection(), -1); + + pressOnSection(0); + moveOntoSection(0, OutOfRangeYOffset); + moveOntoSection(0); + releaseOnSection(0); + // RESULT: sorting by 0 + QCOMPARE(hv->sortIndicatorSection(), 0); + + pressOnSection(1); + releaseOnSection(1, OutOfRangeYOffset); + // RESULT: no change, still sorting by 0 + QCOMPARE(hv->sortIndicatorSection(), 0); + + pressOnSection(1); + moveOntoSection(1, OutOfRangeYOffset); + releaseOnSection(1, OutOfRangeYOffset); + // RESULT: no change, still sorting by 0 + QCOMPARE(hv->sortIndicatorSection(), 0); + + pressOnSection(1); + moveOntoSection(1, OutOfRangeYOffset); + moveOntoSection(1); + releaseOnSection(1); + // RESULT: sorting by 1 + QCOMPARE(hv->sortIndicatorSection(), 1); + + pressOnSection(2); + moveOntoSection(1); + moveOntoSection(2); + moveOntoSection(2, OutOfRangeYOffset); + releaseOnSection(2, OutOfRangeYOffset); + // RESULT: no change, still sorting by 1 + QCOMPARE(hv->sortIndicatorSection(), 1); +} + void tst_QHeaderView::initialSortOrderRole() { QTableView view; // ### Shadowing member view (of type QHeaderView) @@ -3492,5 +3634,18 @@ void tst_QHeaderView::testRemovingColumnsViaLayoutChanged() // The main point of this test is that the section-size restoring code didn't go out of bounds. } +void tst_QHeaderView::testModelMovingColumns() +{ + QtTestModel model(10, 10); + QHeaderView hv(Qt::Horizontal); + hv.setModel(&model); + hv.resizeSections(QHeaderView::ResizeToContents); + hv.show(); + + QPersistentModelIndex index3 = model.index(0, 3); + model.moveColumn(3, 1); + QCOMPARE(index3.column(), 1); +} + QTEST_MAIN(tst_QHeaderView) #include "tst_qheaderview.moc" |