summaryrefslogtreecommitdiffstats
path: root/generator/cppgenerator.cpp
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-12-03 16:55:09 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2010-12-03 17:44:25 -0200
commit53a4a73c516bbeec546cb20234dad6bd9912fdaa (patch)
treef0f297492dc8b1b7e9b7f71154935fc7bf1e8bfe /generator/cppgenerator.cpp
parent07f1fe9dc97e05247043b3e579d94d323a2a48dc (diff)
downloadshiboken-53a4a73c516bbeec546cb20234dad6bd9912fdaa.tar.gz
shiboken-53a4a73c516bbeec546cb20234dad6bd9912fdaa.tar.xz
shiboken-53a4a73c516bbeec546cb20234dad6bd9912fdaa.zip
Write a simpler code to deal with dynamic QMetaObjects.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
Diffstat (limited to 'generator/cppgenerator.cpp')
-rw-r--r--generator/cppgenerator.cpp39
1 files changed, 11 insertions, 28 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 199489dc..b95d1cf2 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -173,7 +173,6 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl
if (usePySideExtensions()) {
if (metaClass->isQObject()) {
s << "#include <signalmanager.h>" << endl;
- s << "#include <dynamicqmetaobject.h>" << endl;
s << "#include <pysidemetafunction.h>" << endl;
}
}
@@ -452,9 +451,6 @@ void CppGenerator::writeConstructorNative(QTextStream& s, const AbstractMetaFunc
OriginalTypeDescription | SkipDefaultValues);
s << " : ";
writeFunctionCall(s, func);
- if (usePySideExtensions() && func->ownerClass()->isQObject())
- s << ", m_metaObject(0)";
-
s << " {" << endl;
const AbstractMetaArgument* lastArg = func->arguments().isEmpty() ? 0 : func->arguments().last();
writeCodeSnips(s, func->injectedCodeSnips(), CodeSnip::Beginning, TypeSystem::NativeCode, func, lastArg);
@@ -779,31 +775,13 @@ void CppGenerator::writeMetaObjectMethod(QTextStream& s, const AbstractMetaClass
{
Indentation indentation(INDENT);
QString wrapperClassName = wrapperName(metaClass);
- QString prefix = wrapperClassName + "::";
- s << "const QMetaObject* " << wrapperClassName << "::metaObject() const\n{\n";
- s << INDENT << "if (!m_metaObject) {\n";
- {
- Indentation indentation(INDENT);
- s << INDENT << "SbkObject* pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);\n"
- << INDENT << "void* typeData = Shiboken::Object::getTypeUserData(pySelf);" << endl
- << INDENT << "if (!typeData) {" << endl;
- {
- Indentation indentation2(INDENT);
- s << INDENT << "m_metaObject = PySide::DynamicQMetaObject::createBasedOn((PyObject*)pySelf, pySelf->ob_type, &"
- << metaClass->qualifiedCppName() << "::staticMetaObject);" << endl
- << INDENT << "Shiboken::Object::setTypeUserData(pySelf, m_metaObject, Shiboken::callCppDestructor<PySide::DynamicQMetaObject>);" << endl;
- }
- s << INDENT << "} else {" << endl;
- {
- Indentation indentation2(INDENT);
- s << INDENT << "m_metaObject = reinterpret_cast<PySide::DynamicQMetaObject*>(typeData);" << endl;
- }
- s << INDENT << "}" << endl;
- }
- s << INDENT << "}" << endl;
- s << INDENT << "return m_metaObject;\n";
- s << "}\n\n";
+ s << "const QMetaObject* " << wrapperClassName << "::metaObject() const" << endl;
+ s << '{' << endl;
+ s << INDENT << "SbkObject* pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);" << endl;
+ s << INDENT << "return reinterpret_cast<QMetaObject*>(Shiboken::Object::getTypeUserData(pySelf));" << endl;
+ s << '}' << endl << endl;
+ // qt_metacall function
s << "int " << wrapperClassName << "::qt_metacall(QMetaObject::Call call, int id, void** args)\n";
s << "{\n";
s << INDENT << "int result = " << metaClass->qualifiedCppName() << "::qt_metacall(call, id, args);\n";
@@ -3214,6 +3192,11 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m
// alloc private data
s << INDENT << "Shiboken::ObjectType::initPrivateData(&" << cpythonTypeName(metaClass->typeEntry()) << ");" << endl;
+ if (usePySideExtensions() && metaClass->isQObject()) {
+ s << INDENT << "Shiboken::ObjectType::setSubTypeInitHook(&" << cpythonTypeName(metaClass->typeEntry()) << ", &PySide::initQObjectSubType);" << endl;
+ s << INDENT << "PySide::initDynamicMetaObject(&" << cpythonTypeName(metaClass->typeEntry()) << ", &" << metaClass->qualifiedCppName() << "::staticMetaObject);";
+ }
+
// class inject-code target/beginning
if (!metaClass->typeEntry()->codeSnips().isEmpty()) {
writeCodeSnips(s, metaClass->typeEntry()->codeSnips(), CodeSnip::Beginning, TypeSystem::TargetLangCode, 0, 0, metaClass);