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 <charles.yin@nokia.com>
This commit is contained in:
Mark Brand 2012-02-10 02:36:29 +01:00 committed by Qt by Nokia
parent f805dd0b40
commit 434c46e8dc
2 changed files with 7 additions and 13 deletions

View File

@ -504,8 +504,7 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in
if (row.op() == QSqlTableModelPrivate::None) { if (row.op() == QSqlTableModelPrivate::None) {
row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update,
d->rec, d->rec);
d->primaryValues(index.row()));
} }
row.setValue(index.column(), value); row.setValue(index.column(), value);
@ -551,7 +550,7 @@ bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values)
QSqlRecord rec(values); QSqlRecord rec(values);
emit beforeUpdate(row, rec); 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); bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries);
QString stmt = d->db.driver()->sqlStatement(QSqlDriver::UpdateStatement, d->tableName, QString stmt = d->db.driver()->sqlStatement(QSqlDriver::UpdateStatement, d->tableName,
rec, prepStatement); rec, prepStatement);
@ -618,7 +617,7 @@ bool QSqlTableModel::deleteRowFromTable(int row)
Q_D(QSqlTableModel); Q_D(QSqlTableModel);
emit beforeDelete(row); 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); bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries);
QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement, QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement,
d->tableName, d->tableName,
@ -1009,9 +1008,7 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
// so fake this by adjusting row // so fake this by adjusting row
--row; --row;
} else { } else {
d->cache[idx] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, d->cache[idx] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete);
QSqlRecord(),
d->primaryValues(idx));
if (d->strategy == OnManualSubmit) if (d->strategy == OnManualSubmit)
emit headerDataChanged(Qt::Vertical, idx, idx); emit headerDataChanged(Qt::Vertical, idx, idx);
} }
@ -1227,8 +1224,7 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record)
QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row]; QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row];
if (mrow.op() == QSqlTableModelPrivate::None) if (mrow.op() == QSqlTableModelPrivate::None)
mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update,
d->rec, d->rec);
d->primaryValues(row));
Map::const_iterator i = map.constBegin(); Map::const_iterator i = map.constBegin();
const Map::const_iterator e = map.constEnd(); const Map::const_iterator e = map.constEnd();

View File

@ -100,8 +100,8 @@ public:
class ModifiedRow class ModifiedRow
{ {
public: public:
inline ModifiedRow(Op o = None, const QSqlRecord &r = QSqlRecord(), const QSqlRecord &pVals = QSqlRecord()) inline ModifiedRow(Op o = None, const QSqlRecord &r = QSqlRecord())
: m_op(o), m_rec(r), m_primaryValues(pVals) : m_op(o), m_rec(r)
{ {
for (int i = m_rec.count() - 1; i >= 0; --i) for (int i = m_rec.count() - 1; i >= 0; --i)
m_rec.setGenerated(i, false); m_rec.setGenerated(i, false);
@ -109,7 +109,6 @@ public:
inline Op op() const { return m_op; } inline Op op() const { return m_op; }
inline QSqlRecord rec() const { return m_rec; } inline QSqlRecord rec() const { return m_rec; }
inline QSqlRecord& recRef() { return m_rec; } inline QSqlRecord& recRef() { return m_rec; }
inline QSqlRecord primaryValues() const { return m_primaryValues; }
inline void setValue(int c, const QVariant &v) inline void setValue(int c, const QVariant &v)
{ {
m_rec.setValue(c, v); m_rec.setValue(c, v);
@ -118,7 +117,6 @@ public:
private: private:
Op m_op; Op m_op;
QSqlRecord m_rec; QSqlRecord m_rec;
QSqlRecord m_primaryValues;
}; };
typedef QMap<int, ModifiedRow> CacheMap; typedef QMap<int, ModifiedRow> CacheMap;