diff options
-rw-r--r-- | src/qml/qml/qqmlboundsignal.cpp | 19 | ||||
-rw-r--r-- | src/qml/qml/qqmlboundsignal_p.h | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 1 | ||||
-rw-r--r-- | src/qml/types/qqmlconnections.cpp | 31 | ||||
-rw-r--r-- | src/qml/types/qqmlconnections_p.h | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlconnections/data/test-connection.qml | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp | 28 |
7 files changed, 86 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index 3d1a9f8a88..f88e844529 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -250,7 +250,7 @@ QQmlBoundSignal::QQmlBoundSignal(QObject *target, int signal, QObject *owner, QQmlEngine *engine) : QQmlNotifierEndpoint(QQmlNotifierEndpoint::QQmlBoundSignal), m_prevSignal(0), m_nextSignal(0), - m_expression(0) + m_enabled(true), m_expression(0) { addToObject(owner); @@ -313,11 +313,26 @@ void QQmlBoundSignal::takeExpression(QQmlBoundSignalExpression *e) m_expression->setNotifyOnValueChanged(false); } +/*! + This property holds whether the item will emit signals. + + The QQmlBoundSignal callback will only emit a signal if this property is set to true. + + By default, this property is true. + */ +void QQmlBoundSignal::setEnabled(bool enabled) +{ + if (m_enabled == enabled) + return; + + m_enabled = enabled; +} + void QQmlBoundSignal_callback(QQmlNotifierEndpoint *e, void **a) { QQmlBoundSignal *s = static_cast<QQmlBoundSignal*>(e); - if (!s->m_expression) + if (!s->m_expression || !s->m_enabled) return; QV4DebugService *service = QQmlDebugConnector::service<QV4DebugService>(); diff --git a/src/qml/qml/qqmlboundsignal_p.h b/src/qml/qml/qqmlboundsignal_p.h index 3742317484..ef8fdd4a1a 100644 --- a/src/qml/qml/qqmlboundsignal_p.h +++ b/src/qml/qml/qqmlboundsignal_p.h @@ -108,6 +108,8 @@ public: QQmlBoundSignalExpression *expression() const; void takeExpression(QQmlBoundSignalExpression *); + void setEnabled(bool enabled); + private: friend void QQmlBoundSignal_callback(QQmlNotifierEndpoint *, void **); friend class QQmlPropertyPrivate; @@ -119,6 +121,8 @@ private: QQmlBoundSignal **m_prevSignal; QQmlBoundSignal *m_nextSignal; + bool m_enabled; + QQmlBoundSignalExpressionPointer m_expression; }; diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 9c5e48ae32..47cd36b8f6 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -176,6 +176,7 @@ void QQmlEnginePrivate::registerBaseTypes(const char *uri, int versionMajor, int qmlRegisterType<QQmlComponent>(uri,versionMajor,versionMinor,"Component"); qmlRegisterType<QObject>(uri,versionMajor,versionMinor,"QtObject"); qmlRegisterType<QQmlBind>(uri, versionMajor, versionMinor,"Binding"); + qmlRegisterType<QQmlConnections,1>(uri, versionMajor, (versionMinor < 3 ? 3 : versionMinor), "Connections"); //Only available in >=2.3 qmlRegisterType<QQmlConnections>(uri, versionMajor, versionMinor,"Connections"); qmlRegisterType<QQmlTimer>(uri, versionMajor, versionMinor,"Timer"); qmlRegisterType<QQmlInstantiator>(uri, versionMajor, (versionMinor < 1 ? 1 : versionMinor), "Instantiator"); //Only available in >=2.1 diff --git a/src/qml/types/qqmlconnections.cpp b/src/qml/types/qqmlconnections.cpp index 6a93410ecb..5f69bf5f94 100644 --- a/src/qml/types/qqmlconnections.cpp +++ b/src/qml/types/qqmlconnections.cpp @@ -51,11 +51,12 @@ QT_BEGIN_NAMESPACE class QQmlConnectionsPrivate : public QObjectPrivate { public: - QQmlConnectionsPrivate() : target(0), targetSet(false), ignoreUnknownSignals(false), componentcomplete(true) {} + QQmlConnectionsPrivate() : target(0), enabled(true), targetSet(false), ignoreUnknownSignals(false), componentcomplete(true) {} QList<QQmlBoundSignal*> boundsignals; QObject *target; + bool enabled; bool targetSet; bool ignoreUnknownSignals; bool componentcomplete; @@ -177,6 +178,34 @@ void QQmlConnections::setTarget(QObject *obj) } /*! + \qmlproperty bool QtQml::Connections::enabled + \since 5.7 + + This property holds whether the item accepts change events. + + By default, this property is \c true. +*/ +bool QQmlConnections::isEnabled() const +{ + Q_D(const QQmlConnections); + return d->enabled; +} + +void QQmlConnections::setEnabled(bool enabled) +{ + Q_D(QQmlConnections); + if (d->enabled == enabled) + return; + + d->enabled = enabled; + + foreach (QQmlBoundSignal *s, d->boundsignals) + s->setEnabled(d->enabled); + + emit enabledChanged(); +} + +/*! \qmlproperty bool QtQml::Connections::ignoreUnknownSignals Normally, a connection to a non-existent signal produces runtime errors. diff --git a/src/qml/types/qqmlconnections_p.h b/src/qml/types/qqmlconnections_p.h index 170f47b54f..e9eb593c6b 100644 --- a/src/qml/types/qqmlconnections_p.h +++ b/src/qml/types/qqmlconnections_p.h @@ -52,6 +52,7 @@ class Q_AUTOTEST_EXPORT QQmlConnections : public QObject, public QQmlParserStatu Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) + Q_REVISION(1) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool ignoreUnknownSignals READ ignoreUnknownSignals WRITE setIgnoreUnknownSignals) public: @@ -61,11 +62,15 @@ public: QObject *target() const; void setTarget(QObject *); + bool isEnabled() const; + void setEnabled(bool enabled); + bool ignoreUnknownSignals() const; void setIgnoreUnknownSignals(bool ignore); Q_SIGNALS: void targetChanged(); + Q_REVISION(1) void enabledChanged(); private: void connectSignals(); 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<QQuickItem*>(c.create()); + QVERIFY(item != 0); + + QQmlConnections *connections = item->findChild<QQmlConnections*>("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" |