Toshihiro Shimizu 890ddd
#ifndef T_UNDO_INCLUDED
Toshihiro Shimizu 890ddd
#define T_UNDO_INCLUDED
Toshihiro Shimizu 890ddd
Shinya Kitaoka 262a92
#include <memory></memory>
Shinya Kitaoka 262a92
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tsmartpointer.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qobject></qobject>
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TNZCORE_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    TUndo  class
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TUndo
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	bool m_isLastInBlock;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TUndo() {}
Toshihiro Shimizu 890ddd
	virtual ~TUndo() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual int getSize() const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void undo() const = 0;
Toshihiro Shimizu 890ddd
	virtual void redo() const = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void onAdd() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// for history viewer panel
Toshihiro Shimizu 890ddd
	virtual QString getHistoryString() { return QObject::tr("Unidentified Action"); }
Toshihiro Shimizu 890ddd
	virtual int getHistoryType() { return 0; } //HistoryType::Unidentified
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	// Noncopyable
Toshihiro Shimizu 890ddd
	TUndo(const TUndo &undo);
Toshihiro Shimizu 890ddd
	TUndo &operator=(const TUndo &undo);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    TUndoManager  class
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TUndoManager : public QObject
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TUndoManager();
Toshihiro Shimizu 890ddd
	~TUndoManager();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	static TUndoManager *manager();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void beginBlock();
Toshihiro Shimizu 890ddd
	void endBlock();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void add(TUndo *undo);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool undo();
Toshihiro Shimizu 890ddd
	bool redo();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void reset();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	/*!If forward = false remove n elements in the stack before m_imp->m_current;
Toshihiro Shimizu 890ddd
    else if forward = true remove n elements in the stack after m_imp->m_current.
Toshihiro Shimizu 890ddd
    If n = -1 remove all elements before or after m_imp->m_current.*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void popUndo(int n = -1, bool forward = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! undo() and redo() methods call TUndoManager::manager()->skip() if
Toshihiro Shimizu 890ddd
	//! they want another undo/redo performed
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void skip();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Set the size of memory used for undo redo.
Toshihiro Shimizu 890ddd
	//! \b memorySyze is expressed in MB
Toshihiro Shimizu 890ddd
	void setUndoMemorySize(int memorySyze);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// for history viewer pane
Toshihiro Shimizu 890ddd
	int getHistoryCount();
Toshihiro Shimizu 890ddd
	int getCurrentHistoryIndex();
Toshihiro Shimizu 890ddd
	TUndo *getUndoItem(int index);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Q_SIGNALS :
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		void
Toshihiro Shimizu 890ddd
		historyChanged();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void somethingChanged();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	struct TUndoManagerImp;
Shinya Kitaoka 262a92
	std::unique_ptr<tundomanagerimp> m_imp;</tundomanagerimp>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	// Noncopyable
Toshihiro Shimizu 890ddd
	TUndoManager(const TUndoManager &);
Toshihiro Shimizu 890ddd
	TUndoManager &operator=(const TUndoManager &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
//    TUndoScopedBlock  class
Toshihiro Shimizu 890ddd
//************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
struct TUndoScopedBlock {
Toshihiro Shimizu 890ddd
	TUndoScopedBlock() { TUndoManager::manager()->beginBlock(); }
Toshihiro Shimizu 890ddd
	~TUndoScopedBlock() { TUndoManager::manager()->endBlock(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	// Noncopyable
Toshihiro Shimizu 890ddd
	TUndoScopedBlock(const TUndoScopedBlock &);
Toshihiro Shimizu 890ddd
	TUndoScopedBlock &operator=(const TUndoScopedBlock &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // T_UNDO_INCLUDED