QGIS API Documentation  2.99.0-Master (b058df7)
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 "qgis_core.h"
19 #include <QList>
20 #include <QSet>
21 
22 #include "qgsfeature.h"
23 #include "qgsfields.h"
24 #include "qgsgeometry.h"
25 
27 
28 typedef QList<int> QgsAttributeList SIP_SKIP;
29 typedef QSet<int> QgsAttributeIds SIP_SKIP;
30 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
31 
36 class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
37 {
38  Q_OBJECT
39  public:
41 
43  virtual bool isModified() const;
44 
45 
51  virtual bool addFeature( QgsFeature &f );
52 
54  virtual bool addFeatures( QgsFeatureList &features );
55 
57  virtual bool deleteFeature( QgsFeatureId fid );
58 
60  virtual bool deleteFeatures( const QgsFeatureIds &fid );
61 
63  virtual bool changeGeometry( QgsFeatureId fid, const QgsGeometry &geom );
64 
66  virtual bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
67 
71  virtual bool addAttribute( const QgsField &field );
72 
74  virtual bool deleteAttribute( int attr );
75 
82  virtual bool renameAttribute( int attr, const QString &newName );
83 
99  virtual bool commitChanges( QStringList &commitErrors );
100 
102  virtual void rollBack();
103 
108  QgsFeatureMap addedFeatures() const { return mAddedFeatures; }
109 
116  bool isFeatureAdded( QgsFeatureId id ) const { return mAddedFeatures.contains( id ); }
117 
122  QgsChangedAttributesMap changedAttributeValues() const { return mChangedAttributeValues; }
123 
130  bool isFeatureAttributesChanged( QgsFeatureId id ) const { return mChangedAttributeValues.contains( id ); }
131 
136  QgsAttributeList deletedAttributeIds() const { return mDeletedAttributeIds; }
137 
144  bool isAttributeDeleted( int index ) const { return mDeletedAttributeIds.contains( index ); }
145 
149  QList<QgsField> addedAttributes() const { return mAddedAttributes; }
150 
155  QgsGeometryMap changedGeometries() const { return mChangedGeometries; }
156 
163  bool isFeatureGeometryChanged( QgsFeatureId id ) const { return mChangedGeometries.contains( id ); }
164 
169  QgsFeatureIds deletedFeatureIds() const { return mDeletedFeatureIds; }
170 
177  bool isFeatureDeleted( QgsFeatureId id ) const { return mDeletedFeatureIds.contains( id ); }
178 
179  //QString dumpEditBuffer();
180 
181  protected slots:
182  void undoIndexChanged( int index );
183 
184  signals:
186  void layerModified();
187 
188  void featureAdded( QgsFeatureId fid );
189  void featureDeleted( QgsFeatureId fid );
190 
196  void geometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
197 
198  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
199  void attributeAdded( int idx );
200  void attributeDeleted( int idx );
201 
208  void attributeRenamed( int idx, const QString &newName );
209 
211  void committedAttributesDeleted( const QString &layerId, const QgsAttributeList &deletedAttributes );
212  void committedAttributesAdded( const QString &layerId, const QList<QgsField> &addedAttributes );
213 
220  void committedAttributesRenamed( const QString &layerId, const QgsFieldNameMap &renamedAttributes );
221  void committedFeaturesAdded( const QString &layerId, const QgsFeatureList &addedFeatures );
222  void committedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );
223  void committedAttributeValuesChanges( const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues );
224  void committedGeometriesChanges( const QString &layerId, const QgsGeometryMap &changedGeometries );
225 
226  protected:
227 
229  QgsVectorLayerEditBuffer() = default;
230 
231  void updateFields( QgsFields &fields );
232 
234  void updateFeatureGeometry( QgsFeature &f );
235 
237  void updateChangedAttributes( QgsFeature &f );
238 
240  void handleAttributeAdded( int index );
241 
243  void handleAttributeDeleted( int index );
244 
246  void updateAttributeMapIndex( QgsAttributeMap &attrs, int index, int offset ) const;
247 
248  void updateLayerFields();
249 
250  protected:
251  QgsVectorLayer *L = nullptr;
252  friend class QgsVectorLayer;
253 
262 
272 
279 
282 
285 
288 
290  QList<QgsField> mAddedAttributes;
291 
294 
297 
298  friend class QgsGrassProvider; //GRASS provider totally abuses the edit buffer
299 };
300 
301 #endif // QGSVECTORLAYEREDITBUFFER_H
Undo command for deleting attri of a vector layer in transaction group.
Undo command for removing an existing attribute from a vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:537
Undo command for deleting a feature from a vector layer.
Undo command for deleting attri of a vector layer in transaction group.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:544
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:549
Base class for undo commands within a QgsVectorLayerEditBuffer.
Container of fields for a vector layer.
Definition: qgsfields.h:42
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:111
Undo command for vector layer in transaction group mode.
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:62
QgsFieldNameMap mRenamedAttributes
Renamed attributes which are not committed.
QgsChangedAttributesMap changedAttributeValues() const
Returns a map of features with changed attributes values which are not committed. ...
Undo command for adding attri to a vector layer in transaction group.
Undo command for changing attr value from a vector layer in transaction group.
QgsFeatureIds deletedFeatureIds() const
Returns a list of deleted feature IDs which are not committed.
Undo command for adding a feature to a vector layer.
QSet< int > QgsAttributeIds
Undo command for changing feature geometry from a vector layer in transaction group.
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.
#define SIP_SKIP
Definition: qgis_sip.h:119
QMap< int, QVariant > QgsAttributeMap
Definition: qgsattributes.h:39
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.
Undo command for running a specific sql query in transaction group.
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not committed.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
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.
QMap< int, QString > QgsFieldNameMap
Definition: qgsattributes.h:45
Undo command for adding a new attribute to a vector layer.
Undo command for deleting features from a vector layer in transaction group.
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:528
Undo command for adding a feature to a vector layer in transaction group mode.
qint64 QgsFeatureId
Definition: qgsfeature.h:37
bool isFeatureDeleted(QgsFeatureId id) const
Returns true if the specified feature ID has been deleted but not committed.
QList< int > QgsAttributeList
Definition: qgsfield.h:27
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.