Skip to content

Commit

Permalink
- added QMultiMap conversion for SIP from Stefanie Tellex
Browse files Browse the repository at this point in the history
- fixed featuresInRectangle and snapWithContext bindings
- added Stefanie to contributors
- keep list of contributors sorted


git-svn-id: http://svn.osgeo.org/qgis/trunk@8151 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Feb 13, 2008
1 parent 0a29430 commit 116e4a4
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 10 deletions.
7 changes: 4 additions & 3 deletions CONTRIBUTORS
Expand Up @@ -9,18 +9,19 @@ Brook Milligan
Carl Anderson
Carlos Dávila
Christian Ferreira
Faunalia (http://www.faunalia.it)
Fernando Pacheco
Frank Warmerdam
Hyao (IRC nickname)
Jean-Denis Giguere
Jerrit Collord
Jürgen E. Fischer
Magnus Homann
Markus Neteler
Maurizio Napolitano
Paul Ramsey
Peter Ersts
Stefanie Tellex
Tom Russo
Tyler Mitchell
Yann Chemin
Faunalia (http://www.faunalia.it)
Jürgen E. Fischer
Fernando Pacheco
119 changes: 116 additions & 3 deletions python/core/conversions.sip
Expand Up @@ -7,7 +7,7 @@ which are not wrapped by PyQt:
- QSet<TYPE>
- QMap<int, QMap<int, TYPE> >
- QMap<TYPE1, TYPE2*>

- QMultiMap<double, TYPE2>
*/

%ModuleHeaderCode
Expand Down Expand Up @@ -410,8 +410,6 @@ template<TYPE>
};




template<TYPE1, TYPE2>
%MappedType QMap<TYPE1, TYPE2*>
{
Expand Down Expand Up @@ -518,3 +516,118 @@ template<TYPE1, TYPE2>
return sipGetState(sipTransferObj);
%End
};



template<double, TYPE2>
%MappedType QMultiMap<double, TYPE2>
{
%TypeHeaderCode
#include <QMultiMap>
%End

%ConvertFromTypeCode
// Create the dictionary.
PyObject *d = PyDict_New();

if (!d)
return NULL;

// Set the dictionary elements.
QMultiMap<double, TYPE2>::const_iterator i = sipCpp->constBegin();

while (i != sipCpp->constEnd())
{

const double t1 = i.key();
const TYPE2 * t2 = &i.value();
PyObject *t1obj = PyFloat_FromDouble(t1);
PyObject *t2obj = sipConvertFromInstance(t2, sipClass_TYPE2, sipTransferObj);
if (PyDict_GetItem(d, t1obj) == NULL) {
PyObject *lst = PyList_New(0);
PyDict_SetItem(d, t1obj, lst);
if (lst)
Py_DECREF(lst);
}

if (t1obj == NULL || t2obj == NULL ||
PyList_Append(PyDict_GetItem(d, t1obj), t2obj) < 0)
{
Py_DECREF(d);
if (t1obj)
Py_DECREF(t1obj);

if (t2obj)
Py_DECREF(t2obj);

return NULL;
}
Py_DECREF(t1obj);
Py_DECREF(t2obj);

++i;
}

return d;
%End

%ConvertToTypeCode
PyObject *t1obj, *t2obj;
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t i = 0;
#else
int i = 0;
#endif

// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyDict_Check(sipPy))
return 0;

while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
if (!sipCanConvertToInstance(PyList_GET_ITEM(t2obj, i),
sipClass_TYPE2, SIP_NOT_NONE))
return 0;
}
}

return 1;
}

QMultiMap<double, TYPE2> *qm = new QMultiMap<double, TYPE2>;
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
int state2;
double k = PyFloat_AsDouble(t1obj);
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
TYPE2 *t2 =
reinterpret_cast<TYPE2 *>(sipConvertToInstance(PyList_GET_ITEM(t2obj,
i),
sipClass_TYPE2,
sipTransferObj,
SIP_NOT_NONE,
&state2,
sipIsErr));

if (*sipIsErr)
{
sipReleaseInstance(t2, sipClass_TYPE2, state2);

delete qm;
return 0;
}

qm->insert(k, *t2);

sipReleaseInstance(t2, sipClass_TYPE2, state2);
}
}

*sipCppPtr = qm;

return sipGetState(sipTransferObj);
%End
};
7 changes: 3 additions & 4 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -132,7 +132,7 @@ public:

/**Returns the features contained in the rectangle. Considers the changed, added, deleted and permanent features
@return 0 in case of success*/
int featuresInRectangle(const QgsRect& searchRect, QList<QgsFeature>& features, bool fetchGeometries = true, bool fetchAttributes = true);
int featuresInRectangle(const QgsRect& searchRect, QList<QgsFeature>& features /Out/, bool fetchGeometries = true, bool fetchAttributes = true);

/**Gets the feature at the given feature id. Considers the changed, added, deleted and permanent features
@return 0 in case of success*/
Expand Down Expand Up @@ -245,9 +245,8 @@ existing rings, 5 no feature found where ring can be inserted*/
@param snap_to to segment / to vertex
@return 0 in case of success
*/
// TODO: wrap QMultiMap
//int snapWithContext(const QgsPoint& startPoint, double snappingTolerance, QMultiMap<double, QgsSnappingResult>& snappingResults,
// QgsSnapper::SNAP_TO snap_to);
int snapWithContext(const QgsPoint& startPoint, double snappingTolerance, QMultiMap<double, QgsSnappingResult>& snappingResults /Out/,
QgsSnapper::SNAP_TO snap_to);

/**
Commits edited attributes. Depending on the feature id,
Expand Down

0 comments on commit 116e4a4

Please sign in to comment.