Code refactoring: Empty border styles
Excel prefer <border><left/><right/><top/><bottom/><diagonal/></border> to <border/>
This commit is contained in:
@@ -1233,7 +1233,7 @@ int Format::theme() 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 defaultValue;
|
||||
}
|
||||
|
||||
@@ -505,17 +505,14 @@ void Styles::writeBorder(QXmlStreamWriter &writer, const Format &border, bool is
|
||||
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>());
|
||||
if (border.hasProperty(FormatPrivate::P_Border_RightStyle))
|
||||
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>());
|
||||
if (border.hasProperty(FormatPrivate::P_Border_BottomStyle))
|
||||
writeSubBorder(writer, QStringLiteral("bottom"), border.bottomBorderStyle(), border.property(FormatPrivate::P_Border_BottomColor).value<XlsxColor>());
|
||||
|
||||
writeSubBorder(writer, QStringLiteral("left"), border.leftBorderStyle(), border.property(FormatPrivate::P_Border_LeftColor).value<XlsxColor>());
|
||||
writeSubBorder(writer, QStringLiteral("right"), border.rightBorderStyle(), border.property(FormatPrivate::P_Border_RightColor).value<XlsxColor>());
|
||||
writeSubBorder(writer, QStringLiteral("top"), border.topBorderStyle(), border.property(FormatPrivate::P_Border_TopColor).value<XlsxColor>());
|
||||
writeSubBorder(writer, QStringLiteral("bottom"), border.bottomBorderStyle(), border.property(FormatPrivate::P_Border_BottomColor).value<XlsxColor>());
|
||||
|
||||
//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>());
|
||||
|
||||
if (isDxf) {
|
||||
|
||||
@@ -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 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()
|
||||
@@ -92,7 +93,7 @@ void StylesTest::testWriteBorders()
|
||||
|
||||
QByteArray xmlData = styles.saveToXmlData();
|
||||
|
||||
QVERIFY(xmlData.contains("<border><right style=\"thin\">"));
|
||||
QVERIFY(xmlData.contains("<border><left/><right style=\"thin\">"));
|
||||
}
|
||||
|
||||
void StylesTest::testReadFonts()
|
||||
|
||||
Reference in New Issue
Block a user