From c421281a0291fd48c616a6e37315364ce0553c0f Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Sun, 3 Jun 2012 21:10:32 +0200 Subject: Adapt to connection-related changes in qtbase The QQmlData hooks signalEmitted() and receivers() now receive the index in the signal index range (i.e., excluding non-signal methods). This was done to avoid Q(Meta)Object having to compute the class's method offset; the signal offset should be sufficient for everyone. This required adapting QQmlNotifier, QQmlBoundSignal, QQmlPropertyCache and friends to use the signal index range whenever a property's notify signal is involved in the internal connection lists and property captures. Using the signal index range also reduces the memory used for NotifyList::notifies, since useless entries for non-signal methods will no longer be created. Change-Id: I62872fbea5a1f829b8b03bae3fc1e6acd84cf886 Reviewed-by: Aaron Kennedy --- src/qml/qml/qqmlproperty.cpp | 53 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'src/qml/qml/qqmlproperty.cpp') diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index a797a73373..945f6de5c0 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -58,6 +58,7 @@ #include "qqmlvaluetypeproxybinding_p.h" #include +#include #include #include @@ -362,7 +363,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) if (d && d->notifyIndex != -1) { object = currentObject; - core = *ddata->propertyCache->method(d->notifyIndex); + core = *ddata->propertyCache->signal(d->notifyIndex); return; } } @@ -390,6 +391,18 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) } } +/*! \internal + Returns the index of this property's signal, in the signal index range + (see QObjectPrivate::signalIndex()). This is different from + QMetaMethod::methodIndex(). +*/ +int QQmlPropertyPrivate::signalIndex() const +{ + Q_ASSERT(type() == QQmlProperty::SignalProperty); + QMetaMethod m = object->metaObject()->method(core.coreIndex); + return QMetaObjectPrivate::signalIndex(m); +} + /*! Create a copy of \a other. */ @@ -963,7 +976,7 @@ QQmlPropertyPrivate::signalExpression(const QQmlProperty &that) QQmlAbstractBoundSignal *signalHandler = data->signalHandlers; - while (signalHandler && signalHandler->index() != that.index()) + while (signalHandler && signalHandler->index() != QQmlPropertyPrivate::get(that)->signalIndex()) signalHandler = signalHandler->m_nextSignal; if (signalHandler) @@ -1011,14 +1024,15 @@ QQmlPropertyPrivate::takeSignalExpression(const QQmlProperty &that, QQmlAbstractBoundSignal *signalHandler = data->signalHandlers; - while (signalHandler && signalHandler->index() != that.index()) + while (signalHandler && signalHandler->index() != QQmlPropertyPrivate::get(that)->signalIndex()) signalHandler = signalHandler->m_nextSignal; if (signalHandler) return signalHandler->takeExpression(expr); if (expr) { - QQmlBoundSignal *signal = new QQmlBoundSignal(that.d->object, that.index(), that.d->object, + int signalIndex = QQmlPropertyPrivate::get(that)->signalIndex(); + QQmlBoundSignal *signal = new QQmlBoundSignal(that.d->object, signalIndex, that.d->object, expr->context()->engine); signal->takeExpression(expr); } @@ -1875,16 +1889,25 @@ QMetaMethod QQmlPropertyPrivate::findSignalByName(const QMetaObject *mo, const Q return QMetaMethod(); } -static inline void flush_vme_signal(const QObject *object, int index) +/*! \internal + If \a indexInSignalRange is true, \a index is treated as a signal index + (see QObjectPrivate::signalIndex()), otherwise it is treated as a + method index (QMetaMethod::methodIndex()). +*/ +static inline void flush_vme_signal(const QObject *object, int index, bool indexInSignalRange) { QQmlData *data = static_cast(QObjectPrivate::get(const_cast(object))->declarativeData); if (data && data->propertyCache) { - QQmlPropertyData *property = data->propertyCache->method(index); + QQmlPropertyData *property = indexInSignalRange ? data->propertyCache->signal(index) + : data->propertyCache->method(index); if (property && property->isVMESignal()) { - QQmlVMEMetaObject *vme = QQmlVMEMetaObject::getForMethod(const_cast(object), - index); - vme->connectAliasSignal(index); + QQmlVMEMetaObject *vme; + if (indexInSignalRange) + vme = QQmlVMEMetaObject::getForSignal(const_cast(object), index); + else + vme = QQmlVMEMetaObject::getForMethod(const_cast(object), index); + vme->connectAliasSignal(index, indexInSignalRange); } } } @@ -1900,15 +1923,21 @@ bool QQmlPropertyPrivate::connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type, int *types) { - flush_vme_signal(sender, signal_index); - flush_vme_signal(receiver, method_index); + static const bool indexInSignalRange = false; + flush_vme_signal(sender, signal_index, indexInSignalRange); + flush_vme_signal(receiver, method_index, indexInSignalRange); return QMetaObject::connect(sender, signal_index, receiver, method_index, type, types); } +/*! \internal + \a signal_index MUST be in the signal index range (see QObjectPrivate::signalIndex()). + This is different from QMetaMethod::methodIndex(). +*/ void QQmlPropertyPrivate::flushSignal(const QObject *sender, int signal_index) { - flush_vme_signal(sender, signal_index); + static const bool indexInSignalRange = true; + flush_vme_signal(sender, signal_index, indexInSignalRange); } QT_END_NAMESPACE -- cgit v1.2.3