QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  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 
100 bool QgsVectorLayerEditPassthrough::commitChanges( QStringList& /*commitErrors*/ )
101 {
102  return true;
103 }
104 
106 {
107 }