Try add a new class QXlsx::Document
This commit is contained in:
+5
-2
@@ -24,7 +24,9 @@ HEADERS += $$PWD/xlsxdocpropscore_p.h \
|
|||||||
$$PWD/xlsxglobal.h \
|
$$PWD/xlsxglobal.h \
|
||||||
$$PWD/xlsxdrawing_p.h \
|
$$PWD/xlsxdrawing_p.h \
|
||||||
$$PWD/xlsxxmlreader_p.h \
|
$$PWD/xlsxxmlreader_p.h \
|
||||||
$$PWD/xlsxzipreader_p.h
|
$$PWD/xlsxzipreader_p.h \
|
||||||
|
$$PWD/xlsxdocument.h \
|
||||||
|
$$PWD/xlsxdocument_p.h
|
||||||
|
|
||||||
SOURCES += $$PWD/xlsxdocpropscore.cpp \
|
SOURCES += $$PWD/xlsxdocpropscore.cpp \
|
||||||
$$PWD/xlsxdocpropsapp.cpp \
|
$$PWD/xlsxdocpropsapp.cpp \
|
||||||
@@ -42,4 +44,5 @@ SOURCES += $$PWD/xlsxdocpropscore.cpp \
|
|||||||
$$PWD/xlsxpackage.cpp \
|
$$PWD/xlsxpackage.cpp \
|
||||||
$$PWD/xlsxdrawing.cpp \
|
$$PWD/xlsxdrawing.cpp \
|
||||||
$$PWD/xlsxxmlreader.cpp \
|
$$PWD/xlsxxmlreader.cpp \
|
||||||
$$PWD/xlsxzipreader.cpp
|
$$PWD/xlsxzipreader.cpp \
|
||||||
|
$$PWD/xlsxdocument.cpp
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
#include "xlsxdocument.h"
|
||||||
|
#include "xlsxdocument_p.h"
|
||||||
|
#include "xlsxworkbook.h"
|
||||||
|
#include "xlsxworksheet.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
namespace QXlsx {
|
||||||
|
|
||||||
|
DocumentPrivate::DocumentPrivate(Document *p) :
|
||||||
|
q_ptr(p), defaultPackageName(QStringLiteral("Book1"))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DocumentPrivate::loadPackage(QIODevice *device)
|
||||||
|
{
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\class Document
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
Document::Document(QObject *parent) :
|
||||||
|
QObject(parent), d_ptr(new DocumentPrivate(this))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Document::Document(const QString &name, QObject *parent) :
|
||||||
|
QObject(parent), d_ptr(new DocumentPrivate(this))
|
||||||
|
{
|
||||||
|
d_ptr->packageName = name;
|
||||||
|
if (QFile::exists(name)) {
|
||||||
|
QFile xlsx(name);
|
||||||
|
if (xlsx.open(QFile::ReadOnly))
|
||||||
|
d_ptr->loadPackage(&xlsx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Document::Document(QIODevice *device, QObject *parent) :
|
||||||
|
QObject(parent), d_ptr(new DocumentPrivate(this))
|
||||||
|
{
|
||||||
|
if (device && device->isReadable())
|
||||||
|
d_ptr->loadPackage(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Document::save()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Document::saveAs(const QString &name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Document::saveAs(QIODevice *device)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Document::~Document()
|
||||||
|
{
|
||||||
|
delete d_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QXlsx
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef QXLSX_XLSXDOCUMENT_H
|
||||||
|
#define QXLSX_XLSXDOCUMENT_H
|
||||||
|
|
||||||
|
#include "xlsxglobal.h"
|
||||||
|
#include <QObject>
|
||||||
|
class QIODevice;
|
||||||
|
|
||||||
|
namespace QXlsx {
|
||||||
|
|
||||||
|
class Workbook;
|
||||||
|
class Worksheet;
|
||||||
|
class DocumentPrivate;
|
||||||
|
class Q_XLSX_EXPORT Document : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_DECLARE_PRIVATE(Document)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Document(QObject *parent = 0);
|
||||||
|
Document(const QString &name, QObject *parent=0);
|
||||||
|
Document(QIODevice *device, QObject *parent=0);
|
||||||
|
~Document();
|
||||||
|
|
||||||
|
bool save();
|
||||||
|
bool saveAs(const QString &name);
|
||||||
|
bool saveAs(QIODevice *device);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(Document)
|
||||||
|
DocumentPrivate * const d_ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QXlsx
|
||||||
|
|
||||||
|
#endif // QXLSX_XLSXDOCUMENT_H
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef XLSXDOCUMENT_P_H
|
||||||
|
#define XLSXDOCUMENT_P_H
|
||||||
|
|
||||||
|
#include "xlsxdocument.h"
|
||||||
|
|
||||||
|
namespace QXlsx {
|
||||||
|
|
||||||
|
class DocumentPrivate
|
||||||
|
{
|
||||||
|
Q_DECLARE_PUBLIC(Document)
|
||||||
|
public:
|
||||||
|
DocumentPrivate(Document *p);
|
||||||
|
|
||||||
|
bool loadPackage(QIODevice *device);
|
||||||
|
|
||||||
|
Document *q_ptr;
|
||||||
|
const QString defaultPackageName; //default name when package name not specified
|
||||||
|
QString packageName; //name of the .xlsx file
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // XLSXDOCUMENT_P_H
|
||||||
@@ -34,6 +34,8 @@
|
|||||||
#include "xlsxrelationships_p.h"
|
#include "xlsxrelationships_p.h"
|
||||||
#include "xlsxzipwriter_p.h"
|
#include "xlsxzipwriter_p.h"
|
||||||
#include "xlsxdrawing_p.h"
|
#include "xlsxdrawing_p.h"
|
||||||
|
#include "xlsxzipreader_p.h"
|
||||||
|
#include "xlsxdocument.h"
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -87,6 +89,14 @@ Package::Package(Workbook *workbook) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Package::parsePackage(QIODevice *packageDevice, Document *document)
|
||||||
|
{
|
||||||
|
ZipReader zipReader(packageDevice);
|
||||||
|
QStringList filePaths = zipReader.filePaths();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool Package::createPackage(const QString &packageName)
|
bool Package::createPackage(const QString &packageName)
|
||||||
{
|
{
|
||||||
ZipWriter zipWriter(packageName);
|
ZipWriter zipWriter(packageName);
|
||||||
@@ -107,7 +117,7 @@ bool Package::createPackage(const QString &packageName)
|
|||||||
writeSharedStringsFile(zipWriter);
|
writeSharedStringsFile(zipWriter);
|
||||||
writeDocPropsAppFile(zipWriter);
|
writeDocPropsAppFile(zipWriter);
|
||||||
writeDocPropsCoreFile(zipWriter);
|
writeDocPropsCoreFile(zipWriter);
|
||||||
writeContentTypesFiles(zipWriter);
|
writeContentTypesFile(zipWriter);
|
||||||
m_workbook->styles()->prepareStyles();
|
m_workbook->styles()->prepareStyles();
|
||||||
writeStylesFiles(zipWriter);
|
writeStylesFiles(zipWriter);
|
||||||
writeThemeFile(zipWriter);
|
writeThemeFile(zipWriter);
|
||||||
@@ -161,7 +171,7 @@ void Package::writeDrawingFiles(ZipWriter &zipWriter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Package::writeContentTypesFiles(ZipWriter &zipWriter)
|
void Package::writeContentTypesFile(ZipWriter &zipWriter)
|
||||||
{
|
{
|
||||||
ContentTypes content;
|
ContentTypes content;
|
||||||
|
|
||||||
|
|||||||
@@ -25,18 +25,22 @@
|
|||||||
#ifndef QXLSX_PACKAGE_H
|
#ifndef QXLSX_PACKAGE_H
|
||||||
#define QXLSX_PACKAGE_H
|
#define QXLSX_PACKAGE_H
|
||||||
|
|
||||||
|
#include "xlsxglobal.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
class QIODevice;
|
||||||
|
|
||||||
namespace QXlsx {
|
namespace QXlsx {
|
||||||
|
|
||||||
class Workbook;
|
class Workbook;
|
||||||
class ZipWriter;
|
class ZipWriter;
|
||||||
|
class Document;
|
||||||
|
|
||||||
class Package
|
class XLSX_AUTOTEST_EXPORT Package
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Package(Workbook *workbook);
|
Package(Workbook *workbook);
|
||||||
|
|
||||||
|
bool parsePackage(QIODevice *packageDevice, Document *document);
|
||||||
bool createPackage(const QString &packageName);
|
bool createPackage(const QString &packageName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -51,7 +55,7 @@ private:
|
|||||||
void writeSharedStringsFile(ZipWriter &zipWriter);
|
void writeSharedStringsFile(ZipWriter &zipWriter);
|
||||||
void writeDocPropsAppFile(ZipWriter &zipWriter);
|
void writeDocPropsAppFile(ZipWriter &zipWriter);
|
||||||
void writeDocPropsCoreFile(ZipWriter &zipWriter);
|
void writeDocPropsCoreFile(ZipWriter &zipWriter);
|
||||||
void writeContentTypesFiles(ZipWriter &zipWriter);
|
void writeContentTypesFile(ZipWriter &zipWriter);
|
||||||
void writeStylesFiles(ZipWriter &zipWriter);
|
void writeStylesFiles(ZipWriter &zipWriter);
|
||||||
void writeThemeFile(ZipWriter &zipWriter);
|
void writeThemeFile(ZipWriter &zipWriter);
|
||||||
void writeRootRelsFile(ZipWriter &zipWriter);
|
void writeRootRelsFile(ZipWriter &zipWriter);
|
||||||
|
|||||||
Reference in New Issue
Block a user