diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 075e32ff6e..d31e4bc335 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -510,7 +510,7 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in if (row.op() == QSqlTableModelPrivate::None) row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, - d->rec); + record(index.row())); row.setValue(index.column(), value); emit dataChanged(index, index); @@ -1004,7 +1004,7 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent) // so fake this by adjusting row --row; } else { - d->cache[idx] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete); + d->cache[idx] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, record(idx)); if (d->strategy == OnManualSubmit) emit headerDataChanged(Qt::Vertical, idx, idx); } @@ -1235,7 +1235,7 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &values) QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row]; if (mrow.op() == QSqlTableModelPrivate::None) mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, - d->rec); + record(row)); Map::const_iterator i = map.constBegin(); const Map::const_iterator e = map.constEnd(); diff --git a/src/sql/models/qsqltablemodel_p.h b/src/sql/models/qsqltablemodel_p.h index 168b689441..7266810c40 100644 --- a/src/sql/models/qsqltablemodel_p.h +++ b/src/sql/models/qsqltablemodel_p.h @@ -102,10 +102,7 @@ public: public: inline ModifiedRow(Op o = None, const QSqlRecord &r = QSqlRecord()) : m_op(o), m_rec(r), m_submitted(false) - { - for (int i = m_rec.count() - 1; i >= 0; --i) - m_rec.setGenerated(i, false); - } + { init_rec(); } inline Op op() const { return m_op; } inline QSqlRecord rec() const { return m_rec; } inline QSqlRecord& recRef() { return m_rec; } @@ -117,8 +114,15 @@ public: inline bool submitted() const { return m_submitted; } inline void setSubmitted() { m_submitted = true; } private: + void init_rec() + { + for (int i = m_rec.count() - 1; i >= 0; --i) + m_rec.setGenerated(i, false); + m_db_values = m_rec; + } Op m_op; QSqlRecord m_rec; + QSqlRecord m_db_values; bool m_submitted; };