reduce cost of checking cache for data() and headerData()
Assume requested row is usually not cached. Change-Id: I7727b431cc3841528aa6390400b93b1218773e65 Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
This commit is contained in:
parent
e5c8927fe8
commit
60f24ec608
@ -382,6 +382,8 @@ QVariant QSqlTableModel::data(const QModelIndex &index, int role) const
|
||||
// and indexInQuery is not virtual (grrr) so any values we pass to QSQM need
|
||||
// to handle the insertedRows
|
||||
QModelIndex item = indexInQuery(index);
|
||||
|
||||
if (d->cache.contains(index.row())) {
|
||||
const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row());
|
||||
|
||||
switch (d->strategy) {
|
||||
@ -403,6 +405,7 @@ QVariant QSqlTableModel::data(const QModelIndex &index, int role) const
|
||||
return row.rec.value(item.column());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// We need to handle row mapping here, but not column mapping
|
||||
return QSqlQueryModel::data(index.sibling(item.row(), index.column()), role);
|
||||
@ -415,12 +418,14 @@ QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, in
|
||||
{
|
||||
Q_D(const QSqlTableModel);
|
||||
if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
|
||||
if (d->cache.contains(section)) {
|
||||
const QSqlTableModelPrivate::Op op = d->cache.value(section).op;
|
||||
if (op == QSqlTableModelPrivate::Insert)
|
||||
return QLatin1String("*");
|
||||
else if (op == QSqlTableModelPrivate::Delete)
|
||||
return QLatin1String("!");
|
||||
}
|
||||
}
|
||||
return QSqlQueryModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user