summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-10-29 18:53:42 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-11-03 10:29:31 -0300
commit4cd7a240d8db7de44b471a8ef0ed2f956addb743 (patch)
tree511ef8e13a689e73b788d6a1afc72578ccdbf9db
parentc7945787c556d2e3e40a1b9ef93147c640ee8ff6 (diff)
downloadpyside-4cd7a240d8db7de44b471a8ef0ed2f956addb743.tar.gz
pyside-4cd7a240d8db7de44b471a8ef0ed2f956addb743.tar.xz
pyside-4cd7a240d8db7de44b471a8ef0ed2f956addb743.zip
Renamed qsignal, qslot, qproperty files to pyside*.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Lauro Neto <lauro.neto@openbossa.org>
-rw-r--r--PySide/QtCore/glue/qobject_connect.cpp12
-rw-r--r--libpyside/CMakeLists.txt10
-rw-r--r--libpyside/dynamicqmetaobject.cpp10
-rw-r--r--libpyside/pyside.cpp14
-rw-r--r--libpyside/pysideproperty.cpp (renamed from libpyside/qproperty.cpp)13
-rw-r--r--libpyside/pysideproperty.h (renamed from libpyside/qproperty.h)0
-rw-r--r--libpyside/pysideproperty_p.h (renamed from libpyside/qproperty_p.h)0
-rw-r--r--libpyside/pysidesignal.cpp (renamed from libpyside/qsignal.cpp)125
-rw-r--r--libpyside/pysidesignal.h (renamed from libpyside/qsignal.h)37
-rw-r--r--libpyside/pysidesignal_p.h (renamed from libpyside/qsignal_p.h)2
-rw-r--r--libpyside/pysideslot.cpp (renamed from libpyside/qslot.cpp)5
-rw-r--r--libpyside/pysideslot_p.h (renamed from libpyside/qslot_p.h)0
-rw-r--r--libpyside/signalmanager.cpp128
-rw-r--r--libpyside/signalmanager.h7
14 files changed, 197 insertions, 166 deletions
diff --git a/PySide/QtCore/glue/qobject_connect.cpp b/PySide/QtCore/glue/qobject_connect.cpp
index b98a411..7702655 100644
--- a/PySide/QtCore/glue/qobject_connect.cpp
+++ b/PySide/QtCore/glue/qobject_connect.cpp
@@ -28,14 +28,14 @@ static bool qobjectConnect(QObject* source, const char* signal, QObject* receive
if (!signal || !slot)
return false;
- if (!PySide::checkSignal(signal))
+ if (!PySide::Signal::checkQtSignal(signal))
return false;
signal++;
if (!PySide::SignalManager::registerMetaMethod(source, signal, QMetaMethod::Signal))
return false;
- bool isSignal = PySide::isSignal(slot);
+ bool isSignal = PySide::Signal::isQtSignal(slot);
slot++;
PySide::SignalManager::registerMetaMethod(receiver, slot, isSignal ? QMetaMethod::Signal : QMetaMethod::Slot);
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)
{
- if (!signal || !PySide::checkSignal(signal))
+ if (!signal || !PySide::Signal::checkQtSignal(signal))
return false;
signal++;
@@ -62,7 +62,7 @@ static bool qobjectConnectCallback(QObject* source, const char* signal, PyObject
return false;
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();
int slotIndex = metaObject->indexOfSlot(slot);
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)
{
- if (!PySide::checkSignal(signal))
+ if (!PySide::Signal::checkQtSignal(signal))
return false;
PySide::SignalManager& signalManager = PySide::SignalManager::instance();
@@ -110,7 +110,7 @@ static bool qobjectDisconnectCallback(QObject* source, const char* signal, PyObj
return false;
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);
qtSlotName = qtSlotName.prepend('1');
diff --git a/libpyside/CMakeLists.txt b/libpyside/CMakeLists.txt
index aec0894..939bcc4 100644
--- a/libpyside/CMakeLists.txt
+++ b/libpyside/CMakeLists.txt
@@ -4,9 +4,9 @@ set(libpyside_SRC
dynamicqmetaobject.cpp
signalmanager.cpp
globalreceiver.cpp
-qsignal.cpp
-qslot.cpp
-qproperty.cpp
+pysidesignal.cpp
+pysideslot.cpp
+pysideproperty.cpp
pyside.cpp
)
@@ -37,8 +37,8 @@ set(libpyside_HEADERS
pysidemacros.h
signalmanager.h
pyside.h
- qsignal.h
- qproperty.h
+ pysidesignal.h
+ pysideproperty.h
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
diff --git a/libpyside/dynamicqmetaobject.cpp b/libpyside/dynamicqmetaobject.cpp
index 03153b3..6ec65aa 100644
--- a/libpyside/dynamicqmetaobject.cpp
+++ b/libpyside/dynamicqmetaobject.cpp
@@ -22,6 +22,11 @@
#include "dynamicqmetaobject.h"
#include "dynamicqmetaobject_p.h"
+#include "pysidesignal.h"
+#include "pysidesignal_p.h"
+#include "pysideproperty.h"
+#include "pysideproperty_p.h"
+
#include <QByteArray>
#include <QString>
#include <QStringList>
@@ -32,11 +37,6 @@
#include <QDebug>
#include <QMetaMethod>
-#include "qsignal.h"
-#include "qsignal_p.h"
-#include "qproperty.h"
-#include "qproperty_p.h"
-
#define MAX_SIGNALS_COUNT 50
#define MAX_SLOTS_COUNT 50
diff --git a/libpyside/pyside.cpp b/libpyside/pyside.cpp
index 086bdad..833ae9c 100644
--- a/libpyside/pyside.cpp
+++ b/libpyside/pyside.cpp
@@ -20,8 +20,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
#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 <conversions.h>
#include <typeresolver.h>
@@ -29,12 +35,6 @@
#include <cctype>
#include <QStack>
#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;
diff --git a/libpyside/qproperty.cpp b/libpyside/pysideproperty.cpp
index 0980808..51f848d 100644
--- a/libpyside/qproperty.cpp
+++ b/libpyside/pysideproperty.cpp
@@ -20,15 +20,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <shiboken.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 "qproperty.h"
-#include "qproperty_p.h"
-#include "dynamicqmetaobject_p.h"
-#include "qsignal.h"
-#include "qsignal_p.h"
#define QPROPERTY_CLASS_NAME "Property"
diff --git a/libpyside/qproperty.h b/libpyside/pysideproperty.h
index f137e80..f137e80 100644
--- a/libpyside/qproperty.h
+++ b/libpyside/pysideproperty.h
diff --git a/libpyside/qproperty_p.h b/libpyside/pysideproperty_p.h
index 1ba9cb2..1ba9cb2 100644
--- a/libpyside/qproperty_p.h
+++ b/libpyside/pysideproperty_p.h
diff --git a/libpyside/qsignal.cpp b/libpyside/pysidesignal.cpp
index 332cc82..41750aa 100644
--- a/libpyside/qsignal.cpp
+++ b/libpyside/pysidesignal.cpp
@@ -19,17 +19,16 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <Python.h>
+#include "pysidesignal.h"
+#include "pysidesignal_p.h"
+#include "signalmanager.h"
#include <shiboken.h>
-#include <Python.h>
#include <QDebug>
-#include "qsignal.h"
-#include "qsignal_p.h"
-#include "signalmanager.h"
-
#define SIGNAL_CLASS_NAME "Signal"
-#define QT_SIGNAL_SENTINEL "2"
+#define QT_SIGNAL_SENTINEL '2'
namespace PySide { namespace Signal {
@@ -665,7 +664,7 @@ PyObject* buildQtCompatible(const char* signature)
{
char* qtSignature;
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);
free(qtSignature);
return ret;
@@ -700,6 +699,118 @@ const char** getSignatures(PyObject* signal, int *size)
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 PySide
diff --git a/libpyside/qsignal.h b/libpyside/pysidesignal.h
index e32e064..8a590a1 100644
--- a/libpyside/qsignal.h
+++ b/libpyside/pysidesignal.h
@@ -23,9 +23,12 @@
#ifndef PYSIDE_SIGNAL_H
#define PYSIDE_SIGNAL_H
+#include <QObject>
+#include <QString>
+#include <QStringList>
+
#include <pysidemacros.h>
#include <Python.h>
-#include <QObject>
namespace Shiboken
{
@@ -110,6 +113,38 @@ PYSIDE_API void updateSourceObject(PyObject* source);
**/
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 PySide
diff --git a/libpyside/qsignal_p.h b/libpyside/pysidesignal_p.h
index 7f61469..d13e47e 100644
--- a/libpyside/qsignal_p.h
+++ b/libpyside/pysidesignal_p.h
@@ -51,10 +51,12 @@ extern "C"
}; //extern "C"
namespace PySide { namespace Signal {
+
void init(PyObject* module);
bool connect(PyObject* source, const char* signal, PyObject* callback);
char* getTypeName(PyObject*);
const char** getSignatures(PyObject* self, int *size);
+ QString codeCallbackName(PyObject* callback, const QString& funcName);
}} //namespace PySide
diff --git a/libpyside/qslot.cpp b/libpyside/pysideslot.cpp
index ff63a6c..538a258 100644
--- a/libpyside/qslot.cpp
+++ b/libpyside/pysideslot.cpp
@@ -20,10 +20,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "dynamicqmetaobject_p.h"
+#include "pysidesignal_p.h"
+
#include <shiboken.h>
#include <QString>
-#include "dynamicqmetaobject_p.h"
-#include "qsignal_p.h"
#define SLOT_DEC_NAME "Slot"
diff --git a/libpyside/qslot_p.h b/libpyside/pysideslot_p.h
index b02c36a..b02c36a 100644
--- a/libpyside/qslot_p.h
+++ b/libpyside/pysideslot_p.h
diff --git a/libpyside/signalmanager.cpp b/libpyside/signalmanager.cpp
index 1e5824e..a8ee412 100644
--- a/libpyside/signalmanager.cpp
+++ b/libpyside/signalmanager.cpp
@@ -21,6 +21,10 @@
*/
#include "signalmanager.h"
+#include "pysidesignal.h"
+#include "pysideproperty.h"
+#include "pysideproperty_p.h"
+#include "pyside.h"
#include <QHash>
#include <QStringList>
@@ -33,10 +37,6 @@
#include <basewrapper.h>
#include <conversions.h>
-#include "qproperty.h"
-#include "qproperty_p.h"
-#include "pyside.h"
-
#if QSLOT_CODE != 1 || QSIGNAL_CODE != 2
#error QSLOT_CODE and/or QSIGNAL_CODE changed! change the hardcoded stuff to the correct value!
#endif
@@ -105,124 +105,8 @@ struct Converter<PySide::PyObjectWrapper>
};
-
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
{
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)
{
- if (!checkSignal(signal))
+ if (!Signal::checkQtSignal(signal))
return false;
signal++;
int signalIndex = source->metaObject()->indexOfSignal(signal);
if (signalIndex != -1) {
bool isShortCircuit;
- QStringList argTypes = getArgsFromSignature(signal, &isShortCircuit);
+ QStringList argTypes = Signal::getArgsFromSignature(signal, &isShortCircuit);
if (isShortCircuit)
return emitShortCircuitSignal(source, signalIndex, args);
diff --git a/libpyside/signalmanager.h b/libpyside/signalmanager.h
index 2fda008..91c86e0 100644
--- a/libpyside/signalmanager.h
+++ b/libpyside/signalmanager.h
@@ -45,13 +45,9 @@ public:
operator PyObject*() const;
private:
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
{
public:
@@ -76,6 +72,7 @@ public:
private:
struct SignalManagerPrivate;
SignalManagerPrivate* m_d;
+
SignalManager();
~SignalManager();