kspread

region.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005-2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 */
00018 
00019 
00020 #ifndef KSPREAD_REGION
00021 #define KSPREAD_REGION
00022 
00023 #include <qrect.h>
00024 #include <qstring.h>
00025 #include <qvaluelist.h>
00026 
00027 #include <kdebug.h>
00028 
00029 #include <koffice_export.h>
00030 
00031 #include "kspread_global.h"
00032 #include "kspread_util.h"
00033 
00034 namespace KSpread
00035 {
00036 class Manipulator;
00037 class Sheet;
00038 class View;
00039 
00043 class KSPREAD_EXPORT Region
00044 {
00045 protected:
00046   class Element;
00047   class Point;
00048   class Range;
00049 
00050 public:
00055   Region();
00056 
00063   Region(const QPoint& point, Sheet* sheet = 0);
00064 
00071   Region(const QRect& range, Sheet* sheet = 0);
00072 
00080   Region(View* view, const QString& strRegion, Sheet* sheet = 0);
00081 
00087   Region(const Region& region);
00088 
00096   Region(int col, int row, Sheet* sheet = 0);
00097 
00107   Region(int col, int row, int width, int height, Sheet* sheet = 0);
00108 
00112   virtual ~Region();
00113 
00114 
00115 
00120   QString name(Sheet* originSheet = 0) const;
00121 
00127   Sheet* filterSheetName(QString& sRegion);
00128 
00129 
00130 
00134   bool isEmpty() const;
00135 
00139   bool isSingular() const;
00140 
00144   bool isContiguous() const;
00145 
00149   bool isValid() const;
00150 
00156   bool isColumnSelected(uint col = 0) const;
00157 
00163   bool isRowSelected(uint row = 0) const;
00164 
00168   bool isColumnOrRowSelected() const;
00169 
00174   bool isColumnAffected(uint col) const;
00175 
00180   bool isRowAffected(uint row) const;
00181 
00187   bool contains(const QPoint& point, Sheet* sheet = 0) const;
00188 
00189 
00190 
00191   /* TODO Stefan #2: Optimize! Adjacent Points/Ranges */
00197   Element* add(const QPoint& point, Sheet* sheet = 0);
00203   Element* add(const QRect& range, Sheet* sheet = 0);
00208   Element* add(const Region& region);
00209 
00210   /* TODO Stefan #3: Improve! */
00215   void sub(const QPoint& point);
00220   void sub(const QRect& range);
00225   void sub(const Region& region);
00226 
00231   virtual Element* eor(const QPoint& point, Sheet* sheet = 0);
00232 
00236   virtual void clear();
00237 
00238 
00239 
00240   QRect boundingRect() const;
00241 
00242 
00243 
00248   bool operator==(const Region& region) const;
00249 
00253   void operator=(const Region& region);
00254 
00255 
00256 
00260   View* view() const;
00261 
00265   void setView(View*);
00266 
00267 
00268   typedef QValueList<Element*>::Iterator      Iterator;
00269   typedef QValueList<Element*>::ConstIterator ConstIterator;
00270 
00271   ConstIterator constBegin() const;
00272   ConstIterator constEnd() const;
00273 
00274 protected:
00278   QValueList<Element*>& cells() const;
00279 
00288   Iterator insert(Iterator iterator, const QPoint& point, Sheet*, bool multi = true);
00297   Iterator insert(Iterator iterator, const QRect& range, Sheet*, bool multi = true);
00298 
00299   virtual Point* createPoint(const QPoint&) const;
00300   virtual Point* createPoint(const QString&) const;
00301   virtual Point* createPoint(const Point&) const;
00302   virtual Range* createRange(const QRect&) const;
00303   virtual Range* createRange(const QString&) const;
00304   virtual Range* createRange(const Range&) const;
00305 
00306 private:
00307   class Private;
00308   Private *d;
00309 };
00310 
00311 
00312 /***************************************************************************
00313   class Region::Element
00314 ****************************************************************************/
00324 class Region::Element
00325 {
00326 public:
00327   enum Type { Undefined, Point, Range };
00328 
00329   Element();
00330   virtual ~Element();
00331 
00332   virtual Type type() const { return Undefined; }
00333   virtual bool isValid() const { return false; }
00334   virtual bool isColumn() const { return false; }
00335   virtual bool isRow() const { return false; }
00336 
00337   virtual bool contains(const QPoint&) const { return false; }
00338   virtual bool contains(const QRect&) const { return false; }
00339 
00340   virtual QString name(Sheet* = 0) const { return QString(""); }
00341   virtual QRect rect() const { return QRect(); }
00342   virtual const QColor& color() const { return Qt::black; }
00343 
00344   Sheet* sheet() const { return m_sheet; }
00345   void setSheet(Sheet* sheet) { m_sheet = sheet; }
00346 
00347 protected:
00348   /* TODO Stefan #6:
00349       Elaborate, if this pointer could be avoided by QDict or whatever in
00350       Region.
00351   */
00352   Sheet* m_sheet;
00353 };
00354 
00355 
00356 /***************************************************************************
00357   class Region::Point
00358 ****************************************************************************/
00359 
00370 class Region::Point : public Region::Element
00371 {
00372 public:
00373   Point(const QPoint&);
00374   Point(const QString&);
00375   virtual ~Point();
00376 
00377   virtual Type type() const { return Element::Point; }
00378   virtual bool isValid() const { return (!m_point.isNull() && util_isPointValid(pos())); }
00379   virtual bool isColumn() const { return false; }
00380   virtual bool isRow() const { return false; }
00381 
00382   virtual bool contains(const QPoint&) const;
00383   virtual bool contains(const QRect&) const;
00384 
00385   virtual QString name(Sheet* originSheet = 0) const;
00386 
00387   virtual QRect rect() const { return QRect(m_point,m_point); }
00388 
00389   QPoint pos() const { return m_point; }
00390 
00391 private:
00392   QPoint m_point;
00393 };
00394 
00395 
00396 /***************************************************************************
00397   class Region:.Range
00398 ****************************************************************************/
00399 
00410 class Region::Range : public Region::Element
00411 {
00412 public:
00413   Range(const QRect&);
00414   Range(const QString&);
00415   virtual ~Range();
00416 
00417   virtual Type type() const { return Element::Range; }
00418   virtual bool isValid() const { return !m_range.isNull() && util_isRectValid(rect()); }
00419   virtual bool isColumn() const { return (m_range.normalize().top() == 1 && m_range.normalize().bottom() == KS_rowMax); }
00420   virtual bool isRow() const { return (m_range.normalize().left() == 1 && m_range.normalize().right() == KS_colMax); }
00421 
00422   virtual bool contains(const QPoint&) const;
00423   virtual bool contains(const QRect&) const;
00424 
00425   virtual QString name(Sheet* originSheet = 0) const;
00426 
00427   virtual QRect rect() const { return m_range; }
00428 
00429   int width() const;
00430   int height() const;
00431 
00432 private:
00433   QRect m_range;
00434 };
00435 
00436 } // namespace KSpread
00437 
00438 
00439 /***************************************************************************
00440   kdDebug support
00441 ****************************************************************************/
00442 
00443 inline kdbgstream operator<<( kdbgstream str, const KSpread::Region& r )
00444 {
00445   str << "Region = " << r.name();
00446   return str;
00447 }
00448 
00449 #endif // KSPREAD_REGION
KDE Home | KDE Accessibility Home | Description of Access Keys