commit
9faf7f245a
2 changed files with 14 additions and 7 deletions
4
map.cpp
4
map.cpp
|
@ -618,7 +618,7 @@ void Map::_floodFillCollisionElevation(int x, int y, uint collision, uint elevat
|
||||||
|
|
||||||
void Map::undo() {
|
void Map::undo() {
|
||||||
if (blockdata) {
|
if (blockdata) {
|
||||||
Blockdata *commit = history.pop();
|
Blockdata *commit = history.back();
|
||||||
if (commit != NULL) {
|
if (commit != NULL) {
|
||||||
blockdata->copyFrom(commit);
|
blockdata->copyFrom(commit);
|
||||||
emit mapChanged(this);
|
emit mapChanged(this);
|
||||||
|
@ -638,7 +638,7 @@ void Map::redo() {
|
||||||
|
|
||||||
void Map::commit() {
|
void Map::commit() {
|
||||||
if (blockdata) {
|
if (blockdata) {
|
||||||
if (!blockdata->equals(history.history.at(history.head))) {
|
if (!blockdata->equals(history.current())) {
|
||||||
Blockdata* commit = blockdata->copy();
|
Blockdata* commit = blockdata->copy();
|
||||||
history.push(commit);
|
history.push(commit);
|
||||||
emit mapChanged(this);
|
emit mapChanged(this);
|
||||||
|
|
17
map.h
17
map.h
|
@ -13,14 +13,10 @@
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class History {
|
class History {
|
||||||
public:
|
public:
|
||||||
QList<T> history;
|
|
||||||
int head = -1;
|
|
||||||
int saved = -1;
|
|
||||||
|
|
||||||
History() {
|
History() {
|
||||||
|
|
||||||
}
|
}
|
||||||
T pop() {
|
T back() {
|
||||||
if (head > 0) {
|
if (head > 0) {
|
||||||
return history.at(--head);
|
return history.at(--head);
|
||||||
}
|
}
|
||||||
|
@ -42,12 +38,23 @@ public:
|
||||||
history.append(commit);
|
history.append(commit);
|
||||||
head++;
|
head++;
|
||||||
}
|
}
|
||||||
|
T current() {
|
||||||
|
if (head < 0 || history.length() == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return history.at(head);
|
||||||
|
}
|
||||||
void save() {
|
void save() {
|
||||||
saved = head;
|
saved = head;
|
||||||
}
|
}
|
||||||
bool isSaved() {
|
bool isSaved() {
|
||||||
return saved == head;
|
return saved == head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<T> history;
|
||||||
|
int head = -1;
|
||||||
|
int saved = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Connection {
|
class Connection {
|
||||||
|
|
Loading…
Reference in a new issue