From b3754443687017028d239c898e261e6693b94418 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Thu, 28 Nov 2013 23:58:55 +0800 Subject: [PATCH] Make use of XlsxColor for ConditionalFormatting --- src/xlsx/xlsxconditionalformatting.cpp | 36 +++++++------------------- src/xlsx/xlsxconditionalformatting_p.h | 2 +- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/xlsx/xlsxconditionalformatting.cpp b/src/xlsx/xlsxconditionalformatting.cpp index b7a939b..031aa58 100644 --- a/src/xlsx/xlsxconditionalformatting.cpp +++ b/src/xlsx/xlsxconditionalformatting.cpp @@ -69,22 +69,6 @@ void ConditionalFormattingPrivate::writeCfVo(const XlsxCfVoData &cfvo, QXmlStrea writer.writeAttribute(QStringLiteral("gte"), QStringLiteral("0")); } -void ConditionalFormattingPrivate::writeColor(const QColor &color, QXmlStreamWriter &writer) const -{ - writer.writeStartElement(QStringLiteral("color")); - if (color.isValid()) { - writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.name().mid(1)); //remove # -// } else if (!themeColor.isEmpty()) { -// QStringList themes = themeColor.split(QLatin1Char(':')); -// writer.writeAttribute(QStringLiteral("theme"), themes[0]); -// if (!themes[1].isEmpty()) -// writer.writeAttribute(QStringLiteral("tint"), themes[1]); - } else { - writer.writeAttribute(QStringLiteral("auto"), QStringLiteral("1")); - } - writer.writeEndElement();//color -} - /*! * \class ConditionalFormatting * \brief Conditional formatting for single cell or ranges @@ -323,7 +307,7 @@ bool ConditionalFormatting::addDataBarRule(const QColor &color, ValueObjectType QSharedPointer cfRule(new XlsxCfRuleData); cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("dataBar"); - cfRule->attrs[XlsxCfRuleData::A_color1] = color; + cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(color); if (stopIfTrue) cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; if (!showData) @@ -360,8 +344,8 @@ bool ConditionalFormatting::add2ColorScaleRule(const QColor &minColor, const QCo QSharedPointer cfRule(new XlsxCfRuleData); cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale"); - cfRule->attrs[XlsxCfRuleData::A_color1] = minColor; - cfRule->attrs[XlsxCfRuleData::A_color2] = maxColor; + cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(minColor); + cfRule->attrs[XlsxCfRuleData::A_color2] = XlsxColor(maxColor); if (stopIfTrue) cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; @@ -389,9 +373,9 @@ bool ConditionalFormatting::add3ColorScaleRule(const QColor &minColor, const QCo QSharedPointer cfRule(new XlsxCfRuleData); cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("colorScale"); - cfRule->attrs[XlsxCfRuleData::A_color1] = minColor; - cfRule->attrs[XlsxCfRuleData::A_color2] = midColor; - cfRule->attrs[XlsxCfRuleData::A_color3] = maxColor; + cfRule->attrs[XlsxCfRuleData::A_color1] = XlsxColor(minColor); + cfRule->attrs[XlsxCfRuleData::A_color2] = XlsxColor(midColor); + cfRule->attrs[XlsxCfRuleData::A_color3] = XlsxColor(maxColor); if (stopIfTrue) cfRule->attrs[XlsxCfRuleData::A_stopIfTrue] = true; @@ -508,7 +492,7 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const writer.writeAttribute(QStringLiteral("showValue"), QStringLiteral("0")); d->writeCfVo(rule->attrs[XlsxCfRuleData::A_cfvo1].value(), writer); d->writeCfVo(rule->attrs[XlsxCfRuleData::A_cfvo2].value(), writer); - d->writeColor(rule->attrs[XlsxCfRuleData::A_color1].value(), writer); + rule->attrs[XlsxCfRuleData::A_color1].value().saveToXml(writer); writer.writeEndElement();//dataBar } else if (rule->attrs[XlsxCfRuleData::A_type] == QLatin1String("colorScale")) { writer.writeStartElement(QStringLiteral("colorScale")); @@ -517,10 +501,10 @@ bool ConditionalFormatting::saveToXml(QXmlStreamWriter &writer) const if (rule->attrs.contains(XlsxCfRuleData::A_cfvo3)) d->writeCfVo(rule->attrs[XlsxCfRuleData::A_cfvo3].value(), writer); - d->writeColor(rule->attrs[XlsxCfRuleData::A_color1].value(), writer); - d->writeColor(rule->attrs[XlsxCfRuleData::A_color2].value(), writer); + rule->attrs[XlsxCfRuleData::A_color1].value().saveToXml(writer); + rule->attrs[XlsxCfRuleData::A_color2].value().saveToXml(writer); if (rule->attrs.contains(XlsxCfRuleData::A_color3)) - d->writeColor(rule->attrs[XlsxCfRuleData::A_color3].value(), writer); + rule->attrs[XlsxCfRuleData::A_color3].value().saveToXml(writer); writer.writeEndElement();//colorScale } diff --git a/src/xlsx/xlsxconditionalformatting_p.h b/src/xlsx/xlsxconditionalformatting_p.h index 03cb94b..149c7d7 100644 --- a/src/xlsx/xlsxconditionalformatting_p.h +++ b/src/xlsx/xlsxconditionalformatting_p.h @@ -39,6 +39,7 @@ #include "xlsxConditionalFormatting.h" #include "xlsxformat.h" +#include "xlsxcolor_p.h" #include #include #include @@ -115,7 +116,6 @@ public: ~ConditionalFormattingPrivate(); void writeCfVo(const XlsxCfVoData& cfvo, QXmlStreamWriter &writer) const; - void writeColor(const QColor &color, QXmlStreamWriter &writer) const; QList >cfRules; QList ranges;