PythonQt
Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
PythonQtConv Class Reference

a static class that offers methods for type conversion More...

#include <PythonQtConversion.h>

Static Public Member Functions

static PyObjectGetPyBool (bool val)
 get a ref counted True or False Python object
 
static PyObjectConvertQtValueToPython (const PythonQtMethodInfo::ParameterInfo &info, const void *data)
 converts the Qt parameter given in data, interpreting it as a info parameter, into a Python object,
 
static voidConvertPythonToQt (const PythonQtMethodInfo::ParameterInfo &info, PyObject *obj, bool strict, PythonQtClassInfo *classInfo, void *alreadyAllocatedCPPObject, PythonQtArgumentFrame *frame=nullptr)
 
static voidCreateQtReturnValue (const PythonQtMethodInfo::ParameterInfo &info, PythonQtArgumentFrame *frame)
 creates a data storage for the passed parameter type and returns a void pointer to be set as arg[0] of qt_metacall
 
static PyObjectQStringToPyObject (const QString &str)
 converts QString to Python string (unicode!)
 
static PyObjectQStringListToPyObject (const QStringList &list)
 converts QStringList to Python tuple
 
static PyObjectQStringListToPyList (const QStringList &list)
 converts QStringList to Python list
 
static QString PyObjGetRepresentation (PyObject *val)
 get string representation of py object
 
static QString PyObjGetString (PyObject *val)
 get string value from py object
 
static QString PyObjGetString (PyObject *val, bool strict, bool &ok)
 get string value from py object
 
static QByteArray PyObjGetBytes (PyObject *val, bool strict, bool &ok)
 get bytes from py object
 
static QByteArray PyObjGetBytesAllowString (PyObject *val, bool strict, bool &ok)
 get bytes from py object, also allows Python string
 
static int PyObjGetInt (PyObject *val, bool strict, bool &ok)
 get int from py object
 
static qint64 PyObjGetLongLong (PyObject *val, bool strict, bool &ok)
 get int64 from py object
 
static quint64 PyObjGetULongLong (PyObject *val, bool strict, bool &ok)
 get int64 from py object
 
static double PyObjGetDouble (PyObject *val, bool strict, bool &ok)
 get double from py object
 
static bool PyObjGetBool (PyObject *val, bool strict, bool &ok)
 get bool from py object
 
static QStringList PyObjToStringList (PyObject *val, bool strict, bool &ok)
 create a string list from python sequence
 
static QVariant PyObjToQVariant (PyObject *val, int type=-1)
 
static PyObjectQVariantToPyObject (const QVariant &v)
 convert QVariant from PyObject
 
static PyObjectQVariantHashToPyObject (const QVariantHash &m)
 
static PyObjectQVariantMapToPyObject (const QVariantMap &m)
 
static PyObjectQVariantListToPyObject (const QVariantList &l)
 
static QString CPPObjectToString (int type, const void *data)
 get human readable string from CPP object (when the metatype is known)
 
static void registerPythonToMetaTypeConverter (int metaTypeId, PythonQtConvertPythonToMetaTypeCB *cb)
 register a converter callback from python to cpp for given metatype
 
static void registerMetaTypeToPythonConverter (int metaTypeId, PythonQtConvertMetaTypeToPythonCB *cb)
 register a converter callback from cpp to python for given metatype
 
static void setPythonSequenceToQVariantListCallback (PythonQtConvertPythonSequenceToQVariantListCB *cb)
 
static PyObjectconvertQtValueToPythonInternal (int type, const void *data)
 converts the Qt parameter given in data, interpreting it as a type registered qvariant/meta type, into a Python object,
 
static PyObjectcreateCopyFromMetaType (int type, const void *object)
 creates a copy of given object, using the QMetaType
 
static voidcastWrapperTo (PythonQtInstanceWrapper *wrapper, const QByteArray &className, bool &ok)
 cast wrapper to given className if possible
 
static bool convertToPythonQtObjectPtr (PyObject *obj, void *outPtr, int, bool)
 
static PyObjectconvertFromPythonQtObjectPtr (const void *inObject, int)
 
static bool convertToPythonQtSafeObjectPtr (PyObject *obj, void *outPtr, int, bool)
 
static PyObjectconvertFromPythonQtSafeObjectPtr (const void *inObject, int)
 
static bool convertToQListOfPythonQtObjectPtr (PyObject *obj, void *outList, int, bool)
 
static PyObjectconvertFromQListOfPythonQtObjectPtr (const void *inObject, int)
 
