aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-04-06 19:18:06 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-04-08 15:57:16 +0200
commitf296c300614cbe2c9de66fe05ea7201d79249062 (patch)
tree4fde16688d250e380ad0f046a815ac70233d37e2 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
parentbe12b71faeba23a8ef0cf9695e11aa847b68ae7e (diff)
QQuickTableView: add function: itemAtCell(const QPoint)
Add a function to the API to let the application get the item loaded for a specific cell. [ChangeLog][TableView] A function 'itemAtCell()' has now been added to let the application get the delegate item loaded for a specific cell. Change-Id: Ie84ef44ea2a0a901487812c4d611b98d4c86ee22 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index e0917cbea9..679ced17d7 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -182,6 +182,8 @@ private slots:
void positionViewAtRow();
void positionViewAtColumn_data();
void positionViewAtColumn();
+ void itemAtCell_data();
+ void itemAtCell();
};
tst_QQuickTableView::tst_QQuickTableView()
@@ -2954,6 +2956,42 @@ void tst_QQuickTableView::positionViewAtColumn()
}
}
+void tst_QQuickTableView::itemAtCell_data()
+{
+ QTest::addColumn<QPoint>("cell");
+ QTest::addColumn<bool>("shouldExist");
+
+ QTest::newRow("0, 0") << QPoint(0, 0) << true;
+ QTest::newRow("0, 4") << QPoint(0, 4) << true;
+ QTest::newRow("4, 0") << QPoint(4, 0) << true;
+ QTest::newRow("4, 4") << QPoint(4, 4) << true;
+ QTest::newRow("30, 30") << QPoint(30, 30) << false;
+ QTest::newRow("-1, -1") << QPoint(-1, -1) << false;
+}
+
+void tst_QQuickTableView::itemAtCell()
+{
+ QFETCH(QPoint, cell);
+ QFETCH(bool, shouldExist);
+
+ LOAD_TABLEVIEW("plaintableview.qml");
+ auto model = TestModelAsVariant(100, 100);
+ tableView->setModel(model);
+
+ WAIT_UNTIL_POLISHED;
+
+ const auto item = tableView->itemAtCell(cell);
+ if (shouldExist) {
+ const auto context = qmlContext(item);
+ const int contextRow = context->contextProperty("row").toInt();
+ const int contextColumn = context->contextProperty("column").toInt();
+ QCOMPARE(contextColumn, cell.x());
+ QCOMPARE(contextRow, cell.y());
+ } else {
+ QVERIFY(!item);
+ }
+}
+
QTEST_MAIN(tst_QQuickTableView)
#include "tst_qquicktableview.moc"