Browse Source

Code refactoring: Empty border styles

Excel prefer <border><left/><right/><top/><bottom/><diagonal/></border> to
<border/>
master
Debao Zhang 11 years ago
parent
commit
780ceef359
  1. 2
      src/xlsx/xlsxformat.cpp
  2. 7
      src/xlsx/xlsxstyles.cpp
  3. 3
      tests/auto/styles/tst_stylestest.cpp

2
src/xlsx/xlsxformat.cpp

@ -1233,7 +1233,7 @@ int Format::theme() const
*/ */
QVariant Format::property(int propertyId, const QVariant &defaultValue) const QVariant Format::property(int propertyId, const QVariant &defaultValue) const
{ {
if (d->property.contains(propertyId)) if (d && d->property.contains(propertyId))
return d->property[propertyId]; return d->property[propertyId];
return defaultValue; return defaultValue;
} }

7
src/xlsx/xlsxstyles.cpp

@ -505,17 +505,14 @@ void Styles::writeBorder(QXmlStreamWriter &writer, const Format &border, bool is
writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1")); writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1"));
} }
} }
if (border.hasProperty(FormatPrivate::P_Border_LeftStyle))
writeSubBorder(writer, QStringLiteral("left"), border.leftBorderStyle(), border.property(FormatPrivate::P_Border_LeftColor).value<XlsxColor>()); writeSubBorder(writer, QStringLiteral("left"), border.leftBorderStyle(), border.property(FormatPrivate::P_Border_LeftColor).value<XlsxColor>());
if (border.hasProperty(FormatPrivate::P_Border_RightStyle))
writeSubBorder(writer, QStringLiteral("right"), border.rightBorderStyle(), border.property(FormatPrivate::P_Border_RightColor).value<XlsxColor>()); writeSubBorder(writer, QStringLiteral("right"), border.rightBorderStyle(), border.property(FormatPrivate::P_Border_RightColor).value<XlsxColor>());
if (border.hasProperty(FormatPrivate::P_Border_TopStyle))
writeSubBorder(writer, QStringLiteral("top"), border.topBorderStyle(), border.property(FormatPrivate::P_Border_TopColor).value<XlsxColor>()); writeSubBorder(writer, QStringLiteral("top"), border.topBorderStyle(), border.property(FormatPrivate::P_Border_TopColor).value<XlsxColor>());
if (border.hasProperty(FormatPrivate::P_Border_BottomStyle))
writeSubBorder(writer, QStringLiteral("bottom"), border.bottomBorderStyle(), border.property(FormatPrivate::P_Border_BottomColor).value<XlsxColor>()); writeSubBorder(writer, QStringLiteral("bottom"), border.bottomBorderStyle(), border.property(FormatPrivate::P_Border_BottomColor).value<XlsxColor>());
//Condition DXF formats don't allow diagonal style //Condition DXF formats don't allow diagonal style
if (!isDxf && border.hasProperty(FormatPrivate::P_Border_DiagonalStyle)) if (!isDxf)
writeSubBorder(writer, QStringLiteral("diagonal"), border.diagonalBorderStyle(), border.property(FormatPrivate::P_Border_DiagonalColor).value<XlsxColor>()); writeSubBorder(writer, QStringLiteral("diagonal"), border.diagonalBorderStyle(), border.property(FormatPrivate::P_Border_DiagonalColor).value<XlsxColor>());
if (isDxf) { if (isDxf) {

3
tests/auto/styles/tst_stylestest.cpp

@ -37,6 +37,7 @@ void StylesTest::testEmptyStyle()
// QVERIFY2(xmlData.contains("<cellXfs count=\"1\"><xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/></cellXfs>"), "Must have one cell style"); // QVERIFY2(xmlData.contains("<cellXfs count=\"1\"><xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/></cellXfs>"), "Must have one cell style");
QVERIFY2(xmlData.contains("<cellXfs count=\"1\"><xf xfId=\"0\"/></cellXfs>"), "Must have one cell style"); QVERIFY2(xmlData.contains("<cellXfs count=\"1\"><xf xfId=\"0\"/></cellXfs>"), "Must have one cell style");
QVERIFY2(xmlData.contains("<border><left/><right/><top/><bottom/><diagonal/></border>"), "Excel don't simply generate <border/>, through it works");
} }
void StylesTest::testAddXfFormat() void StylesTest::testAddXfFormat()
@ -92,7 +93,7 @@ void StylesTest::testWriteBorders()
QByteArray xmlData = styles.saveToXmlData(); QByteArray xmlData = styles.saveToXmlData();
QVERIFY(xmlData.contains("<border><right style=\"thin\">")); QVERIFY(xmlData.contains("<border><left/><right style=\"thin\">"));
} }
void StylesTest::testReadFonts() void StylesTest::testReadFonts()

Loading…
Cancel
Save