static PyObjectconvertFromStringRef (const void *inObject, int)
 
static QByteArray getCPPTypeName (PyObject *type)
 Returns the name of the equivalent CPP type (for signals and slots)
 
static bool isStringType (PyTypeObject *type)
 Returns if the given object is a string (or unicode string)
 
static void registerStringViewTypes ()
 Register QStringView like types, that need to be handled specially.
 

Static Protected Member Functions

static voidhandlePythonToQtAutoConversion (int typeId, PyObject *obj, void *alreadyAllocatedCPPObject, PythonQtArgumentFrame *frame)
 handle automatic conversion of some special types (QColor, QBrush, ...)
 
static PyObjectConvertQListOfPointerTypeToPythonList (QList< void * > *list, const PythonQtMethodInfo::ParameterInfo &info)
 converts the list of pointers of given type to Python
 
static bool ConvertPythonListToQListOfPointerType (PyObject *obj, QList< void * > *list, const PythonQtMethodInfo::ParameterInfo &info, bool strict)
 tries to convert the python object to a QList of pointers to type objects, returns true on success
 
template<typename Map >
static void pythonToMapVariant (PyObject *val, QVariant &result)
 helper template method for conversion from Python to QVariantMap/Hash
 
template<typename Map >
static PyObjectmapToPython (const Map &m)
 helper template function for QVariantMapToPyObject/QVariantHashToPyObject
 

Static Protected Attributes

static QHash< int, PythonQtConvertMetaTypeToPythonCB * > _metaTypeToPythonConverters
 
static QHash< int, PythonQtConvertPythonToMetaTypeCB * > _pythonToMetaTypeConverters
 
static PythonQtConvertPythonSequenceToQVariantListCB_pythonSequenceToQVariantListCB
 
static int stringRefTypeId
 

Detailed Description

a static class that offers methods for type conversion

Definition at line 113 of file PythonQtConversion.h.

Member Function Documentation

◆ castWrapperTo()

static void * PythonQtConv::castWrapperTo ( PythonQtInstanceWrapper wrapper,
const QByteArray className,
bool ok 
)
static

cast wrapper to given className if possible

Referenced by PythonQtConvertPythonListToListOfKnownClass().

◆ convertFromPythonQtObjectPtr()

static PyObject * PythonQtConv::convertFromPythonQtObjectPtr ( const void inObject,
int   
)
static

◆ convertFromPythonQtSafeObjectPtr()

static PyObject * PythonQtConv::convertFromPythonQtSafeObjectPtr ( const void inObject,
int   
)
static

◆ convertFromQListOfPythonQtObjectPtr()

static PyObject * PythonQtConv::convertFromQListOfPythonQtObjectPtr ( const void inObject,
int   
)
static

◆ convertFromStringRef()

static PyObject * PythonQtConv::convertFromStringRef ( const void inObject,
int   
)
static

◆ ConvertPythonListToQListOfPointerType()

static bool PythonQtConv::ConvertPythonListToQListOfPointerType ( PyObject obj,
QList< void * > *  list,
const PythonQtMethodInfo::ParameterInfo info,
bool  strict 
)
staticprotected

tries to convert the python object to a QList of pointers to type objects, returns true on success

◆ ConvertPythonToQt()

static void * PythonQtConv::ConvertPythonToQt ( const PythonQtMethodInfo::ParameterInfo info,
PyObject obj,
bool  strict,
PythonQtClassInfo classInfo,
void alreadyAllocatedCPPObject,
PythonQtArgumentFrame frame = nullptr 
)
static

convert python object to Qt (according to the given parameter) and if the conversion should be strict (classInfo is currently not used anymore) If an alreadyAllocatedCPPObject is used it must have the same type as given by info.typeId

◆ ConvertQListOfPointerTypeToPythonList()

static PyObject * PythonQtConv::ConvertQListOfPointerTypeToPythonList ( QList< void * > *  list,
const PythonQtMethodInfo::ParameterInfo info 
)
staticprotected

converts the list of pointers of given type to Python

◆ ConvertQtValueToPython()

static PyObject * PythonQtConv::ConvertQtValueToPython ( const PythonQtMethodInfo::ParameterInfo info,
const void data 
)
static

converts the Qt parameter given in data, interpreting it as a info parameter, into a Python object,

◆ convertQtValueToPythonInternal()

static PyObject * PythonQtConv::convertQtValueToPythonInternal ( int  type,
const void data 
)
static

