aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllistmodel
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-05-27 14:14:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-29 09:25:44 +0200
commit0306626a4deb8c36b219ba08a68248d3a454b697 (patch)
treec51fe9b5c7d8b89fdf1b105dc01f318a4da34b05 /tests/auto/qml/qqmllistmodel
parentb5cab0515bf316d60ec6dca25b699872d4daeb45 (diff)
Fix emission of QQmlListModel::rowsAboutToBeXxx() signals
Call beginInsertRows(), beginMoveRows() and beginRemoveRows() before the change to ensure that rowsAboutToBeInserted(), rowsAboutToBeMoved() and rowsAboutToBeRemoved() get emitted before the change as appropriate. NOTE: This patch solves the problem for the most common use case, when ListModel is used without WorkerScript. QQmlListModelWorkerAgent needs similar changes in order to fix the signals when ListModel is used with WorkerScript (QTBUG-39321). Task-number: QTBUG-39279 Change-Id: Idec5167d70b242f6f7d8b7cff008e130afc62505 Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'tests/auto/qml/qqmllistmodel')
-rw-r--r--tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
index 9b57eeffa9..b37f0e3d26 100644
--- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
+++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
@@ -132,6 +132,7 @@ private slots:
void empty_element_warning_data();
void datetime();
void datetime_data();
+ void about_to_be_signals();
};
bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object)
@@ -1306,6 +1307,134 @@ void tst_qqmllistmodel::datetime()
QVERIFY(expected == dtResult);
}
+class RowTester : public QObject
+{
+ Q_OBJECT
+public:
+ RowTester(QAbstractItemModel *model) : QObject(model), model(model)
+ {
+ reset();
+ connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), this, SLOT(rowsAboutToBeInserted()));
+ connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted()));
+ connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(rowsAboutToBeRemoved()));
+ connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved()));
+ connect(model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(rowsAboutToBeMoved()));
+ connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(rowsMoved()));
+ }
+
+ void reset()
+ {
+ rowsAboutToBeInsertedCalls = 0;
+ rowsAboutToBeInsertedCount = 0;
+ rowsInsertedCalls = 0;
+ rowsInsertedCount = 0;
+ rowsAboutToBeRemovedCalls = 0;
+ rowsAboutToBeRemovedCount = 0;
+ rowsRemovedCalls = 0;
+ rowsRemovedCount = 0;
+ rowsAboutToBeMovedCalls = 0;
+ rowsAboutToBeMovedData.clear();
+ rowsMovedCalls = 0;
+ rowsMovedData.clear();
+ }
+
+ int rowsAboutToBeInsertedCalls;
+ int rowsAboutToBeInsertedCount;
+ int rowsInsertedCalls;
+ int rowsInsertedCount;
+ int rowsAboutToBeRemovedCalls;
+ int rowsAboutToBeRemovedCount;
+ int rowsRemovedCalls;
+ int rowsRemovedCount;
+ int rowsAboutToBeMovedCalls;
+ QVariantList rowsAboutToBeMovedData;
+ int rowsMovedCalls;
+ QVariantList rowsMovedData;
+
+private slots:
+ void rowsAboutToBeInserted()
+ {
+ rowsAboutToBeInsertedCalls++;
+ rowsAboutToBeInsertedCount = model->rowCount();
+ }
+
+ void rowsInserted()
+ {
+ rowsInsertedCalls++;
+ rowsInsertedCount = model->rowCount();
+ }
+
+ void rowsAboutToBeRemoved()
+ {
+ rowsAboutToBeRemovedCalls++;
+ rowsAboutToBeRemovedCount = model->rowCount();
+ }
+
+ void rowsRemoved()
+ {
+ rowsRemovedCalls++;
+ rowsRemovedCount = model->rowCount();
+ }
+
+ void rowsAboutToBeMoved()
+ {
+ rowsAboutToBeMovedCalls++;
+ for (int i = 0; i < model->rowCount(); ++i)
+ rowsAboutToBeMovedData += model->data(model->index(i, 0), 0);
+ }
+
+ void rowsMoved()
+ {
+ rowsMovedCalls++;
+ for (int i = 0; i < model->rowCount(); ++i)
+ rowsMovedData += model->data(model->index(i, 0), 0);
+ }
+
+private:
+ QAbstractItemModel *model;
+};
+
+void tst_qqmllistmodel::about_to_be_signals()
+{
+ QQmlEngine engine;
+ QQmlListModel model;
+ QQmlEngine::setContextForObject(&model,engine.rootContext());
+
+ RowTester tester(&model);
+
+ QQmlExpression e1(engine.rootContext(), &model, "{append({'test':0})}");
+ e1.evaluate();
+
+ QCOMPARE(tester.rowsAboutToBeInsertedCalls, 1);
+ QCOMPARE(tester.rowsAboutToBeInsertedCount, 0);
+ QCOMPARE(tester.rowsInsertedCalls, 1);
+ QCOMPARE(tester.rowsInsertedCount, 1);
+
+ QQmlExpression e2(engine.rootContext(), &model, "{append({'test':1})}");
+ e2.evaluate();
+
+ QCOMPARE(tester.rowsAboutToBeInsertedCalls, 2);
+ QCOMPARE(tester.rowsAboutToBeInsertedCount, 1);
+ QCOMPARE(tester.rowsInsertedCalls, 2);
+ QCOMPARE(tester.rowsInsertedCount, 2);
+
+ QQmlExpression e3(engine.rootContext(), &model, "{move(0, 1, 1)}");
+ e3.evaluate();
+
+ QCOMPARE(tester.rowsAboutToBeMovedCalls, 1);
+ QCOMPARE(tester.rowsAboutToBeMovedData, QVariantList() << 0.0 << 1.0);
+ QCOMPARE(tester.rowsMovedCalls, 1);
+ QCOMPARE(tester.rowsMovedData, QVariantList() << 1.0 << 0.0);
+
+ QQmlExpression e4(engine.rootContext(), &model, "{remove(0, 2)}");
+ e4.evaluate();
+
+ QCOMPARE(tester.rowsAboutToBeRemovedCalls, 1);
+ QCOMPARE(tester.rowsAboutToBeRemovedCount, 2);
+ QCOMPARE(tester.rowsRemovedCalls, 1);
+ QCOMPARE(tester.rowsRemovedCount, 0);
+}
+
QTEST_MAIN(tst_qqmllistmodel)
#include "tst_qqmllistmodel.moc"