before doing anything. Previously, it would remove what it could and
ignore the rest of the range.
+* removeRows(), for OnFieldChange and OnRowChange, allows only 1 row to be
+removed and only if there are no other changed rows.
+
* setRecord() and insertRecord()
-Only use fields where generated flag is set to true. This is
is consistent with the meaning of the flag.
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.
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) {
QCOMPARE(model.data(model.index(1, 1)).toString(), QString("blah"));
QFAIL_SQL(model, insertRow(2));
QCOMPARE(model.rowCount(), 2);
+ QFAIL_SQL(model, removeRow(1));
+ QCOMPARE(model.rowCount(), 2);
} else {
QVERIFY_SQL(model, setData(model.index(1, 1), QString("eggs")));
QCOMPARE(model.data(model.index(1, 1)).toString(), QString("eggs"));
QCOMPARE(model.data(model.index(1, 1)).toString(), QString("spam"));
QVERIFY_SQL(model, insertRow(2));
QCOMPARE(model.rowCount(), 3);
+ QVERIFY_SQL(model, removeRow(1));
+ QCOMPARE(model.rowCount(), 3);
}
// restore empty table
QVERIFY(!model.removeRows(1, 0)); // zero count
QVERIFY(!model.removeRows(5, 1)); // past end (DOESN'T causes a beforeDelete to be emitted)
QVERIFY(!model.removeRows(1, 0, model.index(2, 0))); // can't pass a valid modelindex
+ QFAIL_SQL(model, removeRows(0, 2)); // more than 1 row on OnFieldChange
- QVERIFY_SQL(model, removeRows(0, 2));
+ QVERIFY_SQL(model, removeRows(0, 1));
+ QVERIFY_SQL(model, removeRows(1, 1));
QCOMPARE(beforeDeleteSpy.count(), 2);
QVERIFY(beforeDeleteSpy.at(0).at(0).toInt() == 0);
QVERIFY(beforeDeleteSpy.at(1).at(0).toInt() == 1);
QFAIL_SQL(model, setData(model.index(1, 1), QString("sam i am")));
QFAIL_SQL(model, setRecord(1, model.record(1)));
QFAIL_SQL(model, insertRow(1));
+ QFAIL_SQL(model, removeRow(1));
QFAIL_SQL(model, isDirty(model.index(1, 1)));
model.revertAll();