1 // xlsxvalidation.h
2 
3 #ifndef QXLSX_XLSXDATAVALIDATION_H
4 #define QXLSX_XLSXDATAVALIDATION_H
5 
6 #include <QtGlobal>
7 #include <QSharedDataPointer>
8 #include <QString>
9 #include <QList>
10 #include <QXmlStreamReader>
11 #include <QXmlStreamWriter>
12 
13 #include "xlsxglobal.h"
14 
15 class QXmlStreamReader;
16 class QXmlStreamWriter;
17 
18 QT_BEGIN_NAMESPACE_XLSX
19 
20 class Worksheet;
21 class CellRange;
22 class CellReference;
23 
24 class DataValidationPrivate;
25 class   DataValidation
26 {
27 public:
28     enum ValidationType
29     {
30         None,
31         Whole,
32         Decimal,
33         List,
34         Date,
35         Time,
36         TextLength,
37         Custom
38     };
39 
40     enum ValidationOperator
41     {
42         Between,
43         NotBetween,
44         Equal,
45         NotEqual,
46         LessThan,
47         LessThanOrEqual,
48         GreaterThan,
49         GreaterThanOrEqual
50     };
51 
52     enum ErrorStyle
53     {
54         Stop,
55         Warning,
56         Information
57     };
58 
59     DataValidation();
60     DataValidation(ValidationType type, ValidationOperator op=Between, const QString &formula1=QString()
61             , const QString &formula2=QString(), bool allowBlank=false);
62     DataValidation(const DataValidation &other);
63     ~DataValidation();
64 
65     ValidationType validationType() const;
66     ValidationOperator validationOperator() const;
67     ErrorStyle errorStyle() const;
68     QString formula1() const;
69     QString formula2() const;
70     bool allowBlank() const;
71     QString errorMessage() const;
72     QString errorMessageTitle() const;
73     QString promptMessage() const;
74     QString promptMessageTitle() const;
75     bool isPromptMessageVisible() const;
76     bool isErrorMessageVisible() const;
77     QList<CellRange> ranges() const;
78 
79     void setValidationType(ValidationType type);
80     void setValidationOperator(ValidationOperator op);
81     void setErrorStyle(ErrorStyle es);
82     void setFormula1(const QString &formula);
83     void setFormula2(const QString &formula);
84     void setErrorMessage(const QString &error, const QString &title=QString());
85     void setPromptMessage(const QString &prompt, const QString &title=QString());
86     void setAllowBlank(bool enable);
87     void setPromptMessageVisible(bool visible);
88     void setErrorMessageVisible(bool visible);
89 
90     void addCell(const CellReference &cell);
91     void addCell(int row, int col);
92     void addRange(int firstRow, int firstCol, int lastRow, int lastCol);
93     void addRange(const CellRange &range);
94 
95     DataValidation &operator=(const DataValidation &other);
96 
97     bool saveToXml(QXmlStreamWriter &writer) const;
98     static DataValidation loadFromXml(QXmlStreamReader &reader);
99 private:
100     QSharedDataPointer<DataValidationPrivate> d;
101 };
102 
103 QT_END_NAMESPACE_XLSX
104 
105 #endif // QXLSX_XLSXDATAVALIDATION_H
106