QGIS API Documentation  2.17.0-Master (973e4b0)
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 <QUndoCommand>
20 
21 #include <QVariant>
22 #include <QSet>
23 #include <QList>
24 
25 #include "qgsfield.h"
26 #include "qgsfeature.h"
27 
28 class QgsGeometry;
29 class QgsGeometryCache;
30 
31 #include "qgsvectorlayer.h"
33 
39 class CORE_EXPORT QgsVectorLayerUndoCommand : public QUndoCommand
40 {
41  public:
42 
47  : QUndoCommand()
48  , mBuffer( buffer )
49  {}
50 
52  inline QgsVectorLayer *layer() { return mBuffer->L; }
53  inline QgsGeometryCache *cache() { return mBuffer->L->cache(); }
54 
55  virtual int id() const override { return -1; }
56  virtual bool mergeWith( const QUndoCommand * ) override { return false; }
57 
58  protected:
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 
126 
127  virtual void undo() override;
128  virtual void redo() override;
129  virtual int id() const override;
130  virtual bool mergeWith( const QUndoCommand * ) override;
131 
132  private:
133  QgsFeatureId mFid;
134  QgsGeometry* mOldGeom;
135  mutable QgsGeometry* mNewGeom;
136 };
137 
138 
145 {
146  public:
147 
155  QgsVectorLayerUndoCommandChangeAttribute( QgsVectorLayerEditBuffer* buffer, QgsFeatureId fid, int fieldIndex, const QVariant &newValue, const QVariant &oldValue );
156  virtual void undo() override;
157  virtual void redo() override;
158 
159  private:
160  QgsFeatureId mFid;
161  int mFieldIndex;
162  QVariant mOldValue;
163  QVariant mNewValue;
164  bool mFirstChange;
165 };
166 
173 {
174  public:
175 
181 
182  virtual void undo() override;
183  virtual void redo() override;
184 
185  private:
186  QgsField mField;
187  int mFieldIndex;
188 };
189 
196 {
197  public:
198 
204 
205  virtual void undo() override;
206  virtual void redo() override;
207 
208  private:
209  int mFieldIndex;
210  bool mProviderField;
211  int mOriginIndex;
212  QgsField mOldField;
213  QgsEditorWidgetConfig mOldEditorWidgetConfig;
214 
215  QMap<QgsFeatureId, QVariant> mDeletedValues;
216  QString mOldName;
217 };
218 
219 
227 {
228  public:
229 
235  QgsVectorLayerUndoCommandRenameAttribute( QgsVectorLayerEditBuffer* buffer, 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
QgsVectorLayerEditBuffer * mBuffer
Associated edit buffer.
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:76
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
Undo command for adding a feature to a vector layer.
Undo command for modifying the geometry of a feature from a vector layer.
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
QgsVectorLayer * layer()
Returns the layer associated with the undo command.
virtual void redo()
Undo command for renaming an existing attribute of a vector layer.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
Undo command for adding a new attribute to a vector layer.
virtual void undo()
QgsVectorLayerUndoCommand(QgsVectorLayerEditBuffer *buffer)
Constructor for QgsVectorLayerUndoCommand.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Represents a vector layer which manages a vector based data sets.