summaryrefslogtreecommitdiffstats
path: root/src/sql/models
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2012-03-15 11:23:27 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-15 15:35:43 +0100
commit26450fe6a6340b09b1e3fa49c35028aa15ef223f (patch)
tree3c39e9d1aebb649953e6a758c0820702083e502c /src/sql/models
parent108748404beb607538ea965a21fa932d275eecdd (diff)
QSqlTableModel::removeRows() enforce edit strategy
For OnFieldChange and OnRowChange, we don't want more than one row in the cache with uncommitted changes. This could happen if deletion in the database fails while other changes are pending. Chosen solution is to return false if other rows have pending changes. Also, we only allow 1 row removed at a time. Updated test, changes and documentation. Change-Id: I68baf6d221789b4754e891535070011c759a2155 Reviewed-by: Honglei Zhang <honglei.zhang@nokia.com>
Diffstat (limited to 'src/sql/models')
-rw-r--r--src/sql/models/qsqltablemodel.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index 153c2e80f9..d8d691fa0c 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -1021,11 +1021,18 @@ bool QSqlTableModel::removeColumns(int column, int count, const QModelIndex &par
an invalid model index.
When the edit strategy is OnManualSubmit, deletion of rows from
- the database is delayed until submitAll() is called; otherwise,
- deletions are immediate.
+ the database is delayed until submitAll() is called.
- Inserted but not yet submitted rows in the range to be removed
- are immediately removed from the model.
+ For OnFieldChange and OnRowChange, only one row may be deleted
+ at a time and only if no other row has a cached change. Deletions
+ are submitted immediately to the database. The model retains a
+ blank row for successfully deleted row until refreshed with select().
+
+ After failed deletion, the operation is not reverted in the model.
+ The application may resubmit or revert.
+
+ Inserted but not yet successfully submitted rows in the range to be
+ removed are immediately removed from the model.
Before a row is deleted from the database, the beforeDelete()
signal is emitted.
@@ -1047,6 +1054,10 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
else if (!count)
return true;
+ if (d->strategy != OnManualSubmit)
+ if (count > 1 || (d->cache.value(row).submitted() && isDirty()))
+ return false;
+
// Iterate backwards so we don't have to worry about removed rows causing
// higher cache entries to shift downwards.
for (int idx = row + count - 1; idx >= row; --idx) {