diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-22 12:18:56 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-09-22 12:18:56 (GMT) |
commit | 5085d5027f168db01e60e2161d44d9445f9c7beb (patch) | |
tree | 8c356970804cc36090c5201c3a521caddad97f94 /src/declarative/qml/qmlmetaproperty.cpp | |
parent | 8d5a395e176239b7e3ee8822cb251b2e631c21de (diff) | |
download | Qt-5085d5027f168db01e60e2161d44d9445f9c7beb.zip Qt-5085d5027f168db01e60e2161d44d9445f9c7beb.tar.gz Qt-5085d5027f168db01e60e2161d44d9445f9c7beb.tar.bz2 |
Add plumbing for more advanced signal property control
Diffstat (limited to 'src/declarative/qml/qmlmetaproperty.cpp')
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.cpp | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 792b098..8f76240 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -547,6 +547,9 @@ QmlAbstractBinding *QmlMetaProperty::binding() const \a newBinding will be enabled, and the returned binding (if any) will be disabled. + + Ownership of \a newBinding transfers to QML. Ownership of the return value + is assumed by the caller. */ QmlAbstractBinding * QmlMetaProperty::setBinding(QmlAbstractBinding *newBinding) const @@ -577,6 +580,59 @@ QmlMetaProperty::setBinding(QmlAbstractBinding *newBinding) const return 0; } +/*! + Returns the expression associated with this signal property, or 0 if no + signal expression exists. +*/ +QmlExpression *QmlMetaProperty::signalExpression() const +{ + if (!(type() & SignalProperty)) + return 0; + + const QObjectList &children = d->object->children(); + + for (int ii = 0; ii < children.count(); ++ii) { + QObject *child = children.at(ii); + + QmlBoundSignal *signal = QmlBoundSignal::cast(child); + if (signal && signal->index() == coreIndex()) + return signal->expression(); + } + + return 0; +} + +/*! + Set the signal expression associated with this signal property to \a expr. + Returns the existing signal expression (if any), otherwise 0. + + Ownership of \a expr transfers to QML. Ownership of the return value is + assumed by the caller. +*/ +QmlExpression *QmlMetaProperty::setSignalExpression(QmlExpression *expr) const +{ + if (!(type() & SignalProperty)) + return 0; + + const QObjectList &children = d->object->children(); + + for (int ii = 0; ii < children.count(); ++ii) { + QObject *child = children.at(ii); + + QmlBoundSignal *signal = QmlBoundSignal::cast(child); + if (signal && signal->index() == coreIndex()) + return signal->setExpression(expr); + } + + if (expr) { + QmlBoundSignal *signal = new QmlBoundSignal(d->object, d->signal, + d->object); + return signal->setExpression(expr); + } else { + return 0; + } +} + void QmlMetaPropertyPrivate::findSignalInt(QObject *obj, const QString &name) { const QMetaObject *mo = obj->metaObject(); @@ -617,9 +673,9 @@ QVariant QmlMetaProperty::read() const const QObjectList &children = object()->children(); for (int ii = 0; ii < children.count(); ++ii) { - QmlBoundSignal *sig = qobject_cast<QmlBoundSignal *>(children.at(ii)); + QmlBoundSignal *sig = QmlBoundSignal::cast(children.at(ii)); if (sig && sig->index() == d->coreIdx) - return sig->expression(); + return sig->expression()->expression(); } } else if (type() & Property) { if (type() & Attached) { @@ -653,13 +709,13 @@ void QmlMetaPropertyPrivate::writeSignalProperty(const QVariant &value) const QObjectList &children = object->children(); for (int ii = 0; ii < children.count(); ++ii) { - QmlBoundSignal *sig = qobject_cast<QmlBoundSignal *>(children.at(ii)); + QmlBoundSignal *sig = QmlBoundSignal::cast(children.at(ii)); if (sig && sig->index() == coreIdx) { if (expr.isEmpty()) { sig->disconnect(); sig->deleteLater(); } else { - sig->setExpression(expr); + sig->expression()->setExpression(expr); } return; } @@ -667,7 +723,7 @@ void QmlMetaPropertyPrivate::writeSignalProperty(const QVariant &value) if (!expr.isEmpty()) { // XXX scope - (void *)new QmlBoundSignal(qmlContext(object), expr, object, coreIdx, object); + (void *)new QmlBoundSignal(qmlContext(object), expr, object, signal, object); } } |