aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-05-20 09:52:59 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-05-31 13:05:08 +0200
commita1297194ca0b679eedf03a133fa1785a68bcc662 (patch)
tree8af1d9f7c608eb9c1a9f6cb3011a3c63f0f7dcf3 /tests
parent065fb607863e6df5d079b27dd275790e64bd982c (diff)
QQuickTableView: ensure we use the correct margins during key navigation
Ensure we use the correct margins when navigating with the arrow keys at the beginning and end of the table. When e.g navigating to the first column in the model, we want to flick the view all the way to the start, margins included. It should already have worked like this, but must have broke after earlier copy/pase operations. Change-Id: I438b20518602e4cc5b49e137f633a7f550a9dec8 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 7b5b5e0f70..c219665959 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -227,6 +227,7 @@ private slots:
void setCurrentIndexOnFirstKeyPress_data();
void setCurrentIndexOnFirstKeyPress();
void setCurrentIndexFromMouse();
+ void showMarginsWhenNavigatingToEnd();
void disableKeyNavigation();
void disablePointerNavigation();
void selectUsingArrowKeys();
@@ -4699,6 +4700,56 @@ void tst_QQuickTableView::setCurrentIndexFromMouse()
QCOMPARE(tableView->currentRow(), cellAtEnd.y());
}
+void tst_QQuickTableView::showMarginsWhenNavigatingToEnd()
+{
+ LOAD_TABLEVIEW("plaintableview.qml");
+
+ TestModel model(40, 40);
+ QItemSelectionModel selectionModel(&model);
+
+ tableView->setModel(QVariant::fromValue(&model));
+ tableView->setSelectionModel(&selectionModel);
+ tableView->setAnimate(false);
+ tableView->setFocus(true);
+
+ QQuickWindow *window = tableView->window();
+
+ WAIT_UNTIL_POLISHED;
+
+ const qreal margin = 10;
+ tableView->setLeftMargin(margin);
+ tableView->setRightMargin(margin);
+ tableView->setTopMargin(margin);
+ tableView->setBottomMargin(margin);
+
+ selectionModel.setCurrentIndex(tableView->modelIndex(QPoint(1, 1)), QItemSelectionModel::NoUpdate);
+
+ // move to cell 0, 1
+ QCOMPARE(tableView->contentX(), 0);
+ QTest::keyPress(window, Qt::Key_Left);
+ QCOMPARE(tableView->contentX(), -margin);
+
+ // move to cell 0, 0
+ QCOMPARE(tableView->contentY(), 0);
+ QTest::keyPress(window, Qt::Key_Up);
+ QCOMPARE(tableView->contentY(), -margin);
+
+ selectionModel.setCurrentIndex(tableView->modelIndex(QPoint(38, 38)), QItemSelectionModel::NoUpdate);
+ tableView->positionViewAtCell(tableView->cellAtIndex(selectionModel.currentIndex()), QQuickTableView::Contain);
+
+ WAIT_UNTIL_POLISHED;
+
+ // move to cell 39, 38
+ QTest::keyPress(window, Qt::Key_Right);
+ const qreal cellRightEdge = tableViewPrivate->loadedTableOuterRect.right();
+ QCOMPARE(tableView->contentX(), cellRightEdge + margin - tableView->width());
+
+ // move to cell 39, 39
+ QTest::keyPress(window, Qt::Key_Down);
+ const qreal cellBottomEdge = tableViewPrivate->loadedTableOuterRect.bottom();
+ QCOMPARE(tableView->contentY(), cellBottomEdge + margin - tableView->height());
+}
+
void tst_QQuickTableView::disablePointerNavigation()
{
LOAD_TABLEVIEW("tableviewwithselected1.qml");