QGIS API Documentation  master-59fd5e0
src/core/qgsvectorlayerundocommand.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsvectorlayerundocommand.h
00003     ---------------------
00004     begin                : June 2009
00005     copyright            : (C) 2009 by Martin Dobias
00006     email                : wonder dot sk at gmail dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #ifndef QGSVECTORLAYERUNDOCOMMAND_H
00017 #define QGSVECTORLAYERUNDOCOMMAND_H
00018 
00019 #include <QUndoCommand>
00020 
00021 #include <QVariant>
00022 #include <QSet>
00023 #include <QList>
00024 
00025 #include "qgsfield.h"
00026 #include "qgsfeature.h"
00027 
00028 class QgsGeometry;
00029 class QgsGeometryCache;
00030 
00031 #include "qgsvectorlayer.h"
00032 #include "qgsvectorlayereditbuffer.h"
00033 
00034 
00035 class QgsVectorLayerUndoCommand : public QUndoCommand
00036 {
00037   public:
00038     QgsVectorLayerUndoCommand( QgsVectorLayerEditBuffer *buffer )
00039         : QUndoCommand()
00040         , mBuffer( buffer )
00041     {}
00042     inline QgsVectorLayer *layer() { return mBuffer->L; }
00043     inline QgsGeometryCache *cache() { return mBuffer->L->cache(); }
00044 
00045     virtual int id() const { return -1; }
00046     virtual bool mergeWith( QUndoCommand * ) { return false; }
00047 
00048   protected:
00049     QgsVectorLayerEditBuffer* mBuffer;
00050 };
00051 
00052 
00053 class QgsVectorLayerUndoCommandAddFeature : public QgsVectorLayerUndoCommand
00054 {
00055   public:
00056     QgsVectorLayerUndoCommandAddFeature( QgsVectorLayerEditBuffer* buffer, QgsFeature& f );
00057 
00058     virtual void undo();
00059     virtual void redo();
00060 
00061   private:
00062     QgsFeature mFeature;
00063 };
00064 
00065 
00066 class QgsVectorLayerUndoCommandDeleteFeature : public QgsVectorLayerUndoCommand
00067 {
00068   public:
00069     QgsVectorLayerUndoCommandDeleteFeature( QgsVectorLayerEditBuffer* buffer, QgsFeatureId fid );
00070 
00071     virtual void undo();
00072     virtual void redo();
00073 
00074   private:
00075     QgsFeatureId mFid;
00076     QgsFeature mOldAddedFeature;
00077 };
00078 
00079 
00080 class QgsVectorLayerUndoCommandChangeGeometry : public QgsVectorLayerUndoCommand
00081 {
00082   public:
00083     QgsVectorLayerUndoCommandChangeGeometry( QgsVectorLayerEditBuffer* buffer, QgsFeatureId fid, QgsGeometry* newGeom );
00084     ~QgsVectorLayerUndoCommandChangeGeometry();
00085 
00086     virtual void undo();
00087     virtual void redo();
00088     virtual int id() const;
00089     virtual bool mergeWith( const QUndoCommand * );
00090 
00091   private:
00092     QgsFeatureId mFid;
00093     QgsGeometry* mOldGeom;
00094     mutable QgsGeometry* mNewGeom;
00095 };
00096 
00097 
00098 class QgsVectorLayerUndoCommandChangeAttribute : public QgsVectorLayerUndoCommand
00099 {
00100   public:
00101     QgsVectorLayerUndoCommandChangeAttribute( QgsVectorLayerEditBuffer* buffer, QgsFeatureId fid, int fieldIndex, const QVariant& newValue );
00102     virtual void undo();
00103     virtual void redo();
00104 
00105   private:
00106     QgsFeatureId mFid;
00107     int mFieldIndex;
00108     QVariant mOldValue;
00109     QVariant mNewValue;
00110     bool mFirstChange;
00111 };
00112 
00113 
00114 class QgsVectorLayerUndoCommandAddAttribute : public QgsVectorLayerUndoCommand
00115 {
00116   public:
00117     QgsVectorLayerUndoCommandAddAttribute( QgsVectorLayerEditBuffer* buffer, const QgsField& field );
00118 
00119     virtual void undo();
00120     virtual void redo();
00121 
00122   private:
00123     QgsField mField;
00124     int mFieldIndex;
00125 };
00126 
00127 
00128 class QgsVectorLayerUndoCommandDeleteAttribute : public QgsVectorLayerUndoCommand
00129 {
00130   public:
00131     QgsVectorLayerUndoCommandDeleteAttribute( QgsVectorLayerEditBuffer* buffer, int fieldIndex );
00132 
00133     virtual void undo();
00134     virtual void redo();
00135 
00136   private:
00137     int mFieldIndex;
00138     bool mProviderField;
00139     int mOriginIndex;
00140     QgsField mOldField;
00141 
00142     QMap<QgsFeatureId, QVariant> mDeletedValues;
00143 };
00144 
00145 
00146 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines