PythonQt
Classes | Macros | Typedefs | Functions
PythonQtConversion.h File Reference
#include "PythonQtPythonInclude.h"
#include "PythonQt.h"
#include "PythonQtMisc.h"
#include "PythonQtClassInfo.h"
#include "PythonQtMethodInfo.h"
#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...
 

Macros

#define PythonQtRegisterListTemplateConverter(type, innertype)
 
#define PythonQtRegisterListTemplateConverterForKnownClass(type, innertype)
 
#define PythonQtRegisterQPairConverter(type1, type2)
 
#define PythonQtRegisterIntegerMapConverter(type, innertype)
 
#define PythonQtRegisterListTemplateQPairConverter(listtype, type1, type2)
 
#define PythonQtRegisterToolClassesTemplateConverter(innertype)
 
#define PythonQtRegisterToolClassesTemplateConverterForKnownClass(innertype)
 

Typedefs

typedef PyObjectPythonQtConvertMetaTypeToPythonCB(const void *inObject, int metaTypeId)
 
typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject *inObject, void *outObject, int metaTypeId, bool strict)
 
typedef QVariant PythonQtConvertPythonSequenceToQVariantListCB(PyObject *inObject)
 

Functions

template<class ListType , class T >
PyObjectPythonQtConvertListOfValueTypeToPythonList (const void *inList, int metaTypeId)
 
template<class ListType , class T >
bool PythonQtConvertPythonListToListOfValueType (PyObject *obj, void *outList, int metaTypeId, bool)
 
template<class ListType , class T >
PyObjectPythonQtConvertListOfKnownClassToPythonList (const void *inList, int metaTypeId)
 
template<class ListType , class T >
bool PythonQtConvertPythonListToListOfKnownClass (PyObject *obj, void *outList, int metaTypeId, bool)
 
template<class T1 , class T2 >
PyObjectPythonQtConvertPairToPython (const void *inPair, int metaTypeId)
 
template<class T1 , class T2 >
bool PythonQtConvertPythonToPair (PyObject *obj, void *outPair, int metaTypeId, bool)
 
template<class ListType , class T1 , class T2 >
PyObjectPythonQtConvertListOfPairToPythonList (const void *inList, int metaTypeId)
 
template<class ListType , class T1 , class T2 >
bool PythonQtConvertPythonListToListOfPair (PyObject *obj, void *outList, int metaTypeId, bool)
 
template<class MapType , class T >
PyObjectPythonQtConvertIntegerMapToPython (const void *inMap, int metaTypeId)
 
template<class MapType , class T >
bool PythonQtConvertPythonToIntegerMap (PyObject *val, void *outMap, int metaTypeId, bool)
 

Detailed Description

Author
Florian Link
Last changed by
Author
florian
Date
2006-05

Definition in file PythonQtConversion.h.

Macro Definition Documentation

◆ PythonQtRegisterIntegerMapConverter

#define PythonQtRegisterIntegerMapConverter (   type,
  innertype 
)
Value:
{ int typeId = qRegisterMetaType<type<int, innertype > >(#type"<int, "#innertype">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToIntegerMap<type<int, innertype >, innertype>); \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertIntegerMapToPython<type<int, innertype >, innertype>); \
}
PyObject * PythonQtConvertPairToPython(const void *inPair, int metaTypeId)
PyObject * PythonQtConvertIntegerMapToPython(const void *inMap, int metaTypeId)
bool PythonQtConvertPythonToIntegerMap(PyObject *val, void *outMap, int metaTypeId, bool)

Definition at line 76 of file PythonQtConversion.h.

77{ int typeId = qRegisterMetaType<type<int, innertype > >(#type"<int, "#innertype">"); \
78 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToIntegerMap<type<int, innertype >, innertype>); \
79 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertIntegerMapToPython<type<int, innertype >, innertype>); \
80}

◆ PythonQtRegisterListTemplateConverter

#define PythonQtRegisterListTemplateConverter (   type,
  innertype 
)
Value:
{ int typeId = qRegisterMetaType<type<innertype > >(#type"<"#innertype">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfValueType<type<innertype >, innertype>); \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfValueTypeToPythonList<type<innertype >, innertype>); \
}
PyObject * PythonQtConvertListOfValueTypeToPythonList(const void *inList, int metaTypeId)
bool PythonQtConvertPythonListToListOfValueType(PyObject *obj, void *outList, int metaTypeId, bool)

Definition at line 58 of file PythonQtConversion.h.

59{ int typeId = qRegisterMetaType<type<innertype > >(#type"<"#innertype">"); \
60PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfValueType<type<innertype >, innertype>); \
61PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfValueTypeToPythonList<type<innertype >, innertype>); \
62}

◆ PythonQtRegisterListTemplateConverterForKnownClass

#define PythonQtRegisterListTemplateConverterForKnownClass (   type,
  innertype 
)
Value:
{ int typeId = qRegisterMetaType<type<innertype > >(#type"<"#innertype">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfKnownClass<type<innertype >, innertype>); \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfKnownClassToPythonList<type<innertype >, innertype>); \
}
bool PythonQtConvertPythonListToListOfKnownClass(PyObject *obj, void *outList, int metaTypeId, bool)
PyObject * PythonQtConvertListOfKnownClassToPythonList(const void *inList, int metaTypeId)

Definition at line 64 of file PythonQtConversion.h.

65{ int typeId = qRegisterMetaType<type<innertype > >(#type"<"#innertype">"); \
66 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfKnownClass<type<innertype >, innertype>); \
67 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfKnownClassToPythonList<type<innertype >, innertype>); \
68}

◆ PythonQtRegisterListTemplateQPairConverter

#define PythonQtRegisterListTemplateQPairConverter (   listtype,
  type1,
  type2 
)
Value:
{ \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfPair<listtype<QPair<type1, type2> >, type1, type2>); \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfPairToPythonList<listtype<QPair<type1, type2> >, type1, type2>); \
}
bool PythonQtConvertPythonListToListOfPair(PyObject *obj, void *outList, int metaTypeId, bool)
PyObject * PythonQtConvertListOfPairToPythonList(const void *inList, int metaTypeId)

Definition at line 82 of file PythonQtConversion.h.

83{ \
85 int typeId = qRegisterMetaType<listtype<QPair<type1, type2> > >(#listtype"<QPair<"#type1","#type2">>"); \
86 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfPair<listtype<QPair<type1, type2> >, type1, type2>); \
87 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfPairToPythonList<listtype<QPair<type1, type2> >, type1, type2>); \
88}

◆ PythonQtRegisterQPairConverter

#define PythonQtRegisterQPairConverter (   type1,
  type2 
)
Value:
{ int typeId = qRegisterMetaType<QPair<type1, type2> >("QPair<"#type1","#type2">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToPair<type1, type2>); \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertPairToPython<type1, type2>); \
}

Definition at line 70 of file PythonQtConversion.h.

71{ int typeId = qRegisterMetaType<QPair<type1, type2> >("QPair<"#type1","#type2">"); \
72 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToPair<type1, type2>); \
73 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertPairToPython<type1, type2>); \
74}

◆ PythonQtRegisterToolClassesTemplateConverter

#define PythonQtRegisterToolClassesTemplateConverter (   innertype)

◆ PythonQtRegisterToolClassesTemplateConverterForKnownClass

#define PythonQtRegisterToolClassesTemplateConverterForKnownClass (   innertype)

Typedef Documentation

◆ PythonQtConvertMetaTypeToPythonCB

typedef PyObject * PythonQtConvertMetaTypeToPythonCB(const void *inObject, int metaTypeId)

Definition at line 54 of file PythonQtConversion.h.

◆ PythonQtConvertPythonSequenceToQVariantListCB

typedef QVariant PythonQtConvertPythonSequenceToQVariantListCB(PyObject *inObject)

Definition at line 56 of file PythonQtConversion.h.

◆ PythonQtConvertPythonToMetaTypeCB

typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject *inObject, void *outObject, int metaTypeId, bool strict)

