Code refactoring of Chart part
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include <QtCore>
|
||||
#include "xlsxdocument.h"
|
||||
#include "xlsxpiechart.h"
|
||||
#include "xlsxbarchart.h"
|
||||
#include "xlsxchart.h"
|
||||
#include "xlsxworksheet.h"
|
||||
|
||||
using namespace QXlsx;
|
||||
@@ -17,13 +16,14 @@ int main()
|
||||
//![0]
|
||||
|
||||
//![1]
|
||||
PieChart *pieChart = new PieChart;
|
||||
pieChart->addSeries(CellRange("A1:A9"), sheet->sheetName());
|
||||
sheet->insertChart(3, 3, pieChart, QSize(300, 300));
|
||||
Chart *pieChart = sheet->insertChart(3, 3, QSize(300, 300));
|
||||
pieChart->setChartType(Chart::CT_Pie);
|
||||
pieChart->addSeries(CellRange("A1:A9"));
|
||||
|
||||
Chart *barChart = sheet->insertChart(6, 6, QSize(300, 300));
|
||||
barChart->setChartType(Chart::CT_Bar);
|
||||
barChart->addSeries(CellRange("A1:A9"));
|
||||
|
||||
BarChart *barChart = new BarChart;
|
||||
barChart->addSeries(CellRange("A1:A9"), sheet->sheetName());
|
||||
sheet->insertChart(6, 6, barChart, QSize(300, 300));
|
||||
//![1]
|
||||
|
||||
//![2]
|
||||
|
||||
+3
-11
@@ -39,13 +39,8 @@ HEADERS += $$PWD/xlsxdocpropscore_p.h \
|
||||
$$PWD/xlsxmediafile_p.h \
|
||||
$$PWD/xlsxooxmlfile.h \
|
||||
$$PWD/xlsxooxmlfile_p.h \
|
||||
$$PWD/xlsxchartfile_p.h \
|
||||
$$PWD/xlsxabstractchart.h \
|
||||
$$PWD/xlsxabstractchart_p.h \
|
||||
$$PWD/xlsxpiechart.h \
|
||||
$$PWD/xlsxpiechart_p.h \
|
||||
$$PWD/xlsxbarchart.h \
|
||||
$$PWD/xlsxbarchart_p.h
|
||||
$$PWD/xlsxchart.h \
|
||||
$$PWD/xlsxchart_p.h
|
||||
|
||||
SOURCES += $$PWD/xlsxdocpropscore.cpp \
|
||||
$$PWD/xlsxdocpropsapp.cpp \
|
||||
@@ -72,7 +67,4 @@ SOURCES += $$PWD/xlsxdocpropscore.cpp \
|
||||
$$PWD/xlsxdrawinganchor.cpp \
|
||||
$$PWD/xlsxmediafile.cpp \
|
||||
$$PWD/xlsxooxmlfile.cpp \
|
||||
$$PWD/xlsxchartfile.cpp \
|
||||
$$PWD/xlsxabstractchart.cpp \
|
||||
$$PWD/xlsxpiechart.cpp \
|
||||
$$PWD/xlsxbarchart.cpp
|
||||
$$PWD/xlsxchart.cpp
|
||||
|
||||
@@ -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
|
||||
@@ -23,19 +23,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QXLSX_CHARTFILE_P_H
|
||||
#define QXLSX_CHARTFILE_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.
|
||||
//
|
||||
#ifndef QXLSX_CHART_H
|
||||
#define QXLSX_CHART_H
|
||||
|
||||
#include "xlsxooxmlfile.h"
|
||||
|
||||
@@ -44,35 +33,54 @@
|
||||
class QXmlStreamReader;
|
||||
class QXmlStreamWriter;
|
||||
|
||||
namespace QXlsx {
|
||||
QT_BEGIN_NAMESPACE_XLSX
|
||||
|
||||
class AbstractChart;
|
||||
class Worksheet;
|
||||
class ChartPrivate;
|
||||
class CellRange;
|
||||
class DrawingAnchor;
|
||||
|
||||
class ChartFile : public OOXmlFile
|
||||
class Q_XLSX_EXPORT Chart : public OOXmlFile
|
||||
{
|
||||
public:
|
||||
ChartFile();
|
||||
~ChartFile();
|
||||
Q_DECLARE_PRIVATE(Chart)
|
||||
|
||||
AbstractChart *chart() const;
|
||||
void setChart(AbstractChart *chart);
|
||||
public:
|
||||
enum ChartType {
|
||||
CT_Area,
|
||||
CT_Area3D,
|
||||
CT_Line,
|
||||
CT_Line3D,
|
||||
CT_Stock,
|
||||
CT_Radar,
|
||||
CT_Scatter,
|
||||
CT_Pie,
|
||||
CT_Pie3D,
|
||||
CT_Doughnut,
|
||||
CT_Bar,
|
||||
CT_Bar3D,
|
||||
CT_OfPie,
|
||||
CT_Surface,
|
||||
CT_Surface3D,
|
||||
CT_Bubble
|
||||
};
|
||||
|
||||
~Chart();
|
||||
|
||||
void addSeries(const CellRange &range, Worksheet *sheet=0);
|
||||
void setChartType(ChartType type);
|
||||
void setChartStyle(int id);
|
||||
|
||||
void saveToXmlFile(QIODevice *device) const;
|
||||
bool loadFromXmlFile(QIODevice *device);
|
||||
|
||||
private:
|
||||
bool loadXmlChart(QXmlStreamReader &reader);
|
||||
bool loadXmlPlotArea(QXmlStreamReader &reader);
|
||||
AbstractChart *loadXmlPieChart(QXmlStreamReader &reader);
|
||||
friend class Worksheet;
|
||||
friend class DrawingAnchor;
|
||||
|
||||
bool saveXmlChart(QXmlStreamWriter &writer) const;
|
||||
|
||||
friend class AbstractChart;
|
||||
// Don't use sharedpointer here,
|
||||
// in case some users create AbstractChart in the stack.
|
||||
AbstractChart *m_chart;
|
||||
Chart(Worksheet *parent);
|
||||
};
|
||||
|
||||
} // namespace QXlsx
|
||||
QT_END_NAMESPACE_XLSX
|
||||
|
||||
#endif // QXLSX_CHART_H
|
||||
|
||||
#endif // QXLSX_CHARTFILE_P_H
|
||||
@@ -23,8 +23,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef XLSXABSTRACTCHART_P_H
|
||||
#define XLSXABSTRACTCHART_P_H
|
||||
#ifndef QXLSX_CHART_P_H
|
||||
#define QXLSX_CHART_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
@@ -37,11 +37,15 @@
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "xlsxabstractchart.h"
|
||||
#include <QList>
|
||||
#include "xlsxooxmlfile_p.h"
|
||||
#include "xlsxchart.h"
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
QT_BEGIN_NAMESPACE_XLSX
|
||||
class QXmlStreamReader;
|
||||
class QXmlStreamWriter;
|
||||
|
||||
namespace QXlsx {
|
||||
|
||||
class XlsxSeries
|
||||
{
|
||||
@@ -82,20 +86,33 @@ public:
|
||||
Pos axisPos; //l,r,b,t
|
||||
};
|
||||
|
||||
class AbstractChartPrivate
|
||||
class ChartPrivate : public OOXmlFilePrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(AbstractChart)
|
||||
public:
|
||||
AbstractChartPrivate(AbstractChart *chart);
|
||||
virtual ~AbstractChartPrivate();
|
||||
Q_DECLARE_PUBLIC(Chart)
|
||||
|
||||
public:
|
||||
ChartPrivate(Chart *q);
|
||||
~ChartPrivate();
|
||||
|
||||
bool loadXmlChart(QXmlStreamReader &reader);
|
||||
bool loadXmlPlotArea(QXmlStreamReader &reader);
|
||||
bool loadXmlXxxChart(QXmlStreamReader &reader);
|
||||
bool loadXmlSer(QXmlStreamReader &reader);
|
||||
bool loadXmlAxis(QXmlStreamReader &reader);
|
||||
|
||||
void saveXmlChart(QXmlStreamWriter &writer) const;
|
||||
void saveXmlXxxChart(QXmlStreamWriter &writer) const;
|
||||
void saveXmlSer(QXmlStreamWriter &writer, XlsxSeries *ser, int id) const;
|
||||
void saveXmlAxes(QXmlStreamWriter &writer) const;
|
||||
|
||||
Chart::ChartType chartType;
|
||||
|
||||
QList<QSharedPointer<XlsxSeries> > seriesList;
|
||||
QList<QSharedPointer<XlsxAxis>> axisList;
|
||||
ChartFile *cf;
|
||||
AbstractChart *q_ptr;
|
||||
QList<QSharedPointer<XlsxAxis> > axisList;
|
||||
|
||||
Worksheet *sheet;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE_XLSX
|
||||
#endif // XLSXABSTRACTCHART_P_H
|
||||
} // namespace QXlsx
|
||||
|
||||
#endif // QXLSX_CHART_P_H
|
||||
@@ -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
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "xlsxworkbook_p.h"
|
||||
#include "xlsxdrawing_p.h"
|
||||
#include "xlsxmediafile_p.h"
|
||||
#include "xlsxchartfile_p.h"
|
||||
#include "xlsxchart.h"
|
||||
#include "xlsxzipreader_p.h"
|
||||
#include "xlsxzipwriter_p.h"
|
||||
|
||||
@@ -199,9 +199,9 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
|
||||
}
|
||||
|
||||
//load charts
|
||||
QList<QSharedPointer<ChartFile> > chartFileToLoad = workbook->chartFiles();
|
||||
QList<QSharedPointer<Chart> > chartFileToLoad = workbook->chartFiles();
|
||||
for (int i=0; i<chartFileToLoad.size(); ++i) {
|
||||
QSharedPointer<ChartFile> cf = chartFileToLoad[i];
|
||||
QSharedPointer<Chart> cf = chartFileToLoad[i];
|
||||
cf->loadFromXmlData(zipReader.fileData(cf->filePath()));
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ bool DocumentPrivate::savePackage(QIODevice *device) const
|
||||
// save chart xml files
|
||||
for (int i=0; i<workbook->chartFiles().size(); ++i) {
|
||||
contentTypes.addChartName(QStringLiteral("chart%1").arg(i+1));
|
||||
QSharedPointer<ChartFile> cf = workbook->chartFiles()[i];
|
||||
QSharedPointer<Chart> cf = workbook->chartFiles()[i];
|
||||
zipWriter.addFile(QStringLiteral("xl/charts/chart%1.xml").arg(i+1), cf->saveToXmlData());
|
||||
}
|
||||
|
||||
@@ -403,6 +403,11 @@ bool Document::insertImage(int row, int column, const QImage &image)
|
||||
return currentWorksheet()->insertImage(row, column, image);
|
||||
}
|
||||
|
||||
Chart *Document::insertChart(int row, int col, const QSize &size)
|
||||
{
|
||||
return currentWorksheet()->insertChart(row, col, size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Insert an \a image to current active worksheet to the position \a row, \a column with the given
|
||||
* \a xOffset, \a yOffset, \a xScale and \a yScale.
|
||||
|
||||
@@ -41,6 +41,7 @@ class Cell;
|
||||
class CellRange;
|
||||
class DataValidation;
|
||||
class ConditionalFormatting;
|
||||
class Chart;
|
||||
|
||||
class DocumentPrivate;
|
||||
class Q_XLSX_EXPORT Document : public QObject
|
||||
@@ -60,6 +61,7 @@ public:
|
||||
QVariant read(int row, int col) const;
|
||||
bool insertImage(int row, int col, const QImage &image);
|
||||
Q_DECL_DEPRECATED int insertImage(int row, int column, const QImage &image, double xOffset, double yOffset, double xScale=1, double yScale=1);
|
||||
Chart *insertChart(int row, int col, const QSize &size);
|
||||
int mergeCells(const CellRange &range, const Format &format=Format());
|
||||
int mergeCells(const QString &range, const Format &format=Format());
|
||||
int unmergeCells(const CellRange &range);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "xlsxdrawing_p.h"
|
||||
#include "xlsxdrawinganchor_p.h"
|
||||
#include "xlsxworksheet.h"
|
||||
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QXmlStreamReader>
|
||||
@@ -32,10 +33,10 @@
|
||||
|
||||
namespace QXlsx {
|
||||
|
||||
Drawing::Drawing(Workbook *workbook)
|
||||
:workbook(workbook)
|
||||
Drawing::Drawing(Worksheet *worksheet)
|
||||
:worksheet(worksheet)
|
||||
{
|
||||
|
||||
workbook = worksheet->workbook();
|
||||
}
|
||||
|
||||
Drawing::~Drawing()
|
||||
|
||||
@@ -51,16 +51,18 @@ namespace QXlsx {
|
||||
|
||||
class DrawingAnchor;
|
||||
class Workbook;
|
||||
class Worksheet;
|
||||
class MediaFile;
|
||||
|
||||
class Drawing : public OOXmlFile
|
||||
{
|
||||
public:
|
||||
Drawing(Workbook *workbook);
|
||||
Drawing(Worksheet *workbook);
|
||||
~Drawing();
|
||||
void saveToXmlFile(QIODevice *device) const;
|
||||
bool loadFromXmlFile(QIODevice *device);
|
||||
|
||||
Worksheet *worksheet;
|
||||
Workbook *workbook;
|
||||
QList<DrawingAnchor *> anchors;
|
||||
mutable Relationships relationships;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "xlsxdrawinganchor_p.h"
|
||||
#include "xlsxdrawing_p.h"
|
||||
#include "xlsxmediafile_p.h"
|
||||
#include "xlsxchartfile_p.h"
|
||||
#include "xlsxchart.h"
|
||||
#include "xlsxworkbook.h"
|
||||
#include "xlsxutility_p.h"
|
||||
|
||||
@@ -95,7 +95,7 @@ void DrawingAnchor::setObjectPicture(const QImage &img)
|
||||
m_objectType = Picture;
|
||||
}
|
||||
|
||||
void DrawingAnchor::setObjectGraphicFrame(QSharedPointer<ChartFile> chart)
|
||||
void DrawingAnchor::setObjectGraphicFrame(QSharedPointer<Chart> chart)
|
||||
{
|
||||
m_chartFile = chart;
|
||||
m_drawing->workbook->addChartFile(chart);
|
||||
@@ -194,7 +194,7 @@ void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader)
|
||||
QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name);
|
||||
|
||||
bool exist = false;
|
||||
QList<QSharedPointer<ChartFile> > cfs = m_drawing->workbook->chartFiles();
|
||||
QList<QSharedPointer<Chart> > cfs = m_drawing->workbook->chartFiles();
|
||||
for (int i=0; i<cfs.size(); ++i) {
|
||||
if (cfs[i]->filePath() == path) {
|
||||
//already exist
|
||||
@@ -203,7 +203,7 @@ void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader)
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
m_chartFile = QSharedPointer<ChartFile> (new ChartFile);
|
||||
m_chartFile = QSharedPointer<Chart> (new Chart(m_drawing->worksheet));
|
||||
m_chartFile->setFilePath(path);
|
||||
m_drawing->workbook->addChartFile(m_chartFile);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace QXlsx {
|
||||
|
||||
class Drawing;
|
||||
class MediaFile;
|
||||
class ChartFile;
|
||||
class Chart;
|
||||
|
||||
//Helper class
|
||||
struct XlsxMarker
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
DrawingAnchor(Drawing *drawing, ObjectType objectType);
|
||||
virtual ~DrawingAnchor();
|
||||
void setObjectPicture(const QImage &img);
|
||||
void setObjectGraphicFrame(QSharedPointer<ChartFile> chart);
|
||||
void setObjectGraphicFrame(QSharedPointer<Chart> chart);
|
||||
|
||||
virtual bool loadFromXml(QXmlStreamReader &reader) = 0;
|
||||
virtual void saveToXml(QXmlStreamWriter &writer) const = 0;
|
||||
@@ -105,7 +105,7 @@ protected:
|
||||
Drawing *m_drawing;
|
||||
ObjectType m_objectType;
|
||||
QSharedPointer<MediaFile> m_pictureFile;
|
||||
QSharedPointer<ChartFile> m_chartFile;
|
||||
QSharedPointer<Chart> m_chartFile;
|
||||
|
||||
int m_id;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
@@ -583,7 +583,7 @@ void Workbook::addMediaFile(QSharedPointer<MediaFile> media, bool force)
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QList<QSharedPointer<ChartFile> > Workbook::chartFiles() const
|
||||
QList<QSharedPointer<Chart> > Workbook::chartFiles() const
|
||||
{
|
||||
Q_D(const Workbook);
|
||||
|
||||
@@ -593,7 +593,7 @@ QList<QSharedPointer<ChartFile> > Workbook::chartFiles() const
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
void Workbook::addChartFile(QSharedPointer<ChartFile> chart)
|
||||
void Workbook::addChartFile(QSharedPointer<Chart> chart)
|
||||
{
|
||||
Q_D(Workbook);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class Theme;
|
||||
class Relationships;
|
||||
class DocumentPrivate;
|
||||
class MediaFile;
|
||||
class ChartFile;
|
||||
class Chart;
|
||||
|
||||
class WorkbookPrivate;
|
||||
class Q_XLSX_EXPORT Workbook : public OOXmlFile
|
||||
@@ -81,8 +81,8 @@ public:
|
||||
//internal used member
|
||||
void addMediaFile(QSharedPointer<MediaFile> media, bool force=false);
|
||||
QList<QSharedPointer<MediaFile> > mediaFiles() const;
|
||||
void addChartFile(QSharedPointer<ChartFile> chartFile);
|
||||
QList<QSharedPointer<ChartFile> > chartFiles() const;
|
||||
void addChartFile(QSharedPointer<Chart> chartFile);
|
||||
QList<QSharedPointer<Chart> > chartFiles() const;
|
||||
|
||||
private:
|
||||
friend class Worksheet;
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
QSharedPointer<Styles> styles;
|
||||
QSharedPointer<Theme> theme;
|
||||
QList<QSharedPointer<MediaFile> > mediaFiles;
|
||||
QList<QSharedPointer<ChartFile> > chartFiles;
|
||||
QList<QSharedPointer<Chart> > chartFiles;
|
||||
QList<XlsxDefineNameData> definedNamesList;
|
||||
|
||||
QList<XlsxSheetItemInfo> sheetItemInfoList;//Data from xml file
|
||||
|
||||
@@ -37,8 +37,7 @@
|
||||
#include "xlsxcellrange.h"
|
||||
#include "xlsxconditionalformatting_p.h"
|
||||
#include "xlsxdrawinganchor_p.h"
|
||||
#include "xlsxabstractchart.h"
|
||||
#include "xlsxchartfile_p.h"
|
||||
#include "xlsxchart.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QDateTime>
|
||||
@@ -1025,7 +1024,7 @@ bool Worksheet::insertImage(int row, int column, const QImage &image)
|
||||
return false;
|
||||
|
||||
if (!d->drawing)
|
||||
d->drawing = QSharedPointer<Drawing>(new Drawing(d->workbook));
|
||||
d->drawing = QSharedPointer<Drawing>(new Drawing(this));
|
||||
|
||||
DrawingOneCellAnchor *anchor = new DrawingOneCellAnchor(d->drawing.data(), DrawingAnchor::Picture);
|
||||
|
||||
@@ -1046,16 +1045,12 @@ int Worksheet::insertImage(int row, int column, const QImage &image, const QPoin
|
||||
return insertImage(row, column, image);
|
||||
}
|
||||
|
||||
bool Worksheet::insertChart(int row, int column, AbstractChart *chart, const QSize &size)
|
||||
Chart *Worksheet::insertChart(int row, int column, const QSize &size)
|
||||
{
|
||||
Q_D(Worksheet);
|
||||
for (int i=0; i< d->workbook->chartFiles().size(); ++i) {
|
||||
if (d->workbook->chartFiles()[i]->chart() == chart)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!d->drawing)
|
||||
d->drawing = QSharedPointer<Drawing>(new Drawing(d->workbook));
|
||||
d->drawing = QSharedPointer<Drawing>(new Drawing(this));
|
||||
|
||||
DrawingOneCellAnchor *anchor = new DrawingOneCellAnchor(d->drawing.data(), DrawingAnchor::Picture);
|
||||
|
||||
@@ -1067,10 +1062,10 @@ bool Worksheet::insertChart(int row, int column, AbstractChart *chart, const QSi
|
||||
anchor->from = XlsxMarker(row, column, 0, 0);
|
||||
anchor->ext = size * 9525;
|
||||
|
||||
QSharedPointer<ChartFile> chartFile = QSharedPointer<ChartFile>(new ChartFile);
|
||||
chartFile->setChart(chart);
|
||||
anchor->setObjectGraphicFrame(chartFile);
|
||||
return true;
|
||||
QSharedPointer<Chart> chart = QSharedPointer<Chart>(new Chart(this));
|
||||
anchor->setObjectGraphicFrame(chart);
|
||||
|
||||
return chart.data();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -2117,7 +2112,7 @@ bool Worksheet::loadFromXmlFile(QIODevice *device)
|
||||
QString rId = reader.attributes().value(QStringLiteral("r:id")).toString();
|
||||
QString name = d->relationships.getRelationshipById(rId).target;
|
||||
QString path = QDir::cleanPath(splitPath(filePath())[0] + QLatin1String("/") + name);
|
||||
d->drawing = QSharedPointer<Drawing>(new Drawing(d->workbook));
|
||||
d->drawing = QSharedPointer<Drawing>(new Drawing(this));
|
||||
d->drawing->setFilePath(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class ConditionalFormatting;
|
||||
class CellRange;
|
||||
class RichString;
|
||||
class Relationships;
|
||||
class AbstractChart;
|
||||
class Chart;
|
||||
|
||||
class WorksheetPrivate;
|
||||
class Q_XLSX_EXPORT Worksheet : public OOXmlFile
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
|
||||
bool insertImage(int row, int column, const QImage &image);
|
||||
Q_DECL_DEPRECATED int insertImage(int row, int column, const QImage &image, const QPointF &offset, double xScale=1, double yScale=1);
|
||||
bool insertChart(int row, int column, AbstractChart *chart, const QSize &size);
|
||||
Chart *insertChart(int row, int column, const QSize &size);
|
||||
|
||||
int mergeCells(const QString &range, const Format &format=Format());
|
||||
int mergeCells(const CellRange &range, const Format &format=Format());
|
||||
|
||||
Reference in New Issue
Block a user