Skip to content

Commit

Permalink
add sip bindings for groupLayerRelationship (fixes #2969)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14164 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 28, 2010
1 parent 52b0200 commit 60abf63
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
85 changes: 85 additions & 0 deletions python/core/conversions.sip
Original file line number Diff line number Diff line change
Expand Up @@ -1035,3 +1035,88 @@ template<double, TYPE2>
return sipGetState(sipTransferObj);
%End
};

%MappedType QList < QPair< QString, QList<QString> > >
{
%TypeHeaderCode
#include <QPair>
#include <QList>
#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; i<sipCpp->size(); 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; j<sipCpp->at(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<QString> > > *qm = new QList < QPair< QString, QList<QString> > >;

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<QString *>(sipConvertToInstance(sipString, sipClass_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
l << *t1;
sipReleaseInstance(t1, sipClass_QString, state);
}

QString *t1 = reinterpret_cast<QString *>(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
};
3 changes: 3 additions & 0 deletions python/gui/qgslegendinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString> > > groupLayerRelationship();

//! Return all layers in the project in legend order
//! @note added in 1.5
virtual QList< QgsMapLayer * > layers() const =0;
Expand Down

0 comments on commit 60abf63

Please sign in to comment.