aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2010-08-16 18:15:28 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-08-16 18:43:52 -0300
commita61017d620189108ab844ce9398f453f534de5f3 (patch)
tree96a9a7c242b2ef3a0d49dc0605262d5c7b63c36e
parentf548708c9643481b023763aa25722a5a25a268e1 (diff)
Implement support to signal connection on constructor using named arguments.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--cppgenerator.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index afacdd92f..369ee409d 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -786,7 +786,7 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun
s << endl;
- if (overloadData.hasArgumentWithDefaultValue()) {
+ if (metaClass->isQObject() || overloadData.hasArgumentWithDefaultValue()) {
// Check usage of unknown named arguments
writeNamedArgumentsCheck(s, overloadData);
if (!metaClass->isQObject())
@@ -831,21 +831,38 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun
s << INDENT << "cptr->metaObject();" << endl;
- if (metaClass->isQObject() && overloadData.hasArgumentWithDefaultValue()) {
+ if (metaClass->isQObject()) {
s << INDENT << "for (std::vector<PyObject*>::size_type i = 0; i < propertyKeys.size(); i++) {" << endl;
{
Indentation indent(INDENT);
s << INDENT << "const char* propName = PyString_AS_STRING(propertyKeys[i]);" << endl;
- s << INDENT << "if (cptr->metaObject()->indexOfProperty(propName) == -1) {" << endl;
+ s << INDENT << "const QMetaObject* mo = cptr->metaObject();" << endl;
+ s << INDENT << "if (mo->indexOfProperty(propName) != -1) {" << endl;
{
Indentation indent(INDENT);
- s << INDENT << "delete cptr;" << endl;
- s << INDENT << "PyErr_Format(PyExc_AttributeError, \"'%s' is not a Qt property\", propName);" << endl;
- s << INDENT << "return -1;" << endl;
+ s << INDENT << "cptr->setProperty(propName, ";
+ s << "Shiboken::Converter<QVariant>::toCpp(PyDict_GetItem(kwds, propertyKeys[i])));" << endl;
}
- s << INDENT << '}' << endl;
- s << INDENT << "cptr->setProperty(propName, ";
- s << "Shiboken::Converter<QVariant>::toCpp(PyDict_GetItem(kwds, propertyKeys[i])));" << endl;
+ s << INDENT << "} else {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "QString signalSignature = QString(\"%1()\").arg(propName);" << endl;
+ s << INDENT << "if (mo->indexOfSignal(qPrintable(signalSignature)) != -1) {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "signalSignature = '2' + signalSignature;" << endl;
+ s << INDENT << "PySide::signal_connect(self, qPrintable(signalSignature), PyDict_GetItem(kwds, propertyKeys[i]));" << endl;
+ }
+ s << INDENT << "} else {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "delete cptr;" << endl;
+ s << INDENT << "PyErr_Format(PyExc_AttributeError, \"'%s' is not a Qt property or a signal\", propName);" << endl;
+ s << INDENT << "return -1;" << endl;
+ }
+ s << INDENT << "};" << endl;
+ }
+ s << INDENT << "}" << endl;
}
s << INDENT << '}' << endl;
}