--- qgis10-1.0.2/python/core/conversions.sip 2008-08-20 08:55:54.000000000 +0200 +++ qgis_head/python/core/conversions.sip 2009-12-01 12:49:07.000000000 +0100 @@ -3,12 +3,14 @@ which are not wrapped by PyQt: - QVector< QVector > - QVector< QVector< QVector > > +- QList< QList > - QSet - QSet - QMap > - QMap - QMap - QMultiMap +- QMap* */ %ModuleHeaderCode @@ -18,14 +20,20 @@ #if (PY_VERSION_HEX < 0x02050000) typedef int Py_ssize_t; #endif + %End + template %MappedType QVector< QVector > { %TypeHeaderCode #include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End %ConvertFromTypeCode @@ -102,6 +110,10 @@ { %TypeHeaderCode #include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End %ConvertFromTypeCode @@ -173,10 +185,93 @@ }; + +template +%MappedType QList< QList > +{ +%TypeHeaderCode +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ((l = PyList_New(sipCpp->size())) == NULL) + return NULL; + + const sipMappedType* qlist_type = sipFindMappedType("QList"); + + // Set the list elements. + for (int i = 0; i < sipCpp->size(); ++i) + { + QList* t = new QList(sipCpp->at(i)); + PyObject *tobj; + + if ((tobj = sipConvertFromMappedType(t, qlist_type, sipTransferObj)) == NULL) + { + Py_DECREF(l); + delete t; + return NULL; + } + PyList_SET_ITEM(l, i, tobj); + } + + return l; +%End + +%ConvertToTypeCode + const sipMappedType* qlist_type = sipFindMappedType("QList"); + + // Check the type if that is all that is required. + if (sipIsErr == NULL) + { + if (!PyList_Check(sipPy)) + return 0; + + for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) + if (!sipCanConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, SIP_NOT_NONE)) + return 0; + + return 1; + } + + + QList< QList > *ql = new QList< QList >; + + for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) + { + int state; + //TYPE *t = reinterpret_cast(sipConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + QList * t = reinterpret_cast< QList * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + + if (*sipIsErr) + { + sipReleaseInstance(t, sipClass_TYPE, state); + delete ql; + return 0; + } + ql->append(*t); + sipReleaseInstance(t, sipClass_TYPE, state); + } + + *sipCppPtr = ql; + return sipGetState(sipTransferObj); +%End + +}; + + + + %MappedType QSet { %TypeHeaderCode #include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End %ConvertFromTypeCode @@ -227,6 +322,10 @@ { %TypeHeaderCode #include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End %ConvertFromTypeCode @@ -299,6 +398,10 @@ { %TypeHeaderCode #include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End %ConvertFromTypeCode @@ -416,6 +519,10 @@ { %TypeHeaderCode #include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End %ConvertFromTypeCode @@ -516,7 +623,11 @@ %MappedType QMap { %TypeHeaderCode -#include +#include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End %ConvertFromTypeCode @@ -624,6 +735,10 @@ { %TypeHeaderCode #include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End %ConvertFromTypeCode @@ -737,3 +852,84 @@ return sipGetState(sipTransferObj); %End }; + +%MappedType QMap +{ +%TypeHeaderCode +#include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif +%End + +%ConvertFromTypeCode + +//convert map to a python dictionary + PyObject *d; + + if ((d = PyDict_New()) == NULL) + return NULL; + + for (QMap::iterator it = sipCpp->begin(); it != sipCpp->end(); ++it) + { + QgsOverlayObject* oobj = new QgsOverlayObject(*it.value()); + + PyObject* keyobj = PyInt_FromLong(it.key()); + PyObject* pyOobj = sipConvertFromInstance(oobj, sipClass_QgsOverlayObject, sipTransferObj); + PyDict_SetItem(d, keyobj, pyOobj); + + if(pyOobj == NULL || keyobj == NULL || PyDict_SetItem(d, keyobj, pyOobj) < 0) + { + Py_DECREF(d); + + if (pyOobj) + { + Py_DECREF(pyOobj); + } + + if (keyobj) + { + Py_DECREF(keyobj); + } + return NULL; + } + Py_DECREF(pyOobj); + Py_DECREF(keyobj); + } + return d; + +%End +%ConvertToTypeCode + PyObject *t1obj, *t2obj; +#if PY_VERSION_HEX >= 0x02050000 + Py_ssize_t i = 0; +#else + int i = 0; +#endif + + QMap *qm = new QMap; + + while (PyDict_Next(sipPy, &i, &t1obj, &t2obj)) + { + int state; + int t1 = (int)(PyFloat_AsDouble(t1obj)); + QgsOverlayObject* t2 = reinterpret_cast(sipConvertToInstance(t2obj, sipClass_QgsOverlayObject, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + + if (*sipIsErr) + { + sipReleaseInstance(t2, sipClass_QgsOverlayObject, state); + delete qm; + return 0; + } + + qm->insert(t1, t2); + + sipReleaseInstance(t2, sipClass_QgsOverlayObject, state); + } + + *sipCppPtr = qm; + + return sipGetState(sipTransferObj); +%End +};