Definition at line 55 of file PythonQtConversion.h.

Function Documentation

◆ PythonQtConvertIntegerMapToPython()

template<class MapType , class T >
PyObject * PythonQtConvertIntegerMapToPython ( const void inMap,
int  metaTypeId 
)

Definition at line 468 of file PythonQtConversion.h.

469{
471 static int innerType = -1;
472 if (innerType == -1) {
475 innerType = QMetaType::type(names.at(1).trimmed());
476 }
477 if (innerType == QVariant::Invalid) {
478 std::cerr << "PythonQtConvertIntegerMapToPython: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
479 }
480
482 typename MapType::const_iterator t = map->constBegin();
483 PyObject* key;
484 PyObject* val;
485 for (; t != map->constEnd(); t++) {
486 key = PyInt_FromLong(t.key());
489 Py_DECREF(key);
490 Py_DECREF(val);
491 }
492 return result;
493}
struct _object PyObject
static PyObject * convertQtValueToPythonInternal(int type, const void *data)
converts the Qt parameter given in data, interpreting it as a type registered qvariant/meta type,...
static QByteArray getInnerTemplateTypeName(const QByteArray &typeName)
returns the inner type name of a simple template of the form SomeObject<InnerType>

References PythonQtConv::convertQtValueToPythonInternal(), PythonQtMethodInfo::getInnerTemplateTypeName(), and PythonQtConvertPairToPython().

◆ PythonQtConvertListOfKnownClassToPythonList()

template<class ListType , class T >
PyObject * PythonQtConvertListOfKnownClassToPythonList ( const void inList,
int  metaTypeId 
)

Definition at line 287 of file PythonQtConversion.h.

288{
291 if (innerType == nullptr) {
292 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for " << QMetaType::typeName(metaTypeId) << std::endl;
293 }
294 PyObject* result = PyTuple_New(list->size());
295 int i = 0;
296 Q_FOREACH(const T& value, *list) {
297 T* newObject = new T(value);
299 wrap->_ownedByPythonQt = true;
301 i++;
302 }
303 return result;
304}
a class that stores all required information about a Qt object (and an optional associated C++ class ...
static QByteArray getInnerListTypeName(const QByteArray &typeName)
returns the inner type name of a simple template or the typename without appended "List".
PyObject * wrapPtr(void *ptr, const QByteArray &name, bool passOwnership=false)
PythonQtClassInfo * getClassInfo(const QMetaObject *meta)
get the class info for a meta object (if available)
static PythonQtPrivate * priv()
get access to internal data (should not be used on the public API, but is used by some C functions)
Definition PythonQt.h:557
a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjec...
bool _ownedByPythonQt
flag that stores if the object is owned by pythonQt

References PythonQtInstanceWrapper::_ownedByPythonQt, PythonQtClassInfo::className(), PythonQtPrivate::getClassInfo(), PythonQtMethodInfo::getInnerListTypeName(), PythonQt::priv(), and PythonQtPrivate::wrapPtr().

◆ PythonQtConvertListOfPairToPythonList()

template<class ListType , class T1 , class T2 >
PyObject * PythonQtConvertListOfPairToPythonList ( const void inList,
int  metaTypeId 
)

Definition at line 416 of file PythonQtConversion.h.

417{
419 static int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
420 if (innerType == QVariant::Invalid) {
421 std::cerr << "PythonQtConvertListOfPairToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
422 }
423 PyObject* result = PyTuple_New(list->size());
424 int i = 0;
425 typedef const QPair<T1, T2> Pair;
428 PyTuple_SET_ITEM(result, i, object);
429 i++;
430 }
431 return result;
432}
static int getInnerTemplateMetaType(const QByteArray &typeName)
returns the inner type id of a simple template of the form SomeObject<InnerType>

References PythonQtMethodInfo::getInnerTemplateMetaType(), and PythonQtConvertPairToPython().

◆ PythonQtConvertListOfValueTypeToPythonList()

