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/qml/qdeclarativecompiler.cpp | |
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/qml/qdeclarativecompiler.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativecompiler.cpp | 16 |
1 files changed, 10 insertions, 6 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) { |