diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-09-07 14:13:51 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-09-10 09:31:04 +0000 |
commit | 5ec0599032b78d628ab562d839ae4bf2414c7bf6 (patch) | |
tree | 60da351e66de16a4f655d57734e81bf8114c3850 /tests/auto/quick | |
parent | 2aaf007c1367f58ce80bc660c56ab2c3284d1388 (diff) |
QQuickTableView: don't set contentX/Y to zero when building the table
Don't reset the content item to 0,0 when we do a rebuild of the
table, since that will overwrite whatever the user has set to contentX/Y
explicitly. Doing the latter can be handy if he needs to flick the table
to a start position upon construction. If the user want's to move the
content item back to origin when changing the model, he can instead do
so manually.
Change-Id: Ic7bc424312569e49115dea5037dd1109261a3aff
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r-- | tests/auto/quick/qquicktableview/data/setcontentpos.qml | 71 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 20 |
2 files changed, 91 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/data/setcontentpos.qml b/tests/auto/quick/qquicktableview/data/setcontentpos.qml new file mode 100644 index 0000000000..bff97e4e5e --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/setcontentpos.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 + +Item { + width: 640 + height: 450 + + property alias tableView: tableView + + TableView { + id: tableView + width: 600 + height: 400 + anchors.margins: 1 + clip: true + delegate: tableViewDelegate + columnSpacing: 1 + rowSpacing: 1 + contentX: 250 + contentY: 250 + } + + Component { + id: tableViewDelegate + Rectangle { + implicitWidth: 100 + implicitHeight: 100 + color: "lightgray" + } + } + +} diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index a4c954b1b4..c7fd51f72c 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -104,6 +104,7 @@ private slots: void checkForceLayoutFunction(); void checkContentWidthAndHeight(); void checkExplicitContentWidthAndHeight(); + void checkContentXY(); void noDelegate(); void countDelegateItems_data(); void countDelegateItems(); @@ -586,6 +587,25 @@ void tst_QQuickTableView::checkExplicitContentWidthAndHeight() QCOMPARE(tableView->contentHeight(), 1000); } +void tst_QQuickTableView::checkContentXY() +{ + // Check that you can set contentX and contentY on + // startup, and that this is respected by TableView + LOAD_TABLEVIEW("setcontentpos.qml"); + + auto model = TestModelAsVariant(10, 10); + tableView->setModel(model); + WAIT_UNTIL_POLISHED; + + QCOMPARE(tableView->contentX(), 250); + QCOMPARE(tableView->contentY(), 250); + + // Since we flick the content item, we expect the + // loaded table to end up at row/column 2,2 + QCOMPARE(tableViewPrivate->loadedTable.left(), 2); + QCOMPARE(tableViewPrivate->loadedTable.top(), 2); +} + void tst_QQuickTableView::noDelegate() { // Check that you can skip setting a delegate without |