summaryrefslogtreecommitdiffstats
path: root/libpyside
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-07-20 10:41:31 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-07-20 15:31:33 -0300
commit0a41e336ba25df2d87218555a3a15f96dcc3ec77 (patch)
tree092444defeb0f12bf50ef9c67bbe5f60f0468a80 /libpyside
parentb6e0977d867acdb2529f23c407343f95908662e2 (diff)
downloadpyside-0a41e336ba25df2d87218555a3a15f96dcc3ec77.tar.gz
pyside-0a41e336ba25df2d87218555a3a15f96dcc3ec77.tar.xz
pyside-0a41e336ba25df2d87218555a3a15f96dcc3ec77.zip
Fix bug 926 - "qmlRegisterType does not work with QObject"
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Lauro Neto <lauro.neto@openbossa.org>
Diffstat (limited to 'libpyside')
-rw-r--r--libpyside/pyside.cpp47
-rw-r--r--libpyside/pyside.h8
2 files changed, 48 insertions, 7 deletions
diff --git a/libpyside/pyside.cpp b/libpyside/pyside.cpp
index ea48b17..325e274 100644
--- a/libpyside/pyside.cpp
+++ b/libpyside/pyside.cpp
@@ -44,12 +44,14 @@
#include <QDebug>
static QStack<PySide::CleanupFunction> cleanupFunctionList;
+static void* qobjectNextAddr;
namespace PySide
{
void init(PyObject *module)
{
+ qobjectNextAddr = 0;
ClassInfo::init(module);
Signal::init(module);
Slot::init(module);
@@ -148,17 +150,35 @@ void destroyQCoreApplication()
delete app;
}
-void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base)
+struct TypeUserData {
+ TypeUserData(PyTypeObject* type, const QMetaObject* metaobject) : mo(type, metaobject) {}
+ DynamicQMetaObject mo;
+ std::size_t cppObjSize;
+};
+
+std::size_t getSizeOfQObject(SbkObjectType* type)
+{
+ using namespace Shiboken::ObjectType;
+ TypeUserData* userData = reinterpret_cast<TypeUserData*>(getTypeUserData(reinterpret_cast<SbkObjectType*>(type)));
+ return userData->cppObjSize;
+}
+
+void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base, const std::size_t& cppObjSize)
{
//create DynamicMetaObject based on python type
- DynamicQMetaObject* mo = new PySide::DynamicQMetaObject(reinterpret_cast<PyTypeObject*>(type), base);
- Shiboken::ObjectType::setTypeUserData(type, mo, Shiboken::callCppDestructor<DynamicQMetaObject>);
+ TypeUserData* userData = new TypeUserData(reinterpret_cast<PyTypeObject*>(type), base);
+ userData->cppObjSize = cppObjSize;
+ Shiboken::ObjectType::setTypeUserData(type, userData, Shiboken::callCppDestructor<TypeUserData>);
//initialize staticQMetaObject property
- PyObject* pyMetaObject = Shiboken::TypeResolver::get("QMetaObject*")->toPython(&mo);
-
+ void* metaObjectPtr = &userData->mo;
+ Shiboken::AutoDecRef pyMetaObject(Shiboken::TypeResolver::get("QMetaObject*")->toPython(&metaObjectPtr));
PyObject_SetAttrString(reinterpret_cast<PyObject*>(type), "staticMetaObject", pyMetaObject);
- Py_DECREF(pyMetaObject);
+}
+
+void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base)
+{
+ initDynamicMetaObject(type, base, 0);
}
void initQObjectSubType(SbkObjectType* type, PyObject* args, PyObject* kwds)
@@ -169,11 +189,13 @@ void initQObjectSubType(SbkObjectType* type, PyObject* args, PyObject* kwds)
PyObject* bases = PyTuple_GET_ITEM(args, 1);
int numBases = PyTuple_GET_SIZE(bases);
QMetaObject* baseMo = 0;
+ SbkObjectType* qobjBase = 0;
for (int i = 0; i < numBases; ++i) {
PyTypeObject* base = reinterpret_cast<PyTypeObject*>(PyTuple_GET_ITEM(bases, i));
if (PyType_IsSubtype(base, qObjType)) {
baseMo = reinterpret_cast<QMetaObject*>(Shiboken::ObjectType::getTypeUserData(reinterpret_cast<SbkObjectType*>(base)));
+ qobjBase = reinterpret_cast<SbkObjectType*>(base);
break;
}
}
@@ -182,7 +204,8 @@ void initQObjectSubType(SbkObjectType* type, PyObject* args, PyObject* kwds)
return;
}
- initDynamicMetaObject(type, baseMo);
+ TypeUserData* userData = reinterpret_cast<TypeUserData*>(Shiboken::ObjectType::getTypeUserData(qobjBase));
+ initDynamicMetaObject(type, baseMo, userData->cppObjSize);
}
PyObject* getMetaDataFromQObject(QObject* cppSelf, PyObject* self, PyObject* name)
@@ -249,5 +272,15 @@ bool inherits(PyTypeObject* objType, const char* class_name)
return inherits(base, class_name);
}
+void* nextQObjectMemoryAddr()
+{
+ return qobjectNextAddr;
+}
+
+void setNextQObjectMemoryAddr(void* addr)
+{
+ qobjectNextAddr = addr;
+}
+
} //namespace PySide
diff --git a/libpyside/pyside.h b/libpyside/pyside.h
index 747b08d..3ef7d38 100644
--- a/libpyside/pyside.h
+++ b/libpyside/pyside.h
@@ -77,9 +77,14 @@ template<typename T>
struct initQtMetaType<T, false> {
};
+/// \deprecated
PYSIDE_API void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base);
+PYSIDE_API void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base, const std::size_t& cppObjSize);
PYSIDE_API void initQObjectSubType(SbkObjectType* type, PyObject* args, PyObject* kwds);
+/// Return the size in bytes of a type that inherits QObject.
+PYSIDE_API std::size_t getSizeOfQObject(SbkObjectType* type);
+
typedef void (*CleanupFunction)(void);
/**
@@ -110,6 +115,9 @@ PYSIDE_API PyObject* getMetaDataFromQObject(QObject* cppSelf, PyObject* self, Py
*/
PYSIDE_API bool inherits(PyTypeObject* self, const char* class_name);
+PYSIDE_API void* nextQObjectMemoryAddr();
+PYSIDE_API void setNextQObjectMemoryAddr(void* addr);
+
} //namespace PySide