diff options
author | Dan Cape <dcape@qnx.com> | 2015-08-25 13:34:43 -0400 |
---|---|---|
committer | Dan Cape <dcape@qnx.com> | 2015-09-09 12:52:05 +0000 |
commit | 49c359dd88f962ec04cc7ede8cfa4ae2173e55f7 (patch) | |
tree | c7f5570b55c4885af3cf3c774624b705acaa7ec2 /src/qml/qml | |
parent | 68607aeeeb6ba84b843a0e3d848a5438a36f55a7 (diff) |
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 <michael.brasser@live.com>
Diffstat (limited to 'src/qml/qml')
-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 |
3 files changed, 22 insertions, 2 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 |