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>
bb10
Christian Ehrlicher 2020-12-22 14:16:59 +01:00
parent 1fc3c6f9b9
commit 77e1cc4b39
2 changed files with 5 additions and 8 deletions

View File

@ -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;

View File

@ -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);