From e72853a33c6c7fa80d96fe17e69ba1650a4e5ece Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Tue, 25 Feb 2014 11:46:55 +0800 Subject: [PATCH] Introduce new class AbstractSheet --- src/xlsx/qtxlsx.pri | 5 +- src/xlsx/xlsxabstractsheet.cpp | 149 +++++++++++++++++++++++++++++++++ src/xlsx/xlsxabstractsheet.h | 66 +++++++++++++++ src/xlsx/xlsxabstractsheet_p.h | 65 ++++++++++++++ src/xlsx/xlsxooxmlfile.cpp | 5 ++ src/xlsx/xlsxooxmlfile_p.h | 1 + src/xlsx/xlsxworksheet.cpp | 84 +------------------ src/xlsx/xlsxworksheet.h | 16 +--- src/xlsx/xlsxworksheet_p.h | 11 +-- 9 files changed, 298 insertions(+), 104 deletions(-) create mode 100644 src/xlsx/xlsxabstractsheet.cpp create mode 100644 src/xlsx/xlsxabstractsheet.h create mode 100644 src/xlsx/xlsxabstractsheet_p.h diff --git a/src/xlsx/qtxlsx.pri b/src/xlsx/qtxlsx.pri index cae32b9..c5cb396 100755 --- a/src/xlsx/qtxlsx.pri +++ b/src/xlsx/qtxlsx.pri @@ -14,10 +14,12 @@ HEADERS += $$PWD/xlsxdocpropscore_p.h \ $$PWD/xlsxformat.h \ $$PWD/xlsxworkbook.h \ $$PWD/xlsxstyles_p.h \ + $$PWD/xlsxabstractsheet.h \ + $$PWD/xlsxabstractsheet_p.h \ $$PWD/xlsxworksheet.h \ + $$PWD/xlsxworksheet_p.h \ $$PWD/xlsxzipwriter_p.h \ $$PWD/xlsxworkbook_p.h \ - $$PWD/xlsxworksheet_p.h \ $$PWD/xlsxformat_p.h \ $$PWD/xlsxglobal.h \ $$PWD/xlsxdrawing_p.h \ @@ -52,6 +54,7 @@ SOURCES += $$PWD/xlsxdocpropscore.cpp \ $$PWD/xlsxformat.cpp \ $$PWD/xlsxstyles.cpp \ $$PWD/xlsxworkbook.cpp \ + $$PWD/xlsxabstractsheet.cpp \ $$PWD/xlsxworksheet.cpp \ $$PWD/xlsxzipwriter.cpp \ $$PWD/xlsxdrawing.cpp \ diff --git a/src/xlsx/xlsxabstractsheet.cpp b/src/xlsx/xlsxabstractsheet.cpp new file mode 100644 index 0000000..6b101b1 --- /dev/null +++ b/src/xlsx/xlsxabstractsheet.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** 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 diff --git a/src/xlsx/xlsxabstractsheet.h b/src/xlsx/xlsxabstractsheet.h new file mode 100644 index 0000000..0f40d80 --- /dev/null +++ b/src/xlsx/xlsxabstractsheet.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** 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 +#include + +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 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 diff --git a/src/xlsx/xlsxabstractsheet_p.h b/src/xlsx/xlsxabstractsheet_p.h new file mode 100644 index 0000000..a0cc450 --- /dev/null +++ b/src/xlsx/xlsxabstractsheet_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** Copyright (c) 2013-2014 Debao Zhang +** 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 + +namespace QXlsx { + +class XLSX_AUTOTEST_EXPORT AbstractSheetPrivate : public OOXmlFilePrivate +{ + Q_DECLARE_PUBLIC(AbstractSheet) +public: + AbstractSheetPrivate(AbstractSheet *p); + ~AbstractSheetPrivate(); + + Workbook *workbook; + QSharedPointer drawing; + + QString name; + int id; + bool hidden; + AbstractSheet::SheetType type; +}; + +} +#endif // XLSXABSTRACTSHEET_P_H diff --git a/src/xlsx/xlsxooxmlfile.cpp b/src/xlsx/xlsxooxmlfile.cpp index 6ba85ac..6bf0355 100644 --- a/src/xlsx/xlsxooxmlfile.cpp +++ b/src/xlsx/xlsxooxmlfile.cpp @@ -37,6 +37,11 @@ OOXmlFilePrivate::OOXmlFilePrivate(OOXmlFile *q) } +OOXmlFilePrivate::~OOXmlFilePrivate() +{ + +} + /*! * \internal * diff --git a/src/xlsx/xlsxooxmlfile_p.h b/src/xlsx/xlsxooxmlfile_p.h index 4f16524..76b79ae 100644 --- a/src/xlsx/xlsxooxmlfile_p.h +++ b/src/xlsx/xlsxooxmlfile_p.h @@ -48,6 +48,7 @@ class XLSX_AUTOTEST_EXPORT OOXmlFilePrivate public: OOXmlFilePrivate(OOXmlFile *q); + virtual ~OOXmlFilePrivate(); QString filePathInPackage;//such as "xl/worksheets/sheet1.xml" //used when load the .xlsx file diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 9cbd50d..e611623 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE_XLSX WorksheetPrivate::WorksheetPrivate(Worksheet *p) - : OOXmlFilePrivate(p) + : AbstractSheetPrivate(p) , windowProtection(false), showFormulas(false), showGridLines(true), showRowColHeaders(true) , showZeros(true), rightToLeft(false), tabSelected(false), showRuler(false) , showOutlineSymbols(true), showWhiteSpace(true) @@ -69,8 +69,6 @@ WorksheetPrivate::WorksheetPrivate(Worksheet *p) default_row_height = 15; default_row_zeroed = false; - - hidden = false; } WorksheetPrivate::~WorksheetPrivate() @@ -173,14 +171,11 @@ int WorksheetPrivate::checkDimensions(int row, int col, bool ignore_row, bool ig /*! * \internal */ -Worksheet::Worksheet(const QString &name, int id, Workbook *workbook) : - OOXmlFile(new WorksheetPrivate(this)) +Worksheet::Worksheet(const QString &name, int id, Workbook *workbook) + :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. - workbook = new Workbook; - d_func()->workbook = workbook; + d_func()->workbook = new 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 */ @@ -269,33 +238,6 @@ Relationships &Worksheet::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. */ @@ -1808,15 +1750,6 @@ CellRange Worksheet::dimension() const 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 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 the workbook - */ -Workbook *Worksheet::workbook() const -{ - Q_D(const Worksheet); - return d->workbook; -} - QT_END_NAMESPACE_XLSX diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index c689a5d..929d695 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -25,10 +25,9 @@ #ifndef XLSXWORKSHEET_H #define XLSXWORKSHEET_H -#include "xlsxglobal.h" +#include "xlsxabstractsheet.h" #include "xlsxcell.h" #include "xlsxcellrange.h" -#include "xlsxooxmlfile.h" #include #include #include @@ -53,7 +52,7 @@ class Relationships; class Chart; class WorksheetPrivate; -class Q_XLSX_EXPORT Worksheet : public OOXmlFile +class Q_XLSX_EXPORT Worksheet : public AbstractSheet { Q_DECLARE_PRIVATE(Worksheet) public: @@ -130,9 +129,6 @@ public: bool isWhiteSpaceVisible() const; void setWhiteSpaceVisible(bool visible); - QString sheetName() const; - - Workbook *workbook() const; Relationships &relationships(); ~Worksheet(); private: @@ -141,17 +137,9 @@ private: friend class ::WorksheetTest; Worksheet(const QString &sheetName, int sheetId, Workbook *book); QSharedPointer copy(const QString &distName, int distId) const; - void setSheetName(const QString &sheetName); void saveToXmlFile(QIODevice *device) const; bool loadFromXmlFile(QIODevice *device); - - bool isChartsheet() const; - bool isHidden() const; - void setHidden(bool hidden); - int sheetId() const; - - Drawing *drawing() const; }; QT_END_NAMESPACE_XLSX diff --git a/src/xlsx/xlsxworksheet_p.h b/src/xlsx/xlsxworksheet_p.h index e542f47..96226c2 100644 --- a/src/xlsx/xlsxworksheet_p.h +++ b/src/xlsx/xlsxworksheet_p.h @@ -36,9 +36,8 @@ // We mean it. // -#include "xlsxglobal.h" #include "xlsxworksheet.h" -#include "xlsxooxmlfile_p.h" +#include "xlsxabstractsheet_p.h" #include "xlsxcell.h" #include "xlsxdatavalidation.h" #include "xlsxconditionalformatting.h" @@ -113,7 +112,7 @@ struct XlsxColumnInfo bool collapsed; }; -class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public OOXmlFilePrivate +class XLSX_AUTOTEST_EXPORT WorksheetPrivate : public AbstractSheetPrivate { Q_DECLARE_PUBLIC(Worksheet) public: @@ -144,9 +143,7 @@ public: SharedStrings *sharedStrings() const; - Workbook *workbook; mutable Relationships relationships; - QSharedPointer drawing; QMap > > cellTable; QMap > comments; QMap > > urlTable; @@ -171,10 +168,6 @@ public: int default_row_height; bool default_row_zeroed; - QString name; - int id; - bool hidden; - bool windowProtection; bool showFormulas; bool showGridLines;