diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-29 15:59:45 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-09-03 07:51:40 +0000 |
commit | 5b32b7071725e00cad36e9ee97bcd6e886a254b4 (patch) | |
tree | f83bf2a1f30cd3cc33a001b746be6bb6dbcdd448 /tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | |
parent | 1f2be87eb9093e2287b1a8f87985c50074597117 (diff) |
QQuickTableView: allow negative margins
Currently TableView will hang when using negative margins.
This patch will fix this so that negative margins will work
as expected. An alternative implementations would be to only
allow positive margins, but from an implementation point of
view, there is really no reason to add such a restriction.
Change-Id: Iea89212eb9d7f9d467955e27c70d9b7583a80d2e
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview/tst_qquicktableview.cpp')
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index e5b06051a5..e25a7b72bb 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -717,16 +717,28 @@ void tst_QQuickTableView::checkLayoutOfEqualSizedDelegateItems() void tst_QQuickTableView::checkTableMargins_data() { QTest::addColumn<QVariant>("model"); - QTest::addColumn<QSize>("tableSize"); QTest::addColumn<QSizeF>("spacing"); QTest::addColumn<QMarginsF>("margins"); - QTest::newRow("QAIM 1x1 1,1 0000") << TestModelAsVariant(1, 1) << QSize(1, 1) << QSizeF(1, 1) << QMarginsF(0, 0, 0, 0); - QTest::newRow("QAIM 4x4 1,1 0000") << TestModelAsVariant(4, 4) << QSize(4, 4) << QSizeF(1, 1) << QMarginsF(0, 0, 0, 0); - QTest::newRow("QAIM 1x1 1,1 5555") << TestModelAsVariant(1, 1) << QSize(1, 1) << QSizeF(1, 1) << QMarginsF(5, 5, 5, 5); - QTest::newRow("QAIM 4x4 0,0 3333") << TestModelAsVariant(4, 4) << QSize(4, 4) << QSizeF(0, 0) << QMarginsF(3, 3, 3, 3); - QTest::newRow("QAIM 4x4 2,2 1234") << TestModelAsVariant(4, 4) << QSize(4, 4) << QSizeF(2, 2) << QMarginsF(1, 2, 3, 4); - QTest::newRow("QAIM 1x1 0,0 3210") << TestModelAsVariant(1, 1) << QSize(1, 1) << QSizeF(0, 0) << QMarginsF(3, 2, 1, 0); + QTest::newRow("QAIM single") << TestModelAsVariant(1, 1) << QSizeF(0, 0) << QMarginsF(0, 0, 0, 0); + QTest::newRow("QAIM single, 1,1, no margins") << TestModelAsVariant(1, 1) << QSizeF(1, 1) << QMarginsF(0, 0, 0, 0); + QTest::newRow("QAIM single, no spacing, 1111") << TestModelAsVariant(1, 1) << QSizeF(0, 0) << QMarginsF(1, 1, 1, 1); + + QTest::newRow("QAIM 4x4") << TestModelAsVariant(4, 4) << QSizeF(0, 0) << QMarginsF(0, 0, 0, 0); + QTest::newRow("QAIM 4x4, 1,1, no margins") << TestModelAsVariant(4, 4) << QSizeF(1, 1) << QMarginsF(0, 0, 0, 0); + QTest::newRow("QAIM 4x4, no spacing, 1111") << TestModelAsVariant(1, 1) << QSizeF(0, 0) << QMarginsF(1, 1, 1, 1); + + QTest::newRow("QAIM 1,1 0000") << TestModelAsVariant(20, 20) << QSizeF(1, 1) << QMarginsF(0, 0, 0, 0); + QTest::newRow("QAIM 1,1 5555") << TestModelAsVariant(20, 20) << QSizeF(1, 1) << QMarginsF(5, 5, 5, 5); + QTest::newRow("QAIM 0,0 3333") << TestModelAsVariant(20, 20) << QSizeF(0, 0) << QMarginsF(3, 3, 3, 3); + QTest::newRow("QAIM 2,2 1234") << TestModelAsVariant(20, 20) << QSizeF(2, 2) << QMarginsF(1, 2, 3, 4); + QTest::newRow("QAIM 0,0 3210") << TestModelAsVariant(20, 20) << QSizeF(0, 0) << QMarginsF(3, 2, 1, 0); + + QTest::newRow("QAIM 0,0 negative left margin") << TestModelAsVariant(20, 20) << QSizeF(0, 0) << QMarginsF(-10, 0, 0, 0); + QTest::newRow("QAIM 0,0 negative top margin") << TestModelAsVariant(20, 20) << QSizeF(0, 0) << QMarginsF(0, -10, 0, 0); + QTest::newRow("QAIM 0,0 negative right margin") << TestModelAsVariant(20, 20) << QSizeF(0, 0) << QMarginsF(0, 0, -10, 0); + QTest::newRow("QAIM 0,0 negative bottom margin") << TestModelAsVariant(20, 20) << QSizeF(0, 0) << QMarginsF(0, 0, 0, -10); + QTest::newRow("QAIM 0,0 all margins negative") << TestModelAsVariant(20, 20) << QSizeF(0, 0) << QMarginsF(-10, -10, -10, -10); } void tst_QQuickTableView::checkTableMargins() @@ -734,7 +746,6 @@ void tst_QQuickTableView::checkTableMargins() // Check that the space between the content view and // the items matches the margins we set on the tableview. QFETCH(QVariant, model); - QFETCH(QSize, tableSize); QFETCH(QSizeF, spacing); QFETCH(QMarginsF, margins); LOAD_TABLEVIEW("plaintableview.qml"); @@ -749,19 +760,22 @@ void tst_QQuickTableView::checkTableMargins() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.size(), tableSize); - - auto const topLeftFxItem = tableViewPrivate->loadedTableItem(QPoint(0, 0)); - auto const bottomRightFxItem = tableViewPrivate->loadedTableItem(tableViewPrivate->loadedTable.bottomRight()); - auto const topLeftItem = topLeftFxItem->item; - auto const bottomRightItem = bottomRightFxItem->item; - + // Check left-, and top margins + auto const topLeftItem = tableViewPrivate->loadedTableItem(QPoint(0, 0))->item; qreal leftSpace = topLeftItem->x(); qreal topSpace = topLeftItem->y(); - qreal rightSpace = tableView->contentWidth() - (bottomRightItem->x() + bottomRightItem->width()); - qreal bottomSpace = tableView->contentHeight() - (bottomRightItem->y() + bottomRightItem->height()); QCOMPARE(leftSpace, margins.left()); QCOMPARE(topSpace, margins.top()); + + // Flick the table to the end... + tableView->setContentX(tableView->contentWidth() - tableView->width()); + tableView->setContentY(tableView->contentHeight() - tableView->height()); + const QPoint bottomRightCell = tableViewPrivate->loadedTable.bottomRight(); + auto const bottomRightItem = tableViewPrivate->loadedTableItem(bottomRightCell)->item; + + // ...and check the right-, and bottom margins + qreal rightSpace = tableView->contentWidth() - (bottomRightItem->x() + bottomRightItem->width()); + qreal bottomSpace = tableView->contentHeight() - (bottomRightItem->y() + bottomRightItem->height()); QCOMPARE(rightSpace, margins.right()); QCOMPARE(bottomSpace, margins.bottom()); } |