From dadaf215f71958915728156795813fb8ebc61f0f 2009-05-26 19:13:40 From: florianlink Date: 2009-05-26 19:13:40 Subject: [PATCH] added return value conversion from reference to pointer to work around moc limitations, added toString method generation git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@106 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/generator/abstractmetabuilder.cpp b/generator/abstractmetabuilder.cpp index e2ea460..cdb93b3 100644 --- a/generator/abstractmetabuilder.cpp +++ b/generator/abstractmetabuilder.cpp @@ -502,6 +502,7 @@ bool AbstractMetaBuilder::build() traverseCompareOperator(item); } } + // TODO XXX search and add operator+ etc. to the classes here! { FunctionList stream_operators = m_dom->findFunctions("operator<<") + m_dom->findFunctions("operator>>"); diff --git a/generator/generator.h b/generator/generator.h index 9f67d37..613e235 100644 --- a/generator/generator.h +++ b/generator/generator.h @@ -65,6 +65,7 @@ public: NoBlockedSlot = 0x00100000, SuperCall = 0x00200000, FirstArgIsWrappedObject = 0x00400000, + ConvertReferenceToPtr = 0x00800000, GlobalRefJObject = 0x00100000, diff --git a/generator/shellgenerator.cpp b/generator/shellgenerator.cpp index bb4e120..b5de6ec 100644 --- a/generator/shellgenerator.cpp +++ b/generator/shellgenerator.cpp @@ -88,8 +88,13 @@ void ShellGenerator::writeTypeInfo(QTextStream &s, const AbstractMetaType *type, s << QString(type->indirections(), '*'); - if (type->isReference() && !(options & ExcludeReference)) + if (type->isReference() && !(options & ExcludeReference) && !(options & ConvertReferenceToPtr)) s << "&"; + + if (type->isReference() && (options & ConvertReferenceToPtr)) { + s << "*"; + } + if (!(options & SkipName)) s << ' '; @@ -216,7 +221,7 @@ void ShellGenerator::writeFunctionSignature(QTextStream &s, } } - writeFunctionArguments(s, meta_function->ownerClass(), meta_function->arguments(), option, numArguments); + writeFunctionArguments(s, meta_function->ownerClass(), meta_function->arguments(), Option(option & Option(~ConvertReferenceToPtr)), numArguments); // The extra arguments... for (int i=0; iisSlot()) { s << " "; writeFunctionSignature(s, function, 0, QString(), - Option(FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); + Option(ConvertReferenceToPtr | FirstArgIsWrappedObject| IncludeDefaultExpression | OriginalName | ShowStatic | UnderscoreSpaces)); s << ";" << endl; } } + if (!meta_class->hasDefaultToStringFunction() && meta_class->hasToStringCapability()) { + s << " QString toString(" << meta_class->qualifiedCppName() << "*);" << endl; + } // writeInjectedCode(s, meta_class); diff --git a/generator/shellimplgenerator.cpp b/generator/shellimplgenerator.cpp index 93bbac3..3151466 100644 --- a/generator/shellimplgenerator.cpp +++ b/generator/shellimplgenerator.cpp @@ -169,7 +169,6 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla if (fun->type()) { s << "return "; } - // call the C++ implementation s << meta_class->qualifiedCppName() << "::"; s << fun->originalName() << "("; for (int i = 0; i < args.size(); ++i) { @@ -213,7 +212,7 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla if (fun->isSlot()) continue; writeFunctionSignature(s, fun, meta_class, QString(), - Option(FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces), + Option(ConvertReferenceToPtr | FirstArgIsWrappedObject | OriginalName | ShowStatic | UnderscoreSpaces), "PythonQtWrapper_"); s << endl << "{" << endl; s << " "; @@ -229,8 +228,14 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla QString scriptFunctionName = fun->originalName(); AbstractMetaArgumentList args = fun->arguments(); // call the C++ implementation - if (fun->type()) + if (fun->type()) { s << "return "; + // call the C++ implementation + if (fun->type()->isReference()) { + s << "&"; + } + } + s << "("; if (scriptFunctionName.startsWith("operator>>")) { s << wrappedObject << " >>" << args.at(0)->argumentName(); } else if (scriptFunctionName.startsWith("operator<<")) { @@ -258,11 +263,25 @@ void ShellImplGenerator::write(QTextStream &s, const AbstractMetaClass *meta_cla } s << ")"; } + s << ")"; } s << ";" << endl; s << "}" << endl << endl; } + + if (!meta_class->hasDefaultToStringFunction() && meta_class->hasToStringCapability()) { + FunctionModelItem fun = meta_class->hasToStringCapability(); + int indirections = fun->arguments().at(1)->type().indirections(); + QString deref = QLatin1String(indirections == 0 ? "*" : ""); + s << "QString PythonQtWrapper_" << meta_class->name() << "::toString(" << meta_class->qualifiedCppName() << "* obj) {" << endl; + s << " QString result;" << endl; + s << " QDebug d(&result);" << endl; + s << " d << " << deref << "obj;" << endl; + s << " return result;" << endl; + s << "}" << endl << endl; + } + } void ShellImplGenerator::writeInjectedCode(QTextStream &s, const AbstractMetaClass *meta_class)