diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-06-18 15:06:16 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-22 00:13:28 +0200 |
commit | fa457e593deca9fcffe2d6ec6ca0aa40d9fa7b76 (patch) | |
tree | a8e53434055544fcf3ebeb9ba5982b3d7f72cf38 /src/qml/qml/qqmlpropertycache.cpp | |
parent | 57e3325affbe8bbb8edcc2c6d072db28aee46438 (diff) |
Support enum return types in Q_INVOKABLE functions.
Handle enums correctly when used as the return type of a Q_INVOKABLE
function.
Task-number: QTBUG-23543
Change-Id: I14a506ffee08f5ba6aa0fdf27d6104a3ae5c48b3
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlpropertycache.cpp')
-rw-r--r-- | src/qml/qml/qqmlpropertycache.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 14e474e67d..87e707d1a0 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -1095,6 +1095,56 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index, } } +// Returns the return type of the method. +int QQmlPropertyCache::methodReturnType(QObject *object, const QQmlPropertyData &data, + QByteArray *unknownTypeError) +{ + Q_ASSERT(object && data.coreIndex >= 0); + + int type = data.propType; + + const char *propTypeName = 0; + + if (type == QMetaType::UnknownType) { + // Find the return type name from the method info + QMetaMethod m; + + QQmlData *ddata = QQmlData::get(object, false); + if (ddata && ddata->propertyCache) { + QQmlPropertyCache *c = ddata->propertyCache; + Q_ASSERT(data.coreIndex < c->methodIndexCacheStart + c->methodIndexCache.count()); + + while (data.coreIndex < c->methodIndexCacheStart) + c = c->_parent; + + const QMetaObject *metaObject = c->createMetaObject(); + Q_ASSERT(metaObject); + m = metaObject->method(data.coreIndex); + } else { + m = object->metaObject()->method(data.coreIndex); + } + + type = m.returnType(); + propTypeName = m.typeName(); + } + + QMetaType::TypeFlags flags = QMetaType::typeFlags(type); + if (flags & QMetaType::IsEnumeration) { + type = QVariant::Int; + } else if (type == QMetaType::UnknownType || + (type >= (int)QVariant::UserType && !(flags & QMetaType::PointerToQObject) && + type != qMetaTypeId<QJSValue>())) { + //the UserType clause is to catch registered QFlags + type = EnumType(object->metaObject(), propTypeName, type); + } + + if (type == QMetaType::UnknownType) { + if (unknownTypeError) *unknownTypeError = propTypeName; + } + + return type; +} + QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, const QString &property) { Q_ASSERT(metaObject); |