QHeaderView: Reset lastSectionLogicalIdx on clear()

Otherwise we can fail to stretch the last section when adding new
sections.

Task-number: QTBUG-52446
Change-Id: I7eb5267ac500bf4246e57c3e3a43268bb65ef1f7
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
Ulf Hermann 2016-08-08 17:23:18 +02:00
parent a8390bb197
commit fa95eb0554
2 changed files with 6 additions and 0 deletions

View File

@ -3465,6 +3465,7 @@ void QHeaderViewPrivate::clear()
sectionSelected.clear();
hiddenSectionSize.clear();
sectionItems.clear();
lastSectionLogicalIdx = -1;
invalidateCachedSizeHint();
}
}

View File

@ -3014,6 +3014,11 @@ void tst_QHeaderView::stretchAndRestoreLastSection()
header.swapSections(1, 11);
QCOMPARE(header.sectionSize(1), someOtherSectionSize);
// Clear and re-add. This triggers a different code path than seColumnCount(0)
m.clear();
m.setColumnCount(3);
QVERIFY(header.sectionSize(2) >= biggerSizeThanAnySection);
// Test import/export of the original (not stretched) sectionSize.
m.setColumnCount(0);
m.setColumnCount(10);