summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuciano Wolf <luciano.wolf@openbossa.org>2010-05-17 14:13:26 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-05-17 19:57:06 -0300
commit960774e63afe0a9386383c71c4831fab7c42e790 (patch)
treebce4e9cbddfa0da9cf0c8fae3114e3db4c8ebc65
parent226144304f75e749424a9f7ae2dc9a566c3cfc4e (diff)
downloadshiboken-960774e63afe0a9386383c71c4831fab7c42e790.tar.gz
shiboken-960774e63afe0a9386383c71c4831fab7c42e790.tar.xz
shiboken-960774e63afe0a9386383c71c4831fab7c42e790.zip
Export signals to the generated cpp files.
Reviewer: Hugo Parente Lima <hugo.lima@openbossa.org>, Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--cppgenerator.cpp46
-rw-r--r--cppgenerator.h2
2 files changed, 46 insertions, 2 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 3577d46e..c47d00b6 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -745,9 +745,10 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun
s << endl;
if (metaClass->isQObject()) {
- s << INDENT << "cptr->metaObject();" << endl;
if (usePySideExtensions())
- s << INDENT << "PySide::signal_update_source(self);" << endl;
+ s << INDENT << "PySide::signalUpdateSource(self);" << endl;
+
+ s << INDENT << "cptr->metaObject();" << endl;
}
s << endl << INDENT << "return 1;" << endl;
if (overloadData.maxArgs() > 0)
@@ -2402,6 +2403,45 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu
s << endl;
}
+void CppGenerator::writeSignalInitialization(QTextStream& s, const AbstractMetaClass* metaClass)
+{
+ QHash<QString, QStringList> signatures;
+
+ foreach (const AbstractMetaFunction* cppSignal, metaClass->cppSignalFunctions()) {
+ QString signature;
+ if (cppSignal->declaringClass() == metaClass) {
+ if (cppSignal->arguments().count()) {
+ for (int i = 0; i < cppSignal->arguments().count(); ++i) {
+ if (i > 0)
+ signature += ", ";
+ AbstractMetaArgument *a = cppSignal->arguments().at(i);
+ signature += a->type()->cppSignature();
+ }
+ } else {
+ signature = "void";
+ }
+ signatures[cppSignal->name()].append(QMetaObject::normalizedSignature(signature.toAscii()));
+ }
+ }
+
+ if (signatures.size() == 0)
+ return;
+
+ s << INDENT << "// Initialize signals" << endl;
+ s << INDENT << "PyObject* signal_item;" << endl << endl;
+
+ foreach(QString funcName, signatures.keys()) {
+ s << INDENT << "signal_item = PySide::signalNew(\"" << funcName <<"\"";
+ foreach(QString signature, signatures[funcName])
+ s << ", \"" + signature << "\"";
+ s << ", NULL);" << endl;
+ s << INDENT << "PyDict_SetItemString(" + cpythonTypeName(metaClass) + ".super.ht_type.tp_dict";
+ s << ", \"" << funcName << "\", signal_item);" << endl;
+ s << INDENT << "Py_DECREF(signal_item);" << endl;
+ }
+ s << endl;
+}
+
void CppGenerator::writeFlagsNewMethod(QTextStream& s, const FlagsTypeEntry* cppFlags)
{
QString cpythonName = cpythonFlagsName(cppFlags);
@@ -2757,6 +2797,8 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m
foreach (const AbstractMetaEnum* cppEnum, metaClass->enums())
writeEnumInitialization(s, cppEnum);
+ if (metaClass->hasSignals())
+ writeSignalInitialization(s, metaClass);
// class inject-code target/end
if (!metaClass->typeEntry()->codeSnips().isEmpty()) {
diff --git a/cppgenerator.h b/cppgenerator.h
index 009c2e6c..c6ba546b 100644
--- a/cppgenerator.h
+++ b/cppgenerator.h
@@ -134,6 +134,8 @@ private:
void writeEnumDefinition(QTextStream& s, const AbstractMetaEnum* metaEnum);
void writeEnumInitialization(QTextStream& s, const AbstractMetaEnum* metaEnum);
+ void writeSignalInitialization(QTextStream& s, const AbstractMetaClass* metaClass);
+
void writeFlagsDefinition(QTextStream& s, const AbstractMetaEnum* cppEnum);
void writeFlagsMethods(QTextStream& s, const AbstractMetaEnum* cppEnum);
void writeFlagsNumberMethodsDefinition(QTextStream& s, const AbstractMetaEnum* cppEnum);