1 /*
2  * changewangcolordata.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 #include "changewangcolordata.h"
22 
23 #include "wangcolormodel.h"
24 #include "tilesetdocument.h"
25 
26 #include <QCoreApplication>
27 
28 using namespace Tiled;
29 
ChangeWangColorName(TilesetDocument * tilesetDocument,WangColor * wangColor,const QString & newName)30 ChangeWangColorName::ChangeWangColorName(TilesetDocument *tilesetDocument,
31                                          WangColor *wangColor,
32                                          const QString &newName)
33     : mTilesetDocument(tilesetDocument)
34     , mWangColor(wangColor)
35     , mOldName(wangColor->name())
36     , mNewName(newName)
37 {
38     setText(QCoreApplication::translate("Undo Commands", "Change Terrain Name"));
39 }
40 
undo()41 void ChangeWangColorName::undo()
42 {
43     auto wangColorModel = mTilesetDocument->wangColorModel(mWangColor->wangSet());
44     wangColorModel->setName(mWangColor, mOldName);
45 }
46 
redo()47 void ChangeWangColorName::redo()
48 {
49     auto wangColorModel = mTilesetDocument->wangColorModel(mWangColor->wangSet());
50     wangColorModel->setName(mWangColor, mNewName);
51 }
52 
53 
ChangeWangColorImage(TilesetDocument * tilesetDocument,WangColor * wangColor,int newImageId,QUndoCommand * parent)54 ChangeWangColorImage::ChangeWangColorImage(TilesetDocument *tilesetDocument,
55                                            WangColor *wangColor,
56                                            int newImageId,
57                                            QUndoCommand *parent)
58     : QUndoCommand(parent)
59     , mTilesetDocument(tilesetDocument)
60     , mWangColor(wangColor)
61     , mOldImageId(wangColor->imageId())
62     , mNewImageId(newImageId)
63 {
64     setText(QCoreApplication::translate("Undo Commands", "Change Terrain Image"));
65 }
66 
undo()67 void ChangeWangColorImage::undo()
68 {
69     auto wangColorModel = mTilesetDocument->wangColorModel(mWangColor->wangSet());
70     wangColorModel->setImage(mWangColor, mOldImageId);
71 }
72 
redo()73 void ChangeWangColorImage::redo()
74 {
75     auto wangColorModel = mTilesetDocument->wangColorModel(mWangColor->wangSet());
76     wangColorModel->setImage(mWangColor, mNewImageId);
77 }
78 
79 
ChangeWangColorColor(TilesetDocument * tilesetDocument,WangColor * wangColor,const QColor & newColor)80 ChangeWangColorColor::ChangeWangColorColor(TilesetDocument *tilesetDocument,
81                                            WangColor *wangColor,
82                                            const QColor &newColor)
83     : mTilesetDocument(tilesetDocument)
84     , mWangColor(wangColor)
85     , mOldColor(wangColor->color())
86     , mNewColor(newColor)
87 {
88     setText(QCoreApplication::translate("Undo Commands", "Change Terrain Color"));
89 }
90 
undo()91 void ChangeWangColorColor::undo()
92 {
93     auto wangColorModel = mTilesetDocument->wangColorModel(mWangColor->wangSet());
94     wangColorModel->setColor(mWangColor, mOldColor);
95 }
96 
redo()97 void ChangeWangColorColor::redo()
98 {
99     auto wangColorModel = mTilesetDocument->wangColorModel(mWangColor->wangSet());
100     wangColorModel->setColor(mWangColor, mNewColor);
101 }
102 
103 
ChangeWangColorProbability(TilesetDocument * tilesetDocument,WangColor * wangColor,qreal newProbability)104 ChangeWangColorProbability::ChangeWangColorProbability(TilesetDocument *tilesetDocument,
105                                                        WangColor *wangColor,
106                                                        qreal newProbability)
107     : mTilesetDocument(tilesetDocument)
108     , mWangColor(wangColor)
109     , mOldProbability(wangColor->probability())
110     , mNewProbability(newProbability)
111 {
112     setText(QCoreApplication::translate("Undo Commands", "Change Terrain Probability"));
113 }
114 
undo()115 void ChangeWangColorProbability::undo()
116 {
117     auto wangColorModel = mTilesetDocument->wangColorModel(mWangColor->wangSet());
118     wangColorModel->setProbability(mWangColor, mOldProbability);
119 }
120 
redo()121 void ChangeWangColorProbability::redo()
122 {
123     auto wangColorModel = mTilesetDocument->wangColorModel(mWangColor->wangSet());
124     wangColorModel->setProbability(mWangColor, mNewProbability);
125 }
126