summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-02-15 16:35:01 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2011-02-15 19:04:04 -0200
commit938c2e314c94acf9ab24999e79464e58d8e8371d (patch)
tree298e0faeadbb6f7501b629ff70e87f3ce5df3c17
parent7901c69c9e404e460aee9b35d0a50f24681c9152 (diff)
downloadshiboken-938c2e314c94acf9ab24999e79464e58d8e8371d.tar.gz
shiboken-938c2e314c94acf9ab24999e79464e58d8e8371d.tar.xz
shiboken-938c2e314c94acf9ab24999e79464e58d8e8371d.zip
Fix bug 684 - "New-style signals does not accept signals with enums as arguments."
-rw-r--r--generator/cppgenerator.cpp59
-rw-r--r--generator/cppgenerator.h2
-rw-r--r--generator/headergenerator.cpp3
3 files changed, 55 insertions, 9 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index a2b39655..9d509a37 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -304,6 +304,15 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl
s << "// Native ---------------------------------------------------------" << endl;
s << endl;
+#ifdef AVOID_PROTECTED_HACK
+ if (usePySideExtensions()) {
+ s << "void " << wrapperName(metaClass) << "::pysideInitQtMetaTypes()\n{\n";
+ Indentation indent(INDENT);
+ writeInitQtMetaTypeFunctionBody(s, metaClass);
+ s << "}\n\n";
+ }
+#endif
+
foreach (const AbstractMetaFunction* func, filterFunctions(metaClass)) {
if ((func->isPrivate() && !visibilityModifiedToPrivate(func))
|| (func->isModifiedRemoved() && !func->isAbstract()))
@@ -3133,13 +3142,13 @@ void CppGenerator::writeSignalInitialization(QTextStream& s, const AbstractMetaC
if (i > 0)
signature += ", ";
- AbstractMetaArgument *a = cppSignal->arguments().at(i);
- AbstractMetaType* type = a->type();
+ AbstractMetaArgument* arg = cppSignal->arguments().at(i);
+ AbstractMetaType* type = arg->type();
QString cppSignature = SBK_NORMALIZED_TYPE(qPrintable(type->cppSignature()));
QString originalSignature = SBK_NORMALIZED_TYPE(qPrintable(type->originalTypeDescription()));
- if (!a->defaultValueExpression().isEmpty()) {
+ if (!arg->defaultValueExpression().isEmpty()) {
QString sig = SBK_NORMALIZED_SIGNATURE(signature.toAscii());
if (sig.isEmpty())
sig = "void";
@@ -3489,15 +3498,41 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m
if (!metaClass->isNamespace())
writeRegisterType(s, metaClass);
- if (usePySideExtensions() && !metaClass->isNamespace()) {
- // Qt metatypes are registered only on their first use, so we do this now.
- const char* star = metaClass->typeEntry()->isObject() ? "*" : "";
- s << INDENT << "PySide::initQtMetaType<" << metaClass->qualifiedCppName() << star << " >();" << endl;
+ if (usePySideExtensions()) {
+#ifdef AVOID_PROTECTED_HACK
+ if (shouldGenerateCppWrapper(metaClass))
+ s << INDENT << wrapperName(metaClass) << "::pysideInitQtMetaTypes();\n";
+ else
+ writeInitQtMetaTypeFunctionBody(s, metaClass);
+#else
+ writeInitQtMetaTypeFunctionBody(s, metaClass);
+#endif
}
+
s << '}' << endl << endl;
}
+void CppGenerator::writeInitQtMetaTypeFunctionBody(QTextStream& s, const AbstractMetaClass* metaClass) const
+{
+ const QString className = metaClass->qualifiedCppName();
+ if (!metaClass->isNamespace()) {
+ // Qt metatypes are registered only on their first use, so we do this now.
+ const char* star = metaClass->typeEntry()->isObject() ? "*" : "";
+ s << INDENT << "PySide::initQtMetaType< ::" << className << star << " >();" << endl;
+ }
+ foreach (AbstractMetaEnum* metaEnum, metaClass->enums()) {
+ if (!metaEnum->isPrivate() && !metaEnum->isAnonymous()) {
+ QString n = className + "::" + metaEnum->name();
+ s << INDENT << "qRegisterMetaType< ::" << n << " >(\"" << n << "\");" << endl;
+ if (metaEnum->typeEntry()->flags()) {
+ n = metaEnum->typeEntry()->flags()->originalName();
+ s << INDENT << "qRegisterMetaType< ::" << n << " >(\"" << n << "\");" << endl;
+ }
+ }
+ }
+}
+
void CppGenerator::writeTypeDiscoveryFunction(QTextStream& s, const AbstractMetaClass* metaClass)
{
QString polymorphicExpr = metaClass->typeEntry()->polymorphicIdValue();
@@ -3837,13 +3872,19 @@ void CppGenerator::finishGeneration()
s << endl;
}
- s << '}' << endl << endl;
-
// module inject-code native/end
if (!snips.isEmpty()) {
writeCodeSnips(s, snips, CodeSnip::End, TypeSystem::NativeCode);
s << endl;
}
+
+ if (usePySideExtensions()) {
+ foreach (AbstractMetaEnum* metaEnum, globalEnums)
+ if (!metaEnum->isAnonymous())
+ s << INDENT << "qRegisterMetaType< ::" << metaEnum->name() << " >(\"" << metaEnum->name() << "\");" << endl;
+ }
+
+ s << '}' << endl << endl;
}
}
diff --git a/generator/cppgenerator.h b/generator/cppgenerator.h
index 279ff872..d7674385 100644
--- a/generator/cppgenerator.h
+++ b/generator/cppgenerator.h
@@ -169,6 +169,8 @@ private:
void writeParentChildManagement(QTextStream& s, const AbstractMetaFunction* func, bool userHeuristicForReturn);
bool writeParentChildManagement(QTextStream& s, const AbstractMetaFunction* func, int argIndex, bool userHeuristicPolicy);
void writeReturnValueHeuristics(QTextStream& s, const AbstractMetaFunction* func, const QString& self = "self");
+ void writeInitQtMetaTypeFunctionBody(QTextStream& s, const AbstractMetaClass* metaClass) const;
+
/**
* Returns the multiple inheritance initializer function for the given class.
* \param metaClass the class for whom the function name must be generated.
diff --git a/generator/headergenerator.cpp b/generator/headergenerator.cpp
index b7e2bbdc..b52bf7c9 100644
--- a/generator/headergenerator.cpp
+++ b/generator/headergenerator.cpp
@@ -149,6 +149,9 @@ void HeaderGenerator::generateClass(QTextStream& s, const AbstractMetaClass* met
writeInheritedOverloads(s);
}
+ if (usePySideExtensions())
+ s << INDENT << "static void pysideInitQtMetaTypes();" << endl;
+
s << "};" << endl << endl;
}