QHeaderView: properly restore hidden section size on layoutChanged()

During (re)storing the sections within layoutChanged handling, the
hidden section size was not properly stored which lead to a section
size of 0 when the section was unhided afterwards.

Task-number: QTBUG-66413
Task-number: QTBUG-65478
Change-Id: I0b714c7e0530a1eae82b3bb0e0dc80ed576522d0
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
Christian Ehrlicher 2018-02-15 20:24:40 +01:00
parent c9c9adeef9
commit c0e45ae851
2 changed files with 12 additions and 3 deletions

View File

@ -2168,15 +2168,19 @@ void QHeaderViewPrivate::_q_sectionsAboutToBeChanged()
sectionItems[visual].size = lastSectionSize; sectionItems[visual].size = lastSectionSize;
} }
for (int i = 0; i < sectionItems.size(); ++i) { for (int i = 0; i < sectionItems.size(); ++i) {
const auto &s = sectionItems.at(i); auto s = sectionItems.at(i);
// only add if the section is not default and not visually moved // only add if the section is not default and not visually moved
if (s.size == defaultSectionSize && !s.isHidden && s.resizeMode == globalResizeMode) if (s.size == defaultSectionSize && !s.isHidden && s.resizeMode == globalResizeMode)
continue; continue;
const int logical = logicalIndex(i);
if (s.isHidden)
s.size = hiddenSectionSize.value(logical);
// ### note that we are using column or row 0 // ### note that we are using column or row 0
layoutChangePersistentSections.append({orientation == Qt::Horizontal layoutChangePersistentSections.append({orientation == Qt::Horizontal
? model->index(0, logicalIndex(i), root) ? model->index(0, logical, root)
: model->index(logicalIndex(i), 0, root), : model->index(logical, 0, root),
s}); s});
if (layoutChangePersistentSections.size() > 1000) if (layoutChangePersistentSections.size() > 1000)

View File

@ -2286,7 +2286,9 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
tv.setModel(proxyModel); tv.setModel(proxyModel);
const int section4Size = tv.horizontalHeader()->sectionSize(4) + 1; const int section4Size = tv.horizontalHeader()->sectionSize(4) + 1;
const int section5Size = section4Size + 1;
tv.horizontalHeader()->resizeSection(4, section4Size); tv.horizontalHeader()->resizeSection(4, section4Size);
tv.horizontalHeader()->resizeSection(5, section5Size);
tv.setColumnHidden(5, true); tv.setColumnHidden(5, true);
tv.setColumnHidden(6, true); tv.setColumnHidden(6, true);
tv.horizontalHeader()->swapSections(8, 10); tv.horizontalHeader()->swapSections(8, 10);
@ -2298,6 +2300,9 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QCOMPARE(tv.horizontalHeader()->logicalIndex(8), 10); QCOMPARE(tv.horizontalHeader()->logicalIndex(8), 10);
QCOMPARE(tv.horizontalHeader()->logicalIndex(10), 8); QCOMPARE(tv.horizontalHeader()->logicalIndex(10), 8);
QCOMPARE(tv.horizontalHeader()->sectionSize(4), section4Size); QCOMPARE(tv.horizontalHeader()->sectionSize(4), section4Size);
tv.setColumnHidden(5, false); // unhide, section size must be properly restored
QCOMPARE(tv.horizontalHeader()->sectionSize(5), section5Size);
tv.setColumnHidden(5, true);
QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int))); QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int)));
QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int))); QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int)));