aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp96
1 files changed, 86 insertions, 10 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 6453180999..0375b74386 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -188,6 +188,8 @@ private slots:
void itemAtCell();
void leftRightTopBottomProperties_data();
void leftRightTopBottomProperties();
+ void checkContentSize_data();
+ void checkContentSize();
};
tst_QQuickTableView::tst_QQuickTableView()
@@ -600,6 +602,12 @@ void tst_QQuickTableView::checkForceLayoutEndUpDoingALayout()
for (auto fxItem : tableViewPrivate->loadedItems)
QCOMPARE(fxItem->item->height(), newDelegateSize);
+
+ // Check that the content height has been updated as well
+ const qreal rowSpacing = tableView->rowSpacing();
+ const qreal colSpacing = tableView->columnSpacing();
+ QCOMPARE(tableView->contentWidth(), (10 * (newDelegateSize + colSpacing)) - colSpacing);
+ QCOMPARE(tableView->contentHeight(), (9 * (newDelegateSize + rowSpacing)) - rowSpacing);
}
void tst_QQuickTableView::checkForceLayoutDuringModelChange()
@@ -1305,10 +1313,10 @@ void tst_QQuickTableView::checkSpacingValues()
tableView->polish();
WAIT_UNTIL_POLISHED;
- const qreal expectedInitialContentWidth = columnCount * (delegateWidth + tableView->columnSpacing()) - tableView->columnSpacing();
- const qreal expectedInitialContentHeight = rowCount * (delegateHeight + tableView->rowSpacing()) - tableView->rowSpacing();
- QCOMPARE(tableView->contentWidth(), expectedInitialContentWidth);
- QCOMPARE(tableView->contentHeight(), expectedInitialContentHeight);
+ qreal expectedContentWidth = columnCount * (delegateWidth + tableView->columnSpacing()) - tableView->columnSpacing();
+ qreal expectedContentHeight = rowCount * (delegateHeight + tableView->rowSpacing()) - tableView->rowSpacing();
+ QCOMPARE(tableView->contentWidth(), expectedContentWidth);
+ QCOMPARE(tableView->contentHeight(), expectedContentHeight);
// Valid spacing assignment
tableView->setRowSpacing(42);
@@ -1319,12 +1327,10 @@ void tst_QQuickTableView::checkSpacingValues()
tableView->polish();
WAIT_UNTIL_POLISHED;
- // Even after changing spacing, TableView will keep the initial guesstimated content size. The
- // reason is that deciding the content size based on the currently visible row/columns/spacing
- // will almost always be at a little bit wrong at best. So instead of pretending that TableView
- // knows what the size of the full table is, it sticks with the first guesstimate.
- QCOMPARE(tableView->contentWidth(), expectedInitialContentWidth);
- QCOMPARE(tableView->contentHeight(), expectedInitialContentHeight);
+ expectedContentWidth = columnCount * (delegateWidth + tableView->columnSpacing()) - tableView->columnSpacing();
+ expectedContentHeight = rowCount * (delegateHeight + tableView->rowSpacing()) - tableView->rowSpacing();
+ QCOMPARE(tableView->contentWidth(), expectedContentWidth);
+ QCOMPARE(tableView->contentHeight(), expectedContentHeight);
// Negative spacing is allowed, and can be used to eliminate double edges
// in the grid if the delegate is a rectangle with a border.
@@ -3113,6 +3119,76 @@ void tst_QQuickTableView::leftRightTopBottomProperties()
QCOMPARE(bottomSpy.count(), expectedSignalCount.bottom());
}
+void tst_QQuickTableView::checkContentSize_data()
+{
+ QTest::addColumn<int>("rowCount");
+ QTest::addColumn<int>("colCount");
+
+ QTest::newRow("4x4") << 4 << 4;
+ QTest::newRow("100x100") << 100 << 100;
+ QTest::newRow("0x0") << 0 << 0;
+}
+
+void tst_QQuickTableView::checkContentSize()
+{
+ QFETCH(int, rowCount);
+ QFETCH(int, colCount);
+
+ // Check that the content size is initially correct, and that
+ // it updates when we change e.g the model or spacing (QTBUG-87680)
+ LOAD_TABLEVIEW("plaintableview.qml");
+
+ TestModel model(rowCount, colCount);
+ tableView->setModel(QVariant::fromValue(&model));
+ tableView->setRowSpacing(1);
+ tableView->setColumnSpacing(2);
+
+ WAIT_UNTIL_POLISHED;
+
+ const qreal delegateWidth = 100;
+ const qreal delegateHeight = 50;
+ qreal colSpacing = tableView->columnSpacing();
+ qreal rowSpacing = tableView->rowSpacing();
+
+ // Check that content size has the exepected initial values
+ QCOMPARE(tableView->contentWidth(), colCount == 0 ? 0 : (colCount * (delegateWidth + colSpacing)) - colSpacing);
+ QCOMPARE(tableView->contentHeight(), rowCount == 0 ? 0 : (rowCount * (delegateHeight + rowSpacing)) - rowSpacing);
+
+ // Set no spacing
+ rowSpacing = 0;
+ colSpacing = 0;
+ tableView->setRowSpacing(rowSpacing);
+ tableView->setColumnSpacing(colSpacing);
+ WAIT_UNTIL_POLISHED;
+ QCOMPARE(tableView->contentWidth(), colCount * delegateWidth);
+ QCOMPARE(tableView->contentHeight(), rowCount * delegateHeight);
+
+ // Set typical spacing values
+ rowSpacing = 2;
+ colSpacing = 3;
+ tableView->setRowSpacing(rowSpacing);
+ tableView->setColumnSpacing(colSpacing);
+ WAIT_UNTIL_POLISHED;
+ QCOMPARE(tableView->contentWidth(), colCount == 0 ? 0 : (colCount * (delegateWidth + colSpacing)) - colSpacing);
+ QCOMPARE(tableView->contentHeight(), rowCount == 0 ? 0 : (rowCount * (delegateHeight + rowSpacing)) - rowSpacing);
+
+ // Add a row and a column
+ model.insertRow(0);
+ model.insertColumn(0);
+ rowCount = model.rowCount();
+ colCount = model.columnCount();
+ WAIT_UNTIL_POLISHED;
+ QCOMPARE(tableView->contentWidth(), (colCount * (delegateWidth + colSpacing)) - colSpacing);
+ QCOMPARE(tableView->contentHeight(), (rowCount * (delegateHeight + rowSpacing)) - rowSpacing);
+
+ // Remove a row (this should also make affect contentWidth if rowCount becomes 0)
+ model.removeRow(0);
+ rowCount = model.rowCount();
+ WAIT_UNTIL_POLISHED;
+ QCOMPARE(tableView->contentWidth(), rowCount == 0 ? 0 : (colCount * (delegateWidth + colSpacing)) - colSpacing);
+ QCOMPARE(tableView->contentHeight(), rowCount == 0 ? 0 : (rowCount * (delegateHeight + rowSpacing)) - rowSpacing);
+}
+
QTEST_MAIN(tst_QQuickTableView)
#include "tst_qquicktableview.moc"