File indexing completed on 2024-12-08 12:56:10

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 "KoColumn.h"
0020 #include "KoColumnStyle.h"
0021 #include "KoCellStyle.h"
0022 
0023 #include <KoXmlWriter.h>
0024 
0025 #include <QString>
0026 
0027 namespace {
0028     class VisibilityMap : public QMap<KoColumn::Visibility, QString> {
0029     public:
0030         VisibilityMap()
0031         : QMap<KoColumn::Visibility, QString>()
0032         {
0033             insert(KoColumn::Collapse, "colapse");
0034             insert(KoColumn::Filter, "filter");
0035             insert(KoColumn::Visible, "visible");
0036         }
0037     } visibilityMap;
0038 }
0039 
0040 KoColumn::KoColumn()
0041 : m_defaultCellStyle(0)
0042 , m_style(0)
0043 , m_visibility(Visible)
0044 {
0045 }
0046 
0047 KoColumn::~KoColumn()
0048 {
0049 }
0050 
0051 void KoColumn::setStyle(KoColumnStyle::Ptr style)
0052 {
0053     m_style = style;
0054 }
0055 
0056 KoColumnStyle::Ptr KoColumn::style()
0057 {
0058     return m_style;
0059 }
0060 
0061 KoCellStyle::Ptr KoColumn::defualtCellStyle() const
0062 {
0063     return m_defaultCellStyle;
0064 }
0065 
0066 void KoColumn::setDefaultCellStyle(KoCellStyle::Ptr defaultStyle)
0067 {
0068     m_defaultCellStyle = defaultStyle;
0069 }
0070 
0071 void KoColumn::setVisibility(KoColumn::Visibility visibility)
0072 {
0073     m_visibility = visibility;
0074 }
0075 
0076 KoColumn::Visibility KoColumn::visibility()
0077 {
0078     return m_visibility;
0079 }
0080 
0081 void KoColumn::saveOdf(KoXmlWriter& writer, KoGenStyles& styles)
0082 {
0083     writer.startElement("table:table-column");
0084     if(m_style) {
0085         writer.addAttribute("table:style-name", m_style->saveOdf(styles));
0086     }
0087     if(m_defaultCellStyle) {
0088         writer.addAttribute("table:default-cell-style-name", m_defaultCellStyle->saveOdf(styles));
0089     }
0090     writer.addAttribute("table:visibility", visibilityMap.value(m_visibility));
0091     writer.endElement();//table:column
0092 }