Skip to content

Commit ef8c8d5

Browse files
author
jef
committedAug 28, 2010
add sip bindings for groupLayerRelationship (fixes #2969)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14164 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
 

‎python/core/conversions.sip

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,3 +1035,88 @@ template<double, TYPE2>
10351035
return sipGetState(sipTransferObj);
10361036
%End
10371037
};
1038+
1039+
%MappedType QList < QPair< QString, QList<QString> > >
1040+
{
1041+
%TypeHeaderCode
1042+
#include <QPair>
1043+
#include <QList>
1044+
#if (SIP_VERSION >= 0x040900)
1045+
#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString))
1046+
#endif
1047+
%End
1048+
1049+
%ConvertFromTypeCode
1050+
//convert map to a python dictionary
1051+
PyObject *d;
1052+
1053+
if ((d = PyList_New( sipCpp->size() )) == NULL)
1054+
return NULL;
1055+
1056+
for ( int i = 0; i<sipCpp->size(); i++ )
1057+
{
1058+
PyObject *p;
1059+
if ((p = PyList_New(2) ) == NULL)
1060+
{
1061+
Py_DECREF(d);
1062+
return NULL;
1063+
}
1064+
1065+
PyObject *l;
1066+
if ((l = PyList_New( sipCpp->at(i).second.size() )) == NULL)
1067+
{
1068+
Py_DECREF(d);
1069+
Py_DECREF(p);
1070+
return NULL;
1071+
}
1072+
1073+
for( int j = 0; j<sipCpp->at(i).second.size(); j++ )
1074+
{
1075+
PyObject *t1obj = sipConvertFromNewInstance(new QString(sipCpp->at(i).second.at(j)), sipClass_QString, sipTransferObj);
1076+
PyList_SetItem( l, j, t1obj);
1077+
}
1078+
1079+
PyObject *t1obj = sipConvertFromNewInstance(new QString(sipCpp->at(i).first), sipClass_QString, sipTransferObj);
1080+
PyList_SetItem( p, 0, t1obj );
1081+
PyList_SetItem( p, 1, l);
1082+
1083+
PyList_SetItem( d, i, p );
1084+
}
1085+
1086+
return d;
1087+
%End
1088+
%ConvertToTypeCode
1089+
#if PY_VERSION_HEX >= 0x02050000
1090+
Py_ssize_t i = 0;
1091+
#else
1092+
int i = 0;
1093+
#endif
1094+
QList < QPair< QString, QList<QString> > > *qm = new QList < QPair< QString, QList<QString> > >;
1095+
1096+
for ( i = 0; i < PyList_GET_SIZE(sipPy); i++ )
1097+
{
1098+
PyObject *sipPair = PyList_GetItem( sipPy, i );
1099+
PyObject *sipKey = PyList_GetItem( sipPair, 0 );
1100+
PyObject *sipList = PyList_GetItem( sipPair, 1 );
1101+
1102+
QList< QString > l;
1103+
int state;
1104+
int j;
1105+
for ( j = 0; j < PyList_GET_SIZE( sipList ); j++ )
1106+
{
1107+
PyObject *sipString = PyList_GetItem( sipList, j );
1108+
QString *t1 = reinterpret_cast<QString *>(sipConvertToInstance(sipString, sipClass_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
1109+
l << *t1;
1110+
sipReleaseInstance(t1, sipClass_QString, state);
1111+
}
1112+
1113+
QString *t1 = reinterpret_cast<QString *>(sipConvertToInstance(sipKey, sipClass_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
1114+
qm->append( qMakePair( *t1, l ) );
1115+
sipReleaseInstance(t1, sipClass_QString, state);
1116+
}
1117+
1118+
*sipCppPtr = qm;
1119+
1120+
return sipGetState(sipTransferObj);
1121+
%End
1122+
};

‎python/gui/qgslegendinterface.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class QgsLegendInterface : QObject
1919
//! Return a string list of groups
2020
virtual QStringList groups() =0;
2121

22+
//! Return the relationship between groups and layers in the legend
23+
virtual QList< QPair< QString, QList<QString> > > groupLayerRelationship();
24+
2225
//! Return all layers in the project in legend order
2326
//! @note added in 1.5
2427
virtual QList< QgsMapLayer * > layers() const =0;

0 commit comments

Comments
 (0)
Please sign in to comment.