forked from mapeditor/tiled
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow creating empty tilesets and adding images later
Sponsored-by: Jamie Rocks
- Loading branch information
Showing
13 changed files
with
494 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* addremovetiles.cpp | ||
* Copyright 2013, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | ||
* | ||
* This file is part of Tiled. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "addremovetiles.h" | ||
|
||
#include "mapdocument.h" | ||
#include "tile.h" | ||
#include "tileset.h" | ||
|
||
#include <QCoreApplication> | ||
|
||
namespace Tiled { | ||
namespace Internal { | ||
|
||
AddRemoveTiles::AddRemoveTiles(MapDocument *mapDocument, | ||
Tileset *tileset, | ||
int index, | ||
int count, | ||
const QList<Tile *> &tiles) | ||
: mMapDocument(mapDocument) | ||
, mTileset(tileset) | ||
, mIndex(index) | ||
, mCount(count) | ||
, mTiles(tiles) | ||
{ | ||
} | ||
|
||
AddRemoveTiles::~AddRemoveTiles() | ||
{ | ||
qDeleteAll(mTiles); | ||
} | ||
|
||
void AddRemoveTiles::addTiles() | ||
{ | ||
mTileset->insertTiles(mIndex, mTiles); | ||
mTiles.clear(); | ||
mMapDocument->emitTilesetChanged(mTileset); | ||
} | ||
|
||
void AddRemoveTiles::removeTiles() | ||
{ | ||
mTiles = mTileset->tiles().mid(mIndex, mCount); | ||
mTileset->removeTiles(mIndex, mCount); | ||
mMapDocument->emitTilesetChanged(mTileset); | ||
} | ||
|
||
|
||
AddTiles::AddTiles(MapDocument *mapDocument, | ||
Tileset *tileset, | ||
const QList<Tile *> &tiles) | ||
: AddRemoveTiles(mapDocument, | ||
tileset, | ||
tileset->tileCount(), | ||
tiles.count(), | ||
tiles) | ||
{ | ||
setText(QCoreApplication::translate("Undo Commands", "Add Tiles")); | ||
} | ||
|
||
|
||
RemoveTiles::RemoveTiles(MapDocument *mapDocument, | ||
Tileset *tileset, | ||
int index, | ||
int count) | ||
: AddRemoveTiles(mapDocument, tileset, index, count) | ||
{ | ||
setText(QCoreApplication::translate("Undo Commands", "Remove Tiles")); | ||
} | ||
|
||
} // namespace Internal | ||
} // namespace Tiled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* addremovetiles.h | ||
* Copyright 2013, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | ||
* | ||
* This file is part of Tiled. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef ADDREMOVETILES_H | ||
#define ADDREMOVETILES_H | ||
|
||
#include <QUndoCommand> | ||
|
||
namespace Tiled { | ||
|
||
class Tile; | ||
class Tileset; | ||
|
||
namespace Internal { | ||
|
||
class MapDocument; | ||
|
||
/** | ||
* Abstract base class for AddTiles and RemoveTiles. | ||
*/ | ||
class AddRemoveTiles : public QUndoCommand | ||
{ | ||
public: | ||
AddRemoveTiles(MapDocument *mapDocument, | ||
Tileset *tileset, | ||
int index, | ||
int count, | ||
const QList<Tile*> &tiles = QList<Tile*>()); | ||
|
||
~AddRemoveTiles(); | ||
|
||
protected: | ||
void addTiles(); | ||
void removeTiles(); | ||
|
||
private: | ||
MapDocument *mMapDocument; | ||
Tileset *mTileset; | ||
int mIndex; | ||
int mCount; | ||
QList<Tile*> mTiles; | ||
}; | ||
|
||
/** | ||
* Undo command that adds tiles to a tileset. | ||
*/ | ||
class AddTiles : public AddRemoveTiles | ||
{ | ||
public: | ||
AddTiles(MapDocument *mapDocument, | ||
Tileset *tileset, | ||
const QList<Tile*> &tiles); | ||
|
||
void undo() | ||
{ removeTiles(); } | ||
|
||
void redo() | ||
{ addTiles(); } | ||
}; | ||
|
||
/** | ||
* Undo command that removes tiles from a tileset. | ||
*/ | ||
class RemoveTiles : public AddRemoveTiles | ||
{ | ||
public: | ||
RemoveTiles(MapDocument *mapDocument, | ||
Tileset *tileset, | ||
int index, | ||
int count); | ||
|
||
void undo() | ||
{ addTiles(); } | ||
|
||
void redo() | ||
{ removeTiles(); } | ||
}; | ||
|
||
} // namespace Internal | ||
} // namespace Tiled | ||
|
||
#endif // TILED_INTERNAL_ADDREMOVETILES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.