aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-02-09 20:06:39 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-16 21:02:18 +0000
commitb50c76b669a2e325f8f811bae6d6c649cbc92c5e (patch)
treefcf70638cbf5ab7b9a8e2c5f1141ec232c49f123 /tests
parente3196a7cfaff9ee69e71251bde4c40c54334526b (diff)
QQuickTableView: don't position the table contents outside the viewport
If you call positionViewAtCell(row, Qt.AlignTop) for the last row in the table, the row will be aligned to the top of the view, as requested. But this looks really wrong , since it will cause the table to be flicked to a position that causes it to overshoot by a distance close to the height of the whole view, effectively leaving a big empty gap at the bottom. This looks really buggy. This patch will correct this behavior by ensuring that we never flick the table to an "invalid" position while positioning table at a cell using the requested alignment. Instead we clamp the table to the edges of the viewport. Fixes: QTBUG-100680 Change-Id: Id3003df784a0128df28ee2e78e2456e1fa1e11e8 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit c3d909ec286962c507e346a8d490b905cdd266f8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp203
1 files changed, 148 insertions, 55 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 8c9680f305..2f0e6890e0 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -192,6 +192,10 @@ private slots:
void positionViewAtRow();
void positionViewAtColumn_data();
void positionViewAtColumn();
+ void positionViewAtRowClamped_data();
+ void positionViewAtRowClamped();
+ void positionViewAtColumnClamped_data();
+ void positionViewAtColumnClamped();
void itemAtCell_data();
void itemAtCell();
void leftRightTopBottomProperties_data();
@@ -3138,48 +3142,30 @@ void tst_QQuickTableView::positionViewAtRow_data()
QTest::newRow("AlignTop 1") << 1 << Qt::AlignTop << 0. << 50.;
QTest::newRow("AlignTop 50") << 50 << Qt::AlignTop << 0. << -1.;
QTest::newRow("AlignTop 0") << 0 << Qt::AlignTop << 0. << -1.;
- QTest::newRow("AlignTop 99") << 99 << Qt::AlignTop << 0. << -1.;
-
- QTest::newRow("AlignTop 0") << 0 << Qt::AlignTop << -10. << 0.;
QTest::newRow("AlignTop 1") << 1 << Qt::AlignTop << -10. << 0.;
QTest::newRow("AlignTop 1") << 1 << Qt::AlignTop << -10. << 50.;
QTest::newRow("AlignTop 50") << 50 << Qt::AlignTop << -10. << -1.;
- QTest::newRow("AlignTop 0") << 0 << Qt::AlignTop << -10. << -1.;
- QTest::newRow("AlignTop 99") << 99 << Qt::AlignTop << -10. << -1.;
- QTest::newRow("AlignBottom 0") << 0 << Qt::AlignBottom << 0. << 0.;
- QTest::newRow("AlignBottom 1") << 1 << Qt::AlignBottom << 0. << 0.;
- QTest::newRow("AlignBottom 1") << 1 << Qt::AlignBottom << 0. << 50.;
QTest::newRow("AlignBottom 50") << 50 << Qt::AlignBottom << 0. << -1.;
- QTest::newRow("AlignBottom 0") << 0 << Qt::AlignBottom << 0. << -1.;
+ QTest::newRow("AlignBottom 98") << 98 << Qt::AlignBottom << 0. << -1.;
QTest::newRow("AlignBottom 99") << 99 << Qt::AlignBottom << 0. << -1.;
+ QTest::newRow("AlignBottom 50") << 40 << Qt::AlignBottom << 10. << -1.;
+ QTest::newRow("AlignBottom 40") << 50 << Qt::AlignBottom << -10. << -1.;
+ QTest::newRow("AlignBottom 98") << 98 << Qt::AlignBottom << 10. << -1.;
+ QTest::newRow("AlignBottom 99") << 99 << Qt::AlignBottom << -10. << -1.;
- QTest::newRow("AlignBottom 0") << 0 << Qt::AlignBottom << 10. << 0.;
- QTest::newRow("AlignBottom 1") << 1 << Qt::AlignBottom << 10. << 0.;
- QTest::newRow("AlignBottom 1") << 1 << Qt::AlignBottom << 10. << 50.;
- QTest::newRow("AlignBottom 50") << 50 << Qt::AlignBottom << 10. << -1.;
- QTest::newRow("AlignBottom 0") << 0 << Qt::AlignBottom << 10. << -1.;
- QTest::newRow("AlignBottom 99") << 99 << Qt::AlignBottom << 10. << -1.;
-
- QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << 0. << 0.;
- QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << 0. << 0.;
- QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << 0. << 50.;
+ QTest::newRow("AlignCenter 40") << 40 << Qt::AlignCenter << 0. << -1.;
QTest::newRow("AlignCenter 50") << 50 << Qt::AlignCenter << 0. << -1.;
- QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << 0. << -1.;
- QTest::newRow("AlignCenter 99") << 99 << Qt::AlignCenter << 0. << -1.;
-
- QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << -10. << 0.;
- QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << -10. << 0.;
- QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << -10. << 50.;
+ QTest::newRow("AlignCenter 40") << 40 << Qt::AlignCenter << 10. << -1.;
QTest::newRow("AlignCenter 50") << 50 << Qt::AlignCenter << -10. << -1.;
- QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << -10. << -1.;
- QTest::newRow("AlignCenter 99") << 99 << Qt::AlignCenter << -10. << -1.;
}
void tst_QQuickTableView::positionViewAtRow()
{
// Check that positionViewAtRow actually flicks the view
- // to the right position so that the row becomes visible
+ // to the right position so that the row becomes visible.
+ // For this test, we only check cells that can be placed exactly
+ // according to the given alignment.
QFETCH(int, row);
QFETCH(Qt::AlignmentFlag, alignment);
QFETCH(qreal, offset);
@@ -3229,48 +3215,27 @@ void tst_QQuickTableView::positionViewAtColumn_data()
QTest::newRow("AlignLeft 1") << 1 << Qt::AlignLeft << 0. << 50.;
QTest::newRow("AlignLeft 50") << 50 << Qt::AlignLeft << 0. << -1.;
QTest::newRow("AlignLeft 0") << 0 << Qt::AlignLeft << 0. << -1.;
- QTest::newRow("AlignLeft 99") << 99 << Qt::AlignLeft << 0. << -1.;
-
- QTest::newRow("AlignLeft 0") << 0 << Qt::AlignLeft << -10. << 0.;
QTest::newRow("AlignLeft 1") << 1 << Qt::AlignLeft << -10. << 0.;
QTest::newRow("AlignLeft 1") << 1 << Qt::AlignLeft << -10. << 50.;
QTest::newRow("AlignLeft 50") << 50 << Qt::AlignLeft << -10. << -1.;
- QTest::newRow("AlignLeft 0") << 0 << Qt::AlignLeft << -10. << -1.;
- QTest::newRow("AlignLeft 99") << 99 << Qt::AlignLeft << -10. << -1.;
- QTest::newRow("AlignRight 0") << 0 << Qt::AlignRight << 0. << 0.;
- QTest::newRow("AlignRight 1") << 1 << Qt::AlignRight << 0. << 0.;
- QTest::newRow("AlignRight 1") << 1 << Qt::AlignRight << 0. << 50.;
QTest::newRow("AlignRight 50") << 50 << Qt::AlignRight << 0. << -1.;
- QTest::newRow("AlignRight 0") << 0 << Qt::AlignRight << 0. << -1.;
QTest::newRow("AlignRight 99") << 99 << Qt::AlignRight << 0. << -1.;
-
- QTest::newRow("AlignRight 0") << 0 << Qt::AlignRight << 10. << 0.;
- QTest::newRow("AlignRight 1") << 1 << Qt::AlignRight << 10. << 0.;
- QTest::newRow("AlignRight 1") << 1 << Qt::AlignRight << 10. << 50.;
QTest::newRow("AlignRight 50") << 50 << Qt::AlignRight << 10. << -1.;
- QTest::newRow("AlignRight 0") << 0 << Qt::AlignRight << 10. << -1.;
- QTest::newRow("AlignRight 99") << 99 << Qt::AlignRight << 10. << -1.;
+ QTest::newRow("AlignRight 99") << 99 << Qt::AlignRight << -10. << -1.;
- QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << 0. << 0.;
- QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << 0. << 0.;
- QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << 0. << 50.;
+ QTest::newRow("AlignCenter 40") << 50 << Qt::AlignCenter << 0. << -1.;
QTest::newRow("AlignCenter 50") << 50 << Qt::AlignCenter << 0. << -1.;
- QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << 0. << -1.;
- QTest::newRow("AlignCenter 99") << 99 << Qt::AlignCenter << 0. << -1.;
-
- QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << -10. << 0.;
- QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << -10. << 0.;
- QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << -10. << 50.;
+ QTest::newRow("AlignCenter 40") << 50 << Qt::AlignCenter << 10. << -1.;
QTest::newRow("AlignCenter 50") << 50 << Qt::AlignCenter << -10. << -1.;
- QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << -10. << -1.;
- QTest::newRow("AlignCenter 99") << 99 << Qt::AlignCenter << -10. << -1.;
}
void tst_QQuickTableView::positionViewAtColumn()
{
// Check that positionViewAtColumn actually flicks the view
- // to the right position so that the row becomes visible
+ // to the right position so that the row becomes visible.
+ // For this test, we only check cells that can be placed exactly
+ // according to the given alignment.
QFETCH(int, column);
QFETCH(Qt::AlignmentFlag, alignment);
QFETCH(qreal, offset);
@@ -3308,6 +3273,134 @@ void tst_QQuickTableView::positionViewAtColumn()
}
}
+void tst_QQuickTableView::positionViewAtRowClamped_data()
+{
+ QTest::addColumn<int>("row");
+ QTest::addColumn<Qt::AlignmentFlag>("alignment");
+ QTest::addColumn<qreal>("offset");
+ QTest::addColumn<qreal>("contentYStartPos");
+
+ QTest::newRow("AlignTop 0") << 0 << Qt::AlignTop << -10. << 0.;
+ QTest::newRow("AlignTop 0") << 0 << Qt::AlignTop << -10. << -1.;
+ QTest::newRow("AlignTop 99") << 99 << Qt::AlignTop << 0. << -1.;
+ QTest::newRow("AlignTop 99") << 99 << Qt::AlignTop << -10. << -1.;
+
+ QTest::newRow("AlignBottom 0") << 0 << Qt::AlignBottom << 0. << 0.;
+ QTest::newRow("AlignBottom 1") << 1 << Qt::AlignBottom << 0. << 0.;
+ QTest::newRow("AlignBottom 1") << 1 << Qt::AlignBottom << 0. << 50.;
+ QTest::newRow("AlignBottom 0") << 0 << Qt::AlignBottom << 0. << -1.;
+
+ QTest::newRow("AlignBottom 0") << 0 << Qt::AlignBottom << 10. << 0.;
+ QTest::newRow("AlignBottom 1") << 1 << Qt::AlignBottom << 10. << 0.;
+ QTest::newRow("AlignBottom 1") << 1 << Qt::AlignBottom << 10. << 50.;
+ QTest::newRow("AlignBottom 0") << 0 << Qt::AlignBottom << 10. << -1.;
+ QTest::newRow("AlignBottom 99") << 99 << Qt::AlignBottom << 10. << -1.;
+
+ QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << 0. << 0.;
+ QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << 0. << 0.;
+ QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << 0. << 50.;
+ QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << 0. << -1.;
+ QTest::newRow("AlignCenter 99") << 99 << Qt::AlignCenter << 0. << -1.;
+
+ QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << -10. << 0.;
+ QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << -10. << 0.;
+ QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << -10. << 50.;
+ QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << -10. << -1.;
+ QTest::newRow("AlignCenter 99") << 99 << Qt::AlignCenter << -10. << -1.;
+}
+
+void tst_QQuickTableView::positionViewAtRowClamped()
+{
+ // Check that positionViewAtRow actually flicks the table to the
+ // right position so that the row becomes visible. For this test, we
+ // only test cells that cannot be placed exactly at the given alignment,
+ // because it would cause the table to overshoot. Instead the
+ // table should be flicked to the edge of the viewport, close to the
+ // requested alignment.
+ QFETCH(int, row);
+ QFETCH(Qt::AlignmentFlag, alignment);
+ QFETCH(qreal, offset);
+ QFETCH(qreal, contentYStartPos);
+
+ LOAD_TABLEVIEW("plaintableview.qml");
+ auto model = TestModelAsVariant(100, 100);
+ tableView->setModel(model);
+ if (contentYStartPos >= 0)
+ tableView->setContentY(contentYStartPos);
+
+ WAIT_UNTIL_POLISHED;
+
+ tableView->positionViewAtRow(row, alignment, offset);
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableView->contentY(), row < 50 ? 0 : tableView->contentHeight() - tableView->height());
+}
+
+void tst_QQuickTableView::positionViewAtColumnClamped_data()
+{
+ QTest::addColumn<int>("column");
+ QTest::addColumn<Qt::AlignmentFlag>("alignment");
+ QTest::addColumn<qreal>("offset");
+ QTest::addColumn<qreal>("contentXStartPos");
+
+ QTest::newRow("AlignLeft 0") << 0 << Qt::AlignLeft << -10. << 0.;
+ QTest::newRow("AlignLeft 0") << 0 << Qt::AlignLeft << -10. << -1.;
+ QTest::newRow("AlignLeft 99") << 99 << Qt::AlignLeft << 0. << -1.;
+ QTest::newRow("AlignLeft 99") << 99 << Qt::AlignLeft << -10. << -1.;
+
+ QTest::newRow("AlignRight 0") << 0 << Qt::AlignRight << 0. << 0.;
+ QTest::newRow("AlignRight 1") << 1 << Qt::AlignRight << 0. << 0.;
+ QTest::newRow("AlignRight 1") << 1 << Qt::AlignRight << 0. << 50.;
+ QTest::newRow("AlignRight 0") << 0 << Qt::AlignRight << 0. << -1.;
+
+ QTest::newRow("AlignRight 0") << 0 << Qt::AlignRight << 10. << 0.;
+ QTest::newRow("AlignRight 1") << 1 << Qt::AlignRight << 10. << 0.;
+ QTest::newRow("AlignRight 1") << 1 << Qt::AlignRight << 10. << 50.;
+ QTest::newRow("AlignRight 0") << 0 << Qt::AlignRight << 10. << -1.;
+ QTest::newRow("AlignRight 99") << 99 << Qt::AlignRight << 10. << -1.;
+
+ QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << 0. << 0.;
+ QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << 0. << 0.;
+ QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << 0. << 50.;
+ QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << 0. << -1.;
+ QTest::newRow("AlignCenter 99") << 99 << Qt::AlignCenter << 0. << -1.;
+
+ QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << -10. << 0.;
+ QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << -10. << 0.;
+ QTest::newRow("AlignCenter 1") << 1 << Qt::AlignCenter << -10. << 50.;
+ QTest::newRow("AlignCenter 0") << 0 << Qt::AlignCenter << -10. << -1.;
+ QTest::newRow("AlignCenter 99") << 99 << Qt::AlignCenter << -10. << -1.;
+}
+
+void tst_QQuickTableView::positionViewAtColumnClamped()
+{
+ // Check that positionViewAtColumn actually flicks the table to the
+ // right position so that the column becomes visible. For this test, we
+ // only test cells that cannot be placed exactly at the given alignment,
+ // because it would cause the table to overshoot. Instead the
+ // table should be flicked to the edge of the viewport, close to the
+ // requested alignment.
+ QFETCH(int, column);
+ QFETCH(Qt::AlignmentFlag, alignment);
+ QFETCH(qreal, offset);
+ QFETCH(qreal, contentXStartPos);
+
+ LOAD_TABLEVIEW("plaintableview.qml");
+ auto model = TestModelAsVariant(100, 100);
+ tableView->setModel(model);
+ if (contentXStartPos >= 0)
+ tableView->setContentX(contentXStartPos);
+
+ WAIT_UNTIL_POLISHED;
+
+ tableView->positionViewAtColumn(column, alignment, offset);
+
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableView->contentX(), column < 50 ? 0 : tableView->contentWidth() - tableView->width());
+}
+
void tst_QQuickTableView::itemAtCell_data()
{
QTest::addColumn<QPoint>("cell");