summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qheaderview.cpp
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2016-12-29 18:15:53 +0100
committerDavid Faure <david.faure@kdab.com>2016-12-29 17:32:58 +0000
commit77a8e90cddcfa1c34518ef846a4838874a7bc0c7 (patch)
treed88f2e8f6c57e91317786205582d67db102a3592 /src/widgets/itemviews/qheaderview.cpp
parent73dafaf265a6c6a51611a093c2cc81a6d61767a9 (diff)
QHeaderView: fix restoreState() on a model with more columns
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 <tmartsum@gmail.com>
Diffstat (limited to 'src/widgets/itemviews/qheaderview.cpp')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp14
1 files changed, 14 insertions, 0 deletions
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<Qt::Orientation>(orient);
sortIndicatorOrder = static_cast<Qt::SortOrder>(order);
sortIndicatorSection = sortIndicatorSectionIn;