summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql/models/qsqlquerymodel
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2012-08-29 09:34:41 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-30 13:51:22 +0200
commitc194b7f3454f470d24be729ef660c5cfe7a9b841 (patch)
tree467b19df91b6a463ea8064c5e92a0bf07189500b /tests/auto/sql/models/qsqlquerymodel
parent98c663acd955ed7f0afcaffc50e738690fbb94ae (diff)
QSqlQueryModel: fix nested beginResetModel/endResetModel
Follow-up to 83c9ebbd6692cde99ee692e6549c591100f12545. Consider the case where calls to the reset methods on the same object are nested as in the following sequence: 1. beginResetModel() 2. beginResetModel() 3. endResetModel() 4. endResetModel() In such cases, only the outermost calls, i.e., 1) and 4), should emit signals. After 83c9ebbd6692cde99ee692e6549c591100f12545, 1) and 3) emitted the signals, which is wrong. This is corrected by keeping track of the nesting level. Such sequences can come about when a base class calls the begin/end methods between the calls made by the subclass. QSqlTableModel::select() is an example of this. Test included. Change-Id: Ia62b45cb1abaab00a32bb8357de4a958bcff83e5 Reviewed-by: Andy Shaw <andy.shaw@digia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/sql/models/qsqlquerymodel')
-rw-r--r--tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
index 1c1319630e..582a76b119 100644
--- a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
+++ b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
@@ -91,6 +91,8 @@ private slots:
void setQuerySignalEmission();
void setQueryWithNoRowsInResultSet_data() { generic_data(); }
void setQueryWithNoRowsInResultSet();
+ void nestedResets_data() { generic_data(); }
+ void nestedResets();
void task_180617();
void task_180617_data() { generic_data(); }
@@ -585,6 +587,61 @@ void tst_QSqlQueryModel::setQueryWithNoRowsInResultSet()
QCOMPARE(modelRowsInsertedSpy.count(), 0);
}
+class NestedResetsTest: public QSqlQueryModel
+{
+ Q_OBJECT
+
+public:
+ NestedResetsTest(QObject* parent = 0) : QSqlQueryModel(parent), gotAboutToBeReset(false), gotReset(false)
+ {
+ connect(this, SIGNAL(modelAboutToBeReset()), this, SLOT(modelAboutToBeResetSlot()));
+ connect(this, SIGNAL(modelReset()), this, SLOT(modelResetSlot()));
+ }
+
+ void testme()
+ {
+ // Only the outermost beginResetModel/endResetModel should
+ // emit signals.
+ gotAboutToBeReset = gotReset = false;
+ beginResetModel();
+ QCOMPARE(gotAboutToBeReset, true);
+ QCOMPARE(gotReset, false);
+
+ gotAboutToBeReset = gotReset = false;
+ beginResetModel();
+ QCOMPARE(gotAboutToBeReset, false);
+ QCOMPARE(gotReset, false);
+
+ gotAboutToBeReset = gotReset = false;
+ endResetModel();
+ QCOMPARE(gotAboutToBeReset, false);
+ QCOMPARE(gotReset, false);
+
+ gotAboutToBeReset = gotReset = false;
+ endResetModel();
+ QCOMPARE(gotAboutToBeReset, false);
+ QCOMPARE(gotReset, true);
+ }
+
+private slots:
+ void modelAboutToBeResetSlot() { gotAboutToBeReset = true; }
+ void modelResetSlot() { gotReset = true; }
+
+private:
+ bool gotAboutToBeReset;
+ bool gotReset;
+};
+
+void tst_QSqlQueryModel::nestedResets()
+{
+ QFETCH(QString, dbName);
+ QSqlDatabase db = QSqlDatabase::database(dbName);
+ CHECK_DATABASE(db);
+
+ NestedResetsTest t;
+ t.testme();
+}
+
// For task 180617
// According to the task, several specific duplicate SQL queries would cause
// multiple empty grid lines to be visible in the view