diff options
author | Glenn Watson <glenn.watson@nokia.com> | 2011-11-25 11:58:37 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-27 22:51:39 +0100 |
commit | de9d845441eeb699da85c98d163451bc127fa1de (patch) | |
tree | 3742721b9ef20feade31b32797aa36199c6469ed /src | |
parent | ff049be0726e020937a0fb8aab92b67d88d25188 (diff) |
Add support to moc for registering non-local enums via Q_ENUMS.
When using the Q_ENUMS macro to register an enumeration in a class
with moc, it's now possible to provide a scoped enumeration that
exists in another class. This adds the enum class scope to
a metaobject's list of related classes stored in the extradata
field.
This allows the declarative code to handle non-local enums in
signal and slot functions that are exposed to QML.
Task-number: QTBUG-20639
Change-Id: I94f5292818095fda75762bd1508ba5c69de19503
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/moc/generator.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index bf9c451d2c..81508d1a09 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -313,6 +313,21 @@ void Generator::generateCode() } } } + + // QTBUG-20639 - Accept non-local enums for QML signal/slot parameters. + // Look for any scoped enum declarations, and add those to the list + // of extra/related metaobjects for this object. + QList<QByteArray> enumKeys = cdef->enumDeclarations.keys(); + for (int i = 0; i < enumKeys.count(); ++i) { + const QByteArray &enumKey = enumKeys[i]; + int s = enumKey.lastIndexOf("::"); + if (s > 0) { + QByteArray scope = enumKey.left(s); + if (scope != "Qt" && scope != cdef->classname && !extraList.contains(scope)) + extraList += scope; + } + } + if (!extraList.isEmpty()) { fprintf(out, "#ifdef Q_NO_DATA_RELOCATION\n"); fprintf(out, "static const QMetaObjectAccessor qt_meta_extradata_%s[] = {\n ", qualifiedClassNameIdentifier.constData()); |