summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-10-29 09:47:41 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-10-29 16:23:45 -0300
commit7a439f4d21b08b0ef9b7344ee61dd55f71b13ed6 (patch)
tree8c60803a576cb7e94c66b49a2e584ac66d32134a
parent5944cc8d99d0c72cd87aa572224d3492e05c10eb (diff)
downloadpyside-7a439f4d21b08b0ef9b7344ee61dd55f71b13ed6.tar.gz
pyside-7a439f4d21b08b0ef9b7344ee61dd55f71b13ed6.tar.xz
pyside-7a439f4d21b08b0ef9b7344ee61dd55f71b13ed6.zip
Exported function to instantiate a signal object.
Fixes bug #428 Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--libpyside/qsignal.cpp42
-rw-r--r--libpyside/qsignal.h3
-rw-r--r--libpyside/qsignal_p.h14
3 files changed, 38 insertions, 21 deletions
diff --git a/libpyside/qsignal.cpp b/libpyside/qsignal.cpp
index 31d30fc..9195e4a 100644
--- a/libpyside/qsignal.cpp
+++ b/libpyside/qsignal.cpp
@@ -38,7 +38,7 @@ namespace PySide
//aux
static char* signalBuildSignature(const char*, const char*);
static void signalAppendSignature(SignalData*, char*);
- static void signalInstanceInitialize(PyObject*, PyObject*, SignalData*, PyObject *, int);
+ static void signalInstanceInitialize(PySideSignalInstanceData*, PyObject*, SignalData*, PyObject *, int);
static char* signalParseSignature(PyObject*);
static PyObject* signalBuildQtCompatible(const char*);
}
@@ -46,14 +46,6 @@ namespace PySide
extern "C"
{
-struct SignalData {
- PyObject_HEAD
- bool initialized;
- char* signalName;
- char** signatures;
- int signaturesSize;
- PyObject* homonymousMethod;
-};
//Signal methods
static int signalTpInit(PyObject*, PyObject*, PyObject*);
static void signalFree(void*);
@@ -483,17 +475,21 @@ void initSignalSupport(PyObject* module)
void signalUpdateSource(PyObject* source)
{
- Shiboken::AutoDecRef attrs(PyObject_Dir(source));
+ PyTypeObject * objType = reinterpret_cast<PyTypeObject *>(PyObject_Type(source));
- for(int i = 0, iMax = PyList_GET_SIZE(attrs.object()); i < iMax; ++i) {
- PyObject *attrName = PyList_GET_ITEM(attrs.object(), i);
- Shiboken::AutoDecRef attr(PyObject_GetAttr(reinterpret_cast<PyObject*>(source->ob_type), attrName));
- if (!attr.isNull() && attr->ob_type == &PySideSignalType) {
+ Py_ssize_t pos = 0;
+ PyObject* value;
+ PyObject* key;
+
+ while (PyDict_Next(objType->tp_dict, &pos, &key, &value)) {
+ if (PyObject_TypeCheck(value, &PySideSignalType)) {
Shiboken::AutoDecRef signalInstance((PyObject*)PyObject_New(PySideSignalInstanceData, &PySideSignalInstanceType));
- signalInstanceInitialize(signalInstance, attrName, reinterpret_cast<SignalData*>(attr.object()), source, 0);
- PyObject_SetAttr(source, attrName, signalInstance);
+ signalInstanceInitialize(signalInstance.cast<PySideSignalInstanceData*>(), key, reinterpret_cast<SignalData*>(value), source, 0);
+ PyObject_SetAttr(source, key, signalInstance);
}
}
+
+ Py_XDECREF(objType);
}
char* getTypeName(PyObject* type)
@@ -571,9 +567,15 @@ void signalAppendSignature(SignalData* self, char* signature)
self->signatures[self->signaturesSize-1] = signature;
}
-void signalInstanceInitialize(PyObject* instance, PyObject* name, SignalData* data, PyObject* source, int index)
+PySideSignalInstanceData* signalInitialize(PyObject* self, PyObject* name, PyObject *object)
+{
+ PySideSignalInstanceData* instance = PyObject_New(PySideSignalInstanceData, &PySideSignalInstanceType);
+ signalInstanceInitialize(instance, name, reinterpret_cast<SignalData*>(self), object, 0);
+ return instance;
+}
+
+void signalInstanceInitialize(PySideSignalInstanceData* self, PyObject* name, SignalData* data, PyObject* source, int index)
{
- PySideSignalInstanceData *self = reinterpret_cast<PySideSignalInstanceData*>(instance);
self->d = new PySideSignalInstanceDataPrivate;
PySideSignalInstanceDataPrivate* selfPvt = self->d;
selfPvt->next = 0;
@@ -594,7 +596,7 @@ void signalInstanceInitialize(PyObject* instance, PyObject* name, SignalData* da
index++;
if (index < data->signaturesSize) {
- selfPvt->next = reinterpret_cast<PyObject*>(PyObject_New(PySideSignalInstanceData, &PySideSignalInstanceType));
+ selfPvt->next = PyObject_New(PySideSignalInstanceData, &PySideSignalInstanceType);
signalInstanceInitialize(selfPvt->next, name, data, source, index);
}
}
@@ -620,7 +622,7 @@ PyObject* signalNewFromMethod(PyObject* source, const QList<QMetaMethod>& method
root = item;
if (previous)
- previous->d->next = reinterpret_cast<PyObject*>(item);
+ previous->d->next = item;
item->d = new PySideSignalInstanceDataPrivate;
PySideSignalInstanceDataPrivate* selfPvt = item->d;
diff --git a/libpyside/qsignal.h b/libpyside/qsignal.h
index 4bbf841..3f8dafd 100644
--- a/libpyside/qsignal.h
+++ b/libpyside/qsignal.h
@@ -34,6 +34,7 @@ namespace Shiboken
extern "C"
{
+ extern PYSIDE_API PyTypeObject PySideSignalType;
extern PYSIDE_API PyTypeObject PySideSignalInstanceType;
struct PySideSignalInstanceDataPrivate;
@@ -49,6 +50,8 @@ namespace PySide
PYSIDE_API PyObject* signalNew(const char* name, ...);
PYSIDE_API PyObject* signalNewFromMethod(PyObject* source, const QList<QMetaMethod>& method);
+PYSIDE_API PySideSignalInstanceData* signalInitialize(PyObject* self, PyObject* name, PyObject *object);
+
PYSIDE_API void signalUpdateSource(PyObject* source);
PYSIDE_API void addSignalToWrapper(Shiboken::SbkBaseWrapperType* wrapperType, const char* signalName, PyObject* signal);
PYSIDE_API PyObject* getSignalSource(PySideSignalInstanceData* signal);
diff --git a/libpyside/qsignal_p.h b/libpyside/qsignal_p.h
index b4e4ab8..467acb5 100644
--- a/libpyside/qsignal_p.h
+++ b/libpyside/qsignal_p.h
@@ -29,13 +29,25 @@ extern "C"
{
extern PyTypeObject PySideSignalType;
+ struct SignalData {
+ PyObject_HEAD
+ bool initialized;
+ char* signalName;
+ char** signatures;
+ int signaturesSize;
+ PyObject* homonymousMethod;
+ };
+
+ struct PySideSignalInstanceData;
struct PySideSignalInstanceDataPrivate {
char* signalName;
char* signature;
PyObject* source;
PyObject* homonymousMethod;
- PyObject* next;
+ PySideSignalInstanceData* next;
};
+
+
}; //extern "C"
namespace PySide