diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2020-12-22 14:16:59 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2021-02-12 17:39:37 +0100 |
commit | 77e1cc4b39fb030a5c299a2d068ff24ce232f5f6 (patch) | |
tree | 4bcd386f129d9d5e570234295f9865858353d89b /src/widgets/itemviews | |
parent | 1fc3c6f9b9f62cc3ff2b9106a67523c76c63ac3b (diff) |
QHeaderView: pass sectionSize to createSectionItems()
.. instead complete size for the affected range. The complete size was
calculated before for every call of createSectionItems() and then the
function calculated the size per section back for no reason.
Passing the sum of all sections is therefore not needed and may lead to
an integer overflow for big datasets.
Task-number: QTBUG-88728
Change-Id: I8af0b0c3e97021ff0637fe1ee3ca3adfa23a2d0e
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qheaderview.cpp | 11 | ||||
-rw-r--r-- | src/widgets/itemviews/qheaderview_p.h | 2 |
2 files changed, 5 insertions, 8 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index e815ff53fa..cf74db49fb 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2362,7 +2362,7 @@ void QHeaderView::initializeSections(int start, int end) d->contentsSections = newSectionCount; if (newSectionCount > oldCount) - d->createSectionItems(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode); + d->createSectionItems(start, end, d->defaultSectionSize, d->globalResizeMode); //Q_ASSERT(d->headerLength() == d->length); if (d->sectionCount() != oldCount) @@ -3681,8 +3681,7 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool //Q_ASSERT(newSectionLength > 0); if ((previousSectionResizeMode != newSectionResizeMode || previousSectionLength != newSectionLength) && i > 0) { - int spanLength = (i - spanStartSection) * previousSectionLength; - createSectionItems(spanStartSection, i - 1, spanLength, previousSectionResizeMode); + createSectionItems(spanStartSection, i - 1, previousSectionLength, previousSectionResizeMode); //Q_ASSERT(headerLength() == length); spanStartSection = i; } @@ -3695,16 +3694,14 @@ void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool } createSectionItems(spanStartSection, sectionCount() - 1, - (sectionCount() - spanStartSection) * previousSectionLength, - previousSectionResizeMode); + previousSectionLength, previousSectionResizeMode); //Q_ASSERT(headerLength() == length); resizeRecursionBlock = false; viewport->update(); } -void QHeaderViewPrivate::createSectionItems(int start, int end, int size, QHeaderView::ResizeMode mode) +void QHeaderViewPrivate::createSectionItems(int start, int end, int sizePerSection, QHeaderView::ResizeMode mode) { - int sizePerSection = size / (end - start + 1); if (end >= sectionItems.count()) { sectionItems.resize(end + 1); sectionStartposRecalc = true; diff --git a/src/widgets/itemviews/qheaderview_p.h b/src/widgets/itemviews/qheaderview_p.h index e8a096bf98..130220523f 100644 --- a/src/widgets/itemviews/qheaderview_p.h +++ b/src/widgets/itemviews/qheaderview_p.h @@ -341,7 +341,7 @@ public: }; QList<LayoutChangeItem> layoutChangePersistentSections; - void createSectionItems(int start, int end, int size, QHeaderView::ResizeMode mode); + void createSectionItems(int start, int end, int sectionSize, QHeaderView::ResizeMode mode); void removeSectionsFromSectionItems(int start, int end); void resizeSectionItem(int visualIndex, int oldSize, int newSize); void setDefaultSectionSize(int size); |