QTableWidget: fix cellChanged signal emitted by takeItem()

QTableWidget::takeItem() emitted cellChanged with row and column set to
-1. The internal functions searched for item after it was reset to
nullptr and therefore it was not found.
Since the modified cell is known because it's passed to the takeItem
function, the correct row/column can be retrieved from there.

Task-number: QTBUG-70478
Change-Id: I5ff5991c49f3200efe95fde4c7d0d28e19be7ebf
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Christian Ehrlicher 2018-09-16 21:45:55 +02:00
parent c14103be50
commit c18a91b0dc
2 changed files with 8 additions and 1 deletions

View File

@ -225,7 +225,7 @@ QTableWidgetItem *QTableModel::takeItem(int row, int column)
itm->view = 0;
itm->d->id = -1;
tableItems[i] = 0;
QModelIndex ind = index(itm);
const QModelIndex ind = index(row, column);
emit dataChanged(ind, ind);
}
return itm;

View File

@ -362,11 +362,18 @@ void tst_QTableWidget::takeItem()
for (int c = 0; c < testWidget->columnCount(); ++c)
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
QSignalSpy spy(testWidget, &QTableWidget::cellChanged);
QTableWidgetItem *item = testWidget->takeItem(row, column);
QCOMPARE(!!item, expectItem);
if (expectItem) {
QCOMPARE(item->text(), QString::number(row * column + column));
delete item;
QTRY_COMPARE(spy.count(), 1);
const QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(arguments.size(), 2);
QCOMPARE(arguments.at(0).toInt(), row);
QCOMPARE(arguments.at(1).toInt(), column);
}
QVERIFY(!testWidget->takeItem(row, column));
}