1/* This file is part of the KDE project
2 Copyright 2010 Marijn Kruisselbrink <mkruisselbrink@kde.org>
3 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __MAP_H__
22#define __MAP_H__
23
24#include <QList>
25#include <QObject>
26#include <QString>
27#include <QStringList>
28
29#include "ProtectableObject.h"
30
31#include "calligra_sheets_export.h"
32
33#include <KoDataCenterBase.h>
34#include <KoXmlReader.h>
35
36class KoStore;
37class KoOdfLoadingContext;
38class KoEmbeddedDocumentSaver;
39class KoStyleManager;
40class KoDocumentResourceManager;
41
42class KCompletion;
43
44class QDomElement;
45class QDomDocument;
46class KUndo2Command;
47
48class KoXmlWriter;
49class KoGenStyles;
50class KoOasisSettings;
51
52namespace Calligra
53{
54namespace Sheets
55{
56class ApplicationSettings;
57class BindingManager;
58class CalculationSettings;
59class ColumnFormat;
60class Damage;
61class DatabaseManager;
62class DependencyManager;
63class DocBase;
64class LoadingInfo;
65class NamedAreaManager;
66class RecalcManager;
67class RowFormat;
68class Sheet;
69class Style;
70class StyleManager;
71class ValueParser;
72class ValueConverter;
73class ValueFormatter;
74class ValueCalc;
75
76/**
77 * The "embedded document".
78 * The Map holds all the document data.
79 */
80class CALLIGRA_SHEETS_ODF_EXPORT Map : public QObject, public KoDataCenterBase, public ProtectableObject
81{
82 Q_OBJECT
83public:
84 /**
85 * Created an empty map.
86 */
87 explicit Map(DocBase* doc = 0, int syntaxVersion = 1);
88
89 /**
90 * This deletes all sheets contained in this map.
91 */
92 virtual ~Map();
93
94 /**
95 * \return the document this map belongs to
96 */
97 DocBase* doc() const;
98
99 /**
100 * \brief Sets whether the document can be edited or is read only.
101 */
102 void setReadWrite(bool readwrite = true);
103
104 /**
105 * \return Returns whether the document can be edited or is read only.
106 */
107 bool isReadWrite() const;
108
109 // KoDataCenterBase interface
110 virtual bool completeLoading(KoStore *store);
111 virtual bool completeSaving(KoStore *store, KoXmlWriter *manifestWriter, KoShapeSavingContext * context);
112
113 /**
114 * \return a pointer to the binding manager
115 */
116 BindingManager* bindingManager() const;
117
118 /**
119 * \return a pointer to the database manager
120 */
121 DatabaseManager* databaseManager() const;
122
123 /**
124 * \return a pointer to the dependency manager
125 */
126 DependencyManager* dependencyManager() const;
127
128 /**
129 * \return a pointer to the named area manager
130 */
131 NamedAreaManager* namedAreaManager() const;
132
133 /**
134 * \return a pointer to the recalculation manager
135 */
136 RecalcManager* recalcManager() const;
137
138 /**
139 * @return the StyleManager of this Document
140 */
141 StyleManager* styleManager() const;
142
143 /**
144 * @return the KoStyleManager of this Document
145 */
146 KoStyleManager* textStyleManager() const;
147
148 /**
149 * @return the value parser of this Document
150 */
151 ValueParser* parser() const;
152
153 /**
154 * @return the value formatter of this Document
155 */
156 ValueFormatter* formatter() const;
157
158 /**
159 * @return the value converter of this Document
160 */
161 ValueConverter* converter() const;
162
163 /**
164 * @return the value calculator of this Document
165 */
166 ValueCalc* calc() const;
167
168 /**
169 * \return the application settings
170 */
171 ApplicationSettings* settings() const;
172
173 /**
174 * \return the calculation settings
175 */
176 CalculationSettings* calculationSettings() const;
177
178 /**
179 * \return the default row format
180 */
181 const ColumnFormat* defaultColumnFormat() const;
182
183 /**
184 * \return the default row format
185 */
186 const RowFormat* defaultRowFormat() const;
187
188 /**
189 * Sets the default column width to \p width.
190 */
191 void setDefaultColumnWidth(double width);
192
193 /**
194 * Sets the default row height to \p height.
195 */
196 void setDefaultRowHeight(double height);
197
198 /**
199 * \ingroup OpenDocument
200 */
201 void loadOdfSettings(KoOasisSettings &settings);
202
203 /**
204 * \ingroup OpenDocument
205 */
206 bool saveOdf(KoXmlWriter & xmlWriter, KoShapeSavingContext & savingContext);
207
208 /**
209 * \ingroup OpenDocument
210 */
211 bool loadOdf(const KoXmlElement& mymap, KoOdfLoadingContext& odfContext);
212
213 /**
214 * \ingroup NativeFormat
215 */
216 bool loadXML(const KoXmlElement& mymap);
217
218 /**
219 * \ingroup NativeFormat
220 */
221 QDomElement save(QDomDocument& doc);
222
223
224 bool loadChildren(KoStore* _store);
225
226 /**
227 * The sheet named @p _from is being moved to the sheet @p _to.
228 * If @p _before is true @p _from is inserted before (after otherwise)
229 * @p _to.
230 */
231 void moveSheet(const QString & _from, const QString & _to, bool _before = true);
232
233 /**
234 * Searches for a sheet named @p name .
235 * @return a pointer to the searched sheet
236 * @return @c 0 if nothing was found
237 */
238 Sheet* findSheet(const QString& name) const;
239
240 /**
241 * @return a pointer to the next sheet to @p sheet
242 */
243 Sheet* nextSheet(Sheet* sheet) const;
244
245 /**
246 * @return a pointer to the previous sheet to @p sheet
247 */
248 Sheet* previousSheet(Sheet*) const;
249
250 /**
251 * Creates a new sheet.
252 * The sheet is not added to the map nor added to the GUI.
253 * @return a pointer to a new Sheet
254 */
255 Sheet* createSheet(const QString& name = QString());
256
257 /**
258 * Adds @p sheet to this map.
259 * The sheet becomes the active sheet.
260 */
261 void addSheet(Sheet* sheet);
262
263 /**
264 * Creates a new sheet.
265 * Adds a new sheet to this map.
266 * @return a pointer to the new sheet
267 */
268 Sheet* addNewSheet(const QString& name = QString());
269
270 /**
271 * @return a pointer to the sheet at index @p index in this map
272 * @return @c 0 if the index exceeds the list boundaries
273 */
274 Sheet* sheet(int index) const;
275
276 /**
277 * @return index of @p sheet in this map
278 * @return @c 0 if the index exceeds the list boundaries
279 */
280 int indexOf(Sheet* sheet) const;
281
282 /**
283 * @return the list of sheets in this map
284 */
285 QList<Sheet*>& sheetList() const;
286
287 /**
288 * @return amount of sheets in this map
289 */
290 int count() const;
291
292 void removeSheet(Sheet* sheet);
293 void reviveSheet(Sheet* sheet);
294
295 QStringList visibleSheets() const;
296 QStringList hiddenSheets() const;
297
298 int increaseLoadedRowsCounter(int i = 1);
299
300 /**
301 * \ingroup OpenDocument
302 * \ingroup NativeFormat
303 * \return true if the document is currently loading.
304 */
305 bool isLoading() const;
306
307 /**
308 * \return the document's syntax version
309 * \ingroup NativeFormat
310 */
311 int syntaxVersion() const;
312
313 /**
314 * Sets the document's syntax \p version.
315 * \ingroup NativeFormat
316 */
317 void setSyntaxVersion(int version);
318
319 /**
320 * \ingroup OpenDocument
321 * \ingroup NativeFormat
322 * Creates the loading info, if it does not exist yet.
323 * \return the loading info
324 */
325 LoadingInfo* loadingInfo() const;
326
327 /**
328 * \ingroup OpenDocument
329 * \ingroup NativeFormat
330 * Deletes the loading info. Called after loading is complete.
331 */
332 void deleteLoadingInfo();
333
334 /**
335 * \return the KCompletion object, that allows user input completions.
336 */
337 KCompletion &stringCompletion();
338
339 /**
340 * Adds \p string to the list of string values in order to be able to
341 * complete user inputs.
342 */
343 void addStringCompletion(const QString &string);
344
345 /**
346 * \ingroup Damages
347 */
348 void addDamage(Damage* damage);
349
350 /**
351 * Return a pointer to the resource manager associated with the
352 * document. The resource manager contains
353 * document wide resources * such as variable managers, the image
354 * collection and others.
355 * @see KoCanvasBase::resourceManager()
356 */
357 KoDocumentResourceManager *resourceManager() const;
358public Q_SLOTS:
359 /**
360 * \ingroup Damages
361 */
362 void flushDamages();
363
364 /**
365 * \ingroup Damages
366 */
367 void handleDamages(const QList<Damage*>& damages);
368
369 /**
370 * Emits the signal commandAdded(KUndo2Command *).
371 * You have to connect the signal to the object holding the undo stack or
372 * any relay object, that propagates \p command to the undo stack.
373 */
374 void addCommand(KUndo2Command *command);
375
376Q_SIGNALS:
377 /**
378 * \ingroup Damages
379 */
380 void damagesFlushed(const QList<Damage*>& damages);
381
382 /**
383 * Emitted, if a command was added by addCommand(KUndo2Command *).
384 */
385 void commandAdded(KUndo2Command *command);
386
387 /**
388 * Emitted, if a newly created sheet was added to the document.
389 */
390 void sheetAdded(Sheet* sheet);
391
392 /**
393 * Emitted, if a sheet was deleted from the document.
394 */
395 void sheetRemoved(Sheet* sheet);
396
397 /**
398 * Emitted, if a sheet was revived, i.e. a deleted sheet was reinserted.
399 */
400 void sheetRevived(Sheet* sheet);
401
402 /**
403 * Emitted, if a status \p message should be shown in the status bar
404 * for \p timeout msecs.
405 */
406 void statusMessage(const QString &message, int timeout);
407
408private:
409 Q_DISABLE_COPY(Map)
410
411 class Private;
412 Private * const d;
413};
414
415} // namespace Sheets
416} // namespace Calligra
417
418#endif
419