1 /*
2  * addremovetileset.cpp
3  * Copyright 2010, 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 #include "addremovetileset.h"
22 
23 #include "map.h"
24 #include "mapdocument.h"
25 
26 using namespace Tiled;
27 
AddRemoveTileset(MapDocument * mapDocument,int index,const SharedTileset & tileset,QUndoCommand * parent)28 AddRemoveTileset::AddRemoveTileset(MapDocument *mapDocument,
29                                    int index,
30                                    const SharedTileset &tileset,
31                                    QUndoCommand *parent)
32     : QUndoCommand(parent)
33     , mMapDocument(mapDocument)
34     , mTileset(tileset)
35     , mIndex(index)
36 {
37 }
38 
~AddRemoveTileset()39 AddRemoveTileset::~AddRemoveTileset()
40 {
41 }
42 
removeTileset()43 void AddRemoveTileset::removeTileset()
44 {
45     mMapDocument->removeTilesetAt(mIndex);
46 }
47 
addTileset()48 void AddRemoveTileset::addTileset()
49 {
50     mMapDocument->insertTileset(mIndex, mTileset);
51 }
52 
53 
AddTileset(MapDocument * mapDocument,const SharedTileset & tileset,QUndoCommand * parent)54 AddTileset::AddTileset(MapDocument *mapDocument, const SharedTileset &tileset,
55                        QUndoCommand *parent)
56     : AddRemoveTileset(mapDocument,
57                        mapDocument->map()->tilesets().size(),
58                        tileset,
59                        parent)
60 {
61     setText(QCoreApplication::translate("Undo Commands", "Add Tileset"));
62 }
63 
clone(QUndoCommand * parent) const64 AddTileset *AddTileset::clone(QUndoCommand *parent) const
65 {
66     auto c = new AddTileset(mMapDocument, mTileset, parent);
67     c->mIndex = mIndex;
68     return c;
69 }
70 
71 
RemoveTileset(MapDocument * mapDocument,int index)72 RemoveTileset::RemoveTileset(MapDocument *mapDocument, int index)
73     : AddRemoveTileset(mapDocument,
74                        index,
75                        mapDocument->map()->tilesetAt(index))
76 {
77     setText(QCoreApplication::translate("Undo Commands",
78                                         "Remove Tileset"));
79 }
80