aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp')
-rw-r--r--tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp89
1 files changed, 86 insertions, 3 deletions
diff --git a/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp b/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp
index 28b92fef71..1d83b56f41 100644
--- a/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp
+++ b/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2022 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/qsignalspy.h>
#include <QtTest/qtest.h>
@@ -8,13 +8,18 @@
#include <QAbstractItemModelTester>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlComponent>
-#include <QtQuick/private/qquickwindow_p.h>
+#include <QtQuick/private/qquickmousearea_p.h>
#include <QtQuick/private/qquicktext_p.h>
+#include <QtQuick/private/qquickwindow_p.h>
#include <QtQuickTestUtils/private/qmlutils_p.h>
+#include <QtQuickTestUtils/private/visualtestutils_p.h>
#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
#include <QtQuickTemplates2/private/qquickheaderview_p.h>
+#include <QtQuickTemplates2/private/qquicklabel_p.h>
#include <private/qquickheaderview_p_p.h>
+using namespace QQuickVisualTestUtils;
+
class TestTableModel : public QAbstractTableModel {
Q_OBJECT
Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged)
@@ -130,6 +135,10 @@ class TestTableModelWithHeader : public TestTableModel {
Q_OBJECT
public:
+ enum Role {
+ CustomRole = Qt::UserRole
+ };
+
void setRowCount(int count) override
{
vData.resize(count);
@@ -141,6 +150,17 @@ public:
hData.resize(count);
TestTableModel::setColumnCount(count);
}
+
+ QVariant data(const QModelIndex &index, int role) const override
+ {
+ switch (role) {
+ case CustomRole:
+ return QString("%1-%2").arg(index.column()).arg(index.row());
+ default:
+ return TestTableModel::data(index, role);
+ }
+ }
+
Q_INVOKABLE QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override
{
@@ -153,6 +173,8 @@ public:
auto &data = orientation == Qt::Horizontal ? hData : vData;
return data[section].toString();
}
+ case CustomRole:
+ return (orientation == Qt::Horizontal ? "c" : "r") + QString::number(section);
default:
return QVariant();
}
@@ -174,6 +196,13 @@ public:
return true;
}
+ Q_INVOKABLE QHash<int, QByteArray> roleNames() const override
+ {
+ auto names = TestTableModel::roleNames();
+ names[CustomRole] = "customRole";
+ return names;
+ }
+
private:
QList<QVariant> hData, vData;
};
@@ -196,6 +225,12 @@ private slots:
void testModel();
void listModel();
+ void resizableHandlerBlockingEvents();
+
+ void headerData();
+
+ void warnMissingDefaultRole();
+
private:
QQmlEngine *engine;
QString errorString;
@@ -212,7 +247,7 @@ private:
};
tst_QQuickHeaderView::tst_QQuickHeaderView()
- : QQmlDataTest(QT_QMLTEST_DATADIR)
+ : QQmlDataTest(QT_QMLTEST_DATADIR, FailOnWarningsPolicy::FailOnWarnings)
{
}
@@ -296,10 +331,14 @@ void tst_QQuickHeaderView::testOrientation()
QVERIFY(vhv);
hhv->setSyncView(&otherView);
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression(
+ ".*Setting syncDirection other than Qt::Horizontal is invalid."));
hhv->setSyncDirection(Qt::Vertical);
QVERIFY(QQuickTest::qWaitForPolish(hhv));
vhv->setSyncView(&otherView);
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression(
+ ".*Setting syncDirection other than Qt::Vertical is invalid."));
vhv->setSyncDirection(Qt::Horizontal);
QVERIFY(QQuickTest::qWaitForPolish(vhv));
@@ -376,6 +415,50 @@ void tst_QQuickHeaderView::listModel()
QCOMPARE(vhvCell2->property("text"), "222");
}
+// A header shouldn't block events outside of itself.
+void tst_QQuickHeaderView::resizableHandlerBlockingEvents()
+{
+ QQuickApplicationHelper helper(this, QStringLiteral("resizableHandlerBlockingEvents.qml"));
+ QVERIFY2(helper.errorMessage.isEmpty(), helper.errorMessage);
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ auto mouseArea = window->findChild<QQuickMouseArea *>("mouseArea");
+ QVERIFY(mouseArea);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, mapCenterToWindow(mouseArea));
+ QVERIFY(mouseArea->isPressed());
+}
+
+void tst_QQuickHeaderView::headerData()
+{
+ QQuickApplicationHelper helper(this, QStringLiteral("headerData.qml"));
+ QVERIFY2(helper.errorMessage.isEmpty(), helper.errorMessage);
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ auto headerView = window->property("headerView").value<QQuickHeaderViewBase *>();
+ QVERIFY(headerView);
+ const auto firstHeaderCell = headerView->itemAtIndex(headerView->index(0, 0));
+ QVERIFY(firstHeaderCell);
+ const auto label = firstHeaderCell->findChild<QQuickLabel *>();
+ QVERIFY(label);
+ QCOMPARE(label->text(), "c0");
+}
+
+void tst_QQuickHeaderView::warnMissingDefaultRole()
+{
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*toolTip.*"));
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*Required property.*"));
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression("TableView.*"));
+ QQuickApplicationHelper helper(this, QStringLiteral("DefaultRoles.qml"));
+ QVERIFY2(helper.errorMessage.isEmpty(), helper.errorMessage);
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+}
+
QTEST_MAIN(tst_QQuickHeaderView)
#include "tst_qquickheaderview.moc"