File indexing completed on 2024-06-23 03:45:57

0001 /****************************************************************************
0002 ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
0003 ** All right reserved.
0004 **
0005 ** Permission is hereby granted, free of charge, to any person obtaining
0006 ** a copy of this software and associated documentation files (the
0007 ** "Software"), to deal in the Software without restriction, including
0008 ** without limitation the rights to use, copy, modify, merge, publish,
0009 ** distribute, sublicense, and/or sell copies of the Software, and to
0010 ** permit persons to whom the Software is furnished to do so, subject to
0011 ** the following conditions:
0012 **
0013 ** The above copyright notice and this permission notice shall be
0014 ** included in all copies or substantial portions of the Software.
0015 **
0016 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0017 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0018 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0019 ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
0020 ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0021 ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0022 ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0023 **
0024 ****************************************************************************/
0025 #ifndef XLSXSTYLES_H
0026 #define XLSXSTYLES_H
0027 
0028 //
0029 //  W A R N I N G
0030 //  -------------
0031 //
0032 // This file is not part of the Qt Xlsx API.  It exists for the convenience
0033 // of the Qt Xlsx.  This header file may change from
0034 // version to version without notice, or even be removed.
0035 //
0036 // We mean it.
0037 //
0038 
0039 #include <QSharedPointer>
0040 #include <QHash>
0041 #include <QList>
0042 #include <QMap>
0043 #include <QStringList>
0044 #include <QVector>
0045 #include <QXmlStreamWriter>
0046 #include <QXmlStreamReader>
0047 #include <QIODevice>
0048 
0049 // class StylesTest;
0050 
0051 #include "xlsxglobal.h"
0052 #include "xlsxformat.h"
0053 #include "xlsxabstractooxmlfile.h"
0054 
0055 QT_BEGIN_NAMESPACE_XLSX
0056 
0057 class Format;
0058 class XlsxColor;
0059 
0060 struct XlsxFormatNumberData
0061 {
0062     XlsxFormatNumberData() : formatIndex(0) {}
0063 
0064     int formatIndex;
0065     QString formatString;
0066 };
0067 
0068 class Styles : public AbstractOOXmlFile
0069 {
0070 public:
0071     Styles(CreateFlag flag);
0072     ~Styles();
0073     void addXfFormat(const Format &format, bool force=false);
0074     Format xfFormat(int idx) const;
0075     void addDxfFormat(const Format &format, bool force=false);
0076     Format dxfFormat(int idx) const;
0077 
0078     void saveToXmlFile(QIODevice *device) const override;
0079     bool loadFromXmlFile(QIODevice *device) override;
0080 
0081     QColor getColorByIndex(int idx);
0082 
0083 private:
0084     friend class Format;
0085     // friend class ::StylesTest;
0086 
0087     void fixNumFmt(const Format &format);
0088 
0089     void writeNumFmts(QXmlStreamWriter &writer) const;
0090     void writeFonts(QXmlStreamWriter &writer) const;
0091     void writeFont(QXmlStreamWriter &writer, const Format &font, bool isDxf = false) const;
0092     void writeFills(QXmlStreamWriter &writer) const;
0093     void writeFill(QXmlStreamWriter &writer, const Format &fill, bool isDxf = false) const;
0094     void writeBorders(QXmlStreamWriter &writer) const;
0095     void writeBorder(QXmlStreamWriter &writer, const Format &border, bool isDxf = false) const;
0096     void writeSubBorder(QXmlStreamWriter &writer, const QString &type, int style, const XlsxColor &color) const;
0097     void writeCellXfs(QXmlStreamWriter &writer) const;
0098     void writeDxfs(QXmlStreamWriter &writer) const;
0099     void writeDxf(QXmlStreamWriter &writer, const Format &format) const;
0100     void writeColors(QXmlStreamWriter &writer) const;
0101 
0102     bool readNumFmts(QXmlStreamReader &reader);
0103     bool readFonts(QXmlStreamReader &reader);
0104     bool readFont(QXmlStreamReader &reader, Format &format);
0105     bool readFills(QXmlStreamReader &reader);
0106     bool readFill(QXmlStreamReader &reader, Format &format);
0107     bool readBorders(QXmlStreamReader &reader);
0108     bool readBorder(QXmlStreamReader &reader, Format &format);
0109     bool readSubBorder(QXmlStreamReader &reader, const QString &name, Format::BorderStyle &style, XlsxColor &color);
0110     bool readCellXfs(QXmlStreamReader &reader);
0111     bool readDxfs(QXmlStreamReader &reader);
0112     bool readDxf(QXmlStreamReader &reader);
0113     bool readColors(QXmlStreamReader &reader);
0114     bool readIndexedColors(QXmlStreamReader &reader);
0115 
0116     bool readCellStyleXfs(QXmlStreamReader &reader);
0117 
0118     QHash<QString, int> m_builtinNumFmtsHash;
0119     QMap<int, QSharedPointer<XlsxFormatNumberData> > m_customNumFmtIdMap;
0120     QHash<QString, QSharedPointer<XlsxFormatNumberData> > m_customNumFmtsHash;
0121     int m_nextCustomNumFmtId;
0122     QList<Format> m_fontsList;
0123     QList<Format> m_fillsList;
0124     QList<Format> m_bordersList;
0125     QHash<QByteArray, Format> m_fontsHash;
0126     QHash<QByteArray, Format> m_fillsHash;
0127     QHash<QByteArray, Format> m_bordersHash;
0128 
0129     QVector<QColor> m_indexedColors;
0130     bool m_isIndexedColorsDefault;
0131 
0132     QList<Format> m_xf_formatsList;
0133     QHash<QByteArray, Format> m_xf_formatsHash;
0134 
0135     QList<Format> m_dxf_formatsList;
0136     QHash<QByteArray, Format> m_dxf_formatsHash;
0137 
0138     bool m_emptyFormatAdded;
0139 };
0140 
0141 QT_END_NAMESPACE_XLSX
0142 
0143 #endif // XLSXSTYLES_H