QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "qgsfeature.h"
20#include "qgsfields.h"
21#include "qgsgeometry.h"
22
23#include <QList>
24#include <QSet>
25
26class QgsVectorLayer;
28
29typedef QList<int> QgsAttributeList SIP_SKIP;
30typedef QSet<int> QgsAttributeIds SIP_SKIP;
31typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
32
38class CORE_EXPORT QgsVectorLayerEditBuffer : public QObject
39{
40 Q_OBJECT
41 public:
43
45 virtual bool isModified() const;
46
52 virtual bool addFeature( QgsFeature &f );
53
55 virtual bool addFeatures( QgsFeatureList &features );
56
58 virtual bool deleteFeature( QgsFeatureId fid );
59
61 virtual bool deleteFeatures( const QgsFeatureIds &fid );
62
64 virtual bool changeGeometry( QgsFeatureId fid, const QgsGeometry &geom );
65
67 virtual bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant() );
68
73 virtual bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues );
74
79 virtual bool addAttribute( const QgsField &field );
80
82 virtual bool deleteAttribute( int attr );
83
89 virtual bool renameAttribute( int attr, const QString &newName );
90
106 virtual bool commitChanges( QStringList &commitErrors );
107
109 virtual void rollBack();
110
116
123 QgsFeatureIds allAddedOrEditedFeatures() const;
124
130 bool isFeatureAdded( QgsFeatureId id ) const { return mAddedFeatures.contains( id ); }
131
137
143 bool isFeatureAttributesChanged( QgsFeatureId id ) const { return mChangedAttributeValues.contains( id ); }
144
150
156 bool isAttributeDeleted( int index ) const { return mDeletedAttributeIds.contains( index ); }
157
161 QList<QgsField> addedAttributes() const { return mAddedAttributes; }
162
168
174 bool isFeatureGeometryChanged( QgsFeatureId id ) const { return mChangedGeometries.contains( id ); }
175
181
187 bool isFeatureDeleted( QgsFeatureId id ) const { return mDeletedFeatureIds.contains( id ); }
188
194 void updateFields( QgsFields &fields ) SIP_SKIP;
195
200 QgsVectorLayerEditBufferGroup *editBufferGroup() const;
201
206 void setEditBufferGroup( QgsVectorLayerEditBufferGroup *editBufferGroup );
207
208 //QString dumpEditBuffer();
209
210 protected slots:
211 void undoIndexChanged( int index );
212
213 signals:
216
219
222
228 void geometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
229
233 void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
234
238 void attributeAdded( int idx );
239
243 void attributeDeleted( int idx );
244
250 void attributeRenamed( int idx, const QString &newName );
251
255 void committedAttributesDeleted( const QString &layerId, const QgsAttributeList &deletedAttributes );
256
260 void committedAttributesAdded( const QString &layerId, const QList<QgsField> &addedAttributes );
261
267 void committedAttributesRenamed( const QString &layerId, const QgsFieldNameMap &renamedAttributes );
268
272 void committedFeaturesAdded( const QString &layerId, const QgsFeatureList &addedFeatures );
273
277 void committedFeaturesRemoved( const QString &layerId, const QgsFeatureIds &deletedFeatureIds );
278
282 void committedAttributeValuesChanges( const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues );
283
287 void committedGeometriesChanges( const QString &layerId, const QgsGeometryMap &changedGeometries );
288
289 protected:
290
292
295
298
300 void handleAttributeAdded( int index, const QgsField &field );
301
303 void handleAttributeDeleted( int index );
304
306 void updateAttributeMapIndex( QgsAttributeMap &attrs, int index, int offset ) const;
307
308 void updateLayerFields();
309
310 protected:
311 QgsVectorLayer *L = nullptr;
312
321
332
339
342
345
348
350 QList<QgsField> mAddedAttributes;
351
354
357
359
361
362 friend class QgsGrassProvider; //GRASS provider totally abuses the edit buffer
363
364 private:
365
367
373 bool commitChangesCheckGeometryTypeCompatibility( QStringList &commitErrors );
374
381 bool commitChangesDeleteAttributes( bool &attributesDeleted, QStringList &commitErrors );
382
389 bool commitChangesRenameAttributes( bool &attributesRenamed, QStringList &commitErrors );
390
397 bool commitChangesAddAttributes( bool &attributesAdded, QStringList &commitErrors );
398
405 bool commitChangesCheckAttributesModifications( const QgsFields oldFields, QStringList &commitErrors );
406
413 bool commitChangesChangeAttributes( bool &attributesChanged, QStringList &commitErrors );
414
421 bool commitChangesDeleteFeatures( bool &featuresDeleted, QStringList &commitErrors );
422
429 bool commitChangesAddFeatures( bool &featuresAdded, QStringList &commitErrors );
430};
431
432#endif // QGSVECTORLAYEREDITBUFFER_H
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:54
Container of fields for a vector layer.
Definition qgsfields.h:46
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)
Emitted after attribute deletion has been committed to the layer.
bool isFeatureDeleted(QgsFeatureId id) const
Returns true if the specified feature ID has been deleted but not committed.
virtual bool deleteFeature(QgsFeatureId fid)
Delete a feature from the layer (but does not commit it).
QgsFeatureMap mAddedFeatures
New features which are not committed.
QgsFeatureIds deletedFeatureIds() const
Returns a list of deleted feature IDs which are not committed.
friend class QgsVectorLayerUndoPassthroughCommandChangeGeometry
QgsChangedAttributesMap changedAttributeValues() const
Returns a map of features with changed attributes values which are not committed.
void committedAttributeValuesChanges(const QString &layerId, const QgsChangedAttributesMap &changedAttributesValues)
Emitted after feature attribute value changes have been committed to the layer.
virtual bool renameAttribute(int attr, const QString &newName)
Renames an attribute field (but does not commit it).
void geometryChanged(QgsFeatureId fid, const QgsGeometry &geom)
Emitted when a feature's geometry is changed.
void updateFeatureGeometry(QgsFeature &f)
Update feature with uncommitted geometry updates.
friend class QgsVectorLayerUndoPassthroughCommandDeleteFeatures
virtual bool deleteFeatures(const QgsFeatureIds &fid)
Deletes a set of features from the layer (but does not commit it).
bool isFeatureAdded(QgsFeatureId id) const
Returns true if the specified feature ID has been added but not committed.
void handleAttributeDeleted(int index)
Update added and changed features after removal of an attribute.
virtual bool addAttribute(const QgsField &field)
Adds an attribute field (but does not commit it) returns true if the field was added.
void committedAttributesAdded(const QString &layerId, const QList< QgsField > &addedAttributes)
Emitted after attribute addition has been committed to the layer.
virtual bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it).
friend class QgsVectorLayerUndoPassthroughCommandUpdate
friend class QgsVectorLayerUndoPassthroughCommandAddAttribute
QgsVectorLayerEditBuffer()=default
QgsFieldNameMap mRenamedAttributes
Renamed attributes which are not committed.
friend class QgsVectorLayerUndoPassthroughCommandRenameAttribute
friend class QgsVectorLayerUndoPassthroughCommandChangeAttributes
QgsGeometryMap mChangedGeometries
Changed geometries which are not committed.
void committedAttributesRenamed(const QString &layerId, const QgsFieldNameMap &renamedAttributes)
Emitted after committing an attribute rename.
virtual bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues)
Changes values of attributes (but does not commit it).
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.
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
bool isAttributeDeleted(int index) const
Returns true if the specified attribute has been deleted but not committed.
friend class QgsVectorLayerUndoPassthroughCommandChangeAttribute
void committedFeaturesAdded(const QString &layerId, const QgsFeatureList &addedFeatures)
Emitted after feature addition has been committed to the layer.
void featureDeleted(QgsFeatureId fid)
Emitted when a feature was deleted from the buffer.
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)
Emitted when an attribute was added to the buffer.
void committedGeometriesChanges(const QString &layerId, const QgsGeometryMap &changedGeometries)
Emitted after feature geometry changes have been committed to the layer.
virtual bool addFeature(QgsFeature &f)
Adds a feature.
virtual void rollBack()
Stop editing and discard the edits.
friend class QgsVectorLayerUndoCommandRenameAttribute
friend class QgsVectorLayerUndoPassthroughCommandDeleteAttribute
void handleAttributeAdded(int index, const QgsField &field)
Update added and changed features after addition of an attribute.
QgsVectorLayerEditBufferGroup * mEditBufferGroup
friend class QgsVectorLayerUndoCommandDeleteAttribute
void attributeValueChanged(QgsFeatureId fid, int idx, const QVariant &value)
Emitted when a feature's attribute value has been changed.
void attributeDeleted(int idx)
Emitted when an attribute was deleted from the buffer.
void featureAdded(QgsFeatureId fid)
Emitted when a feature has been added to the buffer.
QgsVectorLayerEditBuffer(QgsVectorLayer *layer)
QgsChangedAttributesMap mChangedAttributeValues
Changed attributes values which are not committed.
virtual bool commitChanges(QStringList &commitErrors)
Attempts to commit any changes to disk.
friend class QgsVectorLayerUndoCommandChangeAttribute
virtual bool deleteAttribute(int attr)
Deletes an attribute field (but does not commit it).
virtual bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant())
Changed an attribute value (but does not commit it).
void updateAttributeMapIndex(QgsAttributeMap &attrs, int index, int offset) const
Updates an index in an attribute map to a new value (for updates of changed attributes).
QList< QgsField > mAddedAttributes
Added attributes fields which are not committed.
virtual bool changeGeometry(QgsFeatureId fid, const QgsGeometry &geom)
Change feature's geometry.
void layerModified()
Emitted when modifications has been done on layer.
void updateChangedAttributes(QgsFeature &f)
Update feature with uncommitted attribute updates.
void committedFeaturesRemoved(const QString &layerId, const QgsFeatureIds &deletedFeatureIds)
Emitted after feature removal has been committed to the layer.
friend class QgsVectorLayerUndoPassthroughCommandAddFeatures
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:134
QMap< int, QString > QgsFieldNameMap
QMap< int, QVariant > QgsAttributeMap
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
Definition qgsfield.h:28
QSet< int > QgsAttributeIds
QList< int > QgsAttributeList
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap