OpenMW
apps/opencs/model/world/commands.hpp
Go to the documentation of this file.
00001 #ifndef CSM_WOLRD_COMMANDS_H
00002 #define CSM_WOLRD_COMMANDS_H
00003 
00004 #include "record.hpp"
00005 
00006 #include <string>
00007 #include <map>
00008 #include <vector>
00009 
00010 #include <QVariant>
00011 #include <QUndoCommand>
00012 #include <QModelIndex>
00013 
00014 #include "universalid.hpp"
00015 
00016 class QModelIndex;
00017 class QAbstractItemModel;
00018 
00019 namespace CSMWorld
00020 {
00021     class IdTable;
00022     class IdTable;
00023     class RecordBase;
00024 
00025     class ModifyCommand : public QUndoCommand
00026     {
00027             QAbstractItemModel& mModel;
00028             QModelIndex mIndex;
00029             QVariant mNew;
00030             QVariant mOld;
00031 
00032         public:
00033 
00034             ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_,
00035                 QUndoCommand *parent = 0);
00036 
00037             virtual void redo();
00038 
00039             virtual void undo();
00040     };
00041 
00042     class CreateCommand : public QUndoCommand
00043     {
00044             IdTable& mModel;
00045             std::string mId;
00046             UniversalId::Type mType;
00047             std::map<int, QVariant> mValues;
00048 
00049         public:
00050 
00051             CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
00052 
00053             void setType (UniversalId::Type type);
00054 
00055             void addValue (int column, const QVariant& value);
00056 
00057             virtual void redo();
00058 
00059             virtual void undo();
00060     };
00061 
00062     class RevertCommand : public QUndoCommand
00063     {
00064             IdTable& mModel;
00065             std::string mId;
00066             RecordBase *mOld;
00067 
00068             // not implemented
00069             RevertCommand (const RevertCommand&);
00070             RevertCommand& operator= (const RevertCommand&);
00071 
00072         public:
00073 
00074             RevertCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
00075 
00076             virtual ~RevertCommand();
00077 
00078             virtual void redo();
00079 
00080             virtual void undo();
00081     };
00082 
00083     class DeleteCommand : public QUndoCommand
00084     {
00085             IdTable& mModel;
00086             std::string mId;
00087             RecordBase *mOld;
00088 
00089             // not implemented
00090             DeleteCommand (const DeleteCommand&);
00091             DeleteCommand& operator= (const DeleteCommand&);
00092 
00093         public:
00094 
00095             DeleteCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
00096 
00097             virtual ~DeleteCommand();
00098 
00099             virtual void redo();
00100 
00101             virtual void undo();
00102     };
00103 
00104     class ReorderRowsCommand : public QUndoCommand
00105     {
00106             IdTable& mModel;
00107             int mBaseIndex;
00108             std::vector<int> mNewOrder;
00109 
00110         public:
00111 
00112             ReorderRowsCommand (IdTable& model, int baseIndex, const std::vector<int>& newOrder);
00113 
00114             virtual void redo();
00115 
00116             virtual void undo();
00117     };
00118 }
00119 
00120 #endif