summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-11-04 18:43:00 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-11-08 16:54:12 +0000
commit8713f22372b7aa63ecafbe87214b8994203fac5f (patch)
tree469f4ada05dd6d540fdba308dd4d669d8e32f388 /tests/auto
parent63967313f57add6517cdc50b8a77fa319a2b7df0 (diff)
QHeaderView: Fix updating hidden sections during initializeSections()
QHeaderView::initializeSections() was calling updateHiddenSections() with wrong parameters which lead to an inconsistency in the hidden section handling. updateHiddenSections() needs the first and last index which got removed. Therefore we must pass the new section count for logicalFirst. Fixes: QTBUG-55461 Change-Id: Ica06125cf19bdd500f55fd9cd59ace1795f3703f Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp55
1 files changed, 47 insertions, 8 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index b6932d4892..9d3770064f 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -253,11 +253,12 @@ protected:
void calculateAndCheck(int cppline, const int precalced_comparedata[]);
void testMinMaxSectionSize(bool stretchLastSection);
- QWidget *topLevel;
- QHeaderView *view;
- QStandardItemModel *model;
- QTableView *m_tableview;
- bool m_using_reset_model;
+ QWidget *topLevel = nullptr;
+ QHeaderView *view = nullptr;
+ QStandardItemModel *model = nullptr;
+ QTableView *m_tableview = nullptr;
+ bool m_using_reset_model = false;
+ bool m_special_prepare = false;
QElapsedTimer timer;
};
@@ -614,6 +615,27 @@ void tst_QHeaderView::hidden()
view->setSectionHidden(1, false);
QCOMPARE(view->isSectionHidden(0), false);
QCOMPARE(view->sectionSize(0), view->defaultSectionSize());
+
+ // d->hiddenSectionSize could go out of sync when a new model
+ // was set which has fewer sections than before and some of them
+ // were hidden
+ QStandardItemModel model2(model->rowCount() - 1, model->columnCount());
+
+ for (int i = 0; i < model->rowCount(); ++i)
+ view->setSectionHidden(i, true);
+ view->setModel(&model2);
+ QVERIFY(view->sectionsHidden());
+ for (int i = 0; i < model2.rowCount(); ++i) {
+ QVERIFY(view->isSectionHidden(i));
+ }
+
+ view->setModel(model);
+ for (int i = 0; i < model2.rowCount(); ++i) {
+ QVERIFY(view->isSectionHidden(i));
+ }
+ QCOMPARE(view->isSectionHidden(model->rowCount() - 1), false);
+ for (int i = 0; i < model->rowCount(); ++i)
+ view->setSectionHidden(i, false);
}
void tst_QHeaderView::stretch()
@@ -2822,6 +2844,7 @@ void tst_QHeaderView::additionalInit()
QFETCH(bool, reset_model);
m_using_reset_model = reset_model;
+ m_special_prepare = special_prepare;
if (m_using_reset_model) {
XResetModel *m = new XResetModel();
@@ -3035,18 +3058,34 @@ void tst_QHeaderView::mixedTests()
view->moveSection(0, 5);
for (int u = model->rowCount(); u >= 0; --u) {
- if (u % 5 != 0)
+ if (u % 5 != 0) {
view->hideSection(u);
- if (u % 3 != 0)
+ QVERIFY(view->isSectionHidden(u));
+ }
+ if (u % 3 != 0) {
view->showSection(u);
+ QVERIFY(!view->isSectionHidden(u));
+ }
}
model->insertRows(3, 7);
model->removeRows(8, 3);
model->setRowCount(model->rowCount() - 10);
+ // the upper is not visible (when m_using_reset_model is true)
+ // the lower 11 are modified due to insert/removeRows
+ for (int u = model->rowCount() - 1; u >= 11; --u) {
+ // when using reset, the hidden rows will *not* move
+ const int calcMod = m_using_reset_model ? u : u - 4; // 7 added, 3 removed
+ if (calcMod % 5 != 0 && calcMod % 3 == 0) {
+ QVERIFY(view->isSectionHidden(u));
+ }
+ if (calcMod % 3 != 0) {
+ QVERIFY(!view->isSectionHidden(u));
+ }
+ }
if (m_using_reset_model) {
- const int precalced_results[] = { 898296472, 337096378, -543340640, 1, -1251526424, -568618976, 9250 };
+ const int precalced_results[] = { 898296472, 337096378, -543340640, -1964432121, -1251526424, -568618976, 9250 };
calculateAndCheck(__LINE__, precalced_results);
} else {
const int precalced_results[] = { 1911338224, 1693514365, -613398968, -1912534953, 1582159424, -1851079000, 9300 };