1 /* 2 * changetilewangid.h 3 * Copyright 2017, Benjamin Trotter <bdtrotte@ucsc.edu> 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 "wangset.h" 24 #include "undocommands.h" 25 26 #include <QUndoCommand> 27 28 namespace Tiled { 29 30 class TilesetDocument; 31 32 class ChangeTileWangId : public QUndoCommand 33 { 34 public: 35 struct WangIdChange { WangIdChangeWangIdChange36 WangIdChange(WangId from, WangId to, int tileId) 37 : from(from) 38 , to(to) 39 , tileId(tileId) 40 {} 41 WangIdChangeWangIdChange42 WangIdChange() 43 {} 44 45 WangId from; 46 WangId to; 47 int tileId = 0; 48 }; 49 50 ChangeTileWangId(); 51 52 ChangeTileWangId(TilesetDocument *tilesetDocument, 53 WangSet *wangSet, 54 Tile *tile, 55 WangId wangId); 56 57 ChangeTileWangId(TilesetDocument *tilesetDocument, 58 WangSet *wangSet, 59 const QVector<WangIdChange> &changes, 60 QUndoCommand *parent = nullptr); 61 62 void undo() override; 63 void redo() override; id()64 int id() const override { return Cmd_ChangeTileWangId; } 65 bool mergeWith(const QUndoCommand *other) override; 66 67 static QVector<WangIdChange> changesOnSetColorCount(const WangSet *wangSet, 68 int colorCount); 69 70 static QVector<WangIdChange> changesOnRemoveColor(const WangSet *wangSet, 71 int removedColor); 72 73 static void applyChanges(WangSet *wangSet, const QVector<WangIdChange> &changes); 74 75 private: 76 Tile *findTile(int tileId) const; 77 78 TilesetDocument *mTilesetDocument; 79 WangSet *mWangSet; 80 QVector<WangIdChange> mChanges; 81 bool mMergeable; 82 }; 83 84 } // namespace Tiled 85