add EventMove command, fix extra signal call in map border resize

This commit is contained in:
garakmon
2020-07-30 16:35:48 -04:00
committed by garak
parent fb1eec1755
commit a0dc347ad3
10 changed files with 290 additions and 160 deletions

View File

@@ -1,5 +1,6 @@
#include "editcommands.h"
#include "mappixmapitem.h"
#include "draggablepixmapitem.h"
#include "bordermetatilespixmapitem.h"
#include <QDebug>
@@ -247,6 +248,8 @@ void ResizeMap::redo() {
map->layout->border->copyFrom(newBorder);
map->setBorderDimensions(newBorderWidth, newBorderHeight, false);
}
map->mapNeedsRedrawing();
}
void ResizeMap::undo() {
@@ -262,7 +265,60 @@ void ResizeMap::undo() {
map->setBorderDimensions(oldBorderWidth, oldBorderHeight, false);
}
map->mapNeedsRedrawing();
QUndoCommand::undo();
}
/******************************************************************************
************************************************************************
******************************************************************************/
EventMove::EventMove(QList<Event *> events,
int deltaX, int deltaY, unsigned actionId,
QUndoCommand *parent) : QUndoCommand(parent) {
setText("Move Event");
this->events = events;
this->deltaX = deltaX;
this->deltaY = deltaY;
this->actionId = actionId;
}
EventMove::~EventMove() {}
void EventMove::redo() {
QUndoCommand::redo();
for (Event *event : events) {
event->pixmapItem->move(deltaX, deltaY);
}
}
void EventMove::undo() {
for (Event *event : events) {
event->pixmapItem->move(-deltaX, -deltaY);
}
QUndoCommand::undo();
}
bool EventMove::mergeWith(const QUndoCommand *command) {
const EventMove *other = static_cast<const EventMove *>(command);
if (actionId != other->actionId)
return false;
this->deltaX += other->deltaX;
this->deltaY += other->deltaY;
return true;
}
/******************************************************************************
************************************************************************
******************************************************************************/

View File

@@ -345,7 +345,6 @@ void Map::setDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
layout->height = QString::number(newHeight);
emit mapChanged(this);
emit mapNeedsRedrawing();
}
void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata) {
@@ -357,7 +356,6 @@ void Map::setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata)
layout->border_height = QString::number(newHeight);
emit mapChanged(this);
emit mapNeedsRedrawing();
}
Block* Map::getBlock(int x, int y) {