template<class ListType , class T >
PyObject * PythonQtConvertListOfValueTypeToPythonList ( const void inList,
int  metaTypeId 
)

Definition at line 237 of file PythonQtConversion.h.

238{
240 static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
241 if (innerType == QVariant::Invalid) {
242 std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
243 }
244 PyObject* result = PyTuple_New(list->size());
245 int i = 0;
246 Q_FOREACH (const T& value, *list) {
248 i++;
249 }
250 return result;
251}

References PythonQtConv::convertQtValueToPythonInternal(), and PythonQtMethodInfo::getInnerTemplateMetaType().

◆ PythonQtConvertPairToPython()

template<class T1 , class T2 >
PyObject * PythonQtConvertPairToPython ( const void *  inPair,
int  metaTypeId 
)

Definition at line 347 of file PythonQtConversion.h.

348{
350 static int innerType1 = -1;
351 static int innerType2 = -1;
352 if (innerType1==-1) {
355 innerType1 = QMetaType::type(names.at(0).trimmed());
356 innerType2 = QMetaType::type(names.at(1).trimmed());
357 }
358 if (innerType1 == QVariant::Invalid || innerType2 == QVariant::Invalid) {
359 std::cerr << "PythonQtConvertPairToPython: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
360 }
364 return result;
365}

References PythonQtConv::convertQtValueToPythonInternal(), and PythonQtMethodInfo::getInnerTemplateTypeName().

Referenced by PythonQtInstanceWrapper::classInfo(), PythonQtWrapper_QMetaObject::classInfo(), PythonQtWrapper_QMetaObject::classInfoCount(), PythonQtWrapper_QMetaObject::classInfoOffset(), PythonQtStdDecorators::connect(), PythonQtWrapper_QMetaObject::constructor(), PythonQtWrapper_QMetaObject::constructorCount(), PythonQtInstanceWrapper::dynamicClassInfo(), PythonQtWrapper_QMetaObject::enumerator(), PythonQtWrapper_QMetaObject::enumeratorCount(), PythonQtWrapper_QMetaObject::enumeratorOffset(), PythonQtWrapper_QMetaObject::getClassName(), PythonQtWrapper_QMetaObject::indexOfClassInfo(), PythonQtWrapper_QMetaObject::indexOfConstructor(), PythonQtWrapper_QMetaObject::indexOfEnumerator(), PythonQtWrapper_QMetaObject::indexOfMethod(), PythonQtWrapper_QMetaObject::indexOfProperty(), PythonQtWrapper_QMetaObject::indexOfSignal(), PythonQtWrapper_QMetaObject::indexOfSlot(), PythonQtUtils::isPythonClassType(), PythonQtWrapper_QMetaObject::method(), PythonQtWrapper_QMetaObject::methodCount(), PythonQtUtils::methodName(), PythonQtWrapper_QMetaObject::methodOffset(), PythonQtObjectPtr::operator!=(), PythonQtSafeObjectPtr::operator!=(), PythonQtObjectPtr::operator!=(), PythonQtSafeObjectPtr::operator!=(), PythonQtObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtObjectPtr::operator=(), PythonQtObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtObjectPtr::operator==(), PythonQtSafeObjectPtr::operator==(), PythonQtObjectPtr::operator==(), PythonQtSafeObjectPtr::operator==(), PythonQtInstanceWrapper::passOwnershipToCPP(), PythonQtInstanceWrapper::passOwnershipToPython(), PythonQtWrapper_QMetaObject::property(), PythonQtWrapper_QMetaObject::propertyCount(), PythonQtWrapper_QMetaObject::propertyOffset(), PythonQtConvertIntegerMapToPython(), PythonQtConvertListOfPairToPythonList(), PythonQtConvertPythonListToListOfPair(), PythonQtConvertPythonToIntegerMap(), PythonQtMethodInfo::PythonQtMethodInfo(), PythonQtObjectPtr::PythonQtObjectPtr(), PythonQtObjectPtr::PythonQtObjectPtr(), PythonQtSafeObjectPtr::PythonQtSafeObjectPtr(), PythonQtSafeObjectPtr::PythonQtSafeObjectPtr(), PythonQtSafeObjectPtr::PythonQtSafeObjectPtr(), PythonQtSignalTarget::PythonQtSignalTarget(), PythonQtSlotInfo::PythonQtSlotInfo(), PythonQtSlotInfo::PythonQtSlotInfo(), PythonQtThreadStateSaver::restore(), PythonQtThreadStateSaver::save(), PythonQtSlotInfo::setNextInfo(), PythonQtUtils::signature(), PythonQtWrapper_QMetaObject::static_QMetaObject_checkConnectArgs(), PythonQtStdDecorators::static_QObject_connect(), PythonQtStdDecorators::static_QObject_connect(), PythonQtStdDecorators::static_QObject_disconnect(), PythonQtStdDecorators::static_QObject_disconnect(), PythonQtStdDecorators::static_Qt_qAbs(), PythonQtStdDecorators::static_Qt_qBound(), PythonQtStdDecorators::static_Qt_qCritical(), PythonQtStdDecorators::static_Qt_qDebug(), PythonQtStdDecorators::static_Qt_qFatal(), PythonQtStdDecorators::static_Qt_qFuzzyCompare(), PythonQtStdDecorators::static_Qt_qMax(), PythonQtStdDecorators::static_Qt_qMin(), PythonQtStdDecorators::static_Qt_qrand(), PythonQtStdDecorators::static_Qt_qRound(), PythonQtStdDecorators::static_Qt_qRound64(), PythonQtStdDecorators::static_Qt_qsrand(), PythonQtStdDecorators::static_Qt_qVersion(), PythonQtStdDecorators::static_Qt_qWarning(), PythonQtStdDecorators::static_Qt_SIGNAL(), PythonQtStdDecorators::static_Qt_SLOT(), PythonQtWrapper_QMetaObject::superClass(), PythonQtObjectPtr::takeObject(), PythonQtSafeObjectPtr::takeObject(), PythonQtUtils::typeName(), and PythonQtWrapper_QMetaObject::userProperty().

