QGIS API Documentation  3.17.0-Master (8af46bc54f)
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_sip.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 
33 
40 class CORE_EXPORT QgsVectorLayerUndoCommand : public QUndoCommand
41 {
42  public:
43 
49  : mBuffer( buffer )
50  {}
51 
53  inline QgsVectorLayer *layer() { return mBuffer->L; }
54 
55  int id() const override { return -1; }
56  bool mergeWith( const QUndoCommand * ) override { return false; }
57 
58  protected:
60  QgsVectorLayerEditBuffer *mBuffer = nullptr;
61 };
62 
63 
71 {
72  public:
73 
80 
81  void undo() override;
82  void redo() override;
83 
84  private:
85  QgsFeature mFeature;
86 };
87 
88 
96 {
97  public:
98 
105 
106  void undo() override;
107  void redo() override;
108 
109  private:
110  QgsFeatureId mFid;
111  QgsFeature mOldAddedFeature;
112 };
113 
121 {
122  public:
123 
131 
132  void undo() override;
133  void redo() override;
134  int id() const override;
135  bool mergeWith( const QUndoCommand * ) override;
136 
137  private:
138  QgsFeatureId mFid;
139  QgsGeometry mOldGeom;
140  mutable QgsGeometry mNewGeom;
141 };
142 
143 
151 {
152  public:
153 
162  QgsVectorLayerUndoCommandChangeAttribute( QgsVectorLayerEditBuffer *buffer SIP_TRANSFER, QgsFeatureId fid, int fieldIndex, const QVariant &newValue, const QVariant &oldValue );
163  void undo() override;
164  void redo() override;
165 
166  private:
167  QgsFeatureId mFid;
168  int mFieldIndex;
169  QVariant mOldValue;
170  QVariant mNewValue;
171  bool mFirstChange;
172 };
173 
181 {
182  public:
183 
190 
191  void undo() override;
192  void redo() override;
193 
194  private:
195  QgsField mField;
196  int mFieldIndex;
197 };
198 
206 {
207  public:
208 
215 
216  void undo() override;
217  void redo() override;
218 
219  private:
220  int mFieldIndex;
221  QString mFieldName;
222  bool mProviderField;
223  int mOriginIndex;
224  QgsField mOldField;
225  QVariantMap mOldEditorWidgetConfig;
226 
227  QMap<QgsFeatureId, QVariant> mDeletedValues;
228  QString mOldName;
229 };
230 
231 
240 {
241  public:
242 
249  QgsVectorLayerUndoCommandRenameAttribute( QgsVectorLayerEditBuffer *buffer SIP_TRANSFER, int fieldIndex, const QString &newName );
250 
251  void undo() override;
252  void redo() override;
253 
254  private:
255  int mFieldIndex;
256  bool mProviderField;
257  int mOriginIndex;
258  QString mOldName;
259  QString mNewName;
260 };
261 
262 #endif
Undo command for removing an existing attribute from a vector layer.
Undo command for deleting a feature from a vector layer.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features ...
Definition: qgsfeatureid.h:28
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:123
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Undo command for adding a feature to a vector layer.
Undo command for modifying the geometry of a feature from a vector layer.
bool mergeWith(const QUndoCommand *) override
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:49
Undo command for adding a new attribute to a vector layer.
QgsVectorLayerUndoCommand(QgsVectorLayerEditBuffer *buffer)
Constructor for QgsVectorLayerUndoCommand.
Represents a vector layer which manages a vector based data sets.
const QgsField & field
Definition: qgsfield.h:471