Implemented support to slot decoration.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>,
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
ac217286e2
commit
fde014f5db
4 changed files with 212 additions and 0 deletions
|
|
@ -123,6 +123,30 @@ void DynamicQMetaObject::removeSlot(uint index)
|
|||
}
|
||||
}
|
||||
|
||||
DynamicQMetaObject* DynamicQMetaObject::createBasedOn(PyTypeObject *type, const QMetaObject *base)
|
||||
{
|
||||
PyObject *key, *value;
|
||||
Py_ssize_t pos = 0;
|
||||
|
||||
QString className(type->tp_name);
|
||||
className = className.mid(className.lastIndexOf(".")+1);
|
||||
DynamicQMetaObject *mo = new PySide::DynamicQMetaObject(className.toAscii(), base);
|
||||
|
||||
while (PyDict_Next(type->tp_dict, &pos, &key, &value)) {
|
||||
if (!PyFunction_Check(value))
|
||||
continue;
|
||||
|
||||
if (PyObject_HasAttrString(value, PYSIDE_SLOT_LIST_ATTR)) {
|
||||
PyObject *signature_list = PyObject_GetAttrString(value, PYSIDE_SLOT_LIST_ATTR);
|
||||
for(Py_ssize_t i=0, i_max=PyList_Size(signature_list); i < i_max; i++) {
|
||||
PyObject *signature = PyList_GET_ITEM(signature_list, i);
|
||||
mo->addSlot(PyString_AsString(signature));
|
||||
}
|
||||
}
|
||||
}
|
||||
return mo;
|
||||
}
|
||||
|
||||
void DynamicQMetaObject::removeSignal(uint index)
|
||||
{
|
||||
//Current Qt implementation does not support runtime remove signal
|
||||
|
|
|
|||
|
|
@ -36,10 +36,13 @@
|
|||
#define DYNAMICQMETAOBJECT_H
|
||||
|
||||
#include "pysidemacros.h"
|
||||
#include <Python.h>
|
||||
#include <QMetaObject>
|
||||
#include <QLinkedList>
|
||||
#include <QByteArray>
|
||||
|
||||
#define PYSIDE_SLOT_LIST_ATTR "_slots"
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace PySide
|
||||
|
|
@ -57,6 +60,9 @@ public:
|
|||
void removeSignal(uint idex);
|
||||
void removeSlot(uint index);
|
||||
|
||||
//Retrieve Python metadata to create QMetaObject (class name, signals, slot)
|
||||
static DynamicQMetaObject *createBasedOn(PyTypeObject *obj, const QMetaObject* base);
|
||||
|
||||
private:
|
||||
QLinkedList<QByteArray> m_signals;
|
||||
QLinkedList<QByteArray> m_slots;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue