1 /*
2 * changetile.cpp
3 * Copyright 2017, Thorbjørn Lindeijer <bjorn@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 #include "changetile.h"
22
23 #include "tile.h"
24 #include "tilesetdocument.h"
25
26 #include <QCoreApplication>
27
28 namespace Tiled {
29
ChangeTileType(TilesetDocument * tilesetDocument,const QList<Tile * > & tiles,const QString & type)30 ChangeTileType::ChangeTileType(TilesetDocument *tilesetDocument,
31 const QList<Tile *> &tiles,
32 const QString &type)
33 : QUndoCommand(QCoreApplication::translate("Undo Commands", "Change Tile Type"))
34 , mTilesetDocument(tilesetDocument)
35 , mTiles(tiles)
36 {
37 mTypes.fill(type, tiles.size());
38 }
39
swap()40 void ChangeTileType::swap()
41 {
42 for (int i = 0, size = mTiles.size(); i < size; ++i) {
43 Tile *tile = mTiles.at(i);
44
45 QString oldType = tile->type();
46 mTilesetDocument->setTileType(tile, mTypes.at(i));
47 mTypes[i] = oldType;
48 }
49 }
50
51 } // namespace Tiled
52