xlsxstyles_p.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 <QSharedPointer>
  38. #include <QHash>
  39. #include <QList>
  40. #include <QMap>
  41. #include <QStringList>
  42. #include <QVector>
  43. #include <QXmlStreamWriter>
  44. #include <QXmlStreamReader>
  45. #include <QIODevice>
  46. // class StylesTest;
  47. #include "xlsxglobal.h"
  48. #include "xlsxformat.h"
  49. #include "xlsxabstractooxmlfile.h"
  50. QT_BEGIN_NAMESPACE_XLSX
  51. class Format;
  52. class XlsxColor;
  53. struct XlsxFormatNumberData
  54. {
  55. XlsxFormatNumberData() : formatIndex(0) {}
  56. int formatIndex;
  57. QString formatString;
  58. };
  59. class 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. #if QT_VERSION >= 0x050600
  71. QColor getColorByIndex(int idx);
  72. #endif
  73. private:
  74. friend class Format;
  75. // friend class ::StylesTest;
  76. void fixNumFmt(const Format &format);
  77. void writeNumFmts(QXmlStreamWriter &writer) const;
  78. void writeFonts(QXmlStreamWriter &writer) const;
  79. void writeFont(QXmlStreamWriter &writer, const Format &font, bool isDxf = false) const;
  80. void writeFills(QXmlStreamWriter &writer) const;
  81. void writeFill(QXmlStreamWriter &writer, const Format &fill, bool isDxf = false) const;
  82. void writeBorders(QXmlStreamWriter &writer) const;
  83. void writeBorder(QXmlStreamWriter &writer, const Format &border, bool isDxf = false) const;
  84. void writeSubBorder(QXmlStreamWriter &writer, const QString &type, int style, const XlsxColor &color) const;
  85. void writeCellXfs(QXmlStreamWriter &writer) const;
  86. void writeDxfs(QXmlStreamWriter &writer) const;
  87. void writeDxf(QXmlStreamWriter &writer, const Format &format) const;
  88. void writeColors(QXmlStreamWriter &writer) const;
  89. bool readNumFmts(QXmlStreamReader &reader);
  90. bool readFonts(QXmlStreamReader &reader);
  91. bool readFont(QXmlStreamReader &reader, Format &format);
  92. bool readFills(QXmlStreamReader &reader);
  93. bool readFill(QXmlStreamReader &reader, Format &format);
  94. bool readBorders(QXmlStreamReader &reader);
  95. bool readBorder(QXmlStreamReader &reader, Format &format);
  96. bool readSubBorder(QXmlStreamReader &reader, const QString &name, Format::BorderStyle &style, XlsxColor &color);
  97. bool readCellXfs(QXmlStreamReader &reader);
  98. bool readDxfs(QXmlStreamReader &reader);
  99. bool readDxf(QXmlStreamReader &reader);
  100. bool readColors(QXmlStreamReader &reader);
  101. bool readIndexedColors(QXmlStreamReader &reader);
  102. bool readCellStyleXfs(QXmlStreamReader &reader);
  103. QHash<QString, int> m_builtinNumFmtsHash;
  104. QMap<int, QSharedPointer<XlsxFormatNumberData> > m_customNumFmtIdMap;
  105. QHash<QString, QSharedPointer<XlsxFormatNumberData> > m_customNumFmtsHash;
  106. int m_nextCustomNumFmtId;
  107. QList<Format> m_fontsList;
  108. QList<Format> m_fillsList;
  109. QList<Format> m_bordersList;
  110. QHash<QByteArray, Format> m_fontsHash;
  111. QHash<QByteArray, Format> m_fillsHash;
  112. QHash<QByteArray, Format> m_bordersHash;
  113. QVector<QColor> m_indexedColors;
  114. bool m_isIndexedColorsDefault;
  115. QList<Format> m_xf_formatsList;
  116. QHash<QByteArray, Format> m_xf_formatsHash;
  117. QList<Format> m_dxf_formatsList;
  118. QHash<QByteArray, Format> m_dxf_formatsHash;
  119. bool m_emptyFormatAdded;
  120. };
  121. QT_END_NAMESPACE_XLSX
  122. #endif // XLSXSTYLES_H