converts the Qt parameter given in data, interpreting it as a type registered qvariant/meta type, into a Python object,

Referenced by PythonQtConvertIntegerMapToPython(), PythonQtConvertListOfValueTypeToPythonList(), and PythonQtConvertPairToPython().

◆ convertToPythonQtObjectPtr()

static bool PythonQtConv::convertToPythonQtObjectPtr ( PyObject obj,
void outPtr,
int  ,
bool   
)
static

◆ convertToPythonQtSafeObjectPtr()

static bool PythonQtConv::convertToPythonQtSafeObjectPtr ( PyObject obj,
void outPtr,
int  ,
bool   
)
static

◆ convertToQListOfPythonQtObjectPtr()

static bool PythonQtConv::convertToQListOfPythonQtObjectPtr ( PyObject obj,
void outList,
int  ,
bool   
)
static

◆ CPPObjectToString()

static QString PythonQtConv::CPPObjectToString ( int  type,
const void data 
)
static

get human readable string from CPP object (when the metatype is known)

◆ createCopyFromMetaType()

static PyObject * PythonQtConv::createCopyFromMetaType ( int  type,
const void object 
)
static

creates a copy of given object, using the QMetaType

◆ CreateQtReturnValue()

static void * PythonQtConv::CreateQtReturnValue ( const PythonQtMethodInfo::ParameterInfo info,
PythonQtArgumentFrame frame 
)
static

creates a data storage for the passed parameter type and returns a void pointer to be set as arg[0] of qt_metacall

◆ getCPPTypeName()

static QByteArray PythonQtConv::getCPPTypeName ( PyObject type)
static

Returns the name of the equivalent CPP type (for signals and slots)

◆ GetPyBool()

static PyObject * PythonQtConv::GetPyBool ( bool  val)
static

get a ref counted True or False Python object

◆ handlePythonToQtAutoConversion()

static void * PythonQtConv::handlePythonToQtAutoConversion ( int  typeId,
PyObject obj,
void alreadyAllocatedCPPObject,
PythonQtArgumentFrame frame 
)
staticprotected

handle automatic conversion of some special types (QColor, QBrush, ...)

◆ isStringType()

static bool PythonQtConv::isStringType ( PyTypeObject type)
static

Returns if the given object is a string (or unicode string)

◆ mapToPython()

template<typename Map >
static PyObject * PythonQtConv::mapToPython ( const Map m)
staticprotected

helper template function for QVariantMapToPyObject/QVariantHashToPyObject

◆ PyObjGetBool()

static bool PythonQtConv::PyObjGetBool ( PyObject val,
bool  strict,
bool ok 
)
static

get bool from py object

◆ PyObjGetBytes()

static QByteArray PythonQtConv::PyObjGetBytes ( PyObject val,
bool  strict,
bool ok 
)
static

get bytes from py object

◆ PyObjGetBytesAllowString()

static QByteArray PythonQtConv::PyObjGetBytesAllowString ( PyObject val,
bool  strict,
bool ok 
)
static

get bytes from py object, also allows Python string

◆ PyObjGetDouble()

static double PythonQtConv::PyObjGetDouble ( PyObject val,
bool  strict,
bool ok 
)
static

get double from py object

◆ PyObjGetInt()

static int PythonQtConv::PyObjGetInt ( PyObject val,
bool  strict,
bool ok 
)
static

get int from py object

Referenced by PythonQtConvertPythonToIntegerMap().

◆ PyObjGetLongLong()

static qint64 PythonQtConv::PyObjGetLongLong ( PyObject val,
bool  strict,
bool ok 
)
static

get int64 from py object

◆ PyObjGetRepresentation()

static QString PythonQtConv::PyObjGetRepresentation ( PyObject val)
static

get string representation of py object

◆ PyObjGetString() [1/2]

static QString PythonQtConv::PyObjGetString ( PyObject val)
inlinestatic

get string value from py object

Definition at line 145 of file PythonQtConversion.h.

146 {
147 bool ok;
148 QString s = PyObjGetString(val, false, ok);
149 return s;
150 }
PyObject * PythonQtConvertPairToPython(const void *inPair, int metaTypeId)
static QString PyObjGetString(PyObject *val)
get string value from py object

◆ PyObjGetString() [2/2]

static QString PythonQtConv::PyObjGetString ( PyObject val,
bool  strict,
bool ok 
)
static

get string value from py object

◆ PyObjGetULongLong()

static quint64 PythonQtConv::PyObjGetULongLong ( PyObject val,
bool  strict,
bool ok 
)
static

