summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-06-20 15:18:22 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:15:26 -0300
commite80044aaca2f0769d65a18384df711006a519eb7 (patch)
treea86fb45d29ec3552c756bab72308b7a791a1e4c1
parentd08c86eebf68d049fe80795955fbcf1446e8b0f7 (diff)
Implemented support to qt_metacast function on qobjects.
fixs bug #872. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Hugo Parente Lima <hugo.pl@gmail.com>
-rw-r--r--generator/cppgenerator.cpp17
-rw-r--r--generator/cppgenerator.h1
-rw-r--r--generator/headergenerator.cpp3
3 files changed, 20 insertions, 1 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 9e9c31ae..ef019e9c 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -949,6 +949,23 @@ void CppGenerator::writeMetaObjectMethod(QTextStream& s, const AbstractMetaClass
s << INDENT << "int result = " << metaClass->qualifiedCppName() << "::qt_metacall(call, id, args);\n";
s << INDENT << "return result < 0 ? result : PySide::SignalManager::qt_metacall(this, call, id, args);\n";
s << "}\n\n";
+
+ // qt_metacast function
+ writeMetaCast(s, metaClass);
+}
+
+void CppGenerator::writeMetaCast(QTextStream& s, const AbstractMetaClass* metaClass)
+{
+ Indentation indentation(INDENT);
+ QString wrapperClassName = wrapperName(metaClass);
+ s << "void* " << wrapperClassName << "::qt_metacast(const char* _clname)" << endl;
+ s << '{' << endl;
+ s << INDENT << "if (!_clname) return 0;" << endl;
+ s << INDENT << "SbkObject* pySelf = Shiboken::BindingManager::instance().retrieveWrapper(this);" << endl;
+ s << INDENT << "if (pySelf && PySide::inherits(pySelf->ob_type, _clname))" << endl;
+ s << INDENT << INDENT << "return static_cast<void*>(const_cast< " << wrapperClassName << "* >(this));" << endl;
+ s << INDENT << "return " << metaClass->qualifiedCppName() << "::qt_metacast(_clname);" << endl;
+ s << "}" << endl << endl;
}
void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFunctionList overloads)
diff --git a/generator/cppgenerator.h b/generator/cppgenerator.h
index a5709ec5..185380e4 100644
--- a/generator/cppgenerator.h
+++ b/generator/cppgenerator.h
@@ -46,6 +46,7 @@ private:
void writeDestructorNative(QTextStream& s, const AbstractMetaClass* metaClass);
void writeVirtualMethodNative(QTextStream& s, const AbstractMetaFunction* func);
void writeMetaObjectMethod(QTextStream& s, const AbstractMetaClass* metaClass);
+ void writeMetaCast(QTextStream& s, const AbstractMetaClass* metaClass);
void writeConstructorWrapper(QTextStream &s, const AbstractMetaFunctionList overloads);
void writeDestructorWrapper(QTextStream& s, const AbstractMetaClass* metaClass);
diff --git a/generator/headergenerator.cpp b/generator/headergenerator.cpp
index 3b0de4fd..3a821036 100644
--- a/generator/headergenerator.cpp
+++ b/generator/headergenerator.cpp
@@ -133,7 +133,8 @@ void HeaderGenerator::generateClass(QTextStream& s, const AbstractMetaClass* met
if ((!avoidProtectedHack() || !metaClass->hasPrivateDestructor())
&& usePySideExtensions() && metaClass->isQObject()) {
s << "public:\n";
- s << INDENT << "virtual int qt_metacall(QMetaObject::Call call, int id, void** args);\n";
+ s << INDENT << "virtual int qt_metacall(QMetaObject::Call call, int id, void** args);" << endl;
+ s << INDENT << "virtual void* qt_metacast(const char* _clname);" << endl;
}
if (m_inheritedOverloads.size()) {