summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-05-09 20:36:10 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-05-10 14:03:24 +0000
commitf02256cce12392a35d177511e39052985fc720ac (patch)
tree579fb539ed4f115a416d009eb08cc2cc0ea30841 /tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
parentd2573f4dbde930dc417f66ca7a6b6f242e809e7a (diff)
QHeaderView: reset cached size hint on reset()
QHeaderView::reset() did not reset the cached size hint which could lead to wrong geometries when the model was reset. Task-number: QTBUG-67927 Change-Id: I5100b28a741cc816133a229c422f9abf83f2187e 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.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index 8ed4da7a3b..e7a98955cd 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -243,6 +243,7 @@ private slots:
void testMinMaxSectionSizeStretched();
void testMinMaxSectionSizeNotStretched();
void sizeHintCrash();
+ void testResetCachedSizeHint();
protected:
void setupTestData(bool use_reset_model = false);
@@ -265,13 +266,21 @@ Q_OBJECT
public:
QtTestModel(QObject *parent = 0): QAbstractTableModel(parent),
- cols(0), rows(0), wrongIndex(false) {}
- int rowCount(const QModelIndex&) const { return rows; }
- int columnCount(const QModelIndex&) const { return cols; }
+ cols(0), rows(0), wrongIndex(false), m_bMultiLine(false) {}
+ int rowCount(const QModelIndex&) const override { return rows; }
+ int columnCount(const QModelIndex&) const override { return cols; }
bool isEditable(const QModelIndex &) const { return true; }
- QVariant data(const QModelIndex &idx, int) const
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
{
+ if (role == Qt::DisplayRole)
+ return m_bMultiLine ? QString("%1\n%1").arg(section) : QString::number(section);
+ return QAbstractTableModel::headerData(section, orientation, role);
+ }
+ QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override
+ {
+ if (role != Qt::DisplayRole)
+ return QVariant();
if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) {
wrongIndex = true;
qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), idx.internalPointer());
@@ -354,8 +363,16 @@ public:
emit layoutChanged();
}
+ void setMultiLineHeader(bool bEnable)
+ {
+ beginResetModel();
+ m_bMultiLine = bEnable;
+ endResetModel();
+ }
+
int cols, rows;
mutable bool wrongIndex;
+ bool m_bMultiLine;
};
// Testing get/set functions
@@ -3337,6 +3354,25 @@ void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection)
QCOMPARE(header.sectionSize(0), defaultSectionSize);
}
+void tst_QHeaderView::testResetCachedSizeHint()
+{
+ QtTestModel model;
+ model.rows = model.cols = 10;
+
+ QTableView tv;
+ tv.setModel(&model);
+ tv.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&tv));
+
+ QSize s1 = tv.horizontalHeader()->sizeHint();
+ model.setMultiLineHeader(true);
+ QSize s2 = tv.horizontalHeader()->sizeHint();
+ model.setMultiLineHeader(false);
+ QSize s3 = tv.horizontalHeader()->sizeHint();
+ QCOMPARE(s1, s3);
+ QVERIFY(s1 != s2);
+}
+
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"