@@ -6,6 +6,7 @@ which are not wrapped by PyQt:
66- QSet<int>
77- QSet<TYPE>
88- QMap<int, QMap<int, TYPE> >
9+ - QMap<TYPE1, TYPE2*>
910
1011*/
1112
@@ -408,3 +409,112 @@ template<TYPE>
408409
409410};
410411
412+
413+
414+
415+ template<TYPE1, TYPE2>
416+ %MappedType QMap<TYPE1, TYPE2*>
417+ {
418+ %TypeHeaderCode
419+ #include <qmap.h>
420+ %End
421+
422+ %ConvertFromTypeCode
423+ // Create the dictionary.
424+ PyObject *d = PyDict_New();
425+
426+ if (!d)
427+ return NULL;
428+
429+ // Set the dictionary elements.
430+ QMap<TYPE1, TYPE2*>::const_iterator i = sipCpp->constBegin();
431+
432+ while (i != sipCpp->constEnd())
433+ {
434+ TYPE1 *t1 = new TYPE1(i.key());
435+ TYPE2 *t2 = i.value();
436+
437+ PyObject *t1obj = sipConvertFromNewInstance(t1, sipClass_TYPE1, sipTransferObj);
438+ PyObject *t2obj = sipConvertFromInstance(t2, sipClass_TYPE2, sipTransferObj);
439+
440+ if (t1obj == NULL || t2obj == NULL || PyDict_SetItem(d, t1obj, t2obj) < 0)
441+ {
442+ Py_DECREF(d);
443+
444+ if (t1obj)
445+ Py_DECREF(t1obj);
446+ else
447+ delete t1;
448+
449+ if (t2obj)
450+ Py_DECREF(t2obj);
451+ else
452+ delete t2;
453+
454+ return NULL;
455+ }
456+
457+ Py_DECREF(t1obj);
458+ Py_DECREF(t2obj);
459+
460+ ++i;
461+ }
462+
463+ return d;
464+ %End
465+
466+ %ConvertToTypeCode
467+ PyObject *t1obj, *t2obj;
468+ #if PY_VERSION_HEX >= 0x02050000
469+ Py_ssize_t i = 0;
470+ #else
471+ int i = 0;
472+ #endif
473+
474+ // Check the type if that is all that is required.
475+ if (sipIsErr == NULL)
476+ {
477+ if (!PyDict_Check(sipPy))
478+ return 0;
479+
480+ while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
481+ {
482+ if (!sipCanConvertToInstance(t1obj, sipClass_TYPE1, SIP_NOT_NONE))
483+ return 0;
484+
485+ if (!sipCanConvertToInstance(t2obj, sipClass_TYPE2, SIP_NOT_NONE))
486+ return 0;
487+ }
488+
489+ return 1;
490+ }
491+
492+ QMap<TYPE1, TYPE2*> *qm = new QMap<TYPE1, TYPE2*>;
493+
494+ while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
495+ {
496+ int state1, state2;
497+
498+ TYPE1 *t1 = reinterpret_cast<TYPE1 *>(sipConvertToInstance(t1obj, sipClass_TYPE1, sipTransferObj, SIP_NOT_NONE, &state1, sipIsErr));
499+ TYPE2 *t2 = reinterpret_cast<TYPE2 *>(sipConvertToInstance(t2obj, sipClass_TYPE2, sipTransferObj, SIP_NOT_NONE, &state2, sipIsErr));
500+
501+ if (*sipIsErr)
502+ {
503+ sipReleaseInstance(t1, sipClass_TYPE1, state1);
504+ sipReleaseInstance(t2, sipClass_TYPE2, state2);
505+
506+ delete qm;
507+ return 0;
508+ }
509+
510+ qm->insert(*t1, t2);
511+
512+ sipReleaseInstance(t1, sipClass_TYPE1, state1);
513+ sipReleaseInstance(t2, sipClass_TYPE2, state2);
514+ }
515+
516+ *sipCppPtr = qm;
517+
518+ return sipGetState(sipTransferObj);
519+ %End
520+ };
0 commit comments