From b385e0c3edd0d9e99665cebbd8ee37055594d838 Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Tue, 28 Jun 2011 11:39:04 -0300 Subject: Fixed propagation of properties for user-defined types. Fixes bug #897. Reviewer: Marcelo Lira Luciano Wolf --- libpyside/pysideproperty.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'libpyside') diff --git a/libpyside/pysideproperty.cpp b/libpyside/pysideproperty.cpp index 5f11d36d8..b1cb19c4e 100644 --- a/libpyside/pysideproperty.cpp +++ b/libpyside/pysideproperty.cpp @@ -136,6 +136,7 @@ static void qpropertyMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::C } } + static PyObject* qpropertyTpNew(PyTypeObject* subtype, PyObject* args, PyObject* kwds) { PySideProperty* me = reinterpret_cast(subtype->tp_alloc(subtype, 0)); @@ -193,6 +194,27 @@ void qpropertyFree(void *self) } // extern "C" +namespace { + +static PyObject* getFromType(PyTypeObject* type, PyObject* name) +{ + PyObject* attr = 0; + attr = PyDict_GetItem(type->tp_dict, name); + if (!attr) { + PyObject* bases = type->tp_bases; + int size = PyTuple_GET_SIZE(bases); + for(int i=0; i < size; i++) { + PyObject* base = PyTuple_GET_ITEM(bases, i); + attr = getFromType(reinterpret_cast(base), name); + if (attr) + return attr; + } + } + return attr; +} + +} //namespace + namespace PySide { namespace Property { @@ -275,9 +297,7 @@ PySideProperty* getObject(PyObject* source, PyObject* name) attr = PyDict_GetItem(dict, name); } - if (!attr) - attr = PyDict_GetItem(source->ob_type->tp_dict, name); - + attr = getFromType(source->ob_type, name); if (attr && isPropertyType(attr)) { Py_INCREF(attr); return reinterpret_cast(attr); -- cgit v1.2.3