From d87b50a4b718f39fbf256457fc8ae2507e146f37 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 30 Aug 2013 00:26:20 +0800 Subject: [PATCH] Wrap all char * string with QStringLiteral or QLatin1String --- src/xlsx/xlsxcontenttypes.cpp | 56 +++---- src/xlsx/xlsxdocprops.cpp | 92 +++++------ src/xlsx/xlsxformat.cpp | 22 +-- src/xlsx/xlsxformat_p.h | 4 +- src/xlsx/xlsxpackage.cpp | 42 ++--- src/xlsx/xlsxrelationships.cpp | 26 +-- src/xlsx/xlsxsharedstrings.cpp | 20 +-- src/xlsx/xlsxstyles.cpp | 278 ++++++++++++++++----------------- src/xlsx/xlsxutility.cpp | 6 +- src/xlsx/xlsxworkbook.cpp | 64 ++++---- src/xlsx/xlsxworksheet.cpp | 112 ++++++------- 11 files changed, 361 insertions(+), 361 deletions(-) diff --git a/src/xlsx/xlsxcontenttypes.cpp b/src/xlsx/xlsxcontenttypes.cpp index dfe27c6..117af73 100755 --- a/src/xlsx/xlsxcontenttypes.cpp +++ b/src/xlsx/xlsxcontenttypes.cpp @@ -31,17 +31,17 @@ namespace QXlsx { ContentTypes::ContentTypes() { - m_package_prefix = "application/vnd.openxmlformats-package."; - m_document_prefix = "application/vnd.openxmlformats-officedocument."; + m_package_prefix = QStringLiteral("application/vnd.openxmlformats-package."); + m_document_prefix = QStringLiteral("application/vnd.openxmlformats-officedocument."); - m_defaults.insert("rels", m_package_prefix + "relationships+xml"); - m_defaults.insert("xml", "application/xml"); + m_defaults.insert(QStringLiteral("rels"), m_package_prefix + QStringLiteral("relationships+xml")); + m_defaults.insert(QStringLiteral("xml"), QStringLiteral("application/xml")); - m_overrides.insert("/docProps/app.xml", m_document_prefix + "extended-properties+xml"); - m_overrides.insert("/docProps/core.xml", m_package_prefix + "core-properties+xml"); - m_overrides.insert("/xl/styles.xml", m_document_prefix + "spreadsheetml.styles+xml"); - m_overrides.insert("/xl/theme/theme1.xml", m_document_prefix + "theme+xml"); - m_overrides.insert("/xl/workbook.xml", m_document_prefix + "spreadsheetml.sheet.main+xml"); + m_overrides.insert(QStringLiteral("/docProps/app.xml"), m_document_prefix + QStringLiteral("extended-properties+xml")); + m_overrides.insert(QStringLiteral("/docProps/core.xml"), m_package_prefix + QStringLiteral("core-properties+xml")); + m_overrides.insert(QStringLiteral("/xl/styles.xml"), m_document_prefix + QStringLiteral("spreadsheetml.styles+xml")); + m_overrides.insert(QStringLiteral("/xl/theme/theme1.xml"), m_document_prefix + QStringLiteral("theme+xml")); + m_overrides.insert(QStringLiteral("/xl/workbook.xml"), m_document_prefix + QStringLiteral("spreadsheetml.sheet.main+xml")); } void ContentTypes::addDefault(const QString &key, const QString &value) @@ -56,71 +56,71 @@ void ContentTypes::addOverride(const QString &key, const QString &value) void ContentTypes::addWorksheetName(const QString &name) { - addOverride(QString("/xl/worksheets/%1.xml").arg(name), m_document_prefix + "spreadsheetml.worksheet+xml"); + addOverride(QStringLiteral("/xl/worksheets/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.worksheet+xml")); } void ContentTypes::addChartsheetName(const QString &name) { - addOverride(QString("/xl/chartsheets/%1.xml").arg(name), m_document_prefix + "spreadsheetml.chartsheet+xml"); + addOverride(QStringLiteral("/xl/chartsheets/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.chartsheet+xml")); } void ContentTypes::addChartName(const QString &name) { - addOverride(QString("/xl/charts/%1.xml").arg(name), m_document_prefix + "drawingml.chart+xml"); + addOverride(QStringLiteral("/xl/charts/%1.xml").arg(name), m_document_prefix + QStringLiteral("drawingml.chart+xml")); } void ContentTypes::addCommentName(const QString &name) { - addOverride(QString("/xl/%1.xml").arg(name), m_document_prefix + "spreadsheetml.comments+xml"); + addOverride(QStringLiteral("/xl/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.comments+xml")); } void ContentTypes::addImageTypes(const QStringList &imageTypes) { foreach (QString type, imageTypes) - addOverride(type, "image/" + type); + addOverride(type, QStringLiteral("image/") + type); } void ContentTypes::addTableName(const QString &name) { - addOverride(QString("/xl/tables/%1.xml").arg(name), m_document_prefix + "spreadsheetml.table+xml"); + addOverride(QStringLiteral("/xl/tables/%1.xml").arg(name), m_document_prefix + QStringLiteral("spreadsheetml.table+xml")); } void ContentTypes::addSharedString() { - addOverride("/xl/sharedStrings.xml", m_document_prefix + "spreadsheetml.sharedStrings+xml"); + addOverride(QStringLiteral("/xl/sharedStrings.xml"), m_document_prefix + QStringLiteral("spreadsheetml.sharedStrings+xml")); } void ContentTypes::addVmlName() { - addOverride("vml", m_document_prefix + "vmlDrawing"); + addOverride(QStringLiteral("vml"), m_document_prefix + QStringLiteral("vmlDrawing")); } void ContentTypes::addCalcChain() { - addOverride("/xl/calcChain.xml", m_document_prefix + "spreadsheetml.calcChain+xml"); + addOverride(QStringLiteral("/xl/calcChain.xml"), m_document_prefix + QStringLiteral("spreadsheetml.calcChain+xml")); } void ContentTypes::addVbaProject() { //:TODO - addOverride("bin", "application/vnd.ms-office.vbaProject"); + addOverride(QStringLiteral("bin"), QStringLiteral("application/vnd.ms-office.vbaProject")); } void ContentTypes::saveToXmlFile(QIODevice *device) { XmlStreamWriter writer(device); - writer.writeStartDocument("1.0", true); - writer.writeStartElement("Types"); - writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/package/2006/content-types"); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("Types")); + writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/content-types")); { QMapIterator it(m_defaults); while(it.hasNext()) { it.next(); - writer.writeStartElement("Default"); - writer.writeAttribute("Extension", it.key()); - writer.writeAttribute("ContentType", it.value()); + writer.writeStartElement(QStringLiteral("Default")); + writer.writeAttribute(QStringLiteral("Extension"), it.key()); + writer.writeAttribute(QStringLiteral("ContentType"), it.value()); writer.writeEndElement();//Default } } @@ -129,9 +129,9 @@ void ContentTypes::saveToXmlFile(QIODevice *device) QMapIterator it(m_overrides); while(it.hasNext()) { it.next(); - writer.writeStartElement("Override"); - writer.writeAttribute("PartName", it.key()); - writer.writeAttribute("ContentType", it.value()); + writer.writeStartElement(QStringLiteral("Override")); + writer.writeAttribute(QStringLiteral("PartName"), it.key()); + writer.writeAttribute(QStringLiteral("ContentType"), it.value()); writer.writeEndElement(); //Override } } diff --git a/src/xlsx/xlsxdocprops.cpp b/src/xlsx/xlsxdocprops.cpp index 58a9561..81027f9 100755 --- a/src/xlsx/xlsxdocprops.cpp +++ b/src/xlsx/xlsxdocprops.cpp @@ -50,44 +50,44 @@ void DocProps::saveToXmlFile_App(QIODevice *device) { XmlStreamWriter writer(device); - writer.writeStartDocument("1.0", true); - writer.writeStartElement("Properties"); - writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"); - writer.writeAttribute("xmlns:vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); - writer.writeTextElement("Application", "Microsoft Excel"); - writer.writeTextElement("DocSecurity", "0"); - writer.writeTextElement("ScaleCrop", "false"); - - writer.writeStartElement("HeadingPairs"); - writer.writeStartElement("vt:vector"); - writer.writeAttribute("size", QString::number(m_headingPairsList.size()*2)); - writer.writeAttribute("baseType", "variant"); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("Properties")); + writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties")); + writer.writeAttribute(QStringLiteral("xmlns:vt"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes")); + writer.writeTextElement(QStringLiteral("Application"), QStringLiteral("Microsoft Excel")); + writer.writeTextElement(QStringLiteral("DocSecurity"), QStringLiteral("0")); + writer.writeTextElement(QStringLiteral("ScaleCrop"), QStringLiteral("false")); + + writer.writeStartElement(QStringLiteral("HeadingPairs")); + writer.writeStartElement(QStringLiteral("vt:vector")); + writer.writeAttribute(QStringLiteral("size"), QString::number(m_headingPairsList.size()*2)); + writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("variant")); typedef QPair PairType; //Make foreach happy foreach (PairType pair, m_headingPairsList) { - writer.writeStartElement("vt:variant"); - writer.writeTextElement("vt:lpstr", pair.first); + writer.writeStartElement(QStringLiteral("vt:variant")); + writer.writeTextElement(QStringLiteral("vt:lpstr"), pair.first); writer.writeEndElement(); //vt:variant - writer.writeStartElement("vt:variant"); - writer.writeTextElement("vt:i4", QString::number(pair.second)); + writer.writeStartElement(QStringLiteral("vt:variant")); + writer.writeTextElement(QStringLiteral("vt:i4"), QString::number(pair.second)); writer.writeEndElement(); //vt:variant } writer.writeEndElement();//vt:vector writer.writeEndElement();//HeadingPairs - writer.writeStartElement("TitlesOfParts"); - writer.writeStartElement("vt:vector"); - writer.writeAttribute("size", QString::number(m_titlesOfPartsList.size())); - writer.writeAttribute("baseType", "lpstr"); + writer.writeStartElement(QStringLiteral("TitlesOfParts")); + writer.writeStartElement(QStringLiteral("vt:vector")); + writer.writeAttribute(QStringLiteral("size"), QString::number(m_titlesOfPartsList.size())); + writer.writeAttribute(QStringLiteral("baseType"), QStringLiteral("lpstr")); foreach (QString title, m_titlesOfPartsList) - writer.writeTextElement("vt:lpstr", title); + writer.writeTextElement(QStringLiteral("vt:lpstr"), title); writer.writeEndElement();//vt:vector writer.writeEndElement();//TitlesOfParts - writer.writeTextElement("Company", ""); - writer.writeTextElement("LinksUpToDate", "false"); - writer.writeTextElement("SharedDoc", "false"); - writer.writeTextElement("HyperlinksChanged", "false"); - writer.writeTextElement("AppVersion", "12.0000"); + writer.writeTextElement(QStringLiteral("Company"), QStringLiteral("")); + writer.writeTextElement(QStringLiteral("LinksUpToDate"), QStringLiteral("false")); + writer.writeTextElement(QStringLiteral("SharedDoc"), QStringLiteral("false")); + writer.writeTextElement(QStringLiteral("HyperlinksChanged"), QStringLiteral("false")); + writer.writeTextElement(QStringLiteral("AppVersion"), QStringLiteral("12.0000")); writer.writeEndElement(); //Properties writer.writeEndDocument(); } @@ -96,32 +96,32 @@ void DocProps::saveToXmlFile_Core(QIODevice *device) { XmlStreamWriter writer(device); - writer.writeStartDocument("1.0", true); - writer.writeStartElement("cp:coreProperties"); - writer.writeAttribute("xmlns:cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); - writer.writeAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); - writer.writeAttribute("xmlns:dcterms", "http://purl.org/dc/terms/"); - writer.writeAttribute("xmlns:dcmitype", "http://purl.org/dc/dcmitype/"); - writer.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - writer.writeTextElement("dc:title", ""); - writer.writeTextElement("dc:subject", ""); - writer.writeTextElement("dc:creator", "QXlsxWriter"); - writer.writeTextElement("cp:keywords", ""); - writer.writeTextElement("dc:description", ""); - writer.writeTextElement("cp:lastModifiedBy", ""); - - writer.writeStartElement("dcterms:created"); - writer.writeAttribute("xsi:type", "dcterms:W3CDTF"); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("cp:coreProperties")); + writer.writeAttribute(QStringLiteral("xmlns:cp"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")); + writer.writeAttribute(QStringLiteral("xmlns:dc"), QStringLiteral("http://purl.org/dc/elements/1.1/")); + writer.writeAttribute(QStringLiteral("xmlns:dcterms"), QStringLiteral("http://purl.org/dc/terms/")); + writer.writeAttribute(QStringLiteral("xmlns:dcmitype"), QStringLiteral("http://purl.org/dc/dcmitype/")); + writer.writeAttribute(QStringLiteral("xmlns:xsi"), QStringLiteral("http://www.w3.org/2001/XMLSchema-instance")); + writer.writeTextElement(QStringLiteral("dc:title"), QStringLiteral("")); + writer.writeTextElement(QStringLiteral("dc:subject"), QStringLiteral("")); + writer.writeTextElement(QStringLiteral("dc:creator"), QStringLiteral("QXlsxWriter")); + writer.writeTextElement(QStringLiteral("cp:keywords"), QStringLiteral("")); + writer.writeTextElement(QStringLiteral("dc:description"), QStringLiteral("")); + writer.writeTextElement(QStringLiteral("cp:lastModifiedBy"), QStringLiteral("")); + + writer.writeStartElement(QStringLiteral("dcterms:created")); + writer.writeAttribute(QStringLiteral("xsi:type"), QStringLiteral("dcterms:W3CDTF")); writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); writer.writeEndElement();//dcterms:created - writer.writeStartElement("dcterms:modified"); - writer.writeAttribute("xsi:type", "dcterms:W3CDTF"); + writer.writeStartElement(QStringLiteral("dcterms:modified")); + writer.writeAttribute(QStringLiteral("xsi:type"), QStringLiteral("dcterms:W3CDTF")); writer.writeCharacters(QDateTime::currentDateTime().toString(Qt::ISODate)); writer.writeEndElement();//dcterms:created - writer.writeTextElement("cp:category", ""); - writer.writeTextElement("cp:contentStatus", ""); + writer.writeTextElement(QStringLiteral("cp:category"), QStringLiteral("")); + writer.writeTextElement(QStringLiteral("cp:contentStatus"), QStringLiteral("")); writer.writeEndElement(); //cp:coreProperties writer.writeEndDocument(); } diff --git a/src/xlsx/xlsxformat.cpp b/src/xlsx/xlsxformat.cpp index 725d2b6..df89df4 100755 --- a/src/xlsx/xlsxformat.cpp +++ b/src/xlsx/xlsxformat.cpp @@ -371,25 +371,25 @@ QString Format::horizontalAlignmentString() const QString alignH; switch (d->alignmentData.alignH) { case Format::AlignLeft: - alignH = "left"; + alignH = QStringLiteral("left"); break; case Format::AlignHCenter: - alignH = "center"; + alignH = QStringLiteral("center"); break; case Format::AlignRight: - alignH = "right"; + alignH = QStringLiteral("right"); break; case Format::AlignHFill: - alignH = "fill"; + alignH = QStringLiteral("fill"); break; case Format::AlignHJustify: - alignH = "justify"; + alignH = QStringLiteral("justify"); break; case Format::AlignHMerge: - alignH = "centerContinuous"; + alignH = QStringLiteral("centerContinuous"); break; case Format::AlignHDistributed: - alignH = "distributed"; + alignH = QStringLiteral("distributed"); break; default: break; @@ -403,16 +403,16 @@ QString Format::verticalAlignmentString() const QString align; switch (d->alignmentData.alignV) { case AlignTop: - align = "top"; + align = QStringLiteral("top"); break; case AlignVCenter: - align = "center"; + align = QStringLiteral("center"); break; case AlignVJustify: - align = "justify"; + align = QStringLiteral("justify"); break; case AlignVDistributed: - align = "distributed"; + align = QStringLiteral("distributed"); break; default: break; diff --git a/src/xlsx/xlsxformat_p.h b/src/xlsx/xlsxformat_p.h index d042b10..9c38e21 100644 --- a/src/xlsx/xlsxformat_p.h +++ b/src/xlsx/xlsxformat_p.h @@ -40,8 +40,8 @@ struct FontData FontData() : size(11), italic(false), strikeOut(false), color(QColor()), bold(false) , scirpt(Format::FontScriptNormal), underline(Format::FontUnderlineNone) - , outline(false), shadow(false), name("Calibri"), family(2), charset(0) - , scheme("minor"), condense(0), extend(0) + , outline(false), shadow(false), name(QStringLiteral("Calibri")), family(2), charset(0) + , scheme(QStringLiteral("minor")), condense(0), extend(0) , _dirty(true), _redundant(false), _index(-1) {} diff --git a/src/xlsx/xlsxpackage.cpp b/src/xlsx/xlsxpackage.cpp index 36e6d8c..7d7c5f2 100644 --- a/src/xlsx/xlsxpackage.cpp +++ b/src/xlsx/xlsxpackage.cpp @@ -126,7 +126,7 @@ void Package::writeWorksheetFiles(ZipWriter &zipWriter) QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); sheet->saveToXmlFile(&buffer); - zipWriter.addFile(QString("xl/worksheets/sheet%1.xml").arg(index), data); + zipWriter.addFile(QStringLiteral("xl/worksheets/sheet%1.xml").arg(index), data); index += 1; } } @@ -137,7 +137,7 @@ void Package::writeWorkbookFile(ZipWriter &zipWriter) QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); m_workbook->saveToXmlFile(&buffer); - zipWriter.addFile("xl/workbook.xml", data); + zipWriter.addFile(QStringLiteral("xl/workbook.xml"), data); } void Package::writeContentTypesFiles(ZipWriter &zipWriter) @@ -149,7 +149,7 @@ void Package::writeContentTypesFiles(ZipWriter &zipWriter) if (sheet->isChartsheet()) { } else { - content.addWorksheetName(QString("sheet%1").arg(worksheet_index)); + content.addWorksheetName(QStringLiteral("sheet%1").arg(worksheet_index)); worksheet_index += 1; } } @@ -161,7 +161,7 @@ void Package::writeContentTypesFiles(ZipWriter &zipWriter) QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); content.saveToXmlFile(&buffer); - zipWriter.addFile("[Content_Types].xml", data); + zipWriter.addFile(QStringLiteral("[Content_Types].xml"), data); } void Package::writeDocPropsFiles(ZipWriter &zipWriter) @@ -169,9 +169,9 @@ void Package::writeDocPropsFiles(ZipWriter &zipWriter) DocProps props; if (m_worksheet_count) - props.addHeadingPair("Worksheets", m_worksheet_count); + props.addHeadingPair(QStringLiteral("Worksheets"), m_worksheet_count); if (m_chartsheet_count) - props.addHeadingPair("Chartsheets", m_chartsheet_count); + props.addHeadingPair(QStringLiteral("Chartsheets"), m_chartsheet_count); //Add worksheet parts foreach (Worksheet *sheet, m_workbook->worksheets()){ @@ -189,13 +189,13 @@ void Package::writeDocPropsFiles(ZipWriter &zipWriter) QBuffer buffer1(&data1); buffer1.open(QIODevice::WriteOnly); props.saveToXmlFile_App(&buffer1); - zipWriter.addFile("docProps/app.xml", data1); + zipWriter.addFile(QStringLiteral("docProps/app.xml"), data1); QByteArray data2; QBuffer buffer2(&data2); buffer2.open(QIODevice::WriteOnly); props.saveToXmlFile_Core(&buffer2); - zipWriter.addFile("docProps/core.xml", data2); + zipWriter.addFile(QStringLiteral("docProps/core.xml"), data2); } void Package::writeSharedStringsFile(ZipWriter &zipWriter) @@ -204,7 +204,7 @@ void Package::writeSharedStringsFile(ZipWriter &zipWriter) QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); m_workbook->sharedStrings()->saveToXmlFile(&buffer); - zipWriter.addFile("xl/sharedStrings.xml", data); + zipWriter.addFile(QStringLiteral("xl/sharedStrings.xml"), data); } void Package::writeStylesFiles(ZipWriter &zipWriter) @@ -213,7 +213,7 @@ void Package::writeStylesFiles(ZipWriter &zipWriter) QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); m_workbook->styles()->saveToXmlFile(&buffer); - zipWriter.addFile("xl/styles.xml", data); + zipWriter.addFile(QStringLiteral("xl/styles.xml"), data); } void Package::writeThemeFile(ZipWriter &zipWriter) @@ -222,21 +222,21 @@ void Package::writeThemeFile(ZipWriter &zipWriter) QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); Theme().saveToXmlFile(&buffer); - zipWriter.addFile("xl/theme/theme1.xml", data); + zipWriter.addFile(QStringLiteral("xl/theme/theme1.xml"), data); } void Package::writeRootRelsFile(ZipWriter &zipWriter) { Relationships rels; - rels.addDocumentRelationship("/officeDocument", "xl/workbook.xml"); - rels.addPackageRelationship("/metadata/core-properties", "docProps/core.xml"); - rels.addDocumentRelationship("/extended-properties", "docProps/app.xml"); + rels.addDocumentRelationship(QStringLiteral("/officeDocument"), QStringLiteral("xl/workbook.xml")); + rels.addPackageRelationship(QStringLiteral("/metadata/core-properties"), QStringLiteral("docProps/core.xml")); + rels.addDocumentRelationship(QStringLiteral("/extended-properties"), QStringLiteral("docProps/app.xml")); QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); rels.saveToXmlFile(&buffer); - zipWriter.addFile("_rels/.rels", data); + zipWriter.addFile(QStringLiteral("_rels/.rels"), data); } void Package::writeWorkbookRelsFile(ZipWriter &zipWriter) @@ -247,25 +247,25 @@ void Package::writeWorkbookRelsFile(ZipWriter &zipWriter) int chartsheet_index = 1; foreach (Worksheet *sheet, m_workbook->worksheets()) { if (sheet->isChartsheet()) { - rels.addDocumentRelationship("/chartsheet", QString("chartsheets/sheet%1.xml").arg(chartsheet_index)); + rels.addDocumentRelationship(QStringLiteral("/chartsheet"), QStringLiteral("chartsheets/sheet%1.xml").arg(chartsheet_index)); chartsheet_index += 1; } else { - rels.addDocumentRelationship("/worksheet", QString("worksheets/sheet%1.xml").arg(worksheet_index)); + rels.addDocumentRelationship(QStringLiteral("/worksheet"), QStringLiteral("worksheets/sheet%1.xml").arg(worksheet_index)); worksheet_index += 1; } } - rels.addDocumentRelationship("/theme", "theme/theme1.xml"); - rels.addDocumentRelationship("/styles", "styles.xml"); + rels.addDocumentRelationship(QStringLiteral("/theme"), QStringLiteral("theme/theme1.xml")); + rels.addDocumentRelationship(QStringLiteral("/styles"), QStringLiteral("styles.xml")); if (m_workbook->sharedStrings()->count()) - rels.addDocumentRelationship("/sharedStrings", "sharedStrings.xml"); + rels.addDocumentRelationship(QStringLiteral("/sharedStrings"), QStringLiteral("sharedStrings.xml")); QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); rels.saveToXmlFile(&buffer); - zipWriter.addFile("xl/_rels/workbook.xml.rels", data); + zipWriter.addFile(QStringLiteral("xl/_rels/workbook.xml.rels"), data); } void Package::writeWorksheetRelsFile(ZipWriter &zipWriter) diff --git a/src/xlsx/xlsxrelationships.cpp b/src/xlsx/xlsxrelationships.cpp index 7259cb4..1e2c567 100755 --- a/src/xlsx/xlsxrelationships.cpp +++ b/src/xlsx/xlsxrelationships.cpp @@ -36,32 +36,32 @@ Relationships::Relationships(QObject *parent) : void Relationships::addDocumentRelationship(const QString &relativeType, const QString &target) { - QString type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" + relativeType; + QString type = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships") + relativeType; addRelationship(type, target); } void Relationships::addMsPackageRelationship(const QString &relativeType, const QString &target) { - QString type = "http://schemas.microsoft.com/office/2006/relationships" + relativeType; + QString type = QStringLiteral("http://schemas.microsoft.com/office/2006/relationships") + relativeType; addRelationship(type, target); } void Relationships::addPackageRelationship(const QString &relativeType, const QString &target) { - QString type = "http://schemas.openxmlformats.org/package/2006/relationships" + relativeType; + QString type = QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships") + relativeType; addRelationship(type, target); } void Relationships::addWorksheetRelationship(const QString &relativeType, const QString &target, const QString &targetMode) { - QString type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships" + relativeType; + QString type = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships") + relativeType; addRelationship(type, target, targetMode); } void Relationships::addRelationship(const QString &type, const QString &target, const QString &targetMode) { XlsxRelationship relation; - relation.id = QString("rId%1").arg(m_relationships.size()+1); + relation.id = QStringLiteral("rId%1").arg(m_relationships.size()+1); relation.type = type; relation.target = target; relation.targetMode = targetMode; @@ -73,16 +73,16 @@ void Relationships::saveToXmlFile(QIODevice *device) { XmlStreamWriter writer(device); - writer.writeStartDocument("1.0", true); - writer.writeStartElement("Relationships"); - writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/package/2006/relationships"); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("Relationships")); + writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships")); foreach (XlsxRelationship relation, m_relationships) { - writer.writeStartElement("Relationship"); - writer.writeAttribute("Id", relation.id); - writer.writeAttribute("Type", relation.type); - writer.writeAttribute("Target", relation.target); + writer.writeStartElement(QStringLiteral("Relationship")); + writer.writeAttribute(QStringLiteral("Id"), relation.id); + writer.writeAttribute(QStringLiteral("Type"), relation.type); + writer.writeAttribute(QStringLiteral("Target"), relation.target); if (!relation.targetMode.isNull()) - writer.writeAttribute("TargetMode", relation.targetMode); + writer.writeAttribute(QStringLiteral("TargetMode"), relation.targetMode); writer.writeEndElement(); } writer.writeEndElement();//Relationships diff --git a/src/xlsx/xlsxsharedstrings.cpp b/src/xlsx/xlsxsharedstrings.cpp index dfc95c5..c374a65 100755 --- a/src/xlsx/xlsxsharedstrings.cpp +++ b/src/xlsx/xlsxsharedstrings.cpp @@ -74,21 +74,21 @@ void SharedStrings::saveToXmlFile(QIODevice *device) const { XmlStreamWriter writer(device); - writer.writeStartDocument("1.0", true); - writer.writeStartElement("sst"); - writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); - writer.writeAttribute("count", QString::number(m_stringCount)); - writer.writeAttribute("uniqueCount", QString::number(m_stringTable.size())); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("sst")); + writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); + writer.writeAttribute(QStringLiteral("count"), QString::number(m_stringCount)); + writer.writeAttribute(QStringLiteral("uniqueCount"), QString::number(m_stringTable.size())); foreach (QString string, m_stringList) { - writer.writeStartElement("si"); - if (string.contains(QRegularExpression("^")) || string.contains(QRegularExpression("$"))) { + writer.writeStartElement(QStringLiteral("si")); + if (string.contains(QRegularExpression(QStringLiteral("^"))) || string.contains(QRegularExpression(QStringLiteral("$")))) { //Rich text string, // writer.writeCharacters(string); } else { - writer.writeStartElement("t"); - if (string.contains(QRegularExpression("^\\s")) || string.contains(QRegularExpression("\\s$"))) - writer.writeAttribute("xml:space", "preserve"); + writer.writeStartElement(QStringLiteral("t")); + if (string.contains(QRegularExpression(QStringLiteral("^\\s"))) || string.contains(QRegularExpression(QStringLiteral("\\s$")))) + writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve")); writer.writeCharacters(string); writer.writeEndElement();//t } diff --git a/src/xlsx/xlsxstyles.cpp b/src/xlsx/xlsxstyles.cpp index 4e37ed9..7babd8c 100755 --- a/src/xlsx/xlsxstyles.cpp +++ b/src/xlsx/xlsxstyles.cpp @@ -141,44 +141,44 @@ void Styles::saveToXmlFile(QIODevice *device) { XmlStreamWriter writer(device); - writer.writeStartDocument("1.0", true); - writer.writeStartElement("styleSheet"); - writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("styleSheet")); + writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); -// writer.writeStartElement("numFmts"); +// writer.writeStartElement(QStringLiteral("numFmts")); // writer.writeEndElement();//numFmts writeFonts(writer); writeFills(writer); writeBorders(writer); - writer.writeStartElement("cellStyleXfs"); - writer.writeAttribute("count", "1"); - writer.writeStartElement("xf"); - writer.writeAttribute("numFmtId", "0"); - writer.writeAttribute("fontId", "0"); - writer.writeAttribute("fillId", "0"); - writer.writeAttribute("borderId", "0"); + writer.writeStartElement(QStringLiteral("cellStyleXfs")); + writer.writeAttribute(QStringLiteral("count"), QStringLiteral("1")); + writer.writeStartElement(QStringLiteral("xf")); + writer.writeAttribute(QStringLiteral("numFmtId"), QStringLiteral("0")); + writer.writeAttribute(QStringLiteral("fontId"), QStringLiteral("0")); + writer.writeAttribute(QStringLiteral("fillId"), QStringLiteral("0")); + writer.writeAttribute(QStringLiteral("borderId"), QStringLiteral("0")); writer.writeEndElement();//xf writer.writeEndElement();//cellStyleXfs writeCellXfs(writer); - writer.writeStartElement("cellStyles"); - writer.writeAttribute("count", "1"); - writer.writeStartElement("cellStyle"); - writer.writeAttribute("name", "Normal"); - writer.writeAttribute("xfId", "0"); - writer.writeAttribute("builtinId", "0"); + writer.writeStartElement(QStringLiteral("cellStyles")); + writer.writeAttribute(QStringLiteral("count"), QStringLiteral("1")); + writer.writeStartElement(QStringLiteral("cellStyle")); + writer.writeAttribute(QStringLiteral("name"), QStringLiteral("Normal")); + writer.writeAttribute(QStringLiteral("xfId"), QStringLiteral("0")); + writer.writeAttribute(QStringLiteral("builtinId"), QStringLiteral("0")); writer.writeEndElement();//cellStyle writer.writeEndElement();//cellStyles writeDxfs(writer); - writer.writeStartElement("tableStyles"); - writer.writeAttribute("count", "0"); - writer.writeAttribute("defaultTableStyle", "TableStyleMedium9"); - writer.writeAttribute("defaultPivotStyle", "PivotStyleLight16"); + writer.writeStartElement(QStringLiteral("tableStyles")); + writer.writeAttribute(QStringLiteral("count"), QStringLiteral("0")); + writer.writeAttribute(QStringLiteral("defaultTableStyle"), QStringLiteral("TableStyleMedium9")); + writer.writeAttribute(QStringLiteral("defaultPivotStyle"), QStringLiteral("PivotStyleLight16")); writer.writeEndElement();//tableStyles writer.writeEndElement();//styleSheet @@ -188,67 +188,67 @@ void Styles::saveToXmlFile(QIODevice *device) void Styles::writeFonts(XmlStreamWriter &writer) { - writer.writeStartElement("fonts"); - writer.writeAttribute("count", QString::number(m_font_count)); + writer.writeStartElement(QStringLiteral("fonts")); + writer.writeAttribute(QStringLiteral("count"), QString::number(m_font_count)); foreach (Format *format, m_xf_formats) { if (format->hasFont()) { - writer.writeStartElement("font"); + writer.writeStartElement(QStringLiteral("font")); if (format->fontBold()) - writer.writeEmptyElement("b"); + writer.writeEmptyElement(QStringLiteral("b")); if (format->fontItalic()) - writer.writeEmptyElement("i"); + writer.writeEmptyElement(QStringLiteral("i")); if (format->fontStrikeOut()) - writer.writeEmptyElement("strike"); + writer.writeEmptyElement(QStringLiteral("strike")); if (format->fontOutline()) - writer.writeEmptyElement("outline"); + writer.writeEmptyElement(QStringLiteral("outline")); if (format->fontShadow()) - writer.writeEmptyElement("shadow"); + writer.writeEmptyElement(QStringLiteral("shadow")); if (format->fontUnderline() != Format::FontUnderlineNone) { - writer.writeEmptyElement("u"); + writer.writeEmptyElement(QStringLiteral("u")); if (format->fontUnderline() == Format::FontUnderlineDouble) - writer.writeAttribute("val", "double"); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("double")); else if (format->fontUnderline() == Format::FontUnderlineSingleAccounting) - writer.writeAttribute("val", "singleAccounting"); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("singleAccounting")); else if (format->fontUnderline() == Format::FontUnderlineDoubleAccounting) - writer.writeAttribute("val", "doubleAccounting"); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("doubleAccounting")); } if (format->fontScript() != Format::FontScriptNormal) { - writer.writeEmptyElement("vertAligh"); + writer.writeEmptyElement(QStringLiteral("vertAligh")); if (format->fontScript() == Format::FontScriptSuper) - writer.writeAttribute("val", "superscript"); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("superscript")); else - writer.writeAttribute("val", "subscript"); + writer.writeAttribute(QStringLiteral("val"), QStringLiteral("subscript")); } if (!format->isDxfFormat()) { - writer.writeEmptyElement("sz"); - writer.writeAttribute("val", QString::number(format->fontSize())); + writer.writeEmptyElement(QStringLiteral("sz")); + writer.writeAttribute(QStringLiteral("val"), QString::number(format->fontSize())); } //font color if (format->theme()) { - writer.writeEmptyElement("color"); - writer.writeAttribute("theme", QString::number(format->theme())); + writer.writeEmptyElement(QStringLiteral("color")); + writer.writeAttribute(QStringLiteral("theme"), QString::number(format->theme())); } else if (format->colorIndexed()) { - writer.writeEmptyElement("color"); - writer.writeAttribute("indexed", QString::number(format->colorIndexed())); + writer.writeEmptyElement(QStringLiteral("color")); + writer.writeAttribute(QStringLiteral("indexed"), QString::number(format->colorIndexed())); } else if (format->fontColor().isValid()) { - writer.writeEmptyElement("color"); + writer.writeEmptyElement(QStringLiteral("color")); QString color = format->fontColor().name(); - writer.writeAttribute("rgb", "FF"+color.mid(1));//remove # + writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.mid(1));//remove # } else if (!format->isDxfFormat()) { - writer.writeEmptyElement("color"); - writer.writeAttribute("theme", "1"); + writer.writeEmptyElement(QStringLiteral("color")); + writer.writeAttribute(QStringLiteral("theme"), QStringLiteral("1")); } if (!format->isDxfFormat()) { - writer.writeEmptyElement("name"); - writer.writeAttribute("val", format->fontName()); - writer.writeEmptyElement("family"); - writer.writeAttribute("val", QString::number(format->fontFamily())); - if (format->fontName() == "Calibri") { - writer.writeEmptyElement("scheme"); - writer.writeAttribute("val", format->fontScheme()); + 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()); } } @@ -260,16 +260,16 @@ void Styles::writeFonts(XmlStreamWriter &writer) void Styles::writeFills(XmlStreamWriter &writer) { - writer.writeStartElement("fills"); - writer.writeAttribute("count", QString::number(m_fill_count)); + writer.writeStartElement(QStringLiteral("fills")); + writer.writeAttribute(QStringLiteral("count"), QString::number(m_fill_count)); //wirte two default fill first - writer.writeStartElement("fill"); - writer.writeEmptyElement("patternFill"); - writer.writeAttribute("patternType", "none"); + writer.writeStartElement(QStringLiteral("fill")); + writer.writeEmptyElement(QStringLiteral("patternFill")); + writer.writeAttribute(QStringLiteral("patternType"), QStringLiteral("none")); writer.writeEndElement();//fill - writer.writeStartElement("fill"); - writer.writeEmptyElement("patternFill"); - writer.writeAttribute("patternType", "gray125"); + writer.writeStartElement(QStringLiteral("fill")); + writer.writeEmptyElement(QStringLiteral("patternFill")); + writer.writeAttribute(QStringLiteral("patternType"), QStringLiteral("gray125")); writer.writeEndElement();//fill foreach (Format *format, m_xf_formats) { if (format->hasFill()) { @@ -283,36 +283,36 @@ void Styles::writeFill(XmlStreamWriter &writer, Format *format) { static QMap patternStrings; if (patternStrings.isEmpty()) { - patternStrings[Format::PatternNone] = "none"; - patternStrings[Format::PatternSolid] = "solid"; - patternStrings[Format::PatternMediumGray] = "mediumGray"; - patternStrings[Format::PatternDarkGray] = "darkGray"; - patternStrings[Format::PatternLightGray] = "lightGray"; - patternStrings[Format::PatternDarkHorizontal] = "darkHorizontal"; - patternStrings[Format::PatternDarkVertical] = "darkVertical"; - patternStrings[Format::PatternDarkDown] = "darkDown"; - patternStrings[Format::PatternDarkUp] = "darkUp"; - patternStrings[Format::PatternDarkGrid] = "darkGrid"; - patternStrings[Format::PatternDarkTrellis] = "darkTrellis"; - patternStrings[Format::PatternLightHorizontal] = "lightHorizontal"; - patternStrings[Format::PatternLightVertical] = "lightVertical"; - patternStrings[Format::PatternLightDown] = "lightDown"; - patternStrings[Format::PatternLightUp] = "lightUp"; - patternStrings[Format::PatternLightTrellis] = "lightTrellis"; - patternStrings[Format::PatternGray125] = "gray125"; - patternStrings[Format::PatternGray0625] = "gray0625"; + patternStrings[Format::PatternNone] = QStringLiteral("none"); + patternStrings[Format::PatternSolid] = QStringLiteral("solid"); + patternStrings[Format::PatternMediumGray] = QStringLiteral("mediumGray"); + patternStrings[Format::PatternDarkGray] = QStringLiteral("darkGray"); + patternStrings[Format::PatternLightGray] = QStringLiteral("lightGray"); + patternStrings[Format::PatternDarkHorizontal] = QStringLiteral("darkHorizontal"); + patternStrings[Format::PatternDarkVertical] = QStringLiteral("darkVertical"); + patternStrings[Format::PatternDarkDown] = QStringLiteral("darkDown"); + patternStrings[Format::PatternDarkUp] = QStringLiteral("darkUp"); + patternStrings[Format::PatternDarkGrid] = QStringLiteral("darkGrid"); + patternStrings[Format::PatternDarkTrellis] = QStringLiteral("darkTrellis"); + patternStrings[Format::PatternLightHorizontal] = QStringLiteral("lightHorizontal"); + patternStrings[Format::PatternLightVertical] = QStringLiteral("lightVertical"); + patternStrings[Format::PatternLightDown] = QStringLiteral("lightDown"); + patternStrings[Format::PatternLightUp] = QStringLiteral("lightUp"); + patternStrings[Format::PatternLightTrellis] = QStringLiteral("lightTrellis"); + patternStrings[Format::PatternGray125] = QStringLiteral("gray125"); + patternStrings[Format::PatternGray0625] = QStringLiteral("gray0625"); } - writer.writeStartElement("fill"); - writer.writeStartElement("patternFill"); - writer.writeAttribute("patternType", patternStrings[format->fillPattern()]); + writer.writeStartElement(QStringLiteral("fill")); + writer.writeStartElement(QStringLiteral("patternFill")); + writer.writeAttribute(QStringLiteral("patternType"), patternStrings[format->fillPattern()]); if (format->patternForegroundColor().isValid()) { - writer.writeEmptyElement("fgColor"); - writer.writeAttribute("rgb", "FF"+format->patternForegroundColor().name().mid(1)); + writer.writeEmptyElement(QStringLiteral("fgColor")); + writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+format->patternForegroundColor().name().mid(1)); } if (format->patternBackgroundColor().isValid()) { - writer.writeEmptyElement("bgColor"); - writer.writeAttribute("rgb", "FF"+format->patternBackgroundColor().name().mid(1)); + writer.writeEmptyElement(QStringLiteral("bgColor")); + writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+format->patternBackgroundColor().name().mid(1)); } writer.writeEndElement();//patternFill @@ -321,26 +321,26 @@ void Styles::writeFill(XmlStreamWriter &writer, Format *format) void Styles::writeBorders(XmlStreamWriter &writer) { - writer.writeStartElement("borders"); - writer.writeAttribute("count", QString::number(m_borders_count)); + writer.writeStartElement(QStringLiteral("borders")); + writer.writeAttribute(QStringLiteral("count"), QString::number(m_borders_count)); foreach (Format *format, m_xf_formats) { if (format->hasBorders()) { - writer.writeStartElement("border"); + writer.writeStartElement(QStringLiteral("border")); if (format->diagonalBorderType() == Format::DiagonalBorderUp) { - writer.writeAttribute("diagonalUp", "1"); + writer.writeAttribute(QStringLiteral("diagonalUp"), QStringLiteral("1")); } else if (format->diagonalBorderType() == Format::DiagonalBorderDown) { - writer.writeAttribute("diagonalDown", "1"); + writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1")); } else if (format->DiagnoalBorderBoth) { - writer.writeAttribute("diagonalUp", "1"); - writer.writeAttribute("diagonalDown", "1"); + writer.writeAttribute(QStringLiteral("diagonalUp"), QStringLiteral("1")); + writer.writeAttribute(QStringLiteral("diagonalDown"), QStringLiteral("1")); } - writeSubBorder(writer, "left", format->leftBorderStyle(), format->leftBorderColor()); - writeSubBorder(writer, "right", format->rightBorderStyle(), format->rightBorderColor()); - writeSubBorder(writer, "top", format->topBorderStyle(), format->topBorderColor()); - writeSubBorder(writer, "bottom", format->bottomBorderStyle(), format->bottomBorderColor()); + writeSubBorder(writer, QStringLiteral("left"), format->leftBorderStyle(), format->leftBorderColor()); + writeSubBorder(writer, QStringLiteral("right"), format->rightBorderStyle(), format->rightBorderColor()); + writeSubBorder(writer, QStringLiteral("top"), format->topBorderStyle(), format->topBorderColor()); + writeSubBorder(writer, QStringLiteral("bottom"), format->bottomBorderStyle(), format->bottomBorderColor()); if (!format->isDxfFormat()) { - writeSubBorder(writer, "diagonal", format->diagonalBorderStyle(), format->diagonalBorderColor()); + writeSubBorder(writer, QStringLiteral("diagonal"), format->diagonalBorderStyle(), format->diagonalBorderColor()); } writer.writeEndElement();//border } @@ -357,75 +357,75 @@ void Styles::writeSubBorder(XmlStreamWriter &writer, const QString &type, int st static QMap stylesString; if (stylesString.isEmpty()) { - stylesString[Format::BorderNone] = "none"; - stylesString[Format::BorderThin] = "thin"; - stylesString[Format::BorderMedium] = "medium"; - stylesString[Format::BorderDashed] = "dashed"; - stylesString[Format::BorderDotted] = "dotted"; - stylesString[Format::BorderThick] = "thick"; - stylesString[Format::BorderDouble] = "double"; - stylesString[Format::BorderHair] = "hair"; - stylesString[Format::BorderMediumDashed] = "mediumDashed"; - stylesString[Format::BorderDashDot] = "dashDot"; - stylesString[Format::BorderMediumDashDot] = "mediumDashDot"; - stylesString[Format::BorderDashDotDot] = "dashDotDot"; - stylesString[Format::BorderMediumDashDotDot] = "mediumDashDotDot"; - stylesString[Format::BorderSlantDashDot] = "slantDashDot"; + stylesString[Format::BorderNone] = QStringLiteral("none"); + stylesString[Format::BorderThin] = QStringLiteral("thin"); + stylesString[Format::BorderMedium] = QStringLiteral("medium"); + stylesString[Format::BorderDashed] = QStringLiteral("dashed"); + stylesString[Format::BorderDotted] = QStringLiteral("dotted"); + stylesString[Format::BorderThick] = QStringLiteral("thick"); + stylesString[Format::BorderDouble] = QStringLiteral("double"); + stylesString[Format::BorderHair] = QStringLiteral("hair"); + stylesString[Format::BorderMediumDashed] = QStringLiteral("mediumDashed"); + stylesString[Format::BorderDashDot] = QStringLiteral("dashDot"); + stylesString[Format::BorderMediumDashDot] = QStringLiteral("mediumDashDot"); + stylesString[Format::BorderDashDotDot] = QStringLiteral("dashDotDot"); + stylesString[Format::BorderMediumDashDotDot] = QStringLiteral("mediumDashDotDot"); + stylesString[Format::BorderSlantDashDot] = QStringLiteral("slantDashDot"); } writer.writeStartElement(type); - writer.writeAttribute("style", stylesString[style]); - writer.writeEmptyElement("color"); + writer.writeAttribute(QStringLiteral("style"), stylesString[style]); + writer.writeEmptyElement(QStringLiteral("color")); if (color.isValid()) - writer.writeAttribute("rgb", "FF"+color.name().mid(1)); //remove # + writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.name().mid(1)); //remove # else - writer.writeAttribute("auto", "1"); + writer.writeAttribute(QStringLiteral("auto"), QStringLiteral("1")); writer.writeEndElement();//type } void Styles::writeCellXfs(XmlStreamWriter &writer) { - writer.writeStartElement("cellXfs"); - writer.writeAttribute("count", QString::number(m_xf_formats.size())); + writer.writeStartElement(QStringLiteral("cellXfs")); + writer.writeAttribute(QStringLiteral("count"), QString::number(m_xf_formats.size())); foreach (Format *format, m_xf_formats) { int num_fmt_id = format->numberFormat(); int font_id = format->fontIndex(); int fill_id = format->fillIndex(); int border_id = format->borderIndex(); int xf_id = 0; - writer.writeStartElement("xf"); - writer.writeAttribute("numFmtId", QString::number(num_fmt_id)); - writer.writeAttribute("fontId", QString::number(font_id)); - writer.writeAttribute("fillId", QString::number(fill_id)); - writer.writeAttribute("borderId", QString::number(border_id)); - writer.writeAttribute("xfId", QString::number(xf_id)); + writer.writeStartElement(QStringLiteral("xf")); + writer.writeAttribute(QStringLiteral("numFmtId"), QString::number(num_fmt_id)); + writer.writeAttribute(QStringLiteral("fontId"), QString::number(font_id)); + writer.writeAttribute(QStringLiteral("fillId"), QString::number(fill_id)); + writer.writeAttribute(QStringLiteral("borderId"), QString::number(border_id)); + writer.writeAttribute(QStringLiteral("xfId"), QString::number(xf_id)); if (format->numberFormat() > 0) - writer.writeAttribute("applyNumberFormat", "1"); + writer.writeAttribute(QStringLiteral("applyNumberFormat"), QStringLiteral("1")); if (format->fontIndex() > 0) - writer.writeAttribute("applyFont", "1"); + writer.writeAttribute(QStringLiteral("applyFont"), QStringLiteral("1")); if (format->borderIndex() > 0) - writer.writeAttribute("applyBorder", "1"); + writer.writeAttribute(QStringLiteral("applyBorder"), QStringLiteral("1")); if (format->fillIndex() > 0) - writer.writeAttribute("applyFill", "1"); + writer.writeAttribute(QStringLiteral("applyFill"), QStringLiteral("1")); if (format->alignmentChanged()) - writer.writeAttribute("applyAlignment", "1"); + writer.writeAttribute(QStringLiteral("applyAlignment"), QStringLiteral("1")); if (format->alignmentChanged()) { - writer.writeEmptyElement("alignment"); + writer.writeEmptyElement(QStringLiteral("alignment")); QString alignH = format->horizontalAlignmentString(); if (!alignH.isEmpty()) - writer.writeAttribute("horizontal", alignH); + writer.writeAttribute(QStringLiteral("horizontal"), alignH); QString alignV = format->verticalAlignmentString(); if (!alignV.isEmpty()) - writer.writeAttribute("vertical", alignV); + writer.writeAttribute(QStringLiteral("vertical"), alignV); if (format->indent()) - writer.writeAttribute("indent", QString::number(format->indent())); + writer.writeAttribute(QStringLiteral("indent"), QString::number(format->indent())); if (format->textWrap()) - writer.writeAttribute("wrapText", "1"); + writer.writeAttribute(QStringLiteral("wrapText"), QStringLiteral("1")); if (format->shrinkToFit()) - writer.writeAttribute("shrinkToFit", "1"); + writer.writeAttribute(QStringLiteral("shrinkToFit"), QStringLiteral("1")); if (format->shrinkToFit()) - writer.writeAttribute("shrinkToFit", "1"); + writer.writeAttribute(QStringLiteral("shrinkToFit"), QStringLiteral("1")); } writer.writeEndElement();//xf @@ -435,10 +435,10 @@ void Styles::writeCellXfs(XmlStreamWriter &writer) void Styles::writeDxfs(XmlStreamWriter &writer) { - writer.writeStartElement("dxfs"); - writer.writeAttribute("count", QString::number(m_dxf_formats.size())); + writer.writeStartElement(QStringLiteral("dxfs")); + writer.writeAttribute(QStringLiteral("count"), QString::number(m_dxf_formats.size())); foreach (Format *format, m_dxf_formats) { - writer.writeStartElement("dxf"); + writer.writeStartElement(QStringLiteral("dxf")); writer.writeEndElement();//dxf } writer.writeEndElement(); //dxfs diff --git a/src/xlsx/xlsxutility.cpp b/src/xlsx/xlsxutility.cpp index c98d880..4487304 100755 --- a/src/xlsx/xlsxutility.cpp +++ b/src/xlsx/xlsxutility.cpp @@ -45,7 +45,7 @@ QPoint xl_cell_to_rowcol(const QString &cell_str) { if (cell_str.isEmpty()) return QPoint(0, 0); - QRegularExpression re("^([A-Z]{1,3})(\\d+)$"); + QRegularExpression re(QStringLiteral("^([A-Z]{1,3})(\\d+)$")); QRegularExpressionMatch match = re.match(cell_str); if (match.hasMatch()) { QString col_str = match.captured(1); @@ -87,10 +87,10 @@ QString xl_rowcol_to_cell(int row, int col, bool row_abs, bool col_abs) row += 1; //Change to 1-index QString cell_str; if (col_abs) - cell_str.append("$"); + cell_str.append(QLatin1Char('$')); cell_str.append(xl_col_to_name(col)); if (row_abs) - cell_str.append("$"); + cell_str.append(QLatin1Char('$')); cell_str.append(QString::number(row)); return cell_str; } diff --git a/src/xlsx/xlsxworkbook.cpp b/src/xlsx/xlsxworkbook.cpp index 67fcbd4..f2d1d24 100755 --- a/src/xlsx/xlsxworkbook.cpp +++ b/src/xlsx/xlsxworkbook.cpp @@ -137,7 +137,7 @@ Worksheet *Workbook::addWorksheet(const QString &name) QString worksheetName = name; int index = d->worksheets.size()+1; if (name.isEmpty()) - worksheetName = QString("Sheet%1").arg(index); + worksheetName = QStringLiteral("Sheet%1").arg(index); Worksheet *sheet = new Worksheet(worksheetName, index, this); d->worksheets.append(sheet); @@ -173,53 +173,53 @@ void Workbook::saveToXmlFile(QIODevice *device) Q_D(Workbook); XmlStreamWriter writer(device); - writer.writeStartDocument("1.0", true); - writer.writeStartElement("workbook"); - writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); - writer.writeAttribute("xmlns:r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("workbook")); + writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); + writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); - writer.writeEmptyElement("fileVersion"); - writer.writeAttribute("appName", "xl"); - writer.writeAttribute("lastEdited", "4"); - writer.writeAttribute("lowestEdited", "4"); - writer.writeAttribute("rupBuild", "4505"); -// writer.writeAttribute("codeName", "{37E998C4-C9E5-D4B9-71C8-EB1FF731991C}"); + writer.writeEmptyElement(QStringLiteral("fileVersion")); + writer.writeAttribute(QStringLiteral("appName"), QStringLiteral("xl")); + writer.writeAttribute(QStringLiteral("lastEdited"), QStringLiteral("4")); + writer.writeAttribute(QStringLiteral("lowestEdited"), QStringLiteral("4")); + writer.writeAttribute(QStringLiteral("rupBuild"), QStringLiteral("4505")); +// writer.writeAttribute(QStringLiteral("codeName"), QStringLiteral("{37E998C4-C9E5-D4B9-71C8-EB1FF731991C}")); - writer.writeEmptyElement("workbookPr"); + writer.writeEmptyElement(QStringLiteral("workbookPr")); if (d->date1904) - writer.writeAttribute("date1904", "1"); - writer.writeAttribute("defaultThemeVersion", "124226"); - - writer.writeStartElement("bookViews"); - writer.writeEmptyElement("workbookView"); - writer.writeAttribute("xWindow", QString::number(d->x_window)); - writer.writeAttribute("yWindow", QString::number(d->y_window)); - writer.writeAttribute("windowWidth", QString::number(d->window_width)); - writer.writeAttribute("windowHeight", QString::number(d->window_height)); + writer.writeAttribute(QStringLiteral("date1904"), QStringLiteral("1")); + writer.writeAttribute(QStringLiteral("defaultThemeVersion"), QStringLiteral("124226")); + + writer.writeStartElement(QStringLiteral("bookViews")); + writer.writeEmptyElement(QStringLiteral("workbookView")); + writer.writeAttribute(QStringLiteral("xWindow"), QString::number(d->x_window)); + writer.writeAttribute(QStringLiteral("yWindow"), QString::number(d->y_window)); + writer.writeAttribute(QStringLiteral("windowWidth"), QString::number(d->window_width)); + writer.writeAttribute(QStringLiteral("windowHeight"), QString::number(d->window_height)); //Store the firstSheet when it isn't the default if (d->firstsheet > 0) - writer.writeAttribute("firstSheet", QString::number(d->firstsheet + 1)); + writer.writeAttribute(QStringLiteral("firstSheet"), QString::number(d->firstsheet + 1)); //Store the activeTab when it isn't the first sheet if (d->activesheet > 0) - writer.writeAttribute("activeTab", QString::number(d->activesheet)); + writer.writeAttribute(QStringLiteral("activeTab"), QString::number(d->activesheet)); writer.writeEndElement();//bookviews - writer.writeStartElement("sheets"); + writer.writeStartElement(QStringLiteral("sheets")); foreach (Worksheet *sheet, d->worksheets) { - writer.writeEmptyElement("sheet"); - writer.writeAttribute("name", sheet->name()); - writer.writeAttribute("sheetId", QString::number(sheet->index())); + writer.writeEmptyElement(QStringLiteral("sheet")); + writer.writeAttribute(QStringLiteral("name"), sheet->name()); + writer.writeAttribute(QStringLiteral("sheetId"), QString::number(sheet->index())); if (sheet->isHidden()) - writer.writeAttribute("state", "hidden"); - writer.writeAttribute("r:id", QString("rId%1").arg(sheet->index())); + writer.writeAttribute(QStringLiteral("state"), QStringLiteral("hidden")); + writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(sheet->index())); } writer.writeEndElement();//sheets -// writer.writeStartElement("definedNames"); +// writer.writeStartElement(QStringLiteral("definedNames")); // writer.writeEndElement();//definedNames - writer.writeStartElement("calcPr"); - writer.writeAttribute("calcId", "124519"); + writer.writeStartElement(QStringLiteral("calcPr")); + writer.writeAttribute(QStringLiteral("calcId"), QStringLiteral("124519")); writer.writeEndElement(); //calcPr writer.writeEndElement();//workbook diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 2abcb7c..acd6e53 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -130,7 +130,7 @@ void WorksheetPrivate::calculateSpans() if (span_max != INT32_MIN) { span_min += 1; span_max += 1; - row_spans[span_index] = QString("%1:%2").arg(span_min).arg(span_max); + row_spans[span_index] = QStringLiteral("%1:%2").arg(span_min).arg(span_max); span_max = INT32_MIN; } } @@ -143,7 +143,7 @@ QString WorksheetPrivate::generateDimensionString() if (dim_rowmax == INT32_MIN && dim_colmax == INT32_MIN) { //If the max dimensions are equal to INT32_MIN, then no dimension have been set //and we use the default "A1" - return "A1"; + return QStringLiteral("A1"); } if (dim_rowmax == INT32_MIN) { @@ -154,7 +154,7 @@ QString WorksheetPrivate::generateDimensionString() } else { const QString cell_1 = xl_rowcol_to_cell(0, dim_colmin); const QString cell_2 = xl_rowcol_to_cell(0, dim_colmax); - return cell_1 + ":" + cell_2; + return cell_1 + QLatin1String(":") + cell_2; } } @@ -165,7 +165,7 @@ QString WorksheetPrivate::generateDimensionString() QString cell_1 = xl_rowcol_to_cell(dim_rowmin, dim_colmin); QString cell_2 = xl_rowcol_to_cell(dim_rowmax, dim_colmax); - return cell_1 + ":" + cell_2; + return cell_1 + QLatin1String(":") + cell_2; } /* @@ -302,9 +302,9 @@ int Worksheet::write(int row, int column, const QVariant &value, Format *format) } else if (value.type() == QMetaType::QString) { //string QString token = value.toString(); - if (token.startsWith("=")) { + if (token.startsWith(QLatin1String("="))) { ret = writeFormula(row, column, token, format); - } else if (token.startsWith("{") && token.endsWith("}")) { + } else if (token.startsWith(QLatin1String("{")) && token.endsWith(QLatin1String("}"))) { } else { ret = writeString(row, column, token, format); @@ -366,7 +366,7 @@ int Worksheet::writeFormula(int row, int column, const QString &content, Format return -1; //Remove the formula '=' sign if exists - if (formula.startsWith("=")) + if (formula.startsWith(QLatin1String("="))) formula.remove(0,1); XlsxCellData *data = new XlsxCellData(result, XlsxCellData::Formula, format); @@ -411,65 +411,65 @@ void Worksheet::saveToXmlFile(QIODevice *device) Q_D(Worksheet); XmlStreamWriter writer(device); - writer.writeStartDocument("1.0", true); - writer.writeStartElement("worksheet"); - writer.writeAttribute("xmlns", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); - writer.writeAttribute("xmlns:r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); + writer.writeStartDocument(QStringLiteral("1.0"), true); + writer.writeStartElement(QStringLiteral("worksheet")); + writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); + writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); //for Excel 2010 // writer.writeAttribute("xmlns:mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); // writer.writeAttribute("xmlns:x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); // writer.writeAttribute("mc:Ignorable", "x14ac"); - writer.writeStartElement("dimension"); - writer.writeAttribute("ref", d->generateDimensionString()); + writer.writeStartElement(QStringLiteral("dimension")); + writer.writeAttribute(QStringLiteral("ref"), d->generateDimensionString()); writer.writeEndElement();//dimension - writer.writeStartElement("sheetViews"); - writer.writeStartElement("sheetView"); + writer.writeStartElement(QStringLiteral("sheetViews")); + writer.writeStartElement(QStringLiteral("sheetView")); if (!d->show_zeros) - writer.writeAttribute("showZeros", "0"); + writer.writeAttribute(QStringLiteral("showZeros"), QStringLiteral("0")); if (d->right_to_left) - writer.writeAttribute("rightToLeft", "1"); + writer.writeAttribute(QStringLiteral("rightToLeft"), QStringLiteral("1")); if (d->selected) - writer.writeAttribute("tabSelected", "1"); - writer.writeAttribute("workbookViewId", "0"); + writer.writeAttribute(QStringLiteral("tabSelected"), QStringLiteral("1")); + writer.writeAttribute(QStringLiteral("workbookViewId"), QStringLiteral("0")); writer.writeEndElement();//sheetView writer.writeEndElement();//sheetViews - writer.writeStartElement("sheetFormatPr"); - writer.writeAttribute("defaultRowHeight", QString::number(d->default_row_height)); + writer.writeStartElement(QStringLiteral("sheetFormatPr")); + writer.writeAttribute(QStringLiteral("defaultRowHeight"), QString::number(d->default_row_height)); if (d->default_row_height != 15) - writer.writeAttribute("customHeight", "1"); + writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("1")); if (d->default_row_zeroed) - writer.writeAttribute("zeroHeight", "1"); + writer.writeAttribute(QStringLiteral("zeroHeight"), QStringLiteral("1")); if (d->outline_row_level) - writer.writeAttribute("outlineLevelRow", QString::number(d->outline_row_level)); + writer.writeAttribute(QStringLiteral("outlineLevelRow"), QString::number(d->outline_row_level)); if (d->outline_col_level) - writer.writeAttribute("outlineLevelCol", QString::number(d->outline_col_level)); + writer.writeAttribute(QStringLiteral("outlineLevelCol"), QString::number(d->outline_col_level)); //for Excel 2010 // writer.writeAttribute("x14ac:dyDescent", "0.25"); writer.writeEndElement();//sheetFormatPr if (!d->colsInfo.isEmpty()) { - writer.writeStartElement("cols"); + writer.writeStartElement(QStringLiteral("cols")); foreach (XlsxColumnInfo *col_info, d->colsInfo) { - writer.writeStartElement("col"); - writer.writeAttribute("min", QString::number(col_info->column_min)); - writer.writeAttribute("max", QString::number(col_info->column_max)); - writer.writeAttribute("width", QString::number(col_info->width, 'g', 15)); + writer.writeStartElement(QStringLiteral("col")); + writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->column_min)); + writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->column_max)); + writer.writeAttribute(QStringLiteral("width"), QString::number(col_info->width, 'g', 15)); if (col_info->format) - writer.writeAttribute("style", QString::number(col_info->format->xfIndex())); + writer.writeAttribute(QStringLiteral("style"), QString::number(col_info->format->xfIndex())); if (col_info->hidden) - writer.writeAttribute("hidden", "1"); + writer.writeAttribute(QStringLiteral("hidden"), QStringLiteral("1")); if (col_info->width) - writer.writeAttribute("customWidth", "1"); + writer.writeAttribute(QStringLiteral("customWidth"), QStringLiteral("1")); writer.writeEndElement();//col } writer.writeEndElement();//cols } - writer.writeStartElement("sheetData"); + writer.writeStartElement(QStringLiteral("sheetData")); if (d->dim_rowmax == INT32_MIN) { //If the max dimensions are equal to INT32_MIN, then there is no data to write } else { @@ -496,24 +496,24 @@ void WorksheetPrivate::writeSheetData(XmlStreamWriter &writer) span = row_spans[span_index]; if (cellTable.contains(row_num)) { - writer.writeStartElement("row"); - writer.writeAttribute("r", QString::number(row_num + 1)); + writer.writeStartElement(QStringLiteral("row")); + writer.writeAttribute(QStringLiteral("r"), QString::number(row_num + 1)); if (!span.isEmpty()) - writer.writeAttribute("spans", span); + writer.writeAttribute(QStringLiteral("spans"), span); if (rowsInfo.contains(row_num)) { XlsxRowInfo *rowInfo = rowsInfo[row_num]; if (rowInfo->format) { - writer.writeAttribute("s", QString::number(rowInfo->format->xfIndex())); - writer.writeAttribute("customFormat", "1"); + writer.writeAttribute(QStringLiteral("s"), QString::number(rowInfo->format->xfIndex())); + writer.writeAttribute(QStringLiteral("customFormat"), QStringLiteral("1")); } if (rowInfo->height != 15) { - writer.writeAttribute("ht", QString::number(rowInfo->height)); - writer.writeAttribute("customHeight", "1"); + writer.writeAttribute(QStringLiteral("ht"), QString::number(rowInfo->height)); + writer.writeAttribute(QStringLiteral("customHeight"), QStringLiteral("1")); } if (rowInfo->hidden) - writer.writeAttribute("hidden", "1"); + writer.writeAttribute(QStringLiteral("hidden"), QStringLiteral("1")); } for (int col_num = dim_colmin; col_num <= dim_colmax; col_num++) { @@ -535,36 +535,36 @@ void WorksheetPrivate::writeCellData(XmlStreamWriter &writer, int row, int col, //This is the innermost loop so efficiency is important. QString cell_range = xl_rowcol_to_cell_fast(row, col); - writer.writeStartElement("c"); - writer.writeAttribute("r", cell_range); + writer.writeStartElement(QStringLiteral("c")); + writer.writeAttribute(QStringLiteral("r"), cell_range); //Style used by the cell, row or col if (cell->format) - writer.writeAttribute("s", QString::number(cell->format->xfIndex())); + writer.writeAttribute(QStringLiteral("s"), QString::number(cell->format->xfIndex())); else if (rowsInfo.contains(row) && rowsInfo[row]->format) - writer.writeAttribute("s", QString::number(rowsInfo[row]->format->xfIndex())); + writer.writeAttribute(QStringLiteral("s"), QString::number(rowsInfo[row]->format->xfIndex())); else if (colsInfoHelper.contains(col) && colsInfoHelper[col]->format) - writer.writeAttribute("s", QString::number(colsInfoHelper[col]->format->xfIndex())); + writer.writeAttribute(QStringLiteral("s"), QString::number(colsInfoHelper[col]->format->xfIndex())); if (cell->dataType == XlsxCellData::String) { //cell->data: Index of the string in sharedStringTable - writer.writeAttribute("t", "s"); - writer.writeTextElement("v", cell->value.toString()); + writer.writeAttribute(QStringLiteral("t"), QStringLiteral("s")); + writer.writeTextElement(QStringLiteral("v"), cell->value.toString()); } else if (cell->dataType == XlsxCellData::Number){ double value = cell->value.toDouble(); - writer.writeTextElement("v", QString::number(value, 'g', 15)); + writer.writeTextElement(QStringLiteral("v"), QString::number(value, 'g', 15)); } else if (cell->dataType == XlsxCellData::Formula) { bool ok = true; cell->formula.toDouble(&ok); if (!ok) //is string - writer.writeAttribute("t", "str"); - writer.writeTextElement("f", cell->formula); - writer.writeTextElement("v", cell->value.toString()); + writer.writeAttribute(QStringLiteral("t"), QStringLiteral("str")); + writer.writeTextElement(QStringLiteral("f"), cell->formula); + writer.writeTextElement(QStringLiteral("v"), cell->value.toString()); } else if (cell->dataType == XlsxCellData::ArrayFormula) { } else if (cell->dataType == XlsxCellData::Boolean) { - writer.writeAttribute("t", "b"); - writer.writeTextElement("v", cell->value.toBool() ? "1" : "0"); + writer.writeAttribute(QStringLiteral("t"), QStringLiteral("b")); + writer.writeTextElement(QStringLiteral("v"), cell->value.toBool() ? QStringLiteral("1") : QStringLiteral("0")); } else if (cell->dataType == XlsxCellData::Blank) { //Ok, empty here. } else if (cell->dataType == XlsxCellData::DateTime) { @@ -576,7 +576,7 @@ void WorksheetPrivate::writeCellData(XmlStreamWriter &writer, int row, int col, //Account for Excel erroneously treating 1900 as a leap year. if (!workbook->isDate1904() && excel_time > 59) excel_time += 1; - writer.writeTextElement("v", QString::number(excel_time, 'g', 15)); + writer.writeTextElement(QStringLiteral("v"), QString::number(excel_time, 'g', 15)); } writer.writeEndElement(); //c }