xlsxstyles_p.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 XLSXSTYLES_H
  26. #define XLSXSTYLES_H
  27. //
  28. // W A R N I N G
  29. // -------------
  30. //
  31. // This file is not part of the Qt Xlsx API. It exists for the convenience
  32. // of the Qt Xlsx. This header file may change from
  33. // version to version without notice, or even be removed.
  34. //
  35. // We mean it.
  36. //
  37. #include "xlsxglobal.h"
  38. #include "xlsxformat.h"
  39. #include "xlsxabstractooxmlfile.h"
  40. #include <QSharedPointer>
  41. #include <QHash>
  42. #include <QList>
  43. #include <QMap>
  44. #include <QStringList>
  45. #include <QVector>
  46. class QXmlStreamWriter;
  47. class QXmlStreamReader;
  48. class QIODevice;
  49. class StylesTest;
  50. namespace QXlsx {
  51. class Format;
  52. class XlsxColor;
  53. struct XlsxFormatNumberData
  54. {
  55. XlsxFormatNumberData() : formatIndex(0) {}
  56. int formatIndex;
  57. QString formatString;
  58. };
  59. class XLSX_AUTOTEST_EXPORT Styles : public AbstractOOXmlFile
  60. {
  61. public:
  62. Styles(CreateFlag flag);
  63. ~Styles();
  64. void addXfFormat(const Format &format, bool force=false);
  65. Format xfFormat(int idx) const;
  66. void addDxfFormat(const Format &format, bool force=false);
  67. Format dxfFormat(int idx) const;
  68. void saveToXmlFile(QIODevice *device) const;
  69. bool loadFromXmlFile(QIODevice *device);
  70. QColor getColorByIndex(int idx);
  71. private:
  72. friend class Format;
  73. friend class ::StylesTest;
  74. void fixNumFmt(const Format &format);
  75. void writeNumFmts(QXmlStreamWriter &writer) const;
  76. void writeFonts(QXmlStreamWriter &writer) const;
  77. void writeFont(QXmlStreamWriter &writer, const Format &font, bool isDxf = false) const;
  78. void writeFills(QXmlStreamWriter &writer) const;
  79. void writeFill(QXmlStreamWriter &writer, const Format &fill, bool isDxf = false) const;
  80. void writeBorders(QXmlStreamWriter &writer) const;
  81. void writeBorder(QXmlStreamWriter &writer, const Format &border, bool isDxf = false) const;
  82. void writeSubBorder(QXmlStreamWriter &writer, const QString &type, int style, const XlsxColor &color) const;
  83. void writeCellXfs(QXmlStreamWriter &writer) const;
  84. void writeDxfs(QXmlStreamWriter &writer) const;
  85. void writeDxf(QXmlStreamWriter &writer, const Format &format) const;
  86. void writeColors(QXmlStreamWriter &writer) const;
  87. bool readNumFmts(QXmlStreamReader &reader);
  88. bool readFonts(QXmlStreamReader &reader);
  89. bool readFont(QXmlStreamReader &reader, Format &format);
  90. bool readFills(QXmlStreamReader &reader);
  91. bool readFill(QXmlStreamReader &reader, Format &format);
  92. bool readBorders(QXmlStreamReader &reader);
  93. bool readBorder(QXmlStreamReader &reader, Format &format);
  94. bool readSubBorder(QXmlStreamReader &reader, const QString &name, Format::BorderStyle &style, XlsxColor &color);
  95. bool readCellXfs(QXmlStreamReader &reader);
  96. bool readDxfs(QXmlStreamReader &reader);
  97. bool readDxf(QXmlStreamReader &reader);
  98. bool readColors(QXmlStreamReader &reader);
  99. bool readIndexedColors(QXmlStreamReader &reader);
  100. QHash<QString, int> m_builtinNumFmtsHash;
  101. QMap<int, QSharedPointer<XlsxFormatNumberData> > m_customNumFmtIdMap;
  102. QHash<QString, QSharedPointer<XlsxFormatNumberData> > m_customNumFmtsHash;
  103. int m_nextCustomNumFmtId;
  104. QList<Format> m_fontsList;
  105. QList<Format> m_fillsList;
  106. QList<Format> m_bordersList;
  107. QHash<QByteArray, Format> m_fontsHash;
  108. QHash<QByteArray, Format> m_fillsHash;
  109. QHash<QByteArray, Format> m_bordersHash;
  110. QVector<QColor> m_indexedColors;
  111. bool m_isIndexedColorsDefault;
  112. QList<Format> m_xf_formatsList;
  113. QHash<QByteArray, Format> m_xf_formatsHash;
  114. QList<Format> m_dxf_formatsList;
  115. QHash<QByteArray, Format> m_dxf_formatsHash;
  116. bool m_emptyFormatAdded;
  117. };
  118. }
  119. #endif // XLSXSTYLES_H