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  */
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  }
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  }
66  bool operator==(WPSColumnFormat const &col) const
67  {
68  return compare(col)==0;
69  }
71  bool operator!=(WPSColumnFormat const &col) const
72  {
73  return compare(col)!=0;
74  }
76  bool operator<(WPSColumnFormat const &col) const
77  {
78  return compare(col)<0;
79  }
81  friend std::ostream &operator<<(std::ostream &o, WPSColumnFormat const &col);
82 
84  float m_width;
90  bool m_isHeader;
93 };
94 
95 /*
96  * Structure to store the row properties
97  *
98  * \note use only to define sheet properties, to be changed
99  */
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  }
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  }
124  bool operator==(WPSRowFormat const &row) const
125  {
126  return compare(row)==0;
127  }
129  bool operator!=(WPSRowFormat const &row) const
130  {
131  return compare(row)!=0;
132  }
134  bool operator<(WPSRowFormat const &row) const
135  {
136  return compare(row)<0;
137  }
139  friend std::ostream &operator<<(std::ostream &o, WPSRowFormat const &row);
140 
142  float m_height;
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:
161 
163  virtual ~WPSTable();
164 
166  void add(WPSCellPtr &cell);
167 
169  int numCells() const
170  {
171  return int(m_cellsList.size());
172  }
174  WPSCellPtr getCell(int id);
175 
180  bool sendTable(WPSContentListenerPtr listener);
181 
183  bool sendAsText(WPSContentListenerPtr listener);
184 
185 protected:
187  bool buildStructures();
188 
190  std::vector<WPSCellPtr> m_cellsList;
192  std::vector<float> m_rowsSize, m_colsSize;
193 };
194 
195 #endif
196 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
shared_ptr< WPSContentListener > WPSContentListenerPtr
shared pointer to WPSContentListener
Definition: libwps_internal.h:122
virtual ~WPSTable()
the destructor
Definition: WPSTable.cpp:101
bool m_isPercentWidth
a flag to know if the width is in percent (or in point)
Definition: WPSTable.h:86
bool operator==(WPSColumnFormat const &col) const
operator==
Definition: WPSTable.h:66
bool m_isHeader
a flag to know if the column is a header column
Definition: WPSTable.h:90
std::vector< WPSCellPtr > m_cellsList
the list of cells
Definition: WPSTable.h:190
bool buildStructures()
create the correspondance list, ...
Definition: WPSTable.cpp:122
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSTable.cpp:85
float m_width
the column width, if known
Definition: WPSTable.h:84
friend std::ostream & operator<<(std::ostream &o, WPSColumnFormat const &col)
operator<<
Definition: WPSTable.cpp:42
std::vector< float > m_colsSize
Definition: WPSTable.h:192
WPSCellPtr getCell(int id)
returns the i^th cell
Definition: WPSTable.cpp:110
std::vector< float > m_rowsSize
the final row and col size (in point)
Definition: WPSTable.h:192
int numCells() const
returns the number of cell
Definition: WPSTable.h:169
int m_numRepeat
the number times a column is repeated
Definition: WPSTable.h:92
bool operator==(WPSRowFormat const &row) const
operator==
Definition: WPSTable.h:124
bool operator<(WPSColumnFormat const &col) const
operator<
Definition: WPSTable.h:76
void addTo(librevenge::RVNGPropertyList &propList) const
add to the propList
Definition: WPSTable.cpp:57
Definition: WPSTable.h:39
int compare(WPSColumnFormat const &col) const
a comparison function
Definition: WPSTable.h:56
WPSRowFormat(float height=-1)
constructor
Definition: WPSTable.h:104
bool sendAsText(WPSContentListenerPtr listener)
try to send the table as basic text
Definition: WPSTable.cpp:316
WPSTable()
the constructor
Definition: WPSTable.h:160
bool m_useOptimalHeight
a flag to know if we need to see use-optimal row height
Definition: WPSTable.h:146
bool m_useOptimalWidth
a flag to know if we need to see use-optimal column width
Definition: WPSTable.h:88
bool operator<(WPSRowFormat const &row) const
operator<
Definition: WPSTable.h:134
bool m_isHeader
a flag to know if the row is a header row
Definition: WPSTable.h:148
bool operator!=(WPSRowFormat const &row) const
operator!=
Definition: WPSTable.h:129
int compare(WPSRowFormat const &row) const
a comparison function
Definition: WPSTable.h:114
WPSColumnFormat(float width=-1)
constructor
Definition: WPSTable.h:43
bool sendTable(WPSContentListenerPtr listener)
try to send the table
Definition: WPSTable.cpp:243
Definition: WPSTable.h:156
bool operator!=(WPSColumnFormat const &col) const
operator!=
Definition: WPSTable.h:71
void add(WPSCellPtr &cell)
add a new cells
Definition: WPSTable.cpp:105
float m_height
the row height, if known
Definition: WPSTable.h:142
shared_ptr< WPSCell > WPSCellPtr
shared pointer to WPSCell
Definition: libwps_internal.h:115
bool m_isMinimalHeight
a flag to know if the height is only a minimum
Definition: WPSTable.h:144
Definition: WPSTable.h:100
friend std::ostream & operator<<(std::ostream &o, WPSRowFormat const &row)
operator<<
Definition: WPSTable.cpp:71

Generated on Sat Jul 29 2017 15:32:22 for libwps by doxygen 1.8.8