3
* Copyright 2008-2010, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
4
* Copyright 2009, Jeff Bland <jeff@teamphobic.com>
6
* This file is part of Tiled.
8
* This program is free software; you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License as published by the Free
10
* Software Foundation; either version 2 of the License, or (at your option)
13
* This program is distributed in the hope that it will be useful, but WITHOUT
14
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18
* You should have received a copy of the GNU General Public License along with
19
* this program. If not, see <http://www.gnu.org/licenses/>.
44
class TileSelectionModel;
47
* Represents an editable map. The purpose of this class is to make sure that
48
* any editing operations will cause the appropriate signals to be emitted, in
49
* order to allow the GUI to update accordingly.
51
* At the moment the map document provides the layer model, keeps track of the
52
* the currently selected layer and provides an API for adding and removing
53
* map objects. It also owns the QUndoStack.
55
class MapDocument : public QObject
61
* Constructs a map document around the given map. The map document takes
62
* ownership of the map.
64
MapDocument(Map *map, const QString &fileName = QString());
71
QString fileName() const { return mFileName; }
73
void setFileName(const QString &fileName) { mFileName = fileName; }
76
* Returns the map instance. Be aware that directly modifying the map will
77
* not allow the GUI to update itself appropriately.
79
Map *map() const { return mMap; }
82
* Sets the current layer to the given index.
84
void setCurrentLayer(int index);
87
* Returns the index of the currently selected layer. Returns -1 if no
88
* layer is currently selected.
90
int currentLayer() const;
93
* Resize this map to the given \a size, while at the same time shifting
94
* the contents by \a offset.
96
void resizeMap(const QSize &size, const QPoint &offset);
99
* Offsets the layers at \a layerIndexes by \a offset, within \a bounds,
100
* and optionally wraps on the X or Y axis.
102
void offsetMap(const QList<int> &layerIndexes,
103
const QPoint &offset,
105
bool wrapX, bool wrapY);
111
void addLayer(LayerType layerType);
112
void duplicateLayer();
113
void moveLayerUp(int index);
114
void moveLayerDown(int index);
115
void removeLayer(int index);
117
void insertTileset(int index, Tileset *tileset);
118
void removeTilesetAt(int index);
119
void moveTileset(int from, int to);
122
* Returns the layer model. Can be used to modify the layer stack of the
123
* map, and to display the layer stack in a view.
125
LayerModel *layerModel() const { return mLayerModel; }
128
* Returns the map renderer.
130
MapRenderer *renderer() const { return mRenderer; }
133
* Returns the undo stack of this map document. Should be used to push any
134
* commands on that modify the map.
136
QUndoStack *undoStack() const { return mUndoStack; }
139
* Returns the selected area of tiles.
141
const QRegion &tileSelection() const { return mTileSelection; }
144
* Sets the selected area of tiles.
146
void setTileSelection(const QRegion &selection);
148
void emitMapChanged();
151
* Emits the region changed signal for the specified region. The region
152
* should be in tile coordinates. This method is used by the TilePainter.
154
void emitRegionChanged(const QRegion ®ion);
156
void emitObjectsAdded(const QList<MapObject*> &objects);
157
void emitObjectsRemoved(const QList<MapObject*> &objects);
158
void emitObjectsChanged(const QList<MapObject*> &objects);
160
inline void emitObjectAdded(MapObject *object)
161
{ emitObjectsAdded(QList<MapObject*>() << object); }
163
inline void emitObjectRemoved(MapObject *object)
164
{ emitObjectsRemoved(QList<MapObject*>() << object); }
166
inline void emitObjectChanged(MapObject *object)
167
{ emitObjectsChanged(QList<MapObject*>() << object); }
171
* Emitted when the selected tile region changes. Sends the currently
172
* selected region and the previously selected region.
174
void tileSelectionChanged(const QRegion &newSelection,
175
const QRegion &oldSelection);
178
* Emitted when the map size or its tile size changes.
182
void layerAdded(int index);
183
void layerRemoved(int index);
184
void layerChanged(int index);
187
* Emitted after a new layer was added and the name should be edited.
188
* Applies to the current layer.
190
void editLayerNameRequested();
193
* Emitted when the current layer changes.
195
void currentLayerChanged(int index);
198
* Emitted when a certain region of the map changes. The region is given in
201
void regionChanged(const QRegion ®ion);
203
void tilesetAdded(int index, Tileset *tileset);
204
void tilesetRemoved(Tileset *tileset);
205
void tilesetMoved(int from, int to);
207
void objectsAdded(const QList<MapObject*> &objects);
208
void objectsRemoved(const QList<MapObject*> &objects);
209
void objectsChanged(const QList<MapObject*> &objects);
212
void onLayerAdded(int index);
213
void onLayerRemoved(int index);
218
LayerModel *mLayerModel;
219
QRegion mTileSelection;
220
MapRenderer *mRenderer;
222
QUndoStack *mUndoStack;
225
} // namespace Internal
228
#endif // MAPDOCUMENT_H