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 // Sheets 46 #include "sheets_odf_export.h" 47 #include "Condition.h" 48 49 #include "KoXmlReaderForward.h" 50 51 namespace Calligra 52 { 53 namespace Sheets 54 { 55 class ValueConverter; 56 class ValueParser; 57 58 /** 59 * \class Validity 60 * \ingroup Value 61 * 62 * Validates cell contents. 63 * 64 * \author Stefan Nikolaus <stefan.nikolaus@kdemail.net> 65 */ 66 class CALLIGRA_SHEETS_ODF_EXPORT Validity 67 { 68 public: 69 /// The action invoked, if the validity check fails. 70 enum Action { 71 Stop, ///< Stop 72 Warning, ///< Warn 73 Information ///< Inform 74 }; 75 /// The type of the restriction. 76 enum Restriction { 77 None, ///< No restriction 78 Number, ///< Restrict to numbers 79 Text, ///< Restrict to texts 80 Time, ///< Restrict to times 81 Date, ///< Restrict to dates 82 Integer, ///< Restrict to integers 83 TextLength, ///< Restrict text length 84 List ///< Restrict to lists 85 }; 86 87 /** 88 * Constructor. 89 * Creates a validity check, that allows any content. 90 */ 91 Validity(); 92 93 /** 94 * Copy Constructor. 95 * Copies the validity \p other . 96 */ 97 Validity(const Validity& other); 98 99 /** 100 * Destructor. 101 */ 102 ~Validity(); 103 104 /** 105 * \return \c true if this validity check allows any content 106 */ 107 bool isEmpty() const; 108 109 /** 110 * Tests whether the content of \p cell is allowed. 111 * \return \c true if the content is valid 112 */ 113 bool testValidity(const Cell* cell) const; 114 115 /** 116 * \ingroup NativeFormat 117 * Loads validity checks. 118 */ 119 bool loadXML(Cell* const cell, const KoXmlElement& validityElement); 120 121 /** 122 * \ingroup NativeFormat 123 * Saves validity checks. 124 */ 125 QDomElement saveXML(QDomDocument& doc, const ValueConverter *converter) const; 126 127 Action action() const; 128 bool allowEmptyCell() const; 129 Conditional::Type condition() const; 130 131 bool displayMessage() const; 132 bool displayValidationInformation() const; 133 const QString& messageInfo() const; 134 const QString& message() const; 135 136 const Value &maximumValue() const; 137 const Value &minimumValue() const; 138 139 Restriction restriction() const; 140 const QString& title() const; 141 const QString& titleInfo() const; 142 const QStringList& validityList() const; 143 144 void setAction(Action action); 145 void setAllowEmptyCell(bool allow); 146 void setCondition(Conditional::Type condition); 147 148 void setDisplayMessage(bool display); 149 void setDisplayValidationInformation(bool display); 150 void setMessage(const QString& message); 151 void setMessageInfo(const QString& info); 152 153 void setMaximumValue(const Value &value); 154 void setMinimumValue(const Value &value); 155 156 void setRestriction(Restriction restriction); 157 void setTitle(const QString& title); 158 void setTitleInfo(const QString& info); 159 void setValidityList(const QStringList& list); 160 161 /// \note fake implementation to make QMap happy 162 bool operator<(const Validity&) const { 163 return true; 164 } 165 void operator=(const Validity&); 166 bool operator==(const Validity& other) const; 167 inline bool operator!=(const Validity& other) const { 168 return !operator==(other); 169 } 170 171 static QHash<QString, KoXmlElement> preloadValidities(const KoXmlElement& body); 172 173 private: 174 class Private; 175 QSharedDataPointer<Private> d; 176 }; 177 178 } // namespace Sheets 179 } // namespace Calligra 180 181 Q_DECLARE_METATYPE(Calligra::Sheets::Validity) 182 Q_DECLARE_TYPEINFO(Calligra::Sheets::Validity, Q_MOVABLE_TYPE); 183 184 #endif // CALLIGRA_SHEETS_VALIDITY 185