summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qheaderview.cpp
diff options
context:
space:
mode:
authorArnaud Bienner <arnaud.bienner@gmail.com>2015-01-29 21:35:37 +0100
committerArnaud Bienner <arnaud.bienner@gmail.com>2015-02-03 08:45:33 +0000
commitcd7a36d341c84f2595a33ceeb6ac7458978f30e1 (patch)
treef6888c333403e78f8d14b172d97d42e72c42b016 /src/widgets/itemviews/qheaderview.cpp
parentb85b78f17d3d18887b409a3ce9d2f2c71ae68844 (diff)
QHeaderView: check that length is correct and fix restoring Qt4 state.
When multiple sections were grouped together, sectionItem.size was the total size of grouped sections, not the size of one section. Length is supposed to be equal to the section items length, but the state saved might be corrupted. Task-number: QTBUG-40462 Change-Id: I401a1583dd30880ccf5b4c105a237d6563f212e8 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src/widgets/itemviews/qheaderview.cpp')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp77
1 files changed, 54 insertions, 23 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index beade16339..fe99f7a5e0 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -3641,6 +3641,17 @@ bool QHeaderViewPrivate::read(QDataStream &in)
QVector<int> visualIndicesIn;
QVector<int> logicalIndicesIn;
QHash<int, int> hiddenSectionSizeIn;
+ bool movableSectionsIn;
+ bool clickableSectionsIn;
+ bool highlightSelectedIn;
+ bool stretchLastSectionIn;
+ bool cascadingResizingIn;
+ int stretchSectionsIn;
+ int contentsSectionsIn;
+ int defaultSectionSizeIn;
+ int minimumSectionSizeIn;
+ QVector<SectionItem> sectionItemsIn;
+
in >> orient;
in >> order;
@@ -3662,6 +3673,39 @@ bool QHeaderViewPrivate::read(QDataStream &in)
if (in.status() != QDataStream::Ok || lengthIn < 0)
return false;
+ in >> movableSectionsIn;
+ in >> clickableSectionsIn;
+ in >> highlightSelectedIn;
+ in >> stretchLastSectionIn;
+ in >> cascadingResizingIn;
+ in >> stretchSectionsIn;
+ in >> contentsSectionsIn;
+ in >> defaultSectionSizeIn;
+ in >> minimumSectionSizeIn;
+
+ in >> align;
+
+ in >> global;
+
+ in >> sectionItemsIn;
+ // In Qt4 we had a vector of spans where one span could hold information on more sections.
+ // Now we have an itemvector where one items contains information about one section
+ // For backward compatibility with Qt4 we do the following
+ QVector<SectionItem> newSectionItems;
+ for (int u = 0; u < sectionItemsIn.count(); ++u) {
+ int count = sectionItemsIn.at(u).tmpDataStreamSectionCount;
+ if (count > 0)
+ sectionItemsIn[u].size /= count;
+ for (int n = 0; n < count; ++n)
+ newSectionItems.append(sectionItemsIn[u]);
+ }
+
+ int sectionItemsLengthTotal = 0;
+ foreach (const SectionItem &section, newSectionItems)
+ sectionItemsLengthTotal += section.size;
+ if (sectionItemsLengthTotal != lengthIn)
+ return false;
+
orientation = static_cast<Qt::Orientation>(orient);
sortIndicatorOrder = static_cast<Qt::SortOrder>(order);
sortIndicatorSection = sortIndicatorSectionIn;
@@ -3671,32 +3715,19 @@ bool QHeaderViewPrivate::read(QDataStream &in)
hiddenSectionSize = hiddenSectionSizeIn;
length = lengthIn;
- in >> movableSections;
- in >> clickableSections;
- in >> highlightSelected;
- in >> stretchLastSection;
- in >> cascadingResizing;
- in >> stretchSections;
- in >> contentsSections;
- in >> defaultSectionSize;
- in >> minimumSectionSize;
+ movableSections = movableSectionsIn;
+ clickableSections = clickableSectionsIn;
+ highlightSelected = highlightSelectedIn;
+ stretchLastSection = stretchLastSectionIn;
+ cascadingResizing = cascadingResizingIn;
+ stretchSections = stretchSectionsIn;
+ contentsSections = contentsSectionsIn;
+ defaultSectionSize = defaultSectionSizeIn;
+ minimumSectionSize = minimumSectionSizeIn;
- in >> align;
defaultAlignment = Qt::Alignment(align);
+ globalResizeMode = static_cast<QHeaderView::ResizeMode>(global);
- in >> global;
- globalResizeMode = (QHeaderView::ResizeMode)global;
-
- in >> sectionItems;
- // In Qt4 we had a vector of spans where one span could hold information on more sections.
- // Now we have an itemvector where one items contains information about one section
- // For backward compatibility with Qt4 we do the following
- QVector<SectionItem> newSectionItems;
- for (int u = 0; u < sectionItems.count(); ++u) {
- int count = sectionItems.at(u).tmpDataStreamSectionCount;
- for (int n = 0; n < count; ++n)
- newSectionItems.append(sectionItems[u]);
- }
sectionItems = newSectionItems;
setHiddenSectionsFromBitVector(sectionHidden);
recalcSectionStartPos();