◆ PythonQtConvertPythonListToListOfKnownClass()

template<class ListType , class T >
bool PythonQtConvertPythonListToListOfKnownClass ( PyObject obj,
void outList,
int  metaTypeId,
bool   
)

Definition at line 307 of file PythonQtConversion.h.

308{
311 if (innerType == nullptr) {
312 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for " << QMetaType::typeName(metaTypeId) << std::endl;
313 }
314 bool result = false;
315 if (PySequence_Check(obj)) {
317 if (count >= 0) {
318 result = true;
320 for (int i = 0; i < count; i++) {
324 bool ok;
325 T* object = (T*)PythonQtConv::castWrapperTo(wrap, innerType->className(), ok);
327 if (ok) {
328 list->push_back(*object);
329 } else {
330 result = false;
331 break;
332 }
333 } else {
335 result = false;
336 break;
337 }
338 }
339 }
340 }
341 return result;
342}
PYTHONQT_EXPORT PyTypeObject PythonQtInstanceWrapper_Type
static void * castWrapperTo(PythonQtInstanceWrapper *wrapper, const QByteArray &className, bool &ok)
cast wrapper to given className if possible

References PythonQtConv::castWrapperTo(), PythonQtClassInfo::className(), PythonQtPrivate::getClassInfo(), PythonQtMethodInfo::getInnerListTypeName(), PythonQt::priv(), and PythonQtInstanceWrapper_Type.

◆ PythonQtConvertPythonListToListOfPair()

template<class ListType , class T1 , class T2 >
bool PythonQtConvertPythonListToListOfPair ( PyObject obj,
void outList,
int  metaTypeId,
bool   
)

Definition at line 435 of file PythonQtConversion.h.

436{
438 static int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
439 if (innerType == QVariant::Invalid) {
440 std::cerr << "PythonQtConvertPythonListToListOfPair: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
441 }
442 bool result = false;
443 if (PySequence_Check(obj)) {
445 if (count >= 0) {
446 result = true;
448 for (int i = 0; i < count; i++) {
453 list->push_back(pair);
454 } else {
456 result = false;
457 break;
458 }
459 }
460 }
461 }
462 return result;
463}

