Ensure that we return an invalid QTableWidgetItem when none is available.

Task-number: QTBUG-26195

Change-Id: Iede4f51770bd8c8eab3558137aaf7b1721f25a87
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Stephen Kelly 2012-08-06 18:36:44 +02:00 committed by Qt by Nokia
parent a97d09a84b
commit 2ade633c0a
2 changed files with 17 additions and 1 deletions

View File

@ -234,7 +234,7 @@ QTableWidgetItem *QTableModel::takeItem(int row, int column)
QTableWidgetItem *QTableModel::item(int row, int column) const
{
return tableItems.value(tableIndex(row, column));
return item(index(row, column));
}
QTableWidgetItem *QTableModel::item(const QModelIndex &index) const

View File

@ -100,6 +100,7 @@ private slots:
void task231094();
void task219380_removeLastRow();
void task262056_sortDuplicate();
void itemWithHeaderItems();
private:
QTableWidget *testWidget;
@ -1492,6 +1493,21 @@ void tst_QTableWidget::task262056_sortDuplicate()
}
void tst_QTableWidget::itemWithHeaderItems()
{
// Need a separate testcase for this because the tst_QTableWidget::item testcase
// does creates QTableWidgetItems for each available cell in the table. We're testing
// the case of not all available cells having a QTableWidgetItem set.
QTableWidget table(2, 1);
QTableWidgetItem *item0_0 = new QTableWidgetItem(QTableWidgetItem::UserType);
table.setItem(0, 0, item0_0);
QTableWidgetItem *item1_0 = new QTableWidgetItem(QTableWidgetItem::UserType);
table.setItem(1, 0, item1_0);
QCOMPARE(table.item(0, 1), static_cast<QTableWidgetItem *>(0));
}
QTEST_MAIN(tst_QTableWidget)
#include "tst_qtablewidget.moc"