QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
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
26class QgsVectorLayer;
28
29typedef QList<int> QgsAttributeList SIP_SKIP;
30typedef QSet<int> QgsAttributeIds SIP_SKIP;
31typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
32
37class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
38{
39 Q_OBJECT
40 public:
42
44 virtual bool isModified() const;
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
72 virtual bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues );
73
78 virtual bool addAttribute( const QgsField &field );
79
81 virtual bool deleteAttribute( int attr );
82
88 virtual bool renameAttribute( int attr, const QString &newName );
89
105 virtual bool commitChanges( QStringList &commitErrors );
106
108 virtual void rollBack();
109
114 QgsFeatureMap addedFeatures() const { return mAddedFeatures; }
115
122 QgsFeatureIds allAddedOrEditedFeatures() const;
123
129 bool isFeatureAdded( QgsFeatureId id ) const { return mAddedFeatures.contains( id ); }
130
135 QgsChangedAttributesMap changedAttributeValues() const { return mChangedAttributeValues; }
136
142 bool isFeatureAttributesChanged( QgsFeatureId id ) const { return mChangedAttributeValues.contains( id ); }
143
148 QgsAttributeList deletedAttributeIds() const { return mDeletedAttributeIds; }
149
155 bool isAttributeDeleted( int index ) const { return mDeletedAttributeIds.contains( index ); }
156
160 QList<QgsField> addedAttributes() const { return mAddedAttributes; }
161
166 QgsGeometryMap changedGeometries() const { return mChangedGeometries; }
167
173 bool isFeatureGeometryChanged( QgsFeatureId id ) const { return mChangedGeometries.contains( id ); }
174
179 QgsFeatureIds deletedFeatureIds() const { return mDeletedFeatureIds; }
180
186 bool isFeatureDeleted( QgsFeatureId id ) const { return mDeletedFeatureIds.contains( id ); }
187
193 void updateFields( QgsFields &fields ) SIP_SKIP;
194
199 QgsVectorLayerEditBufferGroup *editBufferGroup() const;
200
205 void setEditBufferGroup( QgsVectorLayerEditBufferGroup *editBufferGroup );
206
207 //QString dumpEditBuffer();
208
209 protected slots:
210 void undoIndexChanged( int index );
211
212 signals:
215
218
224 void geometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
225
226 void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant & );
227 void attributeAdded( int idx );
228 void attributeDeleted( int idx );
229
235 void attributeRenamed( int idx, const QString &newName );
236
238 void committedAttributesDeleted( const QString &layerId, const QgsAttributeList &deletedAttributes );
239 void committedAttributesAdded( const QString &layerId, const QList<QgsField> &addedAttributes );
240
246 void committedAttributesRenamed( const QString &layerId, const QgsFieldNameMap &renamedAttributes );
247 void committedFeaturesAdded( const QString &layerId, const QgsFeatureList &addedFeatures );
248 void committedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );
249 void committedAttributeValuesChanges( const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues );
250 void committedGeometriesChanges( const QString &layerId, const QgsGeometryMap &changedGeometries );
251
252 protected:
253
256
258 void updateFeatureGeometry( QgsFeature &f );
259
261 void updateChangedAttributes( QgsFeature &f );
262
264 void handleAttributeAdded( int index );
265
267 void handleAttributeDeleted( int index );
268
270 void updateAttributeMapIndex( QgsAttributeMap &attrs, int index, int offset ) const;
271
272 void updateLayerFields();
273
274 protected:
275 QgsVectorLayer *L = nullptr;
276
285
296
303
306
309
312
314 QList<QgsField> mAddedAttributes;
315
318
321
322 QgsVectorLayerEditBufferGroup *mEditBufferGroup = nullptr;
323
324 int mBlockModifiedSignals = 0;
325
326 friend class QgsGrassProvider; //GRASS provider totally abuses the edit buffer
327
328 private:
329
331
337 bool commitChangesCheckGeometryTypeCompatibility( QStringList &commitErrors );
338
345 bool commitChangesDeleteAttributes( bool &attributesDeleted, QStringList &commitErrors );
346
353 bool commitChangesRenameAttributes( bool &attributesRenamed, QStringList &commitErrors );
354
361 bool commitChangesAddAttributes( bool &attributesAdded, QStringList &commitErrors );
362
369 bool commitChangesCheckAttributesModifications( const QgsFields oldFields, QStringList &commitErrors );
370
377 bool commitChangesChangeAttributes( bool &attributesChanged, QStringList &commitErrors );
378
385 bool commitChangesDeleteFeatures( bool &featuresDeleted, QStringList &commitErrors );
386
393 bool commitChangesAddFeatures( bool &featuresAdded, QStringList &commitErrors );
394};
395
396#endif // QGSVECTORLAYEREDITBUFFER_H
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:56
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:45
A geometry is the spatial representation of a feature.
The edit buffer group manages a group of edit buffers.
void attributeRenamed(int idx, const QString &newName)
Emitted when an attribute has been renamed.
void committedAttributesDeleted(const QString &layerId, const QgsAttributeList &deletedAttributes)
Signals emitted after committing changes.
bool isFeatureDeleted(QgsFeatureId id) const
Returns true if the specified feature ID has been deleted but not committed.
QgsFeatureMap mAddedFeatures
New features which are not committed.
QgsFeatureIds deletedFeatureIds() const
Returns a list of deleted feature IDs which are not committed.
QgsChangedAttributesMap changedAttributeValues() const
Returns a map of features with changed attributes values which are not committed.
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geom)
Emitted when a feature's geometry is changed.
bool isFeatureAdded(QgsFeatureId id) const
Returns true if the specified feature ID has been added but not committed.
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
QgsVectorLayerEditBuffer()=default
Constructor for QgsVectorLayerEditBuffer.
QgsFieldNameMap mRenamedAttributes
Renamed attributes which are not committed.
QgsGeometryMap mChangedGeometries
Changed geometries which are not committed.
void committedAttributesRenamed(const QString &layerId, const QgsFieldNameMap &renamedAttributes)
Emitted after committing an attribute rename.
QgsAttributeList mDeletedAttributeIds
Deleted attributes fields which are not committed. The list is kept sorted.
QgsFeatureMap addedFeatures() const
Returns a map of new features which are not committed.
QgsFeatureIds mDeletedFeatureIds
Deleted feature IDs which are not committed.
bool isAttributeDeleted(int index) const
Returns true if the specified attribute has been deleted but not committed.
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
void featureDeleted(QgsFeatureId fid)
QgsGeometryMap changedGeometries() const
Returns a map of features with changed geometries which are not committed.
QList< QgsField > addedAttributes() const
Returns a list of added attributes fields which are not committed.
bool isFeatureAttributesChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had an attribute changed but not committed.
bool isFeatureGeometryChanged(QgsFeatureId id) const
Returns true if the specified feature ID has had its geometry changed but not committed.
QgsAttributeList deletedAttributeIds() const
Returns a list of deleted attributes fields which are not committed.
void attributeAdded(int idx)
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
void attributeDeleted(int idx)
void featureAdded(QgsFeatureId fid)
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &)
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not committed.
QList< QgsField > mAddedAttributes
Added attributes fields which are not committed.
void layerModified()
Emitted when modifications has been done on layer.
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
Undo command for adding a new attribute to a vector layer.
Undo command for adding a feature to a vector layer.
Undo command for modifying an attribute of a feature from a vector layer.
Undo command for modifying the geometry of a feature from a vector layer.
Undo command for removing an existing attribute from a vector layer.
Undo command for deleting a feature from a vector layer.
Undo command for renaming an existing attribute of a vector layer.
Base class for undo commands within a QgsVectorLayerEditBuffer.
Undo command for adding attri to a vector layer in transaction group.
Undo command for adding a feature to a vector layer in transaction group mode.
Undo command for changing attr value from a vector layer in transaction group.
Undo command for changing attributes' values from a vector layer in transaction group.
Undo command for changing feature geometry from a vector layer in transaction group.
Undo command for deleting attri of a vector layer in transaction group.
Undo command for deleting features from a vector layer in transaction group.
Undo command for deleting attri of a vector layer in transaction group.
Undo command for running a specific sql query in transaction group.
Undo command for vector layer in transaction group mode.
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition qgis_sip.h:126
QMap< int, QString > QgsFieldNameMap
QMap< int, QVariant > QgsAttributeMap
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition qgsfeature.h:912
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition qgsfeature.h:903
QList< QgsFeature > QgsFeatureList
Definition qgsfeature.h:917
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
Definition qgsfield.h:27
QSet< int > QgsAttributeIds
QList< int > QgsAttributeList
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap