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

0001 /* This file is part of the KDE project
0002    Copyright (C) 2003 Norbert Andres, nandres@web.de
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef CALLIGRA_SHEETS_STYLE_MANAGER
0021 #define CALLIGRA_SHEETS_STYLE_MANAGER
0022 
0023 #include <KoXmlReader.h>
0024 
0025 #include "sheets_odf_export.h"
0026 #include <Style.h>
0027 
0028 class QDomElement;
0029 class QDomDocument;
0030 class QStringList;
0031 
0032 namespace Calligra
0033 {
0034 namespace Sheets
0035 {
0036 class Conditions;
0037 class Map;
0038 class ValueParser;
0039 
0040 /**
0041  * \class StyleManager
0042  * \brief Manages cell styles
0043  * \ingroup Style
0044  * The StyleManager takes care of named styles. It also provides some static
0045  * methods for the preloading of OpenDocument autostyles.
0046  */
0047 class CALLIGRA_SHEETS_ODF_EXPORT StyleManager
0048 {
0049     friend class StyleManagerDialog;
0050 
0051 public:
0052     StyleManager();
0053     ~StyleManager();
0054 
0055     QDomElement save(QDomDocument & doc);
0056     bool loadXML(KoXmlElement const & styles);
0057 
0058     CustomStyle * defaultStyle() const {
0059         return m_defaultStyle;
0060     }
0061 
0062     /**
0063      * Searches for a style named \p name in the map of styles.
0064      * On OpenDocument loading, it searches the name in the map sorted
0065      * by the OpenDocument internal name .
0066      * \return the custom style named \p name
0067      */
0068     CustomStyle * style(QString const & name) const;
0069 
0070     void resetDefaultStyle();
0071 
0072     bool checkCircle(QString const & name, QString const & parent);
0073     bool validateStyleName(QString const & name, CustomStyle * style);
0074     void changeName(QString const & oldName, QString const & newName);
0075 
0076     void insertStyle(CustomStyle *style);
0077 
0078     void takeStyle(CustomStyle * style);
0079     void createBuiltinStyles();
0080 
0081     QStringList styleNames(bool includeDefault = true) const;
0082     int count() const {
0083         return m_styles.count();
0084     }
0085 
0086     // Defines a temporary Oasis style alias.
0087     void defineOasisStyle(const QString &oasisName, const QString &styleName);
0088 
0089     void clearOasisStyles();
0090 
0091    /// OpenDocument name to internal name (on loading) or vice versa (on saving)
0092     QString openDocumentName(const QString&) const;
0093 
0094 private:
0095     void dump() const;
0096 
0097     CustomStyle * m_defaultStyle;
0098     CustomStyles  m_styles; // builtin and custom made styles
0099 
0100     // OpenDocument name to internal name (on loading) or vice versa (on saving)
0101     // NOTE: Temporary! Only valid while loading or saving OpenDocument files.
0102     QHash<QString, QString>  m_oasisStyles;
0103 };
0104 
0105 } // namespace Sheets
0106 } // namespace Calligra
0107 
0108 #endif // CALLIGRA_SHEETS_STYLE_MANAGER