QGIS API Documentation  2.99.0-Master (0cba29c)
qgsvectorlayerundocommand.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerundocommand.h
3  ---------------------
4  begin : June 2009
5  copyright : (C) 2009 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 
16 #ifndef QGSVECTORLAYERUNDOCOMMAND_H
17 #define QGSVECTORLAYERUNDOCOMMAND_H
18 
19 #include "qgis_core.h"
20 #include "qgis.h"
21 #include <QUndoCommand>
22 
23 #include <QVariant>
24 #include <QSet>
25 #include <QList>
26 
27 #include "qgsfields.h"
28 #include "qgsfeature.h"
29 
30 class QgsGeometry;
31 
32 #include "qgsvectorlayer.h"
34 
40 class CORE_EXPORT QgsVectorLayerUndoCommand : public QUndoCommand
41 {
42  public:
43 
48  : QUndoCommand()
49  , mBuffer( buffer )
50  {}
51 
53  inline QgsVectorLayer *layer() { return mBuffer->L; }
54 
55  virtual int id() const override { return -1; }
56  virtual bool mergeWith( const QUndoCommand * ) override { return false; }
57 
58  protected:
60  QgsVectorLayerEditBuffer *mBuffer = nullptr;
61 };
62 
63 
70 {
71  public:
72 
78 
79  virtual void undo() override;
80  virtual void redo() override;
81 
82  private:
83  QgsFeature mFeature;
84 };
85 
86 
93 {
94  public:
95 
101 
102  virtual void undo() override;
103  virtual void redo() override;
104 
105  private:
106  QgsFeatureId mFid;
107  QgsFeature mOldAddedFeature;
108 };
109 
116 {
117  public:
118 
125 
126  virtual void undo() override;
127  virtual void redo() override;
128  virtual int id() const override;
129  virtual bool mergeWith( const QUndoCommand * ) override;
130 
131  private:
132  QgsFeatureId mFid;
133  QgsGeometry mOldGeom;
134  mutable QgsGeometry mNewGeom;
135 };
136 
137 
144 {
145  public:
146 
154  QgsVectorLayerUndoCommandChangeAttribute( QgsVectorLayerEditBuffer *buffer SIP_TRANSFER, QgsFeatureId fid, int fieldIndex, const QVariant &newValue, const QVariant &oldValue );
155  virtual void undo() override;
156  virtual void redo() override;
157 
158  private:
159  QgsFeatureId mFid;
160  int mFieldIndex;
161  QVariant mOldValue;
162  QVariant mNewValue;
163  bool mFirstChange;
164 };
165 
172 {
173  public:
174 
180 
181  virtual void undo() override;
182  virtual void redo() override;
183 
184  private:
185  QgsField mField;
186  int mFieldIndex;
187 };
188 
195 {
196  public:
197 
203 
204  virtual void undo() override;
205  virtual void redo() override;
206 
207  private:
208  int mFieldIndex;
209  QString mFieldName;
210  bool mProviderField;
211  int mOriginIndex;
212  QgsField mOldField;
213  QVariantMap mOldEditorWidgetConfig;
214 
215  QMap<QgsFeatureId, QVariant> mDeletedValues;
216  QString mOldName;
217 };
218 
219 
227 {
228  public:
229 
235  QgsVectorLayerUndoCommandRenameAttribute( QgsVectorLayerEditBuffer *buffer SIP_TRANSFER, int fieldIndex, const QString &newName );
236 
237  virtual void undo() override;
238  virtual void redo() override;
239 
240  private:
241  int mFieldIndex;
242  QString mOldName;
243  QString mNewName;
244 };
245 
246 
247 #endif
Undo command for removing an existing attribute from a vector layer.
virtual bool mergeWith(const QUndoCommand *) override
Undo command for deleting a feature from a vector layer.
virtual int id() const override
Base class for undo commands within a QgsVectorLayerEditBuffer.
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:96
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:61
Undo command for adding a feature to a vector layer.
Undo command for modifying the geometry of a feature from a vector layer.
QgsVectorLayer * layer()
Returns the layer associated with the undo command.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Undo command for renaming an existing attribute of a vector layer.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:46
Undo command for adding a new attribute to a vector layer.
QgsVectorLayerUndoCommand(QgsVectorLayerEditBuffer *buffer)
Constructor for QgsVectorLayerUndoCommand.
qint64 QgsFeatureId
Definition: qgsfeature.h:37
Represents a vector layer which manages a vector based data sets.