Add checkType method to PySide custom converters.
This commit is contained in:
parent
e39bfefde9
commit
ccd189d30c
6 changed files with 49 additions and 15 deletions
|
|
@ -1,12 +1,17 @@
|
||||||
namespace Shiboken {
|
namespace Shiboken {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class Converter<QChar>
|
struct Converter<QChar>
|
||||||
{
|
{
|
||||||
public:
|
static bool checkType(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return PyString_Check(pyObj) && (PyString_Size(pyObj) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
static bool isConvertible(PyObject* pyObj)
|
static bool isConvertible(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
return (PyString_Check(pyObj) && (PyString_Size(pyObj) == 1))
|
return (PyString_Check(pyObj) && (PyString_Size(pyObj) == 1))
|
||||||
|
|| pyObj == Py_None
|
||||||
|| PyInt_Check(pyObj);
|
|| PyInt_Check(pyObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
namespace Shiboken {
|
namespace Shiboken {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class Converter<QString>
|
struct Converter<QString>
|
||||||
{
|
{
|
||||||
public:
|
static bool checkType(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return PyString_Check(pyObj) || PyUnicode_Check(pyObj);
|
||||||
|
}
|
||||||
|
|
||||||
static bool isConvertible(PyObject* pyObj)
|
static bool isConvertible(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
return PyString_Check(pyObj)
|
return PyString_Check(pyObj)
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ struct Converter<QStringRef> : public Converter<QString>
|
||||||
|
|
||||||
static PyObject* toPython(const QStringRef& cppObj)
|
static PyObject* toPython(const QStringRef& cppObj)
|
||||||
{
|
{
|
||||||
const QString* str = cppObj.string();
|
return Converter<QString>::toPython(cppObj.toString());
|
||||||
return Converter<QString>::toPython(*str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringRef toCpp(PyObject* pyObj)
|
static QStringRef toCpp(PyObject* pyObj)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ Q_DECLARE_METATYPE(PyQt_PyObject)
|
||||||
|
|
||||||
namespace Shiboken {
|
namespace Shiboken {
|
||||||
|
|
||||||
|
inline bool Converter<QVariant>::checkType(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return ValueTypeConverter<QVariant>::checkType(pyObj);
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
namespace Shiboken {
|
namespace Shiboken {
|
||||||
inline bool Converter< QPixmap >::isConvertible(PyObject* pyobj)
|
inline bool Converter<QPixmap>::checkType(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return ValueTypeConverter<QPixmap>::checkType(pyObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Converter<QPixmap>::isConvertible(PyObject* pyobj)
|
||||||
{
|
{
|
||||||
if (ValueTypeConverter<QPixmap>::isConvertible(pyobj))
|
if (ValueTypeConverter<QPixmap>::isConvertible(pyobj))
|
||||||
return true;
|
return true;
|
||||||
SbkBaseWrapperType* shiboType = reinterpret_cast<SbkBaseWrapperType*>(SbkType<QPixmap>());
|
SbkBaseWrapperType* shiboType = reinterpret_cast<SbkBaseWrapperType*>(SbkType<QPixmap>());
|
||||||
bool isVariant = SbkQVariant_Check(pyobj);
|
bool isVariant = Converter<QVariant>::checkType(pyobj);
|
||||||
if (isVariant) {
|
if (isVariant) {
|
||||||
QVariant var(Converter<QVariant>::toCpp(pyobj));
|
QVariant var(Converter<QVariant>::toCpp(pyobj));
|
||||||
return var.type() == QVariant::Pixmap;
|
return var.type() == QVariant::Pixmap;
|
||||||
} else if (SbkQSize_Check(pyobj) || SbkQString_Check(pyobj)) {
|
} else if (Converter<QSize>::checkType(pyobj) || Converter<QString>::checkType(pyobj)) {
|
||||||
return true;
|
return true;
|
||||||
} else if (shiboType->ext_isconvertible) {
|
} else if (shiboType->ext_isconvertible) {
|
||||||
return shiboType->ext_isconvertible(pyobj);
|
return shiboType->ext_isconvertible(pyobj);
|
||||||
|
|
@ -17,17 +22,17 @@ inline bool Converter< QPixmap >::isConvertible(PyObject* pyobj)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QPixmap Converter< QPixmap >::toCpp(PyObject* pyobj)
|
inline QPixmap Converter<QPixmap>::toCpp(PyObject* pyobj)
|
||||||
{
|
{
|
||||||
SbkBaseWrapperType* shiboType = reinterpret_cast<SbkBaseWrapperType*>(SbkType<QPixmap>());
|
SbkBaseWrapperType* shiboType = reinterpret_cast<SbkBaseWrapperType*>(SbkType<QPixmap>());
|
||||||
bool isVariant = SbkQVariant_Check(pyobj);
|
bool isVariant = Converter<QVariant>::checkType(pyobj);
|
||||||
if (isVariant) {
|
if (isVariant) {
|
||||||
QVariant var(Converter<QVariant>::toCpp(pyobj));
|
QVariant var(Converter<QVariant>::toCpp(pyobj));
|
||||||
return var.value<QPixmap>();
|
return var.value<QPixmap>();
|
||||||
} else if (SbkQSize_Check(pyobj)) {
|
} else if (Converter<QSize>::checkType(pyobj)) {
|
||||||
return QPixmap(Shiboken::Converter<QSize& >::toCpp(pyobj));
|
return QPixmap(Shiboken::Converter<QSize >::toCpp(pyobj));
|
||||||
} else if (SbkQString_Check(pyobj)) {
|
} else if (Converter<QString>::checkType(pyobj)) {
|
||||||
return QPixmap(Shiboken::Converter<QString& >::toCpp(pyobj));
|
return QPixmap(Shiboken::Converter<QString >::toCpp(pyobj));
|
||||||
} else if (shiboType->ext_isconvertible && shiboType->ext_tocpp && shiboType->ext_isconvertible(pyobj)) {
|
} else if (shiboType->ext_isconvertible && shiboType->ext_tocpp && shiboType->ext_isconvertible(pyobj)) {
|
||||||
QPixmap* cptr = reinterpret_cast<QPixmap*>(shiboType->ext_tocpp(pyobj));
|
QPixmap* cptr = reinterpret_cast<QPixmap*>(shiboType->ext_tocpp(pyobj));
|
||||||
std::auto_ptr<QPixmap> cptr_auto_ptr(cptr);
|
std::auto_ptr<QPixmap> cptr_auto_ptr(cptr);
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,11 @@
|
||||||
template <typename QtDict>
|
template <typename QtDict>
|
||||||
struct QtDictConverter
|
struct QtDictConverter
|
||||||
{
|
{
|
||||||
|
static inline bool checkType(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return isConvertible(pyObj);
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool isConvertible(PyObject* pyObj)
|
static inline bool isConvertible(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<QtDict>()))
|
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<QtDict>()))
|
||||||
|
|
@ -95,6 +100,11 @@ struct QtDictConverter
|
||||||
template <typename MultiMap>
|
template <typename MultiMap>
|
||||||
struct QtMultiMapConverter
|
struct QtMultiMapConverter
|
||||||
{
|
{
|
||||||
|
static inline bool checkType(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return isConvertible(pyObj);
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool isConvertible(PyObject* pyObj)
|
static inline bool isConvertible(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<MultiMap>()))
|
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<MultiMap>()))
|
||||||
|
|
@ -145,6 +155,7 @@ struct QtMultiMapConverter
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline MultiMap toCpp(PyObject* pyObj)
|
static inline MultiMap toCpp(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<MultiMap>()))
|
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<MultiMap>()))
|
||||||
|
|
@ -165,6 +176,11 @@ struct QtMultiMapConverter
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct QSequenceConverter
|
struct QSequenceConverter
|
||||||
{
|
{
|
||||||
|
static inline bool checkType(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return isConvertible(pyObj);
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool isConvertible(PyObject* pyObj)
|
static inline bool isConvertible(PyObject* pyObj)
|
||||||
{
|
{
|
||||||
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<T>()))
|
if (PyObject_TypeCheck(pyObj, Shiboken::SbkType<T>()))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue