Browse Source

Introduce new class AbstractSheet

master
Debao Zhang 11 years ago
parent
commit
e72853a33c
  1. 5
      src/xlsx/qtxlsx.pri
  2. 149
      src/xlsx/xlsxabstractsheet.cpp
  3. 66
      src/xlsx/xlsxabstractsheet.h
  4. 65
      src/xlsx/xlsxabstractsheet_p.h
  5. 5
      src/xlsx/xlsxooxmlfile.cpp
  6. 1
      src/xlsx/xlsxooxmlfile_p.h
  7. 84
      src/xlsx/xlsxworksheet.cpp
  8. 16
      src/xlsx/xlsxworksheet.h
  9. 11
      src/xlsx/xlsxworksheet_p.h

5
src/xlsx/qtxlsx.pri

@ -14,10 +14,12 @@ HEADERS += $$PWD/xlsxdocpropscore_p.h \
$$PWD/xlsxformat.h \ $$PWD/xlsxformat.h \
$$PWD/xlsxworkbook.h \ $$PWD/xlsxworkbook.h \
$$PWD/xlsxstyles_p.h \ $$PWD/xlsxstyles_p.h \
$$PWD/xlsxabstractsheet.h \
$$PWD/xlsxabstractsheet_p.h \
$$PWD/xlsxworksheet.h \ $$PWD/xlsxworksheet.h \
$$PWD/xlsxworksheet_p.h \
$$PWD/xlsxzipwriter_p.h \ $$PWD/xlsxzipwriter_p.h \
$$PWD/xlsxworkbook_p.h \ $$PWD/xlsxworkbook_p.h \
$$PWD/xlsxworksheet_p.h \
$$PWD/xlsxformat_p.h \ $$PWD/xlsxformat_p.h \
$$PWD/xlsxglobal.h \ $$PWD/xlsxglobal.h \
$$PWD/xlsxdrawing_p.h \ $$PWD/xlsxdrawing_p.h \
@ -52,6 +54,7 @@ SOURCES += $$PWD/xlsxdocpropscore.cpp \
$$PWD/xlsxformat.cpp \ $$PWD/xlsxformat.cpp \
$$PWD/xlsxstyles.cpp \ $$PWD/xlsxstyles.cpp \
$$PWD/xlsxworkbook.cpp \ $$PWD/xlsxworkbook.cpp \
$$PWD/xlsxabstractsheet.cpp \
$$PWD/xlsxworksheet.cpp \ $$PWD/xlsxworksheet.cpp \
$$PWD/xlsxzipwriter.cpp \ $$PWD/xlsxzipwriter.cpp \
$$PWD/xlsxdrawing.cpp \ $$PWD/xlsxdrawing.cpp \

149
src/xlsx/xlsxabstractsheet.cpp

@ -0,0 +1,149 @@
/****************************************************************************
** 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 "xlsxabstractsheet.h"
#include "xlsxabstractsheet_p.h"
#include "xlsxworkbook.h"
QT_BEGIN_NAMESPACE_XLSX
AbstractSheetPrivate::AbstractSheetPrivate(AbstractSheet *p)
: OOXmlFilePrivate(p)
{
hidden = false;
type = AbstractSheet::ST_WorkSheet;
}
AbstractSheetPrivate::~AbstractSheetPrivate()
{
}
/*!
\class AbstractSheet
\inmodule QtXlsx
\brief Base class for worksheet, chartsheet, etc.
*/
/*!
\enum AbstractSheet::SheetType
\value ST_WorkSheet,
\omitvalue ST_ChartSheet,
\omitvalue ST_DialogSheet,
\omitvalue ST_MacroSheet
*/
/*!
* \internal
*/
AbstractSheet::AbstractSheet(const QString &name, int id, Workbook *workbook, AbstractSheetPrivate *d) :
OOXmlFile(d)
{
d_func()->name = name;
d_func()->id = id;
d_func()->workbook = workbook;
}
/*!
* Returns the name of the sheet.
*/
QString AbstractSheet::sheetName() const
{
Q_D(const AbstractSheet);
return d->name;
}
/*!
* \internal
*/
void AbstractSheet::setSheetName(const QString &sheetName)
{
Q_D(AbstractSheet);
d->name = sheetName;
}
/*!
* Returns the type of the sheet.
*/
AbstractSheet::SheetType AbstractSheet::sheetType() const
{
Q_D(const AbstractSheet);
return d->type;
}
/*!
* \internal
*/
void AbstractSheet::setSheetType(SheetType type)
{
Q_D(AbstractSheet);
d->type = type;
}
/*!
* \internal
*/
bool AbstractSheet::isHidden() const
{
Q_D(const AbstractSheet);
return d->hidden;
}
/*!
* \internal
*/
void AbstractSheet::setHidden(bool hidden)
{
Q_D(AbstractSheet);
d->hidden = hidden;
}
/*!
* \internal
*/
int AbstractSheet::sheetId() const
{
Q_D(const AbstractSheet);
return d->id;
}
/*!
* \internal
*/
Drawing *AbstractSheet::drawing() const
{
Q_D(const AbstractSheet);
return d->drawing.data();
}
/*!
* Return the workbook
*/
Workbook *AbstractSheet::workbook() const
{
Q_D(const AbstractSheet);
return d->workbook;
}
QT_END_NAMESPACE_XLSX

66
src/xlsx/xlsxabstractsheet.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 XLSXABSTRACTSHEET_H
#define XLSXABSTRACTSHEET_H
#include "xlsxooxmlfile.h"
#include <QStringList>
#include <QSharedPointer>
QT_BEGIN_NAMESPACE_XLSX
class Workbook;
class Drawing;
class AbstractSheetPrivate;
class Q_XLSX_EXPORT AbstractSheet : public OOXmlFile
{
Q_DECLARE_PRIVATE(AbstractSheet)
public:
enum SheetType
{
ST_WorkSheet,
ST_ChartSheet,
ST_DialogSheet,
ST_MacroSheet
};
SheetType sheetType() const;
QString sheetName() const;
bool isHidden() const;
Workbook *workbook() const;
//Relationships &relationships();
protected:
AbstractSheet(const QString &sheetName, int sheetId, Workbook *book, AbstractSheetPrivate *d);
//QSharedPointer<AbstractSheet> copy(const QString &distName, int distId) const;
void setSheetName(const QString &sheetName);
void setHidden(bool hidden);
void setSheetType(SheetType type);
int sheetId() const;
Drawing *drawing() const;
};
QT_END_NAMESPACE_XLSX
#endif // XLSXABSTRACTSHEET_H

65
src/xlsx/xlsxabstractsheet_p.h

@ -0,0 +1,65 @@
/****************************************************************************
** 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 XLSXABSTRACTSHEET_P_H
#define XLSXABSTRACTSHEET_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 "xlsxglobal.h"
#include "xlsxabstractsheet.h"
#include "xlsxooxmlfile_p.h"
#include "xlsxrelationships_p.h"
#include <QSharedPointer>
namespace QXlsx {
class XLSX_AUTOTEST_EXPORT AbstractSheetPrivate : public OOXmlFilePrivate
{
Q_DECLARE_PUBLIC(AbstractSheet)
public:
AbstractSheetPrivate(AbstractSheet *p);
~AbstractSheetPrivate();
Workbook *workbook;
QSharedPointer<Drawing> drawing;
QString name;
int id;
bool hidden;
AbstractSheet::SheetType type;
};
}
#endif // XLSXABSTRACTSHEET_P_H

5
src/xlsx/xlsxooxmlfile.cpp

@ -37,6 +37,11 @@ OOXmlFilePrivate::OOXmlFilePrivate(OOXmlFile *q)
} }
OOXmlFilePrivate::~OOXmlFilePrivate()
{
}
/*! /*!
* \internal * \internal
* *

1
src/xlsx/xlsxooxmlfile_p.h

@ -48,6 +48,7 @@ class XLSX_AUTOTEST_EXPORT OOXmlFilePrivate
public: public:
OOXmlFilePrivate(OOXmlFile *q); OOXmlFilePrivate(OOXmlFile *q);
virtual ~OOXmlFilePrivate();
QString filePathInPackage;//such as "xl/worksheets/sheet1.xml" QString filePathInPackage;//such as "xl/worksheets/sheet1.xml"
//used when load the .xlsx file //used when load the .xlsx file

84
src/xlsx/xlsxworksheet.cpp

@ -57,7 +57,7 @@
QT_BEGIN_NAMESPACE_XLSX QT_BEGIN_NAMESPACE_XLSX
WorksheetPrivate::WorksheetPrivate(Worksheet *p) WorksheetPrivate::WorksheetPrivate(Worksheet *p)
: OOXmlFilePrivate(p) : AbstractSheetPrivate(p)
, windowProtection(false), showFormulas(false), showGridLines(true), showRowColHeaders(true) , windowProtection(false), showFormulas(false), showGridLines(true), showRowColHeaders(true)
, showZeros(true), rightToLeft(false), tabSelected(false), showRuler(false) , showZeros(true), rightToLeft(false), tabSelected(false), showRuler(false)
, showOutlineSymbols(true), showWhiteSpace(true) , showOutlineSymbols(true), showWhiteSpace(true)
@ -69,8 +69,6 @@ WorksheetPrivate::WorksheetPrivate(Worksheet *p)
default_row_height = 15; default_row_height = 15;
default_row_zeroed = false; default_row_zeroed = false;
hidden = false;
} }
WorksheetPrivate::~WorksheetPrivate() WorksheetPrivate::~WorksheetPrivate()
@ -173,14 +171,11 @@ int WorksheetPrivate::checkDimensions(int row, int col, bool ignore_row, bool ig
/*! /*!
* \internal * \internal
*/ */
Worksheet::Worksheet(const QString &name, int id, Workbook *workbook) : Worksheet::Worksheet(const QString &name, int id, Workbook *workbook)
OOXmlFile(new WorksheetPrivate(this)) :AbstractSheet(name, id, workbook, new WorksheetPrivate(this))
{ {
d_func()->name = name;
d_func()->id = id;
if (!workbook) //For unit test propose only. Ignore the memery leak. if (!workbook) //For unit test propose only. Ignore the memery leak.
workbook = new Workbook; d_func()->workbook = new Workbook;
d_func()->workbook = workbook;
} }
/*! /*!
@ -234,32 +229,6 @@ Worksheet::~Worksheet()
{ {
} }
/*!
* \internal
*/
bool Worksheet::isChartsheet() const
{
return false;
}
/*!
* Returns the name of the sheet.
*/
QString Worksheet::sheetName() const
{
Q_D(const Worksheet);
return d->name;
}
/*!
* \internal
*/
void Worksheet::setSheetName(const QString &sheetName)
{
Q_D(Worksheet);
d->name = sheetName;
}
/*! /*!
* \internal * \internal
*/ */
@ -269,33 +238,6 @@ Relationships &Worksheet::relationships()
return d->relationships; return d->relationships;
} }
/*!
* \internal
*/
bool Worksheet::isHidden() const
{
Q_D(const Worksheet);
return d->hidden;
}
/*!
* \internal
*/
void Worksheet::setHidden(bool hidden)
{
Q_D(Worksheet);
d->hidden = hidden;
}
/*!
* \internal
*/
int Worksheet::sheetId() const
{
Q_D(const Worksheet);
return d->id;
}
/*! /*!
* Returns whether sheet is protected. * Returns whether sheet is protected.
*/ */
@ -1808,15 +1750,6 @@ CellRange Worksheet::dimension() const
return d->dimension; return d->dimension;
} }
/*!
* \internal
*/
Drawing *Worksheet::drawing() const
{
Q_D(const Worksheet);
return d->drawing.data();
}
/* /*
Convert the height of a cell from user's units to pixels. If the Convert the height of a cell from user's units to pixels. If the
height hasn't been set by the user we use the default value. If height hasn't been set by the user we use the default value. If
@ -2224,13 +2157,4 @@ SharedStrings *WorksheetPrivate::sharedStrings() const
return workbook->sharedStrings(); return workbook->sharedStrings();
} }
/*!
* Return the workbook
*/
Workbook *Worksheet::workbook() const
{
Q_D(const Worksheet);
return d->workbook;
}
QT_END_NAMESPACE_XLSX QT_END_NAMESPACE_XLSX

16
src/xlsx/xlsxworksheet.h

@ -25,10 +25,9 @@
#ifndef XLSXWORKSHEET_H #ifndef XLSXWORKSHEET_H
#define XLSXWORKSHEET_H #define XLSXWORKSHEET_H
#include "xlsxglobal.h" #include "xlsxabstractsheet.h"
#include "xlsxcell.h" #include "xlsxcell.h"
#include "xlsxcellrange.h" #include "xlsxcellrange.h"
#include "xlsxooxmlfile.h"
#include <QStringList> #include <QStringList>
#include <QMap> #include <QMap>
#include <QVariant> #include <QVariant>
@ -53,7 +52,7 @@ class Relationships;
class Chart; class Chart;
class WorksheetPrivate; class WorksheetPrivate;
class Q_XLSX_EXPORT Worksheet : public OOXmlFile class Q_XLSX_EXPORT Worksheet : public AbstractSheet
{ {
Q_DECLARE_PRIVATE(Worksheet) Q_DECLARE_PRIVATE(Worksheet)
public: public:
@ -130,9 +129,6 @@ public:
bool isWhiteSpaceVisible() const; bool isWhiteSpaceVisible() const;
void setWhiteSpaceVisible(bool visible); void setWhiteSpaceVisible(bool visible);
QString sheetName() const;
Workbook *workbook() const;
Relationships &relationships(); Relationships &relationships();
~Worksheet(); ~Worksheet();
private: private:
@ -141,17 +137,9 @@ private:
friend class ::WorksheetTest; friend class ::WorksheetTest;
Worksheet(const QString &sheetName, int sheetId, Workbook *book); Worksheet(const QString &sheetName, int sheetId, Workbook *book);
QSharedPointer<Worksheet> copy(const QString &distName, int distId) const; QSharedPointer<Worksheet> copy(const QString &distName, int distId) const;
void setSheetName(const QString &sheetName);
void saveToXmlFile(QIODevice *device) const; void saveToXmlFile(QIODevice *device) const;
bool loadFromXmlFile(QIODevice *device); bool loadFromXmlFile(QIODevice *device);
bool isChartsheet() const;
bool isHidden() const;
void setHidden(bool hidden);
int sheetId() const;
Drawing *drawing() const;
}; };
QT_END_NAMESPACE_XLSX QT_END_NAMESPACE_XLSX

11
src/xlsx/xlsxworksheet_p.h

@ -36,9 +36,8 @@
// We mean it. // We mean it.
// //
#include "xlsxglobal.h"
#include "xlsxworksheet.h" #include "xlsxworksheet.h"
#include "xlsxooxmlfile_p.h" #include "xlsxabstractsheet_p.h"
#include "xlsxcell.h" #include "xlsxcell.h"
#include "xlsxdatavalidation.h" #include "xlsxdatavalidation.h"
#include "xlsxconditionalformatting.h" #include "xlsxconditionalformatting.h"
@ -113,7 +112,7 @@ struct XlsxColumnInfo
bool collapsed; bool collapsed;
}; };
class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public OOXmlFilePrivate class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public AbstractSheetPrivate
{ {
Q_DECLARE_PUBLIC(Worksheet) Q_DECLARE_PUBLIC(Worksheet)
public: public:
@ -144,9 +143,7 @@ public:
SharedStrings *sharedStrings() const; SharedStrings *sharedStrings() const;
Workbook *workbook;
mutable Relationships relationships; mutable Relationships relationships;
QSharedPointer<Drawing> drawing;
QMap<int, QMap<int, QSharedPointer<Cell> > > cellTable; QMap<int, QMap<int, QSharedPointer<Cell> > > cellTable;
QMap<int, QMap<int, QString> > comments; QMap<int, QMap<int, QString> > comments;
QMap<int, QMap<int, QSharedPointer<XlsxHyperlinkData> > > urlTable; QMap<int, QMap<int, QSharedPointer<XlsxHyperlinkData> > > urlTable;
@ -171,10 +168,6 @@ public:
int default_row_height; int default_row_height;
bool default_row_zeroed; bool default_row_zeroed;
QString name;
int id;
bool hidden;
bool windowProtection; bool windowProtection;
bool showFormulas; bool showFormulas;
bool showGridLines; bool showGridLines;

Loading…
Cancel
Save