From 12c2a3d85256abcc5a69f05a7504e01e72f24593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Sun, 12 Feb 2012 21:11:04 +0100 Subject: QHeaderView - fix setOffsetToSectionPosition a bit It might be silly to have sections with size 0 without using hideSection. Nevertheless we should still use the principle of least surprise. It does not make sense that hiding a row 'far' away should affect the semantics of setOffsetToSectionPosition on lower indexes. Change-Id: Iaf847eba2ea4d28fc7bcfe3a27d62f432f6f61e0 Reviewed-by: Stephen Kelly --- .../itemviews/qheaderview/tst_qheaderview.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp') diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 4dd57e1b90..3edc125b5a 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -205,6 +205,7 @@ private slots: void QTBUG12268_hiddenMovedSectionSorting(); void QTBUG14242_hideSectionAutoSize(); void ensureNoIndexAtLength(); + void offsetConsistent(); void initialSortOrderRole(); @@ -2168,6 +2169,33 @@ void tst_QHeaderView::ensureNoIndexAtLength() QVERIFY(hv->visualIndexAt(hv->length()) == -1); } +void tst_QHeaderView::offsetConsistent() +{ + // Ensure that a hidden section 'far away' + // does not affect setOffsetToSectionPosition .. + const int sectionToHide = 513; + QTableView qtv; + QStandardItemModel amodel(1000, 4); + qtv.setModel(&amodel); + QHeaderView *hv = qtv.verticalHeader(); + for (int u = 0; u < 100; u += 2) + hv->resizeSection(u, 0); + hv->setOffsetToSectionPosition(150); + int offset1 = hv->offset(); + hv->hideSection(sectionToHide); + hv->setOffsetToSectionPosition(150); + int offset2 = hv->offset(); + QVERIFY(offset1 == offset2); + // Ensure that hidden indexes (still) is considered. + hv->resizeSection(sectionToHide, hv->sectionSize(200) * 2); + hv->setOffsetToSectionPosition(800); + offset1 = hv->offset(); + hv->showSection(sectionToHide); + hv->setOffsetToSectionPosition(800); + offset2 = hv->offset(); + QVERIFY(offset2 > offset1); +} + void tst_QHeaderView::initialSortOrderRole() { QTableView view; // ### Shadowing member view (of type QHeaderView) -- cgit v1.2.3