aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktableview
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-08-22 11:20:03 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-08-22 15:44:49 +0000
commit8ee5dff21c3701a5a0dd1de9bed563da0aa12ef6 (patch)
tree3de793f50b4544f5209a6b5664e2d6ffe0ef7d03 /tests/auto/quick/qquicktableview
parentcd5937273ee14c3941574a2db7cc0f8c3682def0 (diff)
QQmlDelegateModelItem: ensure that we emit changes to row and column
As it stood, we would only emit changes to row and column if index changed as well. But when removing rows and columns from the model, it can happen that we reuse an item that by accident has the same index as the one we change it to, but belonging to a different row and column. So we need to check for changes to the index the same way we do for row and column. Change-Id: I9d507a74aa5dcb0fe7630e7af1e949bd2db7fb47 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktableview')
-rw-r--r--tests/auto/quick/qquicktableview/data/checkrowandcolumnnotchanged.qml94
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp29
2 files changed, 123 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktableview/data/checkrowandcolumnnotchanged.qml b/tests/auto/quick/qquicktableview/data/checkrowandcolumnnotchanged.qml
new file mode 100644
index 0000000000..bef0df2501
--- /dev/null
+++ b/tests/auto/quick/qquicktableview/data/checkrowandcolumnnotchanged.qml
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** 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
+import Qt.labs.qmlmodels 1.0
+
+Item {
+ width: 640
+ height: 450
+
+ property alias tableView: tableView
+
+ TableView {
+ id: tableView
+ width: 600
+ height: 400
+ delegate: DelegateChooser {
+ DelegateChoice {
+ row: 0
+ column: 0
+ delegate: maskDelegate
+ }
+ DelegateChoice {
+ row: 1
+ column: 1
+ delegate: maskDelegate
+ }
+ DelegateChoice {
+ delegate: tableViewDelegate
+ }
+ }
+ }
+
+ Component {
+ // Add this mask delegate, to force QQmlTableInstanceModel to
+ // reuse the precise cells that we want to swap in the test
+ id: maskDelegate
+ Rectangle {
+ implicitWidth: 100
+ implicitHeight: 50
+ color: "green"
+ }
+ }
+
+ Component {
+ id: tableViewDelegate
+ Rectangle {
+ implicitWidth: 100
+ implicitHeight: 50
+ Text {
+ anchors.fill: parent
+ text: column + "," + row
+ }
+ }
+ }
+
+}
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index b49164a78c..ea3531ba13 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -127,6 +127,7 @@ private slots:
void checkContextProperties();
void checkContextPropertiesQQmlListProperyModel_data();
void checkContextPropertiesQQmlListProperyModel();
+ void checkRowAndColumnChangedButNotIndex();
};
tst_QQuickTableView::tst_QQuickTableView()
@@ -1593,6 +1594,34 @@ void tst_QQuickTableView::checkContextPropertiesQQmlListProperyModel()
}
}
+void tst_QQuickTableView::checkRowAndColumnChangedButNotIndex()
+{
+ // Check that context row and column changes even if the index stays the
+ // same when the item is reused. This can happen in rare cases if the item
+ // is first used at e.g (row 1, col 0), but then reused at (row 0, col 1)
+ // while the model has changed row count in-between.
+ LOAD_TABLEVIEW("checkrowandcolumnnotchanged.qml");
+
+ TestModel model(2, 1);
+ tableView->setModel(QVariant::fromValue(&model));
+
+ WAIT_UNTIL_POLISHED;
+
+ model.removeRow(1);
+ model.insertColumn(1);
+ tableView->forceLayout();
+
+ const auto item = tableViewPrivate->loadedTableItem(QPoint(1, 0))->item;
+ const auto context = qmlContext(item.data());
+ const int contextIndex = context->contextProperty("index").toInt();
+ const int contextRow = context->contextProperty("row").toInt();
+ const int contextColumn = context->contextProperty("column").toInt();
+
+ QCOMPARE(contextIndex, 1);
+ QCOMPARE(contextRow, 0);
+ QCOMPARE(contextColumn, 1);
+}
+
QTEST_MAIN(tst_QQuickTableView)
#include "tst_qquicktableview.moc"