QGIS API Documentation  2.14.0-Essen
qgsvectorlayereditbuffer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayereditbuffer.h
3  ---------------------
4  begin : Dezember 2012
5  copyright : (C) 2012 by Martin Dobias
6  email : wonder dot sk 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 #ifndef QGSVECTORLAYEREDITBUFFER_H
16 #define QGSVECTORLAYEREDITBUFFER_H
17 
18 #include <QList>
19 #include <QSet>
20 
21 #include "qgsgeometry.h"
22 #include "qgsfeature.h"
23 #include "qgsfield.h"
24 #include "qgsrectangle.h"
25 #include "qgssnapper.h"
26 
28 
32 
33 class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
34 {
35  Q_OBJECT
36  public:
39 
41  virtual bool isModified() const;
42 
43 
48  virtual bool addFeature( QgsFeature& f );
49 
51  virtual bool addFeatures( QgsFeatureList& features );
52 
54  virtual bool deleteFeature( QgsFeatureId fid );
55 
57  virtual bool deleteFeatures( const QgsFeatureIds& fid );
58 
60  virtual bool changeGeometry( QgsFeatureId fid, QgsGeometry* geom );
61 
63  virtual bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
64 
67  virtual bool addAttribute( const QgsField &field );
68 
70  virtual bool deleteAttribute( int attr );
71 
72 
88  virtual bool commitChanges( QStringList& commitErrors );
89 
91  virtual void rollBack();
92 
93 
94 
96  inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
97 
99  inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
100 
102  inline const QgsAttributeList& deletedAttributeIds() { return mDeletedAttributeIds; }
103 
105  inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
106 
108  inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
109 
110  inline const QgsFeatureIds deletedFeatureIds() { return mDeletedFeatureIds; }
111  //QString dumpEditBuffer();
112 
113  protected slots:
114  void undoIndexChanged( int index );
115 
116  signals:
118  void layerModified();
119 
120  void featureAdded( QgsFeatureId fid );
121  void featureDeleted( QgsFeatureId fid );
122  void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
123  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
124  void attributeAdded( int idx );
125  void attributeDeleted( int idx );
126 
128  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
129  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
130  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
131  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
132  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
133  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
134 
135  protected:
136 
137  QgsVectorLayerEditBuffer() : L( nullptr ) {}
138 
139  void updateFields( QgsFields& fields );
140 
142  void updateFeatureGeometry( QgsFeature &f );
143 
145  void updateChangedAttributes( QgsFeature &f );
146 
148  void handleAttributeAdded( int index );
149 
151  void handleAttributeDeleted( int index );
152 
153 
155  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
156 
157  void updateLayerFields();
158 
159  protected:
161  friend class QgsVectorLayer;
162 
170 
176 
179 
182 
185 
188 
191 
192 };
193 
194 #endif // QGSVECTORLAYEREDITBUFFER_H
const QgsGeometryMap & changedGeometries()
Changed geometries which are not commited.
static unsigned index
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
Container of fields for a vector layer.
Definition: qgsfield.h:187
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not commited.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QSet< int > QgsAttributeIds
QgsGeometryMap mChangedGeometries
Changed geometries which are not commited.
const QgsFeatureIds deletedFeatureIds()
QList< int > QgsAttributeList
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not commited.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
const QList< QgsField > & addedAttributes()
Added attributes fields which are not commited.
const QgsFeatureMap & addedFeatures()
New features which are not commited.
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
QList< QgsField > mAddedAttributes
Added attributes fields which are not commited.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
QgsFeatureMap mAddedFeatures
New features which are not commited.
Represents a vector layer which manages a vector based data sets.
const QgsAttributeList & deletedAttributeIds()
Deleted attributes fields which are not commited.
QgsAttributeList mDeletedAttributeIds
Deleted attributes fields which are not commited.