17 changed files with 656 additions and 7 deletions
@ -0,0 +1,9 @@ |
|||
TARGET = chart |
|||
|
|||
#include(../../../src/xlsx/qtxlsx.pri) |
|||
QT+=xlsx |
|||
|
|||
CONFIG += console |
|||
CONFIG -= app_bundle |
|||
|
|||
SOURCES += main.cpp |
@ -0,0 +1,31 @@ |
|||
#include <QtCore> |
|||
#include "xlsxdocument.h" |
|||
#include "xlsxpiechart.h" |
|||
#include "xlsxworksheet.h" |
|||
|
|||
using namespace QXlsx; |
|||
|
|||
int main() |
|||
{ |
|||
//![0]
|
|||
Document xlsx; |
|||
|
|||
Worksheet *sheet = xlsx.currentWorksheet(); |
|||
for (int i=1; i<10; ++i) |
|||
sheet->write(i, 1, i*i); |
|||
//![0]
|
|||
|
|||
//![1]
|
|||
PieChart *chart = new PieChart; |
|||
chart->addSeries(CellRange("A1:A9"), sheet->sheetName()); |
|||
sheet->insertChart(3, 3, chart, QSize(300, 300)); |
|||
//![1]
|
|||
|
|||
//![2]
|
|||
xlsx.saveAs("Book1.xlsx"); |
|||
//![2]
|
|||
|
|||
Document xlsx2("Book1.xlsx"); |
|||
xlsx2.saveAs("Book2.xlsx"); |
|||
return 0; |
|||
} |
@ -0,0 +1,86 @@ |
|||
/****************************************************************************
|
|||
** 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" |
|||
|
|||
QT_BEGIN_NAMESPACE_XLSX |
|||
|
|||
AbstractChartPrivate::AbstractChartPrivate(AbstractChart *chart) |
|||
:q_ptr(chart) |
|||
{ |
|||
|
|||
} |
|||
|
|||
AbstractChartPrivate::~AbstractChartPrivate() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/*!
|
|||
* \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)); |
|||
} |
|||
|
|||
QT_END_NAMESPACE_XLSX |
@ -0,0 +1,63 @@ |
|||
/****************************************************************************
|
|||
** 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 loadFromXml(QXmlStreamReader &reader) = 0; |
|||
virtual void saveToXml(QXmlStreamWriter &writer) const = 0; |
|||
|
|||
AbstractChartPrivate * d_ptr; |
|||
}; |
|||
|
|||
QT_END_NAMESPACE_XLSX |
|||
|
|||
#endif // QXLSX_XLSXABSTRACTCHART_H
|
@ -0,0 +1,66 @@ |
|||
/****************************************************************************
|
|||
** 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 XLSXABSTRACTCHART_P_H |
|||
#define XLSXABSTRACTCHART_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 "xlsxabstractchart.h" |
|||
#include <QList> |
|||
#include <QSharedPointer> |
|||
|
|||
QT_BEGIN_NAMESPACE_XLSX |
|||
|
|||
class XlsxSeries |
|||
{ |
|||
public: |
|||
|
|||
QString numRef; |
|||
}; |
|||
|
|||
class AbstractChartPrivate |
|||
{ |
|||
Q_DECLARE_PUBLIC(AbstractChart) |
|||
public: |
|||
AbstractChartPrivate(AbstractChart *chart); |
|||
virtual ~AbstractChartPrivate(); |
|||
|
|||
QList<QSharedPointer<XlsxSeries> > seriesList; |
|||
ChartFile *cf; |
|||
AbstractChart *q_ptr; |
|||
}; |
|||
|
|||
QT_END_NAMESPACE_XLSX |
|||
#endif // XLSXABSTRACTCHART_P_H
|
@ -0,0 +1,115 @@ |
|||
/****************************************************************************
|
|||
** 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::loadFromXml(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; |
|||
} |
|||
|
|||
bool PieChartPrivate::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 PieChart::saveToXml(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 |
@ -0,0 +1,49 @@ |
|||
/****************************************************************************
|
|||
** 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 loadFromXml(QXmlStreamReader &reader); |
|||
void saveToXml(QXmlStreamWriter &writer) const; |
|||
}; |
|||
|
|||
QT_END_NAMESPACE_XLSX |
|||
|
|||
#endif // QXLSX_XLSXPIECHART_H
|
@ -0,0 +1,57 @@ |
|||
/****************************************************************************
|
|||
** 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); |
|||
|
|||
bool loadXmlSer(QXmlStreamReader &reader); |
|||
}; |
|||
|
|||
QT_END_NAMESPACE_XLSX |
|||
|
|||
#endif // XLSXPIECHART_P_H
|
Loading…
Reference in new issue