aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlboundsignal.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2012-04-26 16:12:21 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-01 06:07:00 +0200
commit462edd23f953af6ce37d1c42400e2cb4443f5a24 (patch)
treeef505e16ad6e7a439a6217da191fdaac6d9eda3c /src/qml/qml/qqmlboundsignal.cpp
parent7cecad76b6a8beb31c74111b986be0e67bb2e15c (diff)
More robust tracking of signal handler expression ownership.
Reference count the expressions, and improve testing. Change-Id: I810509eae1c7608b367e9ff5f7891a294667a692 Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlboundsignal.cpp')
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp70
1 files changed, 65 insertions, 5 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index c0475b1ed9..b8b74ac2e9 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -233,7 +233,6 @@ QQmlBoundSignal::QQmlBoundSignal(QObject *scope, const QMetaMethod &signal,
QQmlBoundSignal::~QQmlBoundSignal()
{
- delete m_expression;
m_expression = 0;
delete m_params;
}
@@ -255,17 +254,32 @@ QQmlBoundSignalExpression *QQmlBoundSignal::expression() const
Sets the signal expression to \a e. Returns the current signal expression,
or null if there is no signal expression.
- The QQmlBoundSignal instance takes ownership of \a e. The caller is
- assumes ownership of the returned QQmlExpression.
+ The QQmlBoundSignal instance adds a reference to \a e. The caller
+ assumes ownership of the returned QQmlBoundSignalExpression reference.
*/
-QQmlBoundSignalExpression *QQmlBoundSignal::setExpression(QQmlBoundSignalExpression *e)
+QQmlBoundSignalExpressionPointer QQmlBoundSignal::setExpression(QQmlBoundSignalExpression *e)
{
- QQmlBoundSignalExpression *rv = m_expression;
+ QQmlBoundSignalExpressionPointer rv = m_expression;
m_expression = e;
if (m_expression) m_expression->setNotifyOnValueChanged(false);
return rv;
}
+/*!
+ Sets the signal expression to \a e. Returns the current signal expression,
+ or null if there is no signal expression.
+
+ The QQmlBoundSignal instance takes ownership of \a e (and does not add a reference). The caller
+ assumes ownership of the returned QQmlBoundSignalExpression reference.
+*/
+QQmlBoundSignalExpressionPointer QQmlBoundSignal::takeExpression(QQmlBoundSignalExpression *e)
+{
+ QQmlBoundSignalExpressionPointer rv = m_expression;
+ m_expression.take(e);
+ if (m_expression) m_expression->setNotifyOnValueChanged(false);
+ return rv;
+}
+
void QQmlBoundSignal::subscriptionCallback(QQmlNotifierEndpoint *e, void **a)
{
QQmlBoundSignal *s = static_cast<QQmlBoundSignal*>(e);
@@ -401,6 +415,52 @@ int QQmlBoundSignalParameters::metaCall(QMetaObject::Call c, int id, void **a)
}
}
+////////////////////////////////////////////////////////////////////////
+
+QQmlBoundSignalExpressionPointer::QQmlBoundSignalExpressionPointer(QQmlBoundSignalExpression *o)
+: o(o)
+{
+ if (o) o->addref();
+}
+
+QQmlBoundSignalExpressionPointer::QQmlBoundSignalExpressionPointer(const QQmlBoundSignalExpressionPointer &other)
+: o(other.o)
+{
+ if (o) o->addref();
+}
+
+QQmlBoundSignalExpressionPointer::~QQmlBoundSignalExpressionPointer()
+{
+ if (o) o->release();
+}
+
+QQmlBoundSignalExpressionPointer &QQmlBoundSignalExpressionPointer::operator=(const QQmlBoundSignalExpressionPointer &other)
+{
+ if (other.o) other.o->addref();
+ if (o) o->release();
+ o = other.o;
+ return *this;
+}
+
+QQmlBoundSignalExpressionPointer &QQmlBoundSignalExpressionPointer::operator=(QQmlBoundSignalExpression *other)
+{
+ if (other) other->addref();
+ if (o) o->release();
+ o = other;
+ return *this;
+}
+
+/*!
+Takes ownership of \a other. take() does *not* add a reference, as it assumes ownership
+of the callers reference of other.
+*/
+QQmlBoundSignalExpressionPointer &QQmlBoundSignalExpressionPointer::take(QQmlBoundSignalExpression *other)
+{
+ if (o) o->release();
+ o = other;
+ return *this;
+}
+
QT_END_NAMESPACE
#include <qqmlboundsignal.moc>