Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

sheet.h

Go to the documentation of this file.
00001 /*
00002                =.            This file is part of the Opie Project
00003              .=l.            Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
00004            .>+-=
00005  _;:,     .>    :=|.         This program is free software; you can
00006 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00007 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00008 .="- .-=="i,     .._         License as published by the Free Software
00009  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00010      ._= =}       :          or (at your option) any later version.
00011     .%`+i>       _;_.
00012     .i_,=:_.      -<s.       This program is distributed in the hope that
00013      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00014     : ..    .:,     . . .    without even the implied warranty of
00015     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00016   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00017 ..}^=.=       =       ;      Library General Public License for more
00018 ++=   -.     .`     .:       details.
00019  :     =  ...= . :.=-
00020  -.   .:....=;==+<;          You should have received a copy of the GNU
00021   -_. . .   )=.  =           Library General Public License along with
00022     --        :-=`           this library; see the file COPYING.LIB.
00023                              If not, write to the Free Software Foundation,
00024                              Inc., 59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 /*
00030  * Opie Sheet (formerly Sheet/Qt)
00031  * by Serdar Ozler <sozler@sitebest.com>
00032  */
00033 
00034 #ifndef SHEET_H
00035 #define SHEET_H
00036 
00037 /* QT */
00038 #include <qtable.h>
00039 #include <qstack.h>
00040 
00041 typedef struct typeCellBorders
00042 {
00043     QPen right, bottom;
00044 };
00045 
00046 typedef struct typeCellData
00047 {
00048     int col, row;
00049     typeCellBorders borders;
00050     QBrush background;
00051     Qt::AlignmentFlags alignment;
00052     QColor fontColor;
00053     QFont font;
00054     QString data;
00055 };
00056 
00057 
00058 #define NONE_TOKEN 0
00059 #define NUMBER_TOKEN 1
00060 #define VARIABLE_TOKEN 2
00061 #define FUNCTION_TOKEN 3
00062 #define SYMBOL_TOKEN 4
00063 #define STRING_TOKEN 5
00064 
00065 class Expression
00066 {
00067 public:
00068     QString Body;
00069     QList<QString> CompiledBody;
00070     QList<int> CompiledBodyType;
00071     QString SYMBOL;
00072     QString MATHSYMBOL;
00073     QArray<int> ArgsOfFunc;
00074     int FuncDepth;
00075     bool ErrorFound;
00076     int n; // holds the current parser position
00077     QString chunk; // the piece in the parser we are on
00078     int SymbGroup; // the current type
00079 
00080     QString InExpr;
00081 
00082     QChar chunk0(void); // retunrs the first char of expression;
00083     Expression(QString expr1);// constructor
00084 
00085     bool isSymbol(QChar ch);
00086     bool isMathSymbol(QChar ch);
00087     void GetNext();
00088     void First();
00089     void Third();
00090     void Fourth();
00091     void Fifth();
00092     void Sixth();
00093     void Seventh();
00094     void Eighth();
00095     void Ninth();
00096 
00097     bool Expression::Parse(); //parses the expression in RPN format;
00098 
00099 };
00100 
00101 
00102 
00103 class Sheet: public QTable
00104 {
00105     Q_OBJECT
00106 
00107     // Variables
00108     bool clicksLocked;
00109     int selectionNo;
00110     typeCellBorders defaultBorders;
00111     typeCellData defaultCellData;
00112 
00113     // QT objects
00114     QList<typeCellData> sheetData, clipboardData;
00115     QString pressedCell, releasedCell, sheetName;
00116     QStringList listDataParser;
00117 
00118     // Private functions
00119     bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE);
00120     QString findCellName(int row, int col);
00121     bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2);
00122     QString calculateVariable(const QString &variable);
00123     QString calculateFunction(const QString &func, const QString &parameters, int NumOfParams);
00124     QString getParameter(const QString &parameters, int paramNo, bool giveError=FALSE, const QString funcName="");
00125     QString dataParser(const QString &cell, const QString &data);
00126     QString dataParserHelper(const QString &data);
00127     typeCellData *createCellData(int row, int col);
00128     typeCellData *findCellData(int row, int col);
00129 
00130 
00131     //LOGICAL / INFO
00132     double functionCountIf(const QString &param1, const QString &param2, const QString &param3);
00133     double functionSumSQ(const QString &param1, const QString &param2); //sum of squares
00134     QString functionIndex(const QString &param1, const QString &param2, int indx);
00135     //math functions computations
00136     double BesselI0(double x);
00137     double BesselI(int n, double x);
00138     double BesselK0(double x);
00139     double BesselI1(double x);
00140     double BesselK1(double x);
00141     double BesselK(int n, double x);
00142     double BesselJ0(double x);
00143     double BesselY0(double x);
00144     double BesselJ1(double x);
00145     double BesselY1(double x);
00146     double BesselY(int n, double x);
00147     double BesselJ(int n, double x);
00148     double GammaLn(double xx);
00149     double Factorial(double n);
00150     double GammaP(double a, double x);
00151     double GammaQ(double a,double x);
00152     void GammaSeries(double *gamser, double a, double x, double *gln);
00153     void GammaContinuedFraction(double *gammcf, double a, double x, double *gln);
00154     double ErrorFunction(double x);
00155     double ErrorFunctionComplementary(double x);
00156     double Beta(double z, double w);
00157     double BetaContinuedFraction(double a, double b, double x);
00158     double BetaIncomplete(double a, double b, double x);
00159     double functionVariance(const QString &param1, const QString &param2);
00160     double functionVariancePopulation(const QString &param1, const QString &param2);
00161     double functionSkew(const QString &param1, const QString &param2);
00162     double functionKurt(const QString &param1, const QString &param2);
00163 
00164     // Sheet/Qt parser functions
00165     double functionSum(const QString &param1, const QString &param2);
00166     double functionAvg(const QString &param1, const QString &param2);
00167     double functionMax(const QString &param1, const QString &param2);
00168     double functionMin(const QString &param1, const QString &param2);
00169     double functionCount(const QString &param1, const QString &param2);
00170 
00171     // Reimplemented QTable functions
00172     void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected);
00173     void viewportMousePressEvent(QMouseEvent *e);
00174     void viewportMouseMoveEvent(QMouseEvent *e);
00175     void viewportMouseReleaseEvent(QMouseEvent *e);
00176 
00177 public slots:
00178     void slotCellSelected(int row, int col);
00179     void slotCellChanged(int row, int col);
00180 
00181 public:
00182     Sheet(int numRows, int numCols, QWidget *parent);
00183     ~Sheet();
00184     void ReCalc(void);
00185     void setData(const QString &data);
00186     QString getData();
00187 
00188     void setName(const QString &data);
00189     QString getName();
00190 
00191     void setPen(int row, int col, int vertical, const QPen &pen);
00192     QPen getPen(int row, int col, int vertical);
00193 
00194     void setBrush(int row, int col, const QBrush &brush);
00195     QBrush getBrush(int row, int col);
00196 
00197     void setTextAlign(int row, int col, Qt::AlignmentFlags flags);
00198     Qt::AlignmentFlags getAlignment(int row, int col);
00199 
00200     void setTextFont(int row, int col, const QFont &font, const QColor &color);
00201     QFont getFont(int row, int col);
00202     QColor getFontColor(int row, int col);
00203 
00204     void lockClicks(bool lock=TRUE);
00205     void copySheetData(QList<typeCellData> *destSheetData);
00206     void setSheetData(QList<typeCellData> *srcSheetData);
00207     void getSelection(int *row1, int *col1, int *row2, int *col2);
00208 
00209     void insertRows(int no=1, bool allColumns=TRUE);
00210     void insertColumns(int no=1, bool allRows=TRUE);
00211 
00212     void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE);
00213 
00214     // Static functions
00215     static int getHeaderColumn(const QString &section);
00216     static QString getHeaderString(int section);
00217 
00218 public slots:
00219     void editCut();
00220     void editCopy();
00221     void editPaste(bool onlyContents=FALSE);
00222     void editClear();
00223     void swapCells(int row1, int col1, int row2, int col2);
00224 
00225 signals:
00226     void currentDataChanged(const QString &data);
00227     void cellClicked(const QString &cell);
00228     void sheetModified();
00229 };
00230 
00231 #endif

Generated on Sat Nov 5 16:17:01 2005 for OPIE by  doxygen 1.4.2