diff -r c595cfb4791c -r 31540c1f22ea src/history.h --- a/src/history.h Wed Oct 23 13:14:17 2013 +0300 +++ b/src/history.h Mon Jan 20 15:04:26 2014 +0200 @@ -1,6 +1,6 @@ /* * LDForge: LDraw parts authoring CAD - * Copyright (C) 2013 Santeri Piippo + * Copyright (C) 2013, 2014 Santeri Piippo * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,62 +16,74 @@ * along with this program. If not, see . */ -#ifndef HISTORY_H -#define HISTORY_H +#ifndef LDFORGE_HISTORY_H +#define LDFORGE_HISTORY_H -#include "common.h" +#include "main.h" #include "ldtypes.h" -#define IMPLEMENT_HISTORY_TYPE(N) \ - virtual ~N##History(); \ - virtual void undo() const override; \ - virtual void redo() const override; \ - virtual History::Type getType() const override { return History::N; } +#define IMPLEMENT_HISTORY_TYPE(N) \ + virtual ~N##History() {} \ + virtual void undo() const override; \ + virtual void redo() const override; \ + \ + virtual History::EHistoryType getType() const override \ + { \ + return History::E##N##History; \ + } \ + \ + virtual QString getTypeName() const \ + { \ + return #N; \ + } class AbstractHistoryEntry; // ============================================================================= class History -{ PROPERTY (long, pos, setPos) - PROPERTY (LDFile*, file, setFile) - READ_PROPERTY (bool, opened, setOpened) +{ + PROPERTY (private, int, Position, NUM_OPS, STOCK_WRITE) + PROPERTY (public, LDDocument*, Document, NO_OPS, STOCK_WRITE) + PROPERTY (public, bool, Ignoring, BOOL_OPS, STOCK_WRITE) public: typedef QList Changeset; - enum Type - { Del, - Edit, - Add, - Move, - Swap, + enum EHistoryType + { + EDelHistory, + EEditHistory, + EAddHistory, + EMoveHistory, + ESwapHistory, }; History(); void undo(); void redo(); void clear(); - void updateActions() const; - void open(); - void close(); + void addStep(); void add (AbstractHistoryEntry* entry); - inline long size() const - { return m_changesets.size(); + inline long getSize() const + { + return m_changesets.size(); } inline History& operator<< (AbstractHistoryEntry* entry) - { add (entry); + { + add (entry); return *this; } - inline const Changeset& changeset (long pos) const - { return m_changesets[pos]; + inline const Changeset& getChangeset (long pos) const + { + return m_changesets[pos]; } private: - Changeset m_currentArchive; + Changeset m_currentChangeset; QList m_changesets; }; @@ -79,103 +91,94 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= class AbstractHistoryEntry -{ PROPERTY (History*, parent, setParent) +{ + PROPERTY (public, History*, Parent, NO_OPS, STOCK_WRITE) public: - virtual void undo() const {} - virtual void redo() const {} virtual ~AbstractHistoryEntry() {} - virtual History::Type getType() const - { return (History::Type) 0; - } + virtual void undo() const = 0; + virtual void redo() const = 0; + virtual History::EHistoryType getType() const = 0; + virtual QString getTypeName() const = 0; }; // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= class DelHistory : public AbstractHistoryEntry -{ public: - enum Type - { Cut, // was deleted with a cut operation - Other, // was deleted witout specific reason - }; - - PROPERTY (int, index, setIndex) - PROPERTY (str, code, setCode) - PROPERTY (DelHistory::Type, type, setType) +{ + PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) + PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) public: IMPLEMENT_HISTORY_TYPE (Del) - - DelHistory (int idx, LDObject* obj, Type type = Other) : - m_index (idx), - m_code (obj->raw()), - m_type (type) {} + DelHistory (int idx, LDObject* obj); }; // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= class EditHistory : public AbstractHistoryEntry -{ PROPERTY (int, index, setIndex) - PROPERTY (str, oldCode, setOldCode) - PROPERTY (str, newCode, setNewCode) +{ + PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) + PROPERTY (private, QString, OldCode, NO_OPS, STOCK_WRITE) + PROPERTY (private, QString, NewCode, NO_OPS, STOCK_WRITE) public: IMPLEMENT_HISTORY_TYPE (Edit) - EditHistory (int idx, str oldCode, str newCode) : - m_index (idx), - m_oldCode (oldCode), - m_newCode (newCode) {} + EditHistory (int idx, QString oldCode, QString newCode) : + m_Index (idx), + m_OldCode (oldCode), + m_NewCode (newCode) {} }; // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= class AddHistory : public AbstractHistoryEntry -{ public: - enum Type - { Other, // was "just added" - Paste, // was added through a paste operation - }; - - PROPERTY (int, index, setIndex) - PROPERTY (str, code, setCode) - PROPERTY (AddHistory::Type, type, setType) +{ + PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) + PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) public: IMPLEMENT_HISTORY_TYPE (Add) - AddHistory (int idx, LDObject* obj, Type type = Other) : - m_index (idx), - m_code (obj->raw()), - m_type (type) {} + AddHistory (int idx, LDObject* obj) : + m_Index (idx), + m_Code (obj->raw()) {} }; // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= class MoveHistory : public AbstractHistoryEntry -{ public: +{ + public: IMPLEMENT_HISTORY_TYPE (Move) QList indices; - vertex dest; + Vertex dest; - MoveHistory (QList indices, vertex dest) : + MoveHistory (QList indices, Vertex dest) : indices (indices), dest (dest) {} }; +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= class SwapHistory : public AbstractHistoryEntry -{ public: +{ + public: IMPLEMENT_HISTORY_TYPE (Swap) - int a, b; SwapHistory (int a, int b) : a (a), b (b) {} + + private: + int a, b; }; -#endif // HISTORY_H +#endif // LDFORGE_HISTORY_H