From: Thorbjørn Lund Martsum Date: Wed, 18 Jan 2012 14:34:06 +0000 (+0100) Subject: QHeaderView - length returns wrong value fix X-Git-Tag: qt-v5.0.0-alpha1~1495 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=125016ad241125176e5bebab94eebcf50fac20bc;p=profile%2Fivi%2Fqtbase.git QHeaderView - length returns wrong value fix setSectionHidden called with (logindex, true) will sometimes prevent a (correct) call to resizeSection(logicalIndex, 0). This seems a bit odd - however it does execute d->doDelayedResizeSections(). Therefore the section is going to be hidden later. However it is a problem that the length meanwhile is wrong. (That is a value that is not the sum of the sections) This is fixed by execute updates before returning the length. Task-number: QTBUG-14242 Change-Id: Ia1d2f6db3213792b250a6a37942b56554261cd3a Reviewed-by: Robin Burchell --- diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 660570b..af83fb9 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -517,6 +517,8 @@ void QHeaderView::setOffsetToLastSection() int QHeaderView::length() const { Q_D(const QHeaderView); + d->executePostedLayout(); + d->executePostedResize(); //Q_ASSERT(d->headerLength() == d->length); return d->length; } diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 8772177..62da333 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -181,6 +181,7 @@ private slots: void QTBUG7833_sectionClicked(); void QTBUG8650_crashOnInsertSections(); void QTBUG12268_hiddenMovedSectionSorting(); + void QTBUG14242_hideSectionAutoSize(); void initialSortOrderRole(); @@ -2072,6 +2073,26 @@ void tst_QHeaderView::QTBUG12268_hiddenMovedSectionSorting() QCOMPARE(view.horizontalHeader()->hiddenSectionCount(), 1); } +void tst_QHeaderView::QTBUG14242_hideSectionAutoSize() +{ + QTableView qtv; + QStandardItemModel amodel(4, 4); + qtv.setModel(&amodel); + QHeaderView *hv = qtv.verticalHeader(); + hv->setDefaultSectionSize(25); + hv->setResizeMode(QHeaderView::ResizeToContents); + qtv.show(); + + hv->hideSection(0); + int afterlength = hv->length(); + + int calced_length = 0; + for (int u = 0; u < hv->count(); ++u) + calced_length += hv->sectionSize(u); + + QVERIFY(calced_length == afterlength); +} + void tst_QHeaderView::initialSortOrderRole() { QTableView view;