diff options
author | Renato Filho <renato.filho@openbossa.org> | 2011-07-06 19:41:25 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:15:27 -0300 |
commit | 6032293a4f357ccccd57ea96bb74b55254faed59 (patch) | |
tree | e11022e966da3dffb3a714c9fc454d9800872231 /generator | |
parent | db280f75a04ce9aaf884bdbb7b54e269bbf8220d (diff) |
Make sure register QMetaObject before QObject.
Remove all staticMetaObject form know types.
Reviewer: Hugo Parente <hugo.lima@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'generator')
-rw-r--r-- | generator/cppgenerator.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index 698f0cbbb..387a275cb 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -3717,7 +3717,7 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m if (usePySideExtensions() && metaClass->isQObject()) { s << INDENT << "Shiboken::ObjectType::setSubTypeInitHook(&" << pyTypeName << ", &PySide::initQObjectSubType);" << endl; - s << INDENT << "PySide::initDynamicMetaObject(&" << pyTypeName << ", &" << metaClass->qualifiedCppName() << "::staticMetaObject);"; + s << INDENT << "PySide::initDynamicMetaObject(&" << pyTypeName << ", &" << metaClass->qualifiedCppName() << "::staticMetaObject);" << endl; } s << '}' << endl << endl; @@ -3914,8 +3914,18 @@ void CppGenerator::finishGeneration() writeMethodDefinition(s_globalFunctionDef, overloads); } + //this is a temporary solution before new type revison implementation + //We need move QMetaObject register before QObject + AbstractMetaClassList lst = classes(); + AbstractMetaClass* klassQObject = lst.findClass("QObject"); + AbstractMetaClass* klassQMetaObject = lst.findClass("QMetaObject"); + if (klassQObject && klassQMetaObject) { + lst.removeAll(klassQMetaObject); + int indexOf = lst.indexOf(klassQObject); + lst.insert(indexOf, klassQMetaObject); + } - foreach (const AbstractMetaClass* cls, classes()) { + foreach (const AbstractMetaClass* cls, lst) { if (!shouldGenerate(cls)) continue; @@ -3943,6 +3953,8 @@ void CppGenerator::finishGeneration() s << "#include <Python.h>" << endl; s << "#include <shiboken.h>" << endl; s << "#include <algorithm>" << endl; + if (usePySideExtensions()) + s << "#include <pyside.h>" << endl; s << "#include \"" << getModuleHeaderFileName() << '"' << endl << endl; foreach (const Include& include, includes) @@ -3983,6 +3995,23 @@ void CppGenerator::finishGeneration() s << endl; } + // cleanup staticMetaObject attribute + if (usePySideExtensions()) { + s << "void cleanTypesAttributes(void) {" << endl; + s << INDENT << "for (int i = 0, imax = SBK_" << moduleName() << "_IDX_COUNT; i < imax; i++) {" << endl; + { + Indentation indentation(INDENT); + s << INDENT << "PyObject *pyType = reinterpret_cast<PyObject*>(" << cppApiVariableName() << "[i]);" << endl; + s << INDENT << "if (pyType && PyObject_HasAttrString(pyType, \"staticMetaObject\"))"<< endl; + { + Indentation indentation(INDENT); + s << INDENT << "PyObject_SetAttrString(pyType, \"staticMetaObject\", Py_None);" << endl; + } + } + s << INDENT << "}" << endl; + s << "}" << endl; + } + s << "// Global functions "; s << "------------------------------------------------------------" << endl; s << globalFunctionImpl << endl; @@ -4141,8 +4170,13 @@ void CppGenerator::finishGeneration() foreach (AbstractMetaEnum* metaEnum, globalEnums) if (!metaEnum->isAnonymous()) s << INDENT << "qRegisterMetaType< ::" << metaEnum->name() << " >(\"" << metaEnum->name() << "\");" << endl; + + // cleanup staticMetaObject attribute + s << INDENT << "PySide::registerCleanupFunction(cleanTypesAttributes);" << endl; } + + s << '}' << endl << endl; } } |