From 5e4cc9a18284a98a76592ba57e9760fe75183206 Mon Sep 17 00:00:00 2001 From: garakmon Date: Tue, 4 Aug 2020 00:32:50 -0400 Subject: [PATCH] do not add no-ops to edit history for map painting --- src/ui/bordermetatilespixmapitem.cpp | 7 ++- src/ui/collisionpixmapitem.cpp | 21 +++++++-- src/ui/mappixmapitem.cpp | 68 ++++++++++++++++++++++------ 3 files changed, 77 insertions(+), 19 deletions(-) diff --git a/src/ui/bordermetatilespixmapitem.cpp b/src/ui/bordermetatilespixmapitem.cpp index 6a79bbd0..c741bb53 100644 --- a/src/ui/bordermetatilespixmapitem.cpp +++ b/src/ui/bordermetatilespixmapitem.cpp @@ -23,7 +23,12 @@ void BorderMetatilesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) } Blockdata *newBorder = map->layout->border->copy(); - map->editHistory.push(new PaintBorder(map, oldBorder, newBorder, 0)); + if (newBorder->equals(oldBorder)) { + delete newBorder; + delete oldBorder; + } else { + map->editHistory.push(new PaintBorder(map, oldBorder, newBorder, 0)); + } emit borderMetatilesChanged(); } diff --git a/src/ui/collisionpixmapitem.cpp b/src/ui/collisionpixmapitem.cpp index d0652d33..565297fd 100644 --- a/src/ui/collisionpixmapitem.cpp +++ b/src/ui/collisionpixmapitem.cpp @@ -49,7 +49,12 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) { } Blockdata *newCollision = map->layout->blockdata->copy(); - map->editHistory.push(new PaintCollision(map, oldCollision, newCollision, actionId_)); + if (newCollision->equals(oldCollision)) { + delete newCollision; + delete oldCollision; + } else { + map->editHistory.push(new PaintCollision(map, oldCollision, newCollision, actionId_)); + } } } @@ -67,7 +72,12 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) { map->floodFillCollisionElevation(x, y, collision, elevation); Blockdata *newCollision = map->layout->blockdata->copy(); - map->editHistory.push(new BucketFillCollision(map, oldCollision, newCollision)); + if (newCollision->equals(oldCollision)) { + delete newCollision; + delete oldCollision; + } else { + map->editHistory.push(new BucketFillCollision(map, oldCollision, newCollision)); + } } } @@ -84,7 +94,12 @@ void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) { map->magicFillCollisionElevation(x, y, collision, elevation); Blockdata *newCollision = map->layout->blockdata->copy(); - map->editHistory.push(new MagicFillCollision(map, oldCollision, newCollision)); + if (newCollision->equals(oldCollision)) { + delete newCollision; + delete oldCollision; + } else { + map->editHistory.push(new MagicFillCollision(map, oldCollision, newCollision)); + } } } diff --git a/src/ui/mappixmapitem.cpp b/src/ui/mappixmapitem.cpp index da206423..7ab81e0d 100644 --- a/src/ui/mappixmapitem.cpp +++ b/src/ui/mappixmapitem.cpp @@ -71,7 +71,13 @@ void MapPixmapItem::shift(int xDelta, int yDelta, bool fromScriptCall) { } if (!fromScriptCall) { - map->editHistory.push(new ShiftMetatiles(map, backupBlockdata, map->layout->blockdata->copy(), actionId_)); + Blockdata *newMetatiles = map->layout->blockdata->copy(); + if (newMetatiles->equals(backupBlockdata)) { + delete newMetatiles; + delete backupBlockdata; + } else { + map->editHistory.push(new ShiftMetatiles(map, backupBlockdata, newMetatiles, actionId_)); + } } else { delete backupBlockdata; } @@ -95,7 +101,7 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) { y = initialY + (yDiff / selectionDimensions.y()) * selectionDimensions.y(); // for edit history - Blockdata *oldMetatiles; + Blockdata *oldMetatiles = nullptr; if (!fromScriptCall) oldMetatiles = map->layout->blockdata->copy(); for (int i = 0; i < selectionDimensions.x() && i + x < map->getWidth(); i++) @@ -115,7 +121,13 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) { } if (!fromScriptCall) { - map->editHistory.push(new PaintMetatile(map, oldMetatiles, map->layout->blockdata->copy(), actionId_)); + Blockdata *newMetatiles = map->layout->blockdata->copy(); + if (newMetatiles->equals(oldMetatiles)) { + delete newMetatiles; + delete oldMetatiles; + } else { + map->editHistory.push(new PaintMetatile(map, oldMetatiles, newMetatiles, actionId_)); + } } } @@ -163,7 +175,8 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) { } // for edit history - Blockdata *oldMetatiles = map->layout->blockdata->copy(); + Blockdata *oldMetatiles = nullptr; + if (!fromScriptCall) oldMetatiles = map->layout->blockdata->copy(); // Fill the region with the open tile. for (int i = 0; i <= 1; i++) @@ -227,9 +240,15 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) { map->setBlock(actualX, actualY, *block, !fromScriptCall); } - Blockdata *newMetatiles = map->layout->blockdata->copy(); - PaintMetatile *paintEvent = new PaintMetatile(map, oldMetatiles, newMetatiles, actionId_); - map->editHistory.push(paintEvent); + if (!fromScriptCall) { + Blockdata *newMetatiles = map->layout->blockdata->copy(); + if (newMetatiles->equals(oldMetatiles)) { + delete newMetatiles; + delete oldMetatiles; + } else { + map->editHistory.push(new PaintMetatile(map, oldMetatiles, newMetatiles, actionId_)); + } + } } void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) { @@ -342,7 +361,7 @@ void MapPixmapItem::magicFill( return; } - Blockdata *oldMetatiles; + Blockdata *oldMetatiles = nullptr; if (!fromScriptCall) oldMetatiles = map->layout->blockdata->copy(); bool setCollisions = selectedCollisions && selectedCollisions->length() == selectedMetatiles->length(); @@ -369,7 +388,13 @@ void MapPixmapItem::magicFill( } if (!fromScriptCall) { - map->editHistory.push(new MagicFillMetatile(map, oldMetatiles, map->layout->blockdata->copy(), actionId_)); + Blockdata *newMetatiles = map->layout->blockdata->copy(); + if (newMetatiles->equals(oldMetatiles)) { + delete newMetatiles; + delete oldMetatiles; + } else { + map->editHistory.push(new MagicFillMetatile(map, oldMetatiles, newMetatiles, actionId_)); + } } } } @@ -401,7 +426,7 @@ void MapPixmapItem::floodFill( for (int i = 0; i < numMetatiles; i++) visited[i] = false; - Blockdata *oldMetatiles; + Blockdata *oldMetatiles = nullptr; if (!fromScriptCall) oldMetatiles = map->layout->blockdata->copy(); QList todo; @@ -453,7 +478,13 @@ void MapPixmapItem::floodFill( } if (!fromScriptCall) { - map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, map->layout->blockdata->copy(), actionId_)); + Blockdata *newMetatiles = map->layout->blockdata->copy(); + if (newMetatiles->equals(oldMetatiles)) { + delete newMetatiles; + delete oldMetatiles; + } else { + map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, newMetatiles, actionId_)); + } } delete[] visited; @@ -478,7 +509,8 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri setCollisions = true; } - Blockdata *oldMetatiles = map->layout->blockdata->copy(); + Blockdata *oldMetatiles = nullptr; + if (!fromScriptCall) oldMetatiles = map->layout->blockdata->copy(); // Flood fill the region with the open tile. QList todo; @@ -579,9 +611,15 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri } } - Blockdata *newMetatiles = map->layout->blockdata->copy(); - BucketFillMetatile *paintEvent = new BucketFillMetatile(map, oldMetatiles, newMetatiles, actionId_); - map->editHistory.push(paintEvent); + if (!fromScriptCall) { + Blockdata *newMetatiles = map->layout->blockdata->copy(); + if (newMetatiles->equals(oldMetatiles)) { + delete newMetatiles; + delete oldMetatiles; + } else { + map->editHistory.push(new BucketFillMetatile(map, oldMetatiles, newMetatiles, actionId_)); + } + } delete[] visited; }