Fixing QVariant converter toCpp for basic types
Instead of storing a single pointer, the converter now checks for basic python types like string, bool, ints, using the same if/self structure of the constructor. Only as a last resort it tries to convert to a python object holder. Reviewer: Renato Filho <renato.filho@openbossa.org>
This commit is contained in:
parent
6e33903fe2
commit
3ec23a2a89
1 changed files with 34 additions and 2 deletions
|
|
@ -42,8 +42,40 @@ QVariant Shiboken::Converter<QVariant>::toCpp(PyObject* pyobj)
|
||||||
// voodoo stuff to avoid linking qtcore bindings with qtgui bindings
|
// voodoo stuff to avoid linking qtcore bindings with qtgui bindings
|
||||||
uint typeCode = QMetaType::type(pyobj->ob_type->tp_name);
|
uint typeCode = QMetaType::type(pyobj->ob_type->tp_name);
|
||||||
if (!typeCode || typeCode > QVariant::UserType) {
|
if (!typeCode || typeCode > QVariant::UserType) {
|
||||||
Py_INCREF(pyobj);
|
|
||||||
return QVariant::fromValue<PyObjectHolder>(pyobj);
|
// Check the implicit conversion stuff for most python-native types
|
||||||
|
if (SbkPySide_QtCore_QVariant_Type_CheckExact(pyobj)) {
|
||||||
|
QVariant::Type cpp_arg0 = Shiboken::Converter<QVariant::Type >::toCpp(pyobj);
|
||||||
|
// QVariant(QVariant::Type)
|
||||||
|
return QVariant(cpp_arg0);
|
||||||
|
} else if (SbkPySide_QtCore_Qt_GlobalColor_CheckExact(pyobj)) {
|
||||||
|
Qt::GlobalColor cpp_arg0 = Shiboken::Converter<Qt::GlobalColor >::toCpp(pyobj);
|
||||||
|
// QVariant(Qt::GlobalColor)
|
||||||
|
return QVariant(cpp_arg0);
|
||||||
|
} else if (PyBool_Check(pyobj)) {
|
||||||
|
bool cpp_arg0 = Shiboken::Converter<bool >::toCpp(pyobj);
|
||||||
|
// QVariant(bool)
|
||||||
|
return QVariant(cpp_arg0);
|
||||||
|
} else if (PyString_Check(pyobj)) {
|
||||||
|
const char * cpp_arg0 = Shiboken::Converter<const char * >::toCpp(pyobj);
|
||||||
|
// QVariant(const char*)
|
||||||
|
return QVariant(cpp_arg0);
|
||||||
|
} else if (PyFloat_Check(pyobj)) {
|
||||||
|
double cpp_arg0 = Shiboken::Converter<double >::toCpp(pyobj);
|
||||||
|
// QVariant(double)
|
||||||
|
return QVariant(cpp_arg0);
|
||||||
|
} else if (PyNumber_Check(pyobj)) {
|
||||||
|
int cpp_arg0 = Shiboken::Converter<int >::toCpp(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
|
// Is a known Qt type
|
||||||
return QVariant(typeCode, reinterpret_cast<SbkBaseWrapper*>(pyobj)->cptr);
|
return QVariant(typeCode, reinterpret_cast<SbkBaseWrapper*>(pyobj)->cptr);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue