From 49c359dd88f962ec04cc7ede8cfa4ae2173e55f7 Mon Sep 17 00:00:00 2001 From: Dan Cape Date: Tue, 25 Aug 2015 13:34:43 -0400 Subject: Add enabled property to the QML Connections element Now allows a quick way to enable/disable the signal handlers in the QML Connections element. Updated test file to have objectName and added test for this new functionality. Set to be available as of QtQml2.3. [ChangeLog][QML Elements] Allow enabling/disabling of connections established using a Connections element Change-Id: Ib0de2b3c78bb529ef74d5b4bb4ccb0f335cc50de Task-number: QTBUG-36350 Reviewed-by: Michael Brasser --- .../qml/qqmlconnections/data/test-connection.qml | 2 +- .../qml/qqmlconnections/tst_qqmlconnections.cpp | 28 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'tests/auto/qml/qqmlconnections') diff --git a/tests/auto/qml/qqmlconnections/data/test-connection.qml b/tests/auto/qml/qqmlconnections/data/test-connection.qml index ce851fc3db..f44cbc047f 100644 --- a/tests/auto/qml/qqmlconnections/data/test-connection.qml +++ b/tests/auto/qml/qqmlconnections/data/test-connection.qml @@ -6,5 +6,5 @@ Item { property bool tested: false signal testMe - Connections { target: screen; onWidthChanged: screen.tested = true } + Connections { objectName: "connections"; target: screen; onWidthChanged: screen.tested = true } } diff --git a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp index e529c74acc..b148baab35 100644 --- a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp +++ b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp @@ -56,6 +56,7 @@ private slots: void errors(); void rewriteErrors(); void singletonTypeTarget(); + void enableDisable_QTBUG_36350(); private: QQmlEngine engine; @@ -329,6 +330,33 @@ void tst_qqmlconnections::singletonTypeTarget() delete object; } +void tst_qqmlconnections::enableDisable_QTBUG_36350() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("test-connection.qml")); + QQuickItem *item = qobject_cast(c.create()); + QVERIFY(item != 0); + + QQmlConnections *connections = item->findChild("connections"); + QVERIFY(connections); + + connections->setEnabled(false); + QCOMPARE(item->property("tested").toBool(), false); + QCOMPARE(item->width(), 50.); + emit item->setWidth(100.); + QCOMPARE(item->width(), 100.); + QCOMPARE(item->property("tested").toBool(), false); //Should not have received signal to change property + + connections->setEnabled(true); //Re-enable the connectSignals() + QCOMPARE(item->property("tested").toBool(), false); + QCOMPARE(item->width(), 100.); + emit item->setWidth(50.); + QCOMPARE(item->width(), 50.); + QCOMPARE(item->property("tested").toBool(), true); //Should have received signal to change property + + delete item; +} + QTEST_MAIN(tst_qqmlconnections) #include "tst_qqmlconnections.moc" -- cgit v1.2.3