summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2017-10-31 16:05:58 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-01-06 05:17:00 +0000
commit20604ea554b282efa80502c68a499824f8692e7a (patch)
treeed1c27e6e482913d65c687c2a77ba68aa72c4df6 /tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
parent1c0ac8c4b8646e898aa1636f93dcfd34949611cf (diff)
QHeaderView: respect min/maximumSectionSize property
QHeaderView::resizeSection() did not check if the given section size is inside the min/max property bounds. Also on calling setMin/MaximumSectionSize() the current section sizes were not checked if they are inside the new given bounds. This is a small behavior change when a user is setting the section size via resizeSection() without respecting the min/maxSectionSizes. Task-number: QTBUG-64173 Change-Id: Ia9c9eebf058d60c776ab5f8f8336642013ec553f 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.cpp78
1 files changed, 77 insertions, 1 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 8d90f9e59f..a5d131a436 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -239,13 +239,15 @@ private slots:
void testStreamWithHide();
void testStylePosition();
void stretchAndRestoreLastSection();
-
+ void testMinMaxSectionSizeStretched();
+ void testMinMaxSectionSizeNotStretched();
void sizeHintCrash();
protected:
void setupTestData(bool use_reset_model = false);
void additionalInit();
void calculateAndCheck(int cppline, const int precalced_comparedata[]);
+ void testMinMaxSectionSize(bool stretchLastSection);
QWidget *topLevel;
QHeaderView *view;
@@ -402,6 +404,7 @@ void tst_QHeaderView::init()
QCOMPARE(view->length(), 0);
QCOMPARE(view->sizeHint(), QSize(0,0));
QCOMPARE(view->sectionSizeHint(0), -1);
+ view->setMinimumSectionSize(0); // system default min size can be to large
/*
model = new QStandardItemModel(1, 1);
@@ -1604,6 +1607,7 @@ static QByteArray savedState()
QStandardItemModel m(4, 4);
QHeaderView h1(Qt::Horizontal);
h1.setModel(&m);
+ h1.setMinimumSectionSize(0); // system default min size can be to large
h1.swapSections(0, 2);
h1.resizeSection(1, 10);
h1.setSortIndicatorShown(true);
@@ -2194,6 +2198,7 @@ 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.setMinimumSectionSize(0); // system default min size can be to large
header.setStretchLastSection(false);
header.setDefaultSectionSize(17);
header.setModel(&model);
@@ -3182,5 +3187,76 @@ void tst_QHeaderView::stretchAndRestoreLastSection()
QCOMPARE(header.sectionSize(9), someOtherSectionSize);
}
+void tst_QHeaderView::testMinMaxSectionSizeStretched()
+{
+ testMinMaxSectionSize(true);
+}
+
+void tst_QHeaderView::testMinMaxSectionSizeNotStretched()
+{
+ testMinMaxSectionSize(false);
+}
+
+static void waitFor(const std::function<bool()> &func)
+{
+ for (int i = 0; i < 100; i++)
+ {
+ if (func())
+ return;
+ QTest::qWait(10);
+ }
+}
+
+void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection)
+{
+ QStandardItemModel m(5, 5);
+ QTableView tv;
+ tv.setModel(&m);
+ tv.show();
+
+ const int sectionSizeMin = 20;
+ const int sectionSizeMax = 40;
+ const int defaultSectionSize = 30;
+
+ QVERIFY(QTest::qWaitForWindowExposed(&tv));
+
+ QHeaderView &header = *tv.horizontalHeader();
+ header.setMinimumSectionSize(sectionSizeMin);
+ header.setMaximumSectionSize(sectionSizeMax);
+ header.setDefaultSectionSize(defaultSectionSize);
+ header.setStretchLastSection(stretchLastSection);
+
+ // check defaults
+ QCOMPARE(header.sectionSize(0), defaultSectionSize);
+ QCOMPARE(header.sectionSize(3), defaultSectionSize);
+
+ // do not go above maxSectionSize
+ header.resizeSection(0, sectionSizeMax + 1);
+ QCOMPARE(header.sectionSize(0), sectionSizeMax);
+
+ // do not go below minSectionSize
+ header.resizeSection(0, sectionSizeMin - 1);
+ QCOMPARE(header.sectionSize(0), sectionSizeMin);
+
+ // change section size on max change
+ header.setMinimumSectionSize(sectionSizeMin);
+ header.setMaximumSectionSize(sectionSizeMax);
+ header.resizeSection(0, sectionSizeMax);
+ QCOMPARE(header.sectionSize(0), sectionSizeMax);
+ header.setMaximumSectionSize(defaultSectionSize);
+ waitFor([this, &header, defaultSectionSize]() { return header.sectionSize(0) == defaultSectionSize; });
+ QCOMPARE(header.sectionSize(0), defaultSectionSize);
+
+ // change section size on min change
+ header.setMinimumSectionSize(sectionSizeMin);
+ header.setMaximumSectionSize(sectionSizeMax);
+ header.resizeSection(0, sectionSizeMin);
+ QCOMPARE(header.sectionSize(0), sectionSizeMin);
+ header.setMinimumSectionSize(defaultSectionSize);
+ waitFor([this, &header, defaultSectionSize]() { return header.sectionSize(0) == defaultSectionSize; });
+ QCOMPARE(header.sectionSize(0), defaultSectionSize);
+}
+
+
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"