Fixed signal connection with native slot.
Reviewer: Hugo Parente Lima <hugo.lima@openbossa.org>,
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
d699a3abed
commit
6b70a1362c
3 changed files with 31 additions and 16 deletions
|
|
@ -56,7 +56,7 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QMetaObject* metaObject = receiver->metaObject();
|
const QMetaObject* metaObject = receiver->metaObject();
|
||||||
const QByteArray callbackSig = PySide::getCallbackSignature(signal, callback, usingGlobalReceiver).toAscii();
|
const QByteArray callbackSig = PySide::getCallbackSignature(signal, receiver, callback, usingGlobalReceiver).toAscii();
|
||||||
const char* slot = callbackSig.constData();
|
const char* slot = callbackSig.constData();
|
||||||
int slotIndex = metaObject->indexOfSlot(slot);
|
int slotIndex = metaObject->indexOfSlot(slot);
|
||||||
if (slotIndex == -1) {
|
if (slotIndex == -1) {
|
||||||
|
|
@ -103,7 +103,7 @@ static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObj
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QMetaObject* metaObject = receiver->metaObject();
|
const QMetaObject* metaObject = receiver->metaObject();
|
||||||
const QByteArray callbackSig = PySide::getCallbackSignature(signal, callback, usingGlobalReceiver).toAscii();
|
const QByteArray callbackSig = PySide::getCallbackSignature(signal, receiver, callback, usingGlobalReceiver).toAscii();
|
||||||
QByteArray qtSlotName(callbackSig);
|
QByteArray qtSlotName(callbackSig);
|
||||||
qtSlotName = qtSlotName.prepend('1');
|
qtSlotName = qtSlotName.prepend('1');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,12 +104,13 @@ static QString codeCallbackName(PyObject* callback, const QString& funcName)
|
||||||
return funcName+QString::number(quint64(callback), 16);
|
return funcName+QString::number(quint64(callback), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PySide::getCallbackSignature(const char* signal, PyObject* callback, bool encodeName)
|
QString PySide::getCallbackSignature(const char* signal, QObject* receiver, PyObject* callback, bool encodeName)
|
||||||
{
|
{
|
||||||
QString functionName;
|
QString functionName;
|
||||||
|
QString signature;
|
||||||
|
QStringList args;
|
||||||
int numArgs = -1;
|
int numArgs = -1;
|
||||||
bool useSelf = false;
|
bool useSelf = false;
|
||||||
|
|
||||||
bool isMethod = PyMethod_Check(callback);
|
bool isMethod = PyMethod_Check(callback);
|
||||||
bool isFunction = PyFunction_Check(callback);
|
bool isFunction = PyFunction_Check(callback);
|
||||||
|
|
||||||
|
|
@ -123,25 +124,41 @@ QString PySide::getCallbackSignature(const char* signal, PyObject* callback, boo
|
||||||
functionName = ((PyCFunctionObject*)callback)->m_ml->ml_name;
|
functionName = ((PyCFunctionObject*)callback)->m_ml->ml_name;
|
||||||
useSelf = ((PyCFunctionObject*)callback)->m_self;
|
useSelf = ((PyCFunctionObject*)callback)->m_self;
|
||||||
int flags = ((PyCFunctionObject*)callback)->m_ml->ml_flags;
|
int flags = ((PyCFunctionObject*)callback)->m_ml->ml_flags;
|
||||||
if (flags & METH_O)
|
|
||||||
numArgs = 1;
|
if (receiver) {
|
||||||
else if (flags & METH_VARARGS)
|
//Search for signature on metaobject
|
||||||
numArgs = -1;
|
const QMetaObject *mo = receiver->metaObject();
|
||||||
else if (flags & METH_NOARGS)
|
for(int i=0; i < mo->methodCount(); i++) {
|
||||||
numArgs = 0;
|
QMetaMethod me = mo->method(i);
|
||||||
|
if (QString(me.signature()).startsWith(functionName)) {
|
||||||
|
numArgs = me.parameterTypes().size()+1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numArgs == -1) {
|
||||||
|
if (flags & METH_O)
|
||||||
|
numArgs = 1;
|
||||||
|
else if (flags & METH_VARARGS)
|
||||||
|
numArgs = -1;
|
||||||
|
else if (flags & METH_NOARGS)
|
||||||
|
numArgs = 0;
|
||||||
|
}
|
||||||
} else if (PyCallable_Check(callback)) {
|
} else if (PyCallable_Check(callback)) {
|
||||||
functionName = "__callback"+QString::number((size_t)callback);
|
functionName = "__callback"+QString::number((size_t)callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(!functionName.isEmpty());
|
Q_ASSERT(!functionName.isEmpty());
|
||||||
|
|
||||||
QString signature;
|
bool isShortCircuit = false;
|
||||||
|
|
||||||
if (encodeName)
|
if (encodeName)
|
||||||
signature = codeCallbackName(callback, functionName);
|
signature = codeCallbackName(callback, functionName);
|
||||||
else
|
else
|
||||||
signature = functionName;
|
signature = functionName;
|
||||||
|
|
||||||
bool isShortCircuit;
|
args = getArgsFromSignature(signal, &isShortCircuit);
|
||||||
QStringList args = getArgsFromSignature(signal, &isShortCircuit);
|
|
||||||
|
|
||||||
if (!isShortCircuit) {
|
if (!isShortCircuit) {
|
||||||
signature.append('(');
|
signature.append('(');
|
||||||
|
|
@ -313,10 +330,8 @@ int PySide::SignalManager::qt_metacall(QObject* object, QMetaObject::Call call,
|
||||||
} else {
|
} else {
|
||||||
// call python slot
|
// call python slot
|
||||||
Shiboken::GilState gil;
|
Shiboken::GilState gil;
|
||||||
|
|
||||||
QList<QByteArray> paramTypes = method.parameterTypes();
|
QList<QByteArray> paramTypes = method.parameterTypes();
|
||||||
PyObject* self = Shiboken::BindingManager::instance().retrieveWrapper(object);
|
PyObject* self = Shiboken::BindingManager::instance().retrieveWrapper(object);
|
||||||
|
|
||||||
Shiboken::AutoDecRef preparedArgs(PyTuple_New(paramTypes.count()));
|
Shiboken::AutoDecRef preparedArgs(PyTuple_New(paramTypes.count()));
|
||||||
|
|
||||||
for (int i = 0, max = paramTypes.count(); i < max; ++i) {
|
for (int i = 0, max = paramTypes.count(); i < max; ++i) {
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ private:
|
||||||
|
|
||||||
PYSIDE_API bool isSignal(const char* signal);
|
PYSIDE_API bool isSignal(const char* signal);
|
||||||
PYSIDE_API bool checkSignal(const char* signal);
|
PYSIDE_API bool checkSignal(const char* signal);
|
||||||
PYSIDE_API QString getCallbackSignature(const char* signal, PyObject* callback, bool encodeName);
|
PYSIDE_API QString getCallbackSignature(const char* signal, QObject* receiver, PyObject* callback, bool encodeName);
|
||||||
QStringList getArgsFromSignature(const char* signature, bool* isShortCircuit = 0);
|
QStringList getArgsFromSignature(const char* signature, bool* isShortCircuit = 0);
|
||||||
|
|
||||||
class PYSIDE_API SignalManager
|
class PYSIDE_API SignalManager
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue