QSqlTableModel::primaryValues(): take care of row mapping

There is no reason for the caller to be concerned with this.
primaryValues() now takes advantage of the fact that QSqlQueryModel
uses indexInQuery which was recently made virtual.

Change-Id: I7d856ee05f55c3199fd17c618e559320d0582989
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
This commit is contained in:
Mark Brand 2012-02-13 09:57:56 +01:00 committed by Qt by Nokia
parent 555aa4439b
commit f805dd0b40

View File

@ -196,21 +196,16 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
QSqlRecord QSqlTableModelPrivate::primaryValues(int row) const
{
QSqlRecord record;
if (!query.seek(row)) {
error = query.lastError();
return record;
}
if (primaryIndex.isEmpty()) {
record = rec;
for (int i = 0; i < record.count(); ++i)
record.setValue(i, query.value(i));
} else {
record = primaryIndex;
for (int i = 0; i < record.count(); ++i)
record.setValue(i, query.value(rec.indexOf(record.fieldName(i))));
}
return record;
Q_Q(const QSqlTableModel);
if (cache.value(row).op() == Insert)
return QSqlRecord();
QSqlRecord values(primaryIndex.isEmpty() ? rec : primaryIndex);
for (int i = 0; i < values.count(); ++i)
values.setValue(i, q->QSqlQueryModel::data(createIndex(row, rec.indexOf(values.fieldName(i))), Qt::EditRole));
return values;
}
/*!
@ -510,7 +505,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(indexInQuery(index).row()));
d->primaryValues(index.row()));
}
row.setValue(index.column(), value);
@ -1016,7 +1011,7 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
} else {
d->cache[idx] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete,
QSqlRecord(),
d->primaryValues(indexInQuery(createIndex(idx, 0)).row()));
d->primaryValues(idx));
if (d->strategy == OnManualSubmit)
emit headerDataChanged(Qt::Vertical, idx, idx);
}
@ -1233,7 +1228,7 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record)
if (mrow.op() == QSqlTableModelPrivate::None)
mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update,
d->rec,
d->primaryValues(indexInQuery(createIndex(row, 0)).row()));
d->primaryValues(row));
Map::const_iterator i = map.constBegin();
const Map::const_iterator e = map.constEnd();