Fix some issues with QVariant, including the QAbstractKinectScroller one.
This commit is contained in:
parent
77c2be562b
commit
956d6fd530
3 changed files with 82 additions and 44 deletions
|
|
@ -32,57 +32,63 @@ QT_END_NAMESPACE
|
||||||
namespace Shiboken {
|
namespace Shiboken {
|
||||||
|
|
||||||
// all types are convertible to QVariant
|
// all types are convertible to QVariant
|
||||||
inline bool Converter<QVariant>::isConvertible(PyObject* pyobj)
|
inline bool Converter<QVariant>::isConvertible(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QVariant Converter<QVariant>::toCpp(PyObject* pyobj)
|
inline QVariant Converter<QVariant>::toCpp(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
if (SbkQVariant_Check(pyobj))
|
if (SbkQVariant_Check(pyObj))
|
||||||
return *Converter<QVariant*>::toCpp(pyobj);
|
return *Converter<QVariant*>::toCpp(pyObj);
|
||||||
// voodoo stuff to avoid linking qtcore bindings with qtgui bindings
|
|
||||||
QString className(pyobj->ob_type->tp_name);
|
|
||||||
className = className.mid(className.lastIndexOf(".") + 1);
|
|
||||||
uint typeCode = QMetaType::type(className.toAscii());
|
|
||||||
if (!typeCode || typeCode > QVariant::UserType) {
|
|
||||||
|
|
||||||
// Check the implicit conversion stuff for most python-native types
|
// Primitive types
|
||||||
if (SbkPySide_QtCore_QVariant_Type_CheckExact(pyobj)) {
|
if (PyBool_Check(pyObj)) {
|
||||||
QVariant::Type cpp_arg0 = Shiboken::Converter<QVariant::Type >::toCpp(pyobj);
|
// QVariant(bool)
|
||||||
// QVariant(QVariant::Type)
|
return QVariant(Shiboken::Converter<bool>::toCpp(pyObj));
|
||||||
return QVariant(cpp_arg0);
|
} else if (PyString_CheckExact(pyObj)) {
|
||||||
} else if (SbkPySide_QtCore_Qt_GlobalColor_CheckExact(pyobj)) {
|
// QVariant(const char*)
|
||||||
Qt::GlobalColor cpp_arg0 = Shiboken::Converter<Qt::GlobalColor >::toCpp(pyobj);
|
return QVariant(Shiboken::Converter<const char *>::toCpp(pyObj));
|
||||||
// QVariant(Qt::GlobalColor)
|
} else if (PyFloat_CheckExact(pyObj)) {
|
||||||
return QVariant(cpp_arg0);
|
// QVariant(double)
|
||||||
} else if (PyBool_Check(pyobj)) {
|
return QVariant(Shiboken::Converter<double>::toCpp(pyObj));
|
||||||
bool cpp_arg0 = Shiboken::Converter<bool >::toCpp(pyobj);
|
} else if (PyInt_CheckExact(pyObj)) {
|
||||||
// QVariant(bool)
|
// QVariant(int)
|
||||||
return QVariant(cpp_arg0);
|
return QVariant(Shiboken::Converter<int>::toCpp(pyObj));
|
||||||
} else if (PyString_Check(pyobj)) {
|
} else if (PyLong_CheckExact(pyObj)) {
|
||||||
const char * cpp_arg0 = Shiboken::Converter<const char * >::toCpp(pyobj);
|
// QVariant(qlonglong)
|
||||||
// QVariant(const char*)
|
return QVariant(Shiboken::Converter<qlonglong>::toCpp(pyObj));
|
||||||
return QVariant(cpp_arg0);
|
} else if (Shiboken::isShibokenEnum(pyObj)) {
|
||||||
} else if (PyFloat_Check(pyobj)) {
|
// QVariant(enum)
|
||||||
double cpp_arg0 = Shiboken::Converter<double >::toCpp(pyobj);
|
return QVariant(Shiboken::Converter<int>::toCpp(pyObj));
|
||||||
// QVariant(double)
|
} else if (!Shiboken::isShibokenType(pyObj) || Shiboken::isUserType(pyObj)) {
|
||||||
return QVariant(cpp_arg0);
|
// QVariant(User class)
|
||||||
} else if (PyNumber_Check(pyobj)) {
|
Py_INCREF(pyObj);
|
||||||
int cpp_arg0 = Shiboken::Converter<int >::toCpp(pyobj);
|
return QVariant::fromValue<PyObjectHolder>(pyObj);
|
||||||
// QVariant(int)
|
|
||||||
return QVariant(cpp_arg0);
|
|
||||||
} else if (PyLong_Check(pyobj)) {
|
|
||||||
qlonglong cpp_arg0 = Shiboken::Converter<qlonglong >::toCpp(pyobj);
|
|
||||||
// QVariant(qlonglong)
|
|
||||||
return QVariant(cpp_arg0);
|
|
||||||
} else {
|
|
||||||
Py_INCREF(pyobj);
|
|
||||||
return QVariant::fromValue<PyObjectHolder>(pyobj);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Is a known Qt type
|
// a class supported by QVariant?
|
||||||
return QVariant(typeCode, reinterpret_cast<SbkBaseWrapper*>(pyobj)->cptr[0]);
|
const char* typeName = pyObj->ob_type->tp_name;
|
||||||
|
// check if the name starts with PySide.
|
||||||
|
if (!strncmp("PySide.", typeName, 7)) {
|
||||||
|
// get the type name
|
||||||
|
const char* lastDot = typeName;
|
||||||
|
for (int i = 8; typeName[i]; ++i) {
|
||||||
|
if (typeName[i] == '.')
|
||||||
|
lastDot = &typeName[i];
|
||||||
|
}
|
||||||
|
lastDot++;
|
||||||
|
uint typeCode = QMetaType::type(lastDot);
|
||||||
|
if (!typeCode) {// Try with star at end, for QObject*, QWidget* and QAbstractKinectScroller*
|
||||||
|
QString typeName(lastDot);
|
||||||
|
typeName += '*';
|
||||||
|
typeCode = QMetaType::type(typeName.toAscii());
|
||||||
|
}
|
||||||
|
if (typeCode)
|
||||||
|
return QVariant(typeCode, reinterpret_cast<SbkBaseWrapper*>(pyObj)->cptr[0]);
|
||||||
|
}
|
||||||
|
// Is a shiboken type not known by Qt
|
||||||
|
Py_INCREF(pyObj);
|
||||||
|
return QVariant::fromValue<PyObjectHolder>(pyObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1637,7 +1637,12 @@
|
||||||
<conversion-rule file="qvariant_conversions.h" />
|
<conversion-rule file="qvariant_conversions.h" />
|
||||||
<modify-function signature="create(int,const void*)" remove="all" />
|
<modify-function signature="create(int,const void*)" remove="all" />
|
||||||
|
|
||||||
|
<!-- QVariant constructor is a beast with its own rules -->
|
||||||
<modify-function signature="QVariant(float)" remove="all"/>
|
<modify-function signature="QVariant(float)" remove="all"/>
|
||||||
|
<modify-function signature="QVariant(int)" remove="all"/>
|
||||||
|
<modify-function signature="QVariant(double)" remove="all"/>
|
||||||
|
<modify-function signature="QVariant(bool)" remove="all"/>
|
||||||
|
<modify-function signature="QVariant(qlonglong)" remove="all"/>
|
||||||
<modify-function signature="QVariant(int, const void*)" remove="all"/>
|
<modify-function signature="QVariant(int, const void*)" remove="all"/>
|
||||||
<modify-function signature="QVariant(int,const void*,uint)" remove="all"/>
|
<modify-function signature="QVariant(int,const void*,uint)" remove="all"/>
|
||||||
<!-- handled by inject code -->
|
<!-- handled by inject code -->
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,33 @@ class QVariantQPixmap(UsesQApplication):
|
||||||
|
|
||||||
self.assertEqual(variant.typeName(), "QPixmap")
|
self.assertEqual(variant.typeName(), "QPixmap")
|
||||||
|
|
||||||
|
def testQObject(self):
|
||||||
|
obj = QObject()
|
||||||
|
v = QVariant(obj)
|
||||||
|
self.assertEqual(v.typeName(), 'QObject*')
|
||||||
|
|
||||||
|
def testQWidget(self):
|
||||||
|
obj = QWidget()
|
||||||
|
v = QVariant(obj)
|
||||||
|
self.assertEqual(v.typeName(), 'QWidget*')
|
||||||
|
|
||||||
|
class MyColor(QColor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class MyPrimitive(int):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class QVariantMess(unittest.TestCase):
|
||||||
|
def testMyColor(self):
|
||||||
|
c1 = MyColor()
|
||||||
|
v = QVariant(c1)
|
||||||
|
self.assertEqual(type(v.toPyObject()), MyColor)
|
||||||
|
|
||||||
|
def testMyPrimitive(self):
|
||||||
|
p = MyPrimitive(3)
|
||||||
|
v = QVariant(p)
|
||||||
|
self.assertNotEqual(v.type(), QVariant.Int)
|
||||||
|
self.assertTrue(v.toPyObject() is p)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue