author | ar <ar> | 2004-06-12 09:24:00 (UTC) |
---|---|---|
committer | ar <ar> | 2004-06-12 09:24:00 (UTC) |
commit | 7a62e8e3601ee98f5f06261c361fe8132334cd56 (patch) (unidiff) | |
tree | 72e1e68878e32c70140fe1de478bced96670e348 /noncore/apps/opie-sheet/sheet.h | |
parent | 3fbf3cb264200c5ac11dbef43a51f3ab2a969587 (diff) | |
download | opie-7a62e8e3601ee98f5f06261c361fe8132334cd56.zip opie-7a62e8e3601ee98f5f06261c361fe8132334cd56.tar.gz opie-7a62e8e3601ee98f5f06261c361fe8132334cd56.tar.bz2 |
- rename sheet-qt -> opie-sheet
- format source code for a better readability
Diffstat (limited to 'noncore/apps/opie-sheet/sheet.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-sheet/sheet.h | 264 |
1 files changed, 142 insertions, 122 deletions
diff --git a/noncore/apps/opie-sheet/sheet.h b/noncore/apps/opie-sheet/sheet.h index f705cd0..92c8061 100644 --- a/noncore/apps/opie-sheet/sheet.h +++ b/noncore/apps/opie-sheet/sheet.h | |||
@@ -1,169 +1,189 @@ | |||
1 | /*************************************************************************** | 1 | /* |
2 | * * | 2 | =. This file is part of the Opie Project |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org> |
4 | * it under the terms of the GNU General Public License as published by * | 4 | .>+-= |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | _;:, .> :=|. This program is free software; you can |
6 | * (at your option) any later version. * | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | * * | 7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
8 | ***************************************************************************/ | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This program is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. .` .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-=` this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
9 | 28 | ||
10 | /* | 29 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 30 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 31 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 32 | */ |
14 | 33 | ||
15 | #ifndef SHEET_H | 34 | #ifndef SHEET_H |
16 | #define SHEET_H | 35 | #define SHEET_H |
17 | 36 | ||
37 | /* QT */ | ||
18 | #include <qtable.h> | 38 | #include <qtable.h> |
19 | #include <qstack.h> | 39 | #include <qstack.h> |
20 | 40 | ||
21 | typedef struct typeCellBorders | 41 | typedef struct typeCellBorders |
22 | { | 42 | { |
23 | QPen right, bottom; | 43 | QPen right, bottom; |
24 | }; | 44 | }; |
25 | 45 | ||
26 | typedef struct typeCellData | 46 | typedef struct typeCellData |
27 | { | 47 | { |
28 | int col, row; | 48 | int col, row; |
29 | typeCellBorders borders; | 49 | typeCellBorders borders; |
30 | QBrush background; | 50 | QBrush background; |
31 | Qt::AlignmentFlags alignment; | 51 | Qt::AlignmentFlags alignment; |
32 | QColor fontColor; | 52 | QColor fontColor; |
33 | QFont font; | 53 | QFont font; |
34 | QString data; | 54 | QString data; |
35 | }; | 55 | }; |
36 | 56 | ||
37 | 57 | ||
38 | #define NONE_TOKEN 0 | 58 | #define NONE_TOKEN 0 |
39 | #define NUMBER_TOKEN 1 | 59 | #define NUMBER_TOKEN 1 |
40 | #define VARIABLE_TOKEN 2 | 60 | #define VARIABLE_TOKEN 2 |
41 | #define FUNCTION_TOKEN 3 | 61 | #define FUNCTION_TOKEN 3 |
42 | #define SYMBOL_TOKEN 4 | 62 | #define SYMBOL_TOKEN 4 |
43 | #define STRING_TOKEN 5 | 63 | #define STRING_TOKEN 5 |
44 | 64 | ||
45 | class Expression | 65 | class Expression |
46 | { | 66 | { |
47 | public: | 67 | public: |
48 | QString Body; | 68 | QString Body; |
49 | QList<QString> CompiledBody; | 69 | QList<QString> CompiledBody; |
50 | QList<int> CompiledBodyType; | 70 | QList<int> CompiledBodyType; |
51 | QString SYMBOL; | 71 | QString SYMBOL; |
52 | QString MATHSYMBOL; | 72 | QString MATHSYMBOL; |
53 | QArray<int> ArgsOfFunc; | 73 | QArray<int> ArgsOfFunc; |
54 | int FuncDepth; | 74 | int FuncDepth; |
55 | bool ErrorFound; | 75 | bool ErrorFound; |
56 | int n; // holds the current parser position | 76 | int n; // holds the current parser position |
57 | QString chunk; // the piece in the parser we are on | 77 | QString chunk; // the piece in the parser we are on |
58 | int SymbGroup; // the current type | 78 | int SymbGroup; // the current type |
59 | 79 | ||
60 | QString InExpr; | 80 | QString InExpr; |
61 | 81 | ||
62 | QChar chunk0(void); // retunrs the first char of expression; | 82 | QChar chunk0(void); // retunrs the first char of expression; |
63 | Expression(QString expr1);// constructor | 83 | Expression(QString expr1);// constructor |
64 | 84 | ||
65 | bool isSymbol(QChar ch); | 85 | bool isSymbol(QChar ch); |
66 | bool isMathSymbol(QChar ch); | 86 | bool isMathSymbol(QChar ch); |
67 | void GetNext(); | 87 | void GetNext(); |
68 | void First(); | 88 | void First(); |
69 | void Third(); | 89 | void Third(); |
70 | void Fourth(); | 90 | void Fourth(); |
71 | void Fifth(); | 91 | void Fifth(); |
72 | void Sixth(); | 92 | void Sixth(); |
73 | void Seventh(); | 93 | void Seventh(); |
74 | void Eighth(); | 94 | void Eighth(); |
75 | void Ninth(); | 95 | void Ninth(); |
76 | 96 | ||
77 | bool Expression::Parse(); //parses the expression in RPN format; | 97 | bool Expression::Parse(); //parses the expression in RPN format; |
78 | 98 | ||
79 | }; | 99 | }; |
80 | 100 | ||
81 | 101 | ||
82 | 102 | ||
83 | class Sheet: public QTable | 103 | class Sheet: public QTable |
84 | { | 104 | { |
85 | Q_OBJECT | 105 | Q_OBJECT |
86 | 106 | ||
87 | // Variables | 107 | // Variables |
88 | bool clicksLocked; | 108 | bool clicksLocked; |
89 | int selectionNo; | 109 | int selectionNo; |
90 | typeCellBorders defaultBorders; | 110 | typeCellBorders defaultBorders; |
91 | typeCellData defaultCellData; | 111 | typeCellData defaultCellData; |
92 | 112 | ||
93 | // QT objects | 113 | // QT objects |
94 | QList<typeCellData> sheetData, clipboardData; | 114 | QList<typeCellData> sheetData, clipboardData; |
95 | QString pressedCell, releasedCell, sheetName; | 115 | QString pressedCell, releasedCell, sheetName; |
96 | QStringList listDataParser; | 116 | QStringList listDataParser; |
97 | 117 | ||
98 | // Private functions | 118 | // Private functions |
99 | bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE); | 119 | bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE); |
100 | QString findCellName(int row, int col); | 120 | QString findCellName(int row, int col); |
101 | bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2); | 121 | bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2); |
102 | QString calculateVariable(const QString &variable); | 122 | QString calculateVariable(const QString &variable); |
103 | QString calculateFunction(const QString &func, const QString ¶meters, int NumOfParams); | 123 | QString calculateFunction(const QString &func, const QString ¶meters, int NumOfParams); |
104 | QString getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName=""); | 124 | QString getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName=""); |
105 | QString dataParser(const QString &cell, const QString &data); | 125 | QString dataParser(const QString &cell, const QString &data); |
106 | QString dataParserHelper(const QString &data); | 126 | QString dataParserHelper(const QString &data); |
107 | typeCellData *createCellData(int row, int col); | 127 | typeCellData *createCellData(int row, int col); |
108 | typeCellData *findCellData(int row, int col); | 128 | typeCellData *findCellData(int row, int col); |
109 | 129 | ||
110 | 130 | ||
111 | //LOGICAL / INFO | 131 | //LOGICAL / INFO |
112 | double functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3); | 132 | double functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3); |
113 | double functionSumSQ(const QString ¶m1, const QString ¶m2); //sum of squares | 133 | double functionSumSQ(const QString ¶m1, const QString ¶m2); //sum of squares |
114 | QString functionIndex(const QString ¶m1, const QString ¶m2, int indx); | 134 | QString functionIndex(const QString ¶m1, const QString ¶m2, int indx); |
115 | //math functions computations | 135 | //math functions computations |
116 | double BesselI0(double x); | 136 | double BesselI0(double x); |
117 | double BesselI(int n, double x); | 137 | double BesselI(int n, double x); |
118 | double BesselK0(double x); | 138 | double BesselK0(double x); |
119 | double BesselI1(double x); | 139 | double BesselI1(double x); |
120 | double BesselK1(double x); | 140 | double BesselK1(double x); |
121 | double BesselK(int n, double x); | 141 | double BesselK(int n, double x); |
122 | double BesselJ0(double x); | 142 | double BesselJ0(double x); |
123 | double BesselY0(double x); | 143 | double BesselY0(double x); |
124 | double BesselJ1(double x); | 144 | double BesselJ1(double x); |
125 | double BesselY1(double x); | 145 | double BesselY1(double x); |
126 | double BesselY(int n, double x); | 146 | double BesselY(int n, double x); |
127 | double BesselJ(int n, double x); | 147 | double BesselJ(int n, double x); |
128 | double GammaLn(double xx); | 148 | double GammaLn(double xx); |
129 | double Factorial(double n); | 149 | double Factorial(double n); |
130 | double GammaP(double a, double x); | 150 | double GammaP(double a, double x); |
131 | double GammaQ(double a,double x); | 151 | double GammaQ(double a,double x); |
132 | void GammaSeries(double *gamser, double a, double x, double *gln); | 152 | void GammaSeries(double *gamser, double a, double x, double *gln); |
133 | void GammaContinuedFraction(double *gammcf, double a, double x, double *gln); | 153 | void GammaContinuedFraction(double *gammcf, double a, double x, double *gln); |
134 | double ErrorFunction(double x); | 154 | double ErrorFunction(double x); |
135 | double ErrorFunctionComplementary(double x); | 155 | double ErrorFunctionComplementary(double x); |
136 | double Beta(double z, double w); | 156 | double Beta(double z, double w); |
137 | double BetaContinuedFraction(double a, double b, double x); | 157 | double BetaContinuedFraction(double a, double b, double x); |
138 | double BetaIncomplete(double a, double b, double x); | 158 | double BetaIncomplete(double a, double b, double x); |
139 | double functionVariance(const QString ¶m1, const QString ¶m2); | 159 | double functionVariance(const QString ¶m1, const QString ¶m2); |
140 | double functionVariancePopulation(const QString ¶m1, const QString ¶m2); | 160 | double functionVariancePopulation(const QString ¶m1, const QString ¶m2); |
141 | double functionSkew(const QString ¶m1, const QString ¶m2); | 161 | double functionSkew(const QString ¶m1, const QString ¶m2); |
142 | double functionKurt(const QString ¶m1, const QString ¶m2); | 162 | double functionKurt(const QString ¶m1, const QString ¶m2); |
143 | 163 | ||
144 | // Sheet/Qt parser functions | 164 | // Sheet/Qt parser functions |
145 | double functionSum(const QString ¶m1, const QString ¶m2); | 165 | double functionSum(const QString ¶m1, const QString ¶m2); |
146 | double functionAvg(const QString ¶m1, const QString ¶m2); | 166 | double functionAvg(const QString ¶m1, const QString ¶m2); |
147 | double functionMax(const QString ¶m1, const QString ¶m2); | 167 | double functionMax(const QString ¶m1, const QString ¶m2); |
148 | double functionMin(const QString ¶m1, const QString ¶m2); | 168 | double functionMin(const QString ¶m1, const QString ¶m2); |
149 | double functionCount(const QString ¶m1, const QString ¶m2); | 169 | double functionCount(const QString ¶m1, const QString ¶m2); |
150 | 170 | ||
151 | // Reimplemented QTable functions | 171 | // Reimplemented QTable functions |
152 | void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected); | 172 | void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected); |
153 | void viewportMousePressEvent(QMouseEvent *e); | 173 | void viewportMousePressEvent(QMouseEvent *e); |
154 | void viewportMouseMoveEvent(QMouseEvent *e); | 174 | void viewportMouseMoveEvent(QMouseEvent *e); |
155 | void viewportMouseReleaseEvent(QMouseEvent *e); | 175 | void viewportMouseReleaseEvent(QMouseEvent *e); |
156 | 176 | ||
157 | public slots: | 177 | public slots: |
158 | void slotCellSelected(int row, int col); | 178 | void slotCellSelected(int row, int col); |
159 | void slotCellChanged(int row, int col); | 179 | void slotCellChanged(int row, int col); |
160 | 180 | ||
161 | public: | 181 | public: |
162 | Sheet(int numRows, int numCols, QWidget *parent); | 182 | Sheet(int numRows, int numCols, QWidget *parent); |
163 | ~Sheet(); | 183 | ~Sheet(); |
164 | void ReCalc(void); | 184 | void ReCalc(void); |
165 | void setData(const QString &data); | 185 | void setData(const QString &data); |
166 | QString getData(); | 186 | QString getData(); |
167 | 187 | ||
168 | void setName(const QString &data); | 188 | void setName(const QString &data); |
169 | QString getName(); | 189 | QString getName(); |
@@ -190,22 +210,22 @@ class Sheet: public QTable | |||
190 | void insertColumns(int no=1, bool allRows=TRUE); | 210 | void insertColumns(int no=1, bool allRows=TRUE); |
191 | 211 | ||
192 | void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE); | 212 | void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE); |
193 | 213 | ||
194 | // Static functions | 214 | // Static functions |
195 | static int getHeaderColumn(const QString §ion); | 215 | static int getHeaderColumn(const QString §ion); |
196 | static QString getHeaderString(int section); | 216 | static QString getHeaderString(int section); |
197 | 217 | ||
198 | public slots: | 218 | public slots: |
199 | void editCut(); | 219 | void editCut(); |
200 | void editCopy(); | 220 | void editCopy(); |
201 | void editPaste(bool onlyContents=FALSE); | 221 | void editPaste(bool onlyContents=FALSE); |
202 | void editClear(); | 222 | void editClear(); |
203 | void swapCells(int row1, int col1, int row2, int col2); | 223 | void swapCells(int row1, int col1, int row2, int col2); |
204 | 224 | ||
205 | signals: | 225 | signals: |
206 | void currentDataChanged(const QString &data); | 226 | void currentDataChanged(const QString &data); |
207 | void cellClicked(const QString &cell); | 227 | void cellClicked(const QString &cell); |
208 | void sheetModified(); | 228 | void sheetModified(); |
209 | }; | 229 | }; |
210 | 230 | ||
211 | #endif | 231 | #endif |