aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2012-03-22 10:38:00 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-26 02:55:20 +0200
commitd120c3c383d7db7a7c7f1602ba27f04cebb8abfa (patch)
tree1c39dcfbc3f92754b396afa9ac142cb5b471f5fd /src/qml/qml
parent6b516a83051727c1ca02a8b400409927ad615ea6 (diff)
Support registered QFlags in QML methods and signal handlers.
Change-Id: I2a71122303dcf7af4f07c3ffb73456bcdce62a74 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp10
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp24
2 files changed, 24 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 5cc603224a..543b69a1c5 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -55,6 +55,8 @@
#include <QtCore/qstringbuilder.h>
#include <QtCore/qdebug.h>
+Q_DECLARE_METATYPE(QJSValue)
+
QT_BEGIN_NAMESPACE
class QQmlBoundSignalParameters : public QObject
@@ -227,10 +229,14 @@ QQmlBoundSignalParameters::QQmlBoundSignalParameters(const QMetaMethod &method,
prop.setWritable(false);
} else {
QByteArray propType = type;
- if ((QMetaType::typeFlags(t) & QMetaType::IsEnumeration) == QMetaType::IsEnumeration) {
+ QMetaType::TypeFlags flags = QMetaType::typeFlags(t);
+ if (flags & QMetaType::IsEnumeration) {
t = QVariant::Int;
propType = "int";
- } else if (t == QVariant::Invalid) {
+ } else if (t == QVariant::Invalid ||
+ (t >= QVariant::UserType && !(flags & QMetaType::PointerToQObject) &&
+ t != qMetaTypeId<QJSValue>())) {
+ //the UserType clause is to catch registered QFlags
QByteArray scope;
QByteArray name;
int scopeIdx = propType.lastIndexOf("::");
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index 318044a25b..50fd409a00 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -688,7 +688,7 @@ struct StaticQtMetaObject : public QObject
{ return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; }
};
-static int EnumType(const QMetaObject *metaobj, const QByteArray &str)
+static int EnumType(const QMetaObject *metaobj, const QByteArray &str, int type)
{
QByteArray scope;
QByteArray name;
@@ -709,7 +709,7 @@ static int EnumType(const QMetaObject *metaobj, const QByteArray &str)
if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
return QVariant::Int;
}
- return QVariant::Invalid;
+ return type;
}
// Returns an array of the arguments for method \a index. The first entry in the array
@@ -745,10 +745,14 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
for (int ii = 0; ii < argTypeNames.count(); ++ii) {
int type = QMetaType::type(argTypeNames.at(ii));
- if ((QMetaType::typeFlags(type) & QMetaType::IsEnumeration) == QMetaType::IsEnumeration)
+ QMetaType::TypeFlags flags = QMetaType::typeFlags(type);
+ if (flags & QMetaType::IsEnumeration)
type = QVariant::Int;
- else if (type == QVariant::Invalid)
- type = EnumType(object->metaObject(), argTypeNames.at(ii));
+ else if (type == QVariant::Invalid ||
+ (type >= (int)QVariant::UserType && !(flags & QMetaType::PointerToQObject) &&
+ type != qMetaTypeId<QJSValue>()))
+ //the UserType clause is to catch registered QFlags
+ type = EnumType(object->metaObject(), argTypeNames.at(ii), type);
if (type == QVariant::Invalid) {
if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
free(args);
@@ -770,10 +774,14 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
for (int ii = 0; ii < argTypeNames.count(); ++ii) {
int type = QMetaType::type(argTypeNames.at(ii));
- if ((QMetaType::typeFlags(type) & QMetaType::IsEnumeration) == QMetaType::IsEnumeration)
+ QMetaType::TypeFlags flags = QMetaType::typeFlags(type);
+ if (flags & QMetaType::IsEnumeration)
type = QVariant::Int;
- else if (type == QVariant::Invalid)
- type = EnumType(object->metaObject(), argTypeNames.at(ii));
+ else if (type == QVariant::Invalid ||
+ (type >= (int)QVariant::UserType && !(flags & QMetaType::PointerToQObject) &&
+ type != qMetaTypeId<QJSValue>()))
+ //the UserType clause is to catch registered QFlags)
+ type = EnumType(object->metaObject(), argTypeNames.at(ii), type);
if (type == QVariant::Invalid) {
if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
return 0;