diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-05-04 16:51:59 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:15:22 -0300 |
commit | 96a4cc767fa930d236262904abebc4cdff54eff0 (patch) | |
tree | fafccbf79ea8e66e03b1cea601a82df545c5b6ca /generator | |
parent | 4b5380126807dee8bc6a0a06c23f787446e2058c (diff) |
Fix bug 813 - "Can not override connect method when subclassing QObject"
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Renato Araújo <renato.filho@openbossa.org>
Diffstat (limited to 'generator')
-rw-r--r-- | generator/cppgenerator.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index 8d3179d5e..790563772 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -3768,10 +3768,18 @@ void CppGenerator::writeGetattroFunction(QTextStream& s, const AbstractMetaClass { s << "static PyObject* " << cpythonGetattroFunctionName(metaClass) << "(PyObject* self, PyObject* name)" << endl; s << '{' << endl; + + QString getattrFunc; + if (usePySideExtensions() && metaClass->isQObject()) + getattrFunc = "PySide::getMetaDataFromQObject(Shiboken::Converter<QObject*>::toCpp(self), self, name)"; + else + getattrFunc = "PyObject_GenericGetAttr(self, name)"; + if (classNeedsGetattroFunction(metaClass)) { s << INDENT << "if (self) {" << endl; { Indentation indent(INDENT); + s << INDENT << "// Search the method in the instance dict" << endl; s << INDENT << "if (reinterpret_cast<SbkObject*>(self)->ob_dict) {" << endl; { Indentation indent(INDENT); @@ -3785,6 +3793,19 @@ void CppGenerator::writeGetattroFunction(QTextStream& s, const AbstractMetaClass s << INDENT << '}' << endl; } s << INDENT << '}' << endl; + s << INDENT << "// Search the method in the type dict" << endl; + s << INDENT << "if (Shiboken::Object::isUserType(self)) {" << endl; + { + Indentation indent(INDENT); + s << INDENT << "PyObject* meth = PyDict_GetItem(self->ob_type->tp_dict, name);" << endl; + s << INDENT << "if (meth)" << endl; + { + Indentation indent(INDENT); + s << INDENT << "return PyFunction_Check(meth) ? PyMethod_New(meth, self, (PyObject*)self->ob_type) : " << getattrFunc << ';' << endl; + } + } + s << INDENT << '}' << endl; + s << INDENT << "const char* cname = PyString_AS_STRING(name);" << endl; foreach (const AbstractMetaFunction* func, getMethodsWithBothStaticAndNonStaticMethods(metaClass)) { s << INDENT << "if (strcmp(cname, \"" << func->name() << "\") == 0)" << endl; @@ -3794,10 +3815,7 @@ void CppGenerator::writeGetattroFunction(QTextStream& s, const AbstractMetaClass } s << INDENT << '}' << endl; } - if (usePySideExtensions() && metaClass->isQObject()) - s << INDENT << "return PySide::getMetaDataFromQObject(Shiboken::Converter<QObject*>::toCpp(self), self, name);" << endl; - else - s << INDENT << "return PyObject_GenericGetAttr(self, name);" << endl; + s << INDENT << "return " << getattrFunc << ';' << endl; s << '}' << endl; } |