File indexing completed on 2024-05-12 16:35:37

0001 /* This file is part of the KDE project
0002 
0003    Copyright 2004 Laurent Montel <montel@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 
0022 #ifndef CALLIGRA_SHEETS_GENVALIDATIONSTYLE
0023 #define CALLIGRA_SHEETS_GENVALIDATIONSTYLE
0024 
0025 #include "sheets_odf_export.h"
0026 
0027 #include <QMap>
0028 #include <QString>
0029 
0030 class KoXmlWriter;
0031 
0032 namespace Calligra
0033 {
0034 namespace Sheets
0035 {
0036 class Validity;
0037 class ValueConverter;
0038 class GenValidationStyles;
0039 
0040 /**
0041  * \class GenValidationStyle
0042  * \ingroup OpenDocument
0043  */
0044 class GenValidationStyle
0045 {
0046 public:
0047     explicit GenValidationStyle(Validity *_val = 0, const ValueConverter *converter = 0) {
0048         initVal(_val, converter);
0049     }
0050 
0051 
0052     bool operator<(const GenValidationStyle &other) const {
0053         if (allowEmptyCell != other.allowEmptyCell) return (allowEmptyCell < other.allowEmptyCell);
0054         if (condition != other.condition) return (condition < other.condition);
0055         if (titleInfo != other.titleInfo) return (titleInfo < other.titleInfo);
0056         if (displayValidationInformation != other.displayValidationInformation) return (displayValidationInformation < other.displayValidationInformation);
0057         if (messageInfo != other.messageInfo) return (messageInfo < other.messageInfo);
0058         if (messageType != other.messageType) return (messageType < other.messageType);
0059         if (displayMessage != other.displayMessage) return (displayMessage < other.displayMessage);
0060         if (message != other.message) return (message < other.message);
0061         if (title != other.title) return (title < other.title);
0062 
0063         return false;
0064     }
0065 private:
0066     QString createValidationCondition(Validity* _val, const ValueConverter *converter);
0067     QString createTextValidationCondition(Validity* _val);
0068     QString createTimeValidationCondition(Validity* _val, const ValueConverter *converter);
0069     QString createDateValidationCondition(Validity* _val, const ValueConverter *converter);
0070     QString createNumberValidationCondition(Validity* _val);
0071     QString createListValidationCondition(Validity* _val);
0072 
0073     void initVal(Validity *_val, const ValueConverter *converter);
0074 
0075     QString allowEmptyCell;
0076     QString condition;
0077     QString titleInfo;
0078     QString displayValidationInformation;
0079     QString messageInfo;
0080     QString messageType;
0081     QString displayMessage;
0082     QString message;
0083     QString title;
0084     friend class GenValidationStyles;
0085 };
0086 
0087 /**
0088  * \class GenValidationStyles
0089  * \ingroup OpenDocument
0090  */
0091 class CALLIGRA_SHEETS_ODF_EXPORT GenValidationStyles
0092 {
0093 public:
0094     GenValidationStyles();
0095     ~GenValidationStyles();
0096     QString insert(const GenValidationStyle& style);
0097 
0098     typedef QMap<GenValidationStyle, QString> StyleMap;
0099     void writeStyle(KoXmlWriter& writer) const;
0100 
0101 private:
0102     QString makeUniqueName(const QString& base) const;
0103 
0104     /// style definition -> name
0105     StyleMap m_styles;
0106     /// name -> style   (used to check for name uniqueness)
0107     typedef QMap<QString, bool> NameMap;
0108     NameMap m_names;
0109 
0110 };
0111 
0112 } // namespace Sheets
0113 } // namespace Calligra
0114 
0115 #endif