2012-11-29 16:05:28 +01:00
|
|
|
#ifndef CSM_WOLRD_COMMANDS_H
|
|
|
|
#define CSM_WOLRD_COMMANDS_H
|
|
|
|
|
|
|
|
#include "record.hpp"
|
|
|
|
|
2012-12-03 21:44:16 +01:00
|
|
|
#include <string>
|
2013-07-30 12:53:03 +02:00
|
|
|
#include <map>
|
2013-11-14 11:39:14 +01:00
|
|
|
#include <vector>
|
2012-12-03 21:44:16 +01:00
|
|
|
|
2012-11-29 16:05:28 +01:00
|
|
|
#include <QVariant>
|
|
|
|
#include <QUndoCommand>
|
|
|
|
#include <QModelIndex>
|
|
|
|
|
2013-07-30 10:27:17 +02:00
|
|
|
#include "universalid.hpp"
|
2014-07-18 18:26:22 +02:00
|
|
|
#include "nestedtablewrapper.hpp"
|
2013-07-30 10:27:17 +02:00
|
|
|
|
2012-11-29 16:05:28 +01:00
|
|
|
class QModelIndex;
|
|
|
|
class QAbstractItemModel;
|
|
|
|
|
|
|
|
namespace CSMWorld
|
|
|
|
{
|
2013-07-28 13:39:33 +02:00
|
|
|
class IdTable;
|
2015-04-02 20:19:15 +11:00
|
|
|
class IdTree;
|
2015-03-14 12:42:46 +11:00
|
|
|
struct RecordBase;
|
2015-04-09 20:53:41 +10:00
|
|
|
struct NestedTableWrapperBase;
|
2012-12-03 21:44:16 +01:00
|
|
|
|
2012-11-29 16:05:28 +01:00
|
|
|
class ModifyCommand : public QUndoCommand
|
|
|
|
{
|
2015-04-23 14:24:43 +02:00
|
|
|
QAbstractItemModel *mModel;
|
2012-11-29 16:05:28 +01:00
|
|
|
QModelIndex mIndex;
|
|
|
|
QVariant mNew;
|
|
|
|
QVariant mOld;
|
|
|
|
|
2015-05-22 23:53:25 +03:00
|
|
|
bool mHasRecordState;
|
|
|
|
QModelIndex mRecordStateIndex;
|
|
|
|
CSMWorld::RecordBase::State mOldRecordState;
|
|
|
|
|
2012-11-29 16:05:28 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
ModifyCommand (QAbstractItemModel& model, const QModelIndex& index, const QVariant& new_,
|
|
|
|
QUndoCommand *parent = 0);
|
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2012-12-03 21:44:16 +01:00
|
|
|
|
2014-09-20 10:36:43 +02:00
|
|
|
class CreateCommand : public QUndoCommand
|
2014-01-19 16:49:39 +01:00
|
|
|
{
|
2014-09-20 10:36:43 +02:00
|
|
|
std::map<int, QVariant> mValues;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2014-01-19 16:49:39 +01:00
|
|
|
IdTable& mModel;
|
2014-09-20 10:36:43 +02:00
|
|
|
std::string mId;
|
2014-01-19 16:49:39 +01:00
|
|
|
UniversalId::Type mType;
|
2014-09-20 10:36:43 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/// Apply modifications set via addValue.
|
|
|
|
void applyModifications();
|
2014-01-19 16:49:39 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-09-20 10:36:43 +02:00
|
|
|
CreateCommand (IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
|
|
|
|
|
|
|
void setType (UniversalId::Type type);
|
|
|
|
|
|
|
|
void addValue (int column, const QVariant& value);
|
2014-01-27 19:40:05 +01:00
|
|
|
|
2014-01-19 16:49:39 +01:00
|
|
|
virtual void redo();
|
|
|
|
|
2014-01-20 13:59:00 +01:00
|
|
|
virtual void undo();
|
2014-01-19 16:49:39 +01:00
|
|
|
};
|
2014-01-27 19:40:05 +01:00
|
|
|
|
2014-09-20 10:36:43 +02:00
|
|
|
class CloneCommand : public CreateCommand
|
2012-12-03 21:44:16 +01:00
|
|
|
{
|
2014-09-20 10:36:43 +02:00
|
|
|
std::string mIdOrigin;
|
2012-12-03 21:44:16 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-09-20 10:36:43 +02:00
|
|
|
CloneCommand (IdTable& model, const std::string& idOrigin,
|
|
|
|
const std::string& IdDestination,
|
|
|
|
const UniversalId::Type type,
|
|
|
|
QUndoCommand* parent = 0);
|
2013-07-30 12:53:03 +02:00
|
|
|
|
2012-12-03 21:44:16 +01:00
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2012-12-06 14:56:04 +01: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 15:18:41 +01:00
|
|
|
|
|
|
|
class DeleteCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
IdTable& mModel;
|
|
|
|
std::string mId;
|
|
|
|
RecordBase *mOld;
|
2015-04-25 06:06:11 +10:00
|
|
|
UniversalId::Type mType;
|
2012-12-06 15:18:41 +01:00
|
|
|
|
|
|
|
// not implemented
|
|
|
|
DeleteCommand (const DeleteCommand&);
|
|
|
|
DeleteCommand& operator= (const DeleteCommand&);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-04-25 06:06:11 +10:00
|
|
|
DeleteCommand (IdTable& model, const std::string& id,
|
|
|
|
UniversalId::Type type = UniversalId::Type_None, QUndoCommand *parent = 0);
|
2012-12-06 15:18:41 +01:00
|
|
|
|
|
|
|
virtual ~DeleteCommand();
|
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2013-11-14 11:39:14 +01: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 12:35:26 +02:00
|
|
|
|
2015-01-16 15:17:52 +01:00
|
|
|
/// \brief Update cell ID according to x/y-coordinates
|
|
|
|
///
|
|
|
|
/// \note The new value will be calculated in the first call to redo instead of the
|
|
|
|
/// constructor to accommodate multiple coordinate-affecting commands being executed
|
|
|
|
/// in a macro.
|
|
|
|
class UpdateCellCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
IdTable& mModel;
|
|
|
|
int mRow;
|
|
|
|
QModelIndex mIndex;
|
|
|
|
QVariant mNew; // invalid, if new cell ID has not been calculated yet
|
|
|
|
QVariant mOld;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
UpdateCellCommand (IdTable& model, int row, QUndoCommand *parent = 0);
|
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2015-04-25 06:52:53 +10:00
|
|
|
|
|
|
|
|
2014-07-21 09:52:09 +02:00
|
|
|
class NestedTableStoring
|
|
|
|
{
|
|
|
|
NestedTableWrapperBase* mOld;
|
|
|
|
|
|
|
|
public:
|
2015-04-02 20:19:15 +11:00
|
|
|
NestedTableStoring(const IdTree& model, const std::string& id, int parentColumn);
|
|
|
|
|
2014-07-21 09:52:09 +02:00
|
|
|
~NestedTableStoring();
|
2015-04-02 20:19:15 +11:00
|
|
|
|
2014-07-21 09:52:09 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
const NestedTableWrapperBase& getOld() const;
|
|
|
|
};
|
2015-04-02 20:19:15 +11:00
|
|
|
|
2014-07-21 09:52:09 +02:00
|
|
|
class DeleteNestedCommand : public QUndoCommand, private NestedTableStoring
|
2014-06-24 12:35:26 +02:00
|
|
|
{
|
2015-04-02 20:19:15 +11:00
|
|
|
IdTree& mModel;
|
2014-06-24 12:35:26 +02:00
|
|
|
|
|
|
|
std::string mId;
|
|
|
|
|
|
|
|
int mParentColumn;
|
|
|
|
|
|
|
|
int mNestedRow;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-04-02 20:19:15 +11:00
|
|
|
DeleteNestedCommand (IdTree& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
2014-06-24 12:35:26 +02:00
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2015-04-02 20:19:15 +11:00
|
|
|
|
2014-07-21 09:52:09 +02:00
|
|
|
class AddNestedCommand : public QUndoCommand, private NestedTableStoring
|
2014-06-24 19:19:40 +02:00
|
|
|
{
|
2015-04-02 20:19:15 +11:00
|
|
|
IdTree& mModel;
|
2014-06-24 19:19:40 +02:00
|
|
|
|
|
|
|
std::string mId;
|
|
|
|
|
|
|
|
int mNewRow;
|
|
|
|
|
|
|
|
int mParentColumn;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-04-02 20:19:15 +11:00
|
|
|
AddNestedCommand(IdTree& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
|
2014-06-24 19:19:40 +02:00
|
|
|
|
|
|
|
virtual void redo();
|
|
|
|
|
|
|
|
virtual void undo();
|
|
|
|
};
|
2012-11-29 16:05:28 +01:00
|
|
|
}
|
|
|
|
|
2014-06-24 12:35:26 +02:00
|
|
|
#endif
|