1 | /* This file is part of the KDE project |
2 | Copyright 2010 Marijn Kruisselbrink <mkruisselbrink@kde.org> |
3 | Copyright 1998, 1999 Torben Weis <weis@kde.org> |
4 | Copyright 1999- 2006 The KSpread Team <calligra-devel@kde.org> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | Boston, MA 02110-1301, USA. |
20 | */ |
21 | |
22 | #ifndef CALLIGRA_SHEETS_CONDITION_H |
23 | #define CALLIGRA_SHEETS_CONDITION_H |
24 | |
25 | #include "Style.h" |
26 | #include "Value.h" |
27 | |
28 | #include <QDomElement> |
29 | #include <QLinkedList> |
30 | #include <QSharedData> |
31 | #include <QVariant> |
32 | |
33 | #include <KoXmlReader.h> |
34 | |
35 | class QColor; |
36 | class QDomDocument; |
37 | class QFont; |
38 | class QString; |
39 | class KoGenStyle; |
40 | |
41 | namespace Calligra |
42 | { |
43 | namespace Sheets |
44 | { |
45 | class Cell; |
46 | class ValueConverter; |
47 | class ValueParser; |
48 | |
49 | /** |
50 | * \class Conditional |
51 | * \ingroup Style |
52 | * Conditional formatting. |
53 | * Holds the actual condition and the applicable style for conditional |
54 | * Cell formattings. |
55 | */ |
56 | class CALLIGRA_SHEETS_ODF_EXPORT Conditional |
57 | { |
58 | public: |
59 | enum Type { None, Equal, Superior, Inferior, SuperiorEqual, |
60 | InferiorEqual, Between, Different, DifferentTo, |
61 | IsTrueFormula |
62 | }; |
63 | |
64 | Value value1; |
65 | Value value2; |
66 | QString styleName; |
67 | Type cond; |
68 | QString baseCellAddress; |
69 | |
70 | Conditional(); |
71 | |
72 | bool operator==(const Conditional &other) const; |
73 | }; |
74 | |
75 | |
76 | class Conditions; |
77 | uint qHash(const Conditions& conditions); |
78 | uint qHash(const Conditional& condition); |
79 | |
80 | /** |
81 | * \class Conditions |
82 | * \ingroup Style |
83 | * Manages a set of conditions for a cell. |
84 | */ |
85 | class CALLIGRA_SHEETS_ODF_EXPORT Conditions |
86 | { |
87 | public: |
88 | /** |
89 | * Constructor. |
90 | */ |
91 | Conditions(); |
92 | |
93 | /** |
94 | * Copy Constructor. |
95 | */ |
96 | Conditions(const Conditions& other); |
97 | |
98 | /** |
99 | * Destructor.. |
100 | */ |
101 | ~Conditions(); |
102 | |
103 | /** |
104 | * \return \c true if there are no conditions defined |
105 | */ |
106 | bool isEmpty() const; |
107 | |
108 | /** |
109 | * \return the style that matches first (or 0 if no condition matches) |
110 | */ |
111 | Style testConditions(const Cell &cell) const; |
112 | |
113 | /** |
114 | * Retrieve the current list of conditions we're checking |
115 | */ |
116 | QLinkedList<Conditional> conditionList() const; |
117 | |
118 | /** |
119 | * Replace the current list of conditions with this new one |
120 | */ |
121 | void setConditionList(const QLinkedList<Conditional> & list); |
122 | |
123 | /** |
124 | * Returns an optional default style, which is returned by testConditons if none of |
125 | * the conditions matches. |
126 | */ |
127 | Style defaultStyle() const; |
128 | |
129 | /** |
130 | * Set an optional default style. This style is returned by testConditions if none of |
131 | * the conditions matches. |
132 | */ |
133 | void setDefaultStyle(const Style& style); |
134 | |
135 | /** |
136 | * \ingroup NativeFormat |
137 | * Takes a parsed DOM element and recreates the conditions structure out of |
138 | * it |
139 | */ |
140 | void loadConditions(const KoXmlElement &element, const ValueParser *parser); |
141 | |
142 | /** |
143 | * \ingroup NativeFormat |
144 | * Saves the conditions to a DOM tree structure. |
145 | * \return the DOM element for the conditions. |
146 | */ |
147 | QDomElement saveConditions(QDomDocument &doc, ValueConverter *converter) const; |
148 | |
149 | /** |
150 | * \ingroup OpenDocument |
151 | * Loads the condtional formatting. |
152 | */ |
153 | Conditional loadOdfCondition(const QString &conditionValue, const QString &applyStyleName, |
154 | const QString &baseCellAddress, const ValueParser *parser); |
155 | |
156 | /** |
157 | * \ingroup OpenDocument |
158 | * Loads the condtional formattings. |
159 | */ |
160 | void loadOdfConditions(const KoXmlElement &element, const ValueParser *parser, const StyleManager* styleManager); |
161 | |
162 | /** |
163 | * \ingroup OpenDocument |
164 | * Saves the condtional formattings. |
165 | */ |
166 | void saveOdfConditions(KoGenStyle ¤tCellStyle, ValueConverter *converter) const; |
167 | |
168 | /// \note implementation to make QMap happy (which is needed by RectStorage) |
169 | bool operator<(const Conditions& conditions) const { |
170 | return qHash(*this) < qHash(conditions); |
171 | } |
172 | void operator=(const Conditions& other); |
173 | bool operator==(const Conditions& other) const; |
174 | inline bool operator!=(const Conditions& other) const { |
175 | return !operator==(other); |
176 | } |
177 | |
178 | private: |
179 | /** |
180 | * Use this function to see what conditions actually apply currently |
181 | * |
182 | * \param condition a reference to a condition that will be set to the |
183 | * matching condition. If none of the conditions are true |
184 | * then this parameter is undefined on exit (check the |
185 | * return value). |
186 | * |
187 | * \return true if one of the conditions is true, false if not. |
188 | */ |
189 | bool currentCondition(const Cell& cell, Conditional & condition) const; |
190 | |
191 | bool isTrueFormula(const Cell& cell, const QString& formula, const QString& baseCellAddress) const; |
192 | |
193 | /** |
194 | * \ingroup OpenDocument |
195 | */ |
196 | void loadOdfCondition(QString &valExpression, Conditional &newCondition, const ValueParser *parser); |
197 | |
198 | /** |
199 | * \ingroup OpenDocument |
200 | */ |
201 | void loadOdfConditionValue(const QString &styleCondition, Conditional &newCondition, const ValueParser *parser); |
202 | |
203 | /** |
204 | * \ingroup OpenDocument |
205 | */ |
206 | void loadOdfValidationValue(const QStringList &listVal, Conditional &newCondition, const ValueParser *parser); |
207 | |
208 | /** |
209 | * \ingroup OpenDocument |
210 | */ |
211 | QString saveOdfConditionValue(const Conditional &conditionalStyle, ValueConverter *converter) const; |
212 | |
213 | class Private; |
214 | QSharedDataPointer<Private> d; |
215 | }; |
216 | |
217 | } // namespace Sheets |
218 | } // namespace Calligra |
219 | |
220 | Q_DECLARE_METATYPE(Calligra::Sheets::Conditions) |
221 | Q_DECLARE_TYPEINFO(Calligra::Sheets::Conditions, Q_MOVABLE_TYPE); |
222 | |
223 | #endif // CALLIGRA_SHEETS_CONDITION_H |
224 | |