QGIS API Documentation  2.12.0-Lyon
qgsvectorlayereditpassthrough.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayereditpassthrough.cpp
3  ---------------------
4  begin : Jan 12 2015
5  copyright : (C) 2015 by Sandro Mani
6  email : manisandro at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 #include "qgsvectorlayer.h"
18 #include "qgsvectordataprovider.h"
19 
21 {
22 
23  if ( L->dataProvider()->addFeatures( QgsFeatureList() << f ) )
24  {
25  emit featureAdded( f.id() );
26  return true;
27  }
28  return false;
29 }
30 
32 {
33  if ( L->dataProvider()->addFeatures( features ) )
34  {
35  Q_FOREACH ( const QgsFeature& f, features )
36  {
37  emit featureAdded( f.id() );
38  }
39  return true;
40  }
41  return false;
42 }
43 
45 {
46  if ( L->dataProvider()->deleteFeatures( QgsFeatureIds() << fid ) )
47  {
48  emit featureDeleted( fid );
49  return true;
50  }
51  return false;
52 }
53 
55 {
56  QgsGeometryMap geomMap;
57  geomMap.insert( fid, *geom );
58  if ( L->dataProvider()->changeGeometryValues( geomMap ) )
59  {
60  emit geometryChanged( fid, *geom );
61  return true;
62  }
63  return false;
64 }
65 
66 bool QgsVectorLayerEditPassthrough::changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &/*oldValue*/ )
67 {
68  QgsAttributeMap map;
69  map.insert( field, newValue );
70  QgsChangedAttributesMap attribMap;
71  attribMap.insert( fid, map );
72  if ( L->dataProvider()->changeAttributeValues( attribMap ) )
73  {
74  emit attributeValueChanged( fid, field, newValue );
75  return true;
76  }
77  return false;
78 }
79 
81 {
82  if ( L->dataProvider()->addAttributes( QList<QgsField>() << field ) )
83  {
84  emit attributeAdded( L->dataProvider()->fieldNameIndex( field.name() ) );
85  return true;
86  }
87  return false;
88 }
89 
91 {
92  if ( L->dataProvider()->deleteAttributes( QgsAttributeIds() << attr ) )
93  {
94  emit attributeDeleted( attr );
95  return true;
96  }
97  return false;
98 }
99 
101 {
102  return true;
103 }
104 
106 {
107 }
QgsFeatureId id() const
Get the feature ID for this feature.
Definition: qgsfeature.cpp:53
const QString & name() const
Gets the name of the field.
Definition: qgsfield.cpp:72
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes.
bool deleteAttribute(int attr) override
Delete an attribute field (but does not commit it)
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:422
void attributeDeleted(int idx)
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:427
bool addFeature(QgsFeature &f) override
Adds a feature.
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant()) override
Changed an attribute value (but does not commit it)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:176
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual bool addFeatures(QgsFeatureList &flist)
Adds a list of features.
bool addFeatures(QgsFeatureList &features) override
Insert a copy of the given features into the layer (but does not commit it)
void featureAdded(QgsFeatureId fid)
QSet< int > QgsAttributeIds
void attributeAdded(int idx)
void geometryChanged(QgsFeatureId fid, QgsGeometry &geom)
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
void rollBack() override
Stop editing and discard the edits.
bool addAttribute(const QgsField &field) override
Add an attribute field (but does not commit it) returns true if the field was added.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:40
virtual bool changeGeometryValues(QgsGeometryMap &geometry_map)
Changes geometries of existing features.
bool deleteFeature(QgsFeatureId fid) override
Delete a feature from the layer (but does not commit it)
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &)
bool changeGeometry(QgsFeatureId fid, QgsGeometry *geom) override
Change feature's geometry.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
iterator insert(const Key &key, const T &value)
QgsVectorDataProvider * dataProvider()
Returns the data provider.
void featureDeleted(QgsFeatureId fid)
bool commitChanges(QStringList &commitErrors) override
Attempts to commit any changes to disk.