/**************************************************************************** ** 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 XLSXFORMAT_P_H #define XLSXFORMAT_P_H #include "xlsxformat.h" #include namespace QXlsx { struct XlsxFormatNumberData { XlsxFormatNumberData() : formatIndex(0), _valid(true) {} int formatIndex; QString formatString; bool _valid; }; struct XlsxFormatFontData { XlsxFormatFontData() : size(11), italic(false), strikeOut(false), color(QColor()), bold(false) , scirpt(Format::FontScriptNormal), underline(Format::FontUnderlineNone) , outline(false), shadow(false), name(QStringLiteral("Calibri")), family(2), charset(0) , scheme(QStringLiteral("minor")), condense(0), extend(0) , _dirty(true), _indexValid(false), _index(-1) {} int size; bool italic; bool strikeOut; QColor color; QString themeColor; bool bold; Format::FontScript scirpt; Format::FontUnderline underline; bool outline; bool shadow; QString name; int family; int charset; QString scheme; int condense; int extend; QByteArray key() const { if (_dirty) { QByteArray key; QDataStream stream(&key, QIODevice::WriteOnly); stream<(this)->_key = key; const_cast(this)->_dirty = false; const_cast(this)->_indexValid = false;//dirty flag can not be simply cleared. } return _key; } bool indexValid() const { return !_dirty && _indexValid; } int index() const { return _index; } void setIndex(int index) { _index = index; _indexValid = true; } //helper member bool _dirty; //key re-generated and proper index assign is need. private: QByteArray _key; bool _indexValid; //has a valid index, so no need to assign a new one int _index; //index in the Font list }; struct XlsxFormatAlignmentData { XlsxFormatAlignmentData() : alignH(Format::AlignHGeneral), alignV(Format::AlignBottom) , wrap(false), rotation(0), indent(0), shinkToFit(false) {} Format::HorizontalAlignment alignH; Format::VerticalAlignment alignV; bool wrap; int rotation; int indent; bool shinkToFit; }; struct XlsxFormatBorderData { XlsxFormatBorderData() : left(Format::BorderNone), right(Format::BorderNone), top(Format::BorderNone) ,bottom(Format::BorderNone), diagonal(Format::BorderNone) ,diagonalType(Format::DiagonalBorderNone) ,_dirty(true), _indexValid(false), _index(-1) {} Format::BorderStyle left; Format::BorderStyle right; Format::BorderStyle top; Format::BorderStyle bottom; Format::BorderStyle diagonal; QColor leftColor; QColor rightColor; QColor topColor; QColor bottomColor; QColor diagonalColor; QString leftThemeColor; QString rightThemeColor; QString topThemeColor; QString bottomThemeColor; QString diagonalThemeColor; Format::DiagonalBorderType diagonalType; QByteArray key() const { if (_dirty) { QByteArray key; QDataStream stream(&key, QIODevice::WriteOnly); stream << bottom << bottomColor << bottomThemeColor << top << topColor << topThemeColor << diagonal << diagonalColor << diagonalThemeColor << diagonalType << left << leftColor << leftThemeColor << right << rightColor << rightThemeColor; const_cast(this)->_key = key; const_cast(this)->_dirty = false; const_cast(this)->_indexValid = false; } return _key; } bool indexValid() const { return !_dirty && _indexValid; } int index() const { return _index; } void setIndex(int index) { _index = index; _indexValid = true; } //helper member bool _dirty; //key re-generated and proper index assign is need. private: QByteArray _key; bool _indexValid; //has a valid index, so no need to assign a new one int _index; //index in the border list }; struct XlsxFormatFillData { XlsxFormatFillData() : pattern(Format::PatternNone) ,_dirty(true), _indexValid(false), _index(-1) {} Format::FillPattern pattern; QColor bgColor; QColor fgColor; QString bgThemeColor; QString fgThemeColor; QByteArray key() const { if (_dirty) { QByteArray key; QDataStream stream(&key, QIODevice::WriteOnly); stream<< bgColor << bgThemeColor << fgColor << fgThemeColor << pattern; const_cast(this)->_key = key; const_cast(this)->_dirty = false; const_cast(this)->_indexValid = false; } return _key; } bool indexValid() const { return !_dirty && _indexValid; } int index() const { return _index; } void setIndex(int index) { _index = index; _indexValid = true; } //helper member bool _dirty; //key re-generated and proper index assign is need. private: QByteArray _key; bool _indexValid; //has a valid index, so no need to assign a new one int _index; //index in the border list }; struct XlsxFormatProtectionData { XlsxFormatProtectionData() : locked(false), hidden(false) {} bool locked; bool hidden; }; class FormatPrivate : public QSharedData { public: FormatPrivate(); FormatPrivate(const FormatPrivate &other); ~FormatPrivate(); XlsxFormatNumberData numberData; XlsxFormatFontData fontData; XlsxFormatAlignmentData alignmentData; XlsxFormatBorderData borderData; XlsxFormatFillData fillData; XlsxFormatProtectionData protectionData; mutable bool dirty; //The key re-generation is need. mutable QByteArray formatKey; int xf_index; mutable bool xf_indexValid; bool is_dxf_fomat; int dxf_index; mutable bool dxf_indexValid; int theme; }; } #endif // XLSXFORMAT_P_H