Fix bug 294 addind a converter specific for QFlags.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Renato Araújo <renato.filho@openbossa.org>
This commit is contained in:
parent
d686c68707
commit
9a969935cc
1 changed files with 31 additions and 0 deletions
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <conversions.h>
|
#include <conversions.h>
|
||||||
|
#include <QFlag>
|
||||||
|
|
||||||
template <typename QtDict>
|
template <typename QtDict>
|
||||||
struct QtDictConverter
|
struct QtDictConverter
|
||||||
|
|
@ -222,4 +223,34 @@ struct QSequenceConverter
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct QFlagsConverter
|
||||||
|
{
|
||||||
|
static inline bool checkType(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return PyObject_TypeCheck(pyObj, Shiboken::SbkType<T>());
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool isConvertible(PyObject* pyObj)
|
||||||
|
{
|
||||||
|
return PyObject_TypeCheck(pyObj, Shiboken::SbkType<T>())
|
||||||
|
|| PyObject_TypeCheck(pyObj, Shiboken::SbkType<typename T::enum_type>());
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline PyObject* toPython(void* cppobj)
|
||||||
|
{
|
||||||
|
return toPython(*reinterpret_cast<T*>(cppobj));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline PyObject* toPython(T cppenum)
|
||||||
|
{
|
||||||
|
return Shiboken::SbkEnumObject_New(Shiboken::SbkType<T>(), (long) cppenum);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline T toCpp(PyObject* pyobj)
|
||||||
|
{
|
||||||
|
return T(QFlag(reinterpret_cast<Shiboken::SbkEnumObject*>(pyobj)->ob_ival));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue