diff --git a/python/PyQt6/core/conversions.sip b/python/PyQt6/core/conversions.sip index 1bbb7cfe6b6..055a3029a0f 100644 --- a/python/PyQt6/core/conversions.sip +++ b/python/PyQt6/core/conversions.sip @@ -2125,7 +2125,83 @@ template %End }; +%MappedType QMap +{ + %TypeHeaderCode +#include + %End + %ConvertFromTypeCode + // Create the dictionary. + PyObject *d = PyDict_New(); + + if (!d) + return NULL; + + // Set the dictionary elements. + QMap::const_iterator i = sipCpp->constBegin(); + + while (i != sipCpp->constEnd()) + { + PyObject *kobj = PyLong_FromLong(i.key()); + PyObject *vobj = PyLong_FromLong(i.value()); + + if (kobj == NULL || vobj == NULL || PyDict_SetItem(d, kobj, vobj) < 0) + { + Py_DECREF(d); + + if (kobj) { + Py_DECREF(kobj); + } + if (vobj) { + Py_DECREF(vobj); + } + + return NULL; + } + + Py_DECREF(kobj); + Py_DECREF(vobj); + + ++i; + } + + return d; + %End + + %ConvertToTypeCode + PyObject *t1obj, *t2obj; + Py_ssize_t i = 0; + + // 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 t1 = PyLong_AsLong(t1obj); + int t2 = PyLong_AsLong(t2obj); + qm->insert(t1, t2); + } + + *sipCppPtr = qm; + + return sipGetState(sipTransferObj); + %End +}; template %MappedType QMap diff --git a/python/core/conversions.sip b/python/core/conversions.sip index 0531ad7929f..81872ec53a2 100644 --- a/python/core/conversions.sip +++ b/python/core/conversions.sip @@ -2175,7 +2175,83 @@ template %End }; +%MappedType QMap +{ + %TypeHeaderCode +#include + %End + %ConvertFromTypeCode + // Create the dictionary. + PyObject *d = PyDict_New(); + + if (!d) + return NULL; + + // Set the dictionary elements. + QMap::const_iterator i = sipCpp->constBegin(); + + while (i != sipCpp->constEnd()) + { + PyObject *kobj = PyLong_FromLong(i.key()); + PyObject *vobj = PyLong_FromLong(i.value()); + + if (kobj == NULL || vobj == NULL || PyDict_SetItem(d, kobj, vobj) < 0) + { + Py_DECREF(d); + + if (kobj) { + Py_DECREF(kobj); + } + if (vobj) { + Py_DECREF(vobj); + } + + return NULL; + } + + Py_DECREF(kobj); + Py_DECREF(vobj); + + ++i; + } + + return d; + %End + + %ConvertToTypeCode + PyObject *t1obj, *t2obj; + Py_ssize_t i = 0; + + // 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 t1 = PyLong_AsLong(t1obj); + int t2 = PyLong_AsLong(t2obj); + qm->insert(t1, t2); + } + + *sipCppPtr = qm; + + return sipGetState(sipTransferObj); + %End +}; template %MappedType QMap