[QGIS Commit] r12878 - trunk/qgis/python/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Feb 4 16:08:33 EST 2010
Author: wonder
Date: 2010-02-04 16:08:33 -0500 (Thu, 04 Feb 2010)
New Revision: 12878
Modified:
trunk/qgis/python/core/qgsfeature.sip
trunk/qgis/python/core/qgsvectordataprovider.sip
trunk/qgis/python/core/qgsvectorlayer.sip
Log:
PyQGIS: few additions for more pythonic api
- QgsVectorLayer and QgsVectorDataProvider support iterating
- QgsFeature allows direct access to attributes (get/set/del)
Modified: trunk/qgis/python/core/qgsfeature.sip
===================================================================
--- trunk/qgis/python/core/qgsfeature.sip 2010-02-04 20:34:40 UTC (rev 12877)
+++ trunk/qgis/python/core/qgsfeature.sip 2010-02-04 21:08:33 UTC (rev 12878)
@@ -8,6 +8,32 @@
public:
+ SIP_PYOBJECT __getitem__(int key);
+%MethodCode
+ const QgsAttributeMap& attrMap = sipCpp->attributeMap();
+ QgsAttributeMap::const_iterator it = attrMap.find(a0);
+ if (it == attrMap.end())
+ PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
+ else
+ {
+ QVariant* v = new QVariant(it.value());
+ sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
+ }
+%End
+
+ void __setitem__(int key, QVariant value);
+%MethodCode
+ sipCpp->addAttribute(a0, *a1);
+%End
+
+ void __delitem__(int key);
+%MethodCode
+ if (sipCpp->attributeMap().contains(a0))
+ sipCpp->deleteAttribute(a0);
+ else
+ PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
+%End
+
//! Constructor
QgsFeature(int id = 0, QString typeName = "" );
Modified: trunk/qgis/python/core/qgsvectordataprovider.sip
===================================================================
--- trunk/qgis/python/core/qgsvectordataprovider.sip 2010-02-04 20:34:40 UTC (rev 12877)
+++ trunk/qgis/python/core/qgsvectordataprovider.sip 2010-02-04 21:08:33 UTC (rev 12878)
@@ -7,6 +7,23 @@
public:
+ QgsVectorDataProvider* __iter__();
+%MethodCode
+ sipRes = sipCpp;
+%End
+
+ SIP_PYOBJECT __next__();
+%MethodCode
+ QgsFeature* f = new QgsFeature;
+ if (sipCpp->nextFeature(*f))
+ sipRes = sipConvertFromInstance(f, sipClass_QgsFeature, Py_None);
+ else
+ {
+ delete f;
+ PyErr_SetString(PyExc_StopIteration,"");
+ }
+%End
+
// If you add to this, please also add to capabilitiesString()
/**
* enumeration with capabilities that providers might implement
Modified: trunk/qgis/python/core/qgsvectorlayer.sip
===================================================================
--- trunk/qgis/python/core/qgsvectorlayer.sip 2010-02-04 20:34:40 UTC (rev 12877)
+++ trunk/qgis/python/core/qgsvectorlayer.sip 2010-02-04 21:08:33 UTC (rev 12878)
@@ -5,6 +5,25 @@
%End
public:
+
+ QgsVectorLayer* __iter__();
+%MethodCode
+ sipRes = sipCpp;
+%End
+
+ SIP_PYOBJECT __next__();
+%MethodCode
+ QgsFeature* f = new QgsFeature;
+ if (sipCpp->nextFeature(*f))
+ sipRes = sipConvertFromInstance(f, sipClass_QgsFeature, Py_None);
+ else
+ {
+ delete f;
+ PyErr_SetString(PyExc_StopIteration,"");
+ }
+%End
+
+
enum EditType {
LineEdit,
UniqueValues,
More information about the QGIS-commit
mailing list