diff options
| author | Joni Poikelin <joni.poikelin@qt.io> | 2025-02-03 13:47:43 +0200 |
|---|---|---|
| committer | Joni Poikelin <joni.poikelin@qt.io> | 2025-02-04 12:30:42 +0200 |
| commit | c350c3888ec2a24e6d4cbf1d644a0867d4eabc67 (patch) | |
| tree | 315e1b55eb79ed1ff7664691d284b2e9d827373d | |
| parent | 3cf7f87f0629a3bb8489376a58132829dd5b647b (diff) | |
Fix TableView crash when reordering if are either no rows or no columns
Fixes: QTBUG-133301
Pick-to: 6.9 6.8
Change-Id: I3032d790ecf850dce93ad719a3ab63d0773d53c3
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
3 files changed, 56 insertions, 8 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 48517edd4b..f7f0f64a68 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -7505,15 +7505,13 @@ void QQuickTableViewPrivate::initializeIndexMapping() visualIndex[index].index = logicalIndex[index].index = index; }; - if (!tableSize.isEmpty()) { - if (visualIndices[0].size() != tableSize.width() - || logicalIndices[0].size() != tableSize.width()) - initIndices(visualIndices[0], logicalIndices[0], tableSize.width()); + if (visualIndices[0].size() != tableSize.width() + || logicalIndices[0].size() != tableSize.width()) + initIndices(visualIndices[0], logicalIndices[0], tableSize.width()); - if (visualIndices[1].size() != tableSize.height() - || logicalIndices[1].size() != tableSize.height()) - initIndices(visualIndices[1], logicalIndices[1], tableSize.height()); - } + if (visualIndices[1].size() != tableSize.height() + || logicalIndices[1].size() != tableSize.height()) + initIndices(visualIndices[1], logicalIndices[1], tableSize.height()); } void QQuickTableViewPrivate::clearIndexMapping() diff --git a/tests/auto/quickcontrols/qquickheaderview/data/reorderEmptyModel.qml b/tests/auto/quickcontrols/qquickheaderview/data/reorderEmptyModel.qml new file mode 100644 index 0000000000..c92af8b27f --- /dev/null +++ b/tests/auto/quickcontrols/qquickheaderview/data/reorderEmptyModel.qml @@ -0,0 +1,32 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtQuick.Controls +import TestTableModelWithHeader + +ApplicationWindow { + width: 400 + height: 400 + + property alias headerView: headerView + + Column { + HorizontalHeaderView { + id: headerView + objectName: "horizontalHeader" + syncView: tableView + textRole: "customRole" + movableColumns: true + } + TableView { + id: tableView + width: 400 + height: 100 + model: TestTableModelWithHeader { + rowCount: 0 + columnCount: 4 + } + } + } +} diff --git a/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp b/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp index 55f867ddae..c5740df731 100644 --- a/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp +++ b/tests/auto/quickcontrols/qquickheaderview/tst_qquickheaderview.cpp @@ -233,6 +233,7 @@ private slots: void dragInvalidItemDuringReorder(); void horizontalHeaderViewWithListModel_data(); void horizontalHeaderViewWithListModel(); + void reorderEmptyModel(); private: QQmlEngine *engine; @@ -540,6 +541,23 @@ void tst_QQuickHeaderView::horizontalHeaderViewWithListModel() } } +void tst_QQuickHeaderView::reorderEmptyModel() +{ + QQuickApplicationHelper helper(this, QStringLiteral("reorderEmptyModel.qml")); + QVERIFY2(helper.errorMessage.isEmpty(), helper.errorMessage); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + auto hhv = window->findChild<QQuickHorizontalHeaderView *>("horizontalHeader"); + QVERIFY(hhv); + + QSignalSpy columnMovedSpy(hhv, SIGNAL(columnMoved(int, int, int))); + QVERIFY(columnMovedSpy.isValid()); + hhv->moveColumn(0, 1); + QVERIFY(!columnMovedSpy.isEmpty()); +} + QTEST_MAIN(tst_QQuickHeaderView) #include "tst_qquickheaderview.moc" |
