aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-09-16 14:14:45 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-09-16 17:12:34 -0300
commit551f6b9c7240d1f68e50edcec0fc41969beaef1d (patch)
tree3e6c2878b7b59f3aeb129a5581529ddf4627e760
parentc06110168c39e5c44b9b11ff13fd6f9795199df3 (diff)
Fixed connection cleanup function.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--PySide/QtCore/glue/qobject_connect.cpp11
-rw-r--r--PySide/QtCore/typesystem_core.xml6
-rw-r--r--libpyside/dynamicqmetaobject.cpp8
-rw-r--r--libpyside/globalreceiver.cpp26
4 files changed, 30 insertions, 21 deletions
diff --git a/PySide/QtCore/glue/qobject_connect.cpp b/PySide/QtCore/glue/qobject_connect.cpp
index b140374ec..cf7877912 100644
--- a/PySide/QtCore/glue/qobject_connect.cpp
+++ b/PySide/QtCore/glue/qobject_connect.cpp
@@ -75,6 +75,8 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject
slotIndex = metaObject->indexOfSlot(slot);
}
if (QMetaObject::connect(source, signalIndex, receiver, slotIndex, type)) {
+ if (usingGlobalReceiver)
+ signalManager.globalReceiverConnectNotify(source, slotIndex);
#ifndef AVOID_PROTECTED_HACK
source->connectNotify(signal - 1);
#else
@@ -82,8 +84,6 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject
// connectNotify when avoiding the protected hack.
reinterpret_cast<QObjectWrapper*>(source)->connectNotify(signal - 1);
#endif
- if (usingGlobalReceiver)
- signalManager.globalReceiverConnectNotify(source, slotIndex);
return true;
}
@@ -114,6 +114,13 @@ static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObj
if (usingGlobalReceiver) {
int slotIndex = metaObject->indexOfSlot(callbackSig.constData());
signalManager.globalReceiverDisconnectNotify(source, slotIndex);
+ #ifndef AVOID_PROTECTED_HACK
+ source->disconnectNotify(signal - 1);
+ #else
+ // Need to cast to QObjectWrapper* and call the public version of
+ // connectNotify when avoiding the protected hack.
+ reinterpret_cast<QObjectWrapper*>(source)->disconnectNotify(signal - 1);
+ #endif
}
return true;
}
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 4d7e3e4f7..c0b333ff4 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -1230,8 +1230,10 @@
<inject-code class="target" position="beginning">
// Avoid return +1 because SignalManager connect to "destroyed()" signal to control object timelife
int ret = %CPPSELF.%FUNCTION_NAME(%1);
- if (ret > 0 &amp;&amp; strcmp(%1, SIGNAL(destroyed())) == 0 &amp;&amp; PySide::SignalManager::instance().hasConnectionWith(%CPPSELF))
- ret--;
+ if (ret > 0 &amp;&amp; ((strcmp(%1, SIGNAL(destroyed())) == 0) || (strcmp(%1, SIGNAL(destroyed(QObject*))) == 0))) {
+ if (PySide::SignalManager::instance().hasConnectionWith(%CPPSELF))
+ ret--;
+ }
%PYARG_0 = %CONVERTTOPYTHON[int](ret);
</inject-code>
</modify-function>
diff --git a/libpyside/dynamicqmetaobject.cpp b/libpyside/dynamicqmetaobject.cpp
index c2e7f04bb..b97ae0dc3 100644
--- a/libpyside/dynamicqmetaobject.cpp
+++ b/libpyside/dynamicqmetaobject.cpp
@@ -322,11 +322,10 @@ void DynamicQMetaObject::addSlot(const char* slot, const char* type)
//search for a empty space
MethodData blank;
i = qFind(m_slots.begin(), m_slots.end(), blank);
- if (i != m_slots.end()) {
+ if (i != m_slots.end())
*i = MethodData(slot, type);
- } else {
+ else
m_slots << MethodData(slot, type);
- }
updateMetaObject();
}
@@ -438,7 +437,6 @@ void DynamicQMetaObject::writeMethodsData(QLinkedList<MethodData>& methods,
if (iMethod != methods.end() && ((*iMethod).signature().size() > 0) ) {
(*data)[index++] = registerString((*iMethod).signature(), strings); // func name
mType = (*iMethod).type();
- iMethod++;
} else {
(*data)[index++] = null_index; // func name
}
@@ -446,6 +444,8 @@ void DynamicQMetaObject::writeMethodsData(QLinkedList<MethodData>& methods,
(*data)[index++] = (mType.size() > 0 ? registerString(mType, strings) : null_index); // normalized type
(*data)[index++] = null_index; // tags
(*data)[index++] = flags;
+ if (iMethod != methods.end())
+ iMethod++;
}
*prtIndex = index;
diff --git a/libpyside/globalreceiver.cpp b/libpyside/globalreceiver.cpp
index 2dd82aab4..2c126044e 100644
--- a/libpyside/globalreceiver.cpp
+++ b/libpyside/globalreceiver.cpp
@@ -107,7 +107,6 @@ DynamicSlotData::~DynamicSlotData()
Py_DECREF(m_callback);
}
-
GlobalReceiver::GlobalReceiver()
: m_metaObject(GLOBAL_RECEIVER_CLASS_NAME, &QObject::staticMetaObject)
{
@@ -126,20 +125,23 @@ GlobalReceiver::~GlobalReceiver()
void GlobalReceiver::connectNotify(QObject* source, int slotId)
{
if (m_slotReceivers.contains(slotId)) {
- m_slotReceivers[slotId]->addRef(source);
+ DynamicSlotData* data = m_slotReceivers[slotId];
+ if (!data->hasRefTo(source))
+ QObject::connect(source, SIGNAL(destroyed(QObject*)), this, "1"RECEIVER_DESTROYED_SLOT_NAME);
+ data->addRef(source);
}
}
void GlobalReceiver::disconnectNotify(QObject* source, int slotId)
{
- if (m_slotReceivers.contains(slotId)) {
- QObject::disconnect(source, SIGNAL(destroyed(QObject*)), this, "1"RECEIVER_DESTROYED_SLOT_NAME);
-
+ if (m_slotReceivers.contains(slotId)) {
DynamicSlotData *data = m_slotReceivers[slotId];
data->decRef(source);
- if (data->refCount() == 0) {
+ if (data->refCount() == 0)
removeSlot(slotId);
- }
+
+ if (!hasConnectionWith(source))
+ QObject::disconnect(source, SIGNAL(destroyed(QObject*)), this, "1"RECEIVER_DESTROYED_SLOT_NAME);
}
}
@@ -152,9 +154,8 @@ void GlobalReceiver::addSlot(const char* slot, PyObject* callback)
{
m_metaObject.addSlot(slot);
int slotId = m_metaObject.indexOfSlot(slot);
- if (!m_slotReceivers.contains(slotId)) {
+ if (!m_slotReceivers.contains(slotId))
m_slotReceivers[slotId] = new DynamicSlotData(slotId, callback);
- }
bool isShortCircuit = true;
for (int i = 0; slot[i]; ++i) {
@@ -167,6 +168,7 @@ void GlobalReceiver::addSlot(const char* slot, PyObject* callback)
if (isShortCircuit)
m_shortCircuitSlots << slotId;
+
Q_ASSERT(slotId >= QObject::staticMetaObject.methodCount());
}
@@ -236,12 +238,10 @@ int GlobalReceiver::qt_metacall(QMetaObject::Call call, int id, void** args)
retval = PyObject_CallObject(callback, preparedArgs);
}
- if (!retval) {
- qDebug() << "Error calling slot" << m_metaObject.method(id).signature();
+ if (!retval)
PyErr_Print();
- } else {
+ else
Py_DECREF(retval);
- }
return -1;
}