#include "PythonQt.h"#include "PythonQtMisc.h"#include "PythonQtClassInfo.h"#include "PythonQtMethodInfo.h"#include <QWidget>#include <QList>#include <vector>Go to the source code of this file.
Classes | |
| class | PythonQtConv |
| a static class that offers methods for type conversion More... | |
Defines | |
| #define | PythonQtRegisterListTemplateConverter(type, innertype) |
| #define | PythonQtRegisterToolClassesTemplateConverter(innertype) |
Typedefs | |
| typedef PyObject * | PythonQtConvertMetaTypeToPythonCB (const void *inObject, int metaTypeId) |
| typedef bool | PythonQtConvertPythonToMetaTypeCB (PyObject *inObject, void *outObject, int metaTypeId, bool strict) |
Functions | |
| template<class ListType , class T > | |
| PyObject * | PythonQtConvertListOfValueTypeToPythonList (const void *inList, int metaTypeId) |
| template<class ListType , class T > | |
| bool | PythonQtConvertPythonListToListOfValueType (PyObject *obj, void *outList, int metaTypeId, bool) |
Definition in file PythonQtConversion.h.
| #define PythonQtRegisterListTemplateConverter | ( | type, | ||
| innertype | ||||
| ) |
{ int typeId = qRegisterMetaType<type<innertype> >(#type"<"#innertype">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfValueType<type<innertype>, innertype>); \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfValueTypeToPythonList<type<innertype>, innertype>); \
}
Definition at line 57 of file PythonQtConversion.h.
| #define PythonQtRegisterToolClassesTemplateConverter | ( | innertype | ) |
PythonQtRegisterListTemplateConverter(QList, innertype); \ PythonQtRegisterListTemplateConverter(QVector, innertype); \ PythonQtRegisterListTemplateConverter(std::vector, innertype);
Definition at line 63 of file PythonQtConversion.h.
| typedef PyObject* PythonQtConvertMetaTypeToPythonCB(const void *inObject, int metaTypeId) |
Definition at line 54 of file PythonQtConversion.h.
| typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject *inObject, void *outObject, int metaTypeId, bool strict) |
Definition at line 55 of file PythonQtConversion.h.
| PyObject* PythonQtConvertListOfValueTypeToPythonList | ( | const void * | inList, | |
| int | metaTypeId | |||
| ) |
Definition at line 166 of file PythonQtConversion.h.
References PythonQtConv::ConvertQtValueToPythonInternal(), and PythonQtConv::getInnerTemplateMetaType().
{
ListType* list = (ListType*)inList;
static const int innerType = PythonQtConv::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
if (innerType == QVariant::Invalid) {
std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
}
PyObject* result = PyTuple_New(list->size());
int i = 0;
foreach (const T& value, *list) {
PyTuple_SET_ITEM(result, i, PythonQtConv::ConvertQtValueToPythonInternal(innerType, &value));
i++;
}
return result;
}
| bool PythonQtConvertPythonListToListOfValueType | ( | PyObject * | obj, | |
| void * | outList, | |||
| int | metaTypeId, | |||
| bool | ||||
| ) |
Definition at line 183 of file PythonQtConversion.h.
References PythonQtConv::getInnerTemplateMetaType(), and PythonQtConv::PyObjToQVariant().
{
ListType* list = (ListType*)outList;
static const int innerType = PythonQtConv::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
if (innerType == QVariant::Invalid) {
std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
}
bool result = false;
if (PySequence_Check(obj)) {
result = true;
int count = PySequence_Size(obj);
PyObject* value;
for (int i = 0;i<count;i++) {
value = PySequence_GetItem(obj,i);
// this is quite some overhead, but it avoids having another large switch...
QVariant v = PythonQtConv::PyObjToQVariant(value, innerType);
if (v.isValid()) {
list->push_back(qVariantValue<T>(v));
} else {
result = false;
break;
}
}
}
return result;
}
1.7.1