1 | /* This file is part of the KDE project |
2 | Copyright 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net> |
3 | Copyright 2004 Tomas Mecir <mecirt@gmail.com> |
4 | Copyright 1999-2002,2004 Laurent Montel <montel@kde.org> |
5 | Copyright 2002,2004 Ariya Hidayat <ariya@kde.org> |
6 | Copyright 2002-2003 Norbert Andres <nandres@web.de> |
7 | Copyright 2003 Stefan Hetzl <shetzl@chello.at> |
8 | Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de> |
9 | Copyright 2002 Harri Porten <porten@kde.org> |
10 | Copyright 2002 John Dailey <dailey@vt.edu> |
11 | Copyright 1999-2001 David Faure <faure@kde.org> |
12 | Copyright 2000-2001 Werner Trobin <trobin@kde.org> |
13 | Copyright 2000 Simon Hausmann <hausmann@kde.org |
14 | Copyright 1998-1999 Torben Weis <weis@kde.org> |
15 | Copyright 1999 Michael Reiher <michael.reiher@gmx.de> |
16 | Copyright 1999 Reginald Stadlbauer <reggie@kde.org> |
17 | |
18 | This library is free software; you can redistribute it and/or |
19 | modify it under the terms of the GNU Library General Public |
20 | License as published by the Free Software Foundation; either |
21 | version 2 of the License, or (at your option) any later version. |
22 | |
23 | This library is distributed in the hope that it will be useful, |
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
26 | Library General Public License for more details. |
27 | |
28 | You should have received a copy of the GNU Library General Public License |
29 | along with this library; see the file COPYING.LIB. If not, write to |
30 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
31 | Boston, MA 02110-1301, USA. |
32 | */ |
33 | |
34 | #ifndef CALLIGRA_SHEETS_VALIDITY |
35 | #define CALLIGRA_SHEETS_VALIDITY |
36 | |
37 | // Qt |
38 | #include <QDate> |
39 | #include <QHash> |
40 | #include <QSharedDataPointer> |
41 | #include <QStringList> |
42 | #include <QTime> |
43 | #include <QVariant> |
44 | |
45 | // Calligra |
46 | #include "calligra_sheets_export.h" |
47 | |
48 | // KSpread |
49 | #include "Condition.h" |
50 | |
51 | #include "KoXmlReaderForward.h" |
52 | |
53 | namespace Calligra |
54 | { |
55 | namespace Sheets |
56 | { |
57 | class OdfLoadingContext; |
58 | class ValueConverter; |
59 | class ValueParser; |
60 | |
61 | /** |
62 | * \class Validity |
63 | * \ingroup Value |
64 | * |
65 | * Validates cell contents. |
66 | * |
67 | * \author Stefan Nikolaus <stefan.nikolaus@kdemail.net> |
68 | */ |
69 | class CALLIGRA_SHEETS_ODF_EXPORT Validity |
70 | { |
71 | public: |
72 | /// The action invoked, if the validity check fails. |
73 | enum Action { |
74 | Stop, ///< Stop |
75 | Warning, ///< Warn |
76 | Information ///< Inform |
77 | }; |
78 | /// The type of the restriction. |
79 | enum Restriction { |
80 | None, ///< No restriction |
81 | Number, ///< Restrict to numbers |
82 | Text, ///< Restrict to texts |
83 | Time, ///< Restrict to times |
84 | Date, ///< Restrict to dates |
85 | Integer, ///< Restrict to integers |
86 | TextLength, ///< Restrict text length |
87 | List ///< Restrict to lists |
88 | }; |
89 | |
90 | /** |
91 | * Constructor. |
92 | * Creates a validity check, that allows any content. |
93 | */ |
94 | Validity(); |
95 | |
96 | /** |
97 | * Copy Constructor. |
98 | * Copies the validity \p other . |
99 | */ |
100 | Validity(const Validity& other); |
101 | |
102 | /** |
103 | * Destructor. |
104 | */ |
105 | ~Validity(); |
106 | |
107 | /** |
108 | * \return \c true if this validity check allows any content |
109 | */ |
110 | bool isEmpty() const; |
111 | |
112 | /** |
113 | * Tests whether the content of \p cell is allowed. |
114 | * \return \c true if the content is valid |
115 | */ |
116 | bool testValidity(const Cell* cell) const; |
117 | |
118 | /** |
119 | * \ingroup NativeFormat |
120 | * Loads validity checks. |
121 | */ |
122 | bool loadXML(Cell* const cell, const KoXmlElement& validityElement); |
123 | |
124 | /** |
125 | * \ingroup NativeFormat |
126 | * Saves validity checks. |
127 | */ |
128 | QDomElement saveXML(QDomDocument& doc, const ValueConverter *converter) const; |
129 | |
130 | /** |
131 | * \ingroup OpenDocument |
132 | * Loads validity checks. |
133 | */ |
134 | void loadOdfValidation(Cell* const cell, const QString& validationName, |
135 | OdfLoadingContext& tableContext); |
136 | |
137 | Action action() const; |
138 | bool allowEmptyCell() const; |
139 | Conditional::Type condition() const; |
140 | |
141 | bool displayMessage() const; |
142 | bool displayValidationInformation() const; |
143 | const QString& messageInfo() const; |
144 | const QString& message() const; |
145 | |
146 | const Value &maximumValue() const; |
147 | const Value &minimumValue() const; |
148 | |
149 | Restriction restriction() const; |
150 | const QString& title() const; |
151 | const QString& titleInfo() const; |
152 | const QStringList& validityList() const; |
153 | |
154 | void setAction(Action action); |
155 | void setAllowEmptyCell(bool allow); |
156 | void setCondition(Conditional::Type condition); |
157 | |
158 | void setDisplayMessage(bool display); |
159 | void setDisplayValidationInformation(bool display); |
160 | void setMessage(const QString& message); |
161 | void setMessageInfo(const QString& info); |
162 | |
163 | void setMaximumValue(const Value &value); |
164 | void setMinimumValue(const Value &value); |
165 | |
166 | void setRestriction(Restriction restriction); |
167 | void setTitle(const QString& title); |
168 | void setTitleInfo(const QString& info); |
169 | void setValidityList(const QStringList& list); |
170 | |
171 | /// \note fake implementation to make QMap happy |
172 | bool operator<(const Validity&) const { |
173 | return true; |
174 | } |
175 | void operator=(const Validity&); |
176 | bool operator==(const Validity& other) const; |
177 | inline bool operator!=(const Validity& other) const { |
178 | return !operator==(other); |
179 | } |
180 | |
181 | static QHash<QString, KoXmlElement> preloadValidities(const KoXmlElement& body); |
182 | |
183 | private: |
184 | /** |
185 | * \ingroup OpenDocument |
186 | * Helper method for loadOdfValidation(). |
187 | */ |
188 | void loadOdfValidationCondition(QString &valExpression, const ValueParser *parser); |
189 | |
190 | /** |
191 | * \ingroup OpenDocument |
192 | * Helper method for loadOdfValidation(). |
193 | */ |
194 | void loadOdfValidationValue(const QStringList &listVal, const ValueParser *parser); |
195 | |
196 | class Private; |
197 | QSharedDataPointer<Private> d; |
198 | }; |
199 | |
200 | } // namespace Sheets |
201 | } // namespace Calligra |
202 | |
203 | Q_DECLARE_METATYPE(Calligra::Sheets::Validity) |
204 | Q_DECLARE_TYPEINFO(Calligra::Sheets::Validity, Q_MOVABLE_TYPE); |
205 | |
206 | #endif // CALLIGRA_SHEETS_VALIDITY |
207 | |