Renamed qsignal, qslot, qproperty files to pyside*.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Lauro Neto <lauro.neto@openbossa.org>
This commit is contained in:
parent
c7945787c5
commit
4cd7a240d8
14 changed files with 198 additions and 167 deletions
|
|
@ -28,14 +28,14 @@ static bool qobjectConnect(QObject* source, const char* signal, QObject* receive
|
||||||
if (!signal || !slot)
|
if (!signal || !slot)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!PySide::checkSignal(signal))
|
if (!PySide::Signal::checkQtSignal(signal))
|
||||||
return false;
|
return false;
|
||||||
signal++;
|
signal++;
|
||||||
|
|
||||||
if (!PySide::SignalManager::registerMetaMethod(source, signal, QMetaMethod::Signal))
|
if (!PySide::SignalManager::registerMetaMethod(source, signal, QMetaMethod::Signal))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool isSignal = PySide::isSignal(slot);
|
bool isSignal = PySide::Signal::isQtSignal(slot);
|
||||||
slot++;
|
slot++;
|
||||||
PySide::SignalManager::registerMetaMethod(receiver, slot, isSignal ? QMetaMethod::Signal : QMetaMethod::Slot);
|
PySide::SignalManager::registerMetaMethod(receiver, slot, isSignal ? QMetaMethod::Signal : QMetaMethod::Slot);
|
||||||
return QObject::connect(source, signal - 1, receiver, slot - 1, type);
|
return QObject::connect(source, signal - 1, receiver, slot - 1, type);
|
||||||
|
|
@ -43,7 +43,7 @@ static bool qobjectConnect(QObject* source, const char* signal, QObject* receive
|
||||||
|
|
||||||
static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject* callback, Qt::ConnectionType type)
|
static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject* callback, Qt::ConnectionType type)
|
||||||
{
|
{
|
||||||
if (!signal || !PySide::checkSignal(signal))
|
if (!signal || !PySide::Signal::checkQtSignal(signal))
|
||||||
return false;
|
return false;
|
||||||
signal++;
|
signal++;
|
||||||
|
|
||||||
|
|
@ -62,7 +62,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, receiver, callback, usingGlobalReceiver).toAscii();
|
const QByteArray callbackSig = PySide::Signal::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) {
|
||||||
|
|
@ -97,7 +97,7 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject
|
||||||
|
|
||||||
static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObject* callback)
|
static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObject* callback)
|
||||||
{
|
{
|
||||||
if (!PySide::checkSignal(signal))
|
if (!PySide::Signal::checkQtSignal(signal))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
PySide::SignalManager& signalManager = PySide::SignalManager::instance();
|
PySide::SignalManager& signalManager = PySide::SignalManager::instance();
|
||||||
|
|
@ -110,7 +110,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, receiver, callback, usingGlobalReceiver).toAscii();
|
const QByteArray callbackSig = PySide::Signal::getCallbackSignature(signal, receiver, callback, usingGlobalReceiver).toAscii();
|
||||||
QByteArray qtSlotName(callbackSig);
|
QByteArray qtSlotName(callbackSig);
|
||||||
qtSlotName = qtSlotName.prepend('1');
|
qtSlotName = qtSlotName.prepend('1');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ set(libpyside_SRC
|
||||||
dynamicqmetaobject.cpp
|
dynamicqmetaobject.cpp
|
||||||
signalmanager.cpp
|
signalmanager.cpp
|
||||||
globalreceiver.cpp
|
globalreceiver.cpp
|
||||||
qsignal.cpp
|
pysidesignal.cpp
|
||||||
qslot.cpp
|
pysideslot.cpp
|
||||||
qproperty.cpp
|
pysideproperty.cpp
|
||||||
pyside.cpp
|
pyside.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -37,8 +37,8 @@ set(libpyside_HEADERS
|
||||||
pysidemacros.h
|
pysidemacros.h
|
||||||
signalmanager.h
|
signalmanager.h
|
||||||
pyside.h
|
pyside.h
|
||||||
qsignal.h
|
pysidesignal.h
|
||||||
qproperty.h
|
pysideproperty.h
|
||||||
)
|
)
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,11 @@
|
||||||
|
|
||||||
#include "dynamicqmetaobject.h"
|
#include "dynamicqmetaobject.h"
|
||||||
#include "dynamicqmetaobject_p.h"
|
#include "dynamicqmetaobject_p.h"
|
||||||
|
#include "pysidesignal.h"
|
||||||
|
#include "pysidesignal_p.h"
|
||||||
|
#include "pysideproperty.h"
|
||||||
|
#include "pysideproperty_p.h"
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
@ -32,11 +37,6 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
|
|
||||||
#include "qsignal.h"
|
|
||||||
#include "qsignal_p.h"
|
|
||||||
#include "qproperty.h"
|
|
||||||
#include "qproperty_p.h"
|
|
||||||
|
|
||||||
#define MAX_SIGNALS_COUNT 50
|
#define MAX_SIGNALS_COUNT 50
|
||||||
#define MAX_SLOTS_COUNT 50
|
#define MAX_SLOTS_COUNT 50
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,14 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "pyside.h"
|
#include "pyside.h"
|
||||||
|
#include "signalmanager.h"
|
||||||
|
#include "pysideproperty_p.h"
|
||||||
|
#include "pysideproperty.h"
|
||||||
|
#include "pysidesignal.h"
|
||||||
|
#include "pysidesignal_p.h"
|
||||||
|
#include "pysideslot_p.h"
|
||||||
|
|
||||||
#include <basewrapper.h>
|
#include <basewrapper.h>
|
||||||
#include <conversions.h>
|
#include <conversions.h>
|
||||||
#include <typeresolver.h>
|
#include <typeresolver.h>
|
||||||
|
|
@ -29,12 +35,6 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <QStack>
|
#include <QStack>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include "signalmanager.h"
|
|
||||||
#include "qproperty_p.h"
|
|
||||||
#include "qproperty.h"
|
|
||||||
#include "qsignal.h"
|
|
||||||
#include "qsignal_p.h"
|
|
||||||
#include "qslot_p.h"
|
|
||||||
|
|
||||||
static QStack<PySide::CleanupFunction> cleanupFunctionList;
|
static QStack<PySide::CleanupFunction> cleanupFunctionList;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,16 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <shiboken.h>
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
#include "pysideproperty.h"
|
||||||
|
#include "pysideproperty_p.h"
|
||||||
|
#include "dynamicqmetaobject_p.h"
|
||||||
|
#include "pysidesignal.h"
|
||||||
|
#include "pysidesignal_p.h"
|
||||||
|
|
||||||
|
#include <shiboken.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "qproperty.h"
|
|
||||||
#include "qproperty_p.h"
|
|
||||||
#include "dynamicqmetaobject_p.h"
|
|
||||||
#include "qsignal.h"
|
|
||||||
#include "qsignal_p.h"
|
|
||||||
|
|
||||||
#define QPROPERTY_CLASS_NAME "Property"
|
#define QPROPERTY_CLASS_NAME "Property"
|
||||||
|
|
||||||
|
|
@ -19,17 +19,16 @@
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <shiboken.h>
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <QDebug>
|
#include "pysidesignal.h"
|
||||||
|
#include "pysidesignal_p.h"
|
||||||
#include "qsignal.h"
|
|
||||||
#include "qsignal_p.h"
|
|
||||||
#include "signalmanager.h"
|
#include "signalmanager.h"
|
||||||
|
|
||||||
|
#include <shiboken.h>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#define SIGNAL_CLASS_NAME "Signal"
|
#define SIGNAL_CLASS_NAME "Signal"
|
||||||
#define QT_SIGNAL_SENTINEL "2"
|
#define QT_SIGNAL_SENTINEL '2'
|
||||||
|
|
||||||
|
|
||||||
namespace PySide { namespace Signal {
|
namespace PySide { namespace Signal {
|
||||||
|
|
@ -665,7 +664,7 @@ PyObject* buildQtCompatible(const char* signature)
|
||||||
{
|
{
|
||||||
char* qtSignature;
|
char* qtSignature;
|
||||||
qtSignature = reinterpret_cast<char*>(malloc(strlen(signature)+2));
|
qtSignature = reinterpret_cast<char*>(malloc(strlen(signature)+2));
|
||||||
sprintf(qtSignature, QT_SIGNAL_SENTINEL"%s", signature);
|
sprintf(qtSignature, "%c%s", QT_SIGNAL_SENTINEL, signature);
|
||||||
PyObject* ret = PyString_FromString(qtSignature);
|
PyObject* ret = PyString_FromString(qtSignature);
|
||||||
free(qtSignature);
|
free(qtSignature);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -700,6 +699,118 @@ const char** getSignatures(PyObject* signal, int *size)
|
||||||
return (const char**) self->signatures;
|
return (const char**) self->signatures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList getArgsFromSignature(const char* signature, bool* isShortCircuit)
|
||||||
|
{
|
||||||
|
QString qsignature(signature);
|
||||||
|
QStringList result;
|
||||||
|
QRegExp splitRegex("\\s*,\\s*");
|
||||||
|
|
||||||
|
if (isShortCircuit)
|
||||||
|
*isShortCircuit = !qsignature.contains('(');
|
||||||
|
if (qsignature.contains("()") || qsignature.contains("(void)")) {
|
||||||
|
return result;
|
||||||
|
} else if (qsignature.contains('(')) {
|
||||||
|
static QRegExp regex(".+\\((.*)\\)");
|
||||||
|
//get args types
|
||||||
|
QString types = qsignature.replace(regex, "\\1");
|
||||||
|
result = types.split(splitRegex);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString getCallbackSignature(const char* signal, QObject* receiver, PyObject* callback, bool encodeName)
|
||||||
|
{
|
||||||
|
QString functionName;
|
||||||
|
QString signature;
|
||||||
|
QStringList args;
|
||||||
|
int numArgs = -1;
|
||||||
|
bool useSelf = false;
|
||||||
|
bool isMethod = PyMethod_Check(callback);
|
||||||
|
bool isFunction = PyFunction_Check(callback);
|
||||||
|
|
||||||
|
if (isMethod || isFunction) {
|
||||||
|
PyObject* function = isMethod ? PyMethod_GET_FUNCTION(callback) : callback;
|
||||||
|
PyCodeObject* objCode = reinterpret_cast<PyCodeObject*>(PyFunction_GET_CODE(function));
|
||||||
|
functionName = PyString_AS_STRING(objCode->co_name);
|
||||||
|
useSelf = isMethod;
|
||||||
|
numArgs = objCode->co_flags & CO_VARARGS ? -1 : objCode->co_argcount;
|
||||||
|
} else if (PyCFunction_Check(callback)) {
|
||||||
|
functionName = ((PyCFunctionObject*)callback)->m_ml->ml_name;
|
||||||
|
useSelf = ((PyCFunctionObject*)callback)->m_self;
|
||||||
|
int flags = ((PyCFunctionObject*)callback)->m_ml->ml_flags;
|
||||||
|
|
||||||
|
if (receiver) {
|
||||||
|
//Search for signature on metaobject
|
||||||
|
const QMetaObject *mo = receiver->metaObject();
|
||||||
|
for(int i=0; i < mo->methodCount(); i++) {
|
||||||
|
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)) {
|
||||||
|
functionName = "__callback"+QString::number((size_t)callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_ASSERT(!functionName.isEmpty());
|
||||||
|
|
||||||
|
bool isShortCircuit = false;
|
||||||
|
|
||||||
|
if (encodeName)
|
||||||
|
signature = codeCallbackName(callback, functionName);
|
||||||
|
else
|
||||||
|
signature = functionName;
|
||||||
|
|
||||||
|
args = getArgsFromSignature(signal, &isShortCircuit);
|
||||||
|
|
||||||
|
if (!isShortCircuit) {
|
||||||
|
signature.append('(');
|
||||||
|
if (numArgs == -1)
|
||||||
|
numArgs = std::numeric_limits<int>::max();
|
||||||
|
while (args.count() && args.count() > numArgs - useSelf) {
|
||||||
|
args.removeLast();
|
||||||
|
}
|
||||||
|
signature.append(args.join(","));
|
||||||
|
signature.append(')');
|
||||||
|
}
|
||||||
|
return signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isQtSignal(const char* signal)
|
||||||
|
{
|
||||||
|
return (signal && signal[0] == QT_SIGNAL_SENTINEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkQtSignal(const char* signal)
|
||||||
|
{
|
||||||
|
if (!isQtSignal(signal)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Use the function PySide.QtCore.SIGNAL on signals");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString codeCallbackName(PyObject* callback, const QString& funcName)
|
||||||
|
{
|
||||||
|
if (PyMethod_Check(callback)) {
|
||||||
|
PyObject *self = PyMethod_GET_SELF(callback);
|
||||||
|
PyObject *func = PyMethod_GET_FUNCTION(callback);
|
||||||
|
return funcName + QString::number(quint64(self), 16) + QString::number(quint64(func), 16);
|
||||||
|
} else
|
||||||
|
return funcName + QString::number(quint64(callback), 16);
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace Signal
|
} //namespace Signal
|
||||||
} //namespace PySide
|
} //namespace PySide
|
||||||
|
|
||||||
|
|
@ -23,9 +23,12 @@
|
||||||
#ifndef PYSIDE_SIGNAL_H
|
#ifndef PYSIDE_SIGNAL_H
|
||||||
#define PYSIDE_SIGNAL_H
|
#define PYSIDE_SIGNAL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
#include <pysidemacros.h>
|
#include <pysidemacros.h>
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
namespace Shiboken
|
namespace Shiboken
|
||||||
{
|
{
|
||||||
|
|
@ -110,6 +113,38 @@ PYSIDE_API void updateSourceObject(PyObject* source);
|
||||||
**/
|
**/
|
||||||
PYSIDE_API void addSignalToWrapper(Shiboken::SbkBaseWrapperType* wrapperType, const char* signalName, PySideSignal* signal);
|
PYSIDE_API void addSignalToWrapper(Shiboken::SbkBaseWrapperType* wrapperType, const char* signalName, PySideSignal* signal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function verify if the signature is a QtSignal base on SIGNAL flag
|
||||||
|
* @param signature The signal signature
|
||||||
|
* @return Return true if this is a Qt Signal of false if not
|
||||||
|
**/
|
||||||
|
PYSIDE_API bool isQtSignal(const char* signature);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is similar as isQtSignal but this reaise a Python error if this faisl
|
||||||
|
* @param signature The signal signature
|
||||||
|
* @return Return true if this is a Qt Signal of false if not
|
||||||
|
**/
|
||||||
|
PYSIDE_API bool checkQtSignal(const char* signature);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is used to retrieve the signature base on Signal and receiver callback
|
||||||
|
* @param signature The signal signature
|
||||||
|
* @param receiver The QObject which will receiver the signal
|
||||||
|
* @param callback Callback function which will connect with signal
|
||||||
|
* @param encodeName Used to specify if the returned signature will be encoded with Qt signal/slot style
|
||||||
|
* @return Return the callback signature
|
||||||
|
**/
|
||||||
|
PYSIDE_API QString getCallbackSignature(const char* signal, QObject* receiver, PyObject* callback, bool encodeName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to parese the signature and return a list of argument types
|
||||||
|
* @param signature The signal signature
|
||||||
|
* @param isShortCircuit If this is a shortCircuit(python<->python) signal
|
||||||
|
* @return Return true if this is a Qt Signal of false if not
|
||||||
|
**/
|
||||||
|
QStringList getArgsFromSignature(const char* signature, bool* isShortCircuit = 0);
|
||||||
|
|
||||||
} //namespace Signal
|
} //namespace Signal
|
||||||
} //namespace PySide
|
} //namespace PySide
|
||||||
|
|
||||||
|
|
@ -51,10 +51,12 @@ extern "C"
|
||||||
}; //extern "C"
|
}; //extern "C"
|
||||||
|
|
||||||
namespace PySide { namespace Signal {
|
namespace PySide { namespace Signal {
|
||||||
|
|
||||||
void init(PyObject* module);
|
void init(PyObject* module);
|
||||||
bool connect(PyObject* source, const char* signal, PyObject* callback);
|
bool connect(PyObject* source, const char* signal, PyObject* callback);
|
||||||
char* getTypeName(PyObject*);
|
char* getTypeName(PyObject*);
|
||||||
const char** getSignatures(PyObject* self, int *size);
|
const char** getSignatures(PyObject* self, int *size);
|
||||||
|
QString codeCallbackName(PyObject* callback, const QString& funcName);
|
||||||
|
|
||||||
}} //namespace PySide
|
}} //namespace PySide
|
||||||
|
|
||||||
|
|
@ -20,10 +20,11 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "dynamicqmetaobject_p.h"
|
||||||
|
#include "pysidesignal_p.h"
|
||||||
|
|
||||||
#include <shiboken.h>
|
#include <shiboken.h>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "dynamicqmetaobject_p.h"
|
|
||||||
#include "qsignal_p.h"
|
|
||||||
|
|
||||||
#define SLOT_DEC_NAME "Slot"
|
#define SLOT_DEC_NAME "Slot"
|
||||||
|
|
||||||
|
|
@ -21,6 +21,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "signalmanager.h"
|
#include "signalmanager.h"
|
||||||
|
#include "pysidesignal.h"
|
||||||
|
#include "pysideproperty.h"
|
||||||
|
#include "pysideproperty_p.h"
|
||||||
|
#include "pyside.h"
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
@ -33,10 +37,6 @@
|
||||||
#include <basewrapper.h>
|
#include <basewrapper.h>
|
||||||
#include <conversions.h>
|
#include <conversions.h>
|
||||||
|
|
||||||
#include "qproperty.h"
|
|
||||||
#include "qproperty_p.h"
|
|
||||||
#include "pyside.h"
|
|
||||||
|
|
||||||
#if QSLOT_CODE != 1 || QSIGNAL_CODE != 2
|
#if QSLOT_CODE != 1 || QSIGNAL_CODE != 2
|
||||||
#error QSLOT_CODE and/or QSIGNAL_CODE changed! change the hardcoded stuff to the correct value!
|
#error QSLOT_CODE and/or QSIGNAL_CODE changed! change the hardcoded stuff to the correct value!
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -105,124 +105,8 @@ struct Converter<PySide::PyObjectWrapper>
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using namespace PySide;
|
using namespace PySide;
|
||||||
|
|
||||||
bool PySide::isSignal(const char* signal)
|
|
||||||
{
|
|
||||||
return (signal && signal[0] == PYSIDE_SIGNAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PySide::checkSignal(const char* signal)
|
|
||||||
{
|
|
||||||
if (!signal)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (signal[0] != PYSIDE_SIGNAL) {
|
|
||||||
PyErr_SetString(PyExc_TypeError, "Use the function PySide.QtCore.SIGNAL on signals");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString codeCallbackName(PyObject* callback, const QString& funcName)
|
|
||||||
{
|
|
||||||
if (PyMethod_Check(callback)) {
|
|
||||||
PyObject *self = PyMethod_GET_SELF(callback);
|
|
||||||
PyObject *func = PyMethod_GET_FUNCTION(callback);
|
|
||||||
return funcName + QString::number(quint64(self), 16) + QString::number(quint64(func), 16);
|
|
||||||
} else
|
|
||||||
return funcName+QString::number(quint64(callback), 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PySide::getCallbackSignature(const char* signal, QObject* receiver, PyObject* callback, bool encodeName)
|
|
||||||
{
|
|
||||||
QString functionName;
|
|
||||||
QString signature;
|
|
||||||
QStringList args;
|
|
||||||
int numArgs = -1;
|
|
||||||
bool useSelf = false;
|
|
||||||
bool isMethod = PyMethod_Check(callback);
|
|
||||||
bool isFunction = PyFunction_Check(callback);
|
|
||||||
|
|
||||||
if (isMethod || isFunction) {
|
|
||||||
PyObject* function = isMethod ? PyMethod_GET_FUNCTION(callback) : callback;
|
|
||||||
PyCodeObject* objCode = reinterpret_cast<PyCodeObject*>(PyFunction_GET_CODE(function));
|
|
||||||
functionName = PyString_AS_STRING(objCode->co_name);
|
|
||||||
useSelf = isMethod;
|
|
||||||
numArgs = objCode->co_flags & CO_VARARGS ? -1 : objCode->co_argcount;
|
|
||||||
} else if (PyCFunction_Check(callback)) {
|
|
||||||
functionName = ((PyCFunctionObject*)callback)->m_ml->ml_name;
|
|
||||||
useSelf = ((PyCFunctionObject*)callback)->m_self;
|
|
||||||
int flags = ((PyCFunctionObject*)callback)->m_ml->ml_flags;
|
|
||||||
|
|
||||||
if (receiver) {
|
|
||||||
//Search for signature on metaobject
|
|
||||||
const QMetaObject *mo = receiver->metaObject();
|
|
||||||
for(int i=0; i < mo->methodCount(); i++) {
|
|
||||||
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)) {
|
|
||||||
functionName = "__callback"+QString::number((size_t)callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_ASSERT(!functionName.isEmpty());
|
|
||||||
|
|
||||||
bool isShortCircuit = false;
|
|
||||||
|
|
||||||
if (encodeName)
|
|
||||||
signature = codeCallbackName(callback, functionName);
|
|
||||||
else
|
|
||||||
signature = functionName;
|
|
||||||
|
|
||||||
args = getArgsFromSignature(signal, &isShortCircuit);
|
|
||||||
|
|
||||||
if (!isShortCircuit) {
|
|
||||||
signature.append('(');
|
|
||||||
if (numArgs == -1)
|
|
||||||
numArgs = std::numeric_limits<int>::max();
|
|
||||||
while (args.count() && args.count() > numArgs - useSelf) {
|
|
||||||
args.removeLast();
|
|
||||||
}
|
|
||||||
signature.append(args.join(","));
|
|
||||||
signature.append(')');
|
|
||||||
}
|
|
||||||
return signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList PySide::getArgsFromSignature(const char* signature, bool* isShortCircuit)
|
|
||||||
{
|
|
||||||
QString qsignature(signature);
|
|
||||||
QStringList result;
|
|
||||||
QRegExp splitRegex("\\s*,\\s*");
|
|
||||||
|
|
||||||
if (isShortCircuit)
|
|
||||||
*isShortCircuit = !qsignature.contains('(');
|
|
||||||
if (qsignature.contains("()") || qsignature.contains("(void)")) {
|
|
||||||
return result;
|
|
||||||
} else if (qsignature.contains('(')) {
|
|
||||||
static QRegExp regex(".+\\((.*)\\)");
|
|
||||||
//get args types
|
|
||||||
QString types = qsignature.replace(regex, "\\1");
|
|
||||||
result = types.split(splitRegex);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SignalManager::SignalManagerPrivate
|
struct SignalManager::SignalManagerPrivate
|
||||||
{
|
{
|
||||||
GlobalReceiver m_globalReceiver;
|
GlobalReceiver m_globalReceiver;
|
||||||
|
|
@ -335,14 +219,14 @@ static bool emitNormalSignal(QObject* source, int signalIndex, const char* signa
|
||||||
|
|
||||||
bool SignalManager::emitSignal(QObject* source, const char* signal, PyObject* args)
|
bool SignalManager::emitSignal(QObject* source, const char* signal, PyObject* args)
|
||||||
{
|
{
|
||||||
if (!checkSignal(signal))
|
if (!Signal::checkQtSignal(signal))
|
||||||
return false;
|
return false;
|
||||||
signal++;
|
signal++;
|
||||||
|
|
||||||
int signalIndex = source->metaObject()->indexOfSignal(signal);
|
int signalIndex = source->metaObject()->indexOfSignal(signal);
|
||||||
if (signalIndex != -1) {
|
if (signalIndex != -1) {
|
||||||
bool isShortCircuit;
|
bool isShortCircuit;
|
||||||
QStringList argTypes = getArgsFromSignature(signal, &isShortCircuit);
|
QStringList argTypes = Signal::getArgsFromSignature(signal, &isShortCircuit);
|
||||||
|
|
||||||
if (isShortCircuit)
|
if (isShortCircuit)
|
||||||
return emitShortCircuitSignal(source, signalIndex, args);
|
return emitShortCircuitSignal(source, signalIndex, args);
|
||||||
|
|
|
||||||
|
|
@ -45,13 +45,9 @@ public:
|
||||||
operator PyObject*() const;
|
operator PyObject*() const;
|
||||||
private:
|
private:
|
||||||
PyObject* m_me;
|
PyObject* m_me;
|
||||||
|
void* m_data; //future
|
||||||
};
|
};
|
||||||
|
|
||||||
PYSIDE_API bool isSignal(const char* signal);
|
|
||||||
PYSIDE_API bool checkSignal(const char* signal);
|
|
||||||
PYSIDE_API QString getCallbackSignature(const char* signal, QObject* receiver, PyObject* callback, bool encodeName);
|
|
||||||
QStringList getArgsFromSignature(const char* signature, bool* isShortCircuit = 0);
|
|
||||||
|
|
||||||
class PYSIDE_API SignalManager
|
class PYSIDE_API SignalManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -76,6 +72,7 @@ public:
|
||||||
private:
|
private:
|
||||||
struct SignalManagerPrivate;
|
struct SignalManagerPrivate;
|
||||||
SignalManagerPrivate* m_d;
|
SignalManagerPrivate* m_d;
|
||||||
|
|
||||||
SignalManager();
|
SignalManager();
|
||||||
~SignalManager();
|
~SignalManager();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue