diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2012-03-23 09:32:45 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-27 06:54:34 +0200 |
commit | ec7deb3d123bb44b5d57590615a60ed48b1d2860 (patch) | |
tree | 4b6e98a85cc2fece6ad3cad29090a1294e94cd55 /src/qml/qml/qqmlboundsignal.cpp | |
parent | f931ec39513854e56560fe85d55a5d144e22af88 (diff) |
Add QQmlBoundSignalNoParamsqt-v5.0.0-alpha1
This class is used for signal handlers with no parameters, and is more
lightweight than QQmlBoundSignal.
Change-Id: Ie63eb989d334906657fd16fe35386df198654c28
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlboundsignal.cpp')
-rw-r--r-- | src/qml/qml/qqmlboundsignal.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index d666d9ceb0..b375a70d50 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -300,6 +300,71 @@ int QQmlBoundSignalParameters::metaCall(QMetaObject::Call c, int id, void **a) } } +//////////////////////////////////////////////////////////////////////// + +QQmlBoundSignalNoParams::QQmlBoundSignalNoParams(QObject *scope, const QMetaMethod &signal, + QObject *owner) +: m_expression(0), m_owner(owner), m_index(signal.methodIndex()), m_isEvaluating(false) +{ + callback = &subscriptionCallback; + QQmlNotifierEndpoint::connect(scope, m_index); +} + +QQmlBoundSignalNoParams::~QQmlBoundSignalNoParams() +{ + delete m_expression; + m_expression = 0; +} + +int QQmlBoundSignalNoParams::index() const +{ + return m_index; +} + +/*! + Returns the signal expression. +*/ +QQmlExpression *QQmlBoundSignalNoParams::expression() const +{ + return m_expression; +} + +/*! + Sets the signal expression to \a e. Returns the current signal expression, + or null if there is no signal expression. + + The QQmlBoundSignalNoParams instance takes ownership of \a e. The caller is + assumes ownership of the returned QQmlExpression. +*/ +QQmlExpression *QQmlBoundSignalNoParams::setExpression(QQmlExpression *e) +{ + QQmlExpression *rv = m_expression; + m_expression = e; + if (m_expression) m_expression->setNotifyOnValueChanged(false); + return rv; +} + +void QQmlBoundSignalNoParams::subscriptionCallback(QQmlNotifierEndpoint *e) +{ + QQmlBoundSignalNoParams *s = static_cast<QQmlBoundSignalNoParams*>(e); + if (!s->m_expression) + return; + + if (QQmlDebugService::isDebuggingEnabled()) + QV8DebugService::instance()->signalEmitted(QString::fromAscii(s->m_owner->metaObject()->method(s->m_index).signature())); + + QQmlHandlingSignalProfiler prof(s->m_owner, s->m_index, s->m_expression); + + s->m_isEvaluating = true; + + if (s->m_expression && s->m_expression->engine()) { + QQmlExpressionPrivate::get(s->m_expression)->value(); + if (s->m_expression && s->m_expression->hasError()) + QQmlEnginePrivate::warning(s->m_expression->engine(), s->m_expression->error()); + } + s->m_isEvaluating = false; +} + QT_END_NAMESPACE #include <qqmlboundsignal.moc> |