From a8cde04d7a8afa837a16d517986e6272ca20ba2c Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Tue, 24 Dec 2013 09:48:45 +0800 Subject: [PATCH] Code refacting: write fgColor before bgColor --- src/xlsx/xlsxstyles.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/xlsx/xlsxstyles.cpp b/src/xlsx/xlsxstyles.cpp index 40e3981..7542ce2 100755 --- a/src/xlsx/xlsxstyles.cpp +++ b/src/xlsx/xlsxstyles.cpp @@ -467,22 +467,17 @@ void Styles::writeFill(QXmlStreamWriter &writer, const Format &fill, bool /*isDx writer.writeStartElement(QStringLiteral("patternFill")); writer.writeAttribute(QStringLiteral("patternType"), patternStrings[fill.fillPattern()]); // For a solid fill, Excel reverses the role of foreground and background colours - if (fill.hasProperty(FormatPrivate::P_Fill_FgColor)) { - XlsxColor color = fill.property(FormatPrivate::P_Fill_FgColor).value(); - if (fill.fillPattern() == Format::PatternSolid) - color.saveToXml(writer, QStringLiteral("bgColor")); - else - color.saveToXml(writer, QStringLiteral("fgColor")); - } - - if (fill.hasProperty(FormatPrivate::P_Fill_BgColor)) { - XlsxColor color = fill.property(FormatPrivate::P_Fill_BgColor).value(); - if (fill.fillPattern() == Format::PatternSolid) - color.saveToXml(writer, QStringLiteral("fgColor")); - else - color.saveToXml(writer, QStringLiteral("bgColor")); + if (fill.fillPattern() == Format::PatternSolid) { + if (fill.hasProperty(FormatPrivate::P_Fill_BgColor)) + fill.property(FormatPrivate::P_Fill_BgColor).value().saveToXml(writer, QStringLiteral("fgColor")); + if (fill.hasProperty(FormatPrivate::P_Fill_FgColor)) + fill.property(FormatPrivate::P_Fill_FgColor).value().saveToXml(writer, QStringLiteral("bgColor")); + } else { + if (fill.hasProperty(FormatPrivate::P_Fill_FgColor)) + fill.property(FormatPrivate::P_Fill_FgColor).value().saveToXml(writer, QStringLiteral("fgColor")); + if (fill.hasProperty(FormatPrivate::P_Fill_BgColor)) + fill.property(FormatPrivate::P_Fill_BgColor).value().saveToXml(writer, QStringLiteral("bgColor")); } - writer.writeEndElement();//patternFill writer.writeEndElement();//fill }