Skip to content

Commit 0a25f37

Browse files
author
wonder
committedFeb 13, 2008
- added QMultiMap conversion for SIP from Stefanie Tellex
- fixed featuresInRectangle and snapWithContext bindings - added Stefanie to contributors - keep list of contributors sorted git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8151 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

3 files changed

+123
-10
lines changed

3 files changed

+123
-10
lines changed
 

‎CONTRIBUTORS

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ Brook Milligan
99
Carl Anderson
1010
Carlos Dávila
1111
Christian Ferreira
12+
Faunalia (http://www.faunalia.it)
13+
Fernando Pacheco
1214
Frank Warmerdam
1315
Hyao (IRC nickname)
1416
Jean-Denis Giguere
1517
Jerrit Collord
18+
Jürgen E. Fischer
1619
Magnus Homann
1720
Markus Neteler
1821
Maurizio Napolitano
1922
Paul Ramsey
2023
Peter Ersts
24+
Stefanie Tellex
2125
Tom Russo
2226
Tyler Mitchell
2327
Yann Chemin
24-
Faunalia (http://www.faunalia.it)
25-
Jürgen E. Fischer
26-
Fernando Pacheco

‎python/core/conversions.sip

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ which are not wrapped by PyQt:
77
- QSet<TYPE>
88
- QMap<int, QMap<int, TYPE> >
99
- QMap<TYPE1, TYPE2*>
10-
10+
- QMultiMap<double, TYPE2>
1111
*/
1212

1313
%ModuleHeaderCode
@@ -410,8 +410,6 @@ template<TYPE>
410410
};
411411

412412

413-
414-
415413
template<TYPE1, TYPE2>
416414
%MappedType QMap<TYPE1, TYPE2*>
417415
{
@@ -518,3 +516,118 @@ template<TYPE1, TYPE2>
518516
return sipGetState(sipTransferObj);
519517
%End
520518
};
519+
520+
521+
522+
template<double, TYPE2>
523+
%MappedType QMultiMap<double, TYPE2>
524+
{
525+
%TypeHeaderCode
526+
#include <QMultiMap>
527+
%End
528+
529+
%ConvertFromTypeCode
530+
// Create the dictionary.
531+
PyObject *d = PyDict_New();
532+
533+
if (!d)
534+
return NULL;
535+
536+
// Set the dictionary elements.
537+
QMultiMap<double, TYPE2>::const_iterator i = sipCpp->constBegin();
538+
539+
while (i != sipCpp->constEnd())
540+
{
541+
542+
const double t1 = i.key();
543+
const TYPE2 * t2 = &i.value();
544+
PyObject *t1obj = PyFloat_FromDouble(t1);
545+
PyObject *t2obj = sipConvertFromInstance(t2, sipClass_TYPE2, sipTransferObj);
546+
if (PyDict_GetItem(d, t1obj) == NULL) {
547+
PyObject *lst = PyList_New(0);
548+
PyDict_SetItem(d, t1obj, lst);
549+
if (lst)
550+
Py_DECREF(lst);
551+
}
552+
553+
if (t1obj == NULL || t2obj == NULL ||
554+
PyList_Append(PyDict_GetItem(d, t1obj), t2obj) < 0)
555+
{
556+
Py_DECREF(d);
557+
if (t1obj)
558+
Py_DECREF(t1obj);
559+
560+
if (t2obj)
561+
Py_DECREF(t2obj);
562+
563+
return NULL;
564+
}
565+
Py_DECREF(t1obj);
566+
Py_DECREF(t2obj);
567+
568+
++i;
569+
}
570+
571+
return d;
572+
%End
573+
574+
%ConvertToTypeCode
575+
PyObject *t1obj, *t2obj;
576+
#if PY_VERSION_HEX >= 0x02050000
577+
Py_ssize_t i = 0;
578+
#else
579+
int i = 0;
580+
#endif
581+
582+
// Check the type if that is all that is required.
583+
if (sipIsErr == NULL)
584+
{
585+
if (!PyDict_Check(sipPy))
586+
return 0;
587+
588+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
589+
{
590+
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
591+
if (!sipCanConvertToInstance(PyList_GET_ITEM(t2obj, i),
592+
sipClass_TYPE2, SIP_NOT_NONE))
593+
return 0;
594+
}
595+
}
596+
597+
return 1;
598+
}
599+
600+
QMultiMap<double, TYPE2> *qm = new QMultiMap<double, TYPE2>;
601+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
602+
{
603+
int state2;
604+
double k = PyFloat_AsDouble(t1obj);
605+
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
606+
TYPE2 *t2 =
607+
reinterpret_cast<TYPE2 *>(sipConvertToInstance(PyList_GET_ITEM(t2obj,
608+
i),
609+
sipClass_TYPE2,
610+
sipTransferObj,
611+
SIP_NOT_NONE,
612+
&state2,
613+
sipIsErr));
614+
615+
if (*sipIsErr)
616+
{
617+
sipReleaseInstance(t2, sipClass_TYPE2, state2);
618+
619+
delete qm;
620+
return 0;
621+
}
622+
623+
qm->insert(k, *t2);
624+
625+
sipReleaseInstance(t2, sipClass_TYPE2, state2);
626+
}
627+
}
628+
629+
*sipCppPtr = qm;
630+
631+
return sipGetState(sipTransferObj);
632+
%End
633+
};

‎python/core/qgsvectorlayer.sip

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public:
132132

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

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

252251
/**
253252
Commits edited attributes. Depending on the feature id,

0 commit comments

Comments
 (0)
Please sign in to comment.