File indexing completed on 2024-12-01 13:11:43

0001 /*
0002  *  Copyright (c) 2010 Carlos Licea <carlos@kdab.com>
0003  *
0004  *  This library is free software; you can redistribute it and/or modify
0005  *  it under the terms of the GNU Lesser General Public License as published
0006  *  by the Free Software Foundation; either version 2.1 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This library is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU Lesser General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU Lesser General Public License
0015  *  along with this program; if not, write to the Free Software
0016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017  */
0018 
0019 #ifndef KOCELL_H
0020 #define KOCELL_H
0021 
0022 #include "KoCellStyle.h"
0023 class KoCellChild;
0024 class KoCellValue;
0025 class KoTable;
0026 
0027 class KoXmlWriter;
0028 class KoGenStyles;
0029 
0030 #include "koodf2_export.h"
0031 
0032 #include <QList>
0033 
0034 /**
0035  * \class KoCell
0036  * @brief represents a cell inside a table.
0037  **/
0038 class KOODF2_EXPORT KoCell
0039 {
0040     friend class KoTable;
0041 
0042     KoCell();
0043     KoCell& operator=(KoCell&);
0044 
0045 public:
0046     ~KoCell();
0047 
0048     /**
0049      * Set the this Cell style to the given style.
0050      */
0051     void setStyle(KoCellStyle::Ptr style);
0052 
0053     /**
0054      * Returns the style assigned to this KoCell.
0055      * It's null if no style has been set.
0056      */
0057     KoCellStyle::Ptr style() const;
0058 
0059     /**
0060      * Sets the value as defined by element office:value of ODF.
0061      * \see ODF1.2 office:value §19.386.
0062      */
0063     void setValue(KoCellValue* value);
0064     KoCellValue* value() const;
0065 
0066     /**
0067      * A class KoCellChild represents all the items that can be
0068      * contained inside a KoCell.
0069      * \see ODF1.2 table:table-cell §9.1.4
0070      *
0071      * \note The cell takes ownership of the given KoCellChild.
0072      * \note The order in which the elements are written to ODF
0073      * is the same in which they were inserted.
0074      */
0075     void appendChild(KoCellChild* child);
0076 
0077     /**
0078      *  Deletes the old list of children in favor of this one.
0079      */
0080     void setChildren(QList<KoCellChild*> children);
0081 
0082     /**
0083      * Returns all the children appended to the cell.
0084      * \note the cell is still the owner of those objects
0085      */
0086     QList<KoCellChild*> children() const;
0087 
0088     /**
0089      * \brief Sets the row span of the cell.
0090      * By default the span is 1.
0091      * Negative spans are not allowed, they are converted back to 1.
0092      *
0093      * \note the span is not checked to ensure not overlaping.
0094      * Also the covered cells can also be populated with data.
0095      */
0096     void setRowSpan(int span);
0097 
0098     /**
0099      * Gets the row span of the cell.
0100      * \see ODF1.2 table:number-rows-spanned §19.680
0101      */
0102     int rowSpan() const;
0103 
0104     /**
0105      * \brief Sets the column span of the cell.
0106      * By default the span is 1.
0107      * Negative spans are not allowed, they are converted back to 1.
0108      *
0109      * \note the span is not checked to ensure not overlaping.
0110      * Also the covered cells can also be populated with data.
0111      */
0112     void setColumnSpan(int span);
0113 
0114     /**
0115      * Gets the column span of the cell.
0116      * \see ODF1.2 table:number-columns-spanned §19.681
0117      */
0118     int columnSpan() const;
0119 
0120     /**
0121      * \brief Sets this cell to be <table:covered-table-cell>
0122      */
0123     void setCovered(bool covered);
0124 
0125     /**
0126      * Returns if the cell is covered or not.
0127      */
0128     bool isCovered() const;
0129 
0130     /**
0131      * Sets if the cell is protected. Protected cells cannot be edited by the user.
0132      */
0133     void setProtected(bool protect);
0134 
0135     /**
0136      * Returns if the cell is protected or not.
0137      * \see ODF1.2 table:protected §19.698.5
0138      */
0139     bool isProtected() const;
0140 
0141 private:
0142     void saveOdf(KoXmlWriter& writer, KoGenStyles& styles);
0143 
0144     QList<KoCellChild*> m_children;
0145     KoCellValue* m_value;
0146     KoCellStyle::Ptr m_style;
0147 
0148     int m_rowSpan;
0149     int m_columnSpan;
0150     bool m_protected;
0151     bool m_covered;
0152 };
0153 
0154 #endif