00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef SHEET_H
00035 #define SHEET_H
00036
00037
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;
00077 QString chunk;
00078 int SymbGroup;
00079
00080 QString InExpr;
00081
00082 QChar chunk0(void);
00083 Expression(QString expr1);
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();
00098
00099 };
00100
00101
00102
00103 class Sheet: public QTable
00104 {
00105 Q_OBJECT
00106
00107
00108 bool clicksLocked;
00109 int selectionNo;
00110 typeCellBorders defaultBorders;
00111 typeCellData defaultCellData;
00112
00113
00114 QList<typeCellData> sheetData, clipboardData;
00115 QString pressedCell, releasedCell, sheetName;
00116 QStringList listDataParser;
00117
00118
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 ¶meters, int NumOfParams);
00124 QString getParameter(const QString ¶meters, 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
00132 double functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3);
00133 double functionSumSQ(const QString ¶m1, const QString ¶m2);
00134 QString functionIndex(const QString ¶m1, const QString ¶m2, int indx);
00135
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 ¶m1, const QString ¶m2);
00160 double functionVariancePopulation(const QString ¶m1, const QString ¶m2);
00161 double functionSkew(const QString ¶m1, const QString ¶m2);
00162 double functionKurt(const QString ¶m1, const QString ¶m2);
00163
00164
00165 double functionSum(const QString ¶m1, const QString ¶m2);
00166 double functionAvg(const QString ¶m1, const QString ¶m2);
00167 double functionMax(const QString ¶m1, const QString ¶m2);
00168 double functionMin(const QString ¶m1, const QString ¶m2);
00169 double functionCount(const QString ¶m1, const QString ¶m2);
00170
00171
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
00215 static int getHeaderColumn(const QString §ion);
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