Browse Source

Code refactor: Make use of QSharedDataPointer for Format

master
Debao Zhang 11 years ago
parent
commit
4bcce58f00
  1. 1
      src/xlsx/xlsxcell.cpp
  2. 156
      src/xlsx/xlsxformat.cpp
  3. 9
      src/xlsx/xlsxformat.h
  4. 20
      src/xlsx/xlsxformat_p.h
  5. 1
      src/xlsx/xlsxpackage.cpp
  6. 1
      src/xlsx/xlsxrichstring.cpp
  7. 16
      src/xlsx/xlsxsharedstrings.cpp
  8. 16
      src/xlsx/xlsxstyles.cpp
  9. 1
      src/xlsx/xlsxworkbook.cpp
  10. 1
      src/xlsx/xlsxworksheet.cpp

1
src/xlsx/xlsxcell.cpp

@ -25,6 +25,7 @@
#include "xlsxcell.h" #include "xlsxcell.h"
#include "xlsxcell_p.h" #include "xlsxcell_p.h"
#include "xlsxformat.h" #include "xlsxformat.h"
#include "xlsxformat_p.h"
#include "xlsxutility_p.h" #include "xlsxutility_p.h"
#include "xlsxworksheet.h" #include "xlsxworksheet.h"
#include "xlsxworkbook.h" #include "xlsxworkbook.h"

156
src/xlsx/xlsxformat.cpp

@ -30,8 +30,7 @@
QT_BEGIN_NAMESPACE_XLSX QT_BEGIN_NAMESPACE_XLSX
FormatPrivate::FormatPrivate(Format *p) : FormatPrivate::FormatPrivate()
q_ptr(p)
{ {
dirty = true; dirty = true;
@ -44,6 +43,23 @@ FormatPrivate::FormatPrivate(Format *p) :
theme = 0; theme = 0;
} }
FormatPrivate::FormatPrivate(const FormatPrivate &other)
: QSharedData(other)
, numberData(other.numberData), fontData(other.fontData), alignmentData(other.alignmentData)
, borderData(other.borderData), fillData(other.fillData), protectionData(other.protectionData)
, dirty(other.dirty), formatKey(other.formatKey)
, xf_index(other.xf_index), xf_indexValid(other.xf_indexValid)
, is_dxf_fomat(other.is_dxf_fomat), dxf_index(other.dxf_index), dxf_indexValid(other.dxf_indexValid)
, theme(other.theme)
{
}
FormatPrivate::~FormatPrivate()
{
}
/*! /*!
* \class Format * \class Format
* \inmodule QtXlsx * \inmodule QtXlsx
@ -52,20 +68,38 @@ FormatPrivate::FormatPrivate(Format *p) :
/*! /*!
* \internal * Creates a new format.
*/ */
Format::Format() : Format::Format() :
d_ptr(new FormatPrivate(this)) d(new FormatPrivate)
{ {
} }
/*! /*!
* \internal Creates a new format with the same attributes as the \a other format.
*/
Format::Format(const Format &other)
:d(other.d)
{
}
/*!
Assigns the \a other format to this format, and returns a
reference to this format.
*/
Format &Format::operator =(const Format &other)
{
d = other.d;
return *this;
}
/*!
* Destroys this format.
*/ */
Format::~Format() Format::~Format()
{ {
delete d_ptr;
} }
/*! /*!
@ -73,7 +107,6 @@ Format::~Format()
*/ */
int Format::numberFormatIndex() const int Format::numberFormatIndex() const
{ {
Q_D(const Format);
return d->numberData.formatIndex; return d->numberData.formatIndex;
} }
@ -84,7 +117,6 @@ int Format::numberFormatIndex() const
*/ */
void Format::setNumberFormatIndex(int format) void Format::setNumberFormatIndex(int format)
{ {
Q_D(Format);
d->dirty = true; d->dirty = true;
d->numberData.formatIndex = format; d->numberData.formatIndex = format;
d->numberData._valid = true; d->numberData._valid = true;
@ -97,7 +129,6 @@ void Format::setNumberFormatIndex(int format)
*/ */
QString Format::numberFormat() const QString Format::numberFormat() const
{ {
Q_D(const Format);
return d->numberData.formatString; return d->numberData.formatString;
} }
@ -107,7 +138,6 @@ QString Format::numberFormat() const
*/ */
void Format::setNumberFormat(const QString &format) void Format::setNumberFormat(const QString &format)
{ {
Q_D(Format);
if (format.isEmpty()) if (format.isEmpty())
return; return;
d->dirty = true; d->dirty = true;
@ -120,7 +150,6 @@ void Format::setNumberFormat(const QString &format)
*/ */
bool Format::isDateTimeFormat() const bool Format::isDateTimeFormat() const
{ {
Q_D(const Format);
if (d->numberData._valid && d->numberData.formatString.isEmpty()) { if (d->numberData._valid && d->numberData.formatString.isEmpty()) {
int idx = d->numberData.formatIndex; int idx = d->numberData.formatIndex;
//Built in date time number index //Built in date time number index
@ -141,7 +170,6 @@ bool Format::isDateTimeFormat() const
*/ */
bool Format::numFmtIndexValid() const bool Format::numFmtIndexValid() const
{ {
Q_D(const Format);
return d->numberData._valid; return d->numberData._valid;
} }
@ -150,7 +178,6 @@ bool Format::numFmtIndexValid() const
*/ */
void Format::setNumFmt(int index, const QString &string) void Format::setNumFmt(int index, const QString &string)
{ {
Q_D(Format);
d->numberData.formatIndex = index; d->numberData.formatIndex = index;
d->numberData.formatString = string; d->numberData.formatString = string;
d->numberData._valid = true; d->numberData._valid = true;
@ -161,7 +188,6 @@ void Format::setNumFmt(int index, const QString &string)
*/ */
int Format::fontSize() const int Format::fontSize() const
{ {
Q_D(const Format);
return d->fontData.size; return d->fontData.size;
} }
@ -170,7 +196,6 @@ int Format::fontSize() const
*/ */
void Format::setFontSize(int size) void Format::setFontSize(int size)
{ {
Q_D(Format);
d->fontData.size = size; d->fontData.size = size;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -180,7 +205,6 @@ void Format::setFontSize(int size)
*/ */
bool Format::fontItalic() const bool Format::fontItalic() const
{ {
Q_D(const Format);
return d->fontData.italic; return d->fontData.italic;
} }
@ -189,7 +213,6 @@ bool Format::fontItalic() const
*/ */
void Format::setFontItalic(bool italic) void Format::setFontItalic(bool italic)
{ {
Q_D(Format);
d->fontData.italic = italic; d->fontData.italic = italic;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -199,7 +222,6 @@ void Format::setFontItalic(bool italic)
*/ */
bool Format::fontStrikeOut() const bool Format::fontStrikeOut() const
{ {
Q_D(const Format);
return d->fontData.strikeOut; return d->fontData.strikeOut;
} }
@ -208,7 +230,6 @@ bool Format::fontStrikeOut() const
*/ */
void Format::setFontStrikeOut(bool strikeOut) void Format::setFontStrikeOut(bool strikeOut)
{ {
Q_D(Format);
d->fontData.strikeOut = strikeOut; d->fontData.strikeOut = strikeOut;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -218,7 +239,6 @@ void Format::setFontStrikeOut(bool strikeOut)
*/ */
QColor Format::fontColor() const QColor Format::fontColor() const
{ {
Q_D(const Format);
if (!d->fontData.color.isValid() && !d->fontData.themeColor.isEmpty()) { if (!d->fontData.color.isValid() && !d->fontData.themeColor.isEmpty()) {
//!Todo, get the real color from the theme{1}.xml file //!Todo, get the real color from the theme{1}.xml file
//The same is ture for border and fill colord //The same is ture for border and fill colord
@ -232,7 +252,6 @@ QColor Format::fontColor() const
*/ */
void Format::setFontColor(const QColor &color) void Format::setFontColor(const QColor &color)
{ {
Q_D(Format);
d->fontData.color = color; d->fontData.color = color;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -242,7 +261,6 @@ void Format::setFontColor(const QColor &color)
*/ */
bool Format::fontBold() const bool Format::fontBold() const
{ {
Q_D(const Format);
return d->fontData.bold; return d->fontData.bold;
} }
@ -251,7 +269,6 @@ bool Format::fontBold() const
*/ */
void Format::setFontBold(bool bold) void Format::setFontBold(bool bold)
{ {
Q_D(Format);
d->fontData.bold = bold; d->fontData.bold = bold;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -261,7 +278,6 @@ void Format::setFontBold(bool bold)
*/ */
Format::FontScript Format::fontScript() const Format::FontScript Format::fontScript() const
{ {
Q_D(const Format);
return d->fontData.scirpt; return d->fontData.scirpt;
} }
@ -270,7 +286,6 @@ Format::FontScript Format::fontScript() const
*/ */
void Format::setFontScript(FontScript script) void Format::setFontScript(FontScript script)
{ {
Q_D(Format);
d->fontData.scirpt = script; d->fontData.scirpt = script;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -280,7 +295,6 @@ void Format::setFontScript(FontScript script)
*/ */
Format::FontUnderline Format::fontUnderline() const Format::FontUnderline Format::fontUnderline() const
{ {
Q_D(const Format);
return d->fontData.underline; return d->fontData.underline;
} }
@ -289,7 +303,6 @@ Format::FontUnderline Format::fontUnderline() const
*/ */
void Format::setFontUnderline(FontUnderline underline) void Format::setFontUnderline(FontUnderline underline)
{ {
Q_D(Format);
d->fontData.underline = underline; d->fontData.underline = underline;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -299,7 +312,6 @@ void Format::setFontUnderline(FontUnderline underline)
*/ */
bool Format::fontOutline() const bool Format::fontOutline() const
{ {
Q_D(const Format);
return d->fontData.outline; return d->fontData.outline;
} }
@ -308,7 +320,6 @@ bool Format::fontOutline() const
*/ */
void Format::setFontOutline(bool outline) void Format::setFontOutline(bool outline)
{ {
Q_D(Format);
d->fontData.outline = outline; d->fontData.outline = outline;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -318,7 +329,6 @@ void Format::setFontOutline(bool outline)
*/ */
QString Format::fontName() const QString Format::fontName() const
{ {
Q_D(const Format);
return d->fontData.name; return d->fontData.name;
} }
@ -327,7 +337,6 @@ QString Format::fontName() const
*/ */
void Format::setFontName(const QString &name) void Format::setFontName(const QString &name)
{ {
Q_D(Format);
d->fontData.name = name; d->fontData.name = name;
d->fontData._dirty = true; d->fontData._dirty = true;
} }
@ -337,7 +346,6 @@ void Format::setFontName(const QString &name)
*/ */
bool Format::fontIndexValid() const bool Format::fontIndexValid() const
{ {
Q_D(const Format);
return d->fontData.indexValid(); return d->fontData.indexValid();
} }
@ -346,7 +354,6 @@ bool Format::fontIndexValid() const
*/ */
int Format::fontIndex() const int Format::fontIndex() const
{ {
Q_D(const Format);
return d->fontData.index(); return d->fontData.index();
} }
@ -355,7 +362,6 @@ int Format::fontIndex() const
*/ */
void Format::setFontIndex(int index) void Format::setFontIndex(int index)
{ {
Q_D(Format);
d->fontData.setIndex(index); d->fontData.setIndex(index);
} }
@ -364,7 +370,6 @@ void Format::setFontIndex(int index)
*/ */
int Format::fontFamily() const int Format::fontFamily() const
{ {
Q_D(const Format);
return d->fontData.family; return d->fontData.family;
} }
@ -373,7 +378,6 @@ int Format::fontFamily() const
*/ */
bool Format::fontShadow() const bool Format::fontShadow() const
{ {
Q_D(const Format);
return d->fontData.shadow; return d->fontData.shadow;
} }
@ -382,7 +386,6 @@ bool Format::fontShadow() const
*/ */
QString Format::fontScheme() const QString Format::fontScheme() const
{ {
Q_D(const Format);
return d->fontData.scheme; return d->fontData.scheme;
} }
@ -390,9 +393,8 @@ QString Format::fontScheme() const
*/ */
QByteArray Format::fontKey() const QByteArray Format::fontKey() const
{ {
Q_D(const Format);
if (d->fontData._dirty) if (d->fontData._dirty)
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated. d->dirty = true; //Make sure formatKey() will be re-generated.
return d->fontData.key(); return d->fontData.key();
} }
@ -401,7 +403,6 @@ QByteArray Format::fontKey() const
*/ */
Format::HorizontalAlignment Format::horizontalAlignment() const Format::HorizontalAlignment Format::horizontalAlignment() const
{ {
Q_D(const Format);
return d->alignmentData.alignH; return d->alignmentData.alignH;
} }
@ -410,7 +411,6 @@ Format::HorizontalAlignment Format::horizontalAlignment() const
*/ */
void Format::setHorizontalAlignment(HorizontalAlignment align) void Format::setHorizontalAlignment(HorizontalAlignment align)
{ {
Q_D(Format);
if (d->alignmentData.indent &&(align != AlignHGeneral && align != AlignLeft && if (d->alignmentData.indent &&(align != AlignHGeneral && align != AlignLeft &&
align != AlignRight && align != AlignHDistributed)) { align != AlignRight && align != AlignHDistributed)) {
d->alignmentData.indent = 0; d->alignmentData.indent = 0;
@ -430,7 +430,6 @@ void Format::setHorizontalAlignment(HorizontalAlignment align)
*/ */
Format::VerticalAlignment Format::verticalAlignment() const Format::VerticalAlignment Format::verticalAlignment() const
{ {
Q_D(const Format);
return d->alignmentData.alignV; return d->alignmentData.alignV;
} }
@ -439,7 +438,6 @@ Format::VerticalAlignment Format::verticalAlignment() const
*/ */
void Format::setVerticalAlignment(VerticalAlignment align) void Format::setVerticalAlignment(VerticalAlignment align)
{ {
Q_D(Format);
d->alignmentData.alignV = align; d->alignmentData.alignV = align;
d->dirty = true; d->dirty = true;
} }
@ -449,7 +447,6 @@ void Format::setVerticalAlignment(VerticalAlignment align)
*/ */
bool Format::textWrap() const bool Format::textWrap() const
{ {
Q_D(const Format);
return d->alignmentData.wrap; return d->alignmentData.wrap;
} }
@ -458,7 +455,6 @@ bool Format::textWrap() const
*/ */
void Format::setTextWarp(bool wrap) void Format::setTextWarp(bool wrap)
{ {
Q_D(Format);
if (wrap && d->alignmentData.shinkToFit) if (wrap && d->alignmentData.shinkToFit)
d->alignmentData.shinkToFit = false; d->alignmentData.shinkToFit = false;
@ -471,7 +467,6 @@ void Format::setTextWarp(bool wrap)
*/ */
int Format::rotation() const int Format::rotation() const
{ {
Q_D(const Format);
return d->alignmentData.rotation; return d->alignmentData.rotation;
} }
@ -480,7 +475,6 @@ int Format::rotation() const
*/ */
void Format::setRotation(int rotation) void Format::setRotation(int rotation)
{ {
Q_D(Format);
d->alignmentData.rotation = rotation; d->alignmentData.rotation = rotation;
d->dirty = true; d->dirty = true;
} }
@ -490,7 +484,6 @@ void Format::setRotation(int rotation)
*/ */
int Format::indent() const int Format::indent() const
{ {
Q_D(const Format);
return d->alignmentData.indent; return d->alignmentData.indent;
} }
@ -499,7 +492,6 @@ int Format::indent() const
*/ */
void Format::setIndent(int indent) void Format::setIndent(int indent)
{ {
Q_D(Format);
if (indent && (d->alignmentData.alignH != AlignHGeneral if (indent && (d->alignmentData.alignH != AlignHGeneral
&& d->alignmentData.alignH != AlignLeft && d->alignmentData.alignH != AlignLeft
&& d->alignmentData.alignH != AlignRight && d->alignmentData.alignH != AlignRight
@ -515,7 +507,6 @@ void Format::setIndent(int indent)
*/ */
bool Format::shrinkToFit() const bool Format::shrinkToFit() const
{ {
Q_D(const Format);
return d->alignmentData.shinkToFit; return d->alignmentData.shinkToFit;
} }
@ -524,7 +515,6 @@ bool Format::shrinkToFit() const
*/ */
void Format::setShrinkToFit(bool shink) void Format::setShrinkToFit(bool shink)
{ {
Q_D(Format);
if (shink && d->alignmentData.wrap) if (shink && d->alignmentData.wrap)
d->alignmentData.wrap = false; d->alignmentData.wrap = false;
if (shink && (d->alignmentData.alignH == AlignHFill if (shink && (d->alignmentData.alignH == AlignHFill
@ -542,7 +532,6 @@ void Format::setShrinkToFit(bool shink)
*/ */
bool Format::alignmentChanged() const bool Format::alignmentChanged() const
{ {
Q_D(const Format);
return d->alignmentData.alignH != AlignHGeneral return d->alignmentData.alignH != AlignHGeneral
|| d->alignmentData.alignV != AlignBottom || d->alignmentData.alignV != AlignBottom
|| d->alignmentData.indent != 0 || d->alignmentData.indent != 0
@ -553,7 +542,6 @@ bool Format::alignmentChanged() const
QString Format::horizontalAlignmentString() const QString Format::horizontalAlignmentString() const
{ {
Q_D(const Format);
QString alignH; QString alignH;
switch (d->alignmentData.alignH) { switch (d->alignmentData.alignH) {
case Format::AlignLeft: case Format::AlignLeft:
@ -585,7 +573,6 @@ QString Format::horizontalAlignmentString() const
QString Format::verticalAlignmentString() const QString Format::verticalAlignmentString() const
{ {
Q_D(const Format);
QString align; QString align;
switch (d->alignmentData.alignV) { switch (d->alignmentData.alignV) {
case AlignTop: case AlignTop:
@ -633,7 +620,6 @@ void Format::setBorderColor(const QColor &color)
*/ */
Format::BorderStyle Format::leftBorderStyle() const Format::BorderStyle Format::leftBorderStyle() const
{ {
Q_D(const Format);
return d->borderData.left; return d->borderData.left;
} }
@ -642,7 +628,6 @@ Format::BorderStyle Format::leftBorderStyle() const
*/ */
void Format::setLeftBorderStyle(BorderStyle style) void Format::setLeftBorderStyle(BorderStyle style)
{ {
Q_D(Format);
d->borderData.left = style; d->borderData.left = style;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
@ -652,149 +637,126 @@ void Format::setLeftBorderStyle(BorderStyle style)
*/ */
QColor Format::leftBorderColor() const QColor Format::leftBorderColor() const
{ {
Q_D(const Format);
return d->borderData.leftColor; return d->borderData.leftColor;
} }
void Format::setLeftBorderColor(const QColor &color) void Format::setLeftBorderColor(const QColor &color)
{ {
Q_D(Format);
d->borderData.leftColor = color; d->borderData.leftColor = color;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
Format::BorderStyle Format::rightBorderStyle() const Format::BorderStyle Format::rightBorderStyle() const
{ {
Q_D(const Format);
return d->borderData.right; return d->borderData.right;
} }
void Format::setRightBorderStyle(BorderStyle style) void Format::setRightBorderStyle(BorderStyle style)
{ {
Q_D(Format);
d->borderData.right = style; d->borderData.right = style;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
QColor Format::rightBorderColor() const QColor Format::rightBorderColor() const
{ {
Q_D(const Format);
return d->borderData.rightColor; return d->borderData.rightColor;
} }
void Format::setRightBorderColor(const QColor &color) void Format::setRightBorderColor(const QColor &color)
{ {
Q_D(Format);
d->borderData.rightColor = color; d->borderData.rightColor = color;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
Format::BorderStyle Format::topBorderStyle() const Format::BorderStyle Format::topBorderStyle() const
{ {
Q_D(const Format);
return d->borderData.top; return d->borderData.top;
} }
void Format::setTopBorderStyle(BorderStyle style) void Format::setTopBorderStyle(BorderStyle style)
{ {
Q_D(Format);
d->borderData.top = style; d->borderData.top = style;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
QColor Format::topBorderColor() const QColor Format::topBorderColor() const
{ {
Q_D(const Format);
return d->borderData.topColor; return d->borderData.topColor;
} }
void Format::setTopBorderColor(const QColor &color) void Format::setTopBorderColor(const QColor &color)
{ {
Q_D(Format);
d->borderData.topColor = color; d->borderData.topColor = color;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
Format::BorderStyle Format::bottomBorderStyle() const Format::BorderStyle Format::bottomBorderStyle() const
{ {
Q_D(const Format);
return d->borderData.bottom; return d->borderData.bottom;
} }
void Format::setBottomBorderStyle(BorderStyle style) void Format::setBottomBorderStyle(BorderStyle style)
{ {
Q_D(Format);
d->borderData.bottom = style; d->borderData.bottom = style;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
QColor Format::bottomBorderColor() const QColor Format::bottomBorderColor() const
{ {
Q_D(const Format);
return d->borderData.bottomColor; return d->borderData.bottomColor;
} }
void Format::setBottomBorderColor(const QColor &color) void Format::setBottomBorderColor(const QColor &color)
{ {
Q_D(Format);
d->borderData.bottomColor = color; d->borderData.bottomColor = color;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
Format::BorderStyle Format::diagonalBorderStyle() const Format::BorderStyle Format::diagonalBorderStyle() const
{ {
Q_D(const Format);
return d->borderData.diagonal; return d->borderData.diagonal;
} }
void Format::setDiagonalBorderStyle(BorderStyle style) void Format::setDiagonalBorderStyle(BorderStyle style)
{ {
Q_D(Format);
d->borderData.diagonal = style; d->borderData.diagonal = style;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
Format::DiagonalBorderType Format::diagonalBorderType() const Format::DiagonalBorderType Format::diagonalBorderType() const
{ {
Q_D(const Format);
return d->borderData.diagonalType; return d->borderData.diagonalType;
} }
void Format::setDiagonalBorderType(DiagonalBorderType style) void Format::setDiagonalBorderType(DiagonalBorderType style)
{ {
Q_D(Format);
d->borderData.diagonalType = style; d->borderData.diagonalType = style;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
QColor Format::diagonalBorderColor() const QColor Format::diagonalBorderColor() const
{ {
Q_D(const Format);
return d->borderData.diagonalColor; return d->borderData.diagonalColor;
} }
void Format::setDiagonalBorderColor(const QColor &color) void Format::setDiagonalBorderColor(const QColor &color)
{ {
Q_D(Format);
d->borderData.diagonalColor = color; d->borderData.diagonalColor = color;
d->borderData._dirty = true; d->borderData._dirty = true;
} }
bool Format::borderIndexValid() const bool Format::borderIndexValid() const
{ {
Q_D(const Format);
return d->borderData.indexValid(); return d->borderData.indexValid();
} }
int Format::borderIndex() const int Format::borderIndex() const
{ {
Q_D(const Format);
return d->borderData.index(); return d->borderData.index();
} }
void Format::setBorderIndex(int index) void Format::setBorderIndex(int index)
{ {
Q_D(Format);
d->borderData.setIndex(index); d->borderData.setIndex(index);
} }
@ -802,35 +764,30 @@ void Format::setBorderIndex(int index)
*/ */
QByteArray Format::borderKey() const QByteArray Format::borderKey() const
{ {
Q_D(const Format);
if (d->borderData._dirty) if (d->borderData._dirty)
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated. d->dirty = true; //Make sure formatKey() will be re-generated.
return d->borderData.key(); return d->borderData.key();
} }
Format::FillPattern Format::fillPattern() const Format::FillPattern Format::fillPattern() const
{ {
Q_D(const Format);
return d->fillData.pattern; return d->fillData.pattern;
} }
void Format::setFillPattern(FillPattern pattern) void Format::setFillPattern(FillPattern pattern)
{ {
Q_D(Format);
d->fillData.pattern = pattern; d->fillData.pattern = pattern;
d->fillData._dirty = true; d->fillData._dirty = true;
} }
QColor Format::patternForegroundColor() const QColor Format::patternForegroundColor() const
{ {
Q_D(const Format);
return d->fillData.fgColor; return d->fillData.fgColor;
} }
void Format::setPatternForegroundColor(const QColor &color) void Format::setPatternForegroundColor(const QColor &color)
{ {
Q_D(Format);
if (color.isValid() && d->fillData.pattern == PatternNone) if (color.isValid() && d->fillData.pattern == PatternNone)
d->fillData.pattern = PatternSolid; d->fillData.pattern = PatternSolid;
d->fillData.fgColor = color; d->fillData.fgColor = color;
@ -839,13 +796,11 @@ void Format::setPatternForegroundColor(const QColor &color)
QColor Format::patternBackgroundColor() const QColor Format::patternBackgroundColor() const
{ {
Q_D(const Format);
return d->fillData.bgColor; return d->fillData.bgColor;
} }
void Format::setPatternBackgroundColor(const QColor &color) void Format::setPatternBackgroundColor(const QColor &color)
{ {
Q_D(Format);
if (color.isValid() && d->fillData.pattern == PatternNone) if (color.isValid() && d->fillData.pattern == PatternNone)
d->fillData.pattern = PatternSolid; d->fillData.pattern = PatternSolid;
d->fillData.bgColor = color; d->fillData.bgColor = color;
@ -854,19 +809,16 @@ void Format::setPatternBackgroundColor(const QColor &color)
bool Format::fillIndexValid() const bool Format::fillIndexValid() const
{ {
Q_D(const Format);
return d->fillData.indexValid(); return d->fillData.indexValid();
} }
int Format::fillIndex() const int Format::fillIndex() const
{ {
Q_D(const Format);
return d->fillData.index(); return d->fillData.index();
} }
void Format::setFillIndex(int index) void Format::setFillIndex(int index)
{ {
Q_D(Format);
d->fillData.setIndex(index); d->fillData.setIndex(index);
} }
@ -874,42 +826,36 @@ void Format::setFillIndex(int index)
*/ */
QByteArray Format::fillKey() const QByteArray Format::fillKey() const
{ {
Q_D(const Format);
if (d->fillData._dirty) if (d->fillData._dirty)
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated. d->dirty = true; //Make sure formatKey() will be re-generated.
return d->fillData.key(); return d->fillData.key();
} }
bool Format::hidden() const bool Format::hidden() const
{ {
Q_D(const Format);
return d->protectionData.hidden; return d->protectionData.hidden;
} }
void Format::setHidden(bool hidden) void Format::setHidden(bool hidden)
{ {
Q_D(Format);
d->protectionData.hidden = hidden; d->protectionData.hidden = hidden;
d->dirty = true; d->dirty = true;
} }
bool Format::locked() const bool Format::locked() const
{ {
Q_D(const Format);
return d->protectionData.locked; return d->protectionData.locked;
} }
void Format::setLocked(bool locked) void Format::setLocked(bool locked)
{ {
Q_D(Format);
d->protectionData.locked = locked; d->protectionData.locked = locked;
d->dirty = true; d->dirty = true;
} }
QByteArray Format::formatKey() const QByteArray Format::formatKey() const
{ {
Q_D(const Format);
if (d->dirty || d->fontData._dirty || d->borderData._dirty || d->fillData._dirty) { if (d->dirty || d->fontData._dirty || d->borderData._dirty || d->fillData._dirty) {
QByteArray key; QByteArray key;
QDataStream stream(&key, QIODevice::WriteOnly); QDataStream stream(&key, QIODevice::WriteOnly);
@ -918,10 +864,10 @@ QByteArray Format::formatKey() const
<<d->alignmentData.alignH<<d->alignmentData.alignV<<d->alignmentData.indent <<d->alignmentData.alignH<<d->alignmentData.alignV<<d->alignmentData.indent
<<d->alignmentData.rotation<<d->alignmentData.shinkToFit<<d->alignmentData.wrap <<d->alignmentData.rotation<<d->alignmentData.shinkToFit<<d->alignmentData.wrap
<<d->protectionData.hidden<<d->protectionData.locked; <<d->protectionData.hidden<<d->protectionData.locked;
const_cast<FormatPrivate*>(d)->formatKey = key; d->formatKey = key;
const_cast<FormatPrivate*>(d)->dirty = false; d->dirty = false;
const_cast<FormatPrivate*>(d)->xf_indexValid = false; d->xf_indexValid = false;
const_cast<FormatPrivate*>(d)->dxf_indexValid = false; d->dxf_indexValid = false;
} }
return d->formatKey; return d->formatKey;
@ -929,39 +875,33 @@ QByteArray Format::formatKey() const
void Format::setXfIndex(int index) void Format::setXfIndex(int index)
{ {
Q_D(Format);
d->xf_index = index; d->xf_index = index;
d->xf_indexValid = true; d->xf_indexValid = true;
} }
int Format::xfIndex() const int Format::xfIndex() const
{ {
Q_D(const Format);
return d->xf_index; return d->xf_index;
} }
bool Format::xfIndexValid() const bool Format::xfIndexValid() const
{ {
Q_D(const Format);
return !d->dirty && d->xf_indexValid; return !d->dirty && d->xf_indexValid;
} }
void Format::setDxfIndex(int index) void Format::setDxfIndex(int index)
{ {
Q_D(Format);
d->dxf_index = index; d->dxf_index = index;
d->dxf_indexValid = true; d->dxf_indexValid = true;
} }
int Format::dxfIndex() const int Format::dxfIndex() const
{ {
Q_D(const Format);
return d->dxf_index; return d->dxf_index;
} }
bool Format::dxfIndexValid() const bool Format::dxfIndexValid() const
{ {
Q_D(const Format);
return !d->dirty && d->dxf_indexValid; return !d->dirty && d->dxf_indexValid;
} }
@ -977,13 +917,11 @@ bool Format::operator !=(const Format &format) const
bool Format::isDxfFormat() const bool Format::isDxfFormat() const
{ {
Q_D(const Format);
return d->is_dxf_fomat; return d->is_dxf_fomat;
} }
int Format::theme() const int Format::theme() const
{ {
Q_D(const Format);
return d->theme; return d->theme;
} }

9
src/xlsx/xlsxformat.h

@ -30,6 +30,7 @@
#include <QColor> #include <QColor>
#include <QByteArray> #include <QByteArray>
#include <QList> #include <QList>
#include <QSharedDataPointer>
class FormatTest; class FormatTest;
@ -44,7 +45,6 @@ class SharedStrings;
class FormatPrivate; class FormatPrivate;
class Q_XLSX_EXPORT Format class Q_XLSX_EXPORT Format
{ {
Q_DECLARE_PRIVATE(Format)
public: public:
enum FontScript enum FontScript
{ {
@ -132,6 +132,9 @@ public:
PatternLightGrid PatternLightGrid
}; };
Format();
Format(const Format &other);
Format &operator=(const Format &rhs);
~Format(); ~Format();
int numberFormatIndex() const; int numberFormatIndex() const;
@ -220,8 +223,6 @@ private:
friend class SharedStrings; friend class SharedStrings;
friend class ::FormatTest; friend class ::FormatTest;
Format();
bool numFmtIndexValid() const; bool numFmtIndexValid() const;
void setNumFmt(int index, const QString &string); void setNumFmt(int index, const QString &string);
@ -258,7 +259,7 @@ private:
int theme() const; int theme() const;
FormatPrivate * const d_ptr; QSharedDataPointer<FormatPrivate> d;
}; };
QT_END_NAMESPACE_XLSX QT_END_NAMESPACE_XLSX

20
src/xlsx/xlsxformat_p.h

@ -25,6 +25,7 @@
#ifndef XLSXFORMAT_P_H #ifndef XLSXFORMAT_P_H
#define XLSXFORMAT_P_H #define XLSXFORMAT_P_H
#include "xlsxformat.h" #include "xlsxformat.h"
#include <QSharedData>
namespace QXlsx { namespace QXlsx {
@ -250,11 +251,12 @@ struct XlsxFormatProtectionData {
bool hidden; bool hidden;
}; };
class FormatPrivate class FormatPrivate : public QSharedData
{ {
Q_DECLARE_PUBLIC(Format)
public: public:
FormatPrivate(Format *p); FormatPrivate();
FormatPrivate(const FormatPrivate &other);
~FormatPrivate();
XlsxFormatNumberData numberData; XlsxFormatNumberData numberData;
XlsxFormatFontData fontData; XlsxFormatFontData fontData;
@ -263,21 +265,17 @@ public:
XlsxFormatFillData fillData; XlsxFormatFillData fillData;
XlsxFormatProtectionData protectionData; XlsxFormatProtectionData protectionData;
bool dirty; //The key re-generation is need. mutable bool dirty; //The key re-generation is need.
QByteArray formatKey; mutable QByteArray formatKey;
static QList<Format *> s_xfFormats;
int xf_index; int xf_index;
bool xf_indexValid; mutable bool xf_indexValid;
static QList<Format *> s_dxfFormats;
bool is_dxf_fomat; bool is_dxf_fomat;
int dxf_index; int dxf_index;
bool dxf_indexValid; mutable bool dxf_indexValid;
int theme; int theme;
Format *q_ptr;
}; };
} }

1
src/xlsx/xlsxpackage.cpp

@ -38,6 +38,7 @@
#include "xlsxdrawing_p.h" #include "xlsxdrawing_p.h"
#include "xlsxzipreader_p.h" #include "xlsxzipreader_p.h"
#include "xlsxdocument.h" #include "xlsxdocument.h"
#include "xlsxformat_p.h"
#include <QBuffer> #include <QBuffer>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>

1
src/xlsx/xlsxrichstring.cpp

@ -23,6 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "xlsxrichstring_p.h" #include "xlsxrichstring_p.h"
#include "xlsxformat_p.h"
QT_BEGIN_NAMESPACE_XLSX QT_BEGIN_NAMESPACE_XLSX

16
src/xlsx/xlsxsharedstrings.cpp

@ -130,7 +130,7 @@ void SharedStrings::writeRichStringPart_rPr(XmlStreamWriter &writer, Format *for
if (!format) if (!format)
return; return;
XlsxFormatFontData *font = &format->d_ptr->fontData; XlsxFormatFontData *font = &format->d->fontData;
if (font->bold) if (font->bold)
writer.writeEmptyElement(QStringLiteral("b")); writer.writeEmptyElement(QStringLiteral("b"));
@ -303,9 +303,9 @@ Format *SharedStrings::readRichStringPart_rPr(XmlStreamReader &reader, RichStrin
if (reader.name() == QLatin1String("rFont")) { if (reader.name() == QLatin1String("rFont")) {
format->setFontName(attributes.value(QLatin1String("val")).toString()); format->setFontName(attributes.value(QLatin1String("val")).toString());
} else if (reader.name() == QLatin1String("charset")) { } else if (reader.name() == QLatin1String("charset")) {
format->d_ptr->fontData.charset = attributes.value(QLatin1String("val")).toString().toInt(); format->d->fontData.charset = attributes.value(QLatin1String("val")).toString().toInt();
} else if (reader.name() == QLatin1String("family")) { } else if (reader.name() == QLatin1String("family")) {
format->d_ptr->fontData.family = attributes.value(QLatin1String("val")).toString().toInt(); format->d->fontData.family = attributes.value(QLatin1String("val")).toString().toInt();
} else if (reader.name() == QLatin1String("b")) { } else if (reader.name() == QLatin1String("b")) {
format->setFontBold(true); format->setFontBold(true);
} else if (reader.name() == QLatin1String("i")) { } else if (reader.name() == QLatin1String("i")) {
@ -315,11 +315,11 @@ Format *SharedStrings::readRichStringPart_rPr(XmlStreamReader &reader, RichStrin
} else if (reader.name() == QLatin1String("outline")) { } else if (reader.name() == QLatin1String("outline")) {
format->setFontOutline(true); format->setFontOutline(true);
} else if (reader.name() == QLatin1String("shadow")) { } else if (reader.name() == QLatin1String("shadow")) {
format->d_ptr->fontData.shadow = true; format->d->fontData.shadow = true;
} else if (reader.name() == QLatin1String("condense")) { } else if (reader.name() == QLatin1String("condense")) {
format->d_ptr->fontData.condense = attributes.value(QLatin1String("val")).toString().toInt(); format->d->fontData.condense = attributes.value(QLatin1String("val")).toString().toInt();
} else if (reader.name() == QLatin1String("extend")) { } else if (reader.name() == QLatin1String("extend")) {
format->d_ptr->fontData.extend = attributes.value(QLatin1String("val")).toString().toInt(); format->d->fontData.extend = attributes.value(QLatin1String("val")).toString().toInt();
} else if (reader.name() == QLatin1String("color")) { } else if (reader.name() == QLatin1String("color")) {
if (attributes.hasAttribute(QLatin1String("rgb"))) { if (attributes.hasAttribute(QLatin1String("rgb"))) {
QString colorString = attributes.value(QLatin1String("rgb")).toString(); QString colorString = attributes.value(QLatin1String("rgb")).toString();
@ -329,7 +329,7 @@ Format *SharedStrings::readRichStringPart_rPr(XmlStreamReader &reader, RichStrin
} else if (attributes.hasAttribute(QLatin1String("theme"))) { } else if (attributes.hasAttribute(QLatin1String("theme"))) {
QString theme = attributes.value(QLatin1String("theme")).toString(); QString theme = attributes.value(QLatin1String("theme")).toString();
QString tint = attributes.value(QLatin1String("tint")).toString(); QString tint = attributes.value(QLatin1String("tint")).toString();
format->d_ptr->fontData.themeColor = theme + QLatin1Char(':') + tint; format->d->fontData.themeColor = theme + QLatin1Char(':') + tint;
} }
} else if (reader.name() == QLatin1String("sz")) { } else if (reader.name() == QLatin1String("sz")) {
format->setFontSize(attributes.value(QLatin1String("val")).toString().toInt()); format->setFontSize(attributes.value(QLatin1String("val")).toString().toInt());
@ -350,7 +350,7 @@ Format *SharedStrings::readRichStringPart_rPr(XmlStreamReader &reader, RichStrin
else if (value == QLatin1String("subscript")) else if (value == QLatin1String("subscript"))
format->setFontScript(Format::FontScriptSub); format->setFontScript(Format::FontScriptSub);
} else if (reader.name() == QLatin1String("scheme")) { } else if (reader.name() == QLatin1String("scheme")) {
format->d_ptr->fontData.scheme = attributes.value(QLatin1String("val")).toString(); format->d->fontData.scheme = attributes.value(QLatin1String("val")).toString();
} }
} }
} }

16
src/xlsx/xlsxstyles.cpp

@ -138,7 +138,7 @@ void Styles::addFormat(Format *format, bool force)
//Assign a new fmt Id. //Assign a new fmt Id.
format->setNumFmt(m_nextCustomNumFmtId, str); format->setNumFmt(m_nextCustomNumFmtId, str);
QSharedPointer<XlsxFormatNumberData> fmt(new XlsxFormatNumberData(format->d_func()->numberData)); QSharedPointer<XlsxFormatNumberData> fmt(new XlsxFormatNumberData(format->d->numberData));
m_customNumFmtIdMap.insert(m_nextCustomNumFmtId, fmt); m_customNumFmtIdMap.insert(m_nextCustomNumFmtId, fmt);
m_customNumFmtsHash.insert(str, fmt); m_customNumFmtsHash.insert(str, fmt);
@ -149,7 +149,7 @@ void Styles::addFormat(Format *format, bool force)
//Font //Font
if (!format->fontIndexValid()) { if (!format->fontIndexValid()) {
if (!m_fontsHash.contains(format->fontKey())) { if (!m_fontsHash.contains(format->fontKey())) {
QSharedPointer<XlsxFormatFontData> font = QSharedPointer<XlsxFormatFontData>(new XlsxFormatFontData(format->d_func()->fontData)); QSharedPointer<XlsxFormatFontData> font = QSharedPointer<XlsxFormatFontData>(new XlsxFormatFontData(format->d->fontData));
font->setIndex(m_fontsList.size()); //Assign proper index font->setIndex(m_fontsList.size()); //Assign proper index
m_fontsList.append(font); m_fontsList.append(font);
m_fontsHash[font->key()] = font; m_fontsHash[font->key()] = font;
@ -160,7 +160,7 @@ void Styles::addFormat(Format *format, bool force)
//Fill //Fill
if (!format->fillIndexValid()) { if (!format->fillIndexValid()) {
if (!m_fillsHash.contains(format->fillKey())) { if (!m_fillsHash.contains(format->fillKey())) {
QSharedPointer<XlsxFormatFillData> fill = QSharedPointer<XlsxFormatFillData>(new XlsxFormatFillData(format->d_func()->fillData)); QSharedPointer<XlsxFormatFillData> fill = QSharedPointer<XlsxFormatFillData>(new XlsxFormatFillData(format->d->fillData));
fill->setIndex(m_fillsList.size()); //Assign proper index fill->setIndex(m_fillsList.size()); //Assign proper index
m_fillsList.append(fill); m_fillsList.append(fill);
m_fillsHash[fill->key()] = fill; m_fillsHash[fill->key()] = fill;
@ -171,7 +171,7 @@ void Styles::addFormat(Format *format, bool force)
//Border //Border
if (!format->borderIndexValid()) { if (!format->borderIndexValid()) {
if (!m_bordersHash.contains(format->borderKey())) { if (!m_bordersHash.contains(format->borderKey())) {
QSharedPointer<XlsxFormatBorderData> border = QSharedPointer<XlsxFormatBorderData>(new XlsxFormatBorderData(format->d_func()->borderData)); QSharedPointer<XlsxFormatBorderData> border = QSharedPointer<XlsxFormatBorderData>(new XlsxFormatBorderData(format->d->borderData));
border->setIndex(m_bordersList.size()); //Assign proper index border->setIndex(m_bordersList.size()); //Assign proper index
m_bordersList.append(border); m_bordersList.append(border);
m_bordersHash[border->key()] = border; m_bordersHash[border->key()] = border;
@ -897,7 +897,7 @@ bool Styles::readCellXfs(XmlStreamReader &reader)
if (!m_customNumFmtIdMap.contains(numFmtIndex)) if (!m_customNumFmtIdMap.contains(numFmtIndex))
format->setNumberFormatIndex(numFmtIndex); format->setNumberFormatIndex(numFmtIndex);
else else
format->d_func()->numberData = *m_customNumFmtIdMap[numFmtIndex]; format->d->numberData = *m_customNumFmtIdMap[numFmtIndex];
} }
if (xfAttrs.hasAttribute(QLatin1String("applyFont"))) { if (xfAttrs.hasAttribute(QLatin1String("applyFont"))) {
@ -905,7 +905,7 @@ bool Styles::readCellXfs(XmlStreamReader &reader)
if (fontIndex >= m_fontsList.size()) { if (fontIndex >= m_fontsList.size()) {
qDebug("Error read styles.xml, cellXfs fontId"); qDebug("Error read styles.xml, cellXfs fontId");
} else { } else {
format->d_func()->fontData = *m_fontsList[fontIndex]; format->d->fontData = *m_fontsList[fontIndex];
} }
} }
@ -914,7 +914,7 @@ bool Styles::readCellXfs(XmlStreamReader &reader)
if (id >= m_fillsList.size()) { if (id >= m_fillsList.size()) {
qDebug("Error read styles.xml, cellXfs fillId"); qDebug("Error read styles.xml, cellXfs fillId");
} else { } else {
format->d_func()->fillData = *m_fillsList[id]; format->d->fillData = *m_fillsList[id];
} }
} }
@ -923,7 +923,7 @@ bool Styles::readCellXfs(XmlStreamReader &reader)
if (id >= m_bordersList.size()) { if (id >= m_bordersList.size()) {
qDebug("Error read styles.xml, cellXfs borderId"); qDebug("Error read styles.xml, cellXfs borderId");
} else { } else {
format->d_func()->borderData = *m_bordersList[id]; format->d->borderData = *m_bordersList[id];
} }
} }

1
src/xlsx/xlsxworkbook.cpp

@ -32,6 +32,7 @@
#include "xlsxxmlwriter_p.h" #include "xlsxxmlwriter_p.h"
#include "xlsxxmlreader_p.h" #include "xlsxxmlreader_p.h"
#include "xlsxworksheet_p.h" #include "xlsxworksheet_p.h"
#include "xlsxformat_p.h"
#include <QFile> #include <QFile>
#include <QBuffer> #include <QBuffer>

1
src/xlsx/xlsxworksheet.cpp

@ -27,6 +27,7 @@
#include "xlsxworksheet_p.h" #include "xlsxworksheet_p.h"
#include "xlsxworkbook.h" #include "xlsxworkbook.h"
#include "xlsxformat.h" #include "xlsxformat.h"
#include "xlsxformat_p.h"
#include "xlsxutility_p.h" #include "xlsxutility_p.h"
#include "xlsxsharedstrings_p.h" #include "xlsxsharedstrings_p.h"
#include "xlsxxmlwriter_p.h" #include "xlsxxmlwriter_p.h"

Loading…
Cancel
Save