diff options
author | David Faure <david.faure@kdab.com> | 2019-04-13 19:37:37 +0200 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2019-04-23 09:42:54 +0000 |
commit | ba6e0e4aac4d06782325c7032c8ea475f2d3eab0 (patch) | |
tree | 97a2e6b03741ab3f9f5b6a5965b000560ad0eaab /src/widgets/itemviews | |
parent | 49be1a3c1f81a85ab3e9061bc95bf61ebc35ef08 (diff) |
QHeaderView: fix assert when restoring section sizes over less columns
If columns are removed and we get notified via layoutChanged, the code
tries to restore old section sizes, and went out of bounds, leading to
an assert in QVector. Simply add an if() to skip restoring out-of-bounds columns.
This comes from https://bugs.kde.org/show_bug.cgi?id=395181,
which translates into the unittest that is part of this commit.
Change-Id: Ide42176a758f87b21957c40508127d67f1d5a2d9
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qheaderview.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 62abf56751..99309633a7 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2283,13 +2283,15 @@ void QHeaderViewPrivate::_q_sectionsChanged(const QList<QPersistentModelIndex> & : index.row()); // the new visualIndices are already adjusted / reset by initializeSections() const int newVisualIndex = visualIndex(newLogicalIndex); - auto &newSection = sectionItems[newVisualIndex]; - newSection = item.section; - - if (newSection.isHidden) { - // otherwise setSectionHidden will return without doing anything - newSection.isHidden = false; - q->setSectionHidden(newLogicalIndex, true); + if (newVisualIndex < sectionItems.count()) { + auto &newSection = sectionItems[newVisualIndex]; + newSection = item.section; + + if (newSection.isHidden) { + // otherwise setSectionHidden will return without doing anything + newSection.isHidden = false; + q->setSectionHidden(newLogicalIndex, true); + } } } |