From 77a8e90cddcfa1c34518ef846a4838874a7bc0c7 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 29 Dec 2016 18:15:53 +0100 Subject: QHeaderView: fix restoreState() on a model with more columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When saving state for a 3-columns headerview and then restoring that state onto a 5-column headerview, the headerview shouldn't suddenly think it has 3 columns. Rather than making restoreState() fail, we adjust for the additional columns, so that we can still apply the customizations from the user to all other columns (hiding, moving, etc.). Change-Id: I3f220aa322ea8b629d2fe345f8cde13e0ea615d6 Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/itemviews/qheaderview.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 837383f016..1310a060ea 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3857,6 +3857,20 @@ bool QHeaderViewPrivate::read(QDataStream &in) if (sectionItemsLengthTotal != lengthIn) return false; + 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); + } + const int insertCount = currentCount - newSectionItems.count(); + const int insertLength = defaultSectionSizeIn * insertCount; + lengthIn += insertLength; + SectionItem section(defaultSectionSizeIn, globalResizeMode); + newSectionItems.insert(newSectionItems.count(), insertCount, section); // append + } + orientation = static_cast(orient); sortIndicatorOrder = static_cast(order); sortIndicatorSection = sortIndicatorSectionIn; -- cgit v1.2.3