QHeaderView - minor fix to setDefaultSectionSize

This fixes a situation where we (wrongly) assume that
a section with size 0 is hidden. However a hidden
section should be one that we have called hideSection
(or setSectionHidden) on.

Change-Id: Ic14eded2666022f27434dc55927323a74910549c
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-03-10 16:47:02 +01:00 committed by Qt by Nokia
parent 07ff7fe52c
commit fcc01e6c37
2 changed files with 28 additions and 2 deletions

View File

@ -3339,8 +3339,7 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size)
defaultSectionSize = size;
for (int i = 0; i < sectionSpans.count(); ++i) {
QHeaderViewPrivate::SectionSpan &span = sectionSpans[i];
if (span.size > 0) {
//we resize it if it is not hidden (ie size > 0)
if (sectionHidden.isEmpty() || !sectionHidden.testBit(i)) { // resize on not hidden.
const int newSize = size;
if (newSize != span.size) {
length += newSize - span.size; //the whole length is changed

View File

@ -170,6 +170,7 @@ private slots:
void moveSectionAndReset();
void moveSectionAndRemove();
void saveRestore();
void defaultSectionSizeTest();
void defaultAlignment_data();
void defaultAlignment();
@ -1625,6 +1626,32 @@ void tst_QHeaderView::saveRestore()
QVERIFY(s1 == s2);
}
void tst_QHeaderView::defaultSectionSizeTest()
{
// Setup
QTableView qtv;
QStandardItemModel amodel(4, 4);
qtv.setModel(&amodel);
QHeaderView *hv = qtv.verticalHeader();
const int defaultSize = 26;
hv->setDefaultSectionSize(defaultSize + 1); // Set it to a value different from defaultSize.
// no hidden Sections
hv->resizeSection(1, 0);
hv->setDefaultSectionSize(defaultSize);
QVERIFY(hv->sectionSize(1) == defaultSize);
// with hidden sections
hv->resizeSection(1, 0);
hv->hideSection(2);
hv->setDefaultSectionSize(defaultSize);
QVERIFY(hv->sectionSize(0) == defaultSize); // trivial case.
QVERIFY(hv->sectionSize(1) == defaultSize); // just sized 0. Now it should be 10
QVERIFY(hv->sectionSize(2) == 0); // section is hidden. It should not be resized.
}
void tst_QHeaderView::defaultAlignment_data()
{
QTest::addColumn<int>("direction");