From 24e79eb94ef3be8cc6c816d14f1eceb42a0f05a7 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Mon, 24 Sep 2018 10:48:36 -0500 Subject: [PATCH] Move History and HistoryItem to core/ --- core/history.cpp | 4 +++ core/history.h | 58 +++++++++++++++++++++++++++++++++++++ core/historyitem.cpp | 11 +++++++ core/historyitem.h | 15 ++++++++++ map.cpp | 2 ++ map.h | 68 ++------------------------------------------ porymap.pro | 3 ++ project.cpp | 2 ++ 8 files changed, 98 insertions(+), 65 deletions(-) create mode 100644 core/history.cpp create mode 100644 core/history.h create mode 100644 core/historyitem.cpp create mode 100644 core/historyitem.h diff --git a/core/history.cpp b/core/history.cpp new file mode 100644 index 00000000..0991bbd2 --- /dev/null +++ b/core/history.cpp @@ -0,0 +1,4 @@ +#include "history.h" +#include "historyitem.h" + + diff --git a/core/history.h b/core/history.h new file mode 100644 index 00000000..40576ff2 --- /dev/null +++ b/core/history.h @@ -0,0 +1,58 @@ +#ifndef HISTORY_H +#define HISTORY_H + +#include + +template +class History { +public: + History() { } + T back() { + if (head > 0) { + return history.at(--head); + } + return NULL; + } + + T next() { + if (head + 1 < history.length()) { + return history.at(++head); + } + return NULL; + } + + void push(T commit) { + while (head + 1 < history.length()) { + T item = history.last(); + history.removeLast(); + delete item; + } + if (saved > head) { + saved = -1; + } + history.append(commit); + head++; + } + + T current() { + if (head < 0 || history.length() == 0) { + return NULL; + } + return history.at(head); + } + + void save() { + saved = head; + } + + bool isSaved() { + return saved == head; + } + +private: + QList history; + int head = -1; + int saved = -1; +}; + +#endif // HISTORY_H diff --git a/core/historyitem.cpp b/core/historyitem.cpp new file mode 100644 index 00000000..ded89353 --- /dev/null +++ b/core/historyitem.cpp @@ -0,0 +1,11 @@ +#include "historyitem.h" + +HistoryItem::HistoryItem(Blockdata *metatiles, int layoutWidth, int layoutHeight) { + this->metatiles = metatiles; + this->layoutWidth = layoutWidth; + this->layoutHeight = layoutHeight; +} + +HistoryItem::~HistoryItem() { + if (this->metatiles) delete this->metatiles; +} diff --git a/core/historyitem.h b/core/historyitem.h new file mode 100644 index 00000000..d56392d2 --- /dev/null +++ b/core/historyitem.h @@ -0,0 +1,15 @@ +#ifndef HISTORYITEM_H +#define HISTORYITEM_H + +#include "blockdata.h" + +class HistoryItem { +public: + Blockdata *metatiles; + int layoutWidth; + int layoutHeight; + HistoryItem(Blockdata *metatiles, int layoutWidth, int layoutHeight); + ~HistoryItem(); +}; + +#endif // HISTORYITEM_H diff --git a/map.cpp b/map.cpp index c66feb34..6b4be6ae 100755 --- a/map.cpp +++ b/map.cpp @@ -1,3 +1,5 @@ +#include "core/history.h" +#include "core/historyitem.h" #include "map.h" #include "project.h" diff --git a/map.h b/map.h index 992af76d..0363c0c3 100755 --- a/map.h +++ b/map.h @@ -1,9 +1,11 @@ #ifndef MAP_H #define MAP_H -#include "core/tileset.h" #include "core/blockdata.h" +#include "core/history.h" +#include "core/historyitem.h" #include "core/maplayout.h" +#include "core/tileset.h" #include "event.h" #include @@ -12,70 +14,6 @@ #include #include -class HistoryItem { -public: - Blockdata *metatiles; - int layoutWidth; - int layoutHeight; - HistoryItem(Blockdata *metatiles_, int layoutWidth_, int layoutHeight_) { - this->metatiles = metatiles_; - this->layoutWidth = layoutWidth_; - this->layoutHeight = layoutHeight_; - } - ~HistoryItem() { - if (metatiles) delete metatiles; - } -}; - -template -class History { -public: - History() { - - } - T back() { - if (head > 0) { - return history.at(--head); - } - return NULL; - } - T next() { - if (head + 1 < history.length()) { - return history.at(++head); - } - return NULL; - } - void push(T commit) { - while (head + 1 < history.length()) { - HistoryItem *item = history.last(); - history.removeLast(); - delete item; - } - if (saved > head) { - saved = -1; - } - history.append(commit); - head++; - } - T current() { - if (head < 0 || history.length() == 0) { - return NULL; - } - return history.at(head); - } - void save() { - saved = head; - } - bool isSaved() { - return saved == head; - } - -private: - QList history; - int head = -1; - int saved = -1; -}; - class Connection { public: Connection() { diff --git a/porymap.pro b/porymap.pro index 2cf96b86..a213ab6c 100755 --- a/porymap.pro +++ b/porymap.pro @@ -17,6 +17,7 @@ ICON = resources/icons/porymap-icon-1.ico SOURCES += core/block.cpp \ core/blockdata.cpp \ core/heallocation.cpp \ + core/historyitem.cpp \ core/maplayout.cpp \ core/metatile.cpp \ core/tile.cpp \ @@ -40,6 +41,8 @@ SOURCES += core/block.cpp \ HEADERS += core/block.h \ core/blockdata.h \ core/heallocation.h \ + core/history.h \ + core/historyitem.h \ core/maplayout.h \ core/metatile.h \ core/tile.h \ diff --git a/project.cpp b/project.cpp index c68bdc5e..6564e76d 100755 --- a/project.cpp +++ b/project.cpp @@ -1,5 +1,7 @@ #include "parseutil.h" #include "project.h" +#include "core/history.h" +#include "core/historyitem.h" #include "core/tile.h" #include "core/tileset.h" #include "event.h"