kspread

kspread_util.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00003    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef __kspread_util_h__
00022 #define __kspread_util_h__
00023 
00024 #include <qstring.h>
00025 #include <qrect.h>
00026 #include <qdatetime.h>
00027 
00028 #include <koffice_export.h>
00029 
00030 #include "kspread_global.h"
00031 #include "kspread_value.h"
00032 
00033 class QFont;
00034 class QPen;
00035 class QDomElement;
00036 class QDomDocument;
00037 
00038 class KLocale;
00039 
00040 bool util_isPointValid(QPoint point);
00041 bool util_isRectValid(QRect rect);
00042 
00043 namespace KSpread
00044 {
00045 class Cell;
00046 class Map;
00047 class Sheet;
00048 
00054 class KSPREAD_EXPORT Point
00055 {
00056 public:
00057   Point() { _pos.setX( -1 ); _sheet = 0; _columnFixed = false; _rowFixed = false; }
00058   Point( const QString& );
00059   Point( const QString&, Map*, Sheet* default_sheet = 0 );
00060   Point( const Point& c ) {
00061     _pos = c._pos;
00062     _sheet = c._sheet;
00063     _sheetName = c._sheetName;
00064     _columnFixed = c._columnFixed;
00065     _rowFixed = c._rowFixed;
00066   }
00067 
00068   bool isValid() const { return ( util_isPointValid(pos()) && ( _sheet != 0 || _sheetName.isEmpty() ) ); }
00069   bool isSheetKnown() const { return ( ! _sheetName.isEmpty() && _sheet != 0 ); }
00070 
00071   Cell* cell() const;
00072 
00073   bool operator== (const Point &cell) const;
00074   bool operator< (const Point &cell) const;
00075 
00076   int row () const { return _pos.y(); };
00077   int column () const { return _pos.x(); };
00078   void setRow (int r) { _pos.setY (r); };
00079   void setColumn (int c) { _pos.setX (c); };
00080 
00084   void      setSheet(Sheet* sheet);
00085   Sheet*    sheet() const;
00086 
00090   void      setSheetName(QString name);
00091   QString   sheetName() const;
00092 
00096   void      setPos(QPoint pos);
00097   QPoint    pos() const;
00098 
00103   void      setColumnFixed(bool colFixed);
00104   bool      columnFixed() const;
00105 
00109   void      setRowFixed(bool rowFixed);
00110   bool      rowFixed() const;
00111 
00112 
00113 private:
00114   Sheet* _sheet;
00115   QString _sheetName;
00116   QPoint _pos;
00117   bool _columnFixed;
00118   bool _rowFixed;
00119 
00120 private:
00121   void init( const QString& );
00122 };
00123 
00130 class KSPREAD_EXPORT Range
00131 {
00132 public:
00133   Range();
00134 
00135   Range( const QString& );
00136   Range( const QString&, Map*, Sheet* default_sheet = 0 );
00137   Range( const Range& r );
00138   Range( const Point& ul, const Point& lr );
00139 
00148   bool isValid() const;
00149 
00151   bool isSheetKnown() const { return ( !sheetName().isEmpty() && sheet() != 0 ); }
00152 
00154   void getStartPoint(Point* pt);
00156   void getEndPoint(Point* pt);
00157 
00158   int startRow () const { return range().top(); };
00159   int startCol () const { return range().left(); };
00160   int endRow () const { return range().bottom(); };
00161   int endCol () const { return range().right(); };
00162 
00167   virtual void setRange(const QRect& newRange) {_range=newRange;}
00168 
00169   void setRange(int newStartCol, int newStartRow, int newEndCol, int newEndRow)
00170   { _range=QRect(newStartCol,newStartRow,newEndCol-newStartCol,newEndRow-newStartRow); }
00171 
00173   QRect range() const;
00174 
00176   bool contains (const Point &cell) const;
00181   bool intersects (const Range &r) const;
00182 
00188   QString toString() const;
00189 
00191   void setLeftFixed(bool fixed);
00192   bool leftFixed() const;
00193 
00195   void setRightFixed(bool fixed);
00196   bool rightFixed() const;
00197 
00199   void setTopFixed(bool fixed);
00200   bool topFixed() const;
00201 
00203   void setBottomFixed(bool fixed);
00204   bool bottomFixed() const;
00205 
00207   void setSheet(Sheet* sheet);
00208   Sheet* sheet() const;
00209 
00211   void setSheetName(QString sheetName);
00212   QString sheetName() const;
00213 
00218   QString namedArea() const;
00219 
00223   bool operator==(const Range& range) const;
00224 
00225 
00226 private:
00227   Sheet* _sheet;
00228   QString _sheetName;
00229   QString _namedArea;
00230   QRect _range;
00231   bool _leftFixed;
00232   bool _rightFixed;
00233   bool _topFixed;
00234   bool _bottomFixed;
00235 };
00236 
00244 struct RangeList {
00245   QValueList<Point> cells;
00246   QValueList<Range> ranges;
00247 };
00248 
00249 
00256 class RangeIterator
00257 {
00258 public:
00263   RangeIterator(QRect _range, Sheet* _sheet);
00264   ~RangeIterator();
00265 
00269   Cell* first();
00270 
00275   Cell* next();
00276 private:
00277 
00278   QRect range;
00279   Sheet* sheet;
00280   QPoint current;
00281 };
00282 
00283 //helper functions for the formatting
00284 bool formatIsDate (FormatType fmt);
00285 bool formatIsTime (FormatType fmt);
00286 bool formatIsFraction (FormatType fmt);
00287 
00288 
00289 
00290 KSPREAD_EXPORT QString util_rangeName( const QRect &_area );
00291 KSPREAD_EXPORT QString util_rangeName( Sheet *_sheet, const QRect &_area );
00292 QString util_rangeColumnName( const QRect &_area);
00293 QString util_rangeRowName( const QRect &_area);
00294 
00299 KSPREAD_EXPORT int util_decodeColumnLabelText( const QString &_col );
00304 KSPREAD_EXPORT QString util_encodeColumnLabelText( int column );
00305 
00306 bool util_isAllSelected(const QRect &selection);
00307 bool util_isColumnSelected(const QRect &selection);
00308 bool util_isRowSelected(const QRect &selection);
00309 bool util_isRowOrColumnSelected( const QRect &selection );
00310 
00311 
00312 
00313 bool util_validateSheetName(const QString &name);
00314 
00315 QDomElement util_createElement( const QString & tagName, const QFont & font, QDomDocument & doc );
00316 QDomElement util_createElement( const QString & tagname, const QPen & pen, QDomDocument & doc );
00317 QFont       util_toFont( QDomElement & element );
00318 QPen        util_toPen( QDomElement & element );
00319 int         util_penCompare( QPen const & pen1, QPen const & pen2 );
00320 
00321 QString convertRefToRange( const QString & sheet, const QRect & rect );
00322 QString convertRefToBase( const QString & sheet, const QRect & rect );
00323 QString convertRangeToRef( const QString & sheetName, const QRect & _area );
00324 
00325 void insertBracket( QString & s );
00326 QString convertOasisPenToString( const QPen & pen );
00327 QPen convertOasisStringToPen( const QString &str );
00328 
00329 //Return true when it's a reference to cell from sheet.
00330 KSPREAD_EXPORT bool localReferenceAnchor( const QString &_ref );
00331 
00332 
00333 
00334 namespace Oasis
00335 {
00342   // TODO check visibility
00343   KSPREAD_EXPORT QString decodeFormula(const QString& expr, const KLocale* locale = 0);
00350   KSPREAD_EXPORT QString encodeFormula(const QString& expr, const KLocale* locale = 0);
00351 }
00352 
00353 } // namespace KSpread
00354 
00355 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys