File indexing completed on 2024-05-12 16:29:16

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 #include "KoCell.h"
0020 #include "KoDummyCellValue.h"
0021 #include "KoCellChild.h"
0022 #include "KoCellStyle.h"
0023 
0024 #include <KoXmlWriter.h>
0025 
0026 KoCell::KoCell()
0027 : m_value(new KoDummyCellValue)
0028 , m_style(0)
0029 , m_rowSpan(1)
0030 , m_columnSpan(1)
0031 , m_protected(false)
0032 , m_covered(false)
0033 {
0034 }
0035 
0036 KoCell::~KoCell()
0037 {
0038     delete m_value;
0039     qDeleteAll(m_children);
0040 }
0041 
0042 void KoCell::saveOdf(KoXmlWriter& writer, KoGenStyles& styles)
0043 {
0044     if (m_covered) {
0045         writer.startElement("table:covered-table-cell");
0046         writer.endElement(); // table:covered-table-cell
0047     }
0048     else {
0049         writer.startElement("table:table-cell");
0050         m_value->saveOdf(writer);
0051         if(m_style) {
0052             writer.addAttribute("table:style-name", m_style->saveOdf(styles));
0053         }
0054         if(m_columnSpan > 1) {
0055             writer.addAttribute("table:number-columns-spanned", m_columnSpan);
0056         }
0057         if(m_rowSpan > 1) {
0058             writer.addAttribute("table:number-rows-spanned", m_rowSpan);
0059         }
0060         writer.addAttribute("table:protected", m_protected? "true" : "false" );
0061 
0062         foreach(KoCellChild* child, m_children){
0063             child->saveOdf(writer, styles);
0064         }
0065 
0066         writer.endElement();//table:table-cell
0067     }
0068 }
0069 
0070 KoCellValue* KoCell::value() const
0071 {
0072     return m_value;
0073 }
0074 
0075 void KoCell::setValue(KoCellValue* value)
0076 {
0077     delete m_value;
0078     m_value = value;
0079 }
0080 
0081 KoCellStyle::Ptr KoCell::style() const
0082 {
0083     return m_style;
0084 }
0085 
0086 void KoCell::setStyle(KoCellStyle::Ptr style)
0087 {
0088     m_style = style;
0089 }
0090 
0091 QList< KoCellChild* > KoCell::children() const
0092 {
0093     return m_children;
0094 }
0095 
0096 void KoCell::setChildren(QList< KoCellChild* > children)
0097 {
0098     qDeleteAll(m_children);
0099     m_children = children;
0100 }
0101 
0102 void KoCell::appendChild(KoCellChild* child)
0103 {
0104     m_children.append(child);
0105 }
0106 
0107 int KoCell::columnSpan() const
0108 {
0109     return m_columnSpan;
0110 }
0111 
0112 void KoCell::setColumnSpan(int span)
0113 {
0114     m_columnSpan = qMax(1, span);
0115 }
0116 
0117 int KoCell::rowSpan() const
0118 {
0119     return m_rowSpan;
0120 }
0121 
0122 void KoCell::setRowSpan(int span)
0123 {
0124     m_rowSpan = qMax(1, span);
0125 }
0126 
0127 bool KoCell::isProtected() const
0128 {
0129     return m_protected;
0130 }
0131 
0132 bool KoCell::isCovered() const
0133 {
0134     return m_covered;
0135 }
0136 
0137 void KoCell::setCovered(bool covered)
0138 {
0139     m_covered = covered;
0140 }
0141 
0142 void KoCell::setProtected(bool protect)
0143 {
0144     m_protected = protect;
0145 }