Debian Codegraph @

src/lib/WPSTable.h

raw symbols SCIP
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 ([email protected])
11 * Copyright (C) 2006, 2007 Andrew Ziem
12 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
13 * Copyright (C) 2004 Marc Maurer ([email protected])
14 * Copyright (C) 2003-2005 William Lachance ([email protected])
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:
42 //! constructor
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 //! add to the propList
52 void addTo(librevenge::RVNGPropertyList &propList) const;
53 /** a comparison function
54 \note this comparison function does ignore m_numRepeat
55 */
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 //! operator==
66 bool operator==(WPSColumnFormat const &col) const
67 {
68 return compare(col)==0;
69 }
70 //! operator!=
71 bool operator!=(WPSColumnFormat const &col) const
72 {
73 return compare(col)!=0;
74 }
75 //! operator<
76 bool operator<(WPSColumnFormat const &col) const
77 {
78 return compare(col)<0;
79 }
80 //! operator<<
81 friend std::ostream &operator<<(std::ostream &o, WPSColumnFormat const &col);
82
83 //! the column width, if known
84 float m_width;
85 //! a flag to know if the width is in percent (or in point)
86 bool m_isPercentWidth;
87 //! a flag to know if we need to see use-optimal column width
88 bool m_useOptimalWidth;
89 //! a flag to know if the column is a header column
90 bool m_isHeader;
91 //! the number times a column is repeated
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:
103 //! constructor
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 //! add to the propList
112 void addTo(librevenge::RVNGPropertyList &propList) const;
113 //! a comparison function
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 //! operator==
124 bool operator==(WPSRowFormat const &row) const
125 {
126 return compare(row)==0;
127 }
128 //! operator!=
129 bool operator!=(WPSRowFormat const &row) const
130 {
131 return compare(row)!=0;
132 }
133 //! operator<
134 bool operator<(WPSRowFormat const &row) const
135 {
136 return compare(row)<0;
137 }
138 //! operator<<
139 friend std::ostream &operator<<(std::ostream &o, WPSRowFormat const &row);
140
141 //! the row height, if known
142 float m_height;
143 //! a flag to know if the height is only a minimum
144 bool m_isMinimalHeight;
145 //! a flag to know if we need to see use-optimal row height
146 bool m_useOptimalHeight;
147 //! a flag to know if the row is a header row
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:
159 //! the constructor
160 WPSTable()
161 : m_cellsList()
162 , m_rowsSize()
163 , m_colsSize() {}
164 WPSTable &operator=(WPSTable const &)=default;
165 //! the destructor
166 virtual ~WPSTable();
167
168 //! add a new cells
169 void add(WPSCellPtr &cell);
170
171 //! returns the number of cell
172 int numCells() const
173 {
174 return int(m_cellsList.size());
175 }
176 //! returns the i^th cell
177 WPSCellPtr getCell(int id);
178
179 /** try to send the table
180
181 Note: either send the table ( and returns true ) or do nothing.
182 */
183 bool sendTable(WPSContentListenerPtr listener);
184
185 /** try to send the table as basic text */
186 bool sendAsText(WPSContentListenerPtr listener);
187
188 protected:
189 //! create the correspondance list, ...
190 bool buildStructures();
191
192 /** the list of cells */
193 std::vector<WPSCellPtr> m_cellsList;
194 /** the final row and col size (in point) */
195 std::vector<float> m_rowsSize, m_colsSize;
196 };
197
198 #endif
199 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */