Browse Source

Don't convert indexed color ==> rgb color

We can do the convertion when users try to access the colors if needed in
the future
master
Debao Zhang 11 years ago
parent
commit
e35b2abda9
  1. 9
      src/xlsx/xlsxcolor.cpp
  2. 2
      src/xlsx/xlsxcolor_p.h
  3. 12
      src/xlsx/xlsxconditionalformatting.cpp
  4. 4
      src/xlsx/xlsxconditionalformatting_p.h
  5. 20
      src/xlsx/xlsxstyles.cpp

9
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);
}
} else if (attributes.hasAttribute(QLatin1String("theme"))) {
QString theme = attributes.value(QLatin1String("theme")).toString();
QString tint = attributes.value(QLatin1String("tint")).toString();

2
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;

12
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))

4
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<QSharedPointer<XlsxCfRuleData> >cfRules;
QList<CellRange> ranges;

20
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);
}
}

Loading…
Cancel
Save