Regression fix to QHeaderView::setDefaultSectionSize

When the sections has been resized we need to calculate new values
for the section start-positions. Otherwise we break visualIndexAt
and sectionPosition.

This fixes a regression introduced in
b800d8b94a

Change-Id: I148dbf44f742208787ed59b70d82b8048d721e90
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-11-09 15:58:57 +01:00 committed by The Qt Project
parent 46fe591a53
commit fc271b4273
2 changed files with 8 additions and 1 deletions

View File

@ -3382,6 +3382,7 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size)
}
}
}
sectionStartposRecalc = true;
}
void QHeaderViewPrivate::recalcSectionStartPos() const // linear (but fast)

View File

@ -1637,9 +1637,15 @@ void tst_QHeaderView::defaultSectionSizeTest()
{
// Setup
QTableView qtv;
QHeaderView *hv = qtv.verticalHeader();
hv->setDefaultSectionSize(99); // Set it to a value different from defaultSize.
QStandardItemModel amodel(4, 4);
qtv.setModel(&amodel);
QHeaderView *hv = qtv.verticalHeader();
QCOMPARE(hv->sectionSize(0), 99);
QCOMPARE(hv->visualIndexAt(50), 0); // <= also make sure that indexes are calculated
hv->setDefaultSectionSize(40); // Set it to a value different from defaultSize.
QCOMPARE(hv->visualIndexAt(50), 1);
const int defaultSize = 26;
hv->setDefaultSectionSize(defaultSize + 1); // Set it to a value different from defaultSize.