OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
commands.hpp
Go to the documentation of this file.
1 #ifndef CSM_WOLRD_COMMANDS_H
2 #define CSM_WOLRD_COMMANDS_H
3 
4 #include "record.hpp"
5 
6 #include <string>
7 #include <map>
8 #include <vector>
9 
10 #include <QVariant>
11 #include <QUndoCommand>
12 #include <QModelIndex>
13 
14 #include "universalid.hpp"
15 #include "nestedtablewrapper.hpp"
16 
17 class QModelIndex;
18 class QAbstractItemModel;
19 
20 namespace CSMWorld
21 {
22  class IdTable;
23  class IdTree;
24  struct RecordBase;
25  struct NestedTableWrapperBase;
26 
27  class ModifyCommand : public QUndoCommand
28  {
30  QModelIndex mIndex;
31  QVariant mNew;
32  QVariant mOld;
33 
35  QModelIndex mRecordStateIndex;
37 
38  public:
39 
40  ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_,
41  QUndoCommand *parent = 0);
42 
43  virtual void redo();
44 
45  virtual void undo();
46  };
47 
48  class CreateCommand : public QUndoCommand
49  {
50  std::map<int, QVariant> mValues;
51  std::map<int, std::pair<int, QVariant> > mNestedValues;
54 
55  protected:
56 
58  std::string mId;
60 
61  protected:
62 
64  void applyModifications();
65 
66  public:
67 
68  CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
69 
70  void setType (UniversalId::Type type);
71 
72  void addValue (int column, const QVariant& value);
73 
74  void addNestedValue(int parentColumn, int nestedColumn, const QVariant &value);
75 
76  virtual void redo();
77 
78  virtual void undo();
79  };
80 
81  class CloneCommand : public CreateCommand
82  {
83  std::string mIdOrigin;
84 
85  public:
86 
87  CloneCommand (IdTable& model, const std::string& idOrigin,
88  const std::string& IdDestination,
89  const UniversalId::Type type,
90  QUndoCommand* parent = 0);
91 
92  virtual void redo();
93 
94  virtual void undo();
95  };
96 
97  class RevertCommand : public QUndoCommand
98  {
100  std::string mId;
102 
103  // not implemented
104  RevertCommand (const RevertCommand&);
106 
107  public:
108 
109  RevertCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
110 
111  virtual ~RevertCommand();
112 
113  virtual void redo();
114 
115  virtual void undo();
116  };
117 
119  {
121  std::string mId;
124 
125  // not implemented
126  DeleteCommand (const DeleteCommand&);
128 
129  public:
130 
131  DeleteCommand (IdTable& model, const std::string& id,
133 
134  virtual ~DeleteCommand();
135 
136  virtual void redo();
137 
138  virtual void undo();
139  };
140 
142  {
145  std::vector<int> mNewOrder;
146 
147  public:
148 
149  ReorderRowsCommand (IdTable& model, int baseIndex, const std::vector<int>& newOrder);
150 
151  virtual void redo();
152 
153  virtual void undo();
154  };
155 
157  {
158  public:
159 
160  CreatePathgridCommand(IdTable& model, const std::string& id, QUndoCommand *parent = 0);
161 
162  virtual void redo();
163  };
164 
171  {
173  int mRow;
174  QModelIndex mIndex;
175  QVariant mNew; // invalid, if new cell ID has not been calculated yet
176  QVariant mOld;
177 
178  public:
179 
180  UpdateCellCommand (IdTable& model, int row, QUndoCommand *parent = 0);
181 
182  virtual void redo();
183 
184  virtual void undo();
185  };
186 
187 
189  {
191 
192  public:
193  NestedTableStoring(const IdTree& model, const std::string& id, int parentColumn);
194 
196 
197  protected:
198 
199  const NestedTableWrapperBase& getOld() const;
200  };
201 
203  {
205 
206  std::string mId;
207 
209 
211 
212  // The command to redo/undo the Modified status of a record
214 
215  public:
216 
217  DeleteNestedCommand (IdTree& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
218 
219  virtual void redo();
220 
221  virtual void undo();
222  };
223 
225  {
227 
228  std::string mId;
229 
230  int mNewRow;
231 
233 
234  // The command to redo/undo the Modified status of a record
236 
237  public:
238 
239  AddNestedCommand(IdTree& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
240 
241  virtual void redo();
242 
243  virtual void undo();
244  };
245 }
246 
247 #endif
ModifyCommand(QAbstractItemModel &model, const QModelIndex &index, const QVariant &new_, QUndoCommand *parent=0)
Definition: commands.cpp:18
ModifyCommand * mModifyParentCommand
Definition: commands.hpp:213
Definition: nestedtablewrapper.hpp:6
UpdateCellCommand(IdTable &model, int row, QUndoCommand *parent=0)
Definition: commands.cpp:265
int mNewRow
Definition: commands.hpp:230
std::vector< int > mNewOrder
Definition: commands.hpp:145
Definition: commands.hpp:81
Definition: commands.hpp:48
ModifyCommand * mModifyParentCommand
Definition: commands.hpp:235
Definition: idtable.hpp:15
IdTable & mModel
Definition: commands.hpp:99
ReorderRowsCommand(IdTable &model, int baseIndex, const std::vector< int > &newOrder)
Definition: commands.cpp:198
Definition: commands.hpp:188
UniversalId::Type mType
Definition: commands.hpp:123
int mBaseIndex
Definition: commands.hpp:144
const NestedTableWrapperBase & getOld() const
Definition: commands.cpp:378
Definition: commands.hpp:97
QModelIndex mIndex
Definition: commands.hpp:174
CreatePathgridCommand(IdTable &model, const std::string &id, QUndoCommand *parent=0)
Definition: commands.cpp:241
QModelIndex mRecordStateIndex
Definition: commands.hpp:35
Type
Definition: universalid.hpp:40
QVariant mNew
Definition: commands.hpp:175
std::string mIdOrigin
Definition: commands.hpp:83
IdTree & mModel
Definition: commands.hpp:204
DeleteCommand & operator=(const DeleteCommand &)
std::map< int, std::pair< int, QVariant > > mNestedValues
Definition: commands.hpp:51
void setType(UniversalId::Type type)
Definition: commands.cpp:110
virtual void redo()
Definition: commands.cpp:271
Definition: commands.hpp:118
NestedTableWrapperBase * mOld
Definition: commands.hpp:190
State
Definition: record.hpp:10
int mParentColumn
Definition: commands.hpp:232
CreateCommand(IdTable &model, const std::string &id, QUndoCommand *parent=0)
Definition: commands.cpp:94
void addValue(int column, const QVariant &value)
Definition: commands.cpp:100
IdTree & mModel
Definition: commands.hpp:226
int mNestedRow
Definition: commands.hpp:210
NestedTableStoring(const IdTree &model, const std::string &id, int parentColumn)
Definition: commands.cpp:370
virtual void redo()
Definition: commands.cpp:203
std::string mId
Definition: commands.hpp:206
RevertCommand & operator=(const RevertCommand &)
virtual void undo()
Definition: commands.cpp:333
std::string mId
Definition: commands.hpp:121
CSMWorld::RecordBase::State mOldRecordState
Definition: commands.hpp:36
QVariant mOld
Definition: commands.hpp:32
IdTable & mModel
Definition: commands.hpp:143
virtual ~DeleteCommand()
Definition: commands.cpp:170
RecordBase * mOld
Definition: commands.hpp:101
void applyModifications()
Apply modifications set via addValue.
Definition: commands.cpp:72
DeleteCommand(const DeleteCommand &)
virtual void undo()
Definition: commands.cpp:299
virtual void undo()
Definition: commands.cpp:121
virtual void redo()
Definition: commands.cpp:325
virtual void redo()
Definition: commands.cpp:139
Definition: commands.hpp:141
Definition: commands.hpp:156
~NestedTableStoring()
Definition: commands.cpp:373
RevertCommand(const RevertCommand &)
UniversalId::Type mType
Definition: commands.hpp:59
Definition: commands.hpp:202
std::map< int, QVariant > mValues
Definition: commands.hpp:50
int mRow
Definition: commands.hpp:173
Definition: record.hpp:8
QAbstractItemModel * mModel
Definition: commands.hpp:29
bool mHasRecordState
Definition: commands.hpp:34
IdTable & mModel
Definition: commands.hpp:57
AddNestedCommand(IdTree &model, const std::string &id, int nestedRow, int parentColumn, QUndoCommand *parent=0)
Definition: commands.cpp:340
Update cell ID according to x/y-coordinates.
Definition: commands.hpp:170
IdTable & mModel
Definition: commands.hpp:120
RecordBase * mOld
Definition: commands.hpp:122
DeleteNestedCommand(IdTree &model, const std::string &id, int nestedRow, int parentColumn, QUndoCommand *parent=0)
Definition: commands.cpp:305
Definition: commands.hpp:27
virtual void redo()
Definition: commands.cpp:230
CloneCommand(IdTable &model, const std::string &idOrigin, const std::string &IdDestination, const UniversalId::Type type, QUndoCommand *parent=0)
Definition: commands.cpp:219
int mParentColumn
Definition: commands.hpp:208
Definition: universalid.hpp:42
std::string mId
Definition: commands.hpp:100
Definition: idtree.hpp:25
virtual void undo()
Definition: commands.cpp:156
virtual void redo()
Definition: commands.cpp:356
virtual void redo()
Definition: commands.cpp:56
virtual void redo()
Definition: commands.cpp:175
virtual void redo()
Definition: commands.cpp:247
QVariant mNew
Definition: commands.hpp:31
Definition: commands.hpp:224
virtual void undo()
Definition: commands.cpp:208
virtual void undo()
Definition: commands.cpp:363
std::string mId
Definition: commands.hpp:228
virtual void undo()
Definition: commands.cpp:62
virtual void redo()
Definition: commands.cpp:115
QModelIndex mIndex
Definition: commands.hpp:30
QVariant mOld
Definition: commands.hpp:176
void addNestedValue(int parentColumn, int nestedColumn, const QVariant &value)
Definition: commands.cpp:105
IdTable & mModel
Definition: commands.hpp:172
virtual void undo()
Definition: commands.cpp:192
std::string mId
Definition: commands.hpp:58
virtual ~RevertCommand()
Definition: commands.cpp:134
virtual void undo()
Definition: commands.cpp:236