Quantum GIS API Documentation  1.8
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.sk at gmail.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 QgsVectorLayer;
00030 
00031 
00032 // TODO: copied from qgsvectorlayer.h
00033 typedef QList<int> QgsAttributeList;
00034 typedef QSet<int> QgsAttributeIds;
00035 
00036 
00040 class QgsUndoCommand : public QUndoCommand
00041 {
00042   public:
00043 
00045     class AttributeChangeEntry
00046     {
00047       public:
00048         bool isFirstChange;
00049         QVariant original;
00050         QVariant target;
00051     };
00052 
00053     typedef QMap<int, AttributeChangeEntry> AttributeChanges;
00054 
00056     class GeometryChangeEntry
00057     {
00058       public:
00059         GeometryChangeEntry();
00060         ~GeometryChangeEntry();
00061 
00062         void setOriginalGeometry( QgsGeometry& orig );
00063         void setTargetGeometry( QgsGeometry& target );
00064 
00065         QgsGeometry* original;
00066         QgsGeometry* target;
00067     };
00068 
00069 
00070     QgsUndoCommand( QgsVectorLayer* layer, QString text );
00071 
00075     void undo();
00076 
00080     void redo();
00081 
00088     void storeGeometryChange( QgsFeatureId featureId, QgsGeometry& original, QgsGeometry& target );
00089 
00098     void storeAttributeChange( QgsFeatureId featureId, int field, QVariant original, QVariant target, bool isFirstChange );
00099 
00104     void storeFeatureDelete( QgsFeatureId featureId );
00105 
00110     void storeFeatureAdd( QgsFeature& feature );
00111 
00117     void storeAttributeAdd( int index, const QgsField & value );
00118 
00124     void storeAttributeDelete( int index, const QgsField & orig );
00125 
00126   private:
00128     bool mFirstRun;
00129 
00131     QgsVectorLayer* mLayer;
00132 
00134     QMap<QgsFeatureId, GeometryChangeEntry> mGeometryChange;
00135 
00137     QMap<QgsFeatureId, AttributeChanges> mAttributeChange;
00138 
00143     QgsFeatureIds mDeletedFeatureIdChange;
00144 
00146     QgsFieldMap mAddedAttributes;
00147 
00149     QgsFieldMap mDeletedAttributes;
00150 
00154     QgsFeatureList mAddedFeatures;
00155 
00156     friend class QgsVectorLayer;
00157 };
00158 
00159 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines