@@ -103,12 +103,12 @@ template <TYPE>
103
103
104
104
if (*sipIsErr)
105
105
{
106
- sipReleaseInstance (t, sipClass_TYPE , state);
106
+ sipReleaseMappedType (t, qvector_qgspoint , state);
107
107
delete ql;
108
108
return 0;
109
109
}
110
110
ql->append(*t);
111
- sipReleaseInstance (t, sipClass_TYPE , state);
111
+ sipReleaseMappedType (t, qvector_qgspoint , state);
112
112
}
113
113
114
114
*sipCppPtr = ql;
@@ -185,12 +185,12 @@ template <TYPE>
185
185
186
186
if (*sipIsErr)
187
187
{
188
- sipReleaseInstance (t, sipClass_TYPE , state);
188
+ sipReleaseMappedType (t, qvector_qgspoint , state);
189
189
delete ql;
190
190
return 0;
191
191
}
192
192
ql->append(*t);
193
- sipReleaseInstance (t, sipClass_TYPE , state);
193
+ sipReleaseMappedType (t, qvector_qgspoint , state);
194
194
}
195
195
196
196
*sipCppPtr = ql;
@@ -261,12 +261,12 @@ template <TYPE>
261
261
262
262
if (*sipIsErr)
263
263
{
264
- sipReleaseInstance (t, sipClass_TYPE , state);
264
+ sipReleaseMappedType (t, qlist_type , state);
265
265
delete ql;
266
266
return 0;
267
267
}
268
268
ql->append(*t);
269
- sipReleaseInstance (t, sipClass_TYPE , state);
269
+ sipReleaseMappedType (t, qlist_type , state);
270
270
}
271
271
272
272
*sipCppPtr = ql;
@@ -571,38 +571,63 @@ template<TYPE>
571
571
572
572
%ConvertToTypeCode
573
573
PyObject *kobj, *tobj, *kobj2, *tobj2;
574
+ Py_ssize_t i = 0;
575
+
576
+ //TODO: it works using SIP
577
+ #if (SIP_VERSION >= 0x041200)
578
+ const sipMappedType* qmap2 = sipFindMappedType("QMap<int, TYPE>");
579
+ #endif
574
580
575
581
// Check the type if that is all that is required.
576
582
if (sipIsErr == NULL)
577
583
{
578
584
if (!PyDict_Check(sipPy))
579
585
return 0;
580
586
581
- Py_ssize_t i = 0;
582
587
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
583
588
{
584
589
if (!PyDict_Check(tobj))
585
590
return 0;
586
591
592
+ #if (SIP_VERSION >= 0x041200)
593
+ if (!sipCanConvertToMappedType(tobj, qmap2, SIP_NOT_NONE))
594
+ return 0;
595
+ #else
587
596
Py_ssize_t j = 0;
588
597
while (PyDict_Next(tobj, &j, &kobj2, &tobj2))
589
598
{
590
599
if (!sipCanConvertToInstance(tobj2, sipClass_TYPE, SIP_NOT_NONE))
591
600
return 0;
592
601
}
593
-
602
+ #endif
594
603
}
595
604
return 1;
596
605
}
597
606
598
607
QMap<qint64, QMap<int, TYPE> > *qm = new QMap<qint64, QMap<int, TYPE> >;
599
608
600
-
601
- Py_ssize_t i = 0;
602
609
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
603
610
{
604
611
qint64 k = PyLong_AsLongLong(kobj);
605
612
613
+ #if (SIP_VERSION >= 0x041200)
614
+ // TODO: search for the minimum SIP version this code works on, it works
615
+ // on SIP 4.13.3 (GS). See #else to know why the version check is needed.
616
+
617
+ int state;
618
+
619
+ TYPE* t = reinterpret_cast<TYPE*>(sipConvertToMappedType(tobj, qmap2, sipTransferObj,SIP_NOT_NONE,&state,sipIsErr));
620
+
621
+ if (*sipIsErr)
622
+ {
623
+ sipReleaseMappedType(t, qmap2, state);
624
+ delete qm;
625
+ return 0;
626
+ }
627
+
628
+ qm.insert(k, *t);
629
+ sipReleaseMappedType(t, qmap2, state);
630
+ #else
606
631
// using sipConvertToMappedType to convert directly to QMap<int, TYPE> doesn't work
607
632
// and ends with a segfault
608
633
@@ -614,19 +639,20 @@ template<TYPE>
614
639
int k2 = PyInt_AsLong(kobj2);
615
640
int state;
616
641
617
- TYPE* fa = reinterpret_cast<TYPE*>(sipConvertToInstance(tobj2, sipClass_TYPE, sipTransferObj,SIP_NOT_NONE,&state,sipIsErr));
642
+ TYPE* t2 = reinterpret_cast<TYPE*>(sipConvertToInstance(tobj2, sipClass_TYPE, sipTransferObj,SIP_NOT_NONE,&state,sipIsErr));
618
643
619
644
if (*sipIsErr)
620
645
{
621
- sipReleaseInstance(tobj2 , sipClass_TYPE, state);
646
+ sipReleaseInstance(t2 , sipClass_TYPE, state);
622
647
delete qm;
623
648
return 0;
624
649
}
625
650
626
- qm2.insert(k2, *fa );
627
- sipReleaseInstance(tobj2 , sipClass_TYPE, state);
651
+ qm2.insert(k2, *t2 );
652
+ sipReleaseInstance(t2 , sipClass_TYPE, state);
628
653
}
629
654
qm->insert(k, qm2);
655
+ #endif
630
656
}
631
657
632
658
*sipCppPtr = qm;
@@ -703,16 +729,17 @@ template<TYPE>
703
729
{
704
730
int state;
705
731
qint64 k = PyLong_AsLongLong(kobj);
706
- QgsGeometry * fa = reinterpret_cast<QgsGeometry*>(sipConvertToInstance(tobj, sipClass_QgsGeometry, sipTransferObj,SIP_NOT_NONE,&state,sipIsErr));
732
+ QgsGeometry * t = reinterpret_cast<QgsGeometry*>(sipConvertToInstance(tobj, sipClass_QgsGeometry, sipTransferObj,SIP_NOT_NONE,&state,sipIsErr));
707
733
708
734
if (*sipIsErr)
709
735
{
710
- sipReleaseInstance(tobj , sipClass_QgsGeometry, state);
736
+ sipReleaseInstance(t , sipClass_QgsGeometry, state);
711
737
delete qm;
712
738
return 0;
713
739
}
714
740
715
- qm->insert(k, *fa);
741
+ qm->insert(k, *t);
742
+ sipReleaseInstance(t, sipClass_QgsGeometry, state);
716
743
}
717
744
718
745
*sipCppPtr = qm;
0 commit comments