22 changed files with 497 additions and 752 deletions
@ -1,223 +0,0 @@ |
|||
/****************************************************************************
|
|||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
|||
** All right reserved. |
|||
** |
|||
** Permission is hereby granted, free of charge, to any person obtaining |
|||
** a copy of this software and associated documentation files (the |
|||
** "Software"), to deal in the Software without restriction, including |
|||
** without limitation the rights to use, copy, modify, merge, publish, |
|||
** distribute, sublicense, and/or sell copies of the Software, and to |
|||
** permit persons to whom the Software is furnished to do so, subject to |
|||
** the following conditions: |
|||
** |
|||
** The above copyright notice and this permission notice shall be |
|||
** included in all copies or substantial portions of the Software. |
|||
** |
|||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|||
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|||
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|||
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#include "xlsxabstractchart.h" |
|||
#include "xlsxabstractchart_p.h" |
|||
#include "xlsxchartfile_p.h" |
|||
#include "xlsxcellrange.h" |
|||
#include "xlsxutility_p.h" |
|||
#include <QXmlStreamReader> |
|||
#include <QXmlStreamWriter> |
|||
|
|||
QT_BEGIN_NAMESPACE_XLSX |
|||
|
|||
AbstractChartPrivate::AbstractChartPrivate(AbstractChart *chart) |
|||
:q_ptr(chart) |
|||
{ |
|||
|
|||
} |
|||
|
|||
AbstractChartPrivate::~AbstractChartPrivate() |
|||
{ |
|||
|
|||
} |
|||
|
|||
bool AbstractChartPrivate::loadXmlSer(QXmlStreamReader &reader) |
|||
{ |
|||
Q_ASSERT(reader.name() == QLatin1String("ser")); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("f")) { |
|||
XlsxSeries *series = new XlsxSeries; |
|||
series->numRef = reader.readElementText(); |
|||
seriesList.append(QSharedPointer<XlsxSeries>(series)); |
|||
} |
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement |
|||
&& reader.name() == QLatin1String("ser")) { |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
/*!
|
|||
* \class AbstractChart |
|||
* |
|||
* Base class for all the charts. |
|||
*/ |
|||
|
|||
|
|||
AbstractChart::AbstractChart() |
|||
:d_ptr(new AbstractChartPrivate(this)) |
|||
{ |
|||
} |
|||
|
|||
AbstractChart::AbstractChart(AbstractChartPrivate *d) |
|||
:d_ptr(d) |
|||
{ |
|||
|
|||
} |
|||
|
|||
AbstractChart::~AbstractChart() |
|||
{ |
|||
Q_D(AbstractChart); |
|||
if (d->cf) |
|||
d->cf->m_chart = 0; |
|||
} |
|||
|
|||
void AbstractChart::addSeries(const CellRange &range, const QString &sheet) |
|||
{ |
|||
Q_D(AbstractChart); |
|||
|
|||
QString serRef = sheet; |
|||
serRef += QLatin1String("!"); |
|||
serRef += xl_rowcol_to_cell(range.firstRow(), range.firstColumn(), true, true); |
|||
serRef += QLatin1String(":"); |
|||
serRef += xl_rowcol_to_cell(range.lastRow(), range.lastColumn(), true, true); |
|||
|
|||
XlsxSeries *series = new XlsxSeries; |
|||
series->numRef = serRef; |
|||
|
|||
d->seriesList.append(QSharedPointer<XlsxSeries>(series)); |
|||
} |
|||
|
|||
bool AbstractChart::loadAxisFromXml(QXmlStreamReader &reader) |
|||
{ |
|||
Q_D(AbstractChart); |
|||
Q_ASSERT(reader.name().endsWith(QLatin1String("Ax"))); |
|||
QString name = reader.name().toString(); |
|||
|
|||
XlsxAxis *axis = new XlsxAxis; |
|||
if (name == QLatin1String("valAx")) |
|||
axis->type = XlsxAxis::T_Val; |
|||
else if (name == QLatin1String("catAx")) |
|||
axis->type = XlsxAxis::T_Cat; |
|||
else if (name == QLatin1String("serAx")) |
|||
axis->type = XlsxAxis::T_Ser; |
|||
else |
|||
axis->type = XlsxAxis::T_Date; |
|||
|
|||
d->axisList.append(QSharedPointer<XlsxAxis>(axis)); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("axPos")) { |
|||
QXmlStreamAttributes attrs = reader.attributes(); |
|||
QStringRef pos = attrs.value(QLatin1String("val")); |
|||
if (pos==QLatin1String("l")) |
|||
axis->axisPos = XlsxAxis::Left; |
|||
else if (pos==QLatin1String("r")) |
|||
axis->axisPos = XlsxAxis::Right; |
|||
else if (pos==QLatin1String("b")) |
|||
axis->axisPos = XlsxAxis::Bottom; |
|||
else |
|||
axis->axisPos = XlsxAxis::Top; |
|||
} |
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement |
|||
&& reader.name() == name) { |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
void AbstractChart::saveAxisToXml(QXmlStreamWriter &writer) const |
|||
{ |
|||
Q_D(const AbstractChart); |
|||
|
|||
for (int i=0; i<d->axisList.size(); ++i) { |
|||
XlsxAxis *axis = d->axisList[i].data(); |
|||
QString name; |
|||
switch (axis->type) { |
|||
case XlsxAxis::T_Cat: |
|||
name = QStringLiteral("c:catAx"); |
|||
break; |
|||
case XlsxAxis::T_Val: |
|||
name = QStringLiteral("c:valAx"); |
|||
break; |
|||
case XlsxAxis::T_Ser: |
|||
name = QStringLiteral("c:serAx"); |
|||
break; |
|||
case XlsxAxis::T_Date: |
|||
name = QStringLiteral("c:dateAx"); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
QString pos; |
|||
switch (axis->axisPos) { |
|||
case XlsxAxis::Top: |
|||
pos = QStringLiteral("t"); |
|||
break; |
|||
case XlsxAxis::Bottom: |
|||
pos = QStringLiteral("b"); |
|||
break; |
|||
case XlsxAxis::Left: |
|||
pos = QStringLiteral("l"); |
|||
break; |
|||
case XlsxAxis::Right: |
|||
pos = QStringLiteral("r"); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
writer.writeStartElement(name); |
|||
writer.writeEmptyElement(QStringLiteral("c:axId")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(i+1)); |
|||
|
|||
writer.writeStartElement(QStringLiteral("c:scaling")); |
|||
writer.writeEmptyElement(QStringLiteral("c:orientation")); |
|||
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("minMax")); |
|||
writer.writeEndElement();//c:scaling
|
|||
|
|||
writer.writeEmptyElement(QStringLiteral("c:axPos")); |
|||
writer.writeAttribute(QStringLiteral("val"), pos); |
|||
|
|||
writer.writeEmptyElement(QStringLiteral("c:crossAx")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(i%2==0 ? i+2 : i)); |
|||
|
|||
writer.writeEndElement();//name
|
|||
} |
|||
} |
|||
|
|||
bool AbstractChart::loadLegendFromXml(QXmlStreamReader &reader) |
|||
{ |
|||
|
|||
return false; |
|||
} |
|||
|
|||
void AbstractChart::saveLegendToXml(QXmlStreamWriter &writer) const |
|||
{ |
|||
|
|||
} |
|||
|
|||
QT_END_NAMESPACE_XLSX |
@ -1,69 +0,0 @@ |
|||
/****************************************************************************
|
|||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
|||
** All right reserved. |
|||
** |
|||
** Permission is hereby granted, free of charge, to any person obtaining |
|||
** a copy of this software and associated documentation files (the |
|||
** "Software"), to deal in the Software without restriction, including |
|||
** without limitation the rights to use, copy, modify, merge, publish, |
|||
** distribute, sublicense, and/or sell copies of the Software, and to |
|||
** permit persons to whom the Software is furnished to do so, subject to |
|||
** the following conditions: |
|||
** |
|||
** The above copyright notice and this permission notice shall be |
|||
** included in all copies or substantial portions of the Software. |
|||
** |
|||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|||
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|||
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|||
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#ifndef QXLSX_XLSXABSTRACTCHART_H |
|||
#define QXLSX_XLSXABSTRACTCHART_H |
|||
|
|||
#include "xlsxglobal.h" |
|||
|
|||
#include <QString> |
|||
|
|||
class QXmlStreamReader; |
|||
class QXmlStreamWriter; |
|||
|
|||
QT_BEGIN_NAMESPACE_XLSX |
|||
|
|||
class ChartFile; |
|||
class AbstractChartPrivate; |
|||
class CellRange; |
|||
|
|||
class Q_XLSX_EXPORT AbstractChart |
|||
{ |
|||
Q_DECLARE_PRIVATE(AbstractChart) |
|||
|
|||
public: |
|||
AbstractChart(); |
|||
virtual ~AbstractChart(); |
|||
|
|||
void addSeries(const CellRange &range, const QString &sheet=QString()); |
|||
|
|||
protected: |
|||
friend class ChartFile; |
|||
AbstractChart(AbstractChartPrivate *d); |
|||
virtual bool loadXxxChartFromXml(QXmlStreamReader &reader) = 0; |
|||
virtual void saveXxxChartToXml(QXmlStreamWriter &writer) const = 0; |
|||
|
|||
bool loadAxisFromXml(QXmlStreamReader &reader); |
|||
void saveAxisToXml(QXmlStreamWriter &writer) const; |
|||
|
|||
bool loadLegendFromXml(QXmlStreamReader &reader); |
|||
void saveLegendToXml(QXmlStreamWriter &writer) const; |
|||
|
|||
AbstractChartPrivate * d_ptr; |
|||
}; |
|||
|
|||
QT_END_NAMESPACE_XLSX |
|||
|
|||
#endif // QXLSX_XLSXABSTRACTCHART_H
|
@ -0,0 +1,374 @@ |
|||
/****************************************************************************
|
|||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
|||
** All right reserved. |
|||
** |
|||
** Permission is hereby granted, free of charge, to any person obtaining |
|||
** a copy of this software and associated documentation files (the |
|||
** "Software"), to deal in the Software without restriction, including |
|||
** without limitation the rights to use, copy, modify, merge, publish, |
|||
** distribute, sublicense, and/or sell copies of the Software, and to |
|||
** permit persons to whom the Software is furnished to do so, subject to |
|||
** the following conditions: |
|||
** |
|||
** The above copyright notice and this permission notice shall be |
|||
** included in all copies or substantial portions of the Software. |
|||
** |
|||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|||
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|||
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|||
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#include "xlsxchart_p.h" |
|||
#include "xlsxworksheet.h" |
|||
#include "xlsxcellrange.h" |
|||
#include "xlsxutility_p.h" |
|||
|
|||
#include <QIODevice> |
|||
#include <QXmlStreamReader> |
|||
#include <QXmlStreamWriter> |
|||
|
|||
QT_BEGIN_NAMESPACE_XLSX |
|||
|
|||
ChartPrivate::ChartPrivate(Chart *q) |
|||
:OOXmlFilePrivate(q) |
|||
{ |
|||
|
|||
} |
|||
|
|||
ChartPrivate::~ChartPrivate() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/*!
|
|||
* \class Chart |
|||
* |
|||
* Main class for the charts. |
|||
*/ |
|||
|
|||
Chart::Chart(Worksheet *parent) |
|||
:OOXmlFile(new ChartPrivate(this)) |
|||
{ |
|||
d_func()->sheet = parent; |
|||
} |
|||
|
|||
Chart::~Chart() |
|||
{ |
|||
} |
|||
|
|||
void Chart::addSeries(const CellRange &range, Worksheet *sheet) |
|||
{ |
|||
Q_D(Chart); |
|||
|
|||
QString serRef = sheet ? sheet->sheetName() : d->sheet->sheetName(); |
|||
|
|||
serRef += QLatin1String("!"); |
|||
serRef += xl_rowcol_to_cell(range.firstRow(), range.firstColumn(), true, true); |
|||
serRef += QLatin1String(":"); |
|||
serRef += xl_rowcol_to_cell(range.lastRow(), range.lastColumn(), true, true); |
|||
|
|||
XlsxSeries *series = new XlsxSeries; |
|||
series->numRef = serRef; |
|||
|
|||
d->seriesList.append(QSharedPointer<XlsxSeries>(series)); |
|||
} |
|||
|
|||
/*!
|
|||
* Set the type of the chart to \a type |
|||
*/ |
|||
void Chart::setChartType(ChartType type) |
|||
{ |
|||
Q_D(Chart); |
|||
d->chartType = type; |
|||
} |
|||
|
|||
void Chart::setChartStyle(int id) |
|||
{ |
|||
Q_UNUSED(id) |
|||
//!Todo
|
|||
} |
|||
|
|||
/*!
|
|||
* \internal |
|||
*/ |
|||
void Chart::saveToXmlFile(QIODevice *device) const |
|||
{ |
|||
Q_D(const Chart); |
|||
|
|||
QXmlStreamWriter writer(device); |
|||
|
|||
writer.writeStartDocument(QStringLiteral("1.0"), true); |
|||
writer.writeStartElement(QStringLiteral("c:chartSpace")); |
|||
writer.writeAttribute(QStringLiteral("xmlns:c"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); |
|||
writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main")); |
|||
writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); |
|||
|
|||
d->saveXmlChart(writer); |
|||
|
|||
writer.writeEndElement();//c:chartSpace
|
|||
writer.writeEndDocument(); |
|||
} |
|||
|
|||
/*!
|
|||
* \internal |
|||
*/ |
|||
bool Chart::loadFromXmlFile(QIODevice *device) |
|||
{ |
|||
Q_D(Chart); |
|||
|
|||
QXmlStreamReader reader(device); |
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("chart")) { |
|||
if (!d->loadXmlChart(reader)) |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
bool ChartPrivate::loadXmlChart(QXmlStreamReader &reader) |
|||
{ |
|||
Q_ASSERT(reader.name() == QLatin1String("chart")); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("plotArea")) { |
|||
if (!loadXmlPlotArea(reader)) |
|||
return false; |
|||
} else if (reader.name() == QLatin1String("legend")) { |
|||
//!Todo
|
|||
} |
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement && |
|||
reader.name() == QLatin1String("chart")) { |
|||
break; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
bool ChartPrivate::loadXmlPlotArea(QXmlStreamReader &reader) |
|||
{ |
|||
Q_ASSERT(reader.name() == QLatin1String("plotArea")); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("layout")) { |
|||
//!ToDo
|
|||
} else if (reader.name().endsWith(QLatin1String("Chart"))) { |
|||
//For pieChart, barChart, ...
|
|||
loadXmlXxxChart(reader); |
|||
} else if (reader.name().endsWith(QLatin1String("Ax"))) { |
|||
//For valAx, catAx, serAx, dateAx
|
|||
loadXmlAxis(reader); |
|||
} |
|||
|
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement && |
|||
reader.name() == QLatin1String("plotArea")) { |
|||
break; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
bool ChartPrivate::loadXmlXxxChart(QXmlStreamReader &reader) |
|||
{ |
|||
QStringRef name = reader.name(); |
|||
if (name == QLatin1String("pieChart")) chartType = Chart::CT_Pie; |
|||
else if (name == QLatin1String("barChart")) chartType = Chart::CT_Bar; |
|||
|
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("ser")) { |
|||
loadXmlSer(reader); |
|||
} else if (reader.name() == QLatin1String("axId")) { |
|||
|
|||
} |
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement |
|||
&& reader.name() == name) { |
|||
break; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
bool ChartPrivate::loadXmlSer(QXmlStreamReader &reader) |
|||
{ |
|||
Q_ASSERT(reader.name() == QLatin1String("ser")); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("f")) { |
|||
XlsxSeries *series = new XlsxSeries; |
|||
series->numRef = reader.readElementText(); |
|||
seriesList.append(QSharedPointer<XlsxSeries>(series)); |
|||
} |
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement |
|||
&& reader.name() == QLatin1String("ser")) { |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
void ChartPrivate::saveXmlChart(QXmlStreamWriter &writer) const |
|||
{ |
|||
writer.writeStartElement(QStringLiteral("c:chart")); |
|||
writer.writeStartElement(QStringLiteral("c:plotArea")); |
|||
saveXmlXxxChart(writer); |
|||
saveXmlAxes(writer); |
|||
writer.writeEndElement(); //plotArea
|
|||
|
|||
// saveXmlLegend(writer);
|
|||
|
|||
writer.writeEndElement(); //chart
|
|||
} |
|||
|
|||
void ChartPrivate::saveXmlXxxChart(QXmlStreamWriter &writer) const |
|||
{ |
|||
QString t; |
|||
switch (chartType) { |
|||
case Chart::CT_Pie: t = QStringLiteral("c:pieChart"); break; |
|||
case Chart::CT_Bar: t = QStringLiteral("c:barChart"); break; |
|||
default: break; |
|||
} |
|||
|
|||
writer.writeStartElement(t); //pieChart, barChart, ...
|
|||
|
|||
if (chartType==Chart::CT_Bar || chartType==Chart::CT_Bar3D) { |
|||
writer.writeEmptyElement(QStringLiteral("c:barDir")); |
|||
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("col")); |
|||
} |
|||
|
|||
writer.writeEmptyElement(QStringLiteral("c:varyColors")); |
|||
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("1")); |
|||
for (int i=0; i<seriesList.size(); ++i) |
|||
saveXmlSer(writer, seriesList[i].data(), i); |
|||
|
|||
if (chartType == Chart::CT_Bar) { |
|||
if (axisList.isEmpty()) { |
|||
const_cast<ChartPrivate*>(this)->axisList.append(QSharedPointer<XlsxAxis>(new XlsxAxis(XlsxAxis::T_Cat, XlsxAxis::Left))); |
|||
const_cast<ChartPrivate*>(this)->axisList.append(QSharedPointer<XlsxAxis>(new XlsxAxis(XlsxAxis::T_Val, XlsxAxis::Bottom))); |
|||
} |
|||
|
|||
Q_ASSERT(axisList.size()==2); |
|||
for (int i=0; i<axisList.size(); ++i) { |
|||
writer.writeEmptyElement(QStringLiteral("c:axId")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(i+1)); |
|||
} |
|||
} |
|||
|
|||
writer.writeEndElement(); //pieChart, barChart, ...
|
|||
} |
|||
|
|||
void ChartPrivate::saveXmlSer(QXmlStreamWriter &writer, XlsxSeries *ser, int id) const |
|||
{ |
|||
writer.writeStartElement(QStringLiteral("c:ser")); |
|||
writer.writeEmptyElement(QStringLiteral("c:idx")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(id)); |
|||
writer.writeEmptyElement(QStringLiteral("c:order")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(id)); |
|||
writer.writeStartElement(QStringLiteral("c:val")); |
|||
writer.writeStartElement(QStringLiteral("c:numRef")); |
|||
writer.writeTextElement(QStringLiteral("c:f"), ser->numRef); |
|||
writer.writeEndElement();//c:numRef
|
|||
writer.writeEndElement();//c:val
|
|||
writer.writeEndElement();//c:ser
|
|||
} |
|||
|
|||
bool ChartPrivate::loadXmlAxis(QXmlStreamReader &reader) |
|||
{ |
|||
Q_ASSERT(reader.name().endsWith(QLatin1String("Ax"))); |
|||
QString name = reader.name().toString(); |
|||
|
|||
XlsxAxis *axis = new XlsxAxis; |
|||
if (name == QLatin1String("valAx")) |
|||
axis->type = XlsxAxis::T_Val; |
|||
else if (name == QLatin1String("catAx")) |
|||
axis->type = XlsxAxis::T_Cat; |
|||
else if (name == QLatin1String("serAx")) |
|||
axis->type = XlsxAxis::T_Ser; |
|||
else |
|||
axis->type = XlsxAxis::T_Date; |
|||
|
|||
axisList.append(QSharedPointer<XlsxAxis>(axis)); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("axPos")) { |
|||
QXmlStreamAttributes attrs = reader.attributes(); |
|||
QStringRef pos = attrs.value(QLatin1String("val")); |
|||
if (pos==QLatin1String("l")) |
|||
axis->axisPos = XlsxAxis::Left; |
|||
else if (pos==QLatin1String("r")) |
|||
axis->axisPos = XlsxAxis::Right; |
|||
else if (pos==QLatin1String("b")) |
|||
axis->axisPos = XlsxAxis::Bottom; |
|||
else |
|||
axis->axisPos = XlsxAxis::Top; |
|||
} |
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement |
|||
&& reader.name() == name) { |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
void ChartPrivate::saveXmlAxes(QXmlStreamWriter &writer) const |
|||
{ |
|||
for (int i=0; i<axisList.size(); ++i) { |
|||
XlsxAxis *axis = axisList[i].data(); |
|||
QString name; |
|||
switch (axis->type) { |
|||
case XlsxAxis::T_Cat: name = QStringLiteral("c:catAx"); break; |
|||
case XlsxAxis::T_Val: name = QStringLiteral("c:valAx"); break; |
|||
case XlsxAxis::T_Ser: name = QStringLiteral("c:serAx"); break; |
|||
case XlsxAxis::T_Date: name = QStringLiteral("c:dateAx"); break; |
|||
default: break; |
|||
} |
|||
|
|||
QString pos; |
|||
switch (axis->axisPos) { |
|||
case XlsxAxis::Top: pos = QStringLiteral("t"); break; |
|||
case XlsxAxis::Bottom: pos = QStringLiteral("b"); break; |
|||
case XlsxAxis::Left: pos = QStringLiteral("l"); break; |
|||
case XlsxAxis::Right: pos = QStringLiteral("r"); break; |
|||
default: break; |
|||
} |
|||
|
|||
writer.writeStartElement(name); |
|||
writer.writeEmptyElement(QStringLiteral("c:axId")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(i+1)); |
|||
|
|||
writer.writeStartElement(QStringLiteral("c:scaling")); |
|||
writer.writeEmptyElement(QStringLiteral("c:orientation")); |
|||
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("minMax")); |
|||
writer.writeEndElement();//c:scaling
|
|||
|
|||
writer.writeEmptyElement(QStringLiteral("c:axPos")); |
|||
writer.writeAttribute(QStringLiteral("val"), pos); |
|||
|
|||
writer.writeEmptyElement(QStringLiteral("c:crossAx")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(i%2==0 ? i+2 : i)); |
|||
|
|||
writer.writeEndElement();//name
|
|||
} |
|||
} |
|||
|
|||
QT_END_NAMESPACE_XLSX |
@ -1,161 +0,0 @@ |
|||
/****************************************************************************
|
|||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
|||
** All right reserved. |
|||
** |
|||
** Permission is hereby granted, free of charge, to any person obtaining |
|||
** a copy of this software and associated documentation files (the |
|||
** "Software"), to deal in the Software without restriction, including |
|||
** without limitation the rights to use, copy, modify, merge, publish, |
|||
** distribute, sublicense, and/or sell copies of the Software, and to |
|||
** permit persons to whom the Software is furnished to do so, subject to |
|||
** the following conditions: |
|||
** |
|||
** The above copyright notice and this permission notice shall be |
|||
** included in all copies or substantial portions of the Software. |
|||
** |
|||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|||
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|||
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|||
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#include "xlsxchartfile_p.h" |
|||
#include "xlsxabstractchart.h" |
|||
#include "xlsxabstractchart_p.h" |
|||
#include "xlsxpiechart.h" |
|||
#include "xlsxbarchart.h" |
|||
#include <QIODevice> |
|||
#include <QXmlStreamReader> |
|||
#include <QXmlStreamWriter> |
|||
|
|||
namespace QXlsx { |
|||
|
|||
ChartFile::ChartFile() |
|||
{ |
|||
} |
|||
|
|||
ChartFile::~ChartFile() |
|||
{ |
|||
if (m_chart) |
|||
delete m_chart; |
|||
} |
|||
|
|||
AbstractChart* ChartFile::chart() const |
|||
{ |
|||
return m_chart; |
|||
} |
|||
|
|||
void ChartFile::setChart(AbstractChart *chart) |
|||
{ |
|||
m_chart = chart; |
|||
chart->d_func()->cf = this; |
|||
} |
|||
|
|||
void ChartFile::saveToXmlFile(QIODevice *device) const |
|||
{ |
|||
QXmlStreamWriter writer(device); |
|||
|
|||
writer.writeStartDocument(QStringLiteral("1.0"), true); |
|||
writer.writeStartElement(QStringLiteral("c:chartSpace")); |
|||
writer.writeAttribute(QStringLiteral("xmlns:c"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart")); |
|||
writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main")); |
|||
writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); |
|||
|
|||
saveXmlChart(writer); |
|||
|
|||
writer.writeEndElement();//c:chartSpace
|
|||
writer.writeEndDocument(); |
|||
} |
|||
|
|||
bool ChartFile::loadFromXmlFile(QIODevice *device) |
|||
{ |
|||
QXmlStreamReader reader(device); |
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("chart")) { |
|||
if (!loadXmlChart(reader)) |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
bool ChartFile::loadXmlChart(QXmlStreamReader &reader) |
|||
{ |
|||
Q_ASSERT(reader.name() == QLatin1String("chart")); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("plotArea")) { |
|||
if (!loadXmlPlotArea(reader)) |
|||
return false; |
|||
} else if (reader.name() == QLatin1String("legend")) { |
|||
m_chart->loadLegendFromXml(reader); |
|||
} |
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement && |
|||
reader.name() == QLatin1String("chart")) { |
|||
break; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
bool ChartFile::loadXmlPlotArea(QXmlStreamReader &reader) |
|||
{ |
|||
Q_ASSERT(reader.name() == QLatin1String("plotArea")); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("layout")) { |
|||
//...
|
|||
} else if (reader.name().endsWith(QLatin1String("Chart"))) { |
|||
//!Todo: each plotArea can have more than one xxxChart
|
|||
AbstractChart *chart = 0; |
|||
if (reader.name() == QLatin1String("pieChart")) { |
|||
chart = new PieChart; |
|||
} else if (reader.name() == QLatin1String("barChart")) { |
|||
chart = new BarChart; |
|||
} else { |
|||
//Not support
|
|||
return false; |
|||
} |
|||
if (chart) { |
|||
chart->loadXxxChartFromXml(reader); |
|||
setChart(chart); |
|||
} |
|||
} else if (reader.name().endsWith(QLatin1String("Ax"))) { |
|||
//For valAx, catAx, serAx, dateAx
|
|||
m_chart->loadAxisFromXml(reader); |
|||
} |
|||
|
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement && |
|||
reader.name() == QLatin1String("plotArea")) { |
|||
break; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
bool ChartFile::saveXmlChart(QXmlStreamWriter &writer) const |
|||
{ |
|||
writer.writeStartElement(QStringLiteral("c:chart")); |
|||
writer.writeStartElement(QStringLiteral("c:plotArea")); |
|||
m_chart->saveXxxChartToXml(writer); |
|||
m_chart->saveAxisToXml(writer); |
|||
writer.writeEndElement(); //plotArea
|
|||
|
|||
m_chart->saveLegendToXml(writer); |
|||
|
|||
writer.writeEndElement(); //chart
|
|||
return true; |
|||
} |
|||
|
|||
} // namespace QXlsx
|
@ -1,94 +0,0 @@ |
|||
/****************************************************************************
|
|||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
|||
** All right reserved. |
|||
** |
|||
** Permission is hereby granted, free of charge, to any person obtaining |
|||
** a copy of this software and associated documentation files (the |
|||
** "Software"), to deal in the Software without restriction, including |
|||
** without limitation the rights to use, copy, modify, merge, publish, |
|||
** distribute, sublicense, and/or sell copies of the Software, and to |
|||
** permit persons to whom the Software is furnished to do so, subject to |
|||
** the following conditions: |
|||
** |
|||
** The above copyright notice and this permission notice shall be |
|||
** included in all copies or substantial portions of the Software. |
|||
** |
|||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|||
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|||
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|||
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#include "xlsxpiechart.h" |
|||
#include "xlsxpiechart_p.h" |
|||
|
|||
#include <QXmlStreamReader> |
|||
#include <QXmlStreamWriter> |
|||
|
|||
QT_BEGIN_NAMESPACE_XLSX |
|||
|
|||
PieChartPrivate::PieChartPrivate(PieChart *chart) |
|||
: AbstractChartPrivate(chart) |
|||
{ |
|||
|
|||
} |
|||
|
|||
/*!
|
|||
* \class PieChart |
|||
*/ |
|||
|
|||
PieChart::PieChart() |
|||
: AbstractChart(new PieChartPrivate(this)) |
|||
{ |
|||
} |
|||
|
|||
bool PieChart::loadXxxChartFromXml(QXmlStreamReader &reader) |
|||
{ |
|||
Q_ASSERT(reader.name() == QLatin1String("pieChart")); |
|||
|
|||
Q_D(PieChart); |
|||
|
|||
while (!reader.atEnd()) { |
|||
reader.readNextStartElement(); |
|||
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|||
if (reader.name() == QLatin1String("ser")) { |
|||
d->loadXmlSer(reader); |
|||
} |
|||
} else if (reader.tokenType() == QXmlStreamReader::EndElement |
|||
&& reader.name() == QLatin1String("pieChart")) { |
|||
break; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
void PieChart::saveXxxChartToXml(QXmlStreamWriter &writer) const |
|||
{ |
|||
Q_D(const PieChart); |
|||
|
|||
writer.writeStartElement(QStringLiteral("c:pieChart")); |
|||
writer.writeEmptyElement(QStringLiteral("c:varyColors")); |
|||
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("1")); |
|||
for (int i=0; i<d->seriesList.size(); ++i) { |
|||
XlsxSeries *ser = d->seriesList[i].data(); |
|||
writer.writeStartElement(QStringLiteral("c:ser")); |
|||
writer.writeEmptyElement(QStringLiteral("c:idx")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(i)); |
|||
writer.writeEmptyElement(QStringLiteral("c:order")); |
|||
writer.writeAttribute(QStringLiteral("val"), QString::number(i)); |
|||
writer.writeStartElement(QStringLiteral("c:val")); |
|||
writer.writeStartElement(QStringLiteral("c:numRef")); |
|||
writer.writeTextElement(QStringLiteral("c:f"), ser->numRef); |
|||
writer.writeEndElement();//c:numRef
|
|||
writer.writeEndElement();//c:val
|
|||
writer.writeEndElement();//c:ser
|
|||
} |
|||
|
|||
writer.writeEndElement(); //pieChart
|
|||
} |
|||
|
|||
QT_END_NAMESPACE_XLSX |
@ -1,49 +0,0 @@ |
|||
/****************************************************************************
|
|||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
|||
** All right reserved. |
|||
** |
|||
** Permission is hereby granted, free of charge, to any person obtaining |
|||
** a copy of this software and associated documentation files (the |
|||
** "Software"), to deal in the Software without restriction, including |
|||
** without limitation the rights to use, copy, modify, merge, publish, |
|||
** distribute, sublicense, and/or sell copies of the Software, and to |
|||
** permit persons to whom the Software is furnished to do so, subject to |
|||
** the following conditions: |
|||
** |
|||
** The above copyright notice and this permission notice shall be |
|||
** included in all copies or substantial portions of the Software. |
|||
** |
|||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|||
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|||
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|||
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#ifndef QXLSX_XLSXPIECHART_H |
|||
#define QXLSX_XLSXPIECHART_H |
|||
|
|||
#include "xlsxabstractchart.h" |
|||
|
|||
QT_BEGIN_NAMESPACE_XLSX |
|||
|
|||
class PieChartPrivate; |
|||
|
|||
class Q_XLSX_EXPORT PieChart : public AbstractChart |
|||
{ |
|||
Q_DECLARE_PRIVATE(PieChart) |
|||
|
|||
public: |
|||
PieChart(); |
|||
|
|||
protected: |
|||
bool loadXxxChartFromXml(QXmlStreamReader &reader); |
|||
void saveXxxChartToXml(QXmlStreamWriter &writer) const; |
|||
}; |
|||
|
|||
QT_END_NAMESPACE_XLSX |
|||
|
|||
#endif // QXLSX_XLSXPIECHART_H
|
@ -1,55 +0,0 @@ |
|||
/****************************************************************************
|
|||
** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
|||
** All right reserved. |
|||
** |
|||
** Permission is hereby granted, free of charge, to any person obtaining |
|||
** a copy of this software and associated documentation files (the |
|||
** "Software"), to deal in the Software without restriction, including |
|||
** without limitation the rights to use, copy, modify, merge, publish, |
|||
** distribute, sublicense, and/or sell copies of the Software, and to |
|||
** permit persons to whom the Software is furnished to do so, subject to |
|||
** the following conditions: |
|||
** |
|||
** The above copyright notice and this permission notice shall be |
|||
** included in all copies or substantial portions of the Software. |
|||
** |
|||
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|||
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
|||
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
|||
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|||
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|||
** |
|||
****************************************************************************/ |
|||
|
|||
#ifndef XLSXPIECHART_P_H |
|||
#define XLSXPIECHART_P_H |
|||
|
|||
//
|
|||
// W A R N I N G
|
|||
// -------------
|
|||
//
|
|||
// This file is not part of the Qt Xlsx API. It exists for the convenience
|
|||
// of the Qt Xlsx. This header file may change from
|
|||
// version to version without notice, or even be removed.
|
|||
//
|
|||
// We mean it.
|
|||
//
|
|||
|
|||
#include "xlsxpiechart.h" |
|||
#include "xlsxabstractchart_p.h" |
|||
|
|||
QT_BEGIN_NAMESPACE_XLSX |
|||
|
|||
class PieChartPrivate : public AbstractChartPrivate |
|||
{ |
|||
Q_DECLARE_PUBLIC(PieChart) |
|||
|
|||
public: |
|||
PieChartPrivate(PieChart *chart); |
|||
}; |
|||
|
|||
QT_END_NAMESPACE_XLSX |
|||
|
|||
#endif // XLSXPIECHART_P_H
|
Loading…
Reference in new issue