QSqlTableModel::data(): use cached values when available

Simplify logic. If the record is in the cache, even untouched
values should be there. This is also necessary for getting
the most up-to-date values between submitting and the next
select.

Change-Id: I8578d96229797ce9fb0d07fe456301358f2be071
Reviewed-by: Honglei Zhang <honglei.zhang@nokia.com>
This commit is contained in:
Mark Brand 2012-02-15 02:07:59 +01:00 committed by Qt by Nokia
parent e999ca25c6
commit ea6d1fde1b

View File

@ -402,29 +402,9 @@ QVariant QSqlTableModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::EditRole))
return QVariant();
if (d->cache.contains(index.row())) {
const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row());
switch (d->strategy) {
case OnFieldChange:
case OnRowChange:
if (row.op() == QSqlTableModelPrivate::Insert) {
if (index.column() < 0 || index.column() >= row.rec().count())
return QVariant();
return row.rec().value(index.column());
} else if (row.op() == QSqlTableModelPrivate::Update) {
if (row.rec().isGenerated(index.column()))
return row.rec().value(index.column());
}
break;
case OnManualSubmit:
if (row.op() == QSqlTableModelPrivate::Insert
|| (row.op() != QSqlTableModelPrivate::None
&& row.rec().isGenerated(index.column())))
return row.rec().value(index.column());
break;
}
}
const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row());
if (mrow.op() != QSqlTableModelPrivate::None)
return mrow.rec().value(index.column());
return QSqlQueryModel::data(index, role);
}