summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-10-28 13:46:41 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-10-28 14:58:54 -0300
commitb146f4117c676a6a65b1e29a09d5f6c86541cd0d (patch)
treebd01c642b9269b7fda9ee33f78a439e235d905f2
parent016bc9ba8847411cb92ee25a03d50e62f4e9e952 (diff)
downloadshiboken-b146f4117c676a6a65b1e29a09d5f6c86541cd0d.tar.gz
shiboken-b146f4117c676a6a65b1e29a09d5f6c86541cd0d.tar.xz
shiboken-b146f4117c676a6a65b1e29a09d5f6c86541cd0d.zip
Implemented support to dynamic signals created on QML side.
Fixes bug #437. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--generator/cppgenerator.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 7f708d20..02ca2dda 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -3556,7 +3556,7 @@ void CppGenerator::writeGetattroFunction(QTextStream& s, const AbstractMetaClass
s << INDENT << '}' << endl;
}
s << INDENT << "PyObject* attr = PyObject_GenericGetAttr(self, name);" << endl;
- if (usePySideExtensions() && metaClass->isQObject()) {
+ if (usePySideExtensions() && (metaClass->qualifiedCppName() == "QObject")) {
s << INDENT << "if (attr && PySide::isQPropertyType(attr)) {" << endl;
{
Indentation indent(INDENT);
@@ -3571,7 +3571,39 @@ void CppGenerator::writeGetattroFunction(QTextStream& s, const AbstractMetaClass
s << INDENT << "attr = value;" << endl;
}
s << INDENT << "}" << endl;
+
+ s << INDENT << "//search on metaobject (avoid internal attributes started with '__')" << endl
+ << INDENT << "if (!attr && !QString(PyString_AS_STRING(name)).startsWith(\"__\")) {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "QObject* cppSelf = Converter<QObject*>::toCpp(self);" << endl
+ << INDENT << "const QMetaObject* metaObject = cppSelf->metaObject();" << endl
+ << INDENT << "QByteArray cname(PyString_AS_STRING(name));" << endl
+ << INDENT << "cname += '(';" << endl
+ << INDENT << "//signal" << endl
+ << INDENT << "QList<QMetaMethod> signalList;" << endl
+ << INDENT << "for(int i=0, i_max = metaObject->methodCount(); i < i_max; i++) {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "QMetaMethod method = metaObject->method(i);" << endl
+ << INDENT << "if ((method.methodType() == QMetaMethod::Signal) &&" << endl
+ << INDENT << "QString(method.signature()).startsWith(cname))" << endl
+ << INDENT << "signalList.append(method);" << endl;
+ }
+ s << INDENT << "}" << endl
+ << INDENT << "if (signalList.size() > 0) {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "PyObject* pySignal = PySide::signalNewFromMethod(self, signalList);" << endl
+ << INDENT << "PyObject_SetAttr(self, name, pySignal);" << endl
+ << INDENT << "PyObject_GenericSetAttr(self, name, pySignal);" << endl
+ << INDENT << "return pySignal;" << endl;
+ }
+ s << INDENT << "}" << endl;
+ }
+ s << INDENT << "}" << endl;
}
+
s << INDENT << "return attr;" << endl;
s << '}' << endl;
}