diff options
author | Michael Goddard <michael.goddard@nokia.com> | 2010-11-03 01:58:36 (GMT) |
---|---|---|
committer | Michael Goddard <michael.goddard@nokia.com> | 2011-02-04 05:41:02 (GMT) |
commit | 3bed865c35d8eb920ba5a68276fdf1690c834a64 (patch) | |
tree | dd733baba6540ab7089b5e2d0e7358b344476546 | |
parent | 9c61e9a40e774fe32b16c133a5cdd6b9d9d29d83 (diff) | |
download | Qt-3bed865c35d8eb920ba5a68276fdf1690c834a64.zip Qt-3bed865c35d8eb920ba5a68276fdf1690c834a64.tar.gz Qt-3bed865c35d8eb920ba5a68276fdf1690c834a64.tar.bz2 |
Make sure that setRecord emits dataChanged() with OnManualSubmit.
Since the change is immediately visible through data(), this is needed
so that QSortFilterProxyModel etc work correctly.
Change-Id: Ied7afce2e6a1f516b502d3501f9d214df54e52f2
Task-number: QTBUG-14831
Reviewed-by: Charles Yin
-rw-r--r-- | src/sql/models/qsqltablemodel.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp | 9 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 6f9c284..61cd1d3 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -1338,6 +1338,9 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record) else mrow.rec.setValue(idx, record.value(i)); } + + if (isOk) + emit dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1)); return isOk; } } return false; diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp index 1821d9c..9428ef4 100644 --- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp @@ -402,9 +402,14 @@ void tst_QSqlTableModel::setRecord() rec.setValue(2, rec.value(2).toString() + 'X'); QVERIFY(model.setRecord(i, rec)); - if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnManualSubmit) + if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnManualSubmit) { + // setRecord should emit dataChanged() itself for manualSubmit + QCOMPARE(spy.count(), 1); + QCOMPARE(spy.at(0).count(), 2); + QCOMPARE(qvariant_cast<QModelIndex>(spy.at(0).at(0)), model.index(i, 0)); + QCOMPARE(qvariant_cast<QModelIndex>(spy.at(0).at(1)), model.index(i, rec.count() - 1)); QVERIFY(model.submitAll()); - else if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnRowChange && i == model.rowCount() -1) + } else if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnRowChange && i == model.rowCount() -1) model.submit(); else { // dataChanged() is not emitted when submitAll() is called |