kspread Library API Documentation

kspread_util.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library 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 GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __kspread_util_h__
00021 #define __kspread_util_h__
00022 
00023 #include <qstring.h>
00024 #include <qrect.h>
00025 #include <qdatetime.h>
00026 
00027 #include "kspread_global.h"
00028 #include "kspread_value.h"
00029 #include <koffice_export.h>
00030 class KSpreadCell;
00031 class KSpreadMap;
00032 class KSpreadSheet;
00033 class KLocale;
00034 
00035 class QFont;
00036 class QPen;
00037 class QDomElement;
00038 class QDomDocument;
00039 
00040 struct KSPREAD_EXPORT KSpreadPoint
00041 {
00042 public:
00043   KSpreadPoint() { pos.setX( -1 ); sheet = 0; columnFixed = false; rowFixed = false; }
00044   KSpreadPoint( const QString& );
00045   KSpreadPoint( const QString&, KSpreadMap*, KSpreadSheet* default_sheet = 0 );
00046   KSpreadPoint( const KSpreadPoint& c ) {
00047     pos = c.pos;
00048     sheet = c.sheet; sheetName = c.sheetName;
00049     columnFixed = c.columnFixed;
00050     rowFixed = c.rowFixed;
00051   }
00052 
00053   bool isValid() const { return ( pos.x() >= 0 && ( sheet != 0 || sheetName.isEmpty() ) ); }
00054   bool isSheetKnown() const { return ( !sheetName.isEmpty() && sheet != 0 ); }
00055 
00056   KSpreadCell* cell() const;
00057 
00058   bool operator== (const KSpreadPoint &cell) const;
00059   bool operator< (const KSpreadPoint &cell) const;
00060 
00061   int row () const { return pos.y(); };
00062   int column () const { return pos.x(); };
00063   void setRow (int r) { pos.setY (r); };
00064   void setColumn (int c) { pos.setX (c); };
00065 
00066   /*
00067     TODO
00068   bool columnFixed() const { return m_columnFixed; }
00069   bool rowFixed() const { return m_rowFixed; }
00070   QPoint pos() const { return m_pos; }
00071   QString sheetName() const { return m_sheetName; }
00072   KSpreadSheet* sheet() const { return m_sheet; }
00073 
00074 private:
00075   */
00076   KSpreadSheet* sheet;
00077   QString sheetName;
00078   QPoint pos;
00079   bool columnFixed;
00080   bool rowFixed;
00081 
00082 private:
00083   void init( const QString& );
00084 };
00085 
00086 struct KSPREAD_EXPORT KSpreadRange
00087 {
00088   KSpreadRange() { sheet = 0; range.setLeft( -1 ); }
00089   KSpreadRange( const QString& );
00090   KSpreadRange( const QString&, KSpreadMap*, KSpreadSheet* default_sheet = 0 );
00091   KSpreadRange( const KSpreadRange& r ) {
00092     sheet = r.sheet;
00093     sheetName = r.sheetName;
00094     range = r.range;
00095   }
00096   KSpreadRange( const KSpreadPoint& ul, const KSpreadPoint& lr )
00097   {
00098     range = QRect( ul.pos, lr.pos );
00099     if ( ul.sheetName != lr.sheetName )
00100     {
00101       range.setLeft( -1 );
00102       return;
00103     }
00104     sheetName = ul.sheetName;
00105     sheet = ul.sheet;
00106     leftFixed = ul.columnFixed;
00107     rightFixed = lr.columnFixed;
00108     topFixed = ul.rowFixed;
00109     bottomFixed = lr.rowFixed;
00110   }
00111 
00112   bool isValid() const { return ( range.left() >= 0 && range.right() >= 0 && ( sheet != 0 || sheetName.isEmpty() ) ); }
00113   bool isSheetKnown() const { return ( !sheetName.isEmpty() && sheet != 0 ); }
00114 
00115   int startRow () const { return range.top(); };
00116   int startCol () const { return range.left(); };
00117   int endRow () const { return range.bottom(); };
00118   int endCol () const { return range.right(); };
00119 
00121   bool contains (const KSpreadPoint &cell) const;
00123   bool intersects (const KSpreadRange &r) const;
00124 
00125   KSpreadSheet* sheet;
00126   QString sheetName;
00127   QRect range;
00128   bool leftFixed;
00129   bool rightFixed;
00130   bool topFixed;
00131   bool bottomFixed;
00132 };
00133 
00141 struct RangeList {
00142   QValueList<KSpreadPoint> cells;
00143   QValueList<KSpreadRange> ranges;
00144 };
00145 
00146 
00153 class KSpreadRangeIterator
00154 {
00155 public:
00160   KSpreadRangeIterator(QRect _range, KSpreadSheet* _sheet);
00161   ~KSpreadRangeIterator();
00162 
00166   KSpreadCell* first();
00167 
00172   KSpreadCell* next();
00173 private:
00174 
00175   QRect range;
00176   KSpreadSheet* sheet;
00177   QPoint current;
00178 };
00179 
00180 //helper functions for the formatting
00181 bool formatIsDate (FormatType fmt);
00182 bool formatIsTime (FormatType fmt);
00183 bool formatIsFraction (FormatType fmt);
00184 
00185 
00186 
00187 KSPREAD_EXPORT QString util_rangeName( const QRect &_area );
00188 KSPREAD_EXPORT QString util_rangeName( KSpreadSheet *_sheet, const QRect &_area );
00189 QString util_rangeColumnName( const QRect &_area);
00190 QString util_rangeRowName( const QRect &_area);
00191 
00196 KSPREAD_EXPORT int util_decodeColumnLabelText( const QString &_col );
00201 KSPREAD_EXPORT QString util_encodeColumnLabelText( int column );
00202 
00203 QString formatNumber( KSpreadValue const & value, QString format, bool & setRed,
00204                       KLocale const * const locale, bool insert );
00205 
00206 double util_fact( double val, double end );
00207 
00208 bool util_isAllSelected(const QRect &selection);
00209 bool util_isColumnSelected(const QRect &selection);
00210 bool util_isRowSelected(const QRect &selection);
00211 
00212 bool util_validateSheetName(const QString &name);
00213 
00214 QDomElement util_createElement( const QString & tagName, const QFont & font, QDomDocument & doc );
00215 QDomElement util_createElement( const QString & tagname, const QPen & pen, QDomDocument & doc );
00216 QFont       util_toFont( QDomElement & element );
00217 QPen        util_toPen( QDomElement & element );
00218 int         util_penCompare( QPen const & pen1, QPen const & pen2 );
00219 
00220 QString convertRefToRange( const QString & sheet, const QRect & rect );
00221 QString convertRefToBase( const QString & sheet, const QRect & rect );
00222 QString convertRangeToRef( const QString & sheetName, const QRect & _area );
00223 
00224 void insertBracket( QString & s );
00225 QString convertOasisPenToString( const QPen & pen );
00226 QPen convertOasisStringToPen( const QString &str );
00227 
00228 //Return true when it's a reference to cell from sheet.
00229 KSPREAD_EXPORT bool localReferenceAnchor( const QString &_ref );
00230 
00231 
00232 #endif
KDE Logo
This file is part of the documentation for kspread Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:43:27 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003