diff --git a/src/xlsx/xlsxcolor.cpp b/src/xlsx/xlsxcolor.cpp index 3a7534a..7aec0bc 100644 --- a/src/xlsx/xlsxcolor.cpp +++ b/src/xlsx/xlsxcolor.cpp @@ -92,7 +92,7 @@ bool XlsxColor::saveToXml(QXmlStreamWriter &writer, const QString &node) const return true; } -bool XlsxColor::loadFromXml(QXmlStreamReader &reader, Styles *styles) +bool XlsxColor::loadFromXml(QXmlStreamReader &reader) { QXmlStreamAttributes attributes = reader.attributes(); @@ -101,14 +101,7 @@ bool XlsxColor::loadFromXml(QXmlStreamReader &reader, Styles *styles) val.setValue(fromARGBString(colorString)); } else if (attributes.hasAttribute(QLatin1String("indexed"))) { int index = attributes.value(QLatin1String("indexed")).toString().toInt(); - if (styles) { - //Convert to rgb color is possible - QColor c = styles->getColorByIndex(index); - if (c.isValid()) - val.setValue(c); - } else { - val.setValue(index); - } + val.setValue(index); } else if (attributes.hasAttribute(QLatin1String("theme"))) { QString theme = attributes.value(QLatin1String("theme")).toString(); QString tint = attributes.value(QLatin1String("tint")).toString(); diff --git a/src/xlsx/xlsxcolor_p.h b/src/xlsx/xlsxcolor_p.h index 9c43f8a..a34ff22 100644 --- a/src/xlsx/xlsxcolor_p.h +++ b/src/xlsx/xlsxcolor_p.h @@ -67,7 +67,7 @@ public: operator QVariant() const; bool saveToXml(QXmlStreamWriter &writer, const QString &node=QString()) const; - bool loadFromXml(QXmlStreamReader &reader, Styles *styles=0); + bool loadFromXml(QXmlStreamReader &reader); private: QVariant val; diff --git a/src/xlsx/xlsxconditionalformatting.cpp b/src/xlsx/xlsxconditionalformatting.cpp index f933fa5..0f40aeb 100644 --- a/src/xlsx/xlsxconditionalformatting.cpp +++ b/src/xlsx/xlsxconditionalformatting.cpp @@ -506,9 +506,9 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu else if (!rule->attrs.contains(XlsxCfRuleData::A_formula3)) rule->attrs[XlsxCfRuleData::A_formula3] = f; } else if (reader.name() == QLatin1String("dataBar")) { - readCfDataBar(reader, rule, styles); + readCfDataBar(reader, rule); } else if (reader.name() == QLatin1String("colorScale")) { - readCfColorScale(reader, rule, styles); + readCfColorScale(reader, rule); } } if (reader.tokenType() == QXmlStreamReader::EndElement @@ -519,7 +519,7 @@ bool ConditionalFormattingPrivate::readCfRule(QXmlStreamReader &reader, XlsxCfRu return true; } -bool ConditionalFormattingPrivate::readCfDataBar(QXmlStreamReader &reader, XlsxCfRuleData *rule, Styles *styles) +bool ConditionalFormattingPrivate::readCfDataBar(QXmlStreamReader &reader, XlsxCfRuleData *rule) { Q_ASSERT(reader.name() == QLatin1String("dataBar")); QXmlStreamAttributes attrs = reader.attributes(); @@ -538,7 +538,7 @@ bool ConditionalFormattingPrivate::readCfDataBar(QXmlStreamReader &reader, XlsxC rule->attrs[XlsxCfRuleData::A_cfvo2] = QVariant::fromValue(data); } else if (reader.name() == QLatin1String("color")) { XlsxColor color; - color.loadFromXml(reader, styles); + color.loadFromXml(reader); rule->attrs[XlsxCfRuleData::A_color1] = color; } } @@ -551,7 +551,7 @@ bool ConditionalFormattingPrivate::readCfDataBar(QXmlStreamReader &reader, XlsxC return true; } -bool ConditionalFormattingPrivate::readCfColorScale(QXmlStreamReader &reader, XlsxCfRuleData *rule, Styles *styles) +bool ConditionalFormattingPrivate::readCfColorScale(QXmlStreamReader &reader, XlsxCfRuleData *rule) { Q_ASSERT(reader.name() == QLatin1String("colorScale")); @@ -569,7 +569,7 @@ bool ConditionalFormattingPrivate::readCfColorScale(QXmlStreamReader &reader, Xl rule->attrs[XlsxCfRuleData::A_cfvo2] = QVariant::fromValue(data); } else if (reader.name() == QLatin1String("color")) { XlsxColor color; - color.loadFromXml(reader, styles); + color.loadFromXml(reader); if (!rule->attrs.contains(XlsxCfRuleData::A_color1)) rule->attrs[XlsxCfRuleData::A_color1] = color; else if (!rule->attrs.contains(XlsxCfRuleData::A_color2)) diff --git a/src/xlsx/xlsxconditionalformatting_p.h b/src/xlsx/xlsxconditionalformatting_p.h index ff78d90..1ce9c74 100644 --- a/src/xlsx/xlsxconditionalformatting_p.h +++ b/src/xlsx/xlsxconditionalformatting_p.h @@ -118,8 +118,8 @@ public: void writeCfVo(QXmlStreamWriter &writer, const XlsxCfVoData& cfvo) const; bool readCfVo(QXmlStreamReader &reader, XlsxCfVoData& cfvo); bool readCfRule(QXmlStreamReader &reader, XlsxCfRuleData *cfRule, Styles *styles); - bool readCfDataBar(QXmlStreamReader &reader, XlsxCfRuleData *cfRule, Styles *styles); - bool readCfColorScale(QXmlStreamReader &reader, XlsxCfRuleData *cfRule, Styles *styles); + bool readCfDataBar(QXmlStreamReader &reader, XlsxCfRuleData *cfRule); + bool readCfColorScale(QXmlStreamReader &reader, XlsxCfRuleData *cfRule); QList >cfRules; QList ranges; diff --git a/src/xlsx/xlsxstyles.cpp b/src/xlsx/xlsxstyles.cpp index 7542ce2..21d5a5f 100755 --- a/src/xlsx/xlsxstyles.cpp +++ b/src/xlsx/xlsxstyles.cpp @@ -771,7 +771,7 @@ bool Styles::readFont(QXmlStreamReader &reader, Format &format) format.setProperty(FormatPrivate::P_Font_Extend, attributes.value(QLatin1String("val")).toString().toInt()); } else if (reader.name() == QLatin1String("color")) { XlsxColor color; - color.loadFromXml(reader, this); + color.loadFromXml(reader); format.setProperty(FormatPrivate::P_Font_Color, color); } else if (reader.name() == QLatin1String("sz")) { int sz = attributes.value(QLatin1String("val")).toString().toInt(); @@ -1004,7 +1004,7 @@ bool Styles::readSubBorder(QXmlStreamReader &reader, const QString &name, Format reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("color")) - color.loadFromXml(reader, this); + color.loadFromXml(reader); } } } @@ -1225,20 +1225,6 @@ bool Styles::readIndexedColors(QXmlStreamReader &reader) bool Styles::loadFromXmlFile(QIODevice *device) { - { - //Try load colors part first! - QXmlStreamReader reader(device); - while (!reader.atEnd()) { - QXmlStreamReader::TokenType token = reader.readNext(); - if (token == QXmlStreamReader::StartElement) { - if (reader.name() == QLatin1String("colors")) { - readColors(reader); - } - } - } - device->seek(0); - } - QXmlStreamReader reader(device); while (!reader.atEnd()) { QXmlStreamReader::TokenType token = reader.readNext(); @@ -1259,6 +1245,8 @@ bool Styles::loadFromXmlFile(QIODevice *device) } else if (reader.name() == QLatin1String("dxfs")) { readDxfs(reader); + } else if (reader.name() == QLatin1String("colors")) { + readColors(reader); } }