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

0001 /* This file is part of the KDE project
0002    Copyright 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003    Copyright 2004 Tomas Mecir <mecirt@gmail.com>
0004    Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
0005    Copyright 2002,2004 Ariya Hidayat <ariya@kde.org>
0006    Copyright 2002-2003 Norbert Andres <nandres@web.de>
0007    Copyright 2003 Stefan Hetzl <shetzl@chello.at>
0008    Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
0009    Copyright 2002 Harri Porten <porten@kde.org>
0010    Copyright 2002 John Dailey <dailey@vt.edu>
0011    Copyright 1999-2001 David Faure <faure@kde.org>
0012    Copyright 2000-2001 Werner Trobin <trobin@kde.org>
0013    Copyright 2000 Simon Hausmann <hausmann@kde.org
0014    Copyright 1998-1999 Torben Weis <weis@kde.org>
0015    Copyright 1999 Michael Reiher <michael.reiher@gmx.de>
0016    Copyright 1999 Reginald Stadlbauer <reggie@kde.org>
0017 
0018    This library is free software; you can redistribute it and/or
0019    modify it under the terms of the GNU Library General Public
0020    License as published by the Free Software Foundation; either
0021    version 2 of the License, or (at your option) any later version.
0022 
0023    This library is distributed in the hope that it will be useful,
0024    but WITHOUT ANY WARRANTY; without even the implied warranty of
0025    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0026    Library General Public License for more details.
0027 
0028    You should have received a copy of the GNU Library General Public License
0029    along with this library; see the file COPYING.LIB.  If not, write to
0030    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0031    Boston, MA 02110-1301, USA.
0032 */
0033 
0034 #ifndef CALLIGRA_SHEETS_VALIDITY
0035 #define CALLIGRA_SHEETS_VALIDITY
0036 
0037 // Qt
0038 #include <QDate>
0039 #include <QHash>
0040 #include <QSharedDataPointer>
0041 #include <QStringList>
0042 #include <QTime>
0043 #include <QVariant>
0044 
0045 // Sheets
0046 #include "sheets_odf_export.h"
0047 #include "Condition.h"
0048 
0049 #include "KoXmlReaderForward.h"
0050 
0051 namespace Calligra
0052 {
0053 namespace Sheets
0054 {
0055 class ValueConverter;
0056 class ValueParser;
0057 
0058 /**
0059  * \class Validity
0060  * \ingroup Value
0061  *
0062  * Validates cell contents.
0063  *
0064  * \author Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0065  */
0066 class CALLIGRA_SHEETS_ODF_EXPORT Validity
0067 {
0068 public:
0069     /// The action invoked, if the validity check fails.
0070     enum Action {
0071         Stop,       ///< Stop
0072         Warning,    ///< Warn
0073         Information ///< Inform
0074     };
0075     /// The type of the restriction.
0076     enum Restriction {
0077         None,       ///< No restriction
0078         Number,     ///< Restrict to numbers
0079         Text,       ///< Restrict to texts
0080         Time,       ///< Restrict to times
0081         Date,       ///< Restrict to dates
0082         Integer,    ///< Restrict to integers
0083         TextLength, ///< Restrict text length
0084         List        ///< Restrict to lists
0085     };
0086 
0087     /**
0088      * Constructor.
0089      * Creates a validity check, that allows any content.
0090      */
0091     Validity();
0092 
0093     /**
0094      * Copy Constructor.
0095      * Copies the validity \p other .
0096      */
0097     Validity(const Validity& other);
0098 
0099     /**
0100      * Destructor.
0101      */
0102     ~Validity();
0103 
0104     /**
0105      * \return \c true if this validity check allows any content
0106      */
0107     bool isEmpty() const;
0108 
0109     /**
0110      * Tests whether the content of \p cell is allowed.
0111      * \return \c true if the content is valid
0112      */
0113     bool testValidity(const Cell* cell) const;
0114 
0115     /**
0116      * \ingroup NativeFormat
0117      * Loads validity checks.
0118      */
0119     bool loadXML(Cell* const cell, const KoXmlElement& validityElement);
0120 
0121     /**
0122      * \ingroup NativeFormat
0123      * Saves validity checks.
0124      */
0125     QDomElement saveXML(QDomDocument& doc, const ValueConverter *converter) const;
0126 
0127     Action action() const;
0128     bool allowEmptyCell() const;
0129     Conditional::Type condition() const;
0130 
0131     bool displayMessage() const;
0132     bool displayValidationInformation() const;
0133     const QString& messageInfo() const;
0134     const QString& message() const;
0135 
0136     const Value &maximumValue() const;
0137     const Value &minimumValue() const;
0138 
0139     Restriction restriction() const;
0140     const QString& title() const;
0141     const QString& titleInfo() const;
0142     const QStringList& validityList() const;
0143 
0144     void setAction(Action action);
0145     void setAllowEmptyCell(bool allow);
0146     void setCondition(Conditional::Type condition);
0147 
0148     void setDisplayMessage(bool display);
0149     void setDisplayValidationInformation(bool display);
0150     void setMessage(const QString& message);
0151     void setMessageInfo(const QString& info);
0152 
0153     void setMaximumValue(const Value &value);
0154     void setMinimumValue(const Value &value);
0155 
0156     void setRestriction(Restriction restriction);
0157     void setTitle(const QString& title);
0158     void setTitleInfo(const QString& info);
0159     void setValidityList(const QStringList& list);
0160 
0161     /// \note fake implementation to make QMap happy
0162     bool operator<(const Validity&) const {
0163         return true;
0164     }
0165     void operator=(const Validity&);
0166     bool operator==(const Validity& other) const;
0167     inline bool operator!=(const Validity& other) const {
0168         return !operator==(other);
0169     }
0170 
0171     static QHash<QString, KoXmlElement> preloadValidities(const KoXmlElement& body);
0172 
0173 private:
0174     class Private;
0175     QSharedDataPointer<Private> d;
0176 };
0177 
0178 } // namespace Sheets
0179 } // namespace Calligra
0180 
0181 Q_DECLARE_METATYPE(Calligra::Sheets::Validity)
0182 Q_DECLARE_TYPEINFO(Calligra::Sheets::Validity, Q_MOVABLE_TYPE);
0183 
0184 #endif // CALLIGRA_SHEETS_VALIDITY