Created function used in PyObject getAttro.
Moved the code generated to a function in libpyside. Create unit test for bug #525. Reviewer: Hugo Parente Lima <hugo.pl@gmail.com> Marcelo Lira <marcelo.lira@openbossa.org>
This commit is contained in:
parent
0229e5413b
commit
22b7485419
4 changed files with 81 additions and 0 deletions
|
|
@ -28,6 +28,7 @@
|
||||||
#include "pysidesignal_p.h"
|
#include "pysidesignal_p.h"
|
||||||
#include "pysideslot_p.h"
|
#include "pysideslot_p.h"
|
||||||
#include "pysidemetafunction_p.h"
|
#include "pysidemetafunction_p.h"
|
||||||
|
#include "pysidemetafunction.h"
|
||||||
#include "dynamicqmetaobject.h"
|
#include "dynamicqmetaobject.h"
|
||||||
|
|
||||||
#include <basewrapper.h>
|
#include <basewrapper.h>
|
||||||
|
|
@ -225,5 +226,54 @@ void initQObjectSubType(SbkObjectType* type, PyObject* args, PyObject* kwds)
|
||||||
mo->addProperty(propPair.first, propPair.second);
|
mo->addProperty(propPair.first, propPair.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* getMetaDataFromQObject(QObject* cppSelf, PyObject* self, PyObject* name)
|
||||||
|
{
|
||||||
|
PyObject* attr = PyObject_GenericGetAttr(self, name);
|
||||||
|
if (attr && Property::isPropertyType(attr)) {
|
||||||
|
PyObject *value = Property::getValue(reinterpret_cast<PySideProperty*>(attr), self);
|
||||||
|
if (!value)
|
||||||
|
return 0;
|
||||||
|
Py_DECREF(attr);
|
||||||
|
Py_INCREF(value);
|
||||||
|
attr = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//mutate native signals to signal instance type
|
||||||
|
if (attr && PyObject_TypeCheck(attr, &PySideSignalType)) {
|
||||||
|
PyObject* signal = reinterpret_cast<PyObject*>(Signal::initialize(reinterpret_cast<PySideSignal*>(attr), name, self));
|
||||||
|
PyObject_SetAttr(self, name, reinterpret_cast<PyObject*>(signal));
|
||||||
|
return signal;
|
||||||
|
}
|
||||||
|
|
||||||
|
//search on metaobject (avoid internal attributes started with '__')
|
||||||
|
if (!attr && !QString(PyString_AS_STRING(name)).startsWith("__")) {
|
||||||
|
const QMetaObject* metaObject = cppSelf->metaObject();
|
||||||
|
QByteArray cname(PyString_AS_STRING(name));
|
||||||
|
cname += '(';
|
||||||
|
//signal
|
||||||
|
QList<QMetaMethod> signalList;
|
||||||
|
for(int i=0, i_max = metaObject->methodCount(); i < i_max; i++) {
|
||||||
|
QMetaMethod method = metaObject->method(i);
|
||||||
|
if (QString(method.signature()).startsWith(cname)) {
|
||||||
|
if (method.methodType() == QMetaMethod::Signal) {
|
||||||
|
signalList.append(method);
|
||||||
|
} else {
|
||||||
|
PySideMetaFunction* func = MetaFunction::newObject(cppSelf, i);
|
||||||
|
if (func) {
|
||||||
|
PyObject_SetAttr(self, name, (PyObject*)func);
|
||||||
|
return (PyObject*)func;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (signalList.size() > 0) {
|
||||||
|
PyObject* pySignal = reinterpret_cast<PyObject*>(Signal::newObjectFromMethod(self, signalList));
|
||||||
|
PyObject_SetAttr(self, name, pySignal);
|
||||||
|
return pySignal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attr;
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace PySide
|
} //namespace PySide
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,15 @@ PYSIDE_API void runCleanupFunctions();
|
||||||
*/
|
*/
|
||||||
PYSIDE_API void destroyQCoreApplication();
|
PYSIDE_API void destroyQCoreApplication();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for properties and signals registered on MetaObject and return these
|
||||||
|
* \param cppSelf Is the QObject which contains the metaobject
|
||||||
|
* \param self Python object of cppSelf
|
||||||
|
* \param name Name of the argument which the function will try retrieve from MetaData
|
||||||
|
* \return The Python object which contains the Data obtained in metaObject or the Python attribute related with name
|
||||||
|
*/
|
||||||
|
PYSIDE_API PyObject* getMetaDataFromQObject(QObject* cppSelf, PyObject* self, PyObject* name);
|
||||||
|
|
||||||
} //namespace PySide
|
} //namespace PySide
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ PYSIDE_TEST(bug_467.py)
|
||||||
PYSIDE_TEST(bug_480.py)
|
PYSIDE_TEST(bug_480.py)
|
||||||
PYSIDE_TEST(bug_500.py)
|
PYSIDE_TEST(bug_500.py)
|
||||||
PYSIDE_TEST(bug_512.py)
|
PYSIDE_TEST(bug_512.py)
|
||||||
|
PYSIDE_TEST(bug_525.py)
|
||||||
PYSIDE_TEST(customproxywidget_test.py)
|
PYSIDE_TEST(customproxywidget_test.py)
|
||||||
PYSIDE_TEST(deepcopy_test.py)
|
PYSIDE_TEST(deepcopy_test.py)
|
||||||
PYSIDE_TEST(float_to_int_implicit_conversion_test.py)
|
PYSIDE_TEST(float_to_int_implicit_conversion_test.py)
|
||||||
|
|
|
||||||
21
tests/QtGui/bug_525.py
Normal file
21
tests/QtGui/bug_525.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import unittest
|
||||||
|
from PySide.QtGui import QApplication
|
||||||
|
from PySide.QtGui import QMenu
|
||||||
|
|
||||||
|
class M2(QMenu):
|
||||||
|
def __init__(self,parent=None):
|
||||||
|
super(M2,self).__init__(parent)
|
||||||
|
self.setTitle(self.tr("M2"))
|
||||||
|
|
||||||
|
class TestMenuDerivedClass(unittest.TestCase):
|
||||||
|
def aboutToShowHandler(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def testConnectSignal(self):
|
||||||
|
app = QApplication([])
|
||||||
|
m2 = M2()
|
||||||
|
# Test if the aboutToShow signal was translated to correct type
|
||||||
|
m2.aboutToShow.connect(self.aboutToShowHandler)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue