kspread Library API Documentation

kspread_cell.h

00001 /* This file is part of the KDE project
00002 
00003    Copyright 2004 Tomas Mecir <mecirt@gmail.com>
00004    Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
00005    Copyright 2002,2004 Ariya Hidayat <ariya@kde.org>
00006    Copyright 2002-2003 Norbert Andres <nandres@web.de>
00007    Copyright 2003 Stefan Hetzl <shetzl@chello.at>
00008    Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
00009    Copyright 2002 Harri Porten <porten@kde.org>
00010    Copyright 2002 John Dailey <dailey@vt.edu>
00011    Copyright 1999-2001 David Faure <faure@kde.org>
00012    Copyright 2000-2001 Werner Trobin <trobin@kde.org>
00013    Copyright 2000 Simon Hausmann <hausmann@kde.org
00014    Copyright 1998-1999 Torben Weis <weis@kde.org>
00015    Copyright 1999 Michael Reiher <michael.reiher.gmx.de>
00016    Copyright 1999 Reginald Stadlbauer <reggie@kde.org>
00017 
00018    This library is free software; you can redistribute it and/or
00019    modify it under the terms of the GNU Library General Public
00020    License as published by the Free Software Foundation; either
00021    version 2 of the License, or (at your option) any later version.
00022 
00023    This library is distributed in the hope that it will be useful,
00024    but WITHOUT ANY WARRANTY; without even the implied warranty of
00025    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026    Library General Public License for more details.
00027 
00028    You should have received a copy of the GNU Library General Public License
00029    along with this library; see the file COPYING.LIB.  If not, write to
00030    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00031    Boston, MA 02111-1307, USA.
00032 */
00033 
00034 #ifndef KSPREAD_CELL
00035 #define KSPREAD_CELL
00036 
00037 class KSpreadCell;
00038 class KSpreadSheet;
00039 class KSpreadCanvas;
00040 class KSpreadView;
00041 
00042 class KLocale;
00043 class QDomElement;
00044 class QDomDocument;
00045 class KoXmlWriter;
00046 class KoGenStyles;
00047 class KoGenStyle;
00048 class KSParseNode;
00049 class KSpreadGenValidationStyles;
00050 
00051 
00052 #include <qpainter.h>
00053 #include <qptrlist.h>
00054 #include <qdatetime.h>
00055 
00056 #include "kspread_format.h"
00057 #include "kspread_global.h"
00058 #include "kspread_condition.h"
00059 #include "kspread_value.h"
00060 
00061 #include <koOasisStyles.h>
00062 #include <koRect.h>
00063 struct KSpreadValidity
00064 {
00065     KSpreadValidity()
00066     {
00067         valMin = 0.0;
00068         valMax = 0.0;
00069         m_cond = None;
00070         m_action = Stop;
00071         m_allow = Allow_All;
00072         displayMessage = true;
00073         allowEmptyCell = false;
00074             displayValidationInformation = false;
00075     };
00076     QString message;
00077     QString title;
00078     QString titleInfo;
00079     QString messageInfo;
00080     double valMin;
00081     double valMax;
00082     Conditional m_cond;
00083     Action m_action;
00084     Allow m_allow;
00085     QTime  timeMin;
00086     QTime  timeMax;
00087     QDate  dateMin;
00088     QDate  dateMax;
00089     bool displayMessage;
00090     bool allowEmptyCell;
00091     bool displayValidationInformation;
00092     QStringList listValidity;
00093 };
00094 
00095 class CellPrivate;
00096 
00097 
00108 class KSPREAD_EXPORT KSpreadCell : public KSpreadFormat
00109 {
00110   friend class SelectPrivate;
00111   friend class KSpreadConditions;
00112 public:
00113 
00114   KSpreadCell (KSpreadSheet *_sheet, int _column, int _row);
00115   KSpreadCell (KSpreadSheet *_sheet, KSpreadStyle * _style, int _column, int _row);
00116 
00120     ~KSpreadCell();
00121 
00125     KSpreadSheet* sheet() const;
00126 
00131     bool isDefault() const;
00132 
00136     bool isEmpty() const;
00137 
00141     int column() const;
00142 
00146     int row() const;
00147 
00152     QString name() const;
00153 
00158     QString fullName() const;
00159 
00163     QString columnName() const;
00164 
00169     static QString name( int col, int row );
00170 
00175     static QString fullName( const KSpreadSheet *s, int col, int row );
00176 
00181     static QString columnName( uint column );
00182 
00186     KLocale* locale();
00190     bool isFormula() const;
00191 
00196     QString text() const;
00197 
00198     QString strOutText() const;
00199 
00204     const KSpreadValue value() const;
00205 
00209     void setValue( const KSpreadValue& value );
00210 
00211     KSpreadCell* previousCell() const;
00212     KSpreadCell* nextCell() const;
00213     void setPreviousCell( KSpreadCell* c );
00214     void setNextCell( KSpreadCell* c );
00215 
00220     void move( int column, int row );
00221 
00232     void sheetDies();
00233 
00243     QDomElement save( QDomDocument& doc, int _x_offset = 0, int _y_offset = 0, bool force = false, bool copy = false, bool era = false );
00244 
00245     virtual bool saveOasis( KoXmlWriter& xmlwriter , KoGenStyles &mainStyles, int row, int column, int maxCol, int &repeated, KSpreadGenValidationStyles &valStyle );
00246 
00247     void saveOasisValue (KoXmlWriter &xmlWriter);
00248 
00249     QString saveOasisCellStyle( KoGenStyle &currentCellStyle,KoGenStyles &mainStyles, bool force = false, bool copy = false );
00250 
00251     bool load( const QDomElement& cell, int _xshift, int _yshift, PasteMode pm = Normal,
00252            Operation op = OverWrite, bool paste = false );
00253 
00254     bool loadOasis( const QDomElement & element, const KoOasisStyles &oasisStyles );
00255     void loadOasisValidation( const QString& validationName );
00256 
00257     QTime toTime(const QDomElement &element) ;
00258     QDate toDate(const QDomElement &element);
00259 
00265     void copyFormat( int _column, int _row );
00271     void copyFormat( KSpreadCell *_cell );
00272     void copyContent( KSpreadCell *_cell );
00280     void copyAll( KSpreadCell *cell);
00281 
00296     void paintCell( const KoRect & rect, QPainter & painter,
00297                     KSpreadView * view, const KoPoint & coordinate,
00298                     const QPoint & cellRef,
00299                     bool paintBorderRight,
00300                     bool paintBorderBottom,
00301                     bool paintBorderLeft,
00302                     bool paintBorderTop,
00303                     QPen & rightPen,
00304                     QPen & bottomPen,
00305                     QPen & leftPen,
00306                     QPen & topPen,
00307                     bool drawCursor = true );
00308 
00315     int width( int _col = -1, const KSpreadCanvas *_canvas = 0L ) const;
00316 
00322     int height( int _row = -1, const KSpreadCanvas *_canvas = 0L ) const;
00323 
00330     double dblWidth( int _col = -1, const KSpreadCanvas *_canvas = 0L ) const;
00331 
00337     double dblHeight( int _row = -1, const KSpreadCanvas *_canvas = 0L ) const;
00338 
00342     QRect cellRect();
00343 
00351     bool needsPrinting() const;
00352 
00360     void incPrecision();
00368     void decPrecision();
00369 
00374     void setCellText( const QString& _text, bool asString = false );
00375 
00381     void setDisplayText( const QString& _text );
00382 
00389     void setLink( const QString& link );
00390 
00395     QString link() const;
00396 
00398     //
00399     // Methods for querying format stuff.
00400     //
00402 
00403     const QPen & effLeftBorderPen( int col, int row ) const;
00404     const QPen & effTopBorderPen( int col, int row ) const;
00405     const QPen & effRightBorderPen( int col, int row ) const;
00406     const QPen & effBottomBorderPen( int col, int row ) const;
00407     const QPen & effGoUpDiagonalPen( int col, int row ) const;
00408     const QPen & effFallDiagonalPen( int col, int row ) const;
00409     const QColor & effTextColor( int col, int row ) const;
00410 
00411     uint effBottomBorderValue( int col, int row ) const;
00412     uint effRightBorderValue( int col, int row ) const;
00413     uint effLeftBorderValue( int col, int row ) const;
00414     uint effTopBorderValue( int col, int row ) const;
00415 
00419     const QPen& leftBorderPen( int col, int row ) const;
00420 
00424     const QPen& topBorderPen( int col, int row ) const;
00425 
00429     const QPen& rightBorderPen( int col, int row ) const;
00430 
00434     const QPen& bottomBorderPen( int col, int row ) const;
00435 
00439     const QColor& bgColor( int col, int row ) const;
00440 
00444     const QBrush& backGroundBrush( int col, int row ) const;
00445 
00447     //
00448     // Methods for setting format stuff.
00449     //
00451 
00455     void setLeftBorderPen( const QPen& p );
00456 
00460     void setTopBorderPen( const QPen& p );
00461 
00465     void setRightBorderPen( const QPen& p );
00466 
00470     void setBottomBorderPen( const QPen& p );
00471 
00475     virtual void setCurrency( int type, QString const & symbol );
00476 
00478     //
00479     // Other stuff
00480     //
00482 
00489     FormatType formatType() const;
00490 
00491     bool isDate() const;
00492     bool isTime() const;
00493 
00494     void setNumber( double number );
00495 
00497     double getDouble ();
00498 
00499     void convertToDouble ();
00500     void convertToPercent ();
00501     void convertToMoney ();
00502     void convertToTime ();
00503     void convertToDate ();
00504 
00508     double textWidth() const;
00509     double textHeight() const;
00510 
00511 
00518     bool updateChart(bool refresh=true);
00519 
00520     QString testAnchor( int _x, int _y ) const;
00521 
00526     void clicked( KSpreadCanvas *_canvas );
00527 
00536     bool calc(bool delay = true);
00537 
00541     void setCalcDirtyFlag();
00542 
00543     bool calcDirtyFlag();
00544 
00554     void NotifyDepending( int col, int row, KSpreadSheet* sheet, bool isDepending );
00555 
00561     virtual void setLayoutDirtyFlag( bool format = false );
00562     bool layoutDirtyFlag() const;
00563 
00564     void clearDisplayDirtyFlag();
00565     void setDisplayDirtyFlag();
00566 
00575     void obscure( KSpreadCell *cell, bool isForcing = false);
00581     void unobscure(KSpreadCell* cell);
00585     bool isObscured() const;
00591     bool isObscuringForced() const;
00592 
00599     KSpreadCell *ultimateObscuringCell() const;
00600 
00604     QValueList<KSpreadCell*> obscuringCells() const;
00605 
00606     void clearObscuringCells();
00607 
00608 
00619     void forceExtraCells( int _col, int _row, int _x, int _y );
00620 
00624     bool isForceExtraCells() const;
00625 
00630     int mergedXCells() const;
00631 
00636     int mergedYCells() const;
00637 
00641     int extraXCells() const;
00645     int extraYCells() const;
00646 
00647     double extraWidth() const;
00648     double extraHeight() const;
00649 
00657     QString encodeFormula( bool _era = false, int _col = -1, int _row = -1 );
00658     QString decodeFormula( const QString &_text, int _col = -1, int _row = -1 );
00659 
00669     QString pasteOperation( const QString &new_text, const QString &old_text, Operation op );
00670 
00675     bool hasError() const;
00676 
00680     void clearAllErrors();
00681 
00686     void makeLayout( QPainter &_painter, int _col, int _row );
00687 
00693     bool makeFormula();
00694 
00695 
00696     void defaultStyle();
00697 
00701     QValueList<KSpreadConditional> conditionList() const;
00702 
00706     void setConditionList(const QValueList<KSpreadConditional> &newList);
00707 
00708     KSpreadValidity * getValidity( int newStruct = -1 );
00709 
00710     void removeValidity();
00711 
00716     bool testValidity() const;
00717 
00722     void calculateTextParameters( QPainter &painter, int _col, int _row );
00723 
00727     int defineAlignX();
00728 
00729 
00733     bool operator > ( const KSpreadCell & ) const;
00734     bool operator < ( const KSpreadCell & ) const;
00735 
00736     void freeAllObscuredCells();
00737 
00738     /* descriptions of the flags are just below */
00739     enum CellFlags{
00740     /* this uses the same flags variable as KSpreadFormat.  The least significant
00741        16 bits are reserved for the base class, and the most significant 16
00742        have been left for this subclass to use. */
00743       Flag_LayoutDirty           = 0x00010000,
00744       Flag_CalcDirty             = 0x00020000,
00745       Flag_Progress              = 0x00040000,
00746       Flag_UpdatingDeps          = 0x00080000,
00747       Flag_DisplayDirty          = 0x00100000,
00748       Flag_ForceExtra            = 0x00200000,
00749       Flag_CellTooShortX         = 0x00400000,
00750       Flag_CellTooShortY         = 0x00800000,
00751       Flag_ParseError            = 0x01000000,
00752       Flag_CircularCalculation   = 0x02000000,
00753       Flag_DependancyError       = 0x04000000,
00754       Flag_PaintingCell          = 0x08000000, // On during painting
00755       Flag_TextFormatDirty       = 0x10000000
00756     };
00757 
00758     void clearFlag( CellFlags flag );
00759     void setFlag( CellFlags flag );
00760     bool testFlag( CellFlags flag ) const;
00761 
00762   /* descriptions of the flags are as follows: */
00763 
00764   /*
00765    * Error
00766    * True if the cell is calculated and there was an error during calculation
00767    * In that case the cell usually displays "#####"
00768    *
00769    * LayoutDirty
00770    * Flag showing whether the current layout is OK.
00771    * If you change for example the fonts point size, set this flag. When the
00772    * cell must draw itself on the screen it will first recalculate its layout.
00773    *
00774    * CalcDirty
00775    * Shows whether recalculation is necessary.
00776    * If this cell must be recalculated for some reason, for example the user
00777    * entered a new formula, then this flag is set. If @ref #bFormula is FALSE
00778    * nothing will happen at all.
00779    *
00780    * Progress
00781    * Tells whether this cell it currently under calculation.
00782    * If a cell thats 'progressFlag' is set is told to calculate we
00783    * have detected a circular reference and we must stop calulating.
00784    *
00785    * UpdatingDeps
00786    * Tells whether we've already calculated the reverse dependancies for this
00787    * cell.  Similar to the Progress flag but it's for when we are calculating
00788    * in the reverse direction.
00789    * @see updateDependancies()
00790    *
00791    * DisplayDirty - TODO - is this unused now??
00792    * If this flag is set, then it is known that this cell has to be updated
00793    * on the display. This means that somewhere in the calling stack there is a
00794    * function which will call @ref KSpreadSheet::updateCell once it retains
00795    * the control. If a function changes the contents/layout of this cell and this
00796    * flag is not set, then the function must set it at once. After the changes
00797    * are done the function must call <tt>m_pSheet->updateCell(...).
00798    * The flag is cleared by the function m_pSheet->updateCell.
00799    *
00800    * ForceExtra
00801    * Tells whether the cell is forced to exceed its size.
00802    * Cells may occupy other cells space on demand. But you may force
00803    * a cell to do so by setting this flag. Forcing the cell to have
00804    * no extra size will disable this flag!
00805    *
00806    * CellTooShortX
00807    * When it's True displays ** and/or the red triangle and when the
00808    * mouse is over it, the tooltip displays the full value
00809    * it's true when text size is bigger that cell size
00810    * and when Align is center or left
00811    *
00812    * CellTooShortY
00813    * When it's True when mouseover it, the tooltip displays the full value
00814    * it's true when text size is bigger that cell height
00815    */
00816 
00817 protected:
00821     void formatChanged();
00825     KSpreadFormat* fallbackFormat( int col, int row );
00829     const KSpreadFormat* fallbackFormat( int col, int row ) const;
00830 
00834     void applyZoomedFont( QPainter &painter, int _col, int _row );
00835 
00840     void textSize( QPainter &_paint );
00841 
00846     QString textDisplaying( QPainter &painter);
00847 
00853     void clearFormula();
00854 
00863     void checkTextInput();
00864 
00869     void checkNumberFormat();
00870 
00871     void loadOasisValidationCondition( QString &valExpression );
00872     void saveOasisAnnotation( KoXmlWriter &xmlwriter );
00873     void loadOasisConditional( QDomElement * style );
00874 
00875 private:
00876 
00877     CellPrivate* d;
00878     // static const char* s_dataTypeToString[];
00879 
00880     /* helper functions to the paintCell(...) function */
00881     void paintCellBorders( QPainter& painter, const KoRect &rect,
00882                            const KoRect &cellRect, 
00883                const QPoint &cellRef,
00884                            bool paintBorderRight, bool paintBorderBottom,
00885                            bool paintBorderLeft, bool paintBorderTop,
00886                            QPen & rightPen, QPen & bottomPen,
00887                            QPen & leftPen, QPen & topPen );
00888     void paintPageBorders( QPainter& painter, const KoRect &cellRect,
00889                            const QPoint &cellRef,
00890                            bool paintBorderRight, bool paintBorderBottom );
00891     void paintText( QPainter& painter, const KoRect &cellRect,
00892                     const QPoint &cellRef );
00893     void paintMoreTextIndicator( QPainter& painter, const KoRect &cellRect,
00894                                  QColor &backgroundColor );
00895     void paintCommentIndicator( QPainter& painter, const KoRect &cellRect,
00896                                 const QPoint &cellRef, QColor &backgroundColor );
00897     void paintFormulaIndicator( QPainter& painter, const KoRect &cellRect,
00898                                 QColor &backgroundColor );
00899     void paintDefaultBorders( QPainter& painter, const KoRect &rect,
00900                               const KoRect &cellRect, const QPoint &cellRef,
00901                               bool paintBorderRight, bool paintBorderBottom,
00902                               bool paintBorderLeft, bool paintBorderTop,
00903                               QPen const & rightPen, QPen const & bottomPen,
00904                               QPen const & leftPen, QPen const & topPen );
00905     void paintBackground( QPainter& painter, const KoRect &cellRect,
00906                           const QPoint &cellRef, bool selected,
00907                           QColor &backgroundColor );
00908     void paintObscuredCells( const KoRect& rect, QPainter& painter,
00909                              KSpreadView* view, const KoRect &cellRect,
00910                              const QPoint &cellRef,
00911                              bool paintBorderRight, bool paintBorderBottom,
00912                              bool paintBorderLeft, bool paintBorderTop,
00913                              QPen & rightPen, QPen & bottomPen,
00914                              QPen & leftPen, QPen & topPen );
00915     void paintCellDiagonalLines( QPainter& painter, const KoRect &cellRect,
00916                                  const QPoint &cellRef );
00917 
00918 
00919 
00922   void valueChanged ();
00923 
00924   /* helper functions to the makeLayout(...) function */
00925   /* (more to come) */
00926   void setOutputText();
00927 
00928 
00929   /* helper functions to the load/save routines */
00930   bool loadCellData(const QDomElement &text, Operation op);
00931   bool saveCellResult( QDomDocument& doc, QDomElement& result,
00932                        QString str );
00933   void update();
00934   int effAlignX();
00935 
00941   void offsetAlign( int _col, int _row );
00942 
00943     void checkForNamedAreas( QString & formula ) const;
00944     void convertFormula( QString & text, const QString & f ) const;
00945     QString convertFormulaToOasisFormat( const QString & formula ) const;
00946     void loadOasisValidationValue( const QStringList &listVal );
00947 
00948 };
00949 
00950 #endif  // KSPREAD_CELL
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:42:53 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003