QGIS API Documentation  2.15.0-Master (972fc9f)
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 
77  virtual bool renameAttribute( int attr, const QString& newName );
78 
94  virtual bool commitChanges( QStringList& commitErrors );
95 
97  virtual void rollBack();
98 
99 
100 
102  inline const QgsFeatureMap& addedFeatures() { return mAddedFeatures; }
103 
105  inline const QgsChangedAttributesMap& changedAttributeValues() { return mChangedAttributeValues; }
106 
108  inline const QgsAttributeList& deletedAttributeIds() { return mDeletedAttributeIds; }
109 
111  inline const QList<QgsField>& addedAttributes() { return mAddedAttributes; }
112 
114  inline const QgsGeometryMap& changedGeometries() { return mChangedGeometries; }
115 
116  inline const QgsFeatureIds deletedFeatureIds() { return mDeletedFeatureIds; }
117  //QString dumpEditBuffer();
118 
119  protected slots:
120  void undoIndexChanged( int index );
121 
122  signals:
124  void layerModified();
125 
126  void featureAdded( QgsFeatureId fid );
127  void featureDeleted( QgsFeatureId fid );
128  void geometryChanged( QgsFeatureId fid, QgsGeometry &geom );
129  void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
130  void attributeAdded( int idx );
131  void attributeDeleted( int idx );
132 
138  void attributeRenamed( int idx, const QString& newName );
139 
141  void committedAttributesDeleted( const QString& layerId, const QgsAttributeList& deletedAttributes );
142  void committedAttributesAdded( const QString& layerId, const QList<QgsField>& addedAttributes );
143 
149  void committedAttributesRenamed( const QString& layerId, const QgsFieldNameMap& renamedAttributes );
150  void committedFeaturesAdded( const QString& layerId, const QgsFeatureList& addedFeatures );
151  void committedFeaturesRemoved( const QString& layerId, const QgsFeatureIds& deletedFeatureIds );
152  void committedAttributeValuesChanges( const QString& layerId, const QgsChangedAttributesMap& changedAttributesValues );
153  void committedGeometriesChanges( const QString& layerId, const QgsGeometryMap& changedGeometries );
154 
155  protected:
156 
157  QgsVectorLayerEditBuffer() : L( nullptr ) {}
158 
159  void updateFields( QgsFields& fields );
160 
162  void updateFeatureGeometry( QgsFeature &f );
163 
165  void updateChangedAttributes( QgsFeature &f );
166 
168  void handleAttributeAdded( int index );
169 
171  void handleAttributeDeleted( int index );
172 
174  void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;
175 
176  void updateLayerFields();
177 
178  protected:
180  friend class QgsVectorLayer;
181 
190 
196 
199 
202 
205 
208 
211 
214 };
215 
216 #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.