1 | /* This file is part of the KDE project |
2 | Copyright (C) 2003 Norbert Andres, nandres@web.de |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef CALLIGRA_SHEETS_STYLE_MANAGER |
21 | #define CALLIGRA_SHEETS_STYLE_MANAGER |
22 | |
23 | #include "calligra_sheets_export.h" |
24 | #include <KoXmlReader.h> |
25 | |
26 | #include <Style.h> |
27 | |
28 | class QDomElement; |
29 | class QDomDocument; |
30 | class QStringList; |
31 | |
32 | class KoGenStyles; |
33 | class KoOdfStylesReader; |
34 | |
35 | namespace Calligra |
36 | { |
37 | namespace Sheets |
38 | { |
39 | class Conditions; |
40 | class Map; |
41 | class StyleDialog; |
42 | class ValueParser; |
43 | |
44 | /** |
45 | * \class StyleManager |
46 | * \brief Manages cell styles |
47 | * \ingroup Style |
48 | * The StyleManager takes care of named styles. It also provides some static |
49 | * methods for the preloading of OpenDocument autostyles. |
50 | */ |
51 | class CALLIGRA_SHEETS_ODF_EXPORT StyleManager |
52 | { |
53 | friend class StyleManagerDialog; |
54 | |
55 | public: |
56 | StyleManager(); |
57 | ~StyleManager(); |
58 | |
59 | QDomElement save(QDomDocument & doc); |
60 | bool loadXML(KoXmlElement const & styles); |
61 | |
62 | void saveOdf(KoGenStyles &mainStyles); |
63 | void loadOdfStyleTemplate(KoOdfStylesReader& stylesReader, Map* map = 0); |
64 | |
65 | CustomStyle * defaultStyle() const { |
66 | return m_defaultStyle; |
67 | } |
68 | |
69 | /** |
70 | * Searches for a style named \p name in the map of styles. |
71 | * On OpenDocument loading, it searches the name in the map sorted |
72 | * by the OpenDocument internal name . |
73 | * \return the custom style named \p name |
74 | */ |
75 | CustomStyle * style(QString const & name) const; |
76 | |
77 | void resetDefaultStyle(); |
78 | |
79 | bool checkCircle(QString const & name, QString const & parent); |
80 | bool validateStyleName(QString const & name, CustomStyle * style); |
81 | void changeName(QString const & oldName, QString const & newName); |
82 | |
83 | void insertStyle(CustomStyle *style); |
84 | |
85 | void takeStyle(CustomStyle * style); |
86 | void createBuiltinStyles(); |
87 | |
88 | QStringList styleNames() const; |
89 | int count() const { |
90 | return m_styles.count(); |
91 | } |
92 | |
93 | /** |
94 | * Loads OpenDocument auto styles. |
95 | * The auto styles are preloaded, because an auto style could be shared |
96 | * among cells. So, preloading prevents a multiple loading of the same |
97 | * auto style. |
98 | * This method is called before the cell loading process. |
99 | * @param stylesReader repository of styles |
100 | * @return a hash of styles with the OpenDocument internal name as key |
101 | */ |
102 | Styles loadOdfAutoStyles(KoOdfStylesReader& stylesReader, |
103 | QHash<QString, Conditions>& conditionalStyles, |
104 | const ValueParser *parser); |
105 | |
106 | /** |
107 | * Releases unused auto styles. |
108 | * If there are auto styles, which are not used by any cell (uncommon case) |
109 | * this method makes sure, that these get deleted. |
110 | * This method is called after the cell loading porcess. |
111 | * @param autoStyles a hash of styles with the OpenDocument internal name as |
112 | * key |
113 | * @see loadOdfAutoStyles |
114 | */ |
115 | void releaseUnusedAutoStyles(Styles autoStyles); |
116 | |
117 | /// OpenDocument name to internal name (on loading) or vice versa (on saving) |
118 | QString openDocumentName(const QString&) const; |
119 | |
120 | private: |
121 | void dump() const; |
122 | |
123 | CustomStyle * m_defaultStyle; |
124 | CustomStyles m_styles; // builtin and custom made styles |
125 | |
126 | // OpenDocument name to internal name (on loading) or vice versa (on saving) |
127 | // NOTE: Temporary! Only valid while loading or saving OpenDocument files. |
128 | QHash<QString, QString> m_oasisStyles; |
129 | }; |
130 | |
131 | } // namespace Sheets |
132 | } // namespace Calligra |
133 | |
134 | #endif // CALLIGRA_SHEETS_STYLE_MANAGER |
135 | |