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) {
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();

View File

@ -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<int, ModifiedRow> CacheMap;