Add basic graphicFrame support
First step for chart support
This commit is contained in:
+4
-2
@@ -38,7 +38,8 @@ HEADERS += $$PWD/xlsxdocpropscore_p.h \
|
||||
$$PWD/xlsxdrawinganchor_p.h \
|
||||
$$PWD/xlsxmediafile_p.h \
|
||||
$$PWD/xlsxooxmlfile.h \
|
||||
$$PWD/xlsxooxmlfile_p.h
|
||||
$$PWD/xlsxooxmlfile_p.h \
|
||||
$$PWD/xlsxchartfile_p.h
|
||||
|
||||
SOURCES += $$PWD/xlsxdocpropscore.cpp \
|
||||
$$PWD/xlsxdocpropsapp.cpp \
|
||||
@@ -64,4 +65,5 @@ SOURCES += $$PWD/xlsxdocpropscore.cpp \
|
||||
$$PWD/xlsxnumformatparser.cpp \
|
||||
$$PWD/xlsxdrawinganchor.cpp \
|
||||
$$PWD/xlsxmediafile.cpp \
|
||||
$$PWD/xlsxooxmlfile.cpp
|
||||
$$PWD/xlsxooxmlfile.cpp \
|
||||
$$PWD/xlsxchartfile.cpp
|
||||
|
||||
@@ -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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "xlsxchartfile_p.h"
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
namespace QXlsx {
|
||||
|
||||
ChartFile::ChartFile()
|
||||
{
|
||||
}
|
||||
|
||||
void ChartFile::saveToXmlFile(QIODevice *device) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ChartFile::loadFromXmlFile(QIODevice *device)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace QXlsx
|
||||
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
** 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_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.
|
||||
//
|
||||
|
||||
#include "xlsxooxmlfile.h"
|
||||
|
||||
namespace QXlsx {
|
||||
|
||||
class ChartFile : public OOXmlFile
|
||||
{
|
||||
public:
|
||||
ChartFile();
|
||||
|
||||
void saveToXmlFile(QIODevice *device) const;
|
||||
bool loadFromXmlFile(QIODevice *device);
|
||||
};
|
||||
|
||||
} // namespace QXlsx
|
||||
|
||||
#endif // QXLSX_CHARTFILE_P_H
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "xlsxworkbook_p.h"
|
||||
#include "xlsxdrawing_p.h"
|
||||
#include "xlsxmediafile_p.h"
|
||||
#include "xlsxchartfile_p.h"
|
||||
#include "xlsxzipreader_p.h"
|
||||
#include "xlsxzipwriter_p.h"
|
||||
|
||||
@@ -208,6 +209,13 @@ bool DocumentPrivate::loadPackage(QIODevice *device)
|
||||
}
|
||||
}
|
||||
|
||||
//load charts
|
||||
QList<QSharedPointer<ChartFile> > chartFileToLoad = workbook->chartFiles();
|
||||
for (int i=0; i<chartFileToLoad.size(); ++i) {
|
||||
QSharedPointer<ChartFile> cf = chartFileToLoad[i];
|
||||
cf->loadFromXmlData(zipReader.fileData(cf->filePath()));
|
||||
}
|
||||
|
||||
//load media files
|
||||
QList<QSharedPointer<MediaFile> > mediaFileToLoad = workbook->mediaFiles();
|
||||
for (int i=0; i<mediaFileToLoad.size(); ++i) {
|
||||
@@ -285,6 +293,12 @@ bool DocumentPrivate::savePackage(QIODevice *device) const
|
||||
contentTypes.addTheme();
|
||||
zipWriter.addFile(QStringLiteral("xl/theme/theme1.xml"), workbook->theme()->saveToXmlData());
|
||||
|
||||
// save chart xml files
|
||||
for (int i=0; i<workbook->chartFiles().size(); ++i) {
|
||||
QSharedPointer<ChartFile> cf = workbook->chartFiles()[i];
|
||||
zipWriter.addFile(QStringLiteral("xl/charts/chart%1.xml").arg(i+1), cf->saveToXmlData());
|
||||
}
|
||||
|
||||
// save image files
|
||||
for (int i=0; i<workbook->mediaFiles().size(); ++i) {
|
||||
QSharedPointer<MediaFile> mf = workbook->mediaFiles()[i];
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "xlsxdrawinganchor_p.h"
|
||||
#include "xlsxdrawing_p.h"
|
||||
#include "xlsxmediafile_p.h"
|
||||
#include "xlsxchartfile_p.h"
|
||||
#include "xlsxworkbook.h"
|
||||
#include "xlsxutility_p.h"
|
||||
|
||||
@@ -172,7 +173,38 @@ void DrawingAnchor::loadXmlObjectConnectionShape(QXmlStreamReader &reader)
|
||||
|
||||
void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader)
|
||||
{
|
||||
Q_UNUSED(reader)
|
||||
Q_ASSERT(reader.name() == QLatin1String("graphicFrame"));
|
||||
|
||||
while (!reader.atEnd()) {
|
||||
reader.readNextStartElement();
|
||||
if (reader.tokenType() == QXmlStreamReader::StartElement) {
|
||||
if (reader.name() == QLatin1String("chart")) {
|
||||
QString rId = reader.attributes().value(QLatin1String("r:id")).toString();
|
||||
QString name = m_drawing->relationships.getRelationshipById(rId).target;
|
||||
QString path = QDir::cleanPath(splitPath(m_drawing->pathInPackage)[0] + QLatin1String("/") + name);
|
||||
|
||||
bool exist = false;
|
||||
QList<QSharedPointer<ChartFile> > cfs = m_drawing->workbook->chartFiles();
|
||||
for (int i=0; i<cfs.size(); ++i) {
|
||||
if (cfs[i]->filePath() == path) {
|
||||
//already exist
|
||||
exist = true;
|
||||
m_chartFile = cfs[i];
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
m_chartFile = QSharedPointer<ChartFile> (new ChartFile);
|
||||
m_chartFile->setFilePath(path);
|
||||
m_drawing->workbook->addChartFile(m_chartFile);
|
||||
}
|
||||
}
|
||||
} else if (reader.tokenType() == QXmlStreamReader::EndElement
|
||||
&& reader.name() == QLatin1String("graphicFrame")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void DrawingAnchor::loadXmlObjectGroupShape(QXmlStreamReader &reader)
|
||||
@@ -266,7 +298,32 @@ void DrawingAnchor::saveXmlObjectConnectionShape(QXmlStreamWriter &writer) const
|
||||
|
||||
void DrawingAnchor::saveXmlObjectGraphicFrame(QXmlStreamWriter &writer) const
|
||||
{
|
||||
Q_UNUSED(writer)
|
||||
writer.writeStartElement(QStringLiteral("xdr:graphicFrame"));
|
||||
writer.writeAttribute(QStringLiteral("macro"), QString());
|
||||
|
||||
writer.writeStartElement(QStringLiteral("xdr:nvGraphicFramePr"));
|
||||
writer.writeEmptyElement(QStringLiteral("xdr:cNvPr"));
|
||||
writer.writeAttribute(QStringLiteral("id"), QString::number(m_id));
|
||||
writer.writeAttribute(QStringLiteral("name"),QStringLiteral("Chart %1").arg(m_id));
|
||||
writer.writeEmptyElement(QStringLiteral("xdr:cNvGraphicFramePr"));
|
||||
writer.writeEndElement();//xdr:nvGraphicFramePr
|
||||
|
||||
writer.writeStartElement(QStringLiteral("xdr:xfrm"));
|
||||
writer.writeEndElement(); //xdr:xfrm
|
||||
|
||||
writer.writeStartElement(QStringLiteral("a:graphic"));
|
||||
writer.writeStartElement(QStringLiteral("a:graphicData"));
|
||||
writer.writeAttribute(QStringLiteral("uri"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart"));
|
||||
|
||||
int idx = m_drawing->workbook->chartFiles().indexOf(m_chartFile);
|
||||
m_drawing->relationships.addDocumentRelationship(QStringLiteral("/chart"), QStringLiteral("../charts/chart%1.xml").arg(idx));
|
||||
|
||||
writer.writeEmptyElement(QStringLiteral("c:chart"));
|
||||
writer.writeAttribute(QStringLiteral("xmlns:c"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/chart"));
|
||||
writer.writeAttribute(QStringLiteral("xmlns:r"), QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"));
|
||||
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(m_drawing->relationships.count()));
|
||||
|
||||
writer.writeEndElement(); //xdr:graphicFrame
|
||||
}
|
||||
|
||||
void DrawingAnchor::saveXmlObjectGroupShape(QXmlStreamWriter &writer) const
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace QXlsx {
|
||||
|
||||
class Drawing;
|
||||
class MediaFile;
|
||||
class ChartFile;
|
||||
|
||||
//Helper class
|
||||
struct XlsxMarker
|
||||
@@ -103,6 +104,7 @@ protected:
|
||||
Drawing *m_drawing;
|
||||
ObjectType m_objectType;
|
||||
QSharedPointer<MediaFile> m_pictureFile;
|
||||
QSharedPointer<ChartFile> m_chartFile;
|
||||
|
||||
int m_id;
|
||||
};
|
||||
|
||||
@@ -26,6 +26,18 @@
|
||||
#ifndef QXLSX_XLSXMEDIAFILE_H
|
||||
#define QXLSX_XLSXMEDIAFILE_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 "xlsxglobal.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
@@ -80,4 +80,22 @@ bool OOXmlFile::loadFromXmlData(const QByteArray &data)
|
||||
return loadFromXmlFile(&buffer);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
void OOXmlFile::setFilePath(const QString path)
|
||||
{
|
||||
Q_D(OOXmlFile);
|
||||
d->filePathInPackage = path;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QString OOXmlFile::filePath() const
|
||||
{
|
||||
Q_D(const OOXmlFile);
|
||||
return d->filePathInPackage;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE_XLSX
|
||||
|
||||
@@ -37,6 +37,7 @@ class OOXmlFilePrivate;
|
||||
|
||||
class Q_XLSX_EXPORT OOXmlFile
|
||||
{
|
||||
Q_DECLARE_PRIVATE(OOXmlFile)
|
||||
public:
|
||||
virtual ~OOXmlFile();
|
||||
|
||||
@@ -46,6 +47,8 @@ public:
|
||||
virtual QByteArray saveToXmlData() const;
|
||||
virtual bool loadFromXmlData(const QByteArray &data);
|
||||
|
||||
void setFilePath(const QString path);
|
||||
QString filePath() const;
|
||||
protected:
|
||||
OOXmlFile();
|
||||
OOXmlFile(OOXmlFilePrivate *d);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
//
|
||||
|
||||
#include "xlsxooxmlfile.h"
|
||||
#include <QString>
|
||||
|
||||
QT_BEGIN_NAMESPACE_XLSX
|
||||
|
||||
@@ -48,6 +49,9 @@ class XLSX_AUTOTEST_EXPORT OOXmlFilePrivate
|
||||
public:
|
||||
OOXmlFilePrivate(OOXmlFile *q);
|
||||
|
||||
QString filePathInPackage;//such as "xl/worksheets/sheet1.xml"
|
||||
//used when load the .xlsx file
|
||||
|
||||
OOXmlFile *q_ptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -575,4 +575,25 @@ void Workbook::addMediaFile(QSharedPointer<MediaFile> media, bool force)
|
||||
d->mediaFiles.append(media);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QList<QSharedPointer<ChartFile> > Workbook::chartFiles() const
|
||||
{
|
||||
Q_D(const Workbook);
|
||||
|
||||
return d->chartFiles;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
void Workbook::addChartFile(QSharedPointer<ChartFile> chart)
|
||||
{
|
||||
Q_D(Workbook);
|
||||
|
||||
if (!d->chartFiles.contains(chart))
|
||||
d->chartFiles.append(chart);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE_XLSX
|
||||
|
||||
@@ -44,6 +44,7 @@ class Theme;
|
||||
class Relationships;
|
||||
class DocumentPrivate;
|
||||
class MediaFile;
|
||||
class ChartFile;
|
||||
|
||||
class WorkbookPrivate;
|
||||
class Q_XLSX_EXPORT Workbook : public OOXmlFile
|
||||
@@ -80,6 +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;
|
||||
|
||||
private:
|
||||
friend class Worksheet;
|
||||
|
||||
@@ -88,6 +88,7 @@ public:
|
||||
QSharedPointer<Styles> styles;
|
||||
QSharedPointer<Theme> theme;
|
||||
QList<QSharedPointer<MediaFile> > mediaFiles;
|
||||
QList<QSharedPointer<ChartFile> > chartFiles;
|
||||
QList<XlsxDefineNameData> definedNamesList;
|
||||
|
||||
QList<XlsxSheetItemInfo> sheetItemInfoList;//Data from xml file
|
||||
|
||||
Reference in New Issue
Block a user