|
@ -48,7 +48,7 @@ Styles::Styles(bool createEmpty) |
|
|
if (!createEmpty) { |
|
|
if (!createEmpty) { |
|
|
//Add default Format
|
|
|
//Add default Format
|
|
|
Format defaultFmt; |
|
|
Format defaultFmt; |
|
|
addFormat(defaultFmt); |
|
|
addXfFormat(defaultFmt); |
|
|
|
|
|
|
|
|
//Add another fill format
|
|
|
//Add another fill format
|
|
|
Format fillFmt; |
|
|
Format fillFmt; |
|
@ -70,24 +70,24 @@ Format Styles::xfFormat(int idx) const |
|
|
return m_xf_formatsList[idx]; |
|
|
return m_xf_formatsList[idx]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*
|
|
|
Format Styles::dxfFormat(int idx) const |
|
|
Assign index to Font/Fill/Border and Format |
|
|
{ |
|
|
|
|
|
if (idx <0 || idx >= m_dxf_formatsList.size()) |
|
|
|
|
|
return Format(); |
|
|
|
|
|
|
|
|
When \a force is true, add the format to the format list, even other format has |
|
|
return m_dxf_formatsList[idx]; |
|
|
the same key have been in. |
|
|
} |
|
|
This is useful when reading existing .xlsx files which may contains duplicated formats. |
|
|
|
|
|
*/ |
|
|
void Styles::fixNumFmt(const Format &format) |
|
|
void Styles::addFormat(const Format &format, bool force) |
|
|
|
|
|
{ |
|
|
{ |
|
|
if (format.isEmpty()) { |
|
|
if (!format.hasNumFmtData()) |
|
|
//Try do something for empty Format.
|
|
|
return; |
|
|
if (m_emptyFormatAdded) |
|
|
|
|
|
|
|
|
if (format.hasProperty(FormatPrivate::P_NumFmt_Id) |
|
|
|
|
|
&& !format.stringProperty(FormatPrivate::P_NumFmt_FormatCode).isEmpty()) { |
|
|
return; |
|
|
return; |
|
|
m_emptyFormatAdded = true; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//numFmt
|
|
|
|
|
|
if (format.hasNumFmtData() && !format.hasProperty(FormatPrivate::P_NumFmt_Id)) { |
|
|
|
|
|
if (m_builtinNumFmtsHash.isEmpty()) { |
|
|
if (m_builtinNumFmtsHash.isEmpty()) { |
|
|
m_builtinNumFmtsHash.insert(QStringLiteral("General"), 0); |
|
|
m_builtinNumFmtsHash.insert(QStringLiteral("General"), 0); |
|
|
m_builtinNumFmtsHash.insert(QStringLiteral("0"), 1); |
|
|
m_builtinNumFmtsHash.insert(QStringLiteral("0"), 1); |
|
@ -127,15 +127,17 @@ void Styles::addFormat(const Format &format, bool force) |
|
|
m_builtinNumFmtsHash.insert(QStringLiteral("##0.0E+0"), 48); |
|
|
m_builtinNumFmtsHash.insert(QStringLiteral("##0.0E+0"), 48); |
|
|
m_builtinNumFmtsHash.insert(QStringLiteral("@"), 49); |
|
|
m_builtinNumFmtsHash.insert(QStringLiteral("@"), 49); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const QString str = format.numberFormat(); |
|
|
const QString str = format.numberFormat(); |
|
|
|
|
|
if (!str.isEmpty()) { |
|
|
//Assign proper number format index
|
|
|
//Assign proper number format index
|
|
|
if (m_builtinNumFmtsHash.contains(str)) { |
|
|
if (m_builtinNumFmtsHash.contains(str)) { |
|
|
const_cast<Format *>(&format)->setNumberFormat(m_builtinNumFmtsHash[str], str); |
|
|
const_cast<Format *>(&format)->fixNumberFormat(m_builtinNumFmtsHash[str], str); |
|
|
} else if (m_customNumFmtsHash.contains(str)) { |
|
|
} else if (m_customNumFmtsHash.contains(str)) { |
|
|
const_cast<Format *>(&format)->setNumberFormat(m_customNumFmtsHash[str]->formatIndex, str); |
|
|
const_cast<Format *>(&format)->fixNumberFormat(m_customNumFmtsHash[str]->formatIndex, str); |
|
|
} else { |
|
|
} else { |
|
|
//Assign a new fmt Id.
|
|
|
//Assign a new fmt Id.
|
|
|
const_cast<Format *>(&format)->setNumberFormat(m_nextCustomNumFmtId, str); |
|
|
const_cast<Format *>(&format)->fixNumberFormat(m_nextCustomNumFmtId, str); |
|
|
|
|
|
|
|
|
QSharedPointer<XlsxFormatNumberData> fmt(new XlsxFormatNumberData); |
|
|
QSharedPointer<XlsxFormatNumberData> fmt(new XlsxFormatNumberData); |
|
|
fmt->formatIndex = m_nextCustomNumFmtId; |
|
|
fmt->formatIndex = m_nextCustomNumFmtId; |
|
@ -145,8 +147,50 @@ void Styles::addFormat(const Format &format, bool force) |
|
|
|
|
|
|
|
|
m_nextCustomNumFmtId += 1; |
|
|
m_nextCustomNumFmtId += 1; |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
int id = format.numberFormatIndex(); |
|
|
|
|
|
//Assign proper format code, this is needed by dxf format
|
|
|
|
|
|
if (m_customNumFmtIdMap.contains(id)) { |
|
|
|
|
|
const_cast<Format *>(&format)->fixNumberFormat(id, m_customNumFmtIdMap[id]->formatString); |
|
|
|
|
|
} else { |
|
|
|
|
|
QHashIterator<QString, int> it(m_builtinNumFmtsHash); |
|
|
|
|
|
bool find=false; |
|
|
|
|
|
while(it.hasNext()) { |
|
|
|
|
|
it.next(); |
|
|
|
|
|
if (it.value() == id) |
|
|
|
|
|
const_cast<Format *>(&format)->fixNumberFormat(id, it.key()); |
|
|
|
|
|
find = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!find) { |
|
|
|
|
|
//Wrong numFmt
|
|
|
|
|
|
const_cast<Format *>(&format)->fixNumberFormat(id, QStringLiteral("General")); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Assign index to Font/Fill/Border and Format |
|
|
|
|
|
|
|
|
|
|
|
When \a force is true, add the format to the format list, even other format has |
|
|
|
|
|
the same key have been in. |
|
|
|
|
|
This is useful when reading existing .xlsx files which may contains duplicated formats. |
|
|
|
|
|
*/ |
|
|
|
|
|
void Styles::addXfFormat(const Format &format, bool force) |
|
|
|
|
|
{ |
|
|
|
|
|
if (format.isEmpty()) { |
|
|
|
|
|
//Try do something for empty Format.
|
|
|
|
|
|
if (m_emptyFormatAdded) |
|
|
|
|
|
return; |
|
|
|
|
|
m_emptyFormatAdded = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//numFmt
|
|
|
|
|
|
if (format.hasNumFmtData() && !format.hasProperty(FormatPrivate::P_NumFmt_Id)) |
|
|
|
|
|
fixNumFmt(format); |
|
|
|
|
|
|
|
|
//Font
|
|
|
//Font
|
|
|
if (format.hasFontData() && !format.fontIndexValid()) { |
|
|
if (format.hasFontData() && !format.fontIndexValid()) { |
|
|
//Assign proper font index, if has font data.
|
|
|
//Assign proper font index, if has font data.
|
|
@ -190,17 +234,6 @@ void Styles::addFormat(const Format &format, bool force) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Format
|
|
|
//Format
|
|
|
// if (format.isDxfFormat()) {
|
|
|
|
|
|
// if (!format.dxfIndexValid()) {
|
|
|
|
|
|
// if (!m_dxf_formatsHash.contains(format.formatKey())) {
|
|
|
|
|
|
// const_cast<Format *>(&format)->setDxfIndex(m_dxf_formatsList.size());
|
|
|
|
|
|
// m_dxf_formatsList.append(format);
|
|
|
|
|
|
// m_dxf_formatsHash[format.formatKey()] = format;
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// const_cast<Format *>(&format)->setDxfIndex(m_dxf_formatsHash[format.formatKey()].dxfIndex());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
if (!format.isEmpty() && !format.xfIndexValid()) { |
|
|
if (!format.isEmpty() && !format.xfIndexValid()) { |
|
|
if (m_xf_formatsHash.contains(format.formatKey())) |
|
|
if (m_xf_formatsHash.contains(format.formatKey())) |
|
|
const_cast<Format *>(&format)->setXfIndex(m_xf_formatsHash[format.formatKey()].xfIndex()); |
|
|
const_cast<Format *>(&format)->setXfIndex(m_xf_formatsHash[format.formatKey()].xfIndex()); |
|
@ -211,7 +244,24 @@ void Styles::addFormat(const Format &format, bool force) |
|
|
m_xf_formatsList.append(format); |
|
|
m_xf_formatsList.append(format); |
|
|
m_xf_formatsHash[format.formatKey()] = format; |
|
|
m_xf_formatsHash[format.formatKey()] = format; |
|
|
} |
|
|
} |
|
|
// }
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Styles::addDxfFormat(const Format &format, bool force) |
|
|
|
|
|
{ |
|
|
|
|
|
//numFmt
|
|
|
|
|
|
if (format.hasNumFmtData()) |
|
|
|
|
|
fixNumFmt(format); |
|
|
|
|
|
|
|
|
|
|
|
if (!format.isEmpty() && !format.dxfIndexValid()) { |
|
|
|
|
|
if (m_dxf_formatsHash.contains(format.formatKey())) |
|
|
|
|
|
const_cast<Format *>(&format)->setDxfIndex(m_dxf_formatsHash[format.formatKey()].dxfIndex()); |
|
|
|
|
|
else |
|
|
|
|
|
const_cast<Format *>(&format)->setDxfIndex(m_dxf_formatsList.size()); |
|
|
|
|
|
} |
|
|
|
|
|
if (!m_dxf_formatsHash.contains(format.formatKey()) || force) { |
|
|
|
|
|
m_dxf_formatsList.append(format); |
|
|
|
|
|
m_dxf_formatsHash[format.formatKey()] = format; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
QByteArray Styles::saveToXmlData() |
|
|
QByteArray Styles::saveToXmlData() |
|
@ -289,16 +339,32 @@ void Styles::writeNumFmts(XmlStreamWriter &writer) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
not consider dxf format. |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
void Styles::writeFonts(XmlStreamWriter &writer) |
|
|
void Styles::writeFonts(XmlStreamWriter &writer) |
|
|
{ |
|
|
{ |
|
|
writer.writeStartElement(QStringLiteral("fonts")); |
|
|
writer.writeStartElement(QStringLiteral("fonts")); |
|
|
writer.writeAttribute(QStringLiteral("count"), QString::number(m_fontsList.count())); |
|
|
writer.writeAttribute(QStringLiteral("count"), QString::number(m_fontsList.count())); |
|
|
for (int i=0; i<m_fontsList.size(); ++i) { |
|
|
for (int i=0; i<m_fontsList.size(); ++i) |
|
|
const Format &format = m_fontsList[i]; |
|
|
writeFont(writer, m_fontsList[i], false); |
|
|
|
|
|
writer.writeEndElement();//fonts
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Styles::writeFont(XmlStreamWriter &writer, const Format &format, bool isDxf) |
|
|
|
|
|
{ |
|
|
writer.writeStartElement(QStringLiteral("font")); |
|
|
writer.writeStartElement(QStringLiteral("font")); |
|
|
|
|
|
|
|
|
|
|
|
//The condense and extend elements are mainly used in dxf format
|
|
|
|
|
|
if (format.hasProperty(FormatPrivate::P_Font_Condense) |
|
|
|
|
|
&& !format.boolProperty(FormatPrivate::P_Font_Condense)) { |
|
|
|
|
|
writer.writeEmptyElement(QStringLiteral("condense")); |
|
|
|
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0")); |
|
|
|
|
|
} |
|
|
|
|
|
if (format.hasProperty(FormatPrivate::P_Font_Extend) |
|
|
|
|
|
&& !format.boolProperty(FormatPrivate::P_Font_Extend)) { |
|
|
|
|
|
writer.writeEmptyElement(QStringLiteral("extend")); |
|
|
|
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (format.fontBold()) |
|
|
if (format.fontBold()) |
|
|
writer.writeEmptyElement(QStringLiteral("b")); |
|
|
writer.writeEmptyElement(QStringLiteral("b")); |
|
|
if (format.fontItalic()) |
|
|
if (format.fontItalic()) |
|
@ -332,7 +398,7 @@ void Styles::writeFonts(XmlStreamWriter &writer) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (format.hasProperty(FormatPrivate::P_Font_Size)) { |
|
|
if (!isDxf && format.hasProperty(FormatPrivate::P_Font_Size)) { |
|
|
writer.writeEmptyElement(QStringLiteral("sz")); |
|
|
writer.writeEmptyElement(QStringLiteral("sz")); |
|
|
writer.writeAttribute(QStringLiteral("val"), QString::number(format.fontSize())); |
|
|
writer.writeAttribute(QStringLiteral("val"), QString::number(format.fontSize())); |
|
|
} |
|
|
} |
|
@ -349,6 +415,7 @@ void Styles::writeFonts(XmlStreamWriter &writer) |
|
|
writer.writeAttribute(QStringLiteral("tint"), themes[1]); |
|
|
writer.writeAttribute(QStringLiteral("tint"), themes[1]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!isDxf) { |
|
|
if (!format.fontName().isEmpty()) { |
|
|
if (!format.fontName().isEmpty()) { |
|
|
writer.writeEmptyElement(QStringLiteral("name")); |
|
|
writer.writeEmptyElement(QStringLiteral("name")); |
|
|
writer.writeAttribute(QStringLiteral("val"), format.fontName()); |
|
|
writer.writeAttribute(QStringLiteral("val"), format.fontName()); |
|
@ -362,24 +429,8 @@ void Styles::writeFonts(XmlStreamWriter &writer) |
|
|
writer.writeEmptyElement(QStringLiteral("scheme")); |
|
|
writer.writeEmptyElement(QStringLiteral("scheme")); |
|
|
writer.writeAttribute(QStringLiteral("val"), format.stringProperty(FormatPrivate::P_Font_Scheme)); |
|
|
writer.writeAttribute(QStringLiteral("val"), format.stringProperty(FormatPrivate::P_Font_Scheme)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// if (!format.isDxfFormat()) {
|
|
|
|
|
|
// writer.writeEmptyElement(QStringLiteral("sz"));
|
|
|
|
|
|
// writer.writeAttribute(QStringLiteral("val"), QString::number(format.fontSize()));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (!format.isDxfFormat()) {
|
|
|
|
|
|
// writer.writeEmptyElement(QStringLiteral("name"));
|
|
|
|
|
|
// writer.writeAttribute(QStringLiteral("val"), format.fontName());
|
|
|
|
|
|
// writer.writeEmptyElement(QStringLiteral("family"));
|
|
|
|
|
|
// writer.writeAttribute(QStringLiteral("val"), QString::number(format.fontFamily()));
|
|
|
|
|
|
// if (format.fontName() == QLatin1String("Calibri")) {
|
|
|
|
|
|
// writer.writeEmptyElement(QStringLiteral("scheme"));
|
|
|
|
|
|
// writer.writeAttribute(QStringLiteral("val"), format.fontScheme());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
writer.writeEndElement(); //font
|
|
|
|
|
|
} |
|
|
} |
|
|
writer.writeEndElement();//fonts
|
|
|
writer.writeEndElement(); //font
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Styles::writeFills(XmlStreamWriter &writer) |
|
|
void Styles::writeFills(XmlStreamWriter &writer) |
|
@ -393,7 +444,7 @@ void Styles::writeFills(XmlStreamWriter &writer) |
|
|
writer.writeEndElement(); //fills
|
|
|
writer.writeEndElement(); //fills
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Styles::writeFill(XmlStreamWriter &writer, const Format &fill) |
|
|
void Styles::writeFill(XmlStreamWriter &writer, const Format &fill, bool /*isDxf*/) |
|
|
{ |
|
|
{ |
|
|
static QMap<int, QString> patternStrings; |
|
|
static QMap<int, QString> patternStrings; |
|
|
if (patternStrings.isEmpty()) { |
|
|
if (patternStrings.isEmpty()) { |
|
@ -451,9 +502,13 @@ void Styles::writeBorders(XmlStreamWriter &writer) |
|
|
{ |
|
|
{ |
|
|
writer.writeStartElement(QStringLiteral("borders")); |
|
|
writer.writeStartElement(QStringLiteral("borders")); |
|
|
writer.writeAttribute(QStringLiteral("count"), QString::number(m_bordersList.count())); |
|
|
writer.writeAttribute(QStringLiteral("count"), QString::number(m_bordersList.count())); |
|
|
for (int i=0; i<m_bordersList.size(); ++i) { |
|
|
for (int i=0; i<m_bordersList.size(); ++i) |
|
|
const Format &border = m_bordersList[i]; |
|
|
writeBorder(writer, m_bordersList[i]); |
|
|
|
|
|
writer.writeEndElement();//borders
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Styles::writeBorder(XmlStreamWriter &writer, const Format &border, bool isDxf) |
|
|
|
|
|
{ |
|
|
writer.writeStartElement(QStringLiteral("border")); |
|
|
writer.writeStartElement(QStringLiteral("border")); |
|
|
if (border.hasProperty(FormatPrivate::P_Border_DiagonalType)) { |
|
|
if (border.hasProperty(FormatPrivate::P_Border_DiagonalType)) { |
|
|
Format::DiagonalBorderType t = border.diagonalBorderType(); |
|
|
Format::DiagonalBorderType t = border.diagonalBorderType(); |
|
@ -475,13 +530,16 @@ void Styles::writeBorders(XmlStreamWriter &writer) |
|
|
if (border.hasProperty(FormatPrivate::P_Border_BottomStyle)) |
|
|
if (border.hasProperty(FormatPrivate::P_Border_BottomStyle)) |
|
|
writeSubBorder(writer, QStringLiteral("bottom"), border.bottomBorderStyle(), border.bottomBorderColor(), border.stringProperty(FormatPrivate::P_Border_ThemeBottomColor)); |
|
|
writeSubBorder(writer, QStringLiteral("bottom"), border.bottomBorderStyle(), border.bottomBorderColor(), border.stringProperty(FormatPrivate::P_Border_ThemeBottomColor)); |
|
|
|
|
|
|
|
|
// if (!format.isDxfFormat()) {
|
|
|
//Condition DXF formats don't allow diagonal style
|
|
|
if (border.hasProperty(FormatPrivate::P_Border_DiagonalStyle)) |
|
|
if (!isDxf && border.hasProperty(FormatPrivate::P_Border_DiagonalStyle)) |
|
|
writeSubBorder(writer, QStringLiteral("diagonal"), border.diagonalBorderStyle(), border.diagonalBorderColor(), border.stringProperty(FormatPrivate::P_Border_ThemeDiagonalColor)); |
|
|
writeSubBorder(writer, QStringLiteral("diagonal"), border.diagonalBorderStyle(), border.diagonalBorderColor(), border.stringProperty(FormatPrivate::P_Border_ThemeDiagonalColor)); |
|
|
// }
|
|
|
|
|
|
writer.writeEndElement();//border
|
|
|
if (isDxf) { |
|
|
|
|
|
// writeSubBorder(wirter, QStringLiteral("vertical"), );
|
|
|
|
|
|
// writeSubBorder(writer, QStringLiteral("horizontal"), );
|
|
|
} |
|
|
} |
|
|
writer.writeEndElement();//borders
|
|
|
|
|
|
|
|
|
writer.writeEndElement();//border
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Styles::writeSubBorder(XmlStreamWriter &writer, const QString &type, int style, const QColor &color, const QString &themeColor) |
|
|
void Styles::writeSubBorder(XmlStreamWriter &writer, const QString &type, int style, const QColor &color, const QString &themeColor) |
|
@ -619,12 +677,31 @@ void Styles::writeDxfs(XmlStreamWriter &writer) |
|
|
{ |
|
|
{ |
|
|
writer.writeStartElement(QStringLiteral("dxfs")); |
|
|
writer.writeStartElement(QStringLiteral("dxfs")); |
|
|
writer.writeAttribute(QStringLiteral("count"), QString::number(m_dxf_formatsList.size())); |
|
|
writer.writeAttribute(QStringLiteral("count"), QString::number(m_dxf_formatsList.size())); |
|
|
foreach (const Format &format, m_dxf_formatsList) { |
|
|
foreach (const Format &format, m_dxf_formatsList) |
|
|
|
|
|
writeDxf(writer, format); |
|
|
|
|
|
writer.writeEndElement(); //dxfs
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Styles::writeDxf(XmlStreamWriter &writer, const Format &format) |
|
|
|
|
|
{ |
|
|
writer.writeStartElement(QStringLiteral("dxf")); |
|
|
writer.writeStartElement(QStringLiteral("dxf")); |
|
|
Q_UNUSED(format) |
|
|
|
|
|
writer.writeEndElement();//dxf
|
|
|
if (format.hasFontData()) |
|
|
|
|
|
writeFont(writer, format, true); |
|
|
|
|
|
|
|
|
|
|
|
if (format.hasNumFmtData()) { |
|
|
|
|
|
writer.writeEmptyElement(QStringLiteral("numFmt")); |
|
|
|
|
|
writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(format.numberFormatIndex())); |
|
|
|
|
|
writer.writeAttribute(QStringLiteral("formatCode"), format.numberFormat()); |
|
|
} |
|
|
} |
|
|
writer.writeEndElement(); //dxfs
|
|
|
|
|
|
|
|
|
if (format.hasFillData()) |
|
|
|
|
|
writeFill(writer, format, true); |
|
|
|
|
|
|
|
|
|
|
|
if (format.hasBorderData()) |
|
|
|
|
|
writeBorder(writer, format, true); |
|
|
|
|
|
|
|
|
|
|
|
writer.writeEndElement();//dxf
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool Styles::readNumFmts(XmlStreamReader &reader) |
|
|
bool Styles::readNumFmts(XmlStreamReader &reader) |
|
@ -661,7 +738,19 @@ bool Styles::readFonts(XmlStreamReader &reader) |
|
|
if (reader.name() != QLatin1String("font")) |
|
|
if (reader.name() != QLatin1String("font")) |
|
|
return false; |
|
|
return false; |
|
|
Format format; |
|
|
Format format; |
|
|
while((reader.readNextStartElement(),true)) { //read until font endelement.
|
|
|
readFont(reader, format); |
|
|
|
|
|
m_fontsList.append(format); |
|
|
|
|
|
m_fontsHash.insert(format.fontKey(), format); |
|
|
|
|
|
if (format.isValid()) |
|
|
|
|
|
format.setFontIndex(m_fontsList.size()-1); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Styles::readFont(XmlStreamReader &reader, Format &format) |
|
|
|
|
|
{ |
|
|
|
|
|
Q_ASSERT(reader.name() == QLatin1String("font")); |
|
|
|
|
|
while((reader.readNextStartElement(), true)) { //read until font endelement.
|
|
|
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|
|
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
if (reader.name() == QLatin1String("name")) { |
|
|
if (reader.name() == QLatin1String("name")) { |
|
@ -723,11 +812,6 @@ bool Styles::readFonts(XmlStreamReader &reader) |
|
|
if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("font")) |
|
|
if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("font")) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
m_fontsList.append(format); |
|
|
|
|
|
m_fontsHash.insert(format.fontKey(), format); |
|
|
|
|
|
if (format.isValid()) |
|
|
|
|
|
format.setFontIndex(m_fontsList.size()-1); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -741,12 +825,17 @@ bool Styles::readFills(XmlStreamReader &reader) |
|
|
reader.readNextStartElement(); |
|
|
reader.readNextStartElement(); |
|
|
if (reader.name() != QLatin1String("fill") || reader.tokenType() != QXmlStreamReader::StartElement) |
|
|
if (reader.name() != QLatin1String("fill") || reader.tokenType() != QXmlStreamReader::StartElement) |
|
|
return false; |
|
|
return false; |
|
|
readFill(reader); |
|
|
Format fill; |
|
|
|
|
|
readFill(reader, fill); |
|
|
|
|
|
m_fillsList.append(fill); |
|
|
|
|
|
m_fillsHash.insert(fill.fillKey(), fill); |
|
|
|
|
|
if (fill.isValid()) |
|
|
|
|
|
fill.setFillIndex(m_fillsList.size()-1); |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool Styles::readFill(XmlStreamReader &reader) |
|
|
bool Styles::readFill(XmlStreamReader &reader, Format &fill) |
|
|
{ |
|
|
{ |
|
|
Q_ASSERT(reader.name() == QLatin1String("fill")); |
|
|
Q_ASSERT(reader.name() == QLatin1String("fill")); |
|
|
|
|
|
|
|
@ -773,7 +862,6 @@ bool Styles::readFill(XmlStreamReader &reader) |
|
|
patternValues[QStringLiteral("lightGrid")] = Format::PatternLightGrid; |
|
|
patternValues[QStringLiteral("lightGrid")] = Format::PatternLightGrid; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Format fill; |
|
|
|
|
|
while((reader.readNextStartElement(), true)) { //read until fill endelement
|
|
|
while((reader.readNextStartElement(), true)) { //read until fill endelement
|
|
|
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|
|
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|
|
if (reader.name() == QLatin1String("patternFill")) { |
|
|
if (reader.name() == QLatin1String("patternFill")) { |
|
@ -821,11 +909,6 @@ bool Styles::readFill(XmlStreamReader &reader) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
m_fillsList.append(fill); |
|
|
|
|
|
m_fillsHash.insert(fill.fillKey(), fill); |
|
|
|
|
|
if (fill.isValid()) |
|
|
|
|
|
fill.setFillIndex(m_fillsList.size()-1); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -839,15 +922,19 @@ bool Styles::readBorders(XmlStreamReader &reader) |
|
|
reader.readNextStartElement(); |
|
|
reader.readNextStartElement(); |
|
|
if (reader.name() != QLatin1String("border") || reader.tokenType() != QXmlStreamReader::StartElement) |
|
|
if (reader.name() != QLatin1String("border") || reader.tokenType() != QXmlStreamReader::StartElement) |
|
|
return false; |
|
|
return false; |
|
|
readBorder(reader); |
|
|
Format border; |
|
|
|
|
|
readBorder(reader, border); |
|
|
|
|
|
m_bordersList.append(border); |
|
|
|
|
|
m_bordersHash.insert(border.borderKey(), border); |
|
|
|
|
|
if (border.isValid()) |
|
|
|
|
|
border.setBorderIndex(m_bordersList.size()-1); |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool Styles::readBorder(XmlStreamReader &reader) |
|
|
bool Styles::readBorder(XmlStreamReader &reader, Format &border) |
|
|
{ |
|
|
{ |
|
|
Q_ASSERT(reader.name() == QLatin1String("border")); |
|
|
Q_ASSERT(reader.name() == QLatin1String("border")); |
|
|
Format border; |
|
|
|
|
|
|
|
|
|
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
bool isUp = attributes.hasAttribute(QLatin1String("diagonalUp")); |
|
|
bool isUp = attributes.hasAttribute(QLatin1String("diagonalUp")); |
|
@ -907,11 +994,6 @@ bool Styles::readBorder(XmlStreamReader &reader) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
m_bordersList.append(border); |
|
|
|
|
|
m_bordersHash.insert(border.borderKey(), border); |
|
|
|
|
|
if (border.isValid()) |
|
|
|
|
|
border.setBorderIndex(m_bordersList.size()-1); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1085,7 +1167,7 @@ bool Styles::readCellXfs(XmlStreamReader &reader) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
addFormat(format, true); |
|
|
addXfFormat(format, true); |
|
|
|
|
|
|
|
|
//Find the endElement of xf
|
|
|
//Find the endElement of xf
|
|
|
while (!(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("xf"))) |
|
|
while (!(reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("xf"))) |
|
@ -1095,6 +1177,45 @@ bool Styles::readCellXfs(XmlStreamReader &reader) |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Styles::readDxfs(XmlStreamReader &reader) |
|
|
|
|
|
{ |
|
|
|
|
|
Q_ASSERT(reader.name() == QLatin1String("dxfs")); |
|
|
|
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
|
|
|
int count = attributes.value(QLatin1String("count")).toString().toInt(); |
|
|
|
|
|
for (int i=0; i<count; ++i) { |
|
|
|
|
|
reader.readNextStartElement(); |
|
|
|
|
|
if (reader.name() != QLatin1String("dxf")) |
|
|
|
|
|
return false; |
|
|
|
|
|
readDxf(reader); |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Styles::readDxf(XmlStreamReader &reader) |
|
|
|
|
|
{ |
|
|
|
|
|
Q_ASSERT(reader.name() == QLatin1String("dxf")); |
|
|
|
|
|
Format format; |
|
|
|
|
|
while (!(reader.name() == QLatin1String("dxf") && reader.tokenType() == QXmlStreamReader::EndElement)) { |
|
|
|
|
|
reader.readNextStartElement(); |
|
|
|
|
|
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|
|
|
|
|
if (reader.name() == QLatin1String("numFmt")) { |
|
|
|
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
|
|
|
int id = attributes.value(QLatin1String("numFmtId")).toString().toInt(); |
|
|
|
|
|
QString code = attributes.value(QLatin1String("formatCode")).toString(); |
|
|
|
|
|
format.setNumberFormat(id, code); |
|
|
|
|
|
} else if (reader.name() == QLatin1String("font")) { |
|
|
|
|
|
readFont(reader, format); |
|
|
|
|
|
} else if (reader.name() == QLatin1String("fill")) { |
|
|
|
|
|
readFill(reader, format); |
|
|
|
|
|
} else if (reader.name() == QLatin1String("border")) { |
|
|
|
|
|
readBorder(reader, format); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
addDxfFormat(format, true); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
bool Styles::readColors(XmlStreamReader &reader) |
|
|
bool Styles::readColors(XmlStreamReader &reader) |
|
|
{ |
|
|
{ |
|
|
Q_ASSERT(reader.name() == QLatin1String("colors")); |
|
|
Q_ASSERT(reader.name() == QLatin1String("colors")); |
|
|