File indexing completed on 2025-01-19 13:27:37
0001 /* 0002 * This file is part of Office 2007 Filters for Calligra 0003 * 0004 * Copyright (C) 2010 Sebastian Sauer <sebsauer@kdab.com> 0005 * Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). 0006 * 0007 * Contact: Suresh Chande suresh.chande@nokia.com 0008 * 0009 * This library is free software; you can redistribute it and/or 0010 * modify it under the terms of the GNU Lesser General Public License 0011 * version 2.1 as published by the Free Software Foundation. 0012 * 0013 * This library is distributed in the hope that it will be useful, but 0014 * WITHOUT ANY WARRANTY; without even the implied warranty of 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 * Lesser General Public License for more details. 0017 * 0018 * You should have received a copy of the GNU Lesser General Public 0019 * License along with this library; if not, write to the Free Software 0020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 0021 * 02110-1301 USA 0022 * 0023 */ 0024 0025 #ifndef XLSXXMLWORKSHEETREADER_P_H 0026 #define XLSXXMLWORKSHEETREADER_P_H 0027 0028 //! @todo the workboot was designed after filters/kspread/excel/sidewinder to allow to shared as much 0029 //! logic as possible. Goal is to let them both share the same structures and OpenDocument logic 0030 //! some day. 0031 0032 #include <MsooXmlGlobal.h> 0033 #include "XlsxXmlDrawingReader.h" 0034 0035 class Sheet; 0036 class Cell; 0037 0038 class EmbeddedCellObjects 0039 { 0040 public: 0041 EmbeddedCellObjects(){} 0042 ~EmbeddedCellObjects(){ qDeleteAll(drawings); } 0043 QList<XlsxDrawingObject*> drawings; 0044 0045 QList< QPair<QString,QString> > oleObjects; 0046 QList<QString> oleFrameBegins; 0047 QString hyperlink; 0048 }; 0049 0050 class Formula { 0051 protected: 0052 explicit Formula() {} 0053 public: 0054 virtual ~Formula() {} 0055 virtual bool isShared() const = 0; 0056 }; 0057 0058 class FormulaImpl : public Formula { 0059 public: 0060 QString m_formula; 0061 explicit FormulaImpl(const QString &formula) : Formula(), m_formula(formula) {} 0062 bool isShared() const override { return false; } 0063 ~FormulaImpl() override {} 0064 }; 0065 0066 class SharedFormula : public Formula { 0067 public: 0068 Cell *m_referencedCell; 0069 explicit SharedFormula(Cell *referencedCell) : Formula(), m_referencedCell(referencedCell) {} 0070 bool isShared() const override { return true; } 0071 ~SharedFormula() override {} 0072 }; 0073 0074 class Cell 0075 { 0076 public: 0077 void appendDrawing( XlsxDrawingObject* obj ){ 0078 if (!embedded) { 0079 embedded = new EmbeddedCellObjects; 0080 } 0081 embedded->drawings.append( obj ); 0082 } 0083 void appendOleObject( const QPair<QString,QString>& oleObject, const QString& oleFrameBegin ){ 0084 if (!embedded) { 0085 embedded = new EmbeddedCellObjects; 0086 } 0087 embedded->oleObjects.append( oleObject ); 0088 embedded->oleFrameBegins.append( oleFrameBegin ); 0089 } 0090 void setHyperLink( const QString& link ) { 0091 if (!embedded) { 0092 embedded = new EmbeddedCellObjects; 0093 } 0094 embedded->hyperlink = link; 0095 } 0096 QList< QPair<QString,QString> > oleObjects() const { 0097 if (embedded) { 0098 return embedded->oleObjects; 0099 } 0100 else { 0101 return QList< QPair<QString,QString> >(); 0102 } 0103 } 0104 QString hyperlink() const { 0105 if (embedded) { 0106 return embedded->hyperlink; 0107 } 0108 else { 0109 return QString(); 0110 } 0111 } 0112 0113 QString styleName; 0114 QString charStyleName; 0115 QString text; 0116 0117 QString *valueAttrValue; 0118 0119 Formula *formula; 0120 0121 EmbeddedCellObjects* embedded; 0122 0123 int column; 0124 int row; 0125 int rowsMerged; 0126 int columnsMerged; 0127 0128 enum ValueType { 0129 ConstNone, 0130 ConstString, 0131 ConstBoolean, 0132 ConstDate, 0133 ConstFloat 0134 }; 0135 ValueType valueType; 0136 0137 enum ValueAttr { 0138 OfficeNone, 0139 OfficeValue, 0140 OfficeStringValue, 0141 OfficeBooleanValue, 0142 OfficeDateValue 0143 }; 0144 ValueAttr valueAttr; 0145 0146 bool isPlainText : 1; 0147 0148 Cell(int columnIndex, int rowIndex) : valueAttrValue(0), formula(0), embedded(0), column(columnIndex), row(rowIndex), rowsMerged(1), columnsMerged(1), valueType(Cell::ConstNone), valueAttr(OfficeNone), isPlainText(true) {} 0149 ~Cell() { delete valueAttrValue; delete formula; delete embedded; } 0150 }; 0151 0152 class Row 0153 { 0154 public: 0155 QString styleName; 0156 int rowIndex; 0157 bool hidden : 1; 0158 0159 Row(int index) : rowIndex(index), hidden(false) {} 0160 ~Row() {} 0161 }; 0162 0163 class Column 0164 { 0165 public: 0166 QString styleName; 0167 int columnIndex; 0168 bool hidden : 1; 0169 0170 Column(int index) : columnIndex(index), hidden(false) {} 0171 ~Column() {} 0172 }; 0173 0174 class Sheet 0175 { 0176 public: 0177 QString m_name; 0178 double m_defaultRowHeight, m_defaultColWidth, m_baseColWidth; 0179 0180 explicit Sheet(const QString &name) : m_name(name), m_defaultRowHeight(-1.0), m_defaultColWidth(-1.0), m_baseColWidth(-1.0), m_maxRow(0), m_maxColumn(0), m_visible(true) {} 0181 ~Sheet() { qDeleteAll(m_rows); qDeleteAll(m_columns); /*qDeleteAll(m_cells);*/ } 0182 0183 Row* row(int rowIndex, bool autoCreate) 0184 { 0185 Row* r = m_rows[ rowIndex ]; 0186 if (!r && autoCreate) { 0187 r = new Row(/*this,*/ rowIndex); 0188 m_rows[ rowIndex ] = r; 0189 if (rowIndex > m_maxRow) m_maxRow = rowIndex; 0190 } 0191 return r; 0192 } 0193 0194 Column* column(int columnIndex, bool autoCreate) 0195 { 0196 Column* c = m_columns[ columnIndex ]; 0197 if (!c && autoCreate) { 0198 c = new Column(/*this,*/ columnIndex); 0199 m_columns[ columnIndex ] = c; 0200 if (columnIndex > m_maxColumn) m_maxColumn = columnIndex; 0201 } 0202 return c; 0203 } 0204 0205 Cell* cell(int columnIndex, int rowIndex, bool autoCreate) 0206 { 0207 const unsigned hashed = (rowIndex + 1) * MSOOXML::maximumSpreadsheetColumns() + columnIndex + 1; 0208 Cell* c = m_cells[ hashed ]; 0209 if (!c && autoCreate) { 0210 c = new Cell(columnIndex, rowIndex); 0211 m_cells[ hashed ] = c; 0212 this->column(columnIndex, true); 0213 this->row(rowIndex, true); 0214 if (rowIndex > m_maxRow) m_maxRow = rowIndex; 0215 if (columnIndex > m_maxColumn) m_maxColumn = columnIndex; 0216 if (!m_maxCellsInRow.contains(rowIndex) || columnIndex > m_maxCellsInRow[rowIndex]) 0217 m_maxCellsInRow[rowIndex] = columnIndex; 0218 } 0219 return c; 0220 } 0221 0222 int maxRow() const { return m_maxRow; } 0223 int maxColumn() const { return m_maxColumn; } 0224 int maxCellsInRow(int rowIndex) const { return m_maxCellsInRow[rowIndex]; } 0225 0226 bool visible() const { return m_visible; } 0227 void setVisible(bool visible) { m_visible = visible; } 0228 0229 QString pictureBackgroundPath() const { return m_pictureBackgroundPath; } 0230 void setPictureBackgroundPath(const QString& path) { m_pictureBackgroundPath = path; } 0231 0232 private: 0233 QHash<int, Row*> m_rows; 0234 QHash<int, Column*> m_columns; 0235 QHash<unsigned, Cell*> m_cells; 0236 QHash<int, int> m_maxCellsInRow; 0237 QString m_pictureBackgroundPath; 0238 int m_maxRow; 0239 int m_maxColumn; 0240 bool m_visible : 1; 0241 }; 0242 0243 #endif