/
documentmanager.h
269 lines (211 loc) · 6.96 KB
/
documentmanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
* documentmanager.h
* Copyright 2010, Stefan Beller <stefanbeller@googlemail.com>
* Copyright 2010, 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 DOCUMENT_MANAGER_H
#define DOCUMENT_MANAGER_H
#include "document.h"
#include "tileset.h"
#include <QList>
#include <QObject>
#include <QPair>
#include <QPointF>
class QTabWidget;
class QUndoGroup;
class QStackedLayout;
class QTabBar;
namespace Tiled {
class FileSystemWatcher;
namespace Internal {
class AbstractTool;
class Document;
class Editor;
class MapDocument;
class MapEditor;
class MapScene;
class MapView;
class TilesetDocument;
/**
* This class controls the open documents.
*/
class DocumentManager : public QObject
{
Q_OBJECT
public:
static DocumentManager *instance();
static void deleteInstance();
/**
* Returns the document manager widget. It contains the different map views
* and a tab bar to switch between them.
*/
QWidget *widget() const;
void setEditor(Document::DocumentType documentType, Editor *editor);
Editor *editor(Document::DocumentType documentType) const;
void deleteEditor(Document::DocumentType documentType);
Editor *currentEditor() const;
void saveState();
void restoreState();
/**
* Returns the undo group that combines the undo stacks of all opened map
* documents.
*
* @see Document::undoStack()
*/
QUndoGroup *undoGroup() const { return mUndoGroup; }
/**
* Returns the current map document, or 0 when there is none.
*/
Document *currentDocument() const;
/**
* Returns the map view of the current document, or 0 when there is none.
*/
MapView *currentMapView() const;
/**
* Returns the map scene of the current document, or 0 when there is none.
*/
MapScene *currentMapScene() const;
MapView *viewForDocument(MapDocument *mapDocument) const;
/**
* Returns the number of map documents.
*/
int documentCount() const { return mDocuments.size(); }
/**
* Searches for a document with the given \a fileName and returns its
* index. Returns -1 when the document isn't open.
*/
int findDocument(const QString &fileName) const;
/**
* Switches to the map document at the given \a index.
*/
void switchToDocument(int index);
bool switchToDocument(Document *document);
/**
* Adds the new or opened \a document to the document manager.
*/
void addDocument(Document *document);
bool isDocumentModified(Document *document) const;
/**
* Closes the current map document. Will not ask the user whether to save
* any changes!
*/
void closeCurrentDocument();
/**
* Closes the document at the given \a index. Will not ask the user whether
* to save any changes!
*/
void closeDocumentAt(int index);
/**
* Reloads the current document. Will not ask the user whether to save any
* changes!
*
* \sa reloadDocumentAt()
*/
bool reloadCurrentDocument();
/**
* Reloads the document at the given \a index. It will lose any undo
* history and current selections. Will not ask the user whether to save
* any changes!
*
* Returns whether the map loaded successfully.
*/
bool reloadDocumentAt(int index);
/**
* Close all documents. Will not ask the user whether to save any changes!
*/
void closeAllDocuments();
void checkTilesetColumns(MapDocument *mapDocument);
/**
* Returns all open map documents.
*/
const QList<Document*> &documents() const { return mDocuments; }
TilesetDocument *findTilesetDocument(const SharedTileset &tileset) const;
TilesetDocument *findOrCreateTilesetDocument(const SharedTileset &tileset);
/**
* Opens the document for the given \a tileset.
*/
void openTileset(const SharedTileset &tileset);
/**
* Centers the current map on the tile coordinates \a x, \a y.
*/
void centerViewOn(qreal x, qreal y);
void centerViewOn(const QPointF &pos)
{ centerViewOn(pos.x(), pos.y()); }
signals:
void fileOpenRequested();
void fileOpenRequested(const QString &path);
void fileSaveRequested();
/**
* Emitted when the current displayed map document changed.
*/
void currentDocumentChanged(Document *document);
/**
* Emitted when the user requested the document at \a index to be closed.
*/
void documentCloseRequested(int index);
/**
* Emitted when a document is about to be closed.
*/
void documentAboutToClose(Document *document);
/**
* Emitted when an error occurred while reloading the map.
*/
void reloadError(const QString &error);
public slots:
void switchToLeftDocument();
void switchToRightDocument();
void openFile();
void openFile(const QString &path);
void saveFile();
private slots:
void currentIndexChanged();
void fileNameChanged(const QString &fileName,
const QString &oldFileName);
void modifiedChanged();
void updateDocumentTab(Document *document);
void documentSaved();
void documentTabMoved(int from, int to);
void tabContextMenuRequested(const QPoint &pos);
void tilesetAdded(int index, Tileset *tileset);
void tilesetRemoved(Tileset *tileset);
void tilesetReplaced(int index, Tileset *tileset, Tileset *oldTileset);
void tilesetNameChanged(Tileset *tileset);
void fileChanged(const QString &fileName);
void reloadRequested();
void tilesetChanged(Tileset *tileset);
private:
DocumentManager(QObject *parent = nullptr);
~DocumentManager();
bool askForAdjustment(const Tileset &tileset);
void addToTilesetDocument(const SharedTileset &tileset, MapDocument *mapDocument);
void removeFromTilesetDocument(const SharedTileset &tileset, MapDocument *mapDocument);
QList<Document*> mDocuments;
QWidget *mWidget;
QWidget *mNoEditorWidget;
QTabBar *mTabBar;
QStackedLayout *mEditorStack;
MapEditor *mMapEditor;
QHash<Document::DocumentType, Editor*> mEditorForType;
QUndoGroup *mUndoGroup;
FileSystemWatcher *mFileSystemWatcher;
QMap<SharedTileset, TilesetDocument*> mTilesetDocuments;
static DocumentManager *mInstance;
};
} // namespace Tiled::Internal
} // namespace Tiled
#endif // DOCUMENT_MANAGER_H