[QGIS Commit] r8151 - in trunk/qgis: . python/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Feb 13 04:48:05 EST 2008


Author: wonder
Date: 2008-02-13 04:48:05 -0500 (Wed, 13 Feb 2008)
New Revision: 8151

Modified:
   trunk/qgis/CONTRIBUTORS
   trunk/qgis/python/core/conversions.sip
   trunk/qgis/python/core/qgsvectorlayer.sip
Log:
- added QMultiMap conversion for SIP from Stefanie Tellex
- fixed featuresInRectangle and snapWithContext bindings
- added Stefanie to contributors
- keep list of contributors sorted


Modified: trunk/qgis/CONTRIBUTORS
===================================================================
--- trunk/qgis/CONTRIBUTORS	2008-02-13 08:48:07 UTC (rev 8150)
+++ trunk/qgis/CONTRIBUTORS	2008-02-13 09:48:05 UTC (rev 8151)
@@ -9,18 +9,19 @@
 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

Modified: trunk/qgis/python/core/conversions.sip
===================================================================
--- trunk/qgis/python/core/conversions.sip	2008-02-13 08:48:07 UTC (rev 8150)
+++ trunk/qgis/python/core/conversions.sip	2008-02-13 09:48:05 UTC (rev 8151)
@@ -7,7 +7,7 @@
 - QSet<TYPE>
 - QMap<int, QMap<int, TYPE> >
 - QMap<TYPE1, TYPE2*>
-
+- QMultiMap<double, TYPE2>
 */
 
 %ModuleHeaderCode
@@ -410,8 +410,6 @@
 };
 
 
-
-
 template<TYPE1, TYPE2>
 %MappedType QMap<TYPE1, TYPE2*>
 {
@@ -518,3 +516,118 @@
     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
+   };

Modified: trunk/qgis/python/core/qgsvectorlayer.sip
===================================================================
--- trunk/qgis/python/core/qgsvectorlayer.sip	2008-02-13 08:48:07 UTC (rev 8150)
+++ trunk/qgis/python/core/qgsvectorlayer.sip	2008-02-13 09:48:05 UTC (rev 8151)
@@ -132,7 +132,7 @@
 
 /**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*/
@@ -245,9 +245,8 @@
      @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,



More information about the QGIS-commit mailing list