diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2011-08-31 12:36:32 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-01 06:58:23 +0200 |
commit | d481f2ff518df1e44103d1850e7d52bd69260c34 (patch) | |
tree | 1e6713284f99a61c74fbc57b7c753c954a41ff2c /src/declarative/qml/qdeclarativepropertycache.cpp | |
parent | 1dd8b509074ba60da671f7671f8cf09c3fc001ae (diff) |
Allow reference to signals using 'on' handler syntax.
This will allow APIs like the following:
trigger: mouseArea.onClicked
However, signal handlers will not be callable from QML:
mouseArea.onClicked() //throws exception
Change-Id: I2ef5cb4e1f3ed4814ef590962391e1b14e3f0c43
Reviewed-on: http://codereview.qt.nokia.com/3683
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src/declarative/qml/qdeclarativepropertycache.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativepropertycache.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 406e43fc21..05232d981a 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -313,10 +313,14 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb allowedRevisionCache.append(0); int methodCount = metaObject->methodCount(); + Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4); + int signalCount = QMetaObjectPrivate::get(metaObject)->signalCount; // 3 to block the destroyed signal and the deleteLater() slot int methodOffset = qMax(3, metaObject->methodOffset()); methodIndexCache.resize(methodCount - methodIndexCacheStart); + signalHandlerIndexCache.resize(signalCount); + int signalHandlerIndex = 0; for (int ii = methodOffset; ii < methodCount; ++ii) { QMetaMethod m = metaObject->method(ii); if (m.access() == QMetaMethod::Private) @@ -329,6 +333,7 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb while (*cptr != '(') { Q_ASSERT(*cptr != 0); utf8 |= *cptr & 0x80; ++cptr; } Data *data = &methodIndexCache[ii - methodIndexCacheStart]; + Data *sigdata = 0; data->lazyLoad(m); @@ -342,6 +347,12 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb data->metaObjectOffset = allowedRevisionCache.count() - 1; + if (data->isSignal()) { + sigdata = &signalHandlerIndexCache[signalHandlerIndex]; + *sigdata = *data; + sigdata->flags |= Data::IsSignalHandler; + } + Data *old = 0; if (utf8) { @@ -349,11 +360,33 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb if (Data **it = stringCache.value(methodName)) old = *it; stringCache.insert(methodName, data); + + if (data->isSignal()) { + QHashedString on(QStringLiteral("on") % methodName.at(0).toUpper() % methodName.midRef(1)); + stringCache.insert(on, sigdata); + ++signalHandlerIndex; + } } else { QHashedCStringRef methodName(signature, cptr - signature); if (Data **it = stringCache.value(methodName)) old = *it; stringCache.insert(methodName, data); + + if (data->isSignal()) { + int length = methodName.length(); + + char str[length + 3]; + str[0] = 'o'; + str[1] = 'n'; + str[2] = toupper(signature[0]); + if (length > 1) + memcpy(&str[3], &signature[1], length - 1); + str[length + 2] = '\0'; + + QHashedString on(QString::fromLatin1(str)); + stringCache.insert(on, sigdata); + ++signalHandlerIndex; + } } if (old) { |