diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2009-12-16 17:42:50 -0200 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2009-12-16 18:22:45 -0200 |
commit | 9ab2b614214ac925f17818ceda176a543d674fd9 (patch) | |
tree | dfee19780986639ce1d953ab258aea6c6a822e21 /cppgenerator.cpp | |
parent | fe681d0b1105c5e4ce61130700a2707b86320d94 (diff) |
Add metaObject() method to every class derived from QObject when
the flag enable-pyside-extensions is on.
Diffstat (limited to 'cppgenerator.cpp')
-rw-r--r-- | cppgenerator.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index 13c849dd4..9d27639ce 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -90,8 +90,11 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl // headers s << "// default includes" << endl; s << "#include <shiboken.h>" << endl; - if (usePySideExtensions()) + if (usePySideExtensions()) { s << "#include <typeresolver.h>\n"; + if (metaClass->isQObject()) + s << "#include <signalmanager.h>\n"; + } // The multiple inheritance initialization function // needs the 'set' class from C++ STL. @@ -154,6 +157,9 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl writeVirtualMethodNative(s, func); } + if (usePySideExtensions() && metaClass->isQObject()) + writeMetaObjectMethod(s, metaClass); + writeDestructorNative(s, metaClass); s << endl << "// Target ---------------------------------------------------------" << endl; @@ -430,6 +436,21 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu s << '}' << endl << endl; } +void CppGenerator::writeMetaObjectMethod(QTextStream& s, const AbstractMetaClass* metaClass) +{ + Indentation indentation(INDENT); + QString prefix = wrapperName(metaClass) + "::"; + s << "const QMetaObject* " << wrapperName(metaClass) << "::metaObject() const\n{\n"; + s << INDENT << "const QMetaObject* qmetaObject = PySide::SignalManager::instance().getMetaObject(this);\n"; + s << INDENT << "if (!qmetaObject)\n"; + { + Indentation indentation(INDENT); + s << INDENT << "qmetaObject = &" << metaClass->qualifiedCppName() << "::staticMetaObject;\n"; + } + s << INDENT << "return qmetaObject;\n"; + s << "}\n\n"; +} + void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFunctionList overloads) { OverloadData overloadData(overloads, this); |