QTableWidget: assume column 0 when dropping a row below another one

When dropping at a column > 0, the deserialized data wrapped around,
leading to multiple rows being inserted instead of just one (and
column 0 remained empty). Very weird behavior from the user's point of
view.

Drive-by whitespace changes due to clang-format.

Fixes: QTBUG-1387
Change-Id: I8d1dc14c124e468454e98ea6a14f33e3bef6e41a
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
(cherry picked from commit ff8068deb45e45eb683745486956d3c6c795a708)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
David Faure 2024-09-30 22:35:27 +02:00 committed by Qt Cherry-pick Bot
parent ac81827ed8
commit 9f11db1855

View File

@ -849,9 +849,12 @@ bool QTableModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
if (index.isValid()) {
row = index.row();
column = index.column();
}else if (row == -1 || column == -1) { // The user dropped outside the table.
} else if (row == -1 || column == -1) { // The user dropped outside the table.
row = rowCount();
column = 0;
} else { // The user dropped between two rows
// This means inserting a row, which only makes sense at column 0
column = 0;
}
QTableWidget *view = qobject_cast<QTableWidget*>(QObject::parent());