diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-05-08 13:48:24 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-05-14 10:28:02 +0000 |
commit | 1b46ba1e35af5e5d71f71d671906cefcb3b48a19 (patch) | |
tree | cb4c33162e69227684808983e0c45038427807c8 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | b7b49e32080572f8f669651adba88c66a00a2218 (diff) |
TableView: ensure to take spacing into account then loading edges
As it stood, we forgot to take spacing into account when determining
if an edge should be loaded. This meant that we sometimes would
load more edges than necessary when spacing was set to a large value.
Change-Id: I9a2ab96a838d00116aa282b6a40d58a19849936f
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index ad48283e1d..e18ed88348 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -76,6 +76,7 @@ public: QQuickTableViewAttached *getAttachedObject(const QObject *object) const; FxTableItem *findFxTableItem(int row, int column, const QList<FxTableItem *> items) const; + FxTableItem *findLoadedBottomRightItem(const QList<FxTableItem *> items) const; private slots: void initTestCase() override; @@ -90,6 +91,8 @@ private slots: void checkLayoutOfEqualSizedDelegateItems(); void checkTableMargins_data(); void checkTableMargins(); + void fillTableViewButNothingMore_data(); + void fillTableViewButNothingMore(); }; tst_QQuickTableView::tst_QQuickTableView() @@ -119,6 +122,21 @@ FxTableItem *tst_QQuickTableView::findFxTableItem(int row, int column, const QLi return nullptr; } +FxTableItem *tst_QQuickTableView::findLoadedBottomRightItem(const QList<FxTableItem *> items) const +{ + FxTableItem *bottomRightItem = nullptr; + int bottomRightIndex = 0; + + for (int i = items.count() - 1; i > 0; --i) { + FxTableItem *fxitem = items[i]; + if (fxitem->index > bottomRightIndex) { + bottomRightItem = fxitem; + bottomRightIndex = fxitem->index; + } + } + return bottomRightItem; +} + void tst_QQuickTableView::setAndGetModel_data() { QTest::addColumn<QVariant>("model"); @@ -315,6 +333,80 @@ void tst_QQuickTableView::checkTableMargins() QCOMPARE(bottomSpace, margins.bottom()); } +void tst_QQuickTableView::fillTableViewButNothingMore_data() +{ + QTest::addColumn<QSizeF>("spacing"); + QTest::addColumn<QMarginsF>("margins"); + + QTest::newRow("0 0,0 0") << QSizeF(0, 0) << QMarginsF(0, 0, 0, 0); + QTest::newRow("0 10,10 0") << QSizeF(10, 10) << QMarginsF(0, 0, 0, 0); + QTest::newRow("100 10,10 0") << QSizeF(10, 10) << QMarginsF(0, 0, 0, 0); + QTest::newRow("0 0,0 100") << QSizeF(0, 0) << QMarginsF(0, 0, 0, 0); + QTest::newRow("0 10,10 100") << QSizeF(10, 10) << QMarginsF(100, 100, 100, 100); + QTest::newRow("100 10,10 100") << QSizeF(10, 10) << QMarginsF(100, 100, 100, 100); +} + +void tst_QQuickTableView::fillTableViewButNothingMore() +{ + // Check that we end up filling the whole visible part of + // the tableview with cells, but nothing more. + QFETCH(QSizeF, spacing); + QFETCH(QMarginsF, margins); + LOAD_TABLEVIEW("plaintableview.qml"); + + const int rows = 100; + const int columns = 100; + auto model = TestModelAsVariant(rows, columns); + + tableView->setModel(model); + tableView->setRowSpacing(spacing.height()); + tableView->setColumnSpacing(spacing.width()); + tableView->setLeftMargin(margins.left()); + tableView->setTopMargin(margins.top()); + tableView->setRightMargin(margins.right()); + tableView->setBottomMargin(margins.bottom()); + tableView->setCacheBuffer(0); + + WAIT_UNTIL_POLISHED; + + auto const items = tableViewPrivate->loadedItems; + + auto const topLeftFxItem = findFxTableItem(0, 0, items); + QVERIFY(topLeftFxItem); + auto const topLeftItem = topLeftFxItem->item; + + // Check that the top-left item are at the corner of the view + QCOMPARE(topLeftItem->x(), margins.left()); + QCOMPARE(topLeftItem->y(), margins.top()); + + auto const bottomRightFxItem = findLoadedBottomRightItem(items); + QVERIFY(bottomRightFxItem); + auto const bottomRightItem = bottomRightFxItem->item; + auto bottomRightAttached = getAttachedObject(bottomRightItem); + + // Check that the right-most item is overlapping the right edge of the view + QVERIFY(bottomRightItem->x() < tableView->width()); + QVERIFY(bottomRightItem->x() + bottomRightItem->width() >= tableView->width() - spacing.width()); + + // Check that the actual number of columns matches what we expect + qreal cellWidth = bottomRightItem->width() + spacing.width(); + qreal availableWidth = tableView->width() - margins.left(); + int expectedColumns = qCeil(availableWidth / cellWidth); + int actualColumns = bottomRightAttached->column() + 1; + QCOMPARE(actualColumns, expectedColumns); + + // Check that the bottom-most item is overlapping the bottom edge of the view + QVERIFY(bottomRightItem->y() < tableView->height()); + QVERIFY(bottomRightItem->y() + bottomRightItem->height() >= tableView->height() - spacing.height()); + + // Check that the actual number of rows matches what we expect + qreal cellHeight = bottomRightItem->height() + spacing.height(); + qreal availableHeight = tableView->height() - margins.top(); + int expectedRows = qCeil(availableHeight / cellHeight); + int actualRows = bottomRightAttached->row() + 1; + QCOMPARE(actualRows, expectedRows); +} + QTEST_MAIN(tst_QQuickTableView) #include "tst_qquicktableview.moc" |