case QSqlTableModelPrivate::Insert:
if (!insertRowIntoTable(it.value().rec()))
return false;
- d->bottom = d->bottom.sibling(d->bottom.row() + 1, d->bottom.column());
break;
case QSqlTableModelPrivate::Update:
if (!updateRowInTable(it.key(), it.value().rec()))
break;
}
}
+
+ // all changes have been committed
+
+ // clean up inserted rows
+ QSqlTableModelPrivate::CacheMap::Iterator it = d->cache.end();
+ while (it != d->cache.constBegin()) {
+ --it;
+ if (it.value().op() == QSqlTableModelPrivate::Insert) {
+ beginRemoveRows(QModelIndex(), it.key(), it.key());
+ it = d->cache.erase(it);
+ endRemoveRows();
+ }
+ }
d->clearCache();
return select();
}
model.submitAll(); // submitAll() calls select() which clears and repopulates the table
int firstRowIndex = 0, lastRowIndex = 12;
- QCOMPARE(spyRowsRemoved.count(), 1);
- QCOMPARE(spyRowsRemoved.at(0).at(1).toInt(), firstRowIndex);
- QCOMPARE(spyRowsRemoved.at(0).at(2).toInt(), lastRowIndex);
+ QCOMPARE(spyRowsRemoved.count(), 11);
+ // QSqlTableModel emits 10 signals for its 10 inserted rows
+ QCOMPARE(spyRowsRemoved.at(0).at(1).toInt(), lastRowIndex);
+ QCOMPARE(spyRowsRemoved.at(9).at(1).toInt(), firstRowIndex + 3);
+ // QSqlQueryModel emits 1 signal for its 3 rows
+ QCOMPARE(spyRowsRemoved.at(10).at(1).toInt(), firstRowIndex);
+ QCOMPARE(spyRowsRemoved.at(10).at(2).toInt(), firstRowIndex + 2);
QCOMPARE(spyRowsInserted.at(10).at(1).toInt(), firstRowIndex);
QCOMPARE(spyRowsInserted.at(10).at(2).toInt(), lastRowIndex);