File indexing completed on 2024-04-28 16:21:24

0001 /* This file is part of the KDE project
0002    Copyright 2010 Marijn Kruisselbrink <mkruisselbrink@kde.org>
0003    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef __MAP_H__
0022 #define __MAP_H__
0023 
0024 #include <QList>
0025 #include <QObject>
0026 #include <QString>
0027 #include <QStringList>
0028 
0029 #include "ProtectableObject.h"
0030 
0031 #include "sheets_odf_export.h"
0032 
0033 #include <KoDataCenterBase.h>
0034 #include <KoXmlReader.h>
0035 
0036 class KoStore;
0037 class KoStyleManager;
0038 class KoDocumentResourceManager;
0039 
0040 class KCompletion;
0041 
0042 class QDomElement;
0043 class QDomDocument;
0044 class KUndo2Command;
0045 
0046 class KoXmlWriter;
0047 
0048 namespace Calligra
0049 {
0050 namespace Sheets
0051 {
0052 class ApplicationSettings;
0053 class BindingManager;
0054 class CalculationSettings;
0055 class ColumnFormat;
0056 class Damage;
0057 class DatabaseManager;
0058 class DependencyManager;
0059 class DocBase;
0060 class LoadingInfo;
0061 class NamedAreaManager;
0062 class RecalcManager;
0063 class RowFormat;
0064 class Sheet;
0065 class Style;
0066 class StyleManager;
0067 class ValueParser;
0068 class ValueConverter;
0069 class ValueFormatter;
0070 class ValueCalc;
0071 
0072 /**
0073  * The "embedded document".
0074  * The Map holds all the document data.
0075  */
0076 class CALLIGRA_SHEETS_ODF_EXPORT Map : public QObject, public KoDataCenterBase, public ProtectableObject
0077 {
0078     Q_OBJECT
0079 public:
0080     /**
0081      * Created an empty map.
0082      */
0083     explicit Map(DocBase* doc = 0, int syntaxVersion = 1);
0084 
0085     /**
0086      * This deletes all sheets contained in this map.
0087      */
0088     ~Map() override;
0089 
0090     /**
0091      * \return the document this map belongs to
0092      */
0093     DocBase* doc() const;
0094 
0095     /**
0096      * \brief Sets whether the document can be edited or is read only.
0097      */
0098     void setReadWrite(bool readwrite = true);
0099 
0100     /**
0101      * \return Returns whether the document can be edited or is read only.
0102      */
0103     bool isReadWrite() const;
0104 
0105     // KoDataCenterBase interface
0106     bool completeLoading(KoStore *store) override;
0107     bool completeSaving(KoStore *store, KoXmlWriter *manifestWriter, KoShapeSavingContext * context) override;
0108 
0109     /**
0110      * \return a pointer to the binding manager
0111      */
0112     BindingManager* bindingManager() const;
0113 
0114     /**
0115      * \return a pointer to the database manager
0116      */
0117     DatabaseManager* databaseManager() const;
0118 
0119     /**
0120      * \return a pointer to the dependency manager
0121      */
0122     DependencyManager* dependencyManager() const;
0123 
0124     /**
0125      * \return a pointer to the named area manager
0126      */
0127     NamedAreaManager* namedAreaManager() const;
0128 
0129     /**
0130      * \return a pointer to the recalculation manager
0131      */
0132     RecalcManager* recalcManager() const;
0133 
0134     /**
0135      * @return the StyleManager of this Document
0136      */
0137     StyleManager* styleManager() const;
0138 
0139     /**
0140      * @return the KoStyleManager of this Document
0141      */
0142     KoStyleManager* textStyleManager() const;
0143 
0144     /**
0145      * @return the value parser of this Document
0146      */
0147     ValueParser* parser() const;
0148 
0149     /**
0150      * @return the value formatter of this Document
0151      */
0152     ValueFormatter* formatter() const;
0153 
0154     /**
0155      * @return the value converter of this Document
0156      */
0157     ValueConverter* converter() const;
0158 
0159     /**
0160      * @return the value calculator of this Document
0161      */
0162     ValueCalc* calc() const;
0163 
0164     /**
0165      * \return the application settings
0166      */
0167     ApplicationSettings* settings() const;
0168 
0169     /**
0170      * \return the calculation settings
0171      */
0172     CalculationSettings* calculationSettings() const;
0173 
0174     /**
0175      * \return the default row format
0176      */
0177     const ColumnFormat* defaultColumnFormat() const;
0178 
0179     /**
0180      * \return the default row format
0181      */
0182     const RowFormat* defaultRowFormat() const;
0183 
0184     /**
0185      * Sets the default column width to \p width.
0186      */
0187     void setDefaultColumnWidth(double width);
0188 
0189     /**
0190      * Sets the default row height to \p height.
0191      */
0192     void setDefaultRowHeight(double height);
0193 
0194     /**
0195      * \ingroup NativeFormat
0196      */
0197     bool loadXML(const KoXmlElement& mymap);
0198 
0199     /**
0200      * \ingroup NativeFormat
0201      */
0202     QDomElement save(QDomDocument& doc);
0203 
0204 
0205     bool loadChildren(KoStore* _store);
0206 
0207     /**
0208      * The sheet named @p _from is being moved to the sheet @p _to.
0209      * If @p  _before is true @p _from is inserted before (after otherwise)
0210      * @p  _to.
0211      */
0212     void moveSheet(const QString & _from, const QString & _to, bool _before = true);
0213 
0214     /**
0215      * Searches for a sheet named @p name .
0216      * @return a pointer to the searched sheet
0217      * @return @c 0 if nothing was found
0218      */
0219     Sheet* findSheet(const QString& name) const;
0220 
0221     /**
0222      * @return a pointer to the next sheet to @p sheet
0223      */
0224     Sheet* nextSheet(Sheet* sheet) const;
0225 
0226     /**
0227      * @return a pointer to the previous sheet to @p sheet
0228      */
0229     Sheet* previousSheet(Sheet*) const;
0230 
0231     /**
0232      * Creates a new sheet.
0233      * The sheet is not added to the map nor added to the GUI.
0234      * @return a pointer to a new Sheet
0235      */
0236     Sheet* createSheet(const QString& name = QString());
0237 
0238     /**
0239      * Adds @p sheet to this map.
0240      * The sheet becomes the active sheet.
0241     */
0242     void addSheet(Sheet* sheet);
0243 
0244     /**
0245      * Creates a new sheet.
0246      * Adds a new sheet to this map.
0247      * @return a pointer to the new sheet
0248      */
0249     Sheet* addNewSheet(const QString& name = QString());
0250 
0251     /**
0252      * @return a pointer to the sheet at index @p index in this map
0253      * @return @c 0 if the index exceeds the list boundaries
0254      */
0255     Sheet* sheet(int index) const;
0256 
0257     /**
0258      * @return index of @p sheet in this map
0259      * @return @c 0 if the index exceeds the list boundaries
0260      */
0261     int indexOf(Sheet* sheet) const;
0262 
0263     /**
0264      * @return the list of sheets in this map
0265      */
0266     QList<Sheet*>& sheetList() const;
0267 
0268     /**
0269      * @return amount of sheets in this map
0270      */
0271     int count() const;
0272 
0273     void removeSheet(Sheet* sheet);
0274     void reviveSheet(Sheet* sheet);
0275 
0276     QStringList visibleSheets() const;
0277     QStringList hiddenSheets() const;
0278 
0279     void setOverallRowsCounter(int number);
0280     int increaseLoadedRowsCounter(int i = 1);
0281 
0282     /**
0283      * \ingroup NativeFormat
0284      * \return true if the document is currently loading.
0285      */
0286     bool isLoading() const;
0287 
0288     /**
0289      * \ingroup NativeFormat
0290      * \param l whether the document is currently loading
0291      */
0292     void setLoading(bool l);
0293 
0294     /**
0295      * \return the document's syntax version
0296      * \ingroup NativeFormat
0297      */
0298     int syntaxVersion() const;
0299 
0300     /**
0301      * Sets the document's syntax \p version.
0302      * \ingroup NativeFormat
0303      */
0304     void setSyntaxVersion(int version);
0305 
0306     /**
0307      * \ingroup NativeFormat
0308      * Creates the loading info, if it does not exist yet.
0309      * \return the loading info
0310      */
0311     LoadingInfo* loadingInfo() const;
0312 
0313     /**
0314      * \ingroup NativeFormat
0315      * Deletes the loading info. Called after loading is complete.
0316      */
0317     void deleteLoadingInfo();
0318 
0319     /**
0320      * \return the KCompletion object, that allows user input completions.
0321      */
0322     KCompletion &stringCompletion();
0323 
0324     /**
0325      * Adds \p string to the list of string values in order to be able to
0326      * complete user inputs.
0327      */
0328     void addStringCompletion(const QString &string);
0329 
0330     /**
0331      * \ingroup Damages
0332      */
0333     void addDamage(Damage* damage);
0334 
0335     /**
0336      * Return a pointer to the resource manager associated with the
0337      * document. The resource manager contains
0338      * document wide resources * such as variable managers, the image
0339      * collection and others.
0340      * @see KoCanvasBase::resourceManager()
0341      */
0342     KoDocumentResourceManager *resourceManager() const;
0343 public Q_SLOTS:
0344     /**
0345      * \ingroup Damages
0346      */
0347     void flushDamages();
0348 
0349     /**
0350      * \ingroup Damages
0351      */
0352     void handleDamages(const QList<Damage*>& damages);
0353 
0354     /**
0355      * Emits the signal commandAdded(KUndo2Command *).
0356      * You have to connect the signal to the object holding the undo stack or
0357      * any relay object, that propagates \p command to the undo stack.
0358      */
0359     void addCommand(KUndo2Command *command);
0360 
0361 Q_SIGNALS:
0362     /**
0363      * \ingroup Damages
0364      */
0365     void damagesFlushed(const QList<Damage*>& damages);
0366 
0367     /**
0368      * Emitted, if a command was added by addCommand(KUndo2Command *).
0369      */
0370     void commandAdded(KUndo2Command *command);
0371 
0372     /**
0373      * Emitted, if a newly created sheet was added to the document.
0374      */
0375     void sheetAdded(Sheet* sheet);
0376 
0377     /**
0378      * Emitted, if a sheet was deleted from the document.
0379      */
0380     void sheetRemoved(Sheet* sheet);
0381 
0382     /**
0383      * Emitted, if a sheet was revived, i.e. a deleted sheet was reinserted.
0384      */
0385     void sheetRevived(Sheet* sheet);
0386 
0387     /**
0388      * Emitted, if a status \p message should be shown in the status bar
0389      * for \p timeout msecs.
0390      */
0391     void statusMessage(const QString &message, int timeout);
0392 
0393 private:
0394     Q_DISABLE_COPY(Map)
0395 
0396     class Private;
0397     Private * const d;
0398 };
0399 
0400 } // namespace Sheets
0401 } // namespace Calligra
0402 
0403 #endif