QGIS API Documentation  2.17.0-Master (8784312)
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 
102 
103 
105  inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
106 
108  inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
109 
111  inline const QgsAttributeList& deletedAttributeIds() { return mDeletedAttributeIds; }
112 
114  inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
115 
117  inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
118 
119  inline const QgsFeatureIds deletedFeatureIds() { return mDeletedFeatureIds; }
120  //QString dumpEditBuffer();
121 
122  protected slots:
123  void undoIndexChanged( int index );
124 
125  signals:
127  void layerModified();
128 
129  void featureAdded( QgsFeatureId fid );
130  void featureDeleted( QgsFeatureId fid );
131  void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
132  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
133  void attributeAdded( int idx );
134  void attributeDeleted( int idx );
135 
141  void attributeRenamed( int idx, const QString& newName );
142 
144  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
145  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
146 
152  void committedAttributesRenamed( const QString& layerId, const QgsFieldNameMap& renamedAttributes );
153  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
154  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
155  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
156  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
157 
158  protected:
159 
160  QgsVectorLayerEditBuffer() : L( nullptr ) {}
161 
162  void updateFields( QgsFields& fields );
163 
165  void updateFeatureGeometry( QgsFeature &f );
166 
168  void updateChangedAttributes( QgsFeature &f );
169 
171  void handleAttributeAdded( int index );
172 
174  void handleAttributeDeleted( int index );
175 
177  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
178 
179  void updateLayerFields();
180 
181  protected:
183  friend class QgsVectorLayer;
184 
193 
199 
202 
205 
208 
211 
214 
217 };
218 
219 #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:193
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.