summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-07-09 09:56:56 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-13 01:51:44 +0200
commit536ec793b69c16611e73cff4360c6f49b644f740 (patch)
treebe2a36264a4cb22a131944e10918bdc089ae24e2 /tests/auto/corelib/itemmodels
parent0efa445141ce3d7243f28e7b6da730d8dec17e23 (diff)
Make it possible to use new syntax to connect to model signals.
The private signals can not be used as function pointers, as required by the new syntax, so we introduce a parameter which can only be created privately. Change-Id: I3d7bb8a163e764d685e8007cba831fb77e3c6855 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib/itemmodels')
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index 7d052b225b..999335a8ef 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -118,6 +118,8 @@ private slots:
void testRoleNames();
void testDragActions();
+ void testFunctionPointerSignalConnection();
+
private:
DynamicTreeModel *m_model;
};
@@ -2177,5 +2179,110 @@ void tst_QAbstractItemModel::testDragActions()
QVERIFY(actions & Qt::MoveAction);
}
+class SignalConnectionTester : public QObject
+{
+ Q_OBJECT
+public:
+ SignalConnectionTester(QObject *parent = 0)
+ : QObject(parent), testPassed(false)
+ {
+
+ }
+
+public Q_SLOTS:
+ void testSlot()
+ {
+ testPassed = true;
+ }
+ void testSlotWithParam_1(const QModelIndex &idx)
+ {
+ testPassed = !idx.isValid();
+ }
+ void testSlotWithParam_2(const QModelIndex &idx, int start)
+ {
+ testPassed = !idx.isValid() && start == 0;
+ }
+ void testSlotWithParam_3(const QModelIndex &idx, int start, int end)
+ {
+ testPassed = !idx.isValid() && start == 0 && end == 1;
+ }
+
+public:
+ bool testPassed;
+};
+
+void tst_QAbstractItemModel::testFunctionPointerSignalConnection()
+{
+ QStringListModel model;
+ {
+ SignalConnectionTester tester;
+ QObject::connect(&model, &QAbstractItemModel::rowsInserted, &tester, &SignalConnectionTester::testSlot);
+
+ QVERIFY(!tester.testPassed);
+
+ model.insertRows(0, 2);
+
+ QVERIFY(tester.testPassed);
+ tester.testPassed = false;
+ QMetaObject::invokeMethod(&model, "rowsInserted", Q_ARG(QModelIndex, QModelIndex()), Q_ARG(int, 0), Q_ARG(int, 1));
+ QVERIFY(tester.testPassed);
+ }
+ {
+ SignalConnectionTester tester;
+ QObject::connect(&model, &QAbstractItemModel::rowsInserted, &tester, &SignalConnectionTester::testSlotWithParam_1);
+
+ QVERIFY(!tester.testPassed);
+
+ model.insertRows(0, 2);
+
+ QVERIFY(tester.testPassed);
+ tester.testPassed = false;
+ QMetaObject::invokeMethod(&model, "rowsInserted", Q_ARG(QModelIndex, QModelIndex()), Q_ARG(int, 0), Q_ARG(int, 1));
+ QVERIFY(tester.testPassed);
+ }
+ {
+ SignalConnectionTester tester;
+ QObject::connect(&model, &QAbstractItemModel::rowsInserted, &tester, &SignalConnectionTester::testSlotWithParam_2);
+
+ QVERIFY(!tester.testPassed);
+
+ model.insertRows(0, 2);
+
+ QVERIFY(tester.testPassed);
+ tester.testPassed = false;
+ QMetaObject::invokeMethod(&model, "rowsInserted", Q_ARG(QModelIndex, QModelIndex()), Q_ARG(int, 0), Q_ARG(int, 1));
+ QVERIFY(tester.testPassed);
+ }
+ {
+ SignalConnectionTester tester;
+ QObject::connect(&model, &QAbstractItemModel::rowsInserted, &tester, &SignalConnectionTester::testSlotWithParam_3);
+
+ QVERIFY(!tester.testPassed);
+
+ model.insertRows(0, 2);
+
+ QVERIFY(tester.testPassed);
+ tester.testPassed = false;
+ QMetaObject::invokeMethod(&model, "rowsInserted", Q_ARG(QModelIndex, QModelIndex()), Q_ARG(int, 0), Q_ARG(int, 1));
+ QVERIFY(tester.testPassed);
+ }
+ {
+ SignalConnectionTester tester;
+ QObject::connect(&model, SIGNAL(rowsInserted(QModelIndex,int,int)), &tester, SLOT(testSlot()));
+
+ QVERIFY(!tester.testPassed);
+
+ model.insertRows(0, 2);
+
+ QVERIFY(tester.testPassed);
+ tester.testPassed = false;
+ QMetaObject::invokeMethod(&model, "rowsInserted", Q_ARG(QModelIndex, QModelIndex()), Q_ARG(int, 0), Q_ARG(int, 1));
+ QVERIFY(tester.testPassed);
+ }
+ // Intentionally does not compile.
+// model.rowsInserted(QModelIndex(), 0, 0);
+}
+
+
QTEST_MAIN(tst_QAbstractItemModel)
#include "tst_qabstractitemmodel.moc"