QGIS API Documentation  2.99.0-Master (8ec3eaf)
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 "qgsfeature.h"
22 #include "qgsfields.h"
23 #include "qgsgeometry.h"
24 
26 
27 typedef QList<int> QgsAttributeList;
28 typedef QSet<int> QgsAttributeIds;
29 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
30 
34 class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
35 {
36  Q_OBJECT
37  public:
40 
42  virtual bool isModified() const;
43 
44 
49  virtual bool addFeature( QgsFeature& f );
50 
52  virtual bool addFeatures( QgsFeatureList& features );
53 
55  virtual bool deleteFeature( QgsFeatureId fid );
56 
58  virtual bool deleteFeatures( const QgsFeatureIds& fid );
59 
61  virtual bool changeGeometry( QgsFeatureId fid, const QgsGeometry &geom );
62 
64  virtual bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
65 
68  virtual bool addAttribute( const QgsField &field );
69 
71  virtual bool deleteAttribute( int attr );
72 
78  virtual bool renameAttribute( int attr, const QString& newName );
79 
95  virtual bool commitChanges( QStringList& commitErrors );
96 
98  virtual void rollBack();
99 
103  QgsFeatureMap addedFeatures() const { return mAddedFeatures; }
104 
110  bool isFeatureAdded( QgsFeatureId id ) const { return mAddedFeatures.contains( id ); }
111 
115  QgsChangedAttributesMap changedAttributeValues() const { return mChangedAttributeValues; }
116 
122  bool isFeatureAttributesChanged( QgsFeatureId id ) const { return mChangedAttributeValues.contains( id ); }
123 
127  QgsAttributeList deletedAttributeIds() const { return mDeletedAttributeIds; }
128 
134  bool isAttributeDeleted( int index ) const { return mDeletedAttributeIds.contains( index ); }
135 
138  QList<QgsField> addedAttributes() const { return mAddedAttributes; }
139 
143  QgsGeometryMap changedGeometries() const { return mChangedGeometries; }
144 
150  bool isFeatureGeometryChanged( QgsFeatureId id ) const { return mChangedGeometries.contains( id ); }
151 
155  QgsFeatureIds deletedFeatureIds() const { return mDeletedFeatureIds; }
156 
162  bool isFeatureDeleted( QgsFeatureId id ) const { return mDeletedFeatureIds.contains( id ); }
163 
164  //QString dumpEditBuffer();
165 
166  protected slots:
167  void undoIndexChanged( int index );
168 
169  signals:
171  void layerModified();
172 
173  void featureAdded( QgsFeatureId fid );
174  void featureDeleted( QgsFeatureId fid );
175 
180  void geometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
181 
182  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
183  void attributeAdded( int idx );
184  void attributeDeleted( int idx );
185 
191  void attributeRenamed( int idx, const QString& newName );
192 
194  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
195  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
196 
202  void committedAttributesRenamed( const QString& layerId, const QgsFieldNameMap& renamedAttributes );
203  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
204  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
205  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
206  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
207 
208  protected:
209 
210  QgsVectorLayerEditBuffer() : L( nullptr ) {}
211 
212  void updateFields( QgsFields& fields );
213 
215  void updateFeatureGeometry( QgsFeature &f );
216 
218  void updateChangedAttributes( QgsFeature &f );
219 
221  void handleAttributeAdded( int index );
222 
224  void handleAttributeDeleted( int index );
225 
227  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
228 
229  void updateLayerFields();
230 
231  protected:
233  friend class QgsVectorLayer;
234 
243 
249 
252 
255 
258 
260  QList<QgsField> mAddedAttributes;
261 
264 
267 
268  friend class QgsGrassProvider; //GRASS provider totally abuses the edit buffer
269 };
270 
271 #endif // QGSVECTORLAYEREDITBUFFER_H
QMap< int, QString > QgsFieldNameMap
Definition: qgsfeature.h:358
Undo command for removing an existing attribute from a vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:353
static unsigned index
Undo command for deleting a feature from a vector layer.
QMap< int, QVariant > QgsAttributeMap
Definition: qgsfeature.h:44
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:355
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:360
Base class for undo commands within a QgsVectorLayerEditBuffer.
Container of fields for a vector layer.
Definition: qgsfields.h:36
Undo command for modifying an attribute of a feature from a vector layer.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:78
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not committed.
bool isFeatureAdded(QgsFeatureId id) const
Returns true if the specified feature ID has been added but not committed.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:135
QgsFieldNameMap mRenamedAttributes
Renamed attributes which are not committed.
QgsChangedAttributesMap changedAttributeValues() const
Returns a map of features with changed attributes values which are not committed. ...
QgsFeatureIds deletedFeatureIds() const
Returns a list of deleted feature IDs which are not committed.
Undo command for adding a feature to a vector layer.
Undo command for modifying the geometry of a feature from a vector layer.
QgsGeometryMap changedGeometries() const
Returns a map of features with changed geometries which are not committed.
QSet< int > QgsAttributeIds
QgsGeometryMap mChangedGeometries
Changed geometries which are not committed.
QgsAttributeList deletedAttributeIds() const
Returns a list of deleted attributes fields which are not committed.
Undo command for renaming an existing attribute of a vector layer.
QList< int > QgsAttributeList
QList< int > QgsAttributeList
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not committed.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:47
bool isFeatureAttributesChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had an attribute changed but not committed.
bool isAttributeDeleted(int index) const
Returns true if the specified attribute has been deleted but not committed.
Undo command for adding a new attribute to a vector layer.
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
QgsFeatureMap addedFeatures() const
Returns a map of new features which are not committed.
QList< QgsField > mAddedAttributes
Added attributes fields which are not committed.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:350
qint64 QgsFeatureId
Definition: qgsfeature.h:32
bool isFeatureDeleted(QgsFeatureId id) const
Returns true if the specified feature ID has been deleted but not committed.
QList< QgsField > addedAttributes() const
Returns a list of added attributes fields which are not committed.
QgsFeatureMap mAddedFeatures
New features which are not committed.
Represents a vector layer which manages a vector based data sets.
QgsAttributeList mDeletedAttributeIds
Deleted attributes fields which are not committed. The list is kept sorted.
bool isFeatureGeometryChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had its geometry changed but not committed.