summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2019-04-13 19:37:37 +0200
committerDavid Faure <david.faure@kdab.com>2019-04-23 09:42:54 +0000
commitba6e0e4aac4d06782325c7032c8ea475f2d3eab0 (patch)
tree97a2e6b03741ab3f9f5b6a5965b000560ad0eaab /tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
parent49be1a3c1f81a85ab3e9061bc95bf61ebc35ef08 (diff)
QHeaderView: fix assert when restoring section sizes over less columns
If columns are removed and we get notified via layoutChanged, the code tries to restore old section sizes, and went out of bounds, leading to an assert in QVector. Simply add an if() to skip restoring out-of-bounds columns. This comes from https://bugs.kde.org/show_bug.cgi?id=395181, which translates into the unittest that is part of this commit. Change-Id: Ide42176a758f87b21957c40508127d67f1d5a2d9 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index eaf75e7494..1b3e1e1f34 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -248,6 +248,7 @@ private slots:
void sizeHintCrash();
void testResetCachedSizeHint();
void statusTips();
+ void testRemovingColumnsViaLayoutChanged();
protected:
void setupTestData(bool use_reset_model = false);
@@ -353,6 +354,7 @@ public:
void cleanup()
{
+ emit layoutAboutToBeChanged();
cols = 3;
rows = 3;
emit layoutChanged();
@@ -3489,5 +3491,20 @@ void tst_QHeaderView::statusTips()
QCOMPARE(headerView.statusTipText, QLatin1String("[0,1,0] -- Header"));
}
+void tst_QHeaderView::testRemovingColumnsViaLayoutChanged()
+{
+ const int persistentSectionSize = 101;
+
+ QtTestModel model;
+ model.rows = model.cols = 5;
+ view->setModel(&model);
+ for (int i = 0; i < model.cols; ++i)
+ view->resizeSection(i, persistentSectionSize + i);
+ model.cleanup(); // down to 3 via layoutChanged (not columnsRemoved)
+ for (int j = 0; j < model.cols; ++j)
+ QCOMPARE(view->sectionSize(j), persistentSectionSize + j);
+ // The main point of this test is that the section-size restoring code didn't go out of bounds.
+}
+
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"