Move History and HistoryItem to core/
This commit is contained in:
parent
262c79776e
commit
24e79eb94e
8 changed files with 98 additions and 65 deletions
4
core/history.cpp
Normal file
4
core/history.cpp
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#include "history.h"
|
||||||
|
#include "historyitem.h"
|
||||||
|
|
||||||
|
|
58
core/history.h
Normal file
58
core/history.h
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#ifndef HISTORY_H
|
||||||
|
#define HISTORY_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
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<T> history;
|
||||||
|
int head = -1;
|
||||||
|
int saved = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // HISTORY_H
|
11
core/historyitem.cpp
Normal file
11
core/historyitem.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
15
core/historyitem.h
Normal file
15
core/historyitem.h
Normal file
|
@ -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
|
2
map.cpp
2
map.cpp
|
@ -1,3 +1,5 @@
|
||||||
|
#include "core/history.h"
|
||||||
|
#include "core/historyitem.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
|
||||||
|
|
68
map.h
68
map.h
|
@ -1,9 +1,11 @@
|
||||||
#ifndef MAP_H
|
#ifndef MAP_H
|
||||||
#define MAP_H
|
#define MAP_H
|
||||||
|
|
||||||
#include "core/tileset.h"
|
|
||||||
#include "core/blockdata.h"
|
#include "core/blockdata.h"
|
||||||
|
#include "core/history.h"
|
||||||
|
#include "core/historyitem.h"
|
||||||
#include "core/maplayout.h"
|
#include "core/maplayout.h"
|
||||||
|
#include "core/tileset.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
@ -12,70 +14,6 @@
|
||||||
#include <QGraphicsPixmapItem>
|
#include <QGraphicsPixmapItem>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
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 <typename T>
|
|
||||||
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<T> history;
|
|
||||||
int head = -1;
|
|
||||||
int saved = -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Connection {
|
class Connection {
|
||||||
public:
|
public:
|
||||||
Connection() {
|
Connection() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ ICON = resources/icons/porymap-icon-1.ico
|
||||||
SOURCES += core/block.cpp \
|
SOURCES += core/block.cpp \
|
||||||
core/blockdata.cpp \
|
core/blockdata.cpp \
|
||||||
core/heallocation.cpp \
|
core/heallocation.cpp \
|
||||||
|
core/historyitem.cpp \
|
||||||
core/maplayout.cpp \
|
core/maplayout.cpp \
|
||||||
core/metatile.cpp \
|
core/metatile.cpp \
|
||||||
core/tile.cpp \
|
core/tile.cpp \
|
||||||
|
@ -40,6 +41,8 @@ SOURCES += core/block.cpp \
|
||||||
HEADERS += core/block.h \
|
HEADERS += core/block.h \
|
||||||
core/blockdata.h \
|
core/blockdata.h \
|
||||||
core/heallocation.h \
|
core/heallocation.h \
|
||||||
|
core/history.h \
|
||||||
|
core/historyitem.h \
|
||||||
core/maplayout.h \
|
core/maplayout.h \
|
||||||
core/metatile.h \
|
core/metatile.h \
|
||||||
core/tile.h \
|
core/tile.h \
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "parseutil.h"
|
#include "parseutil.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
#include "core/history.h"
|
||||||
|
#include "core/historyitem.h"
|
||||||
#include "core/tile.h"
|
#include "core/tile.h"
|
||||||
#include "core/tileset.h"
|
#include "core/tileset.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
Loading…
Reference in a new issue