/**************************************************************************** ** Copyright (c) 2013 Debao Zhang ** All right reserved. ** ** Permission is hereby granted, free of charge, to any person obtaining ** a copy of this software and associated documentation files (the ** "Software"), to deal in the Software without restriction, including ** without limitation the rights to use, copy, modify, merge, publish, ** distribute, sublicense, and/or sell copies of the Software, and to ** permit persons to whom the Software is furnished to do so, subject to ** the following conditions: ** ** The above copyright notice and this permission notice shall be ** included in all copies or substantial portions of the Software. ** ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ** ****************************************************************************/ #ifndef XLSXSTYLES_H #define XLSXSTYLES_H #include "xlsxglobal.h" #include "xlsxformat.h" #include #include #include #include #include #include class QXmlStreamWriter; class QXmlStreamReader; class QIODevice; class StylesTest; namespace QXlsx { class Format; struct XlsxFormatNumberData { XlsxFormatNumberData() : formatIndex(0) {} int formatIndex; QString formatString; }; class XLSX_AUTOTEST_EXPORT Styles { public: Styles(bool createEmpty=false); ~Styles(); void addXfFormat(const Format &format, bool force=false); Format xfFormat(int idx) const; void addDxfFormat(const Format &format, bool force=false); Format dxfFormat(int idx) const; QByteArray saveToXmlData(); void saveToXmlFile(QIODevice *device); bool loadFromXmlFile(QIODevice *device); bool loadFromXmlData(const QByteArray &data); private: friend class Format; friend class ::StylesTest; void fixNumFmt(const Format &format); void writeNumFmts(QXmlStreamWriter &writer); void writeFonts(QXmlStreamWriter &writer); void writeFont(QXmlStreamWriter &writer, const Format &font, bool isDxf = false); void writeFills(QXmlStreamWriter &writer); void writeFill(QXmlStreamWriter &writer, const Format &fill, bool isDxf = false); void writeBorders(QXmlStreamWriter &writer); void writeBorder(QXmlStreamWriter &writer, const Format &border, bool isDxf = false); void writeSubBorder(QXmlStreamWriter &writer, const QString &type, int style, const QColor &color, const QString &themeColor); void writeCellXfs(QXmlStreamWriter &writer); void writeDxfs(QXmlStreamWriter &writer); void writeDxf(QXmlStreamWriter &writer, const Format &format); bool readNumFmts(QXmlStreamReader &reader); bool readFonts(QXmlStreamReader &reader); bool readFont(QXmlStreamReader &reader, Format &format); bool readFills(QXmlStreamReader &reader); bool readFill(QXmlStreamReader &reader, Format &format); bool readBorders(QXmlStreamReader &reader); bool readBorder(QXmlStreamReader &reader, Format &format); bool readSubBorder(QXmlStreamReader &reader, const QString &name, Format::BorderStyle &style, QColor &color, QString &themeColor); bool readCellXfs(QXmlStreamReader &reader); bool readDxfs(QXmlStreamReader &reader); bool readDxf(QXmlStreamReader &reader); bool readColors(QXmlStreamReader &reader); bool readIndexedColors(QXmlStreamReader &reader); QColor getColorByIndex(int idx); QHash m_builtinNumFmtsHash; QMap > m_customNumFmtIdMap; QHash > m_customNumFmtsHash; int m_nextCustomNumFmtId; QList m_fontsList; QList m_fillsList; QList m_bordersList; QHash m_fontsHash; QHash m_fillsHash; QHash m_bordersHash; QVector m_indexedColors; QList m_xf_formatsList; QHash m_xf_formatsHash; QList m_dxf_formatsList; QHash m_dxf_formatsHash; bool m_emptyFormatAdded; }; } #endif // XLSXSTYLES_H