get int64 from py object

◆ PyObjToQVariant()

static QVariant PythonQtConv::PyObjToQVariant ( PyObject val,
int  type = -1 
)
static

convert python object to qvariant, if type is given it will try to create a qvariant of that type, otherwise it will guess from the python type

Referenced by PythonQtConvertPythonListToListOfValueType(), PythonQtConvertPythonToIntegerMap(), and PythonQtConvertPythonToPair().

◆ PyObjToStringList()

static QStringList PythonQtConv::PyObjToStringList ( PyObject val,
bool  strict,
bool ok 
)
static

create a string list from python sequence

◆ pythonToMapVariant()

template<typename Map >
static void PythonQtConv::pythonToMapVariant ( PyObject val,
QVariant result 
)
staticprotected

helper template method for conversion from Python to QVariantMap/Hash

◆ QStringListToPyList()

static PyObject * PythonQtConv::QStringListToPyList ( const QStringList list)
static

converts QStringList to Python list

◆ QStringListToPyObject()

static PyObject * PythonQtConv::QStringListToPyObject ( const QStringList list)
static

converts QStringList to Python tuple

◆ QStringToPyObject()

static PyObject * PythonQtConv::QStringToPyObject ( const QString str)
static

converts QString to Python string (unicode!)

◆ QVariantHashToPyObject()

static PyObject * PythonQtConv::QVariantHashToPyObject ( const QVariantHash m)
static

◆ QVariantListToPyObject()

static PyObject * PythonQtConv::QVariantListToPyObject ( const QVariantList l)
static

◆ QVariantMapToPyObject()

static PyObject * PythonQtConv::QVariantMapToPyObject ( const QVariantMap m)
static

◆ QVariantToPyObject()

static PyObject * PythonQtConv::QVariantToPyObject ( const QVariant v)
static

convert QVariant from PyObject

◆ registerMetaTypeToPythonConverter()

static void PythonQtConv::registerMetaTypeToPythonConverter ( int  metaTypeId,
PythonQtConvertMetaTypeToPythonCB cb 
)
inlinestatic

register a converter callback from cpp to python for given metatype

Definition at line 192 of file PythonQtConversion.h.

193 {
194 _metaTypeToPythonConverters.insert(metaTypeId, cb);
195 }
static QHash< int, PythonQtConvertMetaTypeToPythonCB * > _metaTypeToPythonConverters

◆ registerPythonToMetaTypeConverter()

static void PythonQtConv::registerPythonToMetaTypeConverter ( int  metaTypeId,
PythonQtConvertPythonToMetaTypeCB cb 
)
inlinestatic

register a converter callback from python to cpp for given metatype

Definition at line 186 of file PythonQtConversion.h.

187 {
188 _pythonToMetaTypeConverters.insert(metaTypeId, cb);
189 }
static QHash< int, PythonQtConvertPythonToMetaTypeCB * > _pythonToMetaTypeConverters

◆ registerStringViewTypes()

static void PythonQtConv::registerStringViewTypes ( )
static

Register QStringView like types, that need to be handled specially.

◆ setPythonSequenceToQVariantListCallback()

static void PythonQtConv::setPythonSequenceToQVariantListCallback ( PythonQtConvertPythonSequenceToQVariantListCB cb)
inlinestatic

set a callback that is called when a Python sequence should be converted to a QVariantList to allow special conversion.

Definition at line 199 of file PythonQtConversion.h.

200 {
202 }
static PythonQtConvertPythonSequenceToQVariantListCB * _pythonSequenceToQVariantListCB

Member Data Documentation

◆ _metaTypeToPythonConverters

QHash<int, PythonQtConvertMetaTypeToPythonCB*> PythonQtConv::_metaTypeToPythonConverters
staticprotected

Definition at line 241 of file PythonQtConversion.h.

◆ _pythonSequenceToQVariantListCB

PythonQtConvertPythonSequenceToQVariantListCB* PythonQtConv::_pythonSequenceToQVariantListCB
staticprotected

Definition at line 243 of file PythonQtConversion.h.

◆ _pythonToMetaTypeConverters

QHash<int, PythonQtConvertPythonToMetaTypeCB*> PythonQtConv::_pythonToMetaTypeConverters
staticprotected

Definition at line 242 of file PythonQtConversion.h.

◆ stringRefTypeId

int PythonQtConv::stringRefTypeId
staticprotected

Definition at line 264 of file PythonQtConversion.h.


The documentation for this class was generated from the following file: