Browse Source

Code refactor: Remove private class XlsxFormatBorderData

master
Debao Zhang 11 years ago
parent
commit
4670445888
  1. 88
      src/xlsx/xlsxformat.cpp
  2. 91
      src/xlsx/xlsxformat_p.h
  3. 112
      src/xlsx/xlsxstyles.cpp
  4. 5
      src/xlsx/xlsxstyles_p.h
  5. 14
      tests/auto/styles/tst_stylestest.cpp

88
src/xlsx/xlsxformat.cpp

@ -33,6 +33,7 @@ QT_BEGIN_NAMESPACE_XLSX
FormatPrivate::FormatPrivate() FormatPrivate::FormatPrivate()
: dirty(true) : dirty(true)
, font_dirty(true), font_index_valid(false), font_index(-1) , font_dirty(true), font_index_valid(false), font_index(-1)
, border_dirty(true), border_index_valid(false), border_index(-1)
, xf_index(-1), xf_indexValid(false) , xf_index(-1), xf_indexValid(false)
, is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false) , is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false)
, theme(0) , theme(0)
@ -42,9 +43,9 @@ FormatPrivate::FormatPrivate()
FormatPrivate::FormatPrivate(const FormatPrivate &other) FormatPrivate::FormatPrivate(const FormatPrivate &other)
: QSharedData(other) : QSharedData(other)
, alignmentData(other.alignmentData) , alignmentData(other.alignmentData)
, borderData(other.borderData), fillData(other.fillData), protectionData(other.protectionData)
, dirty(other.dirty), formatKey(other.formatKey) , dirty(other.dirty), formatKey(other.formatKey)
, font_dirty(other.dirty), font_index_valid(other.font_index_valid), font_key(other.font_key), font_index(other.font_index) , font_dirty(other.font_dirty), font_index_valid(other.font_index_valid), font_key(other.font_key), font_index(other.font_index)
, border_dirty(other.border_dirty), border_index_valid(other.border_index_valid), border_key(other.border_key), border_index(other.border_index)
, xf_index(other.xf_index), xf_indexValid(other.xf_indexValid) , 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) , is_dxf_fomat(other.is_dxf_fomat), dxf_index(other.dxf_index), dxf_indexValid(other.dxf_indexValid)
, theme(other.theme) , theme(other.theme)
@ -594,7 +595,7 @@ void Format::setBorderColor(const QColor &color)
*/ */
Format::BorderStyle Format::leftBorderStyle() const Format::BorderStyle Format::leftBorderStyle() const
{ {
return d->borderData.left; return static_cast<BorderStyle>(intProperty(FormatPrivate::P_Border_LeftStyle));
} }
/*! /*!
@ -602,8 +603,7 @@ Format::BorderStyle Format::leftBorderStyle() const
*/ */
void Format::setLeftBorderStyle(BorderStyle style) void Format::setLeftBorderStyle(BorderStyle style)
{ {
d->borderData.left = style; setProperty(FormatPrivate::P_Border_LeftStyle, style);
d->borderData._dirty = true;
} }
/*! /*!
@ -611,137 +611,136 @@ void Format::setLeftBorderStyle(BorderStyle style)
*/ */
QColor Format::leftBorderColor() const QColor Format::leftBorderColor() const
{ {
return d->borderData.leftColor; return colorProperty(FormatPrivate::P_Border_LeftColor);
} }
void Format::setLeftBorderColor(const QColor &color) void Format::setLeftBorderColor(const QColor &color)
{ {
d->borderData.leftColor = color; setProperty(FormatPrivate::P_Border_LeftColor, color);
d->borderData._dirty = true;
} }
Format::BorderStyle Format::rightBorderStyle() const Format::BorderStyle Format::rightBorderStyle() const
{ {
return d->borderData.right; return static_cast<BorderStyle>(intProperty(FormatPrivate::P_Border_RightStyle));
} }
void Format::setRightBorderStyle(BorderStyle style) void Format::setRightBorderStyle(BorderStyle style)
{ {
d->borderData.right = style; setProperty(FormatPrivate::P_Border_RightStyle, style);
d->borderData._dirty = true;
} }
QColor Format::rightBorderColor() const QColor Format::rightBorderColor() const
{ {
return d->borderData.rightColor; return colorProperty(FormatPrivate::P_Border_RightColor);
} }
void Format::setRightBorderColor(const QColor &color) void Format::setRightBorderColor(const QColor &color)
{ {
d->borderData.rightColor = color; setProperty(FormatPrivate::P_Border_RightColor, color);
d->borderData._dirty = true;
} }
Format::BorderStyle Format::topBorderStyle() const Format::BorderStyle Format::topBorderStyle() const
{ {
return d->borderData.top; return static_cast<BorderStyle>(intProperty(FormatPrivate::P_Border_TopStyle));
} }
void Format::setTopBorderStyle(BorderStyle style) void Format::setTopBorderStyle(BorderStyle style)
{ {
d->borderData.top = style; setProperty(FormatPrivate::P_Border_TopStyle, style);
d->borderData._dirty = true;
} }
QColor Format::topBorderColor() const QColor Format::topBorderColor() const
{ {
return d->borderData.topColor; return colorProperty(FormatPrivate::P_Border_TopColor);
} }
void Format::setTopBorderColor(const QColor &color) void Format::setTopBorderColor(const QColor &color)
{ {
d->borderData.topColor = color; setProperty(FormatPrivate::P_Border_TopColor, color);
d->borderData._dirty = true;
} }
Format::BorderStyle Format::bottomBorderStyle() const Format::BorderStyle Format::bottomBorderStyle() const
{ {
return d->borderData.bottom; return static_cast<BorderStyle>(intProperty(FormatPrivate::P_Border_BottomStyle));
} }
void Format::setBottomBorderStyle(BorderStyle style) void Format::setBottomBorderStyle(BorderStyle style)
{ {
d->borderData.bottom = style; setProperty(FormatPrivate::P_Border_BottomStyle, style);
d->borderData._dirty = true;
} }
QColor Format::bottomBorderColor() const QColor Format::bottomBorderColor() const
{ {
return d->borderData.bottomColor; return colorProperty(FormatPrivate::P_Border_BottomColor);
} }
void Format::setBottomBorderColor(const QColor &color) void Format::setBottomBorderColor(const QColor &color)
{ {
d->borderData.bottomColor = color; setProperty(FormatPrivate::P_Border_BottomColor, color);
d->borderData._dirty = true;
} }
Format::BorderStyle Format::diagonalBorderStyle() const Format::BorderStyle Format::diagonalBorderStyle() const
{ {
return d->borderData.diagonal; return static_cast<BorderStyle>(intProperty(FormatPrivate::P_Border_DiagonalStyle));
} }
void Format::setDiagonalBorderStyle(BorderStyle style) void Format::setDiagonalBorderStyle(BorderStyle style)
{ {
d->borderData.diagonal = style; setProperty(FormatPrivate::P_Border_DiagonalStyle, style);
d->borderData._dirty = true;
} }
Format::DiagonalBorderType Format::diagonalBorderType() const Format::DiagonalBorderType Format::diagonalBorderType() const
{ {
return d->borderData.diagonalType; return static_cast<DiagonalBorderType>(intProperty(FormatPrivate::P_Border_DiagonalType));
} }
void Format::setDiagonalBorderType(DiagonalBorderType style) void Format::setDiagonalBorderType(DiagonalBorderType style)
{ {
d->borderData.diagonalType = style; setProperty(FormatPrivate::P_Border_DiagonalType, style);
d->borderData._dirty = true;
} }
QColor Format::diagonalBorderColor() const QColor Format::diagonalBorderColor() const
{ {
return d->borderData.diagonalColor; return colorProperty(FormatPrivate::P_Border_DiagonalColor);
} }
void Format::setDiagonalBorderColor(const QColor &color) void Format::setDiagonalBorderColor(const QColor &color)
{ {
d->borderData.diagonalColor = color; setProperty(FormatPrivate::P_Border_DiagonalColor, color);
d->borderData._dirty = true;
} }
bool Format::borderIndexValid() const bool Format::borderIndexValid() const
{ {
return d->borderData.indexValid(); return d->border_index_valid;
} }
int Format::borderIndex() const int Format::borderIndex() const
{ {
return d->borderData.index(); return d->border_index;
} }
void Format::setBorderIndex(int index) void Format::setBorderIndex(int index)
{ {
d->borderData.setIndex(index); d->border_index = index;
} }
/* Internal /* Internal
*/ */
QByteArray Format::borderKey() const QByteArray Format::borderKey() const
{ {
if (d->borderData._dirty) if (d->border_dirty) {
d->dirty = true; //Make sure formatKey() will be re-generated. QByteArray key;
QDataStream stream(&key, QIODevice::WriteOnly);
for (int i=FormatPrivate::P_Border_STARTID; i<FormatPrivate::P_Border_ENDID; ++i) {
if (d->property.contains(i))
stream << i << d->property[i];
};
const_cast<Format*>(this)->d->border_key = key;
const_cast<Format*>(this)->d->border_dirty = false;
}
return d->borderData.key(); return d->border_key;
} }
Format::FillPattern Format::fillPattern() const Format::FillPattern Format::fillPattern() const
@ -830,7 +829,7 @@ void Format::setLocked(bool locked)
QByteArray Format::formatKey() const QByteArray Format::formatKey() const
{ {
if (d->dirty || d->borderData._dirty || d->fillData._dirty) { if (d->dirty || d->fillData._dirty) {
QByteArray key; QByteArray key;
QDataStream stream(&key, QIODevice::WriteOnly); QDataStream stream(&key, QIODevice::WriteOnly);
stream<<fontKey()<<borderKey()<<fillKey() stream<<fontKey()<<borderKey()<<fillKey()
@ -933,6 +932,11 @@ void Format::setProperty(int propertyId, const QVariant &value)
d->font_dirty = true; d->font_dirty = true;
d->font_index_valid = false; d->font_index_valid = false;
} }
if (propertyId >= FormatPrivate::P_Border_STARTID && propertyId < FormatPrivate::P_Border_ENDID) {
d->border_dirty = true;
d->border_index_valid = false;
}
} }
/*! /*!

91
src/xlsx/xlsxformat_p.h

@ -45,72 +45,6 @@ struct XlsxFormatAlignmentData
bool shinkToFit; 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<XlsxFormatBorderData*>(this)->_key = key;
const_cast<XlsxFormatBorderData*>(this)->_dirty = false;
const_cast<XlsxFormatBorderData*>(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 { struct XlsxFormatFillData {
XlsxFormatFillData() : XlsxFormatFillData() :
pattern(Format::PatternNone) pattern(Format::PatternNone)
@ -212,7 +146,24 @@ public:
P_Font_ENDID, P_Font_ENDID,
//border //border
P_Border_, P_Border_STARTID,
P_Border_LeftStyle = P_Border_STARTID,
P_Border_RightStyle,
P_Border_TopStyle,
P_Border_BottomStyle,
P_Border_DiagonalStyle,
P_Border_LeftColor,
P_Border_RightColor,
P_Border_TopColor,
P_Border_BottomColor,
P_Border_DiagonalColor,
P_Border_DiagonalType,
P_Border_ThemeLeftColor,
P_Border_ThemeRightColor,
P_Border_ThemeTopColor,
P_Border_ThemeBottomColor,
P_Border_ThemeDiagonalColor,
P_Border_ENDID,
//fill //fill
P_Fill_, P_Fill_,
@ -229,7 +180,6 @@ public:
~FormatPrivate(); ~FormatPrivate();
XlsxFormatAlignmentData alignmentData; XlsxFormatAlignmentData alignmentData;
XlsxFormatBorderData borderData;
XlsxFormatFillData fillData; XlsxFormatFillData fillData;
XlsxFormatProtectionData protectionData; XlsxFormatProtectionData protectionData;
@ -241,6 +191,11 @@ public:
QByteArray font_key; QByteArray font_key;
int font_index; int font_index;
bool border_dirty;
bool border_index_valid;
QByteArray border_key;
int border_index;
int xf_index; int xf_index;
bool xf_indexValid; bool xf_indexValid;

112
src/xlsx/xlsxstyles.cpp

@ -173,12 +173,12 @@ 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->borderData)); format->setBorderIndex(m_bordersList.size()); //Assign proper index
border->setIndex(m_bordersList.size()); //Assign proper index m_bordersList.append(format);
m_bordersList.append(border); m_bordersHash[format->borderKey()] = format;
m_bordersHash[border->key()] = border; } else {
format->setBorderIndex(m_bordersHash[format->borderKey()]->borderIndex());
} }
format->setBorderIndex(m_bordersHash[format->borderKey()]->index());
} }
//Format //Format
@ -444,24 +444,32 @@ void Styles::writeBorders(XmlStreamWriter &writer)
writer.writeStartElement(QStringLiteral("borders")); writer.writeStartElement(QStringLiteral("borders"));
writer.writeAttribute(QStringLiteral("count"), QString::number(m_bordersList.count())); writer.writeAttribute(QStringLiteral("count"), QString::number(m_bordersList.count()));
for (int i=0; i<m_bordersList.size(); ++i) { for (int i=0; i<m_bordersList.size(); ++i) {
QSharedPointer<XlsxFormatBorderData> border = m_bordersList[i]; Format *border = m_bordersList[i];
writer.writeStartElement(QStringLiteral("border")); writer.writeStartElement(QStringLiteral("border"));
if (border->diagonalType == Format::DiagonalBorderUp) { if (border->hasProperty(FormatPrivate::P_Border_DiagonalType)) {
writer.writeAttribute(QStringLiteral("diagonalUp"), QStringLiteral("1")); Format::DiagonalBorderType t = border->diagonalBorderType();
} else if (border->diagonalType == Format::DiagonalBorderDown) { if (t == Format::DiagonalBorderUp) {
writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1")); writer.writeAttribute(QStringLiteral("diagonalUp"), QStringLiteral("1"));
} else if (border->diagonalType == Format::DiagnoalBorderBoth) { } else if (t == Format::DiagonalBorderDown) {
writer.writeAttribute(QStringLiteral("diagonalUp"), QStringLiteral("1")); writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1"));
writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1")); } else if (t == Format::DiagnoalBorderBoth) {
writer.writeAttribute(QStringLiteral("diagonalUp"), QStringLiteral("1"));
writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1"));
}
} }
writeSubBorder(writer, QStringLiteral("left"), border->left, border->leftColor, border->leftThemeColor); if (border->hasProperty(FormatPrivate::P_Border_LeftStyle))
writeSubBorder(writer, QStringLiteral("right"), border->right, border->rightColor, border->rightThemeColor); writeSubBorder(writer, QStringLiteral("left"), border->leftBorderStyle(), border->leftBorderColor(), border->stringProperty(FormatPrivate::P_Border_ThemeLeftColor));
writeSubBorder(writer, QStringLiteral("top"), border->top, border->topColor, border->topThemeColor); if (border->hasProperty(FormatPrivate::P_Border_RightStyle))
writeSubBorder(writer, QStringLiteral("bottom"), border->bottom, border->bottomColor, border->bottomThemeColor); writeSubBorder(writer, QStringLiteral("right"), border->rightBorderStyle(), border->rightBorderColor(), border->stringProperty(FormatPrivate::P_Border_ThemeRightColor));
if (border->hasProperty(FormatPrivate::P_Border_TopStyle))
writeSubBorder(writer, QStringLiteral("top"), border->topBorderStyle(), border->topBorderColor(), border->stringProperty(FormatPrivate::P_Border_ThemeTopColor));
if (border->hasProperty(FormatPrivate::P_Border_BottomStyle))
writeSubBorder(writer, QStringLiteral("bottom"), border->bottomBorderStyle(), border->bottomBorderColor(), border->stringProperty(FormatPrivate::P_Border_ThemeBottomColor));
// if (!format->isDxfFormat()) { // if (!format->isDxfFormat()) {
writeSubBorder(writer, QStringLiteral("diagonal"), border->diagonal, border->diagonalColor, border->diagonalThemeColor); if (border->hasProperty(FormatPrivate::P_Border_DiagonalStyle))
writeSubBorder(writer, QStringLiteral("diagonal"), border->diagonalBorderStyle(), border->diagonalBorderColor(), border->stringProperty(FormatPrivate::P_Border_ThemeDiagonalColor));
// } // }
writer.writeEndElement();//border writer.writeEndElement();//border
} }
@ -787,30 +795,60 @@ bool Styles::readBorders(XmlStreamReader &reader)
bool Styles::readBorder(XmlStreamReader &reader) bool Styles::readBorder(XmlStreamReader &reader)
{ {
Q_ASSERT(reader.name() == QLatin1String("border")); Q_ASSERT(reader.name() == QLatin1String("border"));
QSharedPointer<XlsxFormatBorderData> border(new XlsxFormatBorderData); Format *border = createFormat();
QXmlStreamAttributes attributes = reader.attributes(); QXmlStreamAttributes attributes = reader.attributes();
bool isUp = attributes.hasAttribute(QLatin1String("diagonalUp")); bool isUp = attributes.hasAttribute(QLatin1String("diagonalUp"));
bool isDown = attributes.hasAttribute(QLatin1String("diagonalUp")); bool isDown = attributes.hasAttribute(QLatin1String("diagonalUp"));
if (isUp && isDown) if (isUp && isDown)
border->diagonalType = Format::DiagnoalBorderBoth; border->setDiagonalBorderType(Format::DiagnoalBorderBoth);
else if (isUp) else if (isUp)
border->diagonalType = Format::DiagonalBorderUp; border->setDiagonalBorderType(Format::DiagonalBorderUp);
else if (isDown) else if (isDown)
border->diagonalType = Format::DiagonalBorderDown; border->setDiagonalBorderType(Format::DiagonalBorderDown);
while((reader.readNextStartElement(), true)) { //read until border endelement while((reader.readNextStartElement(), true)) { //read until border endelement
if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.tokenType() == QXmlStreamReader::StartElement) {
if (reader.name() == QLatin1String("left")) if (reader.name() == QLatin1String("left") || reader.name() == QLatin1String("right")
readSubBorder(reader, reader.name().toString(), border->left, border->leftColor, border->leftThemeColor); || reader.name() == QLatin1String("top") || reader.name() == QLatin1String("bottom")
else if (reader.name() == QLatin1String("right")) || reader.name() == QLatin1String("diagonal") ) {
readSubBorder(reader, reader.name().toString(), border->right, border->rightColor, border->rightThemeColor); Format::BorderStyle style(Format::BorderNone);
else if (reader.name() == QLatin1String("top")) QColor color;
readSubBorder(reader, reader.name().toString(), border->top, border->topColor, border->topThemeColor); QString themeColor;
else if (reader.name() == QLatin1String("bottom")) readSubBorder(reader, reader.name().toString(), style, color, themeColor);
readSubBorder(reader, reader.name().toString(), border->bottom, border->bottomColor, border->bottomThemeColor);
else if (reader.name() == QLatin1String("diagonal")) if (reader.name() == QLatin1String("left")) {
readSubBorder(reader, reader.name().toString(), border->diagonal, border->diagonalColor, border->diagonalThemeColor); border->setLeftBorderStyle(style);
if (color.isValid())
border->setLeftBorderColor(color);
else if (!themeColor.isEmpty())
border->setProperty(FormatPrivate::P_Border_ThemeLeftColor, themeColor);
} else if (reader.name() == QLatin1String("right")) {
border->setRightBorderStyle(style);
if (color.isValid())
border->setRightBorderColor(color);
else if (!themeColor.isEmpty())
border->setProperty(FormatPrivate::P_Border_ThemeRightColor, themeColor);
} else if (reader.name() == QLatin1String("top")) {
border->setTopBorderStyle(style);
if (color.isValid())
border->setTopBorderColor(color);
else if (!themeColor.isEmpty())
border->setProperty(FormatPrivate::P_Border_ThemeTopColor, themeColor);
} else if (reader.name() == QLatin1String("bottom")) {
border->setBottomBorderStyle(style);
if (color.isValid())
border->setBottomBorderColor(color);
else if (!themeColor.isEmpty())
border->setProperty(FormatPrivate::P_Border_ThemeBottomColor, themeColor);
} else if (reader.name() == QLatin1String("diagonal")) {
border->setDiagonalBorderStyle(style);
if (color.isValid())
border->setDiagonalBorderColor(color);
else if (!themeColor.isEmpty())
border->setProperty(FormatPrivate::P_Border_ThemeDiagonalColor, themeColor);
}
}
} }
if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("border")) if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("border"))
@ -818,8 +856,8 @@ bool Styles::readBorder(XmlStreamReader &reader)
} }
m_bordersList.append(border); m_bordersList.append(border);
m_bordersHash.insert(border->key(), border); m_bordersHash.insert(border->borderKey(), border);
border->setIndex(m_bordersList.size()-1);//first call key(), then setIndex() border->setBorderIndex(m_bordersList.size()-1);//first call key(), then setIndex()
return true; return true;
} }
@ -931,7 +969,11 @@ 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->borderData = *m_bordersList[id]; Format *borderFormat = m_bordersList[id];
for (int i=FormatPrivate::P_Border_STARTID; i<FormatPrivate::P_Border_ENDID; ++i) {
if (borderFormat->hasProperty(i))
format->setProperty(i, borderFormat->property(i));
}
} }
} }

5
src/xlsx/xlsxstyles_p.h

@ -41,7 +41,6 @@ namespace QXlsx {
class Format; class Format;
struct XlsxFormatFillData; struct XlsxFormatFillData;
struct XlsxFormatBorderData;
class XmlStreamWriter; class XmlStreamWriter;
class XmlStreamReader; class XmlStreamReader;
@ -99,10 +98,10 @@ private:
int m_nextCustomNumFmtId; int m_nextCustomNumFmtId;
QList<Format *> m_fontsList; QList<Format *> m_fontsList;
QList<QSharedPointer<XlsxFormatFillData> > m_fillsList; //Keep a copy of unique fills QList<QSharedPointer<XlsxFormatFillData> > m_fillsList; //Keep a copy of unique fills
QList<QSharedPointer<XlsxFormatBorderData> > m_bordersList; //Keep a copy of unique borders QList<Format *> m_bordersList; //Keep a copy of unique borders
QHash<QByteArray, Format *> m_fontsHash; QHash<QByteArray, Format *> m_fontsHash;
QHash<QByteArray, QSharedPointer<XlsxFormatFillData> > m_fillsHash; QHash<QByteArray, QSharedPointer<XlsxFormatFillData> > m_fillsHash;
QHash<QByteArray, QSharedPointer<XlsxFormatBorderData> > m_bordersHash; QHash<QByteArray, Format *> m_bordersHash;
QVector<QColor> m_indexedColors; QVector<QColor> m_indexedColors;

14
tests/auto/styles/tst_stylestest.cpp

@ -18,6 +18,8 @@ private Q_SLOTS:
void testAddFormat2(); void testAddFormat2();
void testSolidFillBackgroundColor(); void testSolidFillBackgroundColor();
void testWriteBorders();
void testReadNumFmts(); void testReadNumFmts();
void testReadFonts(); void testReadFonts();
void testReadFills(); void testReadFills();
@ -81,6 +83,18 @@ void StylesTest::testSolidFillBackgroundColor()
QVERIFY(xmlData.contains("<patternFill patternType=\"solid\"><fgColor rgb=\"FFff0000\"/>")); QVERIFY(xmlData.contains("<patternFill patternType=\"solid\"><fgColor rgb=\"FFff0000\"/>"));
} }
void StylesTest::testWriteBorders()
{
QXlsx::Styles styles;
QXlsx::Format *format = styles.createFormat();
format->setRightBorderStyle(QXlsx::Format::BorderThin);
styles.addFormat(format);
QByteArray xmlData = styles.saveToXmlData();
QVERIFY(xmlData.contains("<border><right style=\"thin\">"));
}
void StylesTest::testReadFonts() void StylesTest::testReadFonts()
{ {
QByteArray xmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" QByteArray xmlData = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"

Loading…
Cancel
Save