2012-11-29 15:05:28 +00:00
|
|
|
#ifndef CSM_WOLRD_COMMANDS_H
|
|
|
|
#define CSM_WOLRD_COMMANDS_H
|
|
|
|
|
|
|
|
#include "record.hpp"
|
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
#include <string>
|
2013-07-30 10:53:03 +00:00
|
|
|
#include <map>
|
2013-11-14 10:39:14 +00:00
|
|
|
#include <vector>
|
2012-12-03 20:44:16 +00:00
|
|
|
|
2012-11-29 15:05:28 +00:00
|
|
|
#include <QVariant>
|
|
|
|
#include <QUndoCommand>
|
|
|
|
#include <QModelIndex>
|
2014-06-24 10:35:26 +00:00
|
|
|
#include <QVariant>
|
2012-11-29 15:05:28 +00:00
|
|
|
|
2013-07-30 08:27:17 +00:00
|
|
|
#include "universalid.hpp"
|
|
|
|
|
2012-11-29 15:05:28 +00:00
|
|
|
class QModelIndex;
|
|
|
|
class QAbstractItemModel;
|
|
|
|
|
|
|
|
namespace CSMWorld
|
|
|
|
{
|
2013-07-28 11:39:33 +00:00
|
|
|
class IdTable;
|
2012-12-06 13:56:04 +00:00
|
|
|
class IdTable;
|
|
|
|
class RecordBase;
|
2012-12-03 20:44:16 +00:00
|
|
|
|
2012-11-29 15:05:28 +00:00
|
|
|
class ModifyCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
QAbstractItemModel& mModel;
|
|
|
|
QModelIndex mIndex;
|
|
|
|
QVariant mNew;
|
|
|
|
QVariant mOld;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_,
|
|
|
|
QUndoCommand *parent = 0);
|
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2012-12-03 20:44:16 +00:00
|
|
|
|
2014-01-19 15:49:39 +00:00
|
|
|
class CloneCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
IdTable& mModel;
|
|
|
|
std::string mIdOrigin;
|
|
|
|
std::string mIdDestination;
|
|
|
|
UniversalId::Type mType;
|
|
|
|
std::map<int, QVariant> mValues;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-06-24 10:35:26 +00:00
|
|
|
CloneCommand (IdTable& model, const std::string& idOrigin,
|
2014-01-19 15:49:39 +00:00
|
|
|
const std::string& IdDestination,
|
2014-01-20 12:59:00 +00:00
|
|
|
const UniversalId::Type type,
|
2014-01-19 15:49:39 +00:00
|
|
|
QUndoCommand* parent = 0);
|
2014-01-27 18:40:05 +00:00
|
|
|
|
2014-01-19 15:49:39 +00:00
|
|
|
virtual void redo();
|
|
|
|
|
2014-01-20 12:59:00 +00:00
|
|
|
virtual void undo();
|
2014-01-19 15:49:39 +00:00
|
|
|
};
|
2014-01-27 18:40:05 +00:00
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
class CreateCommand : public QUndoCommand
|
|
|
|
{
|
2013-07-28 11:39:33 +00:00
|
|
|
IdTable& mModel;
|
2012-12-03 20:44:16 +00:00
|
|
|
std::string mId;
|
2013-07-30 08:27:17 +00:00
|
|
|
UniversalId::Type mType;
|
2013-07-30 10:53:03 +00:00
|
|
|
std::map<int, QVariant> mValues;
|
2012-12-03 20:44:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-07-28 11:39:33 +00:00
|
|
|
CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
2012-12-03 20:44:16 +00:00
|
|
|
|
2013-07-30 08:27:17 +00:00
|
|
|
void setType (UniversalId::Type type);
|
|
|
|
|
2013-07-30 10:53:03 +00:00
|
|
|
void addValue (int column, const QVariant& value);
|
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2012-12-06 13:56:04 +00:00
|
|
|
|
|
|
|
class RevertCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
IdTable& mModel;
|
|
|
|
std::string mId;
|
|
|
|
RecordBase *mOld;
|
|
|
|
|
|
|
|
// not implemented
|
|
|
|
RevertCommand (const RevertCommand&);
|
|
|
|
RevertCommand& operator= (const RevertCommand&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
RevertCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
|
|
|
|
|
|
|
virtual ~RevertCommand();
|
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2012-12-06 14:18:41 +00:00
|
|
|
|
|
|
|
class DeleteCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
IdTable& mModel;
|
|
|
|
std::string mId;
|
|
|
|
RecordBase *mOld;
|
|
|
|
|
|
|
|
// not implemented
|
|
|
|
DeleteCommand (const DeleteCommand&);
|
|
|
|
DeleteCommand& operator= (const DeleteCommand&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DeleteCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
|
|
|
|
|
|
|
virtual ~DeleteCommand();
|
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2013-11-14 10:39:14 +00:00
|
|
|
|
|
|
|
class ReorderRowsCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
IdTable& mModel;
|
|
|
|
int mBaseIndex;
|
|
|
|
std::vector<int> mNewOrder;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ReorderRowsCommand (IdTable& model, int baseIndex, const std::vector<int>& newOrder);
|
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2014-06-24 10:35:26 +00:00
|
|
|
|
|
|
|
class DeleteNestedCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
IdTable& mModel;
|
|
|
|
|
|
|
|
std::string mId;
|
|
|
|
|
|
|
|
std::vector<QVariant> mOld;
|
|
|
|
|
|
|
|
int mParentColumn;
|
|
|
|
|
|
|
|
int mNestedRow;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-07-01 18:52:27 +00:00
|
|
|
DeleteNestedCommand (IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
2014-06-24 10:35:26 +00:00
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2014-06-24 17:19:40 +00:00
|
|
|
|
|
|
|
class AddNestedCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
IdTable& mModel;
|
|
|
|
|
|
|
|
std::string mId;
|
|
|
|
|
|
|
|
int mNewRow;
|
|
|
|
|
|
|
|
int mParentColumn;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-07-01 18:52:27 +00:00
|
|
|
AddNestedCommand(IdTable& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
2014-06-24 17:19:40 +00:00
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2012-11-29 15:05:28 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 10:35:26 +00:00
|
|
|
#endif
|