diff options
author | Mark Brand <mabrand@mabrand.nl> | 2012-02-28 22:42:02 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-12 23:29:37 +0100 |
commit | 13c57d0f68cffb139311e8e22a074099eb28a88f (patch) | |
tree | 86dfdd944e28e5db1ecab12131baabf7f08f1391 /src | |
parent | 612040a0cd702e4c764e5cbb5d0c091497650c6a (diff) |
QSqlTableModel::isDirty(): new overloaded method
Checks if model has any changes to submit.
Includes new test covering isDirty(index) as well the new
overloaded function.
Task-number: QTBUG-3108
Change-Id: I0ccbda45d5d9f06434cf1e1c037a9efb76d0cc37
Reviewed-by: Honglei Zhang <honglei.zhang@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/sql/models/qsqltablemodel.cpp | 18 | ||||
-rw-r--r-- | src/sql/models/qsqltablemodel.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 5fed167070..30e01b06e7 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -469,6 +469,24 @@ QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, in } /*! + \overload + \since 5.0 + + Returns true if the model contains modified values that have not been + committed to the datase, otherwise false. +*/ +bool QSqlTableModel::isDirty() const +{ + Q_D(const QSqlTableModel); + QSqlTableModelPrivate::CacheMap::ConstIterator i = d->cache.constBegin(); + const QSqlTableModelPrivate::CacheMap::ConstIterator e = d->cache.constEnd(); + for (; i != e; i++) + if (!i.value().submitted()) + return true; + return false; +} + +/*! Returns true if the value at the index \a index is dirty, otherwise false. Dirty values are values that were modified in the model but not yet written into the database. diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h index 13316bc4ed..62e09869c9 100644 --- a/src/sql/models/qsqltablemodel.h +++ b/src/sql/models/qsqltablemodel.h @@ -79,7 +79,9 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + bool isDirty() const; bool isDirty(const QModelIndex &index) const; + void clear(); virtual void setEditStrategy(EditStrategy strategy); |