diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-02-25 00:38:43 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-02-25 00:38:43 (GMT) |
commit | d654f87319408e3d9754fa5a8ad376c3eaef4489 (patch) | |
tree | 7276a6edf146fb9d1426dfd39714a6b2fbc3c4cf /src/declarative | |
parent | fcfb08e40264c3417da91f4e187758d85f190a4f (diff) | |
download | Qt-d654f87319408e3d9754fa5a8ad376c3eaef4489.zip Qt-d654f87319408e3d9754fa5a8ad376c3eaef4489.tar.gz Qt-d654f87319408e3d9754fa5a8ad376c3eaef4489.tar.bz2 |
Automatically connect to signals "onFooChanged" if property is "foo".
This follows on from a2a8cea2835ef24104fe784b6ce0f508cc5637c0 to make
it work for PropertyChanges and QDeclarativeMetaProperty as well.
Task-number: QT-2783
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/qml/qdeclarativecompiler.cpp | 16 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativecompiler_p.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativemetaproperty.cpp | 20 |
3 files changed, 14 insertions, 25 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index b6ebd60..0e54d45 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1314,8 +1314,9 @@ int QDeclarativeCompiler::componentTypeRef() return output->types.count() - 1; } -int QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArray &name) +QMetaMethod QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArray &name) { + Q_ASSERT(mo); int methods = mo->methodCount(); for (int ii = methods - 1; ii >= 0; --ii) { QMetaMethod method = mo->method(ii); @@ -1324,7 +1325,7 @@ int QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArr methodName = methodName.left(idx); if (methodName == name) - return ii; + return method; } // If no signal is found, but the signal is of the form "onBlahChanged", @@ -1332,11 +1333,14 @@ int QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArr if (name.endsWith("Changed")) { QByteArray propName = name.mid(0, name.length() - 7); int propIdx = mo->indexOfProperty(propName.constData()); - if (propIdx >= 0) - return mo->property(propIdx).notifySignalIndex(); + if (propIdx >= 0) { + QMetaProperty prop = mo->property(propIdx); + if (prop.hasNotifySignal()) + return prop.notifySignal(); + } } - return -1; + return QMetaMethod(); } bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, @@ -1351,7 +1355,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl if(name[0] >= 'A' && name[0] <= 'Z') name[0] = name[0] - 'A' + 'a'; - int sigIdx = findSignalByName(obj->metaObject(), name); + int sigIdx = findSignalByName(obj->metaObject(), name).methodIndex(); if (sigIdx == -1) { diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 627490d..2ea3366 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -159,6 +159,8 @@ public: static bool isAttachedPropertyName(const QByteArray &); static bool isSignalPropertyName(const QByteArray &); + static QMetaMethod findSignalByName(const QMetaObject *, const QByteArray &name); + private: static void reset(QDeclarativeCompiledData *); @@ -263,7 +265,6 @@ private: int componentTypeRef(); - static int findSignalByName(const QMetaObject *, const QByteArray &name); static QDeclarativeType *toQmlType(QDeclarativeParser::Object *from); bool canCoerce(int to, QDeclarativeParser::Object *from); bool canCoerce(int to, int from); diff --git a/src/declarative/qml/qdeclarativemetaproperty.cpp b/src/declarative/qml/qdeclarativemetaproperty.cpp index e94ce8c..253174d 100644 --- a/src/declarative/qml/qdeclarativemetaproperty.cpp +++ b/src/declarative/qml/qdeclarativemetaproperty.cpp @@ -53,6 +53,7 @@ #include "qdeclarativedeclarativedata_p.h" #include "qdeclarativestringconverters_p.h" #include "qdeclarativelist_p.h" +#include "qdeclarativecompiler_p.h" #include <QStringList> #include <QtCore/qdebug.h> @@ -177,7 +178,7 @@ void QDeclarativeMetaPropertyPrivate::initProperty(QObject *obj, const QString & QString signalName = name.mid(2); signalName[0] = signalName.at(0).toLower(); - QMetaMethod method = findSignal(obj, signalName); + QMetaMethod method = QDeclarativeCompiler::findSignalByName(obj->metaObject(), signalName.toLatin1().constData()); if (method.signature()) { core.load(method); return; @@ -631,23 +632,6 @@ QDeclarativeExpression *QDeclarativeMetaProperty::setSignalExpression(QDeclarati } } -QMetaMethod QDeclarativeMetaPropertyPrivate::findSignal(QObject *obj, const QString &name) -{ - const QMetaObject *mo = obj->metaObject(); - - int methods = mo->methodCount(); - for (int ii = methods - 1; ii >= 0; --ii) { - QMetaMethod method = mo->method(ii); - QString methodName = QString::fromUtf8(method.signature()); - int idx = methodName.indexOf(QLatin1Char('(')); - methodName = methodName.left(idx); - - if (methodName == name) - return method; - } - return QMetaMethod(); -} - QObject *QDeclarativeMetaPropertyPrivate::attachedObject() const { if (attachedFunc == -1) |