WPSTable.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2/* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
11 * Copyright (C) 2006, 2007 Andrew Ziem
12 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13 * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
14 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
15 *
16 * For minor contributions see the git repository.
17 *
18 * Alternatively, the contents of this file may be used under the terms
19 * of the GNU Lesser General Public License Version 2.1 or later
20 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21 * applicable instead of those above.
22 *
23 * For further information visit http://libwps.sourceforge.net
24 */
25
26#ifndef WPS_TABLE
27# define WPS_TABLE
28
29#include <iostream>
30#include <vector>
31
32#include "libwps_internal.h"
33
34/*
35 * Structure to store the column properties
36 *
37 * \note use only to define sheet properties, to be changed
38 */
39 struct WPSColumnFormat
40{
41 public:
43 explicit WPSColumnFormat(float width=-1)
44 : m_width(width)
45 , m_isPercentWidth(false)
46 , m_useOptimalWidth(false)
47 , m_isHeader(false)
48 , m_numRepeat(1)
49 {
50 }
51
52 void addTo(librevenge::RVNGPropertyList &propList) const;
56 int compare(WPSColumnFormat const &col) const
57 {
58 if (m_width<col.m_width) return 1;
59 if (m_width>col.m_width) return -1;
60 if (m_isPercentWidth!=col.m_isPercentWidth) return m_isPercentWidth ? 1 : -1;
61 if (m_useOptimalWidth!=col.m_useOptimalWidth) return m_useOptimalWidth ? 1 : -1;
62 if (m_isHeader!=col.m_isHeader) return m_isHeader ? 1 : -1;
63 return 0;
64 }
65
66 bool operator==(WPSColumnFormat const &col) const
67 {
68 return compare(col)==0;
69 }
70
71 bool operator!=(WPSColumnFormat const &col) const
72 {
73 return compare(col)!=0;
74 }
75
76 bool operator<(WPSColumnFormat const &col) const
77 {
78 return compare(col)<0;
79 }
80
81 friend std::ostream &operator<<(std::ostream &o, WPSColumnFormat const &col);
82
84 float m_width;
86 bool m_isPercentWidth;
88 bool m_useOptimalWidth;
90 bool m_isHeader;
92 int m_numRepeat;
93};
94
95/*
96 * Structure to store the row properties
97 *
98 * \note use only to define sheet properties, to be changed
99 */
100 struct WPSRowFormat
101{
102 public:
104 explicit WPSRowFormat(float height=-1)
105 : m_height(height)
106 , m_isMinimalHeight(false)
107 , m_useOptimalHeight(false)
108 , m_isHeader(false)
109 {
110 }
111
112 void addTo(librevenge::RVNGPropertyList &propList) const;
114 int compare(WPSRowFormat const &row) const
115 {
116 if (m_height<row.m_height) return 1;
117 if (m_height>row.m_height) return -1;
118 if (m_isMinimalHeight!=row.m_isMinimalHeight) return m_isMinimalHeight ? 1 : -1;
119 if (m_useOptimalHeight!=row.m_useOptimalHeight) return m_useOptimalHeight ? 1 : -1;
120 if (m_isHeader!=row.m_isHeader) return m_isHeader ? 1 : -1;
121 return 0;
122 }
123
124 bool operator==(WPSRowFormat const &row) const
125 {
126 return compare(row)==0;
127 }
128
129 bool operator!=(WPSRowFormat const &row) const
130 {
131 return compare(row)!=0;
132 }
133
134 bool operator<(WPSRowFormat const &row) const
135 {
136 return compare(row)<0;
137 }
138
139 friend std::ostream &operator<<(std::ostream &o, WPSRowFormat const &row);
140
142 float m_height;
144 bool m_isMinimalHeight;
146 bool m_useOptimalHeight;
148 bool m_isHeader;
149};
150
151/*
152 * Structure to store and construct a table from an unstructured list
153 * of cell
154 *
155 */
156 class WPSTable
157{
158 public:
160 WPSTable()
161 : m_cellsList()
162 , m_rowsSize()
163 , m_colsSize() {}
164 WPSTable &operator=(WPSTable const &)=default;
166 virtual ~WPSTable();
167
169 void add(WPSCellPtr &cell);
170
172 int numCells() const
173 {
174 return int(m_cellsList.size());
175 }
176
177 WPSCellPtr getCell(int id);
178
183 bool sendTable(WPSContentListenerPtr listener);
184
186 bool sendAsText(WPSContentListenerPtr listener);
187
188 protected:
190 bool buildStructures();
191
193 std::vector<WPSCellPtr> m_cellsList;
195 std::vector<float> m_rowsSize, m_colsSize;
196};
197
198#endif
199/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSTable::getCell
WPSCellPtr getCell(int id)
returns the i^th cell
Definition WPSTable.cpp:110
WPSTable::sendAsText
bool sendAsText(WPSContentListenerPtr listener)
try to send the table as basic text
Definition WPSTable.cpp:314
WPSTable::WPSTable
WPSTable()
the constructor
Definition WPSTable.h:160
WPSTable::add
void add(WPSCellPtr &cell)
add a new cells
Definition WPSTable.cpp:105
WPSTable::sendTable
bool sendTable(WPSContentListenerPtr listener)
try to send the table
Definition WPSTable.cpp:241
WPSTable::numCells
int numCells() const
returns the number of cell
Definition WPSTable.h:172
WPSTable::buildStructures
bool buildStructures()
create the correspondance list, ...
Definition WPSTable.cpp:122
WPSTable::m_colsSize
std::vector< float > m_colsSize
Definition WPSTable.h:195
WPSTable::m_rowsSize
std::vector< float > m_rowsSize
the final row and col size (in point)
Definition WPSTable.h:195
WPSTable::operator=
WPSTable & operator=(WPSTable const &)=default
WPSTable::m_cellsList
std::vector< WPSCellPtr > m_cellsList
the list of cells
Definition WPSTable.h:193
WPSTable::~WPSTable
virtual ~WPSTable()
the destructor
Definition WPSTable.cpp:101
libwps_internal.h
WPSCellPtr
std::shared_ptr< WPSCell > WPSCellPtr
shared pointer to WPSCell
Definition libwps_internal.h:103
WPSContentListenerPtr
std::shared_ptr< WPSContentListener > WPSContentListenerPtr
shared pointer to WPSContentListener
Definition libwps_internal.h:107
WPSColumnFormat
Definition WPSTable.h:40
WPSColumnFormat::operator==
bool operator==(WPSColumnFormat const &col) const
operator==
Definition WPSTable.h:66
WPSColumnFormat::m_useOptimalWidth
bool m_useOptimalWidth
a flag to know if we need to see use-optimal column width
Definition WPSTable.h:88
WPSColumnFormat::m_width
float m_width
the column width, if known
Definition WPSTable.h:84
WPSColumnFormat::m_isPercentWidth
bool m_isPercentWidth
a flag to know if the width is in percent (or in point)
Definition WPSTable.h:86
WPSColumnFormat::operator!=
bool operator!=(WPSColumnFormat const &col) const
operator!=
Definition WPSTable.h:71
WPSColumnFormat::operator<
bool operator<(WPSColumnFormat const &col) const
operator<
Definition WPSTable.h:76
WPSColumnFormat::m_isHeader
bool m_isHeader
a flag to know if the column is a header column
Definition WPSTable.h:90
WPSColumnFormat::m_numRepeat
int m_numRepeat
the number times a column is repeated
Definition WPSTable.h:92
WPSColumnFormat::WPSColumnFormat
WPSColumnFormat(float width=-1)
constructor
Definition WPSTable.h:43
WPSColumnFormat::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition WPSTable.cpp:57
WPSColumnFormat::compare
int compare(WPSColumnFormat const &col) const
a comparison function
Definition WPSTable.h:56
WPSColumnFormat::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSColumnFormat const &col)
operator<<
Definition WPSTable.cpp:42
WPSRowFormat
Definition WPSTable.h:101
WPSRowFormat::operator!=
bool operator!=(WPSRowFormat const &row) const
operator!=
Definition WPSTable.h:129
WPSRowFormat::operator<<
friend std::ostream & operator<<(std::ostream &o, WPSRowFormat const &row)
operator<<
Definition WPSTable.cpp:71
WPSRowFormat::WPSRowFormat
WPSRowFormat(float height=-1)
constructor
Definition WPSTable.h:104
WPSRowFormat::operator==
bool operator==(WPSRowFormat const &row) const
operator==
Definition WPSTable.h:124
WPSRowFormat::m_useOptimalHeight
bool m_useOptimalHeight
a flag to know if we need to see use-optimal row height
Definition WPSTable.h:146
WPSRowFormat::compare
int compare(WPSRowFormat const &row) const
a comparison function
Definition WPSTable.h:114
WPSRowFormat::addTo
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition WPSTable.cpp:85
WPSRowFormat::m_height
float m_height
the row height, if known
Definition WPSTable.h:142
WPSRowFormat::operator<
bool operator<(WPSRowFormat const &row) const
operator<
Definition WPSTable.h:134
WPSRowFormat::m_isHeader
bool m_isHeader
a flag to know if the row is a header row
Definition WPSTable.h:148
WPSRowFormat::m_isMinimalHeight
bool m_isMinimalHeight
a flag to know if the height is only a minimum
Definition WPSTable.h:144