diff options
author | Brett Stottlemyer <bstottle@ford.com> | 2019-05-14 20:51:16 -0400 |
---|---|---|
committer | Brett Stottlemyer <bstottle@ford.com> | 2019-05-17 20:17:29 +0000 |
commit | 91f83125dd403878c989be4098cc3a35eb5ba06f (patch) | |
tree | 6a15a35bb32ebc745a3bd1f08b88c2c67d0496cd /tools/repc/repcodegenerator.cpp | |
parent | e520e4fd777350673d5022982481f82672fea6ff (diff) |
More fixes for (dynamic) enums in signals and slots
This addresses two larger issues with enums and several smaller fixes.
First, unlike the recent fix for properties, we need to register enums for
queued connections to work and get signal/slot updates over QtRO to work.
This change adds said registration.
Second, enums are identified with the class they are defined in, so passing
updates through a dynamic object requires converting the typenames. The
templated enableRemoting methods become interesting here, as the class
name depends on the type passed as a template parameter. This change also
updates the repc output so enums are properly resolved via the templates.
Smaller fixes include updates to some tests and several places where enums
were converted to/from int. Note: we need (and have always needed) to
convert enums to ints, since the class name is passed as part of the
variant serialization which cannot be changed without major digging into
qvariant and QDataStream serialization internals.
Change-Id: I0a77f85df6a400a7a44394a05c9c2401bee4e4a8
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'tools/repc/repcodegenerator.cpp')
-rw-r--r-- | tools/repc/repcodegenerator.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/tools/repc/repcodegenerator.cpp b/tools/repc/repcodegenerator.cpp index 870033c..fd208c0 100644 --- a/tools/repc/repcodegenerator.cpp +++ b/tools/repc/repcodegenerator.cpp @@ -859,7 +859,7 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass out << " void " << property.name << "Changed(" << fullyQualifiedTypeName(astClass, className, typeForMode(property, mode)) << " " << property.name << ");" << endl; } - QVector<ASTFunction> signalsList = transformEnumParams(astClass, astClass.signalsList, className); + const QVector<ASTFunction> signalsList = transformEnumParams(astClass, astClass.signalsList, className); Q_FOREACH (const ASTFunction &signal, signalsList) out << " void " << signal.name << "(" << signal.paramsAsString() << ");" << endl; @@ -883,15 +883,16 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass out << "public Q_SLOTS:" << endl; Q_FOREACH (const ASTProperty &property, astClass.properties) { if (property.modifier == ASTProperty::ReadPush) { + const auto type = fullyQualifiedTypeName(astClass, className, property.type); if (mode != REPLICA) { - out << " virtual void push" << cap(property.name) << "(" << property.type << " " << property.name << ")" << endl; + out << " virtual void push" << cap(property.name) << "(" << type << " " << property.name << ")" << endl; out << " {" << endl; out << " set" << cap(property.name) << "(" << property.name << ");" << endl; out << " }" << endl; } else { - out << " void push" << cap(property.name) << "(" << property.type << " " << property.name << ")" << endl; + out << " void push" << cap(property.name) << "(" << type << " " << property.name << ")" << endl; out << " {" << endl; - out << " static int __repc_index = " << className << "::staticMetaObject.indexOfSlot(\"push" << cap(property.name) << "(" << property.type << ")\");" << endl; + out << " static int __repc_index = " << className << "::staticMetaObject.indexOfSlot(\"push" << cap(property.name) << "(" << type << ")\");" << endl; out << " QVariantList __repc_args;" << endl; out << " __repc_args << QVariant::fromValue(" << property.name << ");" << endl; out << " send(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args);" << endl; @@ -899,9 +900,11 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass } } } - Q_FOREACH (const ASTFunction &slot, astClass.slotsList) { + const QVector<ASTFunction> slotsList = transformEnumParams(astClass, astClass.slotsList, className); + Q_FOREACH (const ASTFunction &slot, slotsList) { + const auto returnType = fullyQualifiedTypeName(astClass, className, slot.returnType); if (mode != REPLICA) { - out << " virtual " << slot.returnType << " " << slot.name << "(" << slot.paramsAsString() << ") = 0;" << endl; + out << " virtual " << returnType << " " << slot.name << "(" << slot.paramsAsString() << ") = 0;" << endl; } else { // TODO: Discuss whether it is a good idea to special-case for void here, const bool isVoid = slot.returnType == QStringLiteral("void"); @@ -909,7 +912,7 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass if (isVoid) out << " void " << slot.name << "(" << slot.paramsAsString() << ")" << endl; else - out << " QRemoteObjectPendingReply<" << slot.returnType << "> " << slot.name << "(" << slot.paramsAsString()<< ")" << endl; + out << " QRemoteObjectPendingReply<" << returnType << "> " << slot.name << "(" << slot.paramsAsString()<< ")" << endl; out << " {" << endl; out << " static int __repc_index = " << className << "::staticMetaObject.indexOfSlot(\"" << slot.name << "(" << slot.paramsAsString(ASTFunction::Normalized) << ")\");" << endl; out << " QVariantList __repc_args;" << endl; @@ -922,7 +925,7 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass if (isVoid) out << " send(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args);" << endl; else - out << " return QRemoteObjectPendingReply<" << slot.returnType << ">(sendWithReply(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args));" << endl; + out << " return QRemoteObjectPendingReply<" << returnType << ">(sendWithReply(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args));" << endl; out << " }" << endl; } } @@ -1284,8 +1287,12 @@ void RepCodeGenerator::generateSourceAPI(QTextStream &out, const ASTClass &astCl for (int i = 0; i < slotCount; ++i) { const ASTFunction &slot = astClass.slotsList.at(i); - out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"%2\");") - .arg(QString::number(i+pushCount), slot.returnType) << endl; + if (isClassEnum(astClass, slot.returnType)) + out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"$1\").replace(\"$1\", QtPrivate::qtro_enum_signature<ObjectType>(\"%2\"));") + .arg(QString::number(i+pushCount), slot.returnType) << endl; + else + out << QString::fromLatin1(" case %1: return QByteArrayLiteral(\"%2\");") + .arg(QString::number(i+pushCount), slot.returnType) << endl; } out << QStringLiteral(" }") << endl; } else |