QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
36 class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
37 {
38  Q_OBJECT
39  public:
42 
44  virtual bool isModified() const;
45 
46 
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, QgsGeometry* geom );
64 
66  virtual bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
67 
70  virtual bool addAttribute( const QgsField &field );
71 
73  virtual bool deleteAttribute( int attr );
74 
80  virtual bool renameAttribute( int attr, const QString& newName );
81 
97  virtual bool commitChanges( QStringList& commitErrors );
98 
100  virtual void rollBack();
101 
107  virtual bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues );
108 
110  inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
111 
113  inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
114 
116  inline const QgsAttributeList& deletedAttributeIds() { return mDeletedAttributeIds; }
117 
119  inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
120 
122  inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
123 
124  inline const QgsFeatureIds deletedFeatureIds() { return mDeletedFeatureIds; }
125  //QString dumpEditBuffer();
126 
127  protected slots:
128  void undoIndexChanged( int index );
129 
130  signals:
132  void layerModified();
133 
134  void featureAdded( QgsFeatureId fid );
135  void featureDeleted( QgsFeatureId fid );
136  void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
137  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
138  void attributeAdded( int idx );
139  void attributeDeleted( int idx );
140 
146  void attributeRenamed( int idx, const QString& newName );
147 
149  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
150  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
151 
157  void committedAttributesRenamed( const QString& layerId, const QgsFieldNameMap& renamedAttributes );
158  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
159  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
160  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
161  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
162 
163  protected:
164 
165  QgsVectorLayerEditBuffer() : L( nullptr ) {}
166 
167  void updateFields( QgsFields& fields );
168 
170  void updateFeatureGeometry( QgsFeature &f );
171 
173  void updateChangedAttributes( QgsFeature &f );
174 
176  void handleAttributeAdded( int index );
177 
179  void handleAttributeDeleted( int index );
180 
182  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
183 
184  void updateLayerFields();
185 
197  bool adaptGeometry( QgsGeometry* geometry );
198 
199  protected:
201  friend class QgsVectorLayer;
202 
211 
217 
220 
223 
226 
229 
232 
235 };
236 
237 #endif // QGSVECTORLAYEREDITBUFFER_H
const QgsGeometryMap & changedGeometries()
Changed geometries which are not commited.
Undo command for removing an existing attribute from a vector layer.
static unsigned index
Undo command for deleting a feature from a vector layer.
const QgsChangedAttributesMap & changedAttributeValues()
Changed attributes values which are not commited.
Base class for undo commands within a QgsVectorLayerEditBuffer.
Container of fields for a vector layer.
Definition: qgsfield.h:252
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: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
QgsFieldNameMap mRenamedAttributes
Renamed attributes which are not commited.
Undo command for adding a feature to a vector layer.
Undo command for modifying the geometry of a feature from a vector layer.
QSet< int > QgsAttributeIds
QgsGeometryMap mChangedGeometries
Changed geometries which are not commited.
Undo command for renaming an existing attribute of a vector layer.
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.
Undo command for adding a new attribute to a vector layer.
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.