mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
PyQGIS: few additions for more pythonic api
- QgsVectorLayer and QgsVectorDataProvider support iterating - QgsFeature allows direct access to attributes (get/set/del) git-svn-id: http://svn.osgeo.org/qgis/trunk@12878 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
54b079e680
commit
2034de2bc9
@ -8,6 +8,32 @@ class QgsFeature
|
||||
|
||||
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 = "" );
|
||||
|
||||
|
@ -7,6 +7,23 @@ class QgsVectorDataProvider : QgsDataProvider
|
||||
|
||||
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
|
||||
|
@ -5,6 +5,25 @@ class QgsVectorLayer : QgsMapLayer
|
||||
%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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user