diff options
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 140 | ||||
-rw-r--r-- | src/quick/items/qquicktableview_p.h | 20 | ||||
-rw-r--r-- | src/quick/items/qquicktableview_p_p.h | 1 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 118 |
4 files changed, 31 insertions, 248 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index ffd0ff4fa5..093aec6cdc 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -210,42 +210,6 @@ */ /*! - \qmlproperty real QtQuick::TableView::topMargin - - This property holds the margin between the top of the table and - the top of the content view. - - The default value is 0. -*/ - -/*! - \qmlproperty real QtQuick::TableView::bottomMargin - - This property holds the margin between the bottom of the table and - the bottom of the content view. - - The default value is 0. -*/ - -/*! - \qmlproperty real QtQuick::TableView::leftMargin - - This property holds the margin between the left side of the table and - the left side of the content view. - - The default value is 0. -*/ - -/*! - \qmlproperty real QtQuick::TableView::rightMargin - - This property holds the margin between the right side of the table and - the right side of the content view. - - The default value is 0. -*/ - -/*! \qmlproperty var QtQuick::TableView::rowHeightProvider This property can hold a function that returns the row height for each row @@ -531,14 +495,10 @@ void QQuickTableViewPrivate::updateContentWidth() contentSizeBenchMarkPoint.setX(currentRightColumn); const qreal spacing = currentRightColumn * cellSpacing.width(); - const qreal margins = tableMargins.left() + tableMargins.right(); - qreal currentWidth = loadedTableOuterRect.right() - tableMargins.left(); + qreal currentWidth = loadedTableOuterRect.right(); const qreal averageCellWidth = (currentWidth - spacing) / (currentRightColumn + 1); qreal estimatedWidth = (tableSize.width() * (averageCellWidth + cellSpacing.width())) - cellSpacing.width(); - currentWidth += margins; - estimatedWidth += margins; - if (currentRightColumn >= tableSize.width() - 1) { // We are at the last column, and can set the exact width if (currentWidth != q->implicitWidth()) @@ -572,14 +532,10 @@ void QQuickTableViewPrivate::updateContentHeight() contentSizeBenchMarkPoint.setY(currentBottomRow); const qreal spacing = currentBottomRow * cellSpacing.height(); - const qreal margins = tableMargins.top() + tableMargins.bottom(); - qreal currentHeight = loadedTableOuterRect.bottom() - tableMargins.top(); + qreal currentHeight = loadedTableOuterRect.bottom(); const qreal averageCellHeight = (currentHeight - spacing) / (currentBottomRow + 1); qreal estimatedHeight = (tableSize.height() * (averageCellHeight + cellSpacing.height())) - cellSpacing.height(); - currentHeight += margins; - estimatedHeight += margins; - if (currentBottomRow >= tableSize.height() - 1) { // We are at the last row, and can set the exact height if (currentHeight != q->implicitHeight()) @@ -605,23 +561,23 @@ void QQuickTableViewPrivate::enforceTableAtOrigin() bool layoutNeeded = false; const qreal flickMargin = 50; - if (loadedTable.x() == 0 && loadedTableOuterRect.x() > tableMargins.left()) { + if (loadedTable.x() == 0 && loadedTableOuterRect.x() > 0) { // The table is at the beginning, but not at the edge of the - // content view. So move the table to origo. - loadedTableOuterRect.moveLeft(tableMargins.left()); + // content view. So move the table to origin. + loadedTableOuterRect.moveLeft(0); layoutNeeded = true; - } else if (loadedTableOuterRect.x() < tableMargins.left()) { + } else if (loadedTableOuterRect.x() < 0) { // The table is outside the beginning of the content view. Move // the whole table inside, and make some room for flicking. - loadedTableOuterRect.moveLeft(qFuzzyIsNull(tableMargins.left() + loadedTable.x()) ? 0 : flickMargin); + loadedTableOuterRect.moveLeft(loadedTable.x() == 0 ? 0 : flickMargin); layoutNeeded = true; } - if (loadedTable.y() == 0 && loadedTableOuterRect.y() > tableMargins.top()) { - loadedTableOuterRect.moveTop(tableMargins.top()); + if (loadedTable.y() == 0 && loadedTableOuterRect.y() > 0) { + loadedTableOuterRect.moveTop(0); layoutNeeded = true; - } else if (loadedTableOuterRect.y() < tableMargins.top()) { - loadedTableOuterRect.moveTop(qFuzzyIsNull(tableMargins.top() + loadedTable.y()) ? 0 : flickMargin); + } else if (loadedTableOuterRect.y() < 0) { + loadedTableOuterRect.moveTop(loadedTable.y() == 0 ? 0 : flickMargin); layoutNeeded = true; } @@ -1319,7 +1275,7 @@ void QQuickTableViewPrivate::beginRebuildTable() if (rebuildOptions & RebuildOption::All) { releaseLoadedItems(QQmlTableInstanceModel::NotReusable); topLeft = QPoint(0, 0); - topLeftPos = QPointF(tableMargins.left(), tableMargins.top()); + topLeftPos = QPoint(0, 0); q->setContentX(0); q->setContentY(0); } else if (rebuildOptions & RebuildOption::ViewportOnly) { @@ -1783,78 +1739,6 @@ void QQuickTableView::setColumnSpacing(qreal spacing) emit columnSpacingChanged(); } -qreal QQuickTableView::topMargin() const -{ - return d_func()->tableMargins.top(); -} - -void QQuickTableView::setTopMargin(qreal margin) -{ - Q_D(QQuickTableView); - if (qt_is_nan(margin)) - return; - if (qFuzzyCompare(d->tableMargins.top(), margin)) - return; - - d->tableMargins.setTop(margin); - d->invalidateColumnRowPositions(); - emit topMarginChanged(); -} - -qreal QQuickTableView::bottomMargin() const -{ - return d_func()->tableMargins.bottom(); -} - -void QQuickTableView::setBottomMargin(qreal margin) -{ - Q_D(QQuickTableView); - if (qt_is_nan(margin)) - return; - if (qFuzzyCompare(d->tableMargins.bottom(), margin)) - return; - - d->tableMargins.setBottom(margin); - d->invalidateColumnRowPositions(); - emit bottomMarginChanged(); -} - -qreal QQuickTableView::leftMargin() const -{ - return d_func()->tableMargins.left(); -} - -void QQuickTableView::setLeftMargin(qreal margin) -{ - Q_D(QQuickTableView); - if (qt_is_nan(margin)) - return; - if (qFuzzyCompare(d->tableMargins.left(), margin)) - return; - - d->tableMargins.setLeft(margin); - d->invalidateColumnRowPositions(); - emit leftMarginChanged(); -} - -qreal QQuickTableView::rightMargin() const -{ - return d_func()->tableMargins.right(); -} - -void QQuickTableView::setRightMargin(qreal margin) -{ - Q_D(QQuickTableView); - if (qt_is_nan(margin)) - return; - if (qFuzzyCompare(d->tableMargins.right(), margin)) - return; - - d->tableMargins.setRight(margin); - d->invalidateColumnRowPositions(); - emit rightMarginChanged(); -} - QJSValue QQuickTableView::rowHeightProvider() const { return d_func()->rowHeightProvider; diff --git a/src/quick/items/qquicktableview_p.h b/src/quick/items/qquicktableview_p.h index 2ffc23d29b..0a2eff8fc1 100644 --- a/src/quick/items/qquicktableview_p.h +++ b/src/quick/items/qquicktableview_p.h @@ -72,10 +72,6 @@ class Q_QUICK_PRIVATE_EXPORT QQuickTableView : public QQuickFlickable Q_PROPERTY(int columns READ columns NOTIFY columnsChanged) Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged) Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged) - Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged) - Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged) - Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged) Q_PROPERTY(QJSValue rowHeightProvider READ rowHeightProvider WRITE setRowHeightProvider NOTIFY rowHeightProviderChanged) Q_PROPERTY(QJSValue columnWidthProvider READ columnWidthProvider WRITE setColumnWidthProvider NOTIFY columnWidthProviderChanged) Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) @@ -96,18 +92,6 @@ public: qreal columnSpacing() const; void setColumnSpacing(qreal spacing); - qreal topMargin() const; - void setTopMargin(qreal margin); - - qreal bottomMargin() const; - void setBottomMargin(qreal margin); - - qreal leftMargin() const; - void setLeftMargin(qreal margin); - - qreal rightMargin() const; - void setRightMargin(qreal margin); - QJSValue rowHeightProvider() const; void setRowHeightProvider(QJSValue provider); @@ -137,10 +121,6 @@ Q_SIGNALS: void columnsChanged(); void rowSpacingChanged(); void columnSpacingChanged(); - void topMarginChanged(); - void bottomMarginChanged(); - void leftMarginChanged(); - void rightMarginChanged(); void rowHeightProviderChanged(); void columnWidthProviderChanged(); void modelChanged(); diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h index 1e8c10c285..e7b2c57086 100644 --- a/src/quick/items/qquicktableview_p_p.h +++ b/src/quick/items/qquicktableview_p_p.h @@ -227,7 +227,6 @@ public: QPoint contentSizeBenchMarkPoint = QPoint(-1, -1); QSizeF cellSpacing = QSizeF(0, 0); - QMarginsF tableMargins; QQmlTableInstanceModel::ReusableFlag reusableFlag = QQmlTableInstanceModel::Reusable; diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 6a6849eeae..a4c954b1b4 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -111,8 +111,6 @@ private slots: void checkLayoutOfEqualSizedDelegateItems(); void checkFocusRemoved_data(); void checkFocusRemoved(); - void checkTableMargins_data(); - void checkTableMargins(); void fillTableViewButNothingMore_data(); void fillTableViewButNothingMore(); void checkInitialAttachedProperties_data(); @@ -503,31 +501,28 @@ void tst_QQuickTableView::checkContentWidthAndHeight() // to do the calculations once, and use them for both axis, below. QCOMPARE(tableView->width(), tableView->height()); QCOMPARE(tableView->rowSpacing(), tableView->columnSpacing()); - QCOMPARE(tableView->leftMargin(), tableView->rightMargin()); - QCOMPARE(tableView->topMargin(), tableView->bottomMargin()); const int tableSize = 100; const int cellSizeSmall = 100; const int cellSizeLarge = 200; const int spacing = 1; - const int margin = 10; const int smallCellCount = 20; const int largeCellCount = tableSize - smallCellCount; - const qreal spacingAndMargins = ((tableSize - 1) * spacing) + (margin * 2); + const qreal accumulatedSpacing = ((tableSize - 1) * spacing); auto model = TestModelAsVariant(tableSize, tableSize); tableView->setModel(model); WAIT_UNTIL_POLISHED; - const qreal expectedSizeInit = (tableSize * cellSizeSmall) + ((tableSize - 1) * spacing) + (margin * 2); + const qreal expectedSizeInit = (tableSize * cellSizeSmall) + ((tableSize - 1) * spacing); QCOMPARE(tableView->contentWidth(), expectedSizeInit); QCOMPARE(tableView->contentHeight(), expectedSizeInit); // Flick in 5 more rows and columns, but not so far that we start loading in // the ones that are bigger. Loading in more rows and columns of the same // size as the initial ones should not change the first prediction. - qreal flickTo = ((cellSizeSmall + spacing) * 5) + margin; + qreal flickTo = ((cellSizeSmall + spacing) * 5); tableView->setContentX(flickTo); tableView->setContentY(flickTo); @@ -537,7 +532,7 @@ void tst_QQuickTableView::checkContentWidthAndHeight() // Flick to row and column 20 (smallCellCount), since there the row and // column sizes increases with 100. Check that TableView then adjusts // contentWidth and contentHeight accordingly. - flickTo = ((cellSizeSmall + spacing) * smallCellCount) + margin - spacing; + flickTo = ((cellSizeSmall + spacing) * smallCellCount) - spacing; tableView->setContentX(flickTo); tableView->setContentY(flickTo); @@ -549,7 +544,7 @@ void tst_QQuickTableView::checkContentWidthAndHeight() const qreal secondHalfOneScreenLength = largeSizeCellCountInView * cellSizeLarge; const qreal lengthAfterFlick = firstHalfLength + secondHalfOneScreenLength; const qreal averageCellSize = lengthAfterFlick / (smallCellCount + largeSizeCellCountInView); - const qreal expectedSizeHalf = (tableSize * averageCellSize) + spacingAndMargins; + const qreal expectedSizeHalf = (tableSize * averageCellSize) + accumulatedSpacing; QCOMPARE(tableView->contentWidth(), expectedSizeHalf); QCOMPARE(tableView->contentHeight(), expectedSizeHalf); @@ -557,7 +552,7 @@ void tst_QQuickTableView::checkContentWidthAndHeight() // Flick to the end (row/column 100, and overshoot a bit), and // check that we then end up with the exact content width/height. const qreal secondHalfLength = largeCellCount * cellSizeLarge; - const qreal expectedFullSize = (firstHalfLength + secondHalfLength) + spacingAndMargins; + const qreal expectedFullSize = (firstHalfLength + secondHalfLength) + accumulatedSpacing; tableView->setContentX(expectedFullSize); tableView->setContentY(expectedFullSize); @@ -713,6 +708,9 @@ void tst_QQuickTableView::checkLayoutOfEqualSizedDelegateItems() tableView->setModel(model); tableView->setRowSpacing(spacing.height()); tableView->setColumnSpacing(spacing.width()); + + // Setting margins on Flickable should not affect the layout of the + // delegate items, since the margins is "transparent" to the TableView. tableView->setLeftMargin(margins.left()); tableView->setTopMargin(margins.top()); tableView->setRightMargin(margins.right()); @@ -729,8 +727,8 @@ void tst_QQuickTableView::checkLayoutOfEqualSizedDelegateItems() QCOMPARE(item->parentItem(), tableView->contentItem()); const QPoint cell = getContextRowAndColumn(item); - qreal expectedX = margins.left() + (cell.x() * (expectedItemWidth + spacing.width())); - qreal expectedY = margins.top() + (cell.y() * (expectedItemHeight + spacing.height())); + qreal expectedX = cell.x() * (expectedItemWidth + spacing.width()); + qreal expectedY = cell.y() * (expectedItemHeight + spacing.height()); QCOMPARE(item->x(), expectedX); QCOMPARE(item->y(), expectedY); QCOMPARE(item->z(), 1); @@ -782,83 +780,16 @@ void tst_QQuickTableView::checkFocusRemoved() } } -void tst_QQuickTableView::checkTableMargins_data() -{ - QTest::addColumn<QVariant>("model"); - QTest::addColumn<QSizeF>("spacing"); - QTest::addColumn<QMarginsF>("margins"); - - 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() -{ - // Check that the space between the content view and - // the items matches the margins we set on the tableview. - QFETCH(QVariant, model); - QFETCH(QSizeF, spacing); - QFETCH(QMarginsF, margins); - LOAD_TABLEVIEW("plaintableview.qml"); - - 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()); - - WAIT_UNTIL_POLISHED; - - // Check left-, and top margins - auto const topLeftItem = tableViewPrivate->loadedTableItem(QPoint(0, 0))->item; - qreal leftSpace = topLeftItem->x(); - qreal topSpace = topLeftItem->y(); - 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()); -} - 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); + QTest::newRow("0 0,0 0") << QSizeF(0, 0); + QTest::newRow("0 10,10 0") << QSizeF(10, 10); + QTest::newRow("100 10,10 0") << QSizeF(10, 10); + QTest::newRow("0 0,0 100") << QSizeF(0, 0); + QTest::newRow("0 10,10 100") << QSizeF(10, 10); + QTest::newRow("100 10,10 100") << QSizeF(10, 10); } void tst_QQuickTableView::fillTableViewButNothingMore() @@ -866,7 +797,6 @@ 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; @@ -876,20 +806,12 @@ void tst_QQuickTableView::fillTableViewButNothingMore() 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()); WAIT_UNTIL_POLISHED; auto const topLeftFxItem = tableViewPrivate->loadedTableItem(QPoint(0, 0)); 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 = tableViewPrivate->loadedTableItem(tableViewPrivate->loadedTable.bottomRight()); auto const bottomRightItem = bottomRightFxItem->item; const QPoint bottomRightCell = getContextRowAndColumn(bottomRightItem.data()); @@ -900,8 +822,7 @@ void tst_QQuickTableView::fillTableViewButNothingMore() // 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 expectedColumns = qCeil(tableView->width() / cellWidth); int actualColumns = bottomRightCell.x() + 1; QCOMPARE(actualColumns, expectedColumns); @@ -911,8 +832,7 @@ void tst_QQuickTableView::fillTableViewButNothingMore() // 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 expectedRows = qCeil(tableView->height() / cellHeight); int actualRows = bottomRightCell.y() + 1; QCOMPARE(actualRows, expectedRows); } |