kspread

region.h
1/* This file is part of the KDE project
2 Copyright (C) 2005-2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19
20#ifndef KSPREAD_REGION
21#define KSPREAD_REGION
22
23#include <tqrect.h>
24#include <tqstring.h>
25#include <tqvaluelist.h>
26
27#include <kdebug.h>
28
29#include <koffice_export.h>
30
31#include "kspread_global.h"
32#include "kspread_util.h"
33
34namespace KSpread
35{
36class Manipulator;
37class Sheet;
38class View;
39
43class KSPREAD_EXPORT Region
44{
45protected:
46 class Element;
47 class Point;
48 class Range;
49
50public:
55 Region();
56
63 Region(const TQPoint& point, Sheet* sheet = 0);
64
71 Region(const TQRect& range, Sheet* sheet = 0);
72
80 Region(View* view, const TQString& strRegion, Sheet* sheet = 0);
81
87 Region(const Region& region);
88
96 Region(int col, int row, Sheet* sheet = 0);
97
107 Region(int col, int row, int width, int height, Sheet* sheet = 0);
108
112 virtual ~Region();
113
114
115
120 TQString name(Sheet* originSheet = 0) const;
121
127 Sheet* filterSheetName(TQString& sRegion);
128
129
130
134 bool isEmpty() const;
135
139 bool isSingular() const;
140
144 bool isContiguous() const;
145
149 bool isValid() const;
150
156 bool isColumnSelected(uint col = 0) const;
157
163 bool isRowSelected(uint row = 0) const;
164
168 bool isColumnOrRowSelected() const;
169
174 bool isColumnAffected(uint col) const;
175
180 bool isRowAffected(uint row) const;
181
187 bool contains(const TQPoint& point, Sheet* sheet = 0) const;
188
189
190
191 /* TODO Stefan #2: Optimize! Adjacent Points/Ranges */
197 Element* add(const TQPoint& point, Sheet* sheet = 0);
203 Element* add(const TQRect& range, Sheet* sheet = 0);
208 Element* add(const Region& region);
209
210 /* TODO Stefan #3: Improve! */
215 void sub(const TQPoint& point);
220 void sub(const TQRect& range);
225 void sub(const Region& region);
226
231 virtual Element* eor(const TQPoint& point, Sheet* sheet = 0);
232
236 virtual void clear();
237
238
239
240 TQRect boundingRect() const;
241
242
243
248 bool operator==(const Region& region) const;
249
253 void operator=(const Region& region);
254
255
256
260 View* view() const;
261
265 void setView(View*);
266
267
268 typedef TQValueList<Element*>::Iterator Iterator;
269 typedef TQValueList<Element*>::ConstIterator ConstIterator;
270
271 ConstIterator constBegin() const;
272 ConstIterator constEnd() const;
273
274protected:
278 TQValueList<Element*>& cells() const;
279
288 Iterator insert(Iterator iterator, const TQPoint& point, Sheet*, bool multi = true);
297 Iterator insert(Iterator iterator, const TQRect& range, Sheet*, bool multi = true);
298
299 virtual Point* createPoint(const TQPoint&) const;
300 virtual Point* createPoint(const TQString&) const;
301 virtual Point* createPoint(const Point&) const;
302 virtual Range* createRange(const TQRect&) const;
303 virtual Range* createRange(const TQString&) const;
304 virtual Range* createRange(const Range&) const;
305
306private:
307 class Private;
308 Private *d;
309};
310
311
312/***************************************************************************
313 class Region::Element
314****************************************************************************/
325{
326public:
327 enum Type { Undefined, Point, Range };
328
329 Element();
330 virtual ~Element();
331
332 virtual Type type() const { return Undefined; }
333 virtual bool isValid() const { return false; }
334 virtual bool isColumn() const { return false; }
335 virtual bool isRow() const { return false; }
336
337 virtual bool contains(const TQPoint&) const { return false; }
338 virtual bool contains(const TQRect&) const { return false; }
339
340 virtual TQString name(Sheet* = 0) const { return TQString(""); }
341 virtual TQRect rect() const { return TQRect(); }
342 virtual const TQColor& color() const { return TQt::black; }
343
344 Sheet* sheet() const { return m_sheet; }
345 void setSheet(Sheet* sheet) { m_sheet = sheet; }
346
347protected:
348 /* TODO Stefan #6:
349 Elaborate, if this pointer could be avoided by TQDict or whatever in
350 Region.
351 */
352 Sheet* m_sheet;
353};
354
355
356/***************************************************************************
357 class Region::Point
358****************************************************************************/
359
371{
372public:
373 Point(const TQPoint&);
374 Point(const TQString&);
375 virtual ~Point();
376
377 virtual Type type() const { return Element::Point; }
378 virtual bool isValid() const { return (!m_point.isNull() && util_isPointValid(pos())); }
379 virtual bool isColumn() const { return false; }
380 virtual bool isRow() const { return false; }
381
382 virtual bool contains(const TQPoint&) const;
383 virtual bool contains(const TQRect&) const;
384
385 virtual TQString name(Sheet* originSheet = 0) const;
386
387 virtual TQRect rect() const { return TQRect(m_point,m_point); }
388
389 TQPoint pos() const { return m_point; }
390
391private:
392 TQPoint m_point;
393};
394
395
396/***************************************************************************
397 class Region:.Range
398****************************************************************************/
399
411{
412public:
413 Range(const TQRect&);
414 Range(const TQString&);
415 virtual ~Range();
416
417 virtual Type type() const { return Element::Range; }
418 virtual bool isValid() const { return !m_range.isNull() && util_isRectValid(rect()); }
419 virtual bool isColumn() const { return (m_range.normalize().top() == 1 && m_range.normalize().bottom() == KS_rowMax); }
420 virtual bool isRow() const { return (m_range.normalize().left() == 1 && m_range.normalize().right() == KS_colMax); }
421
422 virtual bool contains(const TQPoint&) const;
423 virtual bool contains(const TQRect&) const;
424
425 virtual TQString name(Sheet* originSheet = 0) const;
426
427 virtual TQRect rect() const { return m_range; }
428
429 int width() const;
430 int height() const;
431
432private:
433 TQRect m_range;
434};
435
436} // namespace KSpread
437
438
439/***************************************************************************
440 kdDebug support
441****************************************************************************/
442
443inline kdbgstream operator<<( kdbgstream str, const KSpread::Region& r )
444{
445 str << "Region = " << r.name();
446 return str;
447}
448
449#endif // KSPREAD_REGION
Base class for region elements, which can be points or ranges.
Definition region.h:325
A point in a region.
Definition region.h:371
A range in a region.
Definition region.h:411
The one for all class for points and ranges.
Definition region.h:44
TQString name(Sheet *originSheet=0) const
Definition region.cpp:233
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39