summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql/models/qsqltablemodel
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2012-04-23 01:06:17 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-23 19:20:19 +0200
commit83c9ebbd6692cde99ee692e6549c591100f12545 (patch)
treebc367b1ea99f3a8b679ce338b59b5f95f006585b /tests/auto/sql/models/qsqltablemodel
parent508a90302b5bd2a1b228c62d1a1b24a3e66d24a9 (diff)
QSqlQueryModel::setQuery() don't use deprecated reset()
Previously the method attempted to reset only as a last resort. Now reset() is deprecated and resetting must happen between emitting modelAboutToBeReset() and modelReset(). Since this suffices in all cases to notify views that they must reinterrogate the model, it is no longer necessary to signal explicitly row removals and insertions within the scope of the reset. Additionally, fetchMore() is now called within the scope of the reset so insert signals do not have to be emitted here either. This improved handling of resetting in QSqlQueryModel also allows the cache in QSqlTableModel to be cleared directly at select(). This change may actually allow views to operate more efficiently since they no longer have to react to separate row removal and insert signals. Views can avoid pointless deallocation and reallocation by considering row count only after the reset is finished. The cost is that the columns and horizontal headers must be considered in the view at each setQuery() call. In any case, it is not clear that trying to be smart about this in the model justifies additional complexity. Tests had to be adjusted where they expected explicit row removal and insert signals. Change-Id: I4f7eac1419824361d7d9bdcc6a87092b33e80d7a Task-Id: QTBUG-25419 Reviewed-by: Andy Shaw <andy.shaw@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Honglei Zhang <honglei.zhang@nokia.com>
Diffstat (limited to 'tests/auto/sql/models/qsqltablemodel')
-rw-r--r--tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp52
1 files changed, 9 insertions, 43 deletions
diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
index 2cea8b3546..89085df6c9 100644
--- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -1338,39 +1338,13 @@ void tst_QSqlTableModel::setFilter()
QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
- QSignalSpy rowsRemovedSpy(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)));
- QSignalSpy rowsAboutToBeRemovedSpy(&model,
- SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)));
- QSignalSpy rowsInsertedSpy(&model, SIGNAL(rowsInserted(QModelIndex,int,int)));
- QSignalSpy rowsAboutToBeInsertedSpy(&model,
- SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)));
+ QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset()));
+ QSignalSpy modelResetSpy(&model, SIGNAL(modelReset()));
model.setFilter("id = 2");
// check the signals
- QCOMPARE(rowsAboutToBeRemovedSpy.count(), 1);
- QCOMPARE(rowsRemovedSpy.count(), 1);
- QCOMPARE(rowsAboutToBeInsertedSpy.count(), 1);
- QCOMPARE(rowsInsertedSpy.count(), 1);
- QList<QVariant> args = rowsAboutToBeRemovedSpy.takeFirst();
- QCOMPARE(args.count(), 3);
- QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), QModelIndex());
- QCOMPARE(args.at(1).toInt(), 0);
- QCOMPARE(args.at(2).toInt(), 0);
- args = rowsRemovedSpy.takeFirst();
- QCOMPARE(args.count(), 3);
- QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), QModelIndex());
- QCOMPARE(args.at(1).toInt(), 0);
- QCOMPARE(args.at(2).toInt(), 0);
- args = rowsInsertedSpy.takeFirst();
- QCOMPARE(args.count(), 3);
- QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), QModelIndex());
- QCOMPARE(args.at(1).toInt(), 0);
- QCOMPARE(args.at(2).toInt(), 0);
- args = rowsAboutToBeInsertedSpy.takeFirst();
- QCOMPARE(args.count(), 3);
- QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), QModelIndex());
- QCOMPARE(args.at(1).toInt(), 0);
- QCOMPARE(args.at(2).toInt(), 0);
+ QCOMPARE(modelAboutToBeResetSpy.count(), 1);
+ QCOMPARE(modelResetSpy.count(), 1);
QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.data(model.index(0, 0)).toInt(), 2);
@@ -1500,7 +1474,8 @@ void tst_QSqlTableModel::insertRecordsInLoop()
record.setValue(1, "Testman");
record.setValue(2, 1);
- QSignalSpy spyRowsRemoved(&model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)));
+ QSignalSpy modelAboutToBeResetSpy(&model, SIGNAL(modelAboutToBeReset()));
+ QSignalSpy modelResetSpy(&model, SIGNAL(modelReset()));
QSignalSpy spyRowsInserted(&model, SIGNAL(rowsInserted(const QModelIndex &, int, int)));
for (int i = 0; i < 10; i++) {
QVERIFY(model.insertRecord(model.rowCount(), record));
@@ -1509,18 +1484,9 @@ void tst_QSqlTableModel::insertRecordsInLoop()
}
model.submitAll(); // submitAll() calls select() which clears and repopulates the table
- int firstRowIndex = 0, lastRowIndex = 12;
- 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);
- QCOMPARE(spyRowsInserted.count(), 11);
+ // model emits reset signals
+ QCOMPARE(modelAboutToBeResetSpy.count(), 1);
+ QCOMPARE(modelResetSpy.count(), 1);
QCOMPARE(model.rowCount(), 13);
QCOMPARE(model.columnCount(), 3);