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:
parent
c14103be50
commit
c18a91b0dc
@ -225,7 +225,7 @@ QTableWidgetItem *QTableModel::takeItem(int row, int column)
|
|||||||
itm->view = 0;
|
itm->view = 0;
|
||||||
itm->d->id = -1;
|
itm->d->id = -1;
|
||||||
tableItems[i] = 0;
|
tableItems[i] = 0;
|
||||||
QModelIndex ind = index(itm);
|
const QModelIndex ind = index(row, column);
|
||||||
emit dataChanged(ind, ind);
|
emit dataChanged(ind, ind);
|
||||||
}
|
}
|
||||||
return itm;
|
return itm;
|
||||||
|
@ -362,11 +362,18 @@ void tst_QTableWidget::takeItem()
|
|||||||
for (int c = 0; c < testWidget->columnCount(); ++c)
|
for (int c = 0; c < testWidget->columnCount(); ++c)
|
||||||
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
|
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
|
||||||
|
|
||||||
|
QSignalSpy spy(testWidget, &QTableWidget::cellChanged);
|
||||||
QTableWidgetItem *item = testWidget->takeItem(row, column);
|
QTableWidgetItem *item = testWidget->takeItem(row, column);
|
||||||
QCOMPARE(!!item, expectItem);
|
QCOMPARE(!!item, expectItem);
|
||||||
if (expectItem) {
|
if (expectItem) {
|
||||||
QCOMPARE(item->text(), QString::number(row * column + column));
|
QCOMPARE(item->text(), QString::number(row * column + column));
|
||||||
delete item;
|
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));
|
QVERIFY(!testWidget->takeItem(row, column));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user