diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-06-25 05:13:20 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-06-25 05:13:20 (GMT) |
commit | 46233eaa956e57a4c948cec759a3be606a8bdcb8 (patch) | |
tree | 17e9335f320a7f41d0271f28361cac913a4ad36b /src/declarative/qml | |
parent | 2d7e341646e302506531cb0bf87b8da5d088c319 (diff) | |
download | Qt-46233eaa956e57a4c948cec759a3be606a8bdcb8.zip Qt-46233eaa956e57a4c948cec759a3be606a8bdcb8.tar.gz Qt-46233eaa956e57a4c948cec759a3be606a8bdcb8.tar.bz2 |
Handle enums in method arguments in the same way as QtScript
QML will now invoke methods with enums as arguments, in the same fashion
as QtScript.
QTBUG-11313
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 24 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeobjectscriptclass_p.h | 2 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index aca01b2..3af892d 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -797,6 +797,26 @@ QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e) } } +int QDeclarativeObjectMethodScriptClass::enumType(const QMetaObject *meta, const QString &strname) +{ + QByteArray str = strname.toUtf8(); + QByteArray scope; + QByteArray name; + int scopeIdx = str.lastIndexOf("::"); + if (scopeIdx != -1) { + scope = str.left(scopeIdx); + name = str.mid(scopeIdx + 2); + } else { + name = str; + } + for (int i = meta->enumeratorCount() - 1; i >= 0; --i) { + QMetaEnum m = meta->enumerator(i); + if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope))) + return QVariant::Int; + } + return QVariant::Invalid; +} + QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass::call(Object *o, QScriptContext *ctxt) { MethodData *method = static_cast<MethodData *>(o); @@ -810,7 +830,9 @@ QDeclarativeObjectMethodScriptClass::Value QDeclarativeObjectMethodScriptClass:: // ### Cache for (int ii = 0; ii < argTypeNames.count(); ++ii) { argTypes[ii] = QMetaType::type(argTypeNames.at(ii)); - if (argTypes[ii] == QVariant::Invalid) + if (argTypes[ii] == QVariant::Invalid) + argTypes[ii] = enumType(method->object->metaObject(), argTypeNames.at(ii)); + if (argTypes[ii] == QVariant::Invalid) return Value(ctxt, ctxt->throwError(QString::fromLatin1("Unknown method parameter type: %1").arg(QLatin1String(argTypeNames.at(ii))))); } diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h index 4b27e53..75e384c 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass_p.h +++ b/src/declarative/qml/qdeclarativeobjectscriptclass_p.h @@ -80,6 +80,8 @@ protected: virtual Value property(Object *, const Identifier &); private: + int enumType(const QMetaObject *, const QString &); + PersistentIdentifier m_connectId; PersistentIdentifier m_disconnectId; QScriptValue m_connect; |