From f6b36eaafec24b4c67efff621d380a4ca4257d0b Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 22 May 2017 20:01:04 +0200 Subject: QHeaderView: fix visual/logical index corruption when restoring state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a followup to 77a8e90cddcfa1c34518ef846a4838874a7bc0c7 which didn't handle the case where no columns had been moved. visualIndices and logicalIndices are empty until initializeIndexMapping() is called, in which case appending is wrong. As a result, visualIndex(i) would return -1 for the values over those added by read(), and an assert would happen at painting time. The fix is to leave visualIndices and logicalIndices empty if they are empty already, leaving it to initializeIndexMapping() to fill them later if necessary (e.g. when moving a column). Task-number: QTBUG-60837 Change-Id: Ia7e4b9d3122647984acd434dfaa0400df319d065 Reviewed-by: Marc Mutz Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/itemviews/qheaderview.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index e0e993ce77..76f80c680e 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3876,9 +3876,11 @@ bool QHeaderViewPrivate::read(QDataStream &in) const int currentCount = (orient == Qt::Horizontal ? model->columnCount(root) : model->rowCount(root)); if (newSectionItems.count() < currentCount) { // we have sections not in the saved state, give them default settings - for (int i = newSectionItems.count(); i < currentCount; ++i) { - visualIndicesIn.append(i); - logicalIndicesIn.append(i); + if (!visualIndicesIn.isEmpty() && !logicalIndicesIn.isEmpty()) { + for (int i = newSectionItems.count(); i < currentCount; ++i) { + visualIndicesIn.append(i); + logicalIndicesIn.append(i); + } } const int insertCount = currentCount - newSectionItems.count(); const int insertLength = defaultSectionSizeIn * insertCount; -- cgit v1.2.3