Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsvectorlayerundocommand.cpp
Go to the documentation of this file.
1 
3 
4 #include "qgsgeometry.h"
5 #include "qgsvectorlayer.h"
6 
7 #include "qgslogger.h"
8 
10  : original( NULL ), target( NULL )
11 {
12 }
13 
15 {
16  if ( orig.type() != QGis::UnknownGeometry )
17  {
18  original = new QgsGeometry( orig );
19  }
20  else
21  {
22  original = NULL;
23  }
24 }
25 
27 {
28  if ( dest.type() != QGis::UnknownGeometry )
29  {
30  target = new QgsGeometry( dest );
31  }
32  else
33  {
34  target = NULL;
35  }
36 }
37 
38 
40 {
41  delete original;
42  delete target;
43 }
44 
45 
47  : QUndoCommand()
48 {
49  setText( text );
50  mLayer = vlayer;
51  mFirstRun = true;
52 }
53 
55 {
56  // when the command is added to the undo stack, the redo() function is called
57  // but we have already done the changes in the layer, so we ignore the first redo() call
58  if ( mFirstRun )
59  {
60  mFirstRun = false;
61  return;
62  }
63 
64  mLayer->redoEditCommand( this );
65 }
66 
68 {
69  mLayer->undoEditCommand( this );
70 }
71 
72 
73 void QgsUndoCommand::storeGeometryChange( int featureId, QgsGeometry& original, QgsGeometry& target )
74 {
75  if ( mGeometryChange.contains( featureId ) )
76  {
77  // geometry has been modified already: just alter the resulting geometry
78  mGeometryChange[featureId].setTargetGeometry( target );
79  }
80  else
81  {
82  // create new entry about changed geometry
83  mGeometryChange.insert( featureId, GeometryChangeEntry() );
84  mGeometryChange[featureId].setOriginalGeometry( original );
85  mGeometryChange[featureId].setTargetGeometry( target );
86  }
87 }
88 
89 void QgsUndoCommand::storeAttributeChange( int featureId, int field, QVariant original, QVariant target, bool isFirstChange )
90 {
92  entry.isFirstChange = isFirstChange;
93  entry.original = original;
94  entry.target = target;
95  mAttributeChange[featureId].insert( field, entry );
96 }
97 
98 void QgsUndoCommand::storeAttributeAdd( int index, const QgsField & value )
99 {
100  mAddedAttributes.insert( index, value );
101 }
102 
103 void QgsUndoCommand::storeAttributeDelete( int index, const QgsField & orig )
104 {
105  mDeletedAttributes.insert( index, orig );
106 }
107 
109 {
110  mDeletedFeatureIdChange.insert( featureId );
111 }
112 
114 {
115  mAddedFeatures.append( feature );
116 }