kspread

kspread_util.h
1/* This file is part of the KDE project
2 Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __kspread_util_h__
22#define __kspread_util_h__
23
24#include <tqstring.h>
25#include <tqrect.h>
26#include <tqdatetime.h>
27
28#include <koffice_export.h>
29
30#include "kspread_global.h"
31#include "kspread_value.h"
32
33class TQFont;
34class TQPen;
35class TQDomElement;
36class TQDomDocument;
37
38class TDELocale;
39
40bool util_isPointValid(TQPoint point);
41bool util_isRectValid(TQRect rect);
42
43namespace KSpread
44{
45class Cell;
46class Map;
47class Sheet;
48
54class KSPREAD_EXPORT Point
55{
56public:
57 Point() { _pos.setX( -1 ); _sheet = 0; _columnFixed = false; _rowFixed = false; }
58 Point( const TQString& );
59 Point( const TQString&, Map*, Sheet* default_sheet = 0 );
60 Point( const Point& c ) {
61 _pos = c._pos;
62 _sheet = c._sheet;
63 _sheetName = c._sheetName;
64 _columnFixed = c._columnFixed;
65 _rowFixed = c._rowFixed;
66 }
67
68 bool isValid() const { return ( util_isPointValid(pos()) && ( _sheet != 0 || _sheetName.isEmpty() ) ); }
69 bool isSheetKnown() const { return ( ! _sheetName.isEmpty() && _sheet != 0 ); }
70
71 Cell* cell() const;
72
73 bool operator== (const Point &cell) const;
74 bool operator< (const Point &cell) const;
75
76 int row () const { return _pos.y(); };
77 int column () const { return _pos.x(); };
78 void setRow (int r) { _pos.setY (r); };
79 void setColumn (int c) { _pos.setX (c); };
80
84 void setSheet(Sheet* sheet);
85 Sheet* sheet() const;
86
90 void setSheetName(TQString name);
91 TQString sheetName() const;
92
96 void setPos(TQPoint pos);
97 TQPoint pos() const;
98
103 void setColumnFixed(bool colFixed);
104 bool columnFixed() const;
105
109 void setRowFixed(bool rowFixed);
110 bool rowFixed() const;
111
112
113private:
114 Sheet* _sheet;
115 TQString _sheetName;
116 TQPoint _pos;
117 bool _columnFixed;
118 bool _rowFixed;
119
120private:
121 void init( const TQString& );
122};
123
130class KSPREAD_EXPORT Range
131{
132public:
133 Range();
134
135 Range( const TQString& );
136 Range( const TQString&, Map*, Sheet* default_sheet = 0 );
137 Range( const Range& r );
138 Range( const Point& ul, const Point& lr );
139
148 bool isValid() const;
149
151 bool isSheetKnown() const { return ( !sheetName().isEmpty() && sheet() != 0 ); }
152
154 void getStartPoint(Point* pt);
156 void getEndPoint(Point* pt);
157
158 int startRow () const { return range().top(); };
159 int startCol () const { return range().left(); };
160 int endRow () const { return range().bottom(); };
161 int endCol () const { return range().right(); };
162
167 virtual void setRange(const TQRect& newRange) {_range=newRange;}
168
169 void setRange(int newStartCol, int newStartRow, int newEndCol, int newEndRow)
170 { _range=TQRect(newStartCol,newStartRow,newEndCol-newStartCol,newEndRow-newStartRow); }
171
173 TQRect range() const;
174
176 bool contains (const Point &cell) const;
181 bool intersects (const Range &r) const;
182
188 TQString toString() const;
189
191 void setLeftFixed(bool fixed);
192 bool leftFixed() const;
193
195 void setRightFixed(bool fixed);
196 bool rightFixed() const;
197
199 void setTopFixed(bool fixed);
200 bool topFixed() const;
201
203 void setBottomFixed(bool fixed);
204 bool bottomFixed() const;
205
207 void setSheet(Sheet* sheet);
208 Sheet* sheet() const;
209
211 void setSheetName(TQString sheetName);
212 TQString sheetName() const;
213
218 TQString namedArea() const;
219
223 bool operator==(const Range& range) const;
224
225
226private:
227 Sheet* _sheet;
228 TQString _sheetName;
229 TQString _namedArea;
230 TQRect _range;
231 bool _leftFixed;
232 bool _rightFixed;
233 bool _topFixed;
234 bool _bottomFixed;
235};
236
244struct RangeList {
245 TQValueList<Point> cells;
246 TQValueList<Range> ranges;
247};
248
249
257{
258public:
263 RangeIterator(TQRect _range, Sheet* _sheet);
265
269 Cell* first();
270
275 Cell* next();
276private:
277
278 TQRect range;
279 Sheet* sheet;
280 TQPoint current;
281};
282
283//helper functions for the formatting
284bool formatIsDate (FormatType fmt);
285bool formatIsTime (FormatType fmt);
286bool formatIsFraction (FormatType fmt);
287
288
289
290KSPREAD_EXPORT TQString util_rangeName( const TQRect &_area );
291KSPREAD_EXPORT TQString util_rangeName( Sheet *_sheet, const TQRect &_area );
292TQString util_rangeColumnName( const TQRect &_area);
293TQString util_rangeRowName( const TQRect &_area);
294
299KSPREAD_EXPORT int util_decodeColumnLabelText( const TQString &_col );
304KSPREAD_EXPORT TQString util_encodeColumnLabelText( int column );
305
306bool util_isAllSelected(const TQRect &selection);
307bool util_isColumnSelected(const TQRect &selection);
308bool util_isRowSelected(const TQRect &selection);
309bool util_isRowOrColumnSelected( const TQRect &selection );
310
311
312
313bool util_validateSheetName(const TQString &name);
314
315TQDomElement util_createElement( const TQString & tagName, const TQFont & font, TQDomDocument & doc );
316TQDomElement util_createElement( const TQString & tagname, const TQPen & pen, TQDomDocument & doc );
317TQFont util_toFont( TQDomElement & element );
318TQPen util_toPen( TQDomElement & element );
319int util_penCompare( TQPen const & pen1, TQPen const & pen2 );
320
321TQString convertRefToRange( const TQString & sheet, const TQRect & rect );
322TQString convertRefToBase( const TQString & sheet, const TQRect & rect );
323TQString convertRangeToRef( const TQString & sheetName, const TQRect & _area );
324
325void insertBracket( TQString & s );
326TQString convertOasisPenToString( const TQPen & pen );
327TQPen convertOasisStringToPen( const TQString &str );
328
329//Return true when it's a reference to cell from sheet.
330KSPREAD_EXPORT bool localReferenceAnchor( const TQString &_ref );
331
332
333
334namespace Oasis
335{
342 // TODO check visibility
343 KSPREAD_EXPORT TQString decodeFormula(const TQString& expr, const TDELocale* locale = 0);
350 KSPREAD_EXPORT TQString encodeFormula(const TQString& expr, const TDELocale* locale = 0);
351}
352
353} // namespace KSpread
354
355#endif
For every cell in the spread sheet there is a Cell object.
A map is a simple container for all sheets.
Definition kspread_map.h:59
Represents the position of a single cell in a workbook.
Represents a region within a workbook.
bool isSheetKnown() const
Returns true if this range has an associated Sheet or false otherwise.
virtual void setRange(const TQRect &newRange)
Changes the area on the spreadsheet represented by this range.
The KSpread namespace.
Definition commands.h:39
KSPREAD_EXPORT int util_decodeColumnLabelText(const TQString &_col)
Call this function to decode the text of a column label to an integer i.e.
KSPREAD_EXPORT TQString util_encodeColumnLabelText(int column)
Call this function to encode an integer to the text of the column label i.e.
range-list and cell-list TODO: move to a separate file, improve structure, add iterators and all that...