xlsxdatavalidation.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /****************************************************************************
  2. ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
  3. ** All right reserved.
  4. **
  5. ** Permission is hereby granted, free of charge, to any person obtaining
  6. ** a copy of this software and associated documentation files (the
  7. ** "Software"), to deal in the Software without restriction, including
  8. ** without limitation the rights to use, copy, modify, merge, publish,
  9. ** distribute, sublicense, and/or sell copies of the Software, and to
  10. ** permit persons to whom the Software is furnished to do so, subject to
  11. ** the following conditions:
  12. **
  13. ** The above copyright notice and this permission notice shall be
  14. ** included in all copies or substantial portions of the Software.
  15. **
  16. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. **
  24. ****************************************************************************/
  25. #ifndef QXLSX_XLSXDATAVALIDATION_H
  26. #define QXLSX_XLSXDATAVALIDATION_H
  27. #include "xlsxglobal.h"
  28. #include <QSharedDataPointer>
  29. #include <QString>
  30. #include <QList>
  31. class QXmlStreamReader;
  32. class QXmlStreamWriter;
  33. QT_BEGIN_NAMESPACE_XLSX
  34. class Worksheet;
  35. class CellRange;
  36. class CellReference;
  37. class DataValidationPrivate;
  38. class Q_XLSX_EXPORT DataValidation
  39. {
  40. public:
  41. enum ValidationType
  42. {
  43. None,
  44. Whole,
  45. Decimal,
  46. List,
  47. Date,
  48. Time,
  49. TextLength,
  50. Custom
  51. };
  52. enum ValidationOperator
  53. {
  54. Between,
  55. NotBetween,
  56. Equal,
  57. NotEqual,
  58. LessThan,
  59. LessThanOrEqual,
  60. GreaterThan,
  61. GreaterThanOrEqual
  62. };
  63. enum ErrorStyle
  64. {
  65. Stop,
  66. Warning,
  67. Information
  68. };
  69. DataValidation();
  70. DataValidation(ValidationType type, ValidationOperator op=Between, const QString &formula1=QString()
  71. , const QString &formula2=QString(), bool allowBlank=false);
  72. DataValidation(const DataValidation &other);
  73. ~DataValidation();
  74. ValidationType validationType() const;
  75. ValidationOperator validationOperator() const;
  76. ErrorStyle errorStyle() const;
  77. QString formula1() const;
  78. QString formula2() const;
  79. bool allowBlank() const;
  80. QString errorMessage() const;
  81. QString errorMessageTitle() const;
  82. QString promptMessage() const;
  83. QString promptMessageTitle() const;
  84. bool isPromptMessageVisible() const;
  85. bool isErrorMessageVisible() const;
  86. QList<CellRange> ranges() const;
  87. void setValidationType(ValidationType type);
  88. void setValidationOperator(ValidationOperator op);
  89. void setErrorStyle(ErrorStyle es);
  90. void setFormula1(const QString &formula);
  91. void setFormula2(const QString &formula);
  92. void setErrorMessage(const QString &error, const QString &title=QString());
  93. void setPromptMessage(const QString &prompt, const QString &title=QString());
  94. void setAllowBlank(bool enable);
  95. void setPromptMessageVisible(bool visible);
  96. void setErrorMessageVisible(bool visible);
  97. void addCell(const CellReference &cell);
  98. void addCell(int row, int col);
  99. void addRange(int firstRow, int firstCol, int lastRow, int lastCol);
  100. void addRange(const CellRange &range);
  101. DataValidation &operator=(const DataValidation &other);
  102. bool saveToXml(QXmlStreamWriter &writer) const;
  103. static DataValidation loadFromXml(QXmlStreamReader &reader);
  104. private:
  105. QSharedDataPointer<DataValidationPrivate> d;
  106. };
  107. QT_END_NAMESPACE_XLSX
  108. #endif // QXLSX_XLSXDATAVALIDATION_H