aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKari Hormi <kari.hormi@qt.io>2019-11-06 15:53:40 +0200
committerKari Hormi <kari.hormi@qt.io>2019-11-20 12:45:34 +0200
commitacb6ed0815f92588c3ff875a568e9561fe61218c (patch)
tree9e41e2ca844d2b8e2c20333410089c608b49c7fb /tests
parentaf090d8073a4352f6a92bbe2d015ae87476684c7 (diff)
TableView: use fetchMore() when scrolling to the end of the table
QQmlTableInstanceModel implements canFetchMore and fetchMore functions, but these are not called at any point in QQuickTableView. This change checks if additional data can be fetched when atYEndChanged signal is emitted. Fixes: QTBUG-78273 Change-Id: I49b41b09d9a218826b34f32cd9fe4724a6097b52 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktableview/qquicktableview.pro2
-rw-r--r--tests/auto/quick/qquicktableview/testmodel.h20
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp21
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/qquicktableview.pro b/tests/auto/quick/qquicktableview/qquicktableview.pro
index da0c0b01d0..735c728fc6 100644
--- a/tests/auto/quick/qquicktableview/qquicktableview.pro
+++ b/tests/auto/quick/qquicktableview/qquicktableview.pro
@@ -13,3 +13,5 @@ TESTDATA = data/*
QT += core-private gui-private qml-private quick-private testlib qmlmodels-private
+DISTFILES +=
+
diff --git a/tests/auto/quick/qquicktableview/testmodel.h b/tests/auto/quick/qquicktableview/testmodel.h
index 0243158bda..2697b1e801 100644
--- a/tests/auto/quick/qquicktableview/testmodel.h
+++ b/tests/auto/quick/qquicktableview/testmodel.h
@@ -46,6 +46,13 @@ public:
, m_columns(columns)
{}
+ TestModel(int rows, int columns, bool dataCanBeFetched, QObject *parent = nullptr)
+ : QAbstractTableModel(parent)
+ , m_rows(rows)
+ , m_columns(columns)
+ , m_dataCanBeFetched(dataCanBeFetched)
+ {}
+
int rowCount(const QModelIndex & = QModelIndex()) const override { return m_rows; }
void setRowCount(int count) { beginResetModel(); m_rows = count; emit rowCountChanged(); endResetModel(); }
@@ -141,6 +148,12 @@ public:
return true;
}
+ bool canFetchMore(const QModelIndex &parent) const override
+ {
+ Q_UNUSED(parent)
+ return m_dataCanBeFetched;
+ }
+
void swapRows(int row1, int row2)
{
layoutAboutToBeChanged();
@@ -152,6 +165,12 @@ public:
layoutChanged();
}
+ void fetchMore(const QModelIndex &parent) override
+ {
+ Q_UNUSED(parent)
+ addRow(m_rows - 1);
+ }
+
void clear() {
beginResetModel();
m_rows = 0;
@@ -172,6 +191,7 @@ signals:
private:
int m_rows = 0;
int m_columns = 0;
+ bool m_dataCanBeFetched = false;
QHash<int, QString> modelData;
};
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 0117267429..7037e516fd 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -175,6 +175,7 @@ private slots:
void checkSyncView_differentSizedModels();
void checkSyncView_connect_late_data();
void checkSyncView_connect_late();
+ void checkThatFetchMoreIsCalledWhenScrolledToTheEndOfTable();
};
tst_QQuickTableView::tst_QQuickTableView()
@@ -2676,7 +2677,27 @@ void tst_QQuickTableView::checkSyncView_connect_late()
QCOMPARE(tableViewVPrivate->loadedTableOuterRect.left(), 0);
QCOMPARE(tableViewHVPrivate->loadedTableOuterRect, tableViewPrivate->loadedTableOuterRect);
+}
+
+void tst_QQuickTableView::checkThatFetchMoreIsCalledWhenScrolledToTheEndOfTable()
+{
+ LOAD_TABLEVIEW("plaintableview.qml");
+
+ auto model = TestModelAsVariant(5, 5, true);
+ tableView->setModel(model);
+ WAIT_UNTIL_POLISHED;
+
+ QCOMPARE(tableView->rows(), 5);
+ QCOMPARE(tableView->columns(), 5);
+
+ // Flick table out of view on top
+ tableView->setContentX(0);
+ tableView->setContentY(-tableView->height() - 10);
+ tableView->polish();
+ WAIT_UNTIL_POLISHED;
+ QCOMPARE(tableView->rows(), 6);
+ QCOMPARE(tableView->columns(), 5);
}
QTEST_MAIN(tst_QQuickTableView)