diff --git a/python/core/conversions.sip b/python/core/conversions.sip index d0b6475f5cd..5a1250c0957 100644 --- a/python/core/conversions.sip +++ b/python/core/conversions.sip @@ -1198,6 +1198,112 @@ template }; +template +%MappedType QMap > +{ +%TypeHeaderCode +#include +#include +%End + +%ConvertFromTypeCode + // Create the dictionary. + PyObject *d = PyDict_New(); + + if (!d) + return NULL; + + const sipMappedType *qlist_type = sipFindMappedType("QList"); + + // Set the dictionary elements. + QMap >::const_iterator i; + + for (i = sipCpp->constBegin(); i != sipCpp->constEnd(); ++i) + { + QString *t1 = new QString(i.key()); + + PyObject *t1obj = sipConvertFromNewType(t1, sipType_QString, sipTransferObj); + + QList< TYPE2 > *t2 = new QList< TYPE2 >( i.value() ); + + PyObject *t2obj = sipConvertFromMappedType(t2, qlist_type, sipTransferObj); + + if (t1obj == NULL || t2obj == NULL || PyDict_SetItem(d, t1obj, t2obj) < 0) + { + Py_DECREF(d); + + if (t1obj) + Py_DECREF(t1obj); + + if (t2obj) + Py_DECREF(t2obj); + else + delete t2; + + return NULL; + } + + Py_DECREF(t1obj); + Py_DECREF(t2obj); + } + + return d; +%End + +%ConvertToTypeCode + PyObject *t1obj, *t2obj; + Py_ssize_t i = 0; + + + const sipMappedType *qlist_type = sipFindMappedType("QList"); + + + // Check the type if that is all that is required. + if (sipIsErr == NULL) + { + if (!PyDict_Check(sipPy)) + return 0; + + while (PyDict_Next(sipPy, &i, &t1obj, &t2obj)) + { + if (!sipCanConvertToType(t1obj, sipType_QString, SIP_NOT_NONE)) + return 0; + } + + return 1; + } + + QMap > *qm = new QMap >; + + while (PyDict_Next(sipPy, &i, &t1obj, &t2obj)) + { + int state; + + QString *t1 = reinterpret_cast(sipConvertToType(t1obj, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + + QList *t2 = reinterpret_cast< QList * >(sipConvertToMappedType(t2obj, qlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + if (*sipIsErr) + { + sipReleaseType(t2, sipType_TYPE2, state); + delete qm; + return 0; + } + + if ( t2 ) + qm->insert(*t1, *t2); + else + qm->insert(*t1, QList() ); + + sipReleaseType(t1, sipType_QString, state); + + sipReleaseType(t2, sipType_TYPE2, state); + } + + *sipCppPtr = qm; + + return sipGetState(sipTransferObj); +%End +}; template %MappedType QMultiMap