1 /* 2 * erasetiles.h 3 * Copyright 2009, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> 4 * 5 * This file is part of Tiled. 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation; either version 2 of the License, or (at your option) 10 * any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15 * more details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #pragma once 22 23 #include "undocommands.h" 24 25 #include <QHash> 26 #include <QRegion> 27 #include <QUndoCommand> 28 29 namespace Tiled { 30 31 class Tile; 32 class TileLayer; 33 34 class MapDocument; 35 36 class EraseTiles : public QUndoCommand 37 { 38 public: 39 EraseTiles(MapDocument *mapDocument, 40 TileLayer *tileLayer, 41 const QRegion ®ion); 42 ~EraseTiles() override; 43 44 /** 45 * Sets whether this undo command can be merged with an existing command. 46 */ setMergeable(bool mergeable)47 void setMergeable(bool mergeable) 48 { mMergeable = mergeable; } 49 50 void undo() override; 51 void redo() override; 52 id()53 int id() const override { return Cmd_EraseTiles; } 54 bool mergeWith(const QUndoCommand *other) override; 55 56 private: 57 struct LayerData 58 { 59 void mergeWith(const LayerData &o); 60 61 TileLayer *mErasedCells = nullptr; 62 QRegion mRegion; 63 }; 64 65 MapDocument *mMapDocument; 66 QHash<TileLayer*, LayerData> mLayerData; 67 bool mMergeable; 68 }; 69 70 } // namespace Tiled 71