From 60abf63599c43d3a2043e8aff7ec097681f51e8b Mon Sep 17 00:00:00 2001 From: jef Date: Sat, 28 Aug 2010 09:49:54 +0000 Subject: [PATCH] add sip bindings for groupLayerRelationship (fixes #2969) git-svn-id: http://svn.osgeo.org/qgis/trunk@14164 c8812cc2-4d05-0410-92ff-de0c093fc19c --- python/core/conversions.sip | 85 +++++++++++++++++++++++++++++++ python/gui/qgslegendinterface.sip | 3 ++ 2 files changed, 88 insertions(+) diff --git a/python/core/conversions.sip b/python/core/conversions.sip index 18d4f4b749f..9d840df1946 100644 --- a/python/core/conversions.sip +++ b/python/core/conversions.sip @@ -1035,3 +1035,88 @@ template return sipGetState(sipTransferObj); %End }; + +%MappedType QList < QPair< QString, QList > > +{ +%TypeHeaderCode +#include +#include +#if (SIP_VERSION >= 0x040900) +#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString)) +#endif +%End + +%ConvertFromTypeCode +//convert map to a python dictionary + PyObject *d; + + if ((d = PyList_New( sipCpp->size() )) == NULL) + return NULL; + + for ( int i = 0; isize(); i++ ) + { + PyObject *p; + if ((p = PyList_New(2) ) == NULL) + { + Py_DECREF(d); + return NULL; + } + + PyObject *l; + if ((l = PyList_New( sipCpp->at(i).second.size() )) == NULL) + { + Py_DECREF(d); + Py_DECREF(p); + return NULL; + } + + for( int j = 0; jat(i).second.size(); j++ ) + { + PyObject *t1obj = sipConvertFromNewInstance(new QString(sipCpp->at(i).second.at(j)), sipClass_QString, sipTransferObj); + PyList_SetItem( l, j, t1obj); + } + + PyObject *t1obj = sipConvertFromNewInstance(new QString(sipCpp->at(i).first), sipClass_QString, sipTransferObj); + PyList_SetItem( p, 0, t1obj ); + PyList_SetItem( p, 1, l); + + PyList_SetItem( d, i, p ); + } + + return d; +%End +%ConvertToTypeCode +#if PY_VERSION_HEX >= 0x02050000 + Py_ssize_t i = 0; +#else + int i = 0; +#endif + QList < QPair< QString, QList > > *qm = new QList < QPair< QString, QList > >; + + for ( i = 0; i < PyList_GET_SIZE(sipPy); i++ ) + { + PyObject *sipPair = PyList_GetItem( sipPy, i ); + PyObject *sipKey = PyList_GetItem( sipPair, 0 ); + PyObject *sipList = PyList_GetItem( sipPair, 1 ); + + QList< QString > l; + int state; + int j; + for ( j = 0; j < PyList_GET_SIZE( sipList ); j++ ) + { + PyObject *sipString = PyList_GetItem( sipList, j ); + QString *t1 = reinterpret_cast(sipConvertToInstance(sipString, sipClass_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + l << *t1; + sipReleaseInstance(t1, sipClass_QString, state); + } + + QString *t1 = reinterpret_cast(sipConvertToInstance(sipKey, sipClass_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + qm->append( qMakePair( *t1, l ) ); + sipReleaseInstance(t1, sipClass_QString, state); + } + + *sipCppPtr = qm; + + return sipGetState(sipTransferObj); +%End +}; diff --git a/python/gui/qgslegendinterface.sip b/python/gui/qgslegendinterface.sip index 8f4e34570c7..5291ccf2009 100644 --- a/python/gui/qgslegendinterface.sip +++ b/python/gui/qgslegendinterface.sip @@ -19,6 +19,9 @@ class QgsLegendInterface : QObject //! Return a string list of groups virtual QStringList groups() =0; + //! Return the relationship between groups and layers in the legend + virtual QList< QPair< QString, QList > > groupLayerRelationship(); + //! Return all layers in the project in legend order //! @note added in 1.5 virtual QList< QgsMapLayer * > layers() const =0;