1 /*
2 * addremovewangset.cpp
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 #include "addremovewangset.h"
22
23 #include "wangset.h"
24 #include "tileset.h"
25 #include "tilesetdocument.h"
26 #include "tilesetwangsetmodel.h"
27
28 #include <QCoreApplication>
29
30 using namespace Tiled;
31
AddRemoveWangSet(TilesetDocument * tilesetDocument,int index,WangSet * wangSet)32 AddRemoveWangSet::AddRemoveWangSet(TilesetDocument *tilesetDocument,
33 int index,
34 WangSet *wangSet)
35 : mTilesetDocument(tilesetDocument)
36 , mIndex(index)
37 , mWangSet(wangSet)
38 {
39 }
40
~AddRemoveWangSet()41 AddRemoveWangSet::~AddRemoveWangSet()
42 {
43 }
44
removeWangSet()45 void AddRemoveWangSet::removeWangSet()
46 {
47 Q_ASSERT(!mWangSet);
48 mWangSet = mTilesetDocument->wangSetModel()->takeWangSetAt(mIndex);
49 }
50
addWangSet()51 void AddRemoveWangSet::addWangSet()
52 {
53 Q_ASSERT(mWangSet);
54 mTilesetDocument->wangSetModel()->insertWangSet(mIndex, std::move(mWangSet));
55 }
56
AddWangSet(TilesetDocument * tilesetDocument,WangSet * wangSet)57 AddWangSet::AddWangSet(TilesetDocument *tilesetDocument, WangSet *wangSet)
58 : AddRemoveWangSet(tilesetDocument,
59 wangSet->tileset()->wangSetCount(),
60 wangSet)
61 {
62 setText(QCoreApplication::translate("Undo Commands", "Add Terrain Set"));
63 }
64
RemoveWangSet(TilesetDocument * tilesetDocument,WangSet * wangset)65 RemoveWangSet::RemoveWangSet(TilesetDocument *tilesetDocument, WangSet *wangset)
66 : AddRemoveWangSet(tilesetDocument,
67 tilesetDocument->wangSetModel()->index(wangset).row(),
68 nullptr)
69 {
70 setText(QCoreApplication::translate("Undo Commands", "Remove Terrain Set"));
71 }
72