diff options
author | Bea Lam <bea.lam@nokia.com> | 2011-04-05 06:55:18 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2011-04-12 01:07:49 (GMT) |
commit | f2219ce983098fc14655d8f3bb8a7fee2c9abe4d (patch) | |
tree | f8efd2e3eab7ff4ee868985fa7cdeb3fad0f0f1e /src | |
parent | 6ec7695eaa02c923b90d72e3918b9ab50da63e41 (diff) | |
download | Qt-f2219ce983098fc14655d8f3bb8a7fee2c9abe4d.zip Qt-f2219ce983098fc14655d8f3bb8a7fee2c9abe4d.tar.gz Qt-f2219ce983098fc14655d8f3bb8a7fee2c9abe4d.tar.bz2 |
Allow enum values to be used as signal parameters
The fix does not work for enums declared outside of the class that
emits the signal, since in this case it is not possible to access
the metaobject of the class that declared the enum. However the
fix makes a special case for the Qt namespace to allow enums in this
namespace to be used.
Task-number: QTBUG-15983
Change-Id: I6f72255b07010311a20fe068bd97c7db7b294d9b
Reviewed-by: Aaron Kennedy
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qdeclarativeboundsignal.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp index 28dfea9..47a15cb 100644 --- a/src/declarative/qml/qdeclarativeboundsignal.cpp +++ b/src/declarative/qml/qdeclarativeboundsignal.cpp @@ -225,9 +225,35 @@ QDeclarativeBoundSignalParameters::QDeclarativeBoundSignalParameters(const QMeta QMetaPropertyBuilder prop = mob.addProperty(name, "QObject*"); prop.setWritable(false); } else { + QByteArray propType = type; + if (t >= QVariant::UserType || t == QVariant::Invalid) { + //copy of QDeclarativeObjectScriptClass::enumType() + QByteArray scope; + QByteArray name; + int scopeIdx = propType.lastIndexOf("::"); + if (scopeIdx != -1) { + scope = propType.left(scopeIdx); + name = propType.mid(scopeIdx + 2); + } else { + name = propType; + } + const QMetaObject *meta; + if (scope == "Qt") + meta = &QObject::staticQtMetaObject; + else + meta = parent->parent()->metaObject(); //### assumes parent->parent() + for (int i = meta->enumeratorCount() - 1; i >= 0; --i) { + QMetaEnum m = meta->enumerator(i); + if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope))) { + t = QVariant::Int; + propType = "int"; + break; + } + } + } if (QDeclarativeMetaType::canCopy(t)) { types[ii] = t; - QMetaPropertyBuilder prop = mob.addProperty(name, type); + QMetaPropertyBuilder prop = mob.addProperty(name, propType); prop.setWritable(false); } else { types[ii] = 0x80000000 | t; |