From 434c46e8dc838cec0d2a2193701c52cc78ba0862 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Fri, 10 Feb 2012 02:36:29 +0100 Subject: [PATCH] QSqlTableModel: do not store primaryValues in change cache They can be generated on demand regardless of edit strategy. Change-Id: I1e1853e93cc453f1486b65ce577f00141b9c5c47 Reviewed-by: Yunqiao Yin --- src/sql/models/qsqltablemodel.cpp | 14 +++++--------- src/sql/models/qsqltablemodel_p.h | 6 ++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 457e7539a3..12561ee189 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -504,8 +504,7 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in if (row.op() == QSqlTableModelPrivate::None) { row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, - d->rec, - d->primaryValues(index.row())); + d->rec); } row.setValue(index.column(), value); @@ -551,7 +550,7 @@ bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values) QSqlRecord rec(values); emit beforeUpdate(row, rec); - const QSqlRecord whereValues = d->strategy == OnManualSubmit ? d->cache[row].primaryValues() : d->primaryValues(row); + const QSqlRecord whereValues = d->primaryValues(row); bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); QString stmt = d->db.driver()->sqlStatement(QSqlDriver::UpdateStatement, d->tableName, rec, prepStatement); @@ -618,7 +617,7 @@ bool QSqlTableModel::deleteRowFromTable(int row) Q_D(QSqlTableModel); emit beforeDelete(row); - const QSqlRecord whereValues = d->strategy == OnManualSubmit ? d->cache[row].primaryValues() : d->primaryValues(row); + const QSqlRecord whereValues = d->primaryValues(row); bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement, d->tableName, @@ -1009,9 +1008,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, - QSqlRecord(), - d->primaryValues(idx)); + d->cache[idx] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete); if (d->strategy == OnManualSubmit) emit headerDataChanged(Qt::Vertical, idx, idx); } @@ -1227,8 +1224,7 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record) QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row]; if (mrow.op() == QSqlTableModelPrivate::None) mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, - d->rec, - d->primaryValues(row)); + d->rec); 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 c2e4442a6b..052f99005f 100644 --- a/src/sql/models/qsqltablemodel_p.h +++ b/src/sql/models/qsqltablemodel_p.h @@ -100,8 +100,8 @@ public: class ModifiedRow { public: - inline ModifiedRow(Op o = None, const QSqlRecord &r = QSqlRecord(), const QSqlRecord &pVals = QSqlRecord()) - : m_op(o), m_rec(r), m_primaryValues(pVals) + inline ModifiedRow(Op o = None, const QSqlRecord &r = QSqlRecord()) + : m_op(o), m_rec(r) { for (int i = m_rec.count() - 1; i >= 0; --i) m_rec.setGenerated(i, false); @@ -109,7 +109,6 @@ public: inline Op op() const { return m_op; } inline QSqlRecord rec() const { return m_rec; } inline QSqlRecord& recRef() { return m_rec; } - inline QSqlRecord primaryValues() const { return m_primaryValues; } inline void setValue(int c, const QVariant &v) { m_rec.setValue(c, v); @@ -118,7 +117,6 @@ public: private: Op m_op; QSqlRecord m_rec; - QSqlRecord m_primaryValues; }; typedef QMap CacheMap;