summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/itemviews/qheaderview.cpp31
-rw-r--r--src/gui/itemviews/qheaderview_p.h3
-rw-r--r--tests/auto/qheaderview/tst_qheaderview.cpp24
3 files changed, 50 insertions, 8 deletions
diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp
index 5bd82d41e1..dc63b25d3d 100644
--- a/src/gui/itemviews/qheaderview.cpp
+++ b/src/gui/itemviews/qheaderview.cpp
@@ -1388,8 +1388,7 @@ int QHeaderView::defaultSectionSize() const
void QHeaderView::setDefaultSectionSize(int size)
{
Q_D(QHeaderView);
- d->defaultSectionSize = size;
- d->forceInitializing = true;
+ d->setDefaultSectionSize(size);
}
/*!
@@ -1894,9 +1893,6 @@ void QHeaderView::initializeSections()
//make sure we update the hidden sections
if (newCount < oldCount)
d->updateHiddenSections(0, newCount-1);
- } else if (d->forceInitializing) {
- initializeSections(0, newCount - 1);
- d->forceInitializing = false;
}
}
@@ -1952,7 +1948,7 @@ void QHeaderView::initializeSections(int start, int end)
if (!d->sectionHidden.isEmpty())
d->sectionHidden.resize(d->sectionCount);
- if (d->sectionCount > oldCount || d->forceInitializing)
+ if (d->sectionCount > oldCount)
d->createSectionSpan(start, end, (end - start + 1) * d->defaultSectionSize, d->globalResizeMode);
//Q_ASSERT(d->headerLength() == d->length);
@@ -3364,6 +3360,29 @@ void QHeaderViewPrivate::cascadingResize(int visual, int newSize)
viewport->update();
}
+void QHeaderViewPrivate::setDefaultSectionSize(int size)
+{
+ Q_Q(QHeaderView);
+ defaultSectionSize = size;
+ int currentVisualIndex = 0;
+ for (int i = 0; i < sectionSpans.count(); ++i) {
+ QHeaderViewPrivate::SectionSpan &span = sectionSpans[i];
+ if (span.size > 0) {
+ //we resize it if it is not hidden (ie size > 0)
+ const int newSize = span.count * size;
+ if (newSize != span.size) {
+ length += newSize - span.size; //the whole length is changed
+ const int oldSectionSize = span.sectionSize();
+ span.size = span.count * size;
+ for (int i = currentVisualIndex; i < currentVisualIndex + span.count; ++i) {
+ emit q->sectionResized(logicalIndex(i), oldSectionSize, size);
+ }
+ }
+ }
+ currentVisualIndex += span.count;
+ }
+}
+
void QHeaderViewPrivate::resizeSectionSpan(int visualIndex, int oldSize, int newSize)
{
Q_Q(QHeaderView);
diff --git a/src/gui/itemviews/qheaderview_p.h b/src/gui/itemviews/qheaderview_p.h
index fbba69a647..2889f08300 100644
--- a/src/gui/itemviews/qheaderview_p.h
+++ b/src/gui/itemviews/qheaderview_p.h
@@ -90,7 +90,6 @@ public:
highlightSelected(false),
stretchLastSection(false),
cascadingResizing(false),
- forceInitializing(false),
stretchSections(0),
contentsSections(0),
minimumSectionSize(-1),
@@ -275,7 +274,6 @@ public:
bool highlightSelected;
bool stretchLastSection;
bool cascadingResizing;
- bool forceInitializing;
int stretchSections;
int contentsSections;
int defaultSectionSize;
@@ -310,6 +308,7 @@ public:
void createSectionSpan(int start, int end, int size, QHeaderView::ResizeMode mode);
void removeSectionsFromSpans(int start, int end);
void resizeSectionSpan(int visualIndex, int oldSize, int newSize);
+ void setDefaultSectionSize(int size);
inline int headerSectionCount() const { // for debugging
int count = 0;
diff --git a/tests/auto/qheaderview/tst_qheaderview.cpp b/tests/auto/qheaderview/tst_qheaderview.cpp
index 0867e48a2b..6478854def 100644
--- a/tests/auto/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/qheaderview/tst_qheaderview.cpp
@@ -187,6 +187,7 @@ private slots:
void emptySectionSpan();
void task236450_hidden_data();
void task236450_hidden();
+ void task248050_hideRow();
protected:
QHeaderView *view;
@@ -1919,5 +1920,28 @@ void tst_QHeaderView::task236450_hidden()
}
+void tst_QHeaderView::task248050_hideRow()
+{
+ //this is the sequence of events that make the task fail
+ protected_QHeaderView header(Qt::Vertical);
+ QStandardItemModel model(0, 1);
+ header.setStretchLastSection(false);
+ header.setDefaultSectionSize(17);
+ header.setModel(&model);
+ header.doItemsLayout();
+
+ model.setRowCount(3);
+
+ QCOMPARE(header.sectionPosition(2), 17*2);
+
+ header.hideSection(1);
+ QCOMPARE(header.sectionPosition(2), 17);
+
+ QTest::qWait(100);
+ //the size of the section shouldn't have changed
+ QCOMPARE(header.sectionPosition(2), 17);
+}
+
+
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"