diff options
author | Mark Brand <mabrand@mabrand.nl> | 2012-09-28 10:10:29 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-05 03:16:19 +0200 |
commit | 10ff9de91bedf93852f13a58287afd8831644759 (patch) | |
tree | f26fa943dda21f1a4a4ee3d782e06867fefea6e6 /src/sql/models/qsqltablemodel.cpp | |
parent | 838eadba0b79eab32cdf9e5d04bc2ab3541731d1 (diff) |
QSqlTableModel: don't cache unchanged value in setData()
This is good for performance in terms of avoiding unnecessary
database activity and keeping the cache smaller.
Detail:
This change was not included in the big refactoring of QSqlTM. The
idea was that the model shouldn't second guess the intention of the
application and maybe the application wants to cause a submit.
It was a marginal consideration.
Now I think it's clear that our interest in not unnecessarily
expanding the cache outweighs that. In addition, applications can now
call selectRow() if they worry that the database values for the row
have changed and want to set a value back again.
Test added.
Change-Id: I63814dcb63a96c6ba1c8cc227807725a954a0b68
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/sql/models/qsqltablemodel.cpp')
-rw-r--r-- | src/sql/models/qsqltablemodel.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 56838a4e8f..b979a1a23a 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -542,6 +542,9 @@ bool QSqlTableModel::isDirty(const QModelIndex &index) const For OnRowChange, an index may receive a change only if no other row has a cached change. Changes are not submitted automatically. + Returns true if \a value is equal to the current value. However, + the value will not be submitted to the database. + Returns true if the value could be set or false on error, for example if \a index is out of bounds. @@ -562,6 +565,9 @@ bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, in if (!(flags(index) & Qt::ItemIsEditable)) return false; + if (QSqlTableModel::data(index, role) == value) + return true; + QSqlTableModelPrivate::ModifiedRow &row = d->cache[index.row()]; if (row.op() == QSqlTableModelPrivate::None) |