References PythonQtMethodInfo::getInnerTemplateMetaType(), and PythonQtConvertPairToPython().

◆ PythonQtConvertPythonListToListOfValueType()

template<class ListType , class T >
bool PythonQtConvertPythonListToListOfValueType ( PyObject obj,
void outList,
int  metaTypeId,
bool   
)

Definition at line 254 of file PythonQtConversion.h.

255{
257 static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
258 if (innerType == QVariant::Invalid) {
259 std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
260 }
261 bool result = false;
262 if (PySequence_Check(obj)) {
264 if (count >= 0) {
265 result = true;
267 for (int i = 0;i<count;i++) {
269 // this is quite some overhead, but it avoids having another large switch...
272 if (v.isValid()) {
273 list->push_back(qvariant_cast<T>(v));
274 } else {
275 result = false;
276 break;
277 }
278 }
279 }
280 }
281 return result;
282}
static QVariant PyObjToQVariant(PyObject *val, int type=-1)

References PythonQtMethodInfo::getInnerTemplateMetaType(), and PythonQtConv::PyObjToQVariant().

◆ PythonQtConvertPythonToIntegerMap()

template<class MapType , class T >
bool PythonQtConvertPythonToIntegerMap ( PyObject val,
void outMap,
int  metaTypeId,
bool   
)

Definition at line 496 of file PythonQtConversion.h.

497{
499 static int innerType = -1;
500 if (innerType == -1) {
503 innerType = QMetaType::type(names.at(1).trimmed());
504 }
505 if (innerType == QVariant::Invalid) {
506 std::cerr << "PythonQtConvertPythonToIntegerMap: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
507 }
508 bool result = false;
509 if (PyMapping_Check(val)) {
510 result = true;
512 if (items) {
513 int count = PyList_Size(items);
515 PyObject* key;
517 for (int i = 0; i < count; i++) {
521
522 bool ok;
523 int intKey = PythonQtConv::PyObjGetInt(key, false, ok);
524 // this is quite some overhead, but it avoids having another large switch...
526 if (v.isValid() && ok) {
527 map->insert(intKey, qvariant_cast<T>(v));
528 } else {
529 result = false;
530 break;
531 }
532 }
534 }
535 }
536 return result;
537}
static int PyObjGetInt(PyObject *val, bool strict, bool &ok)
get int from py object

References PythonQtMethodInfo::getInnerTemplateTypeName(), PythonQtConv::PyObjGetInt(), PythonQtConv::PyObjToQVariant(), and PythonQtConvertPairToPython().

◆ PythonQtConvertPythonToPair()

template<class T1 , class T2 >
bool PythonQtConvertPythonToPair ( PyObject obj,
void outPair,
int  metaTypeId,
bool   
)

Definition at line 368 of file PythonQtConversion.h.

369{
371 static int innerType1 = -1;
372 static int innerType2 = -1;
373 if (innerType1 == -1) {
376 innerType1 = QMetaType::type(names.at(0).trimmed());
377 innerType2 = QMetaType::type(names.at(1).trimmed());
378 }
379 if (innerType1 == QVariant::Invalid || innerType2 == QVariant::Invalid) {
380 std::cerr << "PythonQtConvertPythonToPair: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
381 }
382 bool result = false;
383 if (PySequence_Check(obj)) {
385 if (count == 2) {
386 result = true;
388
390 // this is quite some overhead, but it avoids having another large switch...
393 if (v.isValid()) {
394 pair->first = qvariant_cast<T1>(v);
395 } else {
396 return false;
397 }
398
400 // this is quite some overhead, but it avoids having another large switch...
403 if (v.isValid()) {
404 pair->second = qvariant_cast<T2>(v);
405 } else {
406 return false;
407 }
408 }
409 }
410 return result;
411}

References PythonQtMethodInfo::getInnerTemplateTypeName(), and PythonQtConv::PyObjToQVariant().