summaryrefslogtreecommitdiffstats
path: root/src/sql/models/qsqltablemodel.cpp
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2012-02-06 17:19:19 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-07 22:05:51 +0100
commit269ef14215d3c3f89fe6239879a5db111dc1a7b4 (patch)
tree0825c2a4ba8d39b8d12b40f933147e44365e8135 /src/sql/models/qsqltablemodel.cpp
parentf5e1da12f0e7bdeee4db74acc52dfabeb12a4e31 (diff)
QSqlTableModel::removeRows(): require valid full range of rows
If an invalid range of rows is specified, it's likely to be a programming or user error. The old behavior of ignoring out of range rows seems dangerous and complicates the code. Also implement the documented behavior of returning false if changes are unsuccessful for OnFieldChange and OnRowChange. Previously the return value of submit() was ignored. Updated and improved documentation. Change-Id: Iaaf51c6d9a0c8c06fd5d186b4b88358fbeab9936 Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'src/sql/models/qsqltablemodel.cpp')
-rw-r--r--src/sql/models/qsqltablemodel.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index 4094052f1a..df48115af3 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -974,13 +974,20 @@ bool QSqlTableModel::removeColumns(int column, int count, const QModelIndex &par
does not support hierarchical structures, \a parent must be
an invalid model index.
- Emits the beforeDelete() signal before a row is deleted. When
- the edit strategy is OnManualSubmit signal emission is delayed
- until submitAll() is called.
+ When the edit strategy is OnManualSubmit, deletion of rows from
+ the database is delayed until submitAll() is called; otherwise,
+ deletions are immediate.
- Returns true if all rows could be removed; otherwise returns
- false. Detailed error information can be retrieved using
- lastError().
+ Inserted but not yet 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.
+
+ If row < 0 or row + count > rowCount(), no action is taken and
+ false is returned. Returns true if all rows could be removed;
+ otherwise returns false. Detailed database error information
+ can be retrieved using lastError().
\sa removeColumns(), insertRows()
*/
@@ -989,9 +996,12 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
Q_D(QSqlTableModel);
if (parent.isValid() || row < 0 || count <= 0)
return false;
+ else if (row + count > rowCount())
+ return false;
+ else if (!count)
+ return true;
- int i;
- for (i = 0; i < count && row + i < rowCount(); ++i) {
+ for (int i = 0; i < count; ++i) {
int idx = row + i;
if (d->cache.value(idx).op() == QSqlTableModelPrivate::Insert) {
revertRow(idx);
@@ -1007,11 +1017,8 @@ bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
}
}
- if (d->strategy != OnManualSubmit && i > 0)
- submit();
-
- if (i < count)
- return false;
+ if (d->strategy != OnManualSubmit)
+ return submit();
return true;
}