summaryrefslogtreecommitdiff
authorar <ar>2004-06-12 09:24:00 (UTC)
committer ar <ar>2004-06-12 09:24:00 (UTC)
commit7a62e8e3601ee98f5f06261c361fe8132334cd56 (patch) (unidiff)
tree72e1e68878e32c70140fe1de478bced96670e348
parent3fbf3cb264200c5ac11dbef43a51f3ab2a969587 (diff)
downloadopie-7a62e8e3601ee98f5f06261c361fe8132334cd56.zip
opie-7a62e8e3601ee98f5f06261c361fe8132334cd56.tar.gz
opie-7a62e8e3601ee98f5f06261c361fe8132334cd56.tar.bz2
- rename sheet-qt -> opie-sheet
- format source code for a better readability
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/Excel.cpp2867
-rw-r--r--noncore/apps/opie-sheet/Excel.h255
-rw-r--r--noncore/apps/opie-sheet/cellformat.cpp842
-rw-r--r--noncore/apps/opie-sheet/cellformat.h142
-rw-r--r--noncore/apps/opie-sheet/finddlg.cpp132
-rw-r--r--noncore/apps/opie-sheet/finddlg.h59
-rw-r--r--noncore/apps/opie-sheet/main.cpp35
-rw-r--r--noncore/apps/opie-sheet/mainwindow.cpp1467
-rw-r--r--noncore/apps/opie-sheet/mainwindow.h153
-rw-r--r--noncore/apps/opie-sheet/numberdlg.cpp70
-rw-r--r--noncore/apps/opie-sheet/numberdlg.h46
-rw-r--r--noncore/apps/opie-sheet/opie-sheet.pro23
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp4264
-rw-r--r--noncore/apps/opie-sheet/sheet.h264
-rw-r--r--noncore/apps/opie-sheet/sortdlg.cpp310
-rw-r--r--noncore/apps/opie-sheet/sortdlg.h83
-rw-r--r--noncore/apps/opie-sheet/textdlg.cpp62
-rw-r--r--noncore/apps/opie-sheet/textdlg.h46
18 files changed, 5767 insertions, 5353 deletions
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp
index fc49d56..57aef20 100644
--- a/noncore/apps/opie-sheet/Excel.cpp
+++ b/noncore/apps/opie-sheet/Excel.cpp
@@ -1,4 +1,33 @@
1/*
2 =. This file is part of the Opie Project
3 .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
4 .>+-=
5 _;:, .> :=|. This program is free software; you can
6.> <`_, > . <= redistribute it and/or modify it under
7:`=1 )Y*s>-.-- : the terms of the GNU General Public
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*/
1 28
29#include "Excel.h"
2 30
31/* STD */
3#include <stdio.h> 32#include <stdio.h>
4#include <stdlib.h> 33#include <stdlib.h>
@@ -7,42 +36,41 @@
7#include <sys/types.h> 36#include <sys/types.h>
8#include <strings.h> 37#include <strings.h>
9#include "Excel.h"
10 38
11static xfrecord formatter[] = { 39static xfrecord formatter[] = {
12{ 0xe , DATEFORMAT, "%m/%d/%y"}, 40 { 0xe , DATEFORMAT, "%m/%d/%y"},
13{ 0xf , DATEFORMAT, "%d-%b-%y"}, 41 { 0xf , DATEFORMAT, "%d-%b-%y"},
14{ 0x10, DATEFORMAT, "%d-%b"}, 42 { 0x10, DATEFORMAT, "%d-%b"},
15{ 0x11, DATEFORMAT, "%b-%y"}, 43 { 0x11, DATEFORMAT, "%b-%y"},
16{ 0x12, DATEFORMAT, "%I:%M %p"}, 44 { 0x12, DATEFORMAT, "%I:%M %p"},
17{ 0x13, DATEFORMAT, "%I:%M:%S %p"}, 45 { 0x13, DATEFORMAT, "%I:%M:%S %p"},
18{ 0x14, DATEFORMAT, "%H:%M"}, 46 { 0x14, DATEFORMAT, "%H:%M"},
19{ 0x15, DATEFORMAT, "%H:%M:%S"}, 47 { 0x15, DATEFORMAT, "%H:%M:%S"},
20{ 0x16, DATEFORMAT, "%m/%d/%y %H:%M"}, 48 { 0x16, DATEFORMAT, "%m/%d/%y %H:%M"},
21{ 0x2d, DATEFORMAT, "%M:%S"}, 49 { 0x2d, DATEFORMAT, "%M:%S"},
22{ 0x2e, DATEFORMAT, "%H:%M:%S"}, 50 { 0x2e, DATEFORMAT, "%H:%M:%S"},
23{ 0x2f, DATEFORMAT, "%M:%S"}, 51 { 0x2f, DATEFORMAT, "%M:%S"},
24{ 0xa5, DATEFORMAT, "%m/%d/%y %I:%M %p"}, 52 { 0xa5, DATEFORMAT, "%m/%d/%y %I:%M %p"},
25{ 0x1 , NUMBERFORMAT, "%.0f"}, 53 { 0x1 , NUMBERFORMAT, "%.0f"},
26{ 0x2 , NUMBERFORMAT, "%.2f"}, 54 { 0x2 , NUMBERFORMAT, "%.2f"},
27{ 0x3 , NUMBERFORMAT, "#,##%.0f"}, 55 { 0x3 , NUMBERFORMAT, "#,##%.0f"},
28{ 0x4 , NUMBERFORMAT, "#,##%.2f"}, 56 { 0x4 , NUMBERFORMAT, "#,##%.2f"},
29{ 0x5 , NUMBERFORMAT, "$#,##%.0f"}, 57 { 0x5 , NUMBERFORMAT, "$#,##%.0f"},
30{ 0x6 , NUMBERFORMAT, "$#,##%.0f"}, 58 { 0x6 , NUMBERFORMAT, "$#,##%.0f"},
31{ 0x7 , NUMBERFORMAT, "$#,##%.2f"}, 59 { 0x7 , NUMBERFORMAT, "$#,##%.2f"},
32{ 0x8 , NUMBERFORMAT, "$#,##%.2f"}, 60 { 0x8 , NUMBERFORMAT, "$#,##%.2f"},
33{ 0x9 , NUMBERFORMAT, "%.0f%%"}, 61 { 0x9 , NUMBERFORMAT, "%.0f%%"},
34{ 0xa , NUMBERFORMAT, "%.2f%%"}, 62 { 0xa , NUMBERFORMAT, "%.2f%%"},
35{ 0xb , NUMBERFORMAT, "%e"}, 63 { 0xb , NUMBERFORMAT, "%e"},
36{ 0x25, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, 64 { 0x25, NUMBERFORMAT, "#,##%.0f;(#,##0)"},
37{ 0x26, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, 65 { 0x26, NUMBERFORMAT, "#,##%.0f;(#,##0)"},
38{ 0x27, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, 66 { 0x27, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"},
39{ 0x28, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, 67 { 0x28, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"},
40{ 0x29, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, 68 { 0x29, NUMBERFORMAT, "#,##%.0f;(#,##0)"},
41{ 0x2a, NUMBERFORMAT, "$#,##%.0f;($#,##0)"}, 69 { 0x2a, NUMBERFORMAT, "$#,##%.0f;($#,##0)"},
42{ 0x2b, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, 70 { 0x2b, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"},
43{ 0x2c, NUMBERFORMAT, "$#,##%.2f;($#,##0.00)"}, 71 { 0x2c, NUMBERFORMAT, "$#,##%.2f;($#,##0.00)"},
44{ 0x30, NUMBERFORMAT, "##0.0E0"}, 72 { 0x30, NUMBERFORMAT, "##0.0E0"},
45{ 0, 0, ""} 73 { 0, 0, ""}
46}; 74 };
47 75
48 76
@@ -50,306 +78,314 @@ static xfrecord formatter[] = {
50int ExcelBook::Integer2Byte(int b1, int b2) 78int ExcelBook::Integer2Byte(int b1, int b2)
51{ 79{
52 int i1 = b1 & 0xff; 80 int i1 = b1 & 0xff;
53 int i2 = b2 & 0xff; 81 int i2 = b2 & 0xff;
54 int val = i2 << 8 | i1; 82 int val = i2 << 8 | i1;
55 return val; 83 return val;
56}; 84};
57 85
58int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4) 86int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4)
59{ 87{
60 int i1 = Integer2Byte(b1, b2); 88 int i1 = Integer2Byte(b1, b2);
61 int i2 = Integer2Byte(b3, b4); 89 int i2 = Integer2Byte(b3, b4);
62 int val = i2 << 16 | i1; 90 int val = i2 << 16 | i1;
63 return val; 91 return val;
64}; 92};
65 93
66int ExcelBook::Integer2ByteFile(FILE *f) { 94int ExcelBook::Integer2ByteFile(FILE *f)
67 int i1, i2; 95{
68 i1 = fgetc(f); 96 int i1, i2;
69 i2 = fgetc(f); 97 i1 = fgetc(f);
70 return Integer2Byte(i1,i2); 98 i2 = fgetc(f);
99 return Integer2Byte(i1,i2);
71}; 100};
72 101
73float ExcelBook::Float4Byte(int b1, int b2, int b3, int b4) 102float ExcelBook::Float4Byte(int b1, int b2, int b3, int b4)
74{ 103{
75 int i; 104 int i;
76 float f; 105 float f;
77 unsigned char *ieee; 106 unsigned char *ieee;
78 ieee = (unsigned char *) &f; 107 ieee = (unsigned char *) &f;
79 for (i = 0; i < 4; i++) ieee[i] = 0; 108 for (i = 0; i < 4; i++) ieee[i] = 0;
80 ieee[0] = ((int)b4) & 0xff; 109 ieee[0] = ((int)b4) & 0xff;
81 ieee[1] = ((int)b3) & 0xff; 110 ieee[1] = ((int)b3) & 0xff;
82 ieee[2] = ((int)b2) & 0xff; 111 ieee[2] = ((int)b2) & 0xff;
83 ieee[3] = ((int)b1) & 0xff; 112 ieee[3] = ((int)b1) & 0xff;
84 return f; 113 return f;
85}; 114};
86 115
87double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) 116double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4)
88{ 117{
89 long int rk; 118 long int rk;
90 double value; 119 double value;
91 120
92 rk=Integer4Byte(b1,b2,b3,b4); 121 rk=Integer4Byte(b1,b2,b3,b4);
93 //printf("Double4Bytes:%d,%d,%d,%d\r\n",b1,b2,b3,b4); 122 //printf("Double4Bytes:%d,%d,%d,%d\r\n",b1,b2,b3,b4);
94 if ( (rk & 0x02) != 0) 123 if ( (rk & 0x02) != 0)
95 { 124 {
96 long int intval = rk >> 2; //drops the 2 bits 125 long int intval = rk >> 2; //drops the 2 bits
97 printf("Double4Byte:intval=%d, rk=%d, rk>>2=%d\r\n",intval,rk,rk>>2); 126 printf("Double4Byte:intval=%d, rk=%d, rk>>2=%d\r\n",intval,rk,rk>>2);
98 value = (double) intval; 127 value = (double) intval;
99 printf("Double4Byte: VALUEINT=%f\r\n",value); 128 printf("Double4Byte: VALUEINT=%f\r\n",value);
100 if ( (rk & 0x01) != 0) 129 if ( (rk & 0x01) != 0)
101 { 130 {
102 value /= 100.0; 131 value /= 100.0;
103 }; 132 };
104 return value; 133 return value;
105 }else 134 }
106 { 135 else
107 136 {
108 union { double d; unsigned long int b[2]; } dbl_byte; 137
109 unsigned long int valbits = (rk & 0xfffffffc); 138 union { double d; unsigned long int b[2]; } dbl_byte;
110 #if defined(__arm__) && !defined(__vfp__) 139 unsigned long int valbits = (rk & 0xfffffffc);
111 dbl_byte.b[0]=valbits; 140#if defined(__arm__) && !defined(__vfp__)
112 dbl_byte.b[1]=0; 141 dbl_byte.b[0]=valbits;
113 #else 142 dbl_byte.b[1]=0;
114 dbl_byte.b[0]=0; 143#else
115 dbl_byte.b[1]=valbits; 144 dbl_byte.b[0]=0;
116 #endif 145 dbl_byte.b[1]=valbits;
117 printf("dbl_byte.b[0]=%d,dbl_byte.b[1]=%d\r\n",dbl_byte.b[0],dbl_byte.b[1]); 146#endif
118 value=dbl_byte.d; 147 printf("dbl_byte.b[0]=%d,dbl_byte.b[1]=%d\r\n",dbl_byte.b[0],dbl_byte.b[1]);
119 printf("Double4Byte: VALUE=%f\r\n",value); 148 value=dbl_byte.d;
120 149 printf("Double4Byte: VALUE=%f\r\n",value);
121 if ( (rk & 0x01) != 0) 150
122 { 151 if ( (rk & 0x01) != 0)
123 value /= 100.0; 152 {
124 }; 153 value /= 100.0;
125 return value; 154 };
126 }; 155 return value;
156 };
127}; 157};
128 158
129void ExcelBook::DetectEndian(void) 159void ExcelBook::DetectEndian(void)
130{ 160{
131 int end; 161 int end;
132 long i = 0x44332211; 162 long i = 0x44332211;
133 unsigned char* a = (unsigned char*) &i; 163 unsigned char* a = (unsigned char*) &i;
134 end = (*a != 0x11); 164 end = (*a != 0x11);
135 if (end == 1) { 165 if (end == 1)
136 endian = BIG_ENDIAN; 166 {
137 printf("BIGENDIAN!\r\n"); 167 endian = BIG_ENDIAN;
138 } else { 168 printf("BIGENDIAN!\r\n");
139 endian = LITTLE_ENDIAN; 169 }
140 printf("LITTLEENDIAN!\r\n"); 170 else
141 } 171 {
172 endian = LITTLE_ENDIAN;
173 printf("LITTLEENDIAN!\r\n");
174 }
142}; 175};
143 176
144double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) 177double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8)
145{ 178{
146 int i; 179 int i;
147 double d; 180 double d;
148 unsigned char *ieee; 181 unsigned char *ieee;
149 ieee = (unsigned char *)&d; 182 ieee = (unsigned char *)&d;
150 for (i = 0; i < 8; i++) ieee[i] = 0; 183 for (i = 0; i < 8; i++) ieee[i] = 0;
151 if (endian == BIG_ENDIAN) { 184 if (endian == BIG_ENDIAN)
152 ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; 185 {
153 ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; 186 ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff;
154 ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; 187 ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff;
155 ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; 188 ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff;
156 } else { 189 ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff;
157 ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; 190 }
158 ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; 191 else
159 ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; 192 {
160 ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff; 193 ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff;
161 } 194 ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff;
162 return d; 195 ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff;
196 ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff;
197 }
198 return d;
163}; 199};
164 200
165bool ExcelBook::OpenFile(char *Filename) 201bool ExcelBook::OpenFile(char *Filename)
166{ 202{
167 printf("Opening excel file!\r\n"); 203 printf("Opening excel file!\r\n");
168 File= fopen(Filename, "r"); 204 File= fopen(Filename, "r");
169 Position=0; // first byte index in file 205 Position=0; // first byte index in file
170 XFRecords.resize(0); 206 XFRecords.resize(0);
171 SharedStrings.resize(0); 207 SharedStrings.resize(0);
172 Names.resize(0); 208 Names.resize(0);
173 Sheets.resize(0); 209 Sheets.resize(0);
174 if(File==NULL) return false; 210 if(File==NULL) return false;
175 printf("Opened excel file!\r\n"); 211 printf("Opened excel file!\r\n");
176 return true; 212 return true;
177}; 213};
178 214
179bool ExcelBook::CloseFile(void) 215bool ExcelBook::CloseFile(void)
180{ 216{
181 int w1; 217 int w1;
182 for(w1=0;w1<(int)XFRecords.count();w1++) 218 for(w1=0;w1<(int)XFRecords.count();w1++)
183 { 219 {
184 if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;}; 220 if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;};
185 }; 221 };
186 for(w1=0;w1<(int)SharedStrings.count();w1++) 222 for(w1=0;w1<(int)SharedStrings.count();w1++)
187 { 223 {
188 if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;}; 224 if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;};
189 }; 225 };
190 for(w1=0;w1<(int)Names.count();w1++) 226 for(w1=0;w1<(int)Names.count();w1++)
191 { 227 {
192 if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;}; 228 if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;};
193 }; 229 };
194 for(w1=0;w1<(int)Sheets.count();w1++) 230 for(w1=0;w1<(int)Sheets.count();w1++)
195 { 231 {
196 if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;}; 232 if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;};
197 }; 233 };
198 XFRecords.resize(0); 234 XFRecords.resize(0);
199 SharedStrings.resize(0); 235 SharedStrings.resize(0);
200 Names.resize(0); 236 Names.resize(0);
201 Sheets.resize(0); 237 Sheets.resize(0);
202 fclose(File); 238 fclose(File);
203 printf("closed excel file!\r\n"); 239 printf("closed excel file!\r\n");
204 if(File==NULL) return true; 240 if(File==NULL) return true;
205 return false; 241 return false;
206}; 242};
207 243
208void ExcelBook::SeekPosition(int pos) 244void ExcelBook::SeekPosition(int pos)
209{ 245{
210 if(!feof(File)) 246 if(!feof(File))
211 { 247 {
212 Position=pos; 248 Position=pos;
213 //printf("SeekPosition:Pos:%d\r\n",Position); 249 //printf("SeekPosition:Pos:%d\r\n",Position);
214 fseek(File,pos,SEEK_SET); 250 fseek(File,pos,SEEK_SET);
215 }; 251 };
216}; 252};
217 253
218void ExcelBook::SeekSkip(int pos) 254void ExcelBook::SeekSkip(int pos)
219{ 255{
220 if(!feof(File)) 256 if(!feof(File))
221 { 257 {
222 Position=Position+pos; 258 Position=Position+pos;
223 //printf("SeekSkip:Pos:%d\r\n",Position); 259 //printf("SeekSkip:Pos:%d\r\n",Position);
224 fseek(File, Position, SEEK_SET); 260 fseek(File, Position, SEEK_SET);
225 }; 261 };
226}; 262};
227 263
228int ExcelBook::FileEOF(void) 264int ExcelBook::FileEOF(void)
229{ 265{
230 if(File!=NULL) return(feof(File)); else return 0; 266 if(File!=NULL) return(feof(File)); else return 0;
231 //EOF is defined in stdlib as -1 267 //EOF is defined in stdlib as -1
232}; 268};
233 269
234int ExcelBook::Get2Bytes(void) 270int ExcelBook::Get2Bytes(void)
235{ 271{
236 int i1,i2; 272 int i1,i2;
237 i1=0; i2=0; 273 i1=0; i2=0;
238 if (!feof(File)) 274 if (!feof(File))
239 { 275 {
240 i1=fgetc(File); 276 i1=fgetc(File);
241 Position++; 277 Position++;
242 }; 278 };
243 if (!feof(File)) 279 if (!feof(File))
244 { 280 {
245 i2=fgetc(File); 281 i2=fgetc(File);
246 Position++; 282 Position++;
247 }; 283 };
248 return Integer2Byte(i1,i2); 284 return Integer2Byte(i1,i2);
249}; 285};
250 286
251char* ExcelBook::Read(int pos, int length) 287char* ExcelBook::Read(int pos, int length)
252{ 288{
253 int i; 289 int i;
254 char *data; 290 char *data;
255 data= new char[length]; 291 data= new char[length];
256 SeekPosition(pos); 292 SeekPosition(pos);
257 for(i=0; i<length; i++) 293 for(i=0; i<length; i++)
258 { 294 {
259 if(!feof(File)) data[i]=fgetc(File); 295 if(!feof(File)) data[i]=fgetc(File);
260 }; 296 };
261 Position= Position+length; 297 Position= Position+length;
262 return data; 298 return data;
263}; 299};
264 300
265QString ExcelBook::ReadUnicodeChar(int pos, int length) 301QString ExcelBook::ReadUnicodeChar(int pos, int length)
266{ 302{
267 int i; 303 int i;
268 QString data; 304 QString data;
269 int i1=' ',i2=' ',ii; 305 int i1=' ',i2=' ',ii;
270 SeekPosition(pos); 306 SeekPosition(pos);
271 for(i=0; i<length; i++) 307 for(i=0; i<length; i++)
272 { 308 {
273 if(!feof(File)) i1=fgetc(File); 309 if(!feof(File)) i1=fgetc(File);
274 if(!feof(File)) i2=fgetc(File); 310 if(!feof(File)) i2=fgetc(File);
275 ii=Integer2Byte(i1,i2); 311 ii=Integer2Byte(i1,i2);
276 data.append(ii); 312 data.append(ii);
277 Position+=2; 313 Position+=2;
278 }; 314 };
279 return data; 315 return data;
280}; 316};
281 317
282QString* ExcelBook::GetString(int num) 318QString* ExcelBook::GetString(int num)
283{ 319{
284 if(num>=0 && num<(int)SharedStrings.count()) 320 if(num>=0 && num<(int)SharedStrings.count())
285 { 321 {
286 return SharedStrings[num]; 322 return SharedStrings[num];
287 }; 323 };
288 return new QString(""); 324 return new QString("");
289}; 325};
290 326
291int ExcelBook::SeekBOF(void) 327int ExcelBook::SeekBOF(void)
292{ 328{
293 int opcode,version,streamtype,length,ret=0; 329 int opcode,version,streamtype,length,ret=0;
294 char *data; 330 char *data;
295 while(!feof(File)) 331 while(!feof(File))
296 { 332 {
297 opcode=Get2Bytes(); 333 opcode=Get2Bytes();
298 if(opcode==XL_BOF) 334 if(opcode==XL_BOF)
299 { 335 {
300 length=Get2Bytes(); 336 length=Get2Bytes();
301 data=Read(Position,length); 337 data=Read(Position,length);
302 version=Integer2Byte(data[0], data[1]); 338 version=Integer2Byte(data[0], data[1]);
303 streamtype=Integer2Byte(data[2], data[3]); 339 streamtype=Integer2Byte(data[2], data[3]);
304 printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); 340 printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version);
305 delete data; data=NULL; 341 delete data; data=NULL;
306 if (version==BIFF8) ret=8; 342 if (version==BIFF8) ret=8;
307 else if(version==BIFF7) ret=7; 343 else if(version==BIFF7) ret=7;
308 printf("SEEKBOF:versionBIFF%d\r\n",ret); 344 printf("SEEKBOF:versionBIFF%d\r\n",ret);
309 if(streamtype==WBKGLOBAL) return ret *2; 345 if(streamtype==WBKGLOBAL) return ret *2;
310 else if(streamtype==WRKSHEET) return ret *1; 346 else if(streamtype==WRKSHEET) return ret *1;
311 return 1; 347 return 1;
312 }; 348 };
313 }; 349 };
314 return 0; 350 return 0;
315}; 351};
316 352
317ExcelBREC* ExcelBook::GetBREC(void) 353ExcelBREC* ExcelBook::GetBREC(void)
318{ 354{
319 ExcelBREC* rec; 355 ExcelBREC* rec;
320 rec= new ExcelBREC; 356 rec= new ExcelBREC;
321 if(FileEOF()) return NULL; 357 if(FileEOF()) return NULL;
322 rec->data=NULL; 358 rec->data=NULL;
323 rec->code=Get2Bytes(); 359 rec->code=Get2Bytes();
324 rec->length=Get2Bytes(); 360 rec->length=Get2Bytes();
325 rec->position=Position; 361 rec->position=Position;
326 SeekSkip(rec->length); 362 SeekSkip(rec->length);
327 return rec; 363 return rec;
328}; 364};
329 365
330ExcelBREC* ExcelBook::PeekBREC(void) 366ExcelBREC* ExcelBook::PeekBREC(void)
331{ 367{
332 int oldpos; 368 int oldpos;
333 ExcelBREC* NextRec; 369 ExcelBREC* NextRec;
334 oldpos=Position; 370 oldpos=Position;
335 NextRec=GetBREC(); 371 NextRec=GetBREC();
336 SeekPosition(oldpos); 372 SeekPosition(oldpos);
337 return NextRec; 373 return NextRec;
338}; 374};
339 375
340char* ExcelBook::GetDataOfBREC(ExcelBREC* record) 376char* ExcelBook::GetDataOfBREC(ExcelBREC* record)
341{ 377{
342 if(record->data==NULL) 378 if(record->data==NULL)
343 { 379 {
344 ConvertCharToArray(record,Read(record->position,record->length),record->length); 380 ConvertCharToArray(record,Read(record->position,record->length),record->length);
345 }; 381 };
346 return record->data;//new? 382 return record->data;//new?
347}; 383};
348 384
349void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) 385void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length)
350{ 386{
351 record->data=new char[length]; 387 record->data=new char[length];
352 for(int w1=0;w1<=length-1;w1++) 388 for(int w1=0;w1<=length-1;w1++)
353 record->data[w1]=chars[w1]; 389 record->data[w1]=chars[w1];
354}; 390};
355 391
@@ -357,230 +393,231 @@ void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length)
357bool ExcelSheet::InitCells() 393bool ExcelSheet::InitCells()
358{ 394{
359 int r; 395 int r;
360 Cells.resize(rows * cols + cols+1); 396 Cells.resize(rows * cols + cols+1);
361 if(Cells.count()==0) return false; 397 if(Cells.count()==0) return false;
362 for(r=0;r < Cells.count();r++) 398 for(r=0;r < Cells.count();r++)
363 { 399 {
364 Cells[r]=NULL; 400 Cells[r]=NULL;
365 }; 401 };
366 return true; 402 return true;
367}; 403};
368 404
369void ExcelSheet::Set(int row, int col, ExcelCell* cell) 405void ExcelSheet::Set(int row, int col, ExcelCell* cell)
370{ 406{
371 if(cell!=NULL&&(row*cols+col)<Cells.count()) 407 if(cell!=NULL&&(row*cols+col)<Cells.count())
372 { 408 {
373 Cells[row*cols+col]=cell; 409 Cells[row*cols+col]=cell;
374 }; 410 };
375}; 411};
376 412
377ExcelCell* ExcelSheet::Get(int row, int col) 413ExcelCell* ExcelSheet::Get(int row, int col)
378{ 414{
379 ExcelCell* cell; 415 ExcelCell* cell;
380 cell=Cells[row*cols+col]; 416 cell=Cells[row*cols+col];
381 if(cell==NULL) return NULL; 417 if(cell==NULL) return NULL;
382 return cell; 418 return cell;
383}; 419};
384 420
385int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) 421int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record)
386{ 422{
387 char* data=NULL; 423 char* data=NULL;
388 switch (record->code) 424 switch (record->code)
389 { 425 {
390 case XL_DIMENSION: 426 case XL_DIMENSION:
391 data = GetDataOfBREC(record); 427 data = GetDataOfBREC(record);
392 if (record->length == 10) 428 if (record->length == 10)
393 { 429 {
394 sheet->rows = Integer2Byte(data[2], data[3]); 430 sheet->rows = Integer2Byte(data[2], data[3]);
395 sheet->cols = Integer2Byte(data[6], data[7]); 431 sheet->cols = Integer2Byte(data[6], data[7]);
396 } else 432 }
397 { 433 else
398 sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); 434 {
399 sheet->cols = Integer2Byte(data[10], data[11]); 435 sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]);
400 } 436 sheet->cols = Integer2Byte(data[10], data[11]);
401 sheet->InitCells(); 437 }
402 break; 438 sheet->InitCells();
403 439 break;
404 case XL_LABELSST: 440
405 HandleLabelSST(sheet, record); 441 case XL_LABELSST:
406 break; 442 HandleLabelSST(sheet, record);
407 443 break;
408 case XL_RK: 444
409 case XL_RK2: 445 case XL_RK:
410 HandleRK(sheet, record); 446 case XL_RK2:
411 break; 447 HandleRK(sheet, record);
412 448 break;
413 case XL_MULRK: 449
414 HandleMulrk(sheet, record); 450 case XL_MULRK:
415 break; 451 HandleMulrk(sheet, record);
416 452 break;
417 case XL_ROW: 453
418 break; 454 case XL_ROW:
419 455 break;
420 case XL_NUMBER: 456
421 HandleNumber(sheet, record); 457 case XL_NUMBER:
422 break; 458 HandleNumber(sheet, record);
423 459 break;
424 case XL_BOOLERR: 460
425 break; 461 case XL_BOOLERR:
426 462 break;
427 case XL_CONTINUE: 463
428 break; 464 case XL_CONTINUE:
429 465 break;
430 case XL_FORMULA: 466
431 case XL_FORMULA2: 467 case XL_FORMULA:
432 HandleFormula(sheet, record); 468 case XL_FORMULA2:
433 break; 469 HandleFormula(sheet, record);
434 470 break;
435 case XL_LABEL: 471
436 break; 472 case XL_LABEL:
437 473 break;
438 case XL_NAME: 474
439 HandleName(sheet, record); 475 case XL_NAME:
440 break; 476 HandleName(sheet, record);
441 477 break;
442 case XL_BOF: 478
443 break; 479 case XL_BOF:
444 case XL_EOF: 480 break;
445 return 0; 481 case XL_EOF:
446 default: 482 return 0;
447 break; 483 default:
448 }; 484 break;
449 return 1; 485 };
486 return 1;
450}; 487};
451 488
452int ExcelBook::ReadSheet(ExcelSheet* sheet) 489int ExcelBook::ReadSheet(ExcelSheet* sheet)
453{ 490{
454 ExcelBREC* record; 491 ExcelBREC* record;
455 int oldpos; 492 int oldpos;
456 oldpos = Position; 493 oldpos = Position;
457 SeekPosition(sheet->position); 494 SeekPosition(sheet->position);
458 record = GetBREC(); 495 record = GetBREC();
459 while (record!=NULL) 496 while (record!=NULL)
460 { 497 {
461 if (!SheetHandleRecord(sheet, record)) break; 498 if (!SheetHandleRecord(sheet, record)) break;
462 record=GetBREC(); 499 record=GetBREC();
463 }; 500 };
464 SeekPosition(oldpos); 501 SeekPosition(oldpos);
465 return 1; 502 return 1;
466}; 503};
467 504
468ExcelSheet* ExcelBook::GetSheet(void) 505ExcelSheet* ExcelBook::GetSheet(void)
469{ 506{
470 ExcelSheet* sh=NULL; 507 ExcelSheet* sh=NULL;
471 int type; 508 int type;
472 type=SeekBOF(); 509 type=SeekBOF();
473 Version=type; 510 Version=type;
474 sh=new ExcelSheet; 511 sh=new ExcelSheet;
475 if(type) 512 if(type)
476 { 513 {
477 sh->type=type; 514 sh->type=type;
478 sh->position=Position; 515 sh->position=Position;
479 sh->name=QString(""); 516 sh->name=QString("");
480 }; 517 };
481 if(type==8||type==7) 518 if(type==8||type==7)
482 { 519 {
483 ReadSheet(sh); 520 ReadSheet(sh);
484 }; 521 };
485 return sh; 522 return sh;
486}; 523};
487 524
488void ExcelBook::ParseSheets(void) 525void ExcelBook::ParseSheets(void)
489{ 526{
490 int BOFs; 527 int BOFs;
491 ExcelBREC* r; 528 ExcelBREC* r;
492 BOFs=1; 529 BOFs=1;
493 r=GetBREC(); 530 r=GetBREC();
494 while(BOFs) 531 while(BOFs)
495 { 532 {
496 r=GetBREC(); 533 r=GetBREC();
497 switch(r->code) 534 switch(r->code)
498 { 535 {
499 case XL_SST: 536 case XL_SST:
500 HandleSST(r); 537 HandleSST(r);
501 break; 538 break;
502 539
503 case XL_TXO: 540 case XL_TXO:
504 break; 541 break;
505 case XL_NAME: 542 case XL_NAME:
506 break; 543 break;
507 case XL_ROW: 544 case XL_ROW:
508 break; 545 break;
509 546
510 case XL_FORMAT: 547 case XL_FORMAT:
511 HandleFormat(r); 548 HandleFormat(r);
512 break; 549 break;
513 550
514 case XL_XF: 551 case XL_XF:
515 HandleXF(r); 552 HandleXF(r);
516 break; 553 break;
517 554
518 case XL_BOUNDSHEET: 555 case XL_BOUNDSHEET:
519 HandleBoundSheet(r); 556 HandleBoundSheet(r);
520 break; 557 break;
521 558
522 case XL_EXTSST: 559 case XL_EXTSST:
523 break; 560 break;
524 case XL_CONTINUE: 561 case XL_CONTINUE:
525 break; 562 break;
526 563
527 case XL_EOF: 564 case XL_EOF:
528 BOFs--; 565 BOFs--;
529 break; 566 break;
530 567
531 default: 568 default:
532 break; 569 break;
533 }; 570 };
534 }; 571 };
535}; 572};
536 573
537void ExcelBook::GetSheets(void) 574void ExcelBook::GetSheets(void)
538{ 575{
539 ExcelSheet* sheet; 576 ExcelSheet* sheet;
540 Sheets.resize(0); 577 Sheets.resize(0);
541 sheet=GetSheet(); 578 sheet=GetSheet();
542 while (sheet->Cells.count()!= 0 ) 579 while (sheet->Cells.count()!= 0 )
543 { 580 {
544 Sheets.resize(Sheets.count()+1); 581 Sheets.resize(Sheets.count()+1);
545 Sheets[Sheets.count()-1]=sheet; 582 Sheets[Sheets.count()-1]=sheet;
546 sheet->name=*Names[Sheets.count()-1]; 583 sheet->name=*Names[Sheets.count()-1];
547 sheet=GetSheet(); 584 sheet=GetSheet();
548 }; 585 };
549}; 586};
550 587
551bool ExcelBook::ParseBook(char *file) 588bool ExcelBook::ParseBook(char *file)
552{ 589{
553 dateformat=QString(""); 590 dateformat=QString("");
554 DetectEndian(); 591 DetectEndian();
555 OpenFile(file); 592 OpenFile(file);
556 SeekBOF(); 593 SeekBOF();
557 ParseSheets(); 594 ParseSheets();
558 GetSheets(); 595 GetSheets();
559 return true; 596 return true;
560}; 597};
561 598
562QString ExcelBook::GetASCII(char* inbytes, int pos, int chars) 599QString ExcelBook::GetASCII(char* inbytes, int pos, int chars)
563{ 600{
564 int i; 601 int i;
565 QString outstr=""; 602 QString outstr="";
566 for (i = 0; i < chars; i++) 603 for (i = 0; i < chars; i++)
567 { 604 {
568 outstr.append(inbytes[i+pos]); 605 outstr.append(inbytes[i+pos]);
569 }; 606 };
570 return outstr; 607 return outstr;
571}; 608};
572 609
573QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars) 610QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars)
574{ 611{
575 QString outstr=""; 612 QString outstr="";
576 int i; 613 int i;
577 int rc; 614 int rc;
578 for (i=0; i<chars*2; i++) 615 for (i=0; i<chars*2; i++)
579 { 616 {
580 rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]); 617 rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]);
581 outstr.append(QChar(rc)); 618 outstr.append(QChar(rc));
582 i++; 619 i++;
583 }; 620 };
584 return outstr; 621 return outstr;
585}; 622};
586 623
@@ -588,37 +625,38 @@ QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars)
588void ExcelBook::HandleBoundSheet(ExcelBREC* rec) 625void ExcelBook::HandleBoundSheet(ExcelBREC* rec)
589{ 626{
590 char* data; 627 char* data;
591 int type; 628 int type;
592 int visibility; 629 int visibility;
593 int length; 630 int length;
594 int pos; 631 int pos;
595 QString name; 632 QString name;
596 pos = 8; 633 pos = 8;
597 data = GetDataOfBREC(rec); 634 data = GetDataOfBREC(rec);
598 type = data[4]; 635 type = data[4];
599 visibility = data[5]; 636 visibility = data[5];
600 length = data[6]; 637 length = data[6];
601 if(data[7]==0) 638 if(data[7]==0)
602 { 639 {
603 //ascii 640 //ascii
604 name=GetASCII(data,pos,length); 641 name=GetASCII(data,pos,length);
605 }else 642 }
606 { 643 else
607 name=GetUnicode(data,pos,length); 644 {
608 }; 645 name=GetUnicode(data,pos,length);
609 Names.resize(Names.count()+1); 646 };
610 Names[Names.count()-1]=new QString(name); 647 Names.resize(Names.count()+1);
648 Names[Names.count()-1]=new QString(name);
611}; 649};
612 650
613void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec) 651void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec)
614{ 652{
615 char* data; 653 char* data;
616 QString name; 654 QString name;
617 int length; 655 int length;
618 int pos; 656 int pos;
619 pos = 15; 657 pos = 15;
620 data = GetDataOfBREC(rec); 658 data = GetDataOfBREC(rec);
621 length = data[3]; 659 length = data[3];
622 name = GetASCII(data,pos,length); 660 name = GetASCII(data,pos,length);
623 661
624 662
@@ -627,76 +665,76 @@ void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec)
627ExcelFormat* ExcelBook::GetFormatting(int xf) 665ExcelFormat* ExcelBook::GetFormatting(int xf)
628{ 666{
629 int i; 667 int i;
630 ExcelFormat* rec; 668 ExcelFormat* rec;
631 rec=new ExcelFormat(); 669 rec=new ExcelFormat();
632 for (i = 0; formatter[i].code != 0; i++) 670 for (i = 0; formatter[i].code != 0; i++)
633 { 671 {
634 if (xf == formatter[i].code) break; 672 if (xf == formatter[i].code) break;
635 }; 673 };
636 if (formatter[i].format ==NULL) return NULL; 674 if (formatter[i].format ==NULL) return NULL;
637 rec->code = xf; 675 rec->code = xf;
638 rec->type = formatter[i].type; 676 rec->type = formatter[i].type;
639 rec->format = formatter[i].format; 677 rec->format = formatter[i].format;
640 return rec; 678 return rec;
641}; 679};
642 680
643void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes) 681void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes)
644{ 682{
645 QString str=QString(""); 683 QString str=QString("");
646 char* data; 684 char* data;
647 int chars, pos, options, i; 685 int chars, pos, options, i;
648 int richstring, fareaststring, runlength=0; 686 int richstring, fareaststring, runlength=0;
649 int richruns=0,fareastsize=0; 687 int richruns=0,fareastsize=0;
650 int totalstrings; 688 int totalstrings;
651 int uniquestrings; 689 int uniquestrings;
652 data = GetDataOfBREC(rec); 690 data = GetDataOfBREC(rec);
653 totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]); 691 totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]);
654 uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]); 692 uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]);
655 pos = 8; 693 pos = 8;
656 for (i = 0; i < uniquestrings; i++) 694 for (i = 0; i < uniquestrings; i++)
657 { 695 {
658 richruns=0; fareastsize=0; 696 richruns=0; fareastsize=0;
659 chars = Integer2Byte(data[pos], data[pos+1]); 697 chars = Integer2Byte(data[pos], data[pos+1]);
660 pos += 2; 698 pos += 2;
661 options = data[pos]; 699 options = data[pos];
662 pos++; 700 pos++;
663 fareaststring = ((options & 0x04) != 0); 701 fareaststring = ((options & 0x04) != 0);
664 richstring = ((options & 0x08) != 0); 702 richstring = ((options & 0x08) != 0);
665 if(richstring) 703 if(richstring)
666 { 704 {
667 richruns= Integer2Byte(data[pos],data[pos+1]); 705 richruns= Integer2Byte(data[pos],data[pos+1]);
668 pos+=2; 706 pos+=2;
669 }; 707 };
670 if(fareaststring) 708 if(fareaststring)
671 { 709 {
672 fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]); 710 fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]);
673 pos+=4; 711 pos+=4;
674 }; 712 };
675 713
676 if ((options & 0x01) == 0) //8 bit chars 714 if ((options & 0x01) == 0) //8 bit chars
677 { 715 {
678 /* ascii */ 716 /* ascii */
679 str = GetASCII(bytes,pos,chars); 717 str = GetASCII(bytes,pos,chars);
680 pos=pos+chars; 718 pos=pos+chars;
681 if(str[0]=='=') str[0]=' '; 719 if(str[0]=='=') str[0]=' ';
682 }else //16 bit chars 720 }else //16 bit chars
683 { 721 {
684 /* unicode */ 722 /* unicode */
685 str = GetUnicode(bytes,pos,chars); 723 str = GetUnicode(bytes,pos,chars);
686 pos=pos+chars*2; 724 pos=pos+chars*2;
687 }; 725 };
688 // HERE TO PUT richformat handling 726 // HERE TO PUT richformat handling
689 if (richstring) 727 if (richstring)
690 { 728 {
691 pos += 4 * richruns; 729 pos += 4 * richruns;
692 }; 730 };
693 if (fareaststring) 731 if (fareaststring)
694 { 732 {
695 pos += fareastsize; 733 pos += fareastsize;
696 }; 734 };
697 //printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode()); 735 //printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode());
698 SharedStrings.resize(SharedStrings.count()+1); 736 SharedStrings.resize(SharedStrings.count()+1);
699 SharedStrings[SharedStrings.count()-1]=new QString(str); 737 SharedStrings[SharedStrings.count()-1]=new QString(str);
700 } 738 }
701}; 739};
702 740
@@ -704,24 +742,24 @@ void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes)
704char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont) 742char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont)
705{ 743{
706 int i, pos; 744 int i, pos;
707 int length; 745 int length;
708 746
709 char* data; 747 char* data;
710 char* bytes; 748 char* bytes;
711 length = rec->length; 749 length = rec->length;
712 for (i = 0; i < (int) cont->rec.count(); i++) 750 for (i = 0; i < (int) cont->rec.count(); i++)
713 { 751 {
714 length += cont->rec[i]->length; 752 length += cont->rec[i]->length;
715 } 753 }
716 bytes = GetDataOfBREC(rec); 754 bytes = GetDataOfBREC(rec);
717 pos = rec->length; 755 pos = rec->length;
718 for (i = 0; i < (int) cont->rec.count(); i++) 756 for (i = 0; i < (int) cont->rec.count(); i++)
719 { 757 {
720 data = GetDataOfBREC(cont->rec[i]); 758 data = GetDataOfBREC(cont->rec[i]);
721 *bytes += pos; 759 *bytes += pos;
722 bytes = data; 760 bytes = data;
723 pos += cont->rec[i]->length; 761 pos += cont->rec[i]->length;
724 } 762 }
725 return bytes; 763 return bytes;
726}; 764};
727 765
@@ -729,139 +767,142 @@ char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont)
729void ExcelBook::HandleSST(ExcelBREC* rec) 767void ExcelBook::HandleSST(ExcelBREC* rec)
730{ 768{
731 char* bytes; 769 char* bytes;
732 SSTList* cont; 770 SSTList* cont;
733 cont= new SSTList; 771 cont= new SSTList;
734 ExcelBREC* nr; 772 ExcelBREC* nr;
735 nr = PeekBREC(); 773 nr = PeekBREC();
736 while (nr->code == XL_CONTINUE) 774 while (nr->code == XL_CONTINUE)
737 { 775 {
738 cont->rec.resize(cont->rec.count()+1); 776 cont->rec.resize(cont->rec.count()+1);
739 cont->rec[cont->rec.count()-1]=GetBREC(); 777 cont->rec[cont->rec.count()-1]=GetBREC();
740 nr = PeekBREC(); 778 nr = PeekBREC();
741 } 779 }
742 bytes = MergeBytesFromSSTs(rec,cont); 780 bytes = MergeBytesFromSSTs(rec,cont);
743 HandleSetOfSST(rec, bytes); 781 HandleSetOfSST(rec, bytes);
744 for(int w1=0;w1<(int)cont->rec.count();w1++) 782 for(int w1=0;w1<(int)cont->rec.count();w1++)
745 { 783 {
746 if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;}; 784 if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;};
747 }; 785 };
748 cont->rec.resize(0); 786 cont->rec.resize(0);
749}; 787};
750 788
751void ExcelBook::HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec) 789void ExcelBook::HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec)
752{ 790{
753 int index, row, col; 791 int index, row, col;
754 char* data; 792 char* data;
755 data = GetDataOfBREC(rec); 793 data = GetDataOfBREC(rec);
756 index = Integer4Byte(data[6], data[7], data[8], data[9]); 794 index = Integer4Byte(data[6], data[7], data[8], data[9]);
757 row = Integer2Byte(data[0], data[1]); 795 row = Integer2Byte(data[0], data[1]);
758 col = Integer2Byte(data[2], data[3]); 796 col = Integer2Byte(data[2], data[3]);
759 sheet->Set(row,col, CellLabel(row, col, *GetString(index))); 797 sheet->Set(row,col, CellLabel(row, col, *GetString(index)));
760}; 798};
761 799
762ExcelCell* ExcelBook::CellLabel(int row, int col, QString str) 800ExcelCell* ExcelBook::CellLabel(int row, int col, QString str)
763{ 801{
764 ExcelCell* c; 802 ExcelCell* c;
765 c= new ExcelCell; 803 c= new ExcelCell;
766 c->row = row; 804 c->row = row;
767 c->col = col; 805 c->col = col;
768 c->type = CELL_LABEL; 806 c->type = CELL_LABEL;
769 c->valuec = str; 807 c->valuec = str;
770 return c; 808 return c;
771}; 809};
772 810
773ExcelCell* ExcelBook::CellNumber(int row, int col, int index, double d) 811ExcelCell* ExcelBook::CellNumber(int row, int col, int index, double d)
774{ 812{
775 ExcelCell* c; 813 ExcelCell* c;
776 c=new ExcelCell; 814 c=new ExcelCell;
777 c->row = row; 815 c->row = row;
778 c->col = col; 816 c->col = col;
779 c->xfindex = index; 817 c->xfindex = index;
780 c->type = CELL_NUMBER; 818 c->type = CELL_NUMBER;
781 c->valued = d; 819 c->valued = d;
782 return c; 820 return c;
783}; 821};
784 822
785QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col) 823QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col)
786{ 824{
787 time_t date; 825 time_t date;
788 struct tm *tmptr; 826 struct tm *tmptr;
789 ExcelCell* c; 827 ExcelCell* c;
790 char str[128]; 828 char str[128];
791 QString format; 829 QString format;
792 int precision; 830 int precision;
793 int utcOffsetDays = 25569; 831 int utcOffsetDays = 25569;
794 int sInADay = 24 * 60 * 60; 832 int sInADay = 24 * 60 * 60;
795 c = sh->Get(row,col); 833 c = sh->Get(row,col);
796 if (c == NULL) return new QString(""); 834 if (c == NULL) return new QString("");
797 switch (c->type) 835 switch (c->type)
798 { 836 {
799 case CELL_LABEL: 837 case CELL_LABEL:
800 return new QString(c->valuec); 838 return new QString(c->valuec);
801 case CELL_NUMBER: 839 case CELL_NUMBER:
802 if (XFRecords[c->xfindex]->type == DATEFORMAT) 840 if (XFRecords[c->xfindex]->type == DATEFORMAT)
803 { 841 {
804 842
805 format = XFRecords[c->xfindex]->format; 843 format = XFRecords[c->xfindex]->format;
806 date = (time_t) ((c->valued - utcOffsetDays) * sInADay); 844 date = (time_t) ((c->valued - utcOffsetDays) * sInADay);
807 tmptr = gmtime(&date); 845 tmptr = gmtime(&date);
808 if (dateformat) 846 if (dateformat)
809 { 847 {
810 strftime(str,1024,dateformat.ascii(),tmptr); 848 strftime(str,1024,dateformat.ascii(),tmptr);
811 } else 849 }
812 { 850 else
813 strftime(str,1024,format.ascii(),tmptr); 851 {
814 }; 852 strftime(str,1024,format.ascii(),tmptr);
815 } else 853 };
816 if (XFRecords[c->xfindex]->type == NUMBERFORMAT) 854 }
817 { 855 else
818 format = XFRecords[c->xfindex]->format; 856 if (XFRecords[c->xfindex]->type == NUMBERFORMAT)
819 //sprintf(str,format.ascii(),c->valued); 857 {
820 // the real format is ignored... 858 format = XFRecords[c->xfindex]->format;
821 // because there is more work to be done in the field 859 //sprintf(str,format.ascii(),c->valued);
822 precision = CellGetPrecision(c->valued); 860 // the real format is ignored...
823 sprintf(str,"%.*f",precision,c->valued); 861 // because there is more work to be done in the field
824 }else 862 precision = CellGetPrecision(c->valued);
825 { 863 sprintf(str,"%.*f",precision,c->valued);
826 precision = CellGetPrecision(c->valued); 864 }
827 sprintf(str,"%.*f",precision,c->valued); 865 else
828 }; 866 {
829 break; 867 precision = CellGetPrecision(c->valued);
830 case CELL_DATE: 868 sprintf(str,"%.*f",precision,c->valued);
831 break; 869 };
832 case CELL_BOOLEAN: 870 break;
833 break; 871 case CELL_DATE:
834 case CELL_ERROR: 872 break;
835 break; 873 case CELL_BOOLEAN:
836 } 874 break;
837 return new QString(str); 875 case CELL_ERROR:
876 break;
877 }
878 return new QString(str);
838}; 879};
839 880
840int ExcelBook::CellGetPrecision(double d) 881int ExcelBook::CellGetPrecision(double d)
841{ 882{
842 double t; 883 double t;
843 int i,x; 884 int i,x;
844 int count; 885 int count;
845 if (d < 0) d *= -1; 886 if (d < 0) d *= -1;
846 i = (int)d; 887 i = (int)d;
847 t = d - (double)i; 888 t = d - (double)i;
848 if (t <= 0) 889 if (t <= 0)
849 { 890 {
850 return 0; 891 return 0;
851 }; 892 };
852 count = 0; 893 count = 0;
853 for (x = 6; x > 1; x--) 894 for (x = 6; x > 1; x--)
854 { 895 {
855 i = (int)d; 896 i = (int)d;
856 t = d - (double)i; 897 t = d - (double)i;
857 t *= pow(10,x - 2); 898 t *= pow(10,x - 2);
858 i = (int)t; 899 i = (int)t;
859 t = t - (double)i; 900 t = t - (double)i;
860 t *= 10; 901 t *= 10;
861 i = (int)t; 902 i = (int)t;
862 if (i > 0) break; 903 if (i > 0) break;
863 count++; 904 count++;
864 }; 905 };
865 return (5 - count); 906 return (5 - count);
866}; 907};
867 908
@@ -869,47 +910,47 @@ int ExcelBook::CellGetPrecision(double d)
869void ExcelBook::CellSetDateFormat(char *d) 910void ExcelBook::CellSetDateFormat(char *d)
870{ 911{
871 dateformat = QString(d); 912 dateformat = QString(d);
872}; 913};
873 914
874void ExcelBook::HandleMulrk(ExcelSheet* sheet, ExcelBREC* record) 915void ExcelBook::HandleMulrk(ExcelSheet* sheet, ExcelBREC* record)
875{ 916{
876 struct mulrk mulrk; 917 struct mulrk mulrk;
877 char* data; 918 char* data;
878 ExcelCell* cell; 919 ExcelCell* cell;
879 int len; 920 int len;
880 int i; 921 int i;
881 len = record->length; 922 len = record->length;
882 data = GetDataOfBREC(record); 923 data = GetDataOfBREC(record);
883 mulrk.row = Integer2Byte(data[0],data[1]); 924 mulrk.row = Integer2Byte(data[0],data[1]);
884 mulrk.first = Integer2Byte(data[2],data[3]); 925 mulrk.first = Integer2Byte(data[2],data[3]);
885 mulrk.last = Integer2Byte(data[len - 2],data[len - 1]); 926 mulrk.last = Integer2Byte(data[len - 2],data[len - 1]);
886 mulrk.numrks = mulrk.last - mulrk.first + 1; 927 mulrk.numrks = mulrk.last - mulrk.first + 1;
887 MulrkRead(&mulrk, data); 928 MulrkRead(&mulrk, data);
888 for (i = 0; i < mulrk.numrks; i++) 929 for (i = 0; i < mulrk.numrks; i++)
889 { 930 {
890 cell = CellNumber(mulrk.row, mulrk.first + i, mulrk.xfindices[i], mulrk.rkdbls[i]); 931 cell = CellNumber(mulrk.row, mulrk.first + i, mulrk.xfindices[i], mulrk.rkdbls[i]);
891 sheet->Set(mulrk.row,mulrk.first+ i, cell); 932 sheet->Set(mulrk.row,mulrk.first+ i, cell);
892 //printf("handleMULRK:row=%d,col=%d,val=%f\r\n",mulrk.row,mulrk.first+i,mulrk.rkdbls[i]); 933 //printf("handleMULRK:row=%d,col=%d,val=%f\r\n",mulrk.row,mulrk.first+i,mulrk.rkdbls[i]);
893 } 934 }
894 //delete(mulrk.xfindices); 935 //delete(mulrk.xfindices);
895 //delete(mulrk.rkdbls); 936 //delete(mulrk.rkdbls);
896}; 937};
897 938
898void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data) 939void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data)
899{ 940{
900 double d; 941 double d;
901 int i; 942 int i;
902 int pos; 943 int pos;
903 pos = 4; 944 pos = 4;
904 mulrk->xfindices.resize(mulrk->numrks); 945 mulrk->xfindices.resize(mulrk->numrks);
905 mulrk->rkdbls.resize(mulrk->numrks); 946 mulrk->rkdbls.resize(mulrk->numrks);
906 for (i = 0; i < mulrk->numrks; i++) 947 for (i = 0; i < mulrk->numrks; i++)
907 { 948 {
908 mulrk->xfindices[i] = Integer2Byte(data[pos], data[pos+1]); 949 mulrk->xfindices[i] = Integer2Byte(data[pos], data[pos+1]);
909 d=Double4Byte(data[pos+2], data[pos+3], data[pos+4], data[pos+5]); 950 d=Double4Byte(data[pos+2], data[pos+3], data[pos+4], data[pos+5]);
910 //printf("double:%f\r\n",d); 951 //printf("double:%f\r\n",d);
911 mulrk->rkdbls[i] = d; 952 mulrk->rkdbls[i] = d;
912 pos += 6; 953 pos += 6;
913 } 954 }
914}; 955};
915 956
@@ -917,30 +958,30 @@ void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data)
917void ExcelBook::HandleNumber(ExcelSheet* sheet, ExcelBREC* record) 958void ExcelBook::HandleNumber(ExcelSheet* sheet, ExcelBREC* record)
918{ 959{
919 int xfindex, row, col; 960 int xfindex, row, col;
920 char* data; 961 char* data;
921 double d; 962 double d;
922 data = GetDataOfBREC(record); 963 data = GetDataOfBREC(record);
923 row = Integer2Byte(data[0], data[1]); 964 row = Integer2Byte(data[0], data[1]);
924 col = Integer2Byte(data[2], data[3]); 965 col = Integer2Byte(data[2], data[3]);
925 xfindex = Integer2Byte(data[4], data[5]); 966 xfindex = Integer2Byte(data[4], data[5]);
926 #if defined(__arm__) && !defined(__vfp__) 967#if defined(__arm__) && !defined(__vfp__)
927 d=Double8Byte(data[10], data[11], data[12], data[13],data[6], data[7], data[8], data[9]); 968 d=Double8Byte(data[10], data[11], data[12], data[13],data[6], data[7], data[8], data[9]);
928 #else 969#else
929 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); 970 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]);
930 #endif 971#endif
931 //even if ARM is little endian... doubles are been placed as bigendian words. 972 //even if ARM is little endian... doubles are been placed as bigendian words.
932 //thanks pb_ for that. :) 973 //thanks pb_ for that. :)
933 sheet->Set(row,col, CellNumber(row,col,xfindex,d)); 974 sheet->Set(row,col, CellNumber(row,col,xfindex,d));
934 //printf("handleNumber:row=%d,col=%d,val=%f\r\n",row,col,d); 975 //printf("handleNumber:row=%d,col=%d,val=%f\r\n",row,col,d);
935}; 976};
936 977
937ExcelFormat::ExcelFormat() 978ExcelFormat::ExcelFormat()
938{ 979{
939code=0;type=0;format=""; 980 code=0;type=0;format="";
940}; 981};
941 982
942ExcelFormat::ExcelFormat(int c,int t, QString s) 983ExcelFormat::ExcelFormat(int c,int t, QString s)
943{ 984{
944 code=c;type=t;format=s; 985 code=c;type=t;format=s;
945}; 986};
946 987
@@ -948,29 +989,29 @@ ExcelFormat::ExcelFormat(int c,int t, QString s)
948void ExcelBook::HandleFormat(ExcelBREC* rec) 989void ExcelBook::HandleFormat(ExcelBREC* rec)
949{ 990{
950 ExcelFormat* xfrec; 991 ExcelFormat* xfrec;
951 char* data; 992 char* data;
952 int format; 993 int format;
953 data = GetDataOfBREC(rec); 994 data = GetDataOfBREC(rec);
954 format = Integer2Byte(data[2],data[3]); 995 format = Integer2Byte(data[2],data[3]);
955 xfrec = GetFormatting(format); 996 xfrec = GetFormatting(format);
956 /*int idx; 997 /*int idx;
957 idx=XFRecords.count()-1; 998 idx=XFRecords.count()-1;
958 XFRecords[idx]->code=xfrec->code; 999 XFRecords[idx]->code=xfrec->code;
959 XFRecords[idx]->type=xfrec->type; 1000 XFRecords[idx]->type=xfrec->type;
960 XFRecords[idx]->format="manos"; 1001 XFRecords[idx]->format="manos";
961 //XFRecords[XFRecords.count()-1]=xfrec; 1002 //XFRecords[XFRecords.count()-1]=xfrec;
962 printf("6\r\n");*/ 1003 printf("6\r\n");*/
963}; 1004};
964 1005
965void ExcelBook::HandleXF(ExcelBREC* rec) 1006void ExcelBook::HandleXF(ExcelBREC* rec)
966{ 1007{
967 ExcelFormat* xfrec; 1008 ExcelFormat* xfrec;
968 char* data; 1009 char* data;
969 int format; 1010 int format;
970 data = GetDataOfBREC(rec); 1011 data = GetDataOfBREC(rec);
971 format = Integer2Byte(data[2],data[3]); 1012 format = Integer2Byte(data[2],data[3]);
972 xfrec = GetFormatting(format); 1013 xfrec = GetFormatting(format);
973 XFRecords.resize(XFRecords.count()+1); 1014 XFRecords.resize(XFRecords.count()+1);
974 XFRecords[XFRecords.count()-1]=xfrec; 1015 XFRecords[XFRecords.count()-1]=xfrec;
975}; 1016};
976 1017
@@ -979,14 +1020,14 @@ void ExcelBook::HandleXF(ExcelBREC* rec)
979void ExcelBook::HandleRK(ExcelSheet* sheet, ExcelBREC* record) 1020void ExcelBook::HandleRK(ExcelSheet* sheet, ExcelBREC* record)
980{ 1021{
981 int xfindex, row, col; 1022 int xfindex, row, col;
982 char* data; 1023 char* data;
983 double d; 1024 double d;
984 data = GetDataOfBREC(record); 1025 data = GetDataOfBREC(record);
985 row = Integer2Byte(data[0], data[1]); 1026 row = Integer2Byte(data[0], data[1]);
986 col = Integer2Byte(data[2], data[3]); 1027 col = Integer2Byte(data[2], data[3]);
987 xfindex = Integer2Byte(data[4], data[5]); 1028 xfindex = Integer2Byte(data[4], data[5]);
988 d=Double4Byte(data[6], data[7], data[8], data[9]); 1029 d=Double4Byte(data[6], data[7], data[8], data[9]);
989 sheet->Set(row,col,CellNumber(row,col,xfindex,d)); 1030 sheet->Set(row,col,CellNumber(row,col,xfindex,d));
990 //printf("handleRK:row=%d,col=%d,val=%f\r\n",row,col,d); 1031 //printf("handleRK:row=%d,col=%d,val=%f\r\n",row,col,d);
991}; 1032};
992 1033
@@ -994,41 +1035,43 @@ void ExcelBook::HandleRK(ExcelSheet* sheet, ExcelBREC* record)
994void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record) 1035void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record)
995{ 1036{
996 int xfindex, row, col; 1037 int xfindex, row, col;
997 char* data; 1038 char* data;
998 double d; 1039 double d;
999 data = GetDataOfBREC(record); 1040 data = GetDataOfBREC(record);
1000 row = Integer2Byte(data[0], data[1]); 1041 row = Integer2Byte(data[0], data[1]);
1001 col = Integer2Byte(data[2], data[3]); 1042 col = Integer2Byte(data[2], data[3]);
1002 if (data[6] == 0 && data[12] == -1 && data[13] == -1) 1043 if (data[6] == 0 && data[12] == -1 && data[13] == -1)
1003 { 1044 {
1004 // string 1045 // string
1005 } else 1046 }
1006 if (data[6] == 1 && data[12] == -1 && data[13] == -1) 1047 else
1007 { 1048 if (data[6] == 1 && data[12] == -1 && data[13] == -1)
1008 // boolean 1049 {
1009 } else 1050 // boolean
1010 if ( data[6] == 2 && data[12] == -1 && data[13] == -1) 1051 }
1011 { 1052 else
1012 // error 1053 if ( data[6] == 2 && data[12] == -1 && data[13] == -1)
1013 } 1054 {
1014 else 1055 // error
1015 { 1056 }
1016 // number 1057 else
1017 xfindex = Integer2Byte(data[4], data[5]); 1058 {
1018 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); 1059 // number
1019 QString s1; 1060 xfindex = Integer2Byte(data[4], data[5]);
1020 int sz; 1061 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]);
1021 sz=Integer2Byte(data[20],data[21]);// size of the formula 1062 QString s1;
1022 char* formuladata; 1063 int sz;
1023 formuladata=new char[sz]; 1064 sz=Integer2Byte(data[20],data[21]);// size of the formula
1024 for(int w1=0;w1<sz;w1++) 1065 char* formuladata;
1025 { 1066 formuladata=new char[sz];
1026 formuladata[w1]=data[22+w1]; 1067 for(int w1=0;w1<sz;w1++)
1027 }; 1068 {
1028 //22 is the first 0 idx of formula data 1069 formuladata[w1]=data[22+w1];
1029 s1="="+GetFormula(row,col,sheet,formuladata,sz); 1070 };
1030 //printf("GetFormula:Formula=%s\r\n",s1.ascii()); 1071 //22 is the first 0 idx of formula data
1031 sheet->Set(row,col,CellLabel(row,col,s1)); 1072 s1="="+GetFormula(row,col,sheet,formuladata,sz);
1032 } 1073 //printf("GetFormula:Formula=%s\r\n",s1.ascii());
1074 sheet->Set(row,col,CellLabel(row,col,s1));
1075 }
1033}; 1076};
1034 1077
@@ -1036,619 +1079,623 @@ void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record)
1036QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz) 1079QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz)
1037{ 1080{
1038 int length=sz; 1081 int length=sz;
1039 printf("{FormulaParser}\r\n"); 1082 printf("{FormulaParser}\r\n");
1040 printf("row=%d, col=%d, length=%d\r\n",row,col,length); 1083 printf("row=%d, col=%d, length=%d\r\n",row,col,length);
1041 int idx=0; 1084 int idx=0;
1042 int w1,w2,w3,w4; 1085 int w1,w2,w3,w4;
1043 double d1; 1086 double d1;
1044 int token; 1087 int token;
1045 QString s1; 1088 QString s1;
1046 QList <QString> operands; 1089 QList <QString> operands;
1047 operands.setAutoDelete(TRUE); 1090 operands.setAutoDelete(TRUE);
1048 QString formula; 1091 QString formula;
1049 operands.clear(); 1092 operands.clear();
1050 while( idx<length ) 1093 while( idx<length )
1051 { 1094 {
1052 token= data[idx]; idx++; 1095 token= data[idx]; idx++;
1053 switch(token) 1096 switch(token)
1054 { 1097 {
1055 case 0x1E: //prtInt 1098 case 0x1E: //prtInt
1056 w1=Integer2Byte(data[idx],data[idx+1]); 1099 w1=Integer2Byte(data[idx],data[idx+1]);
1057 idx=idx+2; 1100 idx=idx+2;
1058 operands.prepend(new QString(QString::number(w1))); 1101 operands.prepend(new QString(QString::number(w1)));
1059 printf(" token:ptgInt,num=%d\r\n",w1); 1102 printf(" token:ptgInt,num=%d\r\n",w1);
1060 break; 1103 break;
1061 case 0x1F: //ptgNumber 1104 case 0x1F: //ptgNumber
1062 #if defined(__arm__) && !defined(__vfp__) 1105#if defined(__arm__) && !defined(__vfp__)
1063 d1=Double8Byte(data[idx+4],data[idx+5],data[idx+6],data[idx+7] 1106 d1=Double8Byte(data[idx+4],data[idx+5],data[idx+6],data[idx+7]
1064 ,data[idx],data[idx+1],data[idx+2],data[idx+3]); 1107 ,data[idx],data[idx+1],data[idx+2],data[idx+3]);
1065 #else 1108#else
1066 d1=Double8Byte(data[idx],data[idx+1],data[idx+2],data[idx+3] 1109 d1=Double8Byte(data[idx],data[idx+1],data[idx+2],data[idx+3]
1067 ,data[idx+4],data[idx+5],data[idx+6],data[idx+7]); 1110 ,data[idx+4],data[idx+5],data[idx+6],data[idx+7]);
1068 #endif 1111#endif
1069 idx=idx+8; 1112 idx=idx+8;
1070 operands.prepend(new QString(QString::number(d1))); 1113 operands.prepend(new QString(QString::number(d1)));
1071 printf(" token:ptgNumber,num=%f\r\n",d1); 1114 printf(" token:ptgNumber,num=%f\r\n",d1);
1072 break; 1115 break;
1073 case 0x17: //ptgStr 1116 case 0x17: //ptgStr
1074 if(Version==8) 1117 if(Version==8)
1075 { 1118 {
1076 //unicode string 1119 //unicode string
1077 //w1=Integer2Byte(data[idx],data[idx+1]);idx+=2; 1120 //w1=Integer2Byte(data[idx],data[idx+1]);idx+=2;
1078 w1=data[idx];idx++; 1121 w1=data[idx];idx++;
1079 printf("len=%d\r\n",w1); 1122 printf("len=%d\r\n",w1);
1080 int richruns=0; int fareastsize=0; 1123 int richruns=0; int fareastsize=0;
1081 int richstring,fareaststring; 1124 int richstring,fareaststring;
1082 int options = data[idx];idx++; 1125 int options = data[idx];idx++;
1083 fareaststring = ((options & 0x04) != 0); 1126 fareaststring = ((options & 0x04) != 0);
1084 richstring = ((options & 0x08) != 0); 1127 richstring = ((options & 0x08) != 0);
1085 if(richstring) 1128 if(richstring)
1086 { 1129 {
1087 //containts rich string formatting. 1130 //containts rich string formatting.
1088 printf("STRING:richstring\r\n"); 1131 printf("STRING:richstring\r\n");
1089 richruns= Integer2Byte(data[idx],data[idx+1]); 1132 richruns= Integer2Byte(data[idx],data[idx+1]);
1090 printf("richruns:%d\r\n",richruns); 1133 printf("richruns:%d\r\n",richruns);
1091 idx+=2; 1134 idx+=2;
1092 }; 1135 };
1093 if(fareaststring) 1136 if(fareaststring)
1094 { 1137 {
1095 //contains far east formatting 1138 //contains far east formatting
1096 printf("STRING:fareast!\r\n"); 1139 printf("STRING:fareast!\r\n");
1097 fareastsize=Integer4Byte(data[idx], data[idx+1], 1140 fareastsize=Integer4Byte(data[idx], data[idx+1],
1098 data[idx+2], data[idx+3]); 1141 data[idx+2], data[idx+3]);
1099 printf("fareastsize=%d",fareastsize); 1142 printf("fareastsize=%d",fareastsize);
1100 idx+=4; 1143 idx+=4;
1101 }; 1144 };
1102 if ((options & 0x01) == 0) //8 bit chars 1145 if ((options & 0x01) == 0) //8 bit chars
1103 { 1146 {
1104 /* ascii */ 1147 /* ascii */
1105 s1 = GetASCII(data,idx,w1); 1148 s1 = GetASCII(data,idx,w1);
1106 idx=idx+w1; 1149 idx=idx+w1;
1107 printf("STRING:ASCII=%s\r\n",s1.ascii()); 1150 printf("STRING:ASCII=%s\r\n",s1.ascii());
1108 }else //16 bit chars 1151 }else //16 bit chars
1109 { 1152 {
1110 /* unicode */ 1153 /* unicode */
1111 s1 = GetUnicode(data,idx,w1); 1154 s1 = GetUnicode(data,idx,w1);
1112 idx=idx+w1*2; 1155 idx=idx+w1*2;
1113 printf("STRING:unicode=%s\r\n",s1.ascii()); 1156 printf("STRING:unicode=%s\r\n",s1.ascii());
1114 }; 1157 };
1115 // HERE TO PUT richformat handling 1158 // HERE TO PUT richformat handling
1116 if (richstring) 1159 if (richstring)
1117 { 1160 {
1118 idx += 4 * richruns; 1161 idx += 4 * richruns;
1119 }; 1162 };
1120 if (fareaststring) 1163 if (fareaststring)
1121 { 1164 {
1122 idx += fareastsize; 1165 idx += fareastsize;
1123 }; 1166 };
1124 s1=QString("""")+s1+QString(""""); 1167 s1=QString("""")+s1+QString("""");
1125 operands.prepend(new QString(s1)); 1168 operands.prepend(new QString(s1));
1126 }else 1169 }
1127 { 1170 else
1128 w1=data[idx];idx++; 1171 {
1129 s1=GetASCII(data,idx,w1); 1172 w1=data[idx];idx++;
1130 s1=QString("""")+s1+QString(""""); 1173 s1=GetASCII(data,idx,w1);
1131 idx=idx+w1; 1174 s1=QString("""")+s1+QString("""");
1132 operands.prepend(new QString(s1)); 1175 idx=idx+w1;
1133 }; 1176 operands.prepend(new QString(s1));
1134 printf(" token:ptgStr,num=%d\r\n",w1); 1177 };
1135 break; 1178 printf(" token:ptgStr,num=%d\r\n",w1);
1136 case 0x25: 1179 break;
1137 case 0x45: 1180 case 0x25:
1138 case 0x65: // ptgArea 1181 case 0x45:
1139 if(Version==8) 1182 case 0x65: // ptgArea
1140 { 1183 if(Version==8)
1141 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row1 1184 {
1142 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2 1185 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row1
1143 w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1 1186 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2
1144 w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2 1187 w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1
1145 }else 1188 w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2
1146 { 1189 }
1147 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1 1190 else
1148 w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2 1191 {
1149 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col1 1192 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1
1150 w4=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col2 1193 w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2
1151 }; 1194 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col1
1152 //ignores relative or absolute refs 1195 w4=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col2
1153 s1=FindCellName(w1,w3)+":"+FindCellName(w2,w4); 1196 };
1154 printf(" token:ptgArea,ref=%s\r\n",s1.ascii()); 1197 //ignores relative or absolute refs
1155 operands.prepend(new QString(s1)); 1198 s1=FindCellName(w1,w3)+":"+FindCellName(w2,w4);
1156 break; 1199 printf(" token:ptgArea,ref=%s\r\n",s1.ascii());
1157 case 0x24: 1200 operands.prepend(new QString(s1));
1158 case 0x44: 1201 break;
1159 case 0x64://ptgRef 1202 case 0x24:
1160 if(Version==8) 1203 case 0x44:
1161 { 1204 case 0x64://ptgRef
1162 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row 1205 if(Version==8)
1163 w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col 1206 {
1164 }else 1207 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row
1165 { 1208 w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col
1166 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row 1209 }
1167 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col 1210 else
1168 }; 1211 {
1169 s1=FindCellName(w1,w2); 1212 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row
1170 printf("token:ptgRef,ref=%s\r\n",s1.ascii()); 1213 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col
1171 operands.prepend(new QString(s1)); 1214 };
1172 break; 1215 s1=FindCellName(w1,w2);
1173 case 0x1D: // ptgBool 1216 printf("token:ptgRef,ref=%s\r\n",s1.ascii());
1174 w1=data[idx];idx++; 1217 operands.prepend(new QString(s1));
1175 printf("token:ptgBool,val=%d\r\n",w1); 1218 break;
1176 operands.prepend(new QString(QString::number(w1))); 1219 case 0x1D: // ptgBool
1177 break; 1220 w1=data[idx];idx++;
1178 case 0x16://ptg MissArg 1221 printf("token:ptgBool,val=%d\r\n",w1);
1179 printf("token:ptgMissArg, val=' '\r\n"); 1222 operands.prepend(new QString(QString::number(w1)));
1180 operands.prepend(new QString("0")); 1223 break;
1181 break; 1224 case 0x16://ptg MissArg
1182 case 0x12://ptgUplus== 1225 printf("token:ptgMissArg, val=' '\r\n");
1183 printf("token:ptgUplus\r\n"); 1226 operands.prepend(new QString("0"));
1184 s1=QString("+")+operands.first()->ascii(); 1227 break;
1185 operands.removeFirst(); 1228 case 0x12://ptgUplus==
1186 operands.prepend(new QString(s1)); 1229 printf("token:ptgUplus\r\n");
1187 break; 1230 s1=QString("+")+operands.first()->ascii();
1188 case 0x13://ptgUminus 1231 operands.removeFirst();
1189 printf("token:ptgUminus\r\n"); 1232 operands.prepend(new QString(s1));
1190 s1=QString("-")+operands.first()->ascii(); 1233 break;
1191 operands.removeFirst(); 1234 case 0x13://ptgUminus
1192 operands.prepend(new QString(s1)); 1235 printf("token:ptgUminus\r\n");
1193 break; 1236 s1=QString("-")+operands.first()->ascii();
1194 case 0x03://ptgAdd 1237 operands.removeFirst();
1195 printf("token:ptgAdd\r\n"); 1238 operands.prepend(new QString(s1));
1196 operands.first(); 1239 break;
1197 s1=operands.next()->ascii() 1240 case 0x03://ptgAdd
1198 +QString("+")+operands.first()->ascii(); 1241 printf("token:ptgAdd\r\n");
1199 operands.removeFirst();operands.removeFirst(); 1242 operands.first();
1200 operands.prepend(new QString(s1)); 1243 s1=operands.next()->ascii()
1201 break; 1244 +QString("+")+operands.first()->ascii();
1202 case 0x04://ptgSub 1245 operands.removeFirst();operands.removeFirst();
1203 printf("token:ptgSub\r\n"); 1246 operands.prepend(new QString(s1));
1204 operands.first(); 1247 break;
1205 s1=operands.next()->ascii() 1248 case 0x04://ptgSub
1206 +QString("-")+operands.first()->ascii(); 1249 printf("token:ptgSub\r\n");
1207 operands.removeFirst();operands.removeFirst(); 1250 operands.first();
1208 operands.prepend(new QString(s1)); 1251 s1=operands.next()->ascii()
1209 break; 1252 +QString("-")+operands.first()->ascii();
1210 case 0x05://ptgMul 1253 operands.removeFirst();operands.removeFirst();
1211 printf("token:ptgMul\r\n"); 1254 operands.prepend(new QString(s1));
1212 operands.first(); 1255 break;
1213 s1=operands.next()->ascii() 1256 case 0x05://ptgMul
1214 +QString("*")+operands.first()->ascii(); 1257 printf("token:ptgMul\r\n");
1215 operands.removeFirst();operands.removeFirst(); 1258 operands.first();
1216 operands.prepend(new QString(s1)); 1259 s1=operands.next()->ascii()
1217 break; 1260 +QString("*")+operands.first()->ascii();
1218 case 0x06://ptgDiv 1261 operands.removeFirst();operands.removeFirst();
1219 printf("token:ptgDiv\r\n"); 1262 operands.prepend(new QString(s1));
1220 operands.first(); 1263 break;
1221 s1=operands.next()->ascii() 1264 case 0x06://ptgDiv
1222 +QString("/")+operands.first()->ascii(); 1265 printf("token:ptgDiv\r\n");
1223 operands.removeFirst();operands.removeFirst(); 1266 operands.first();
1224 operands.prepend(new QString(s1)); 1267 s1=operands.next()->ascii()
1225 break; 1268 +QString("/")+operands.first()->ascii();
1226 case 0x07://ptgPOWER 1269 operands.removeFirst();operands.removeFirst();
1227 printf("token:ptgPow\r\n"); 1270 operands.prepend(new QString(s1));
1228 operands.first(); 1271 break;
1229 s1=QString("POWER(")+operands.next()->ascii() 1272 case 0x07://ptgPOWER
1230 +QString(",")+operands.first()->ascii()+QString(")"); 1273 printf("token:ptgPow\r\n");
1231 operands.removeFirst();operands.removeFirst(); 1274 operands.first();
1232 operands.prepend(new QString(s1)); 1275 s1=QString("POWER(")+operands.next()->ascii()
1233 break; 1276 +QString(",")+operands.first()->ascii()+QString(")");
1234 case 0x08://ptgConcat 1277 operands.removeFirst();operands.removeFirst();
1235 printf("token:ptgConcat\r\n"); 1278 operands.prepend(new QString(s1));
1236 operands.first(); 1279 break;
1237 s1=QString("CONCATENATE(")+operands.next()->ascii() 1280 case 0x08://ptgConcat
1238 +QString(",")+operands.first()->ascii()+QString(")"); 1281 printf("token:ptgConcat\r\n");
1239 operands.removeFirst();operands.removeFirst(); 1282 operands.first();
1240 operands.prepend(new QString(s1)); 1283 s1=QString("CONCATENATE(")+operands.next()->ascii()
1241 break; 1284 +QString(",")+operands.first()->ascii()+QString(")");
1242 case 0x15://ptgParenthesis 1285 operands.removeFirst();operands.removeFirst();
1243 printf("token:ptgParenthesis\r\n"); 1286 operands.prepend(new QString(s1));
1244 s1=QString("(")+operands.first()->ascii()+QString(")"); 1287 break;
1245 operands.removeFirst(); 1288 case 0x15://ptgParenthesis
1246 operands.prepend(new QString(s1)); 1289 printf("token:ptgParenthesis\r\n");
1247 break; 1290 s1=QString("(")+operands.first()->ascii()+QString(")");
1248 case 0x14://ptgPercent 1291 operands.removeFirst();
1249 printf("token:ptgPercent\r\n"); 1292 operands.prepend(new QString(s1));
1250 s1=operands.first()->ascii()+QString("*0.01"); 1293 break;
1251 operands.removeFirst(); 1294 case 0x14://ptgPercent
1252 operands.prepend(new QString(s1)); 1295 printf("token:ptgPercent\r\n");
1253 break; 1296 s1=operands.first()->ascii()+QString("*0.01");
1254 case 0x9://ptgLessThan 1297 operands.removeFirst();
1255 printf("token:ptgLESS\r\n"); 1298 operands.prepend(new QString(s1));
1256 operands.first(); 1299 break;
1257 s1=operands.next()->ascii() 1300 case 0x9://ptgLessThan
1258 +QString("<")+operands.first()->ascii(); 1301 printf("token:ptgLESS\r\n");
1259 operands.removeFirst();operands.removeFirst(); 1302 operands.first();
1260 operands.prepend(new QString(s1)); 1303 s1=operands.next()->ascii()
1261 break; 1304 +QString("<")+operands.first()->ascii();
1262 case 0xa://ptgLessEqual 1305 operands.removeFirst();operands.removeFirst();
1263 printf("token:ptgLESS_EQUAL\r\n"); 1306 operands.prepend(new QString(s1));
1264 operands.first(); 1307 break;
1265 s1=operands.next()->ascii() 1308 case 0xa://ptgLessEqual
1266 +QString("<=")+operands.first()->ascii(); 1309 printf("token:ptgLESS_EQUAL\r\n");
1267 operands.removeFirst();operands.removeFirst(); 1310 operands.first();
1268 operands.prepend(new QString(s1)); 1311 s1=operands.next()->ascii()
1269 break; 1312 +QString("<=")+operands.first()->ascii();
1270 case 0xb://ptgEQUAL 1313 operands.removeFirst();operands.removeFirst();
1271 printf("token:ptgEQUAL\r\n"); 1314 operands.prepend(new QString(s1));
1272 operands.first(); 1315 break;
1273 s1=operands.next()->ascii() 1316 case 0xb://ptgEQUAL
1274 +QString("==")+operands.first()->ascii(); 1317 printf("token:ptgEQUAL\r\n");
1275 operands.removeFirst();operands.removeFirst(); 1318 operands.first();
1276 operands.prepend(new QString(s1)); 1319 s1=operands.next()->ascii()
1277 break; 1320 +QString("==")+operands.first()->ascii();
1278 case 0xc://ptgGREATER_EQUAL 1321 operands.removeFirst();operands.removeFirst();
1279 printf("token:ptgGREAT_EQUAL\r\n"); 1322 operands.prepend(new QString(s1));
1280 operands.first(); 1323 break;
1281 s1=operands.next()->ascii() 1324 case 0xc://ptgGREATER_EQUAL
1282 +QString(">=")+operands.first()->ascii(); 1325 printf("token:ptgGREAT_EQUAL\r\n");
1283 operands.removeFirst();operands.removeFirst(); 1326 operands.first();
1284 operands.prepend(new QString(s1)); 1327 s1=operands.next()->ascii()
1285 break; 1328 +QString(">=")+operands.first()->ascii();
1286 case 0xd://ptgGREAT_THAN 1329 operands.removeFirst();operands.removeFirst();
1287 printf("token:ptgGREAT_THAN\r\n"); 1330 operands.prepend(new QString(s1));
1288 operands.first(); 1331 break;
1289 s1=operands.next()->ascii() 1332 case 0xd://ptgGREAT_THAN
1290 +QString(">")+operands.first()->ascii(); 1333 printf("token:ptgGREAT_THAN\r\n");
1291 operands.removeFirst();operands.removeFirst(); 1334 operands.first();
1292 operands.prepend(new QString(s1)); 1335 s1=operands.next()->ascii()
1293 break; 1336 +QString(">")+operands.first()->ascii();
1294 case 0xe://ptgNOT_EQUAL 1337 operands.removeFirst();operands.removeFirst();
1295 printf("token:ptgNOTequal\r\n"); 1338 operands.prepend(new QString(s1));
1296 operands.first(); 1339 break;
1297 s1=operands.next()->ascii() 1340 case 0xe://ptgNOT_EQUAL
1298 +QString("!=")+operands.first()->ascii(); 1341 printf("token:ptgNOTequal\r\n");
1299 operands.removeFirst();operands.removeFirst(); 1342 operands.first();
1300 operands.prepend(new QString(s1)); 1343 s1=operands.next()->ascii()
1301 break; 1344 +QString("!=")+operands.first()->ascii();
1302 case 0x19://attribute can be Sum,If,Choose 1345 operands.removeFirst();operands.removeFirst();
1303 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; 1346 operands.prepend(new QString(s1));
1304 idx++; 1347 break;
1305 printf("token:ATTRIBUTE:0x%x\r\n",w3); 1348 case 0x19://attribute can be Sum,If,Choose
1306 for(w4=idx;w4<length;w4++) 1349 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;
1307 printf("0x%x, ",data[w4]); 1350 idx++;
1308 if(w3&0x01)//choose 1351 printf("token:ATTRIBUTE:0x%x\r\n",w3);
1309 { 1352 for(w4=idx;w4<length;w4++)
1310 printf("token:CHOOSE\r\n"); 1353 printf("0x%x, ",data[w4]);
1311 } 1354 if(w3&0x01)//choose
1312 else if(w3&0x02)//if 1355 {
1313 { 1356 printf("token:CHOOSE\r\n");
1314 printf("token:IF\r\n"); 1357 }
1315 } 1358 else if(w3&0x02)//if
1316 else if(w3&0x10)//sum 1359 {
1317 { 1360 printf("token:IF\r\n");
1318 printf("token:SUM\r\n"); 1361 }
1319 }; 1362 else if(w3&0x10)//sum
1320 1363 {
1321 break; 1364 printf("token:SUM\r\n");
1322 1365 };
1323 1366
1324 case 0x21: 1367 break;
1325 case 0x22: 1368
1326 case 0x42: 1369
1327 case 0x62: 1370 case 0x21:
1328 case 0x41: 1371 case 0x22:
1329 case 0x61://ptgFunction 1372 case 0x42:
1330 printf("token:ptgFunction\r\n"); 1373 case 0x62:
1331 if(token==0x22||token==0x42||token==0x62) 1374 case 0x41:
1332 { 1375 case 0x61://ptgFunction
1333 w2=(int)data[idx];idx++; 1376 printf("token:ptgFunction\r\n");
1334 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; 1377 if(token==0x22||token==0x42||token==0x62)
1335 }else 1378 {
1336 { 1379 w2=(int)data[idx];idx++;
1337 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; 1380 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;
1338 }; 1381 }
1339 switch(w1) 1382 else
1340 { 1383 {
1341 case 0xf://SIN 1384 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;
1342 s1=QString("SIN(")+operands.first()->ascii()+QString(")"); 1385 };
1343 operands.removeFirst(); 1386 switch(w1)
1344 operands.prepend(new QString(s1)); 1387 {
1345 break; 1388 case 0xf://SIN
1346 case 0x10://COS 1389 s1=QString("SIN(")+operands.first()->ascii()+QString(")");
1347 s1=QString("COS(")+operands.first()->ascii()+QString(")"); 1390 operands.removeFirst();
1348 operands.removeFirst(); 1391 operands.prepend(new QString(s1));
1349 operands.prepend(new QString(s1)); 1392 break;
1350 break; 1393 case 0x10://COS
1351 case 0x11://tan 1394 s1=QString("COS(")+operands.first()->ascii()+QString(")");
1352 s1=QString("TAN(")+operands.first()->ascii()+QString(")"); 1395 operands.removeFirst();
1353 operands.removeFirst(); 1396 operands.prepend(new QString(s1));
1354 operands.prepend(new QString(s1)); 1397 break;
1355 break; 1398 case 0x11://tan
1356 case 0x62://asin 1399 s1=QString("TAN(")+operands.first()->ascii()+QString(")");
1357 s1=QString("ASIN(")+operands.first()->ascii()+QString(")"); 1400 operands.removeFirst();
1358 operands.removeFirst(); 1401 operands.prepend(new QString(s1));
1359 operands.prepend(new QString(s1)); 1402 break;
1360 break; 1403 case 0x62://asin
1361 case 0x63://ACOS 1404 s1=QString("ASIN(")+operands.first()->ascii()+QString(")");
1362 s1=QString("ACOS(")+operands.first()->ascii()+QString(")"); 1405 operands.removeFirst();
1363 operands.removeFirst(); 1406 operands.prepend(new QString(s1));
1364 operands.prepend(new QString(s1)); 1407 break;
1365 break; 1408 case 0x63://ACOS
1366 case 0x12://ATAN 1409 s1=QString("ACOS(")+operands.first()->ascii()+QString(")");
1367 s1=QString("ATAN(")+operands.first()->ascii()+QString(")"); 1410 operands.removeFirst();
1368 operands.removeFirst(); 1411 operands.prepend(new QString(s1));
1369 operands.prepend(new QString(s1)); 1412 break;
1370 break; 1413 case 0x12://ATAN
1371 case 0xe5://SINH 1414 s1=QString("ATAN(")+operands.first()->ascii()+QString(")");
1372 s1=QString("SINH(")+operands.first()->ascii()+QString(")"); 1415 operands.removeFirst();
1373 operands.removeFirst(); 1416 operands.prepend(new QString(s1));
1374 operands.prepend(new QString(s1)); 1417 break;
1375 break; 1418 case 0xe5://SINH
1376 case 0xe6://COSH 1419 s1=QString("SINH(")+operands.first()->ascii()+QString(")");
1377 s1=QString("COSH(")+operands.first()->ascii()+QString(")"); 1420 operands.removeFirst();
1378 operands.removeFirst(); 1421 operands.prepend(new QString(s1));
1379 operands.prepend(new QString(s1)); 1422 break;
1380 break; 1423 case 0xe6://COSH
1381 case 0xe7://TANH 1424 s1=QString("COSH(")+operands.first()->ascii()+QString(")");
1382 s1=QString("TANH(")+operands.first()->ascii()+QString(")"); 1425 operands.removeFirst();
1383 operands.removeFirst(); 1426 operands.prepend(new QString(s1));
1384 operands.prepend(new QString(s1)); 1427 break;
1385 break; 1428 case 0xe7://TANH
1386 case 0xe8://ASINH 1429 s1=QString("TANH(")+operands.first()->ascii()+QString(")");
1387 s1=QString("ASINH(")+operands.first()->ascii()+QString(")"); 1430 operands.removeFirst();
1388 operands.removeFirst(); 1431 operands.prepend(new QString(s1));
1389 operands.prepend(new QString(s1)); 1432 break;
1390 break; 1433 case 0xe8://ASINH
1391 case 0xe9://ACOSH 1434 s1=QString("ASINH(")+operands.first()->ascii()+QString(")");
1392 s1=QString("ACOSH(")+operands.first()->ascii()+QString(")"); 1435 operands.removeFirst();
1393 operands.removeFirst(); 1436 operands.prepend(new QString(s1));
1394 operands.prepend(new QString(s1)); 1437 break;
1395 break; 1438 case 0xe9://ACOSH
1396 case 0xea://ATANH 1439 s1=QString("ACOSH(")+operands.first()->ascii()+QString(")");
1397 s1=QString("ATANH(")+operands.first()->ascii()+QString(")"); 1440 operands.removeFirst();
1398 operands.removeFirst(); 1441 operands.prepend(new QString(s1));
1399 operands.prepend(new QString(s1)); 1442 break;
1400 break; 1443 case 0xea://ATANH
1401 case 0x13://pi 1444 s1=QString("ATANH(")+operands.first()->ascii()+QString(")");
1402 s1="PI()"; 1445 operands.removeFirst();
1403 operands.prepend(new QString(s1)); 1446 operands.prepend(new QString(s1));
1404 break; 1447 break;
1405 case 0x14://sqrt 1448 case 0x13://pi
1406 s1=QString("SQRT(")+operands.first()->ascii()+QString(")"); 1449 s1="PI()";
1407 operands.removeFirst(); 1450 operands.prepend(new QString(s1));
1408 operands.prepend(new QString(s1)); 1451 break;
1409 break; 1452 case 0x14://sqrt
1410 case 0x15://exp 1453 s1=QString("SQRT(")+operands.first()->ascii()+QString(")");
1411 s1=QString("EXP(")+operands.first()->ascii()+QString(")"); 1454 operands.removeFirst();
1412 operands.removeFirst(); 1455 operands.prepend(new QString(s1));
1413 operands.prepend(new QString(s1)); 1456 break;
1414 break; 1457 case 0x15://exp
1415 case 0x16://LN 1458 s1=QString("EXP(")+operands.first()->ascii()+QString(")");
1416 s1=QString("LN(")+operands.first()->ascii()+QString(")"); 1459 operands.removeFirst();
1417 operands.removeFirst(); 1460 operands.prepend(new QString(s1));
1418 operands.prepend(new QString(s1)); 1461 break;
1419 break; 1462 case 0x16://LN
1420 case 0x17://LOG10 1463 s1=QString("LN(")+operands.first()->ascii()+QString(")");
1421 s1=QString("LOG10(")+operands.first()->ascii()+QString(")"); 1464 operands.removeFirst();
1422 operands.removeFirst(); 1465 operands.prepend(new QString(s1));
1423 operands.prepend(new QString(s1)); 1466 break;
1424 break; 1467 case 0x17://LOG10
1425 case 0x18://ABS 1468 s1=QString("LOG10(")+operands.first()->ascii()+QString(")");
1426 s1=QString("ABS(")+operands.first()->ascii()+QString(")"); 1469 operands.removeFirst();
1427 operands.removeFirst(); 1470 operands.prepend(new QString(s1));
1428 operands.prepend(new QString(s1)); 1471 break;
1429 break; 1472 case 0x18://ABS
1430 case 0x19://int 1473 s1=QString("ABS(")+operands.first()->ascii()+QString(")");
1431 s1=QString("INT(")+operands.first()->ascii()+QString(")"); 1474 operands.removeFirst();
1432 operands.removeFirst(); 1475 operands.prepend(new QString(s1));
1433 operands.prepend(new QString(s1)); 1476 break;
1434 break; 1477 case 0x19://int
1435 case 0x1a://sign 1478 s1=QString("INT(")+operands.first()->ascii()+QString(")");
1436 s1=QString("SIGN(")+operands.first()->ascii()+QString(")"); 1479 operands.removeFirst();
1437 operands.removeFirst(); 1480 operands.prepend(new QString(s1));
1438 operands.prepend(new QString(s1)); 1481 break;
1439 break; 1482 case 0x1a://sign
1440 case 0x1b://round 1483 s1=QString("SIGN(")+operands.first()->ascii()+QString(")");
1441 operands.first(); 1484 operands.removeFirst();
1442 s1=QString("ROUND(")+operands.next()->ascii() 1485 operands.prepend(new QString(s1));
1443 +QString(",")+operands.first()->ascii() 1486 break;
1444 +QString(")"); 1487 case 0x1b://round
1445 operands.removeFirst();operands.removeFirst(); 1488 operands.first();
1446 operands.prepend(new QString(s1)); 1489 s1=QString("ROUND(")+operands.next()->ascii()
1447 break; 1490 +QString(",")+operands.first()->ascii()
1448 case 0x1d://index 1491 +QString(")");
1449 operands.first(); 1492 operands.removeFirst();operands.removeFirst();
1450 s1=QString("INDEX(")+operands.next()->ascii() 1493 operands.prepend(new QString(s1));
1451 +QString(",") 1494 break;
1452 +operands.first()->ascii()+QString(")"); 1495 case 0x1d://index
1453 operands.removeFirst(); 1496 operands.first();
1454 operands.removeFirst(); 1497 s1=QString("INDEX(")+operands.next()->ascii()
1455 operands.prepend(new QString(s1)); 1498 +QString(",")
1456 break; 1499 +operands.first()->ascii()+QString(")");
1457 case 0x1: // if ATTRIBUTE 1500 operands.removeFirst();
1458 operands.first();operands.next(); 1501 operands.removeFirst();
1459 s1=QString("IF(")+operands.next()->ascii()+QString(","); 1502 operands.prepend(new QString(s1));
1460 operands.first(); 1503 break;
1461 s1=s1+operands.next()->ascii()+QString(","); 1504 case 0x1: // if ATTRIBUTE
1462 s1=s1+operands.first()->ascii()+QString(")"); 1505 operands.first();operands.next();
1463 operands.removeFirst(); 1506 s1=QString("IF(")+operands.next()->ascii()+QString(",");
1464 operands.removeFirst(); 1507 operands.first();
1465 operands.removeFirst(); 1508 s1=s1+operands.next()->ascii()+QString(",");
1466 operands.prepend(new QString(s1)); 1509 s1=s1+operands.first()->ascii()+QString(")");
1467 break; 1510 operands.removeFirst();
1468 case 0x81://isblank 1511 operands.removeFirst();
1469 s1=QString("ISBLANK(")+operands.first()->ascii() 1512 operands.removeFirst();
1470 +QString(")"); 1513 operands.prepend(new QString(s1));
1471 operands.removeFirst(); 1514 break;
1472 operands.prepend(new QString(s1)); 1515 case 0x81://isblank
1473 break; 1516 s1=QString("ISBLANK(")+operands.first()->ascii()
1474 case 0x80://isnumber 1517 +QString(")");
1475 s1=QString("ISNUMBER(")+operands.first()->ascii() 1518 operands.removeFirst();
1476 +QString(")"); 1519 operands.prepend(new QString(s1));
1477 operands.removeFirst(); 1520 break;
1478 operands.prepend(new QString(s1)); 1521 case 0x80://isnumber
1479 break; 1522 s1=QString("ISNUMBER(")+operands.first()->ascii()
1480 case 0x120://ceiling 1523 +QString(")");
1481 operands.first(); 1524 operands.removeFirst();
1482 s1=QString("CEILING(")+operands.next()->ascii() 1525 operands.prepend(new QString(s1));
1483 +QString(",")+operands.first()->ascii() 1526 break;
1484 +QString(")"); 1527 case 0x120://ceiling
1485 operands.removeFirst();operands.removeFirst(); 1528 operands.first();
1486 operands.prepend(new QString(s1)); 1529 s1=QString("CEILING(")+operands.next()->ascii()
1487 break; 1530 +QString(",")+operands.first()->ascii()
1488 case 0x11d://floor 1531 +QString(")");
1489 operands.first(); 1532 operands.removeFirst();operands.removeFirst();
1490 s1=QString("FLOOR(")+operands.next()->ascii() 1533 operands.prepend(new QString(s1));
1491 +QString(",")+operands.first()->ascii() 1534 break;
1492 +QString(")"); 1535 case 0x11d://floor
1493 operands.removeFirst();operands.removeFirst(); 1536 operands.first();
1494 operands.prepend(new QString(s1)); 1537 s1=QString("FLOOR(")+operands.next()->ascii()
1495 break; 1538 +QString(",")+operands.first()->ascii()
1496 case 0x157://degrees 1539 +QString(")");
1497 s1=QString("DEGREES(")+operands.first()->ascii() 1540 operands.removeFirst();operands.removeFirst();
1498 +QString(")"); 1541 operands.prepend(new QString(s1));
1499 operands.removeFirst(); 1542 break;
1500 operands.prepend(new QString(s1)); 1543 case 0x157://degrees
1501 break; 1544 s1=QString("DEGREES(")+operands.first()->ascii()
1502 case 0x156://radians 1545 +QString(")");
1503 s1=QString("RADIANS(")+operands.first()->ascii() 1546 operands.removeFirst();
1504 +QString(")"); 1547 operands.prepend(new QString(s1));
1505 operands.removeFirst(); 1548 break;
1506 operands.prepend(new QString(s1)); 1549 case 0x156://radians
1507 break; 1550 s1=QString("RADIANS(")+operands.first()->ascii()
1508 case 0xb8://fact 1551 +QString(")");
1509 s1=QString("FACT(")+operands.first()->ascii() 1552 operands.removeFirst();
1510 +QString(")"); 1553 operands.prepend(new QString(s1));
1511 operands.removeFirst(); 1554 break;
1512 operands.prepend(new QString(s1)); 1555 case 0xb8://fact
1513 break; 1556 s1=QString("FACT(")+operands.first()->ascii()
1514 case 0x27://MOD 1557 +QString(")");
1515 operands.first(); 1558 operands.removeFirst();
1516 s1=QString("MOD(")+operands.next()->ascii() 1559 operands.prepend(new QString(s1));
1517 +QString(",")+operands.first()->ascii() 1560 break;
1518 +QString(")"); 1561 case 0x27://MOD
1519 operands.removeFirst();operands.removeFirst(); 1562 operands.first();
1520 operands.prepend(new QString(s1)); 1563 s1=QString("MOD(")+operands.next()->ascii()
1521 break; 1564 +QString(",")+operands.first()->ascii()
1522 case 0x151://power 1565 +QString(")");
1523 operands.first(); 1566 operands.removeFirst();operands.removeFirst();
1524 s1=QString("POWER(")+operands.next()->ascii() 1567 operands.prepend(new QString(s1));
1525 +QString(",")+operands.first()->ascii() 1568 break;
1526 +QString(")"); 1569 case 0x151://power
1527 operands.removeFirst();operands.removeFirst(); 1570 operands.first();
1528 operands.prepend(new QString(s1)); 1571 s1=QString("POWER(")+operands.next()->ascii()
1529 break; 1572 +QString(",")+operands.first()->ascii()
1530 case 0x3f://rand() 1573 +QString(")");
1531 s1="RAND()"; 1574 operands.removeFirst();operands.removeFirst();
1532 operands.prepend(new QString(s1)); 1575 operands.prepend(new QString(s1));
1533 break; 1576 break;
1534 case 0x4://sum 1577 case 0x3f://rand()
1535 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1578 s1="RAND()";
1536 s1=QString("SUM(")+operands.first()->ascii() 1579 operands.prepend(new QString(s1));
1537 +QString(")"); 1580 break;
1538 operands.removeFirst(); 1581 case 0x4://sum
1539 operands.prepend(new QString(s1)); 1582 for(w4=1;w4<w2;w4++) operands.removeFirst();
1540 break; 1583 s1=QString("SUM(")+operands.first()->ascii()
1541 case 0x6://min 1584 +QString(")");
1542 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1585 operands.removeFirst();
1543 s1=QString("MIN(")+operands.first()->ascii() 1586 operands.prepend(new QString(s1));
1544 +QString(")"); 1587 break;
1545 operands.removeFirst(); 1588 case 0x6://min
1546 operands.prepend(new QString(s1)); 1589 for(w4=1;w4<w2;w4++) operands.removeFirst();
1547 break; 1590 s1=QString("MIN(")+operands.first()->ascii()
1548 case 0x7://max 1591 +QString(")");
1549 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1592 operands.removeFirst();
1550 s1=QString("MAX(")+operands.first()->ascii() 1593 operands.prepend(new QString(s1));
1551 +QString(")"); 1594 break;
1552 operands.removeFirst(); 1595 case 0x7://max
1553 operands.prepend(new QString(s1)); 1596 for(w4=1;w4<w2;w4++) operands.removeFirst();
1554 break; 1597 s1=QString("MAX(")+operands.first()->ascii()
1555 case 0x5://average 1598 +QString(")");
1556 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1599 operands.removeFirst();
1557 s1=QString("AVERAGE(")+operands.first()->ascii() 1600 operands.prepend(new QString(s1));
1558 +QString(")"); 1601 break;
1559 operands.removeFirst(); 1602 case 0x5://average
1560 operands.prepend(new QString(s1)); 1603 for(w4=1;w4<w2;w4++) operands.removeFirst();
1561 break; 1604 s1=QString("AVERAGE(")+operands.first()->ascii()
1562 case 0x2e://var 1605 +QString(")");
1563 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1606 operands.removeFirst();
1564 s1=QString("VAR(")+operands.first()->ascii() 1607 operands.prepend(new QString(s1));
1565 +QString(")"); 1608 break;
1566 operands.removeFirst(); 1609 case 0x2e://var
1567 operands.prepend(new QString(s1)); 1610 for(w4=1;w4<w2;w4++) operands.removeFirst();
1568 break; 1611 s1=QString("VAR(")+operands.first()->ascii()
1569 case 0xc2://varp 1612 +QString(")");
1570 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1613 operands.removeFirst();
1571 s1=QString("VARP(")+operands.first()->ascii() 1614 operands.prepend(new QString(s1));
1572 +QString(")"); 1615 break;
1573 operands.removeFirst(); 1616 case 0xc2://varp
1574 operands.prepend(new QString(s1)); 1617 for(w4=1;w4<w2;w4++) operands.removeFirst();
1575 break; 1618 s1=QString("VARP(")+operands.first()->ascii()
1576 case 0xc://stdev 1619 +QString(")");
1577 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1620 operands.removeFirst();
1578 s1=QString("STDEV(")+operands.first()->ascii() 1621 operands.prepend(new QString(s1));
1579 +QString(")"); 1622 break;
1580 operands.removeFirst(); 1623 case 0xc://stdev
1581 operands.prepend(new QString(s1)); 1624 for(w4=1;w4<w2;w4++) operands.removeFirst();
1582 break; 1625 s1=QString("STDEV(")+operands.first()->ascii()
1583 case 0xc1://stdevp 1626 +QString(")");
1584 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1627 operands.removeFirst();
1585 s1=QString("STDEVP(")+operands.first()->ascii() 1628 operands.prepend(new QString(s1));
1586 +QString(")"); 1629 break;
1587 operands.removeFirst(); 1630 case 0xc1://stdevp
1588 operands.prepend(new QString(s1)); 1631 for(w4=1;w4<w2;w4++) operands.removeFirst();
1589 break; 1632 s1=QString("STDEVP(")+operands.first()->ascii()
1590 case 0x143://skew 1633 +QString(")");
1591 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1634 operands.removeFirst();
1592 s1=QString("SKEW(")+operands.first()->ascii() 1635 operands.prepend(new QString(s1));
1593 +QString(")"); 1636 break;
1594 operands.removeFirst(); 1637 case 0x143://skew
1595 operands.prepend(new QString(s1)); 1638 for(w4=1;w4<w2;w4++) operands.removeFirst();
1596 break; 1639 s1=QString("SKEW(")+operands.first()->ascii()
1597 case 0x142://kurt 1640 +QString(")");
1598 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1641 operands.removeFirst();
1599 s1=QString("KURT(")+operands.first()->ascii() 1642 operands.prepend(new QString(s1));
1600 +QString(")"); 1643 break;
1601 operands.removeFirst(); 1644 case 0x142://kurt
1602 operands.prepend(new QString(s1)); 1645 for(w4=1;w4<w2;w4++) operands.removeFirst();
1603 break; 1646 s1=QString("KURT(")+operands.first()->ascii()
1604 case 0x0://count 1647 +QString(")");
1605 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1648 operands.removeFirst();
1606 s1=QString("COUNT(")+operands.first()->ascii() 1649 operands.prepend(new QString(s1));
1607 +QString(")"); 1650 break;
1608 operands.removeFirst(); 1651 case 0x0://count
1609 operands.prepend(new QString(s1)); 1652 for(w4=1;w4<w2;w4++) operands.removeFirst();
1610 break; 1653 s1=QString("COUNT(")+operands.first()->ascii()
1611 1654 +QString(")");
1612 default: 1655 operands.removeFirst();
1613 printf("token:FUNCTION_UNKNOWN=0x%x\r\n",w1); 1656 operands.prepend(new QString(s1));
1614 return QString("FUNC_UNKNOWN"); 1657 break;
1615 break; 1658
1616 1659 default:
1617 }; 1660 printf("token:FUNCTION_UNKNOWN=0x%x\r\n",w1);
1618 1661 return QString("FUNC_UNKNOWN");
1619 break; 1662 break;
1620 1663
1621 default: 1664 };
1622 printf("tokenUNKNOWN=0x%x\r\n",token); 1665
1623 return QString("TOKEN_UKNOWN"); 1666 break;
1624 //it is dangerous to go to idx++ and not return 1667
1625 // because the result is unexpected. 1668 default:
1626 // but there is a possibility the the parser will give the correct 1669 printf("tokenUNKNOWN=0x%x\r\n",token);
1627 // answer, because there are some tokens in excel formulas that can be //ignored. 1670 return QString("TOKEN_UKNOWN");
1628 idx++; 1671 //it is dangerous to go to idx++ and not return
1629 break; 1672 // because the result is unexpected.
1630 }; 1673 // but there is a possibility the the parser will give the correct
1631 1674 // answer, because there are some tokens in excel formulas that can be //ignored.
1632 }; 1675 idx++;
1633 1676 break;
1634 1677 };
1635 1678
1636 printf("{////FormulaParser}\r\n"); 1679 };
1637 printf("GetFormula:::::::r=%d,c=%d,,,%s\r\n",row,col,s1.ascii()); 1680
1638 printf("\r\n"); 1681
1639 s1=operands.first()->ascii(); 1682
1640 operands.clear(); 1683 printf("{////FormulaParser}\r\n");
1641return QString(s1); 1684 printf("GetFormula:::::::r=%d,c=%d,,,%s\r\n",row,col,s1.ascii());
1685 printf("\r\n");
1686 s1=operands.first()->ascii();
1687 operands.clear();
1688 return QString(s1);
1642}; 1689};
1643 1690
1644QString ExcelBook::FindCellName(int row, int col) 1691QString ExcelBook::FindCellName(int row, int col)
1645{ 1692{
1646 row++;col++; 1693 row++;col++;
1647 QString s1=""; 1694 QString s1="";
1648 int i1=col % 26; 1695 int i1=col % 26;
1649 int i2=col / 26; 1696 int i2=col / 26;
1650 if (i2!=0) s1=(char)(i2+65); //65 =A 1697 if (i2!=0) s1=(char)(i2+65); //65 =A
1651 s1=s1+(char)(i1+65-1); 1698 s1=s1+(char)(i1+65-1);
1652 return (s1+QString::number(row)); 1699 return (s1+QString::number(row));
1653}; 1700};
1654 1701
diff --git a/noncore/apps/opie-sheet/Excel.h b/noncore/apps/opie-sheet/Excel.h
index 0a581cf..51ccf5c 100644
--- a/noncore/apps/opie-sheet/Excel.h
+++ b/noncore/apps/opie-sheet/Excel.h
@@ -1,3 +1,36 @@
1/*
2 =. This file is part of the Opie Project
3 .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
4 .>+-=
5 _;:, .> :=|. This program is free software; you can
6.> <`_, > . <= redistribute it and/or modify it under
7:`=1 )Y*s>-.-- : the terms of the GNU General Public
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*/
28
29/* QT */
30#include <qstring.h>
31#include <qarray.h>
32#include <qlist.h>
1 33
34/* STD */
2#include <stdio.h> 35#include <stdio.h>
3#include <stdlib.h> 36#include <stdlib.h>
@@ -6,7 +39,4 @@
6#include <sys/types.h> 39#include <sys/types.h>
7#include <strings.h> 40#include <strings.h>
8#include <qstring.h>
9#include <qarray.h>
10#include <qlist.h>
11 41
12#define DATEFORMAT 0x1 42#define DATEFORMAT 0x1
@@ -56,16 +86,16 @@ class ExcelFormat
56{ 86{
57public: 87public:
58int code; 88 int code;
59int type; 89 int type;
60QString format; 90 QString format;
61ExcelFormat(); 91 ExcelFormat();
62ExcelFormat(int c,int t, QString s); 92 ExcelFormat(int c,int t, QString s);
63}; 93};
64 94
65struct xfrecord 95struct xfrecord
66{ 96{
67int code; 97 int code;
68int type; 98 int type;
69QString format; 99 QString format;
70}; 100};
71 101
@@ -73,10 +103,10 @@ class ExcelCell
73{ 103{
74public: 104public:
75int type; 105 int type;
76int row,col; 106 int row,col;
77int xfindex; //xf format index of cell 107 int xfindex; //xf format index of cell
78int valuei; 108 int valuei;
79double valued; 109 double valued;
80QString valuec; 110 QString valuec;
81 111
82}; 112};
@@ -85,8 +115,8 @@ class ExcelBREC
85{ 115{
86public: 116public:
87 int code; 117 int code;
88 int length; 118 int length;
89 int position; 119 int position;
90 char* data; 120 char* data;
91}; 121};
92 122
@@ -94,5 +124,5 @@ class SSTList
94{ 124{
95public: 125public:
96 QArray <ExcelBREC*> rec; 126 QArray <ExcelBREC*> rec;
97}; 127};
98 128
@@ -100,106 +130,99 @@ class ExcelSheet
100{ 130{
101public: 131public:
102 QString name; 132 QString name;
103 ExcelBREC BOFRecord; 133 ExcelBREC BOFRecord;
104 int position; 134 int position;
105 int type; 135 int type;
106 int rows; 136 int rows;
107 int cols; 137 int cols;
108 138
109 int cellsize,rowalloc,cellalloc; 139 int cellsize,rowalloc,cellalloc;
110 QArray <ExcelCell*> Cells; 140 QArray <ExcelCell*> Cells;
111 bool InitCells(void); // true if ok 141 bool InitCells(void); // true if ok
112 ExcelCell* Get(int row, int col); 142 ExcelCell* Get(int row, int col);
113 void Set(int row, int col, ExcelCell* cell); 143 void Set(int row, int col, ExcelCell* cell);
114 144
115}; 145};
116 146
117struct mulrk { 147struct mulrk
118 int row; 148{
119 int first; 149 int row;
120 int last; 150 int first;
121 int numrks; 151 int last;
122 QArray<int> rknumbers; 152 int numrks;
123 QArray<double> rkdbls; 153 QArray<int> rknumbers;
124 QArray<int> xfindices; 154 QArray<double> rkdbls;
155 QArray<int> xfindices;
125}; 156};
126 157
127
128
129
130class ExcelBook 158class ExcelBook
131{ 159{
132public: 160public:
133FILE *File; 161 FILE *File;
134int Position; 162 int Position;
135//int stringcount; 163 //int stringcount;
136QArray <QString*> SharedStrings; 164 QArray <QString*> SharedStrings;
137//int xfcount; 165 //int xfcount;
138QArray <ExcelFormat*> XFRecords; 166 QArray <ExcelFormat*> XFRecords;
139//int Sheetcount; 167 //int Sheetcount;
140QArray <ExcelSheet*> Sheets; 168 QArray <ExcelSheet*> Sheets;
141//int name count; 169 //int name count;
142QArray <QString*> Names; 170 QArray <QString*> Names;
143 171
144QString dateformat; 172 QString dateformat;
145int Version; 173 int Version;
146int endian; 174 int endian;
147int Integer2Byte(int b1, int b2 ); 175 int Integer2Byte(int b1, int b2 );
148int Integer4Byte(int b1, int b2, int b3, int b4 ); 176 int Integer4Byte(int b1, int b2, int b3, int b4 );
149int Integer2ByteFile(FILE *f); 177 int Integer2ByteFile(FILE *f);
150float Float4Byte(int b1, int b2, int b3, int b4); 178 float Float4Byte(int b1, int b2, int b3, int b4);
151double Double4Byte(int b1, int b2, int b3, int b4); 179 double Double4Byte(int b1, int b2, int b3, int b4);
152double Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8); 180 double Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8);
153void DetectEndian(void); 181 void DetectEndian(void);
154 182
155bool OpenFile(char *Filename); // true if ok 183 bool OpenFile(char *Filename); // true if ok
156bool CloseFile(void); // true if ok 184 bool CloseFile(void); // true if ok
157void SeekPosition(int pos); // go to Pos 185 void SeekPosition(int pos); // go to Pos
158void SeekSkip(int pos); // skips pos bytes. 186 void SeekSkip(int pos); // skips pos bytes.
159int FileEOF(void); //returns -1 if EOF else 0 187 int FileEOF(void); //returns -1 if EOF else 0
160int Get2Bytes(void); //gets an int from the file 188 int Get2Bytes(void); //gets an int from the file
161char* Read(int pos, int length); 189 char* Read(int pos, int length);
162QString ReadUnicodeChar(int pos, int length); 190 QString ReadUnicodeChar(int pos, int length);
163QString* GetString(int num); //gets the num string from SharedStrings; 191 QString* GetString(int num); //gets the num string from SharedStrings;
164int SeekBOF(void); 192 int SeekBOF(void);
165ExcelBREC* GetBREC(void); 193 ExcelBREC* GetBREC(void);
166ExcelBREC* PeekBREC(void); 194 ExcelBREC* PeekBREC(void);
167char* GetDataOfBREC(ExcelBREC* record); 195 char* GetDataOfBREC(ExcelBREC* record);
168void ConvertCharToArray(ExcelBREC* record, char* chars, int length); 196 void ConvertCharToArray(ExcelBREC* record, char* chars, int length);
169int SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record); 197 int SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record);
170int ReadSheet(ExcelSheet* sheet); //read the sheet sheet* 198 int ReadSheet(ExcelSheet* sheet); //read the sheet sheet*
171ExcelSheet* GetSheet(void); 199 ExcelSheet* GetSheet(void);
172void ParseSheets(void); 200 void ParseSheets(void);
173void GetSheets(void); 201 void GetSheets(void);
174 202
175bool ParseBook(char *file); // THIS IS THE MAIN PARSE FUNCTION of file 203 bool ParseBook(char *file); // THIS IS THE MAIN PARSE FUNCTION of file
176QString GetASCII(char* inbytes, int pos, int chars); 204 QString GetASCII(char* inbytes, int pos, int chars);
177QString GetUnicode(char * inbytes, int pos, int chars); 205 QString GetUnicode(char * inbytes, int pos, int chars);
178void HandleBoundSheet( ExcelBREC* rec); 206 void HandleBoundSheet( ExcelBREC* rec);
179void HandleName(ExcelSheet* sheet, ExcelBREC* rec); 207 void HandleName(ExcelSheet* sheet, ExcelBREC* rec);
180ExcelFormat* GetFormatting(int xf); 208 ExcelFormat* GetFormatting(int xf);
181void HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes); 209 void HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes);
182char* MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont); 210 char* MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont);
183void HandleSST(ExcelBREC* rec); 211 void HandleSST(ExcelBREC* rec);
184void HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec); 212 void HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec);
185ExcelCell* CellLabel(int row, int col, QString str); 213 ExcelCell* CellLabel(int row, int col, QString str);
186ExcelCell* CellNumber(int row, int col, int index, double d); 214 ExcelCell* CellNumber(int row, int col, int index, double d);
187QString* CellDataString(ExcelSheet* sh, int row, int col); 215 QString* CellDataString(ExcelSheet* sh, int row, int col);
188int CellGetPrecision(double d); 216 int CellGetPrecision(double d);
189void CellSetDateFormat(char *d); 217 void CellSetDateFormat(char *d);
190void HandleMulrk(ExcelSheet* sheet, ExcelBREC* record); 218 void HandleMulrk(ExcelSheet* sheet, ExcelBREC* record);
191void MulrkRead(struct mulrk *mulrk, char* data); 219 void MulrkRead(struct mulrk *mulrk, char* data);
192void HandleNumber(ExcelSheet* sheet, ExcelBREC* record); 220 void HandleNumber(ExcelSheet* sheet, ExcelBREC* record);
193void HandleFormat(ExcelBREC* rec); 221 void HandleFormat(ExcelBREC* rec);
194void HandleXF(ExcelBREC* rec); 222 void HandleXF(ExcelBREC* rec);
195void HandleRK(ExcelSheet* sheet, ExcelBREC* record); 223 void HandleRK(ExcelSheet* sheet, ExcelBREC* record);
196void HandleFormula(ExcelSheet* sheet, ExcelBREC* record); 224 void HandleFormula(ExcelSheet* sheet, ExcelBREC* record);
197QString GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz); 225 QString GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz);
198QString FindCellName(int row, int col); 226 QString FindCellName(int row, int col);
199
200
201
202
203
204}; 227};
205 228
diff --git a/noncore/apps/opie-sheet/cellformat.cpp b/noncore/apps/opie-sheet/cellformat.cpp
index 342ebe9..602d20d 100644
--- a/noncore/apps/opie-sheet/cellformat.cpp
+++ b/noncore/apps/opie-sheet/cellformat.cpp
@@ -1,10 +1,29 @@
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/*
@@ -15,4 +34,5 @@
15#include "cellformat.h" 34#include "cellformat.h"
16 35
36/* QT */
17#include <qlistbox.h> 37#include <qlistbox.h>
18#include <qlabel.h> 38#include <qlabel.h>
@@ -35,11 +55,11 @@ QColor qtColors[COLOR_COUNT]={Qt::black,Qt::white, Qt::darkGray,
35 55
36Qt::BrushStyle brushStyles[STYLE_COUNT]={Qt::SolidPattern, 56Qt::BrushStyle brushStyles[STYLE_COUNT]={Qt::SolidPattern,
37 Qt::Dense1Pattern, Qt::Dense2Pattern, 57 Qt::Dense1Pattern, Qt::Dense2Pattern,
38 Qt::Dense3Pattern, Qt::Dense4Pattern, 58 Qt::Dense3Pattern, Qt::Dense4Pattern,
39 Qt::Dense5Pattern, Qt::Dense6Pattern, 59 Qt::Dense5Pattern, Qt::Dense6Pattern,
40 Qt::Dense7Pattern, Qt::HorPattern, 60 Qt::Dense7Pattern, Qt::HorPattern,
41 Qt::VerPattern, Qt::CrossPattern, 61 Qt::VerPattern, Qt::CrossPattern,
42 Qt::BDiagPattern, Qt::FDiagPattern, 62 Qt::BDiagPattern, Qt::FDiagPattern,
43 Qt::DiagCrossPattern}; 63 Qt::DiagCrossPattern};
44 64
45QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"}; 65QString namesHAlign[HALIGN_COUNT]={"Left", "Right", "Center"};
@@ -47,273 +67,272 @@ QString namesVAlign[VALIGN_COUNT]={"Top", "Bottom", "Center"};
47 67
48Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft, 68Qt::AlignmentFlags flagsHAlign[HALIGN_COUNT]={Qt::AlignLeft,
49 Qt::AlignRight, 69 Qt::AlignRight,
50 Qt::AlignHCenter}; 70 Qt::AlignHCenter};
51 71
52Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop, 72Qt::AlignmentFlags flagsVAlign[VALIGN_COUNT]={Qt::AlignTop,
53 Qt::AlignBottom, 73 Qt::AlignBottom,
54 Qt::AlignVCenter}; 74 Qt::AlignVCenter};
55 75
56CellFormat::CellFormat(QWidget *parent) 76CellFormat::CellFormat(QWidget *parent)
57 :QDialog(parent, 0, TRUE) 77 :QDialog(parent, 0, TRUE)
58{ 78{
59 // Main widget 79 // Main widget
60 tabs=new QTabWidget(this); 80 tabs=new QTabWidget(this);
61 widgetBorders=new QWidget(tabs); 81 widgetBorders=new QWidget(tabs);
62 widgetBackground=new QWidget(tabs); 82 widgetBackground=new QWidget(tabs);
63 widgetFont=new QWidget(tabs); 83 widgetFont=new QWidget(tabs);
64 widgetAlignment=new QWidget(tabs); 84 widgetAlignment=new QWidget(tabs);
65 tabs->addTab(widgetBorders, tr("&Borders")); 85 tabs->addTab(widgetBorders, tr("&Borders"));
66 tabs->addTab(widgetBackground, tr("Back&ground")); 86 tabs->addTab(widgetBackground, tr("Back&ground"));
67 tabs->addTab(widgetFont, tr("&Font")); 87 tabs->addTab(widgetFont, tr("&Font"));
68 tabs->addTab(widgetAlignment, tr("&Alignment")); 88 tabs->addTab(widgetAlignment, tr("&Alignment"));
69 89
70 fontDB.loadRenderers(); 90 fontDB.loadRenderers();
71 changedFont=changedAlign=changedBrush=FALSE; 91 changedFont=changedAlign=changedBrush=FALSE;
72 92
73 // Borders tab 93 // Borders tab
74 borderEditor=new BorderEditor(widgetBorders); 94 borderEditor=new BorderEditor(widgetBorders);
75 borderEditor->setGeometry(10, 10, 215, 145); 95 borderEditor->setGeometry(10, 10, 215, 145);
76 connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)), 96 connect(borderEditor, SIGNAL(clicked(BorderEditor::BorderArea)),
77 this, SLOT(borderClicked(BorderEditor::BorderArea))); 97 this, SLOT(borderClicked(BorderEditor::BorderArea)));
78 98
79 comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165); 99 comboBordersWidth=createCombo(COMBO_WIDTH, widgetBorders, tr("&Width:"), 165);
80 comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); 100 comboBordersColor=createCombo(COMBO_COLOR, widgetBorders, tr("&Color:"), 165+(COMBO_HEIGHTS+10));
81 101
82 buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders); 102 buttonBordersDefaults=new QPushButton(tr("&Default Borders"), widgetBorders);
83 buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 103 buttonBordersDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10),
84 110, COMBO_HEIGHTS); 104 110, COMBO_HEIGHTS);
85 105
86 connect(buttonBordersDefaults, SIGNAL(clicked()), 106 connect(buttonBordersDefaults, SIGNAL(clicked()),
87 this, SLOT(slotBordersDefaults())); 107 this, SLOT(slotBordersDefaults()));
88 108
89 // Background tab 109 // Background tab
90 frameBackground=new QFrame(widgetBackground); 110 frameBackground=new QFrame(widgetBackground);
91 frameBackground->setGeometry(10, 10, 215, 145); 111 frameBackground->setGeometry(10, 10, 215, 145);
92 frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); 112 frameBackground->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
93 113
94 comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165); 114 comboBackgroundStyle=createCombo(COMBO_STYLE, widgetBackground, tr("&Style:"), 165);
95 connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); 115 connect(comboBackgroundStyle, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int)));
96 comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10)); 116 comboBackgroundColor=createCombo(COMBO_COLOR, widgetBackground, tr("&Color:"), 165+(COMBO_HEIGHTS+10));
97 connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int))); 117 connect(comboBackgroundColor, SIGNAL(activated(int)), this, SLOT(backgroundClicked(int)));
98 118
99 buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground); 119 buttonBackgroundDefaults=new QPushButton(tr("&Default Background"), widgetBackground);
100 buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); 120 buttonBackgroundDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
101 connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults())); 121 connect(buttonBackgroundDefaults, SIGNAL(clicked()), this, SLOT(slotBackgroundDefaults()));
102 122
103 // Font tab 123 // Font tab
104 frameFont=new QFrame(widgetFont); 124 frameFont=new QFrame(widgetFont);
105 frameFont->setGeometry(10, 10, 215, 125); 125 frameFont->setGeometry(10, 10, 215, 125);
106 frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); 126 frameFont->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
107 127
108 comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145); 128 comboFontFamily=createCombo(COMBO_FONT, widgetFont, tr("&Font:"), 145);
109 connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); 129 connect(comboFontFamily, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
110 comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10)); 130 comboFontSize=createCombo(COMBO_SIZE, widgetFont, tr("&Size:"), 145+(COMBO_HEIGHTS+10));
111 connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); 131 connect(comboFontSize, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
112 comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10)); 132 comboFontColor=createCombo(COMBO_COLOR, widgetFont, tr("&Color:"), 145+2*(COMBO_HEIGHTS+10));
113 connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int))); 133 connect(comboFontColor, SIGNAL(activated(int)), this, SLOT(fontClicked(int)));
114 134
115 checkFontBold=new QCheckBox(tr("&Bold"), widgetFont); 135 checkFontBold=new QCheckBox(tr("&Bold"), widgetFont);
116 checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); 136 checkFontBold->setGeometry(10, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS);
117 connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); 137 connect(checkFontBold, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool)));
118 checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont); 138 checkFontItalic=new QCheckBox(tr("&Italic"), widgetFont);
119 checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS); 139 checkFontItalic->setGeometry(60, 145+3*(COMBO_HEIGHTS+10), 40, COMBO_HEIGHTS);
120 connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool))); 140 connect(checkFontItalic, SIGNAL(toggled(bool)), this, SLOT(fontClicked(bool)));
121 141
122 buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont); 142 buttonFontDefaults=new QPushButton(tr("&Default Font"), widgetFont);
123 buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); 143 buttonFontDefaults->setGeometry(115, 145+3*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
124 connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults())); 144 connect(buttonFontDefaults, SIGNAL(clicked()), this, SLOT(slotFontDefaults()));
125 145
126 // Alignment tab 146 // Alignment tab
127 frameAlignment=new QFrame(widgetAlignment); 147 frameAlignment=new QFrame(widgetAlignment);
128 frameAlignment->setGeometry(10, 10, 215, 145); 148 frameAlignment->setGeometry(10, 10, 215, 145);
129 frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); 149 frameAlignment->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
130 150
131 comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165); 151 comboAlignmentVertical=createCombo(COMBO_VALIGN, widgetAlignment, tr("&Vertical:"), 165);
132 connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); 152 connect(comboAlignmentVertical, SIGNAL(activated(int)), this, SLOT(alignClicked(int)));
133 comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10)); 153 comboAlignmentHorizontal=createCombo(COMBO_HALIGN, widgetAlignment, tr("&Horizontal:"), 165+(COMBO_HEIGHTS+10));
134 connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int))); 154 connect(comboAlignmentHorizontal, SIGNAL(activated(int)), this, SLOT(alignClicked(int)));
135 155
136 checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment); 156 checkAlignmentWrap=new QCheckBox(tr("&Word Wrap"), widgetAlignment);
137 checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS); 157 checkAlignmentWrap->setGeometry(10, 165+2*(COMBO_HEIGHTS+10), 90, COMBO_HEIGHTS);
138 connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool))); 158 connect(checkAlignmentWrap, SIGNAL(toggled(bool)), this, SLOT(alignClicked(bool)));
139 159
140 buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment); 160 buttonAlignmentDefaults=new QPushButton(tr("&Default Alignment"), widgetAlignment);
141 buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS); 161 buttonAlignmentDefaults->setGeometry(115, 165+2*(COMBO_HEIGHTS+10), 110, COMBO_HEIGHTS);
142 connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults())); 162 connect(buttonAlignmentDefaults, SIGNAL(clicked()), this, SLOT(slotAlignmentDefaults()));
143 163
144 // Main widget 164 // Main widget
145 box=new QVBoxLayout(this); 165 box=new QVBoxLayout(this);
146 box->addWidget(tabs); 166 box->addWidget(tabs);
147 167
148 setCaption(tr("Format Cells")); 168 setCaption(tr("Format Cells"));
149} 169}
150 170
151CellFormat::~CellFormat() 171CellFormat::~CellFormat()
152{ 172{}
153}
154 173
155int CellFormat::findColorIndex(const QColor &color) 174int CellFormat::findColorIndex(const QColor &color)
156{ 175{
157 for (int i=0; i<COLOR_COUNT; ++i) 176 for (int i=0; i<COLOR_COUNT; ++i)
158 if (qtColors[i]==color) 177 if (qtColors[i]==color)
159 return i; 178 return i;
160 return 0; 179 return 0;
161} 180}
162 181
163int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag) 182int CellFormat::findVAlignIndex(Qt::AlignmentFlags flag)
164{ 183{
165 for (int i=0; i<VALIGN_COUNT; ++i) 184 for (int i=0; i<VALIGN_COUNT; ++i)
166 if (flagsVAlign[i] & flag) 185 if (flagsVAlign[i] & flag)
167 return i; 186 return i;
168 return 0; 187 return 0;
169} 188}
170 189
171int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag) 190int CellFormat::findHAlignIndex(Qt::AlignmentFlags flag)
172{ 191{
173 for (int i=0; i<HALIGN_COUNT; ++i) 192 for (int i=0; i<HALIGN_COUNT; ++i)
174 if (flagsHAlign[i] & flag) 193 if (flagsHAlign[i] & flag)
175 return i; 194 return i;
176 return 0; 195 return 0;
177} 196}
178 197
179int CellFormat::findBrushStyleIndex(Qt::BrushStyle style) 198int CellFormat::findBrushStyleIndex(Qt::BrushStyle style)
180{ 199{
181 for (int i=0; i<STYLE_COUNT; ++i) 200 for (int i=0; i<STYLE_COUNT; ++i)
182 if (brushStyles[i]==style) 201 if (brushStyles[i]==style)
183 return i; 202 return i;
184 return 0; 203 return 0;
185} 204}
186 205
187void CellFormat::setBrushBackground(const QBrush &brush) 206void CellFormat::setBrushBackground(const QBrush &brush)
188{ 207{
189 comboBackgroundColor->setCurrentItem(findColorIndex(brush.color())); 208 comboBackgroundColor->setCurrentItem(findColorIndex(brush.color()));
190 comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style())); 209 comboBackgroundStyle->setCurrentItem(findBrushStyleIndex(brush.style()));
191 210
192 QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height()); 211 QPixmap pix(frameBackground->contentsRect().width(), frameBackground->contentsRect().height());
193 QPainter p(&pix); 212 QPainter p(&pix);
194 pix.fill(); 213 pix.fill();
195 p.fillRect(pix.rect(), brush); 214 p.fillRect(pix.rect(), brush);
196 frameBackground->setBackgroundPixmap(pix); 215 frameBackground->setBackgroundPixmap(pix);
197 216
198 brushBackground=brush; 217 brushBackground=brush;
199} 218}
200 219
201void CellFormat::setTextFont(const QFont &font, const QColor &color) 220void CellFormat::setTextFont(const QFont &font, const QColor &color)
202{ 221{
203 comboFontColor->setCurrentItem(findColorIndex(color)); 222 comboFontColor->setCurrentItem(findColorIndex(color));
204 comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family())); 223 comboFontFamily->setCurrentItem(findComboItemIndex(comboFontFamily, font.family()));
205 comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize()))); 224 comboFontSize->setCurrentItem(findComboItemIndex(comboFontSize, QString::number(font.pointSize())));
206 checkFontBold->setChecked(font.weight()==QFont::Bold); 225 checkFontBold->setChecked(font.weight()==QFont::Bold);
207 checkFontItalic->setChecked(font.italic()); 226 checkFontItalic->setChecked(font.italic());
208 227
209 QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height()); 228 QPixmap pix(frameFont->contentsRect().width(), frameFont->contentsRect().height());
210 QPainter p(&pix); 229 QPainter p(&pix);
211 pix.fill(); 230 pix.fill();
212 p.fillRect(pix.rect(), Qt::white); 231 p.fillRect(pix.rect(), Qt::white);
213 p.setFont(font); 232 p.setFont(font);
214 p.setPen(color); 233 p.setPen(color);
215 p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet")); 234 p.drawText(pix.rect(), Qt::AlignCenter, tr("Opie Sheet"));
216 frameFont->setBackgroundPixmap(pix); 235 frameFont->setBackgroundPixmap(pix);
217 236
218 fontFont=font; 237 fontFont=font;
219 fontColor=color; 238 fontColor=color;
220} 239}
221 240
222void CellFormat::setTextAlign(Qt::AlignmentFlags flags) 241void CellFormat::setTextAlign(Qt::AlignmentFlags flags)
223{ 242{
224 comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags)); 243 comboAlignmentVertical->setCurrentItem(findVAlignIndex(flags));
225 comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags)); 244 comboAlignmentHorizontal->setCurrentItem(findHAlignIndex(flags));
226 checkAlignmentWrap->setChecked(flags & Qt::WordBreak); 245 checkAlignmentWrap->setChecked(flags & Qt::WordBreak);
227 246
228 QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height()); 247 QPixmap pix(frameAlignment->contentsRect().width(), frameAlignment->contentsRect().height());
229 QPainter p(&pix); 248 QPainter p(&pix);
230 pix.fill(); 249 pix.fill();
231 p.fillRect(pix.rect(), Qt::white); 250 p.fillRect(pix.rect(), Qt::white);
232 p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet")); 251 p.drawText(10, 10, pix.width()-20, pix.height()-20, flags, tr("Opie Sheet"));
233 frameAlignment->setBackgroundPixmap(pix); 252 frameAlignment->setBackgroundPixmap(pix);
234 253
235 textAlignment=flags; 254 textAlignment=flags;
236} 255}
237 256
238void CellFormat::slotFontDefaults() 257void CellFormat::slotFontDefaults()
239{ 258{
240 changedFont=TRUE; 259 changedFont=TRUE;
241 setTextFont(font(), Qt::black); 260 setTextFont(font(), Qt::black);
242} 261}
243 262
244void CellFormat::slotAlignmentDefaults() 263void CellFormat::slotAlignmentDefaults()
245{ 264{
246 changedAlign=TRUE; 265 changedAlign=TRUE;
247 setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop)); 266 setTextAlign((Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop));
248} 267}
249 268
250void CellFormat::slotBackgroundDefaults() 269void CellFormat::slotBackgroundDefaults()
251{ 270{
252 changedBrush=TRUE; 271 changedBrush=TRUE;
253 setBrushBackground(Qt::white); 272 setBrushBackground(Qt::white);
254} 273}
255 274
256void CellFormat::slotBordersDefaults() 275void CellFormat::slotBordersDefaults()
257{ 276{
258 QPen defaultPen(Qt::gray, 1, Qt::SolidLine); 277 QPen defaultPen(Qt::gray, 1, Qt::SolidLine);
259 borderEditor->setPen(defaultPen, BorderEditor::Top); 278 borderEditor->setPen(defaultPen, BorderEditor::Top);
260 borderEditor->setPen(defaultPen, BorderEditor::Bottom); 279 borderEditor->setPen(defaultPen, BorderEditor::Bottom);
261 borderEditor->setPen(defaultPen, BorderEditor::Left); 280 borderEditor->setPen(defaultPen, BorderEditor::Left);
262 borderEditor->setPen(defaultPen, BorderEditor::Right); 281 borderEditor->setPen(defaultPen, BorderEditor::Right);
263 borderEditor->setPen(defaultPen, BorderEditor::Vert); 282 borderEditor->setPen(defaultPen, BorderEditor::Vert);
264 borderEditor->setPen(defaultPen, BorderEditor::Horz); 283 borderEditor->setPen(defaultPen, BorderEditor::Horz);
265} 284}
266 285
267void CellFormat::backgroundClicked(int index) 286void CellFormat::backgroundClicked(int index)
268{ 287{
269 changedBrush=TRUE; 288 changedBrush=TRUE;
270 setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()])); 289 setBrushBackground(QBrush(qtColors[comboBackgroundColor->currentItem()], brushStyles[comboBackgroundStyle->currentItem()]));
271} 290}
272 291
273void CellFormat::fontClicked(bool on) 292void CellFormat::fontClicked(bool on)
274{ 293{
275 fontClicked(0); 294 fontClicked(0);
276} 295}
277 296
278void CellFormat::fontClicked(int index) 297void CellFormat::fontClicked(int index)
279{ 298{
280 changedFont=TRUE; 299 changedFont=TRUE;
281 setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]); 300 setTextFont(QFont(comboFontFamily->currentText(), comboFontSize->currentText().toInt(), checkFontBold->isChecked() ? QFont::Bold : QFont::Normal, checkFontItalic->isChecked(), QFont::AnyCharSet), qtColors[comboFontColor->currentItem()]);
282} 301}
283 302
284void CellFormat::alignClicked(bool on) 303void CellFormat::alignClicked(bool on)
285{ 304{
286 alignClicked(0); 305 alignClicked(0);
287} 306}
288 307
289void CellFormat::alignClicked(int index) 308void CellFormat::alignClicked(int index)
290{ 309{
291 changedAlign=TRUE; 310 changedAlign=TRUE;
292 setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0))); 311 setTextAlign((Qt::AlignmentFlags)(flagsVAlign[comboAlignmentVertical->currentItem()] | flagsHAlign[comboAlignmentHorizontal->currentItem()] | (checkAlignmentWrap->isChecked() ? Qt::WordBreak : 0)));
293} 312}
294 313
295void CellFormat::createSizeCombo(QComboBox *combo) 314void CellFormat::createSizeCombo(QComboBox *combo)
296{ 315{
297 combo->clear(); 316 combo->clear();
298 QValueList<int> sizes=fontDB.standardSizes(); 317 QValueList<int> sizes=fontDB.standardSizes();
299 for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i) 318 for (QValueList<int>::ConstIterator i=sizes.begin(); i!=sizes.end(); ++i)
300 combo->insertItem(QString::number(*i)); 319 combo->insertItem(QString::number(*i));
301} 320}
302 321
303void CellFormat::borderClicked(BorderEditor::BorderArea area) 322void CellFormat::borderClicked(BorderEditor::BorderArea area)
304{ 323{
305 QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine); 324 QPen newPen(qtColors[comboBordersColor->currentItem()], comboBordersWidth->currentItem()+1, Qt::SolidLine);
306 if (newPen==borderEditor->getPen(area)) 325 if (newPen==borderEditor->getPen(area))
307 borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area); 326 borderEditor->setPen(QPen(Qt::gray, 1, Qt::NoPen), area);
308 else 327 else
309 borderEditor->setPen(newPen, area); 328 borderEditor->setPen(newPen, area);
310} 329}
311 330
312int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item) 331int CellFormat::findComboItemIndex(QComboBox *combo, const QString &item)
313{ 332{
314 for (int i=0; i<combo->count(); ++i) 333 for (int i=0; i<combo->count(); ++i)
315 if (combo->text(i)==item) 334 if (combo->text(i)==item)
316 return i; 335 return i;
317 return 0; 336 return 0;
318} 337}
319 338
@@ -321,10 +340,10 @@ QComboBox *CellFormat::createCombo(comboType type, QWidget *parent,
321 const QString &caption, int y) 340 const QString &caption, int y)
322{ 341{
323 QComboBox *combo=new QComboBox(FALSE, parent); 342 QComboBox *combo=new QComboBox(FALSE, parent);
324 combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS); 343 combo->setGeometry(70, y, COMBO_WIDTHS, COMBO_HEIGHTS);
325 combo->setSizeLimit(5); 344 combo->setSizeLimit(5);
326 345
327 switch (type) 346 switch (type)
328 { 347 {
329 case COMBO_WIDTH: createWidthCombo(combo); break; 348 case COMBO_WIDTH: createWidthCombo(combo); break;
330 case COMBO_STYLE: createStyleCombo(combo); break; 349 case COMBO_STYLE: createStyleCombo(combo); break;
@@ -334,187 +353,187 @@ QComboBox *CellFormat::createCombo(comboType type, QWidget *parent,
334 case COMBO_HALIGN: createHAlignCombo(combo); break; 353 case COMBO_HALIGN: createHAlignCombo(combo); break;
335 case COMBO_VALIGN: createVAlignCombo(combo); break; 354 case COMBO_VALIGN: createVAlignCombo(combo); break;
336 default: break; 355 default: break;
337 } 356 }
338 357
339 QLabel *label=new QLabel(combo, caption, parent); 358 QLabel *label=new QLabel(combo, caption, parent);
340 label->setGeometry(10, y, 50, COMBO_HEIGHTS); 359 label->setGeometry(10, y, 50, COMBO_HEIGHTS);
341 360
342 return combo; 361 return combo;
343} 362}
344 363
345void CellFormat::createHAlignCombo(QComboBox *combo) 364void CellFormat::createHAlignCombo(QComboBox *combo)
346{ 365{
347 for (int i=0; i<HALIGN_COUNT; ++i) 366 for (int i=0; i<HALIGN_COUNT; ++i)
348 combo->insertItem(namesHAlign[i]); 367 combo->insertItem(namesHAlign[i]);
349} 368}
350 369
351void CellFormat::createVAlignCombo(QComboBox *combo) 370void CellFormat::createVAlignCombo(QComboBox *combo)
352{ 371{
353 for (int i=0; i<VALIGN_COUNT; ++i) 372 for (int i=0; i<VALIGN_COUNT; ++i)
354 combo->insertItem(namesVAlign[i]); 373 combo->insertItem(namesVAlign[i]);
355} 374}
356 375
357void CellFormat::createWidthCombo(QComboBox *combo) 376void CellFormat::createWidthCombo(QComboBox *combo)
358{ 377{
359 int width=combo->listBox()->maxItemWidth(); 378 int width=combo->listBox()->maxItemWidth();
360 QPixmap pix(width, COMBO_HEIGHTS); 379 QPixmap pix(width, COMBO_HEIGHTS);
361 QPainter p(&pix); 380 QPainter p(&pix);
362 381
363 for (int i=1; i<=6; ++i) 382 for (int i=1; i<=6; ++i)
364 { 383 {
365 pix.fill(); 384 pix.fill();
366 p.setPen(QPen(Qt::black, i, Qt::SolidLine)); 385 p.setPen(QPen(Qt::black, i, Qt::SolidLine));
367 p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); 386 p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2);
368 combo->insertItem(pix); 387 combo->insertItem(pix);
369 } 388 }
370} 389}
371 390
372void CellFormat::createFontCombo(QComboBox *combo) 391void CellFormat::createFontCombo(QComboBox *combo)
373{ 392{
374 combo->insertStringList(fontDB.families()); 393 combo->insertStringList(fontDB.families());
375} 394}
376 395
377void CellFormat::createStyleCombo(QComboBox *combo) 396void CellFormat::createStyleCombo(QComboBox *combo)
378{ 397{
379 int width=combo->listBox()->maxItemWidth(); 398 int width=combo->listBox()->maxItemWidth();
380 QPixmap pix(width, COMBO_HEIGHTS); 399 QPixmap pix(width, COMBO_HEIGHTS);
381 QPainter p(&pix); 400 QPainter p(&pix);
382 401
383 for (int i=0; i<STYLE_COUNT; ++i) 402 for (int i=0; i<STYLE_COUNT; ++i)
384 { 403 {
385 pix.fill(); 404 pix.fill();
386 p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]); 405 p.fillRect(5, 5, width-10, COMBO_HEIGHTS-10, brushStyles[i]);
387 combo->insertItem(pix); 406 combo->insertItem(pix);
388 } 407 }
389} 408}
390 409
391void CellFormat::createColorCombo(QComboBox *combo) 410void CellFormat::createColorCombo(QComboBox *combo)
392{ 411{
393 int width=combo->listBox()->maxItemWidth(); 412 int width=combo->listBox()->maxItemWidth();
394 QPixmap pix(width, COMBO_HEIGHTS); 413 QPixmap pix(width, COMBO_HEIGHTS);
395 QPainter p(&pix); 414 QPainter p(&pix);
396 415
397 for (int i=0; i<COLOR_COUNT; ++i) 416 for (int i=0; i<COLOR_COUNT; ++i)
398 { 417 {
399 pix.fill(); 418 pix.fill();
400 p.setPen(QPen(qtColors[i], 3, Qt::SolidLine)); 419 p.setPen(QPen(qtColors[i], 3, Qt::SolidLine));
401 p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2); 420 p.drawLine(5, COMBO_HEIGHTS/2, width-10, COMBO_HEIGHTS/2);
402 combo->insertItem(pix); 421 combo->insertItem(pix);
403 } 422 }
404} 423}
405 424
406int CellFormat::exec(Sheet *s) 425int CellFormat::exec(Sheet *s)
407{ 426{
408 sheet=s; 427 sheet=s;
409 int row1, row2, col1, col2, row, col; 428 int row1, row2, col1, col2, row, col;
410 sheet->getSelection(&row1, &col1, &row2, &col2); 429 sheet->getSelection(&row1, &col1, &row2, &col2);
411 430
412 QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0), 431 QPen penTop=sheet->getPen(row1-1, col1, 0), penBottom=sheet->getPen(row2, col1, 0),
413 penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1), 432 penLeft=sheet->getPen(row1, col1-1, 1), penRight=sheet->getPen(row1, col2, 1),
414 penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0), 433 penVert=sheet->getPen(row1, col1, 1), penHorz=sheet->getPen(row1, col1, 0),
415 penDefault=borderEditor->getDefaultPen(); 434 penDefault=borderEditor->getDefaultPen();
416 for (row=row1+1; row<=row2; ++row) 435 for (row=row1+1; row<=row2; ++row)
417 if (sheet->getPen(row, col1-1, 1)!=penLeft) 436 if (sheet->getPen(row, col1-1, 1)!=penLeft)
418 { 437 {
419 penLeft=penDefault; 438 penLeft=penDefault;
420 break; 439 break;
421 } 440 }
422 for (row=row1+1; row<=row2; ++row) 441 for (row=row1+1; row<=row2; ++row)
423 if (sheet->getPen(row, col2, 1)!=penRight) 442 if (sheet->getPen(row, col2, 1)!=penRight)
424 { 443 {
425 penRight=penDefault; 444 penRight=penDefault;
426 break; 445 break;
427 } 446 }
428 for (col=col1+1; col<=col2; ++col) 447 for (col=col1+1; col<=col2; ++col)
429 if (sheet->getPen(row1-1, col, 0)!=penTop) 448 if (sheet->getPen(row1-1, col, 0)!=penTop)
430 { 449 {
431 penTop=penDefault; 450 penTop=penDefault;
432 break; 451 break;
433 } 452 }
434 for (col=col1+1; col<=col2; ++col) 453 for (col=col1+1; col<=col2; ++col)
435 if (sheet->getPen(row2, col, 0)!=penBottom) 454 if (sheet->getPen(row2, col, 0)!=penBottom)
436 { 455 {
437 penBottom=penDefault; 456 penBottom=penDefault;
438 break; 457 break;
439 } 458 }
440 for (row=row1; row<=row2; ++row) 459 for (row=row1; row<=row2; ++row)
441 for (col=col1; col<col2; ++col)
442 if (sheet->getPen(row, col, 1)!=penVert)
443 {
444 penVert=penDefault;
445 break;
446 }
447 for (row=row1; row<row2; ++row)
448 for (col=col1; col<=col2; ++col)
449 if (sheet->getPen(row, col, 0)!=penHorz)
450 {
451 penHorz=penDefault;
452 break;
453 }
454
455 borderEditor->setPen(penTop, BorderEditor::Top);
456 borderEditor->setPen(penBottom, BorderEditor::Bottom);
457 borderEditor->setPen(penLeft, BorderEditor::Left);
458 borderEditor->setPen(penRight, BorderEditor::Right);
459 borderEditor->setPen(penVert, BorderEditor::Vert);
460 borderEditor->setPen(penHorz, BorderEditor::Horz);
461
462 setBrushBackground(sheet->getBrush(row1, col1));
463 setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1));
464 setTextAlign(sheet->getAlignment(row1, col1));
465
466 if (QDialog::exec()==QDialog::Accepted)
467 {
468 penTop=borderEditor->getPen(BorderEditor::Top);
469 penBottom=borderEditor->getPen(BorderEditor::Bottom);
470 penLeft=borderEditor->getPen(BorderEditor::Left);
471 penRight=borderEditor->getPen(BorderEditor::Right);
472 penVert=borderEditor->getPen(BorderEditor::Vert);
473 penHorz=borderEditor->getPen(BorderEditor::Horz);
474
475 if (penTop!=penDefault)
476 for (col=col1; col<=col2; ++col)
477 sheet->setPen(row1-1, col, 0, penTop);
478 if (penBottom!=penDefault)
479 for (col=col1; col<=col2; ++col)
480 sheet->setPen(row2, col, 0, penBottom);
481 if (penLeft!=penDefault)
482 for (row=row1; row<=row2; ++row)
483 sheet->setPen(row, col1-1, 1, penLeft);
484 if (penRight!=penDefault)
485 for (row=row1; row<=row2; ++row)
486 sheet->setPen(row, col2, 1, penRight);
487 if (penVert!=penDefault)
488 for (row=row1; row<=row2; ++row)
489 for (col=col1; col<col2; ++col) 460 for (col=col1; col<col2; ++col)
490 sheet->setPen(row, col, 1, penVert); 461 if (sheet->getPen(row, col, 1)!=penVert)
491 if (penHorz!=penDefault) 462 {
492 for (row=row1; row<row2; ++row) 463 penVert=penDefault;
493 for (col=col1; col<=col2; ++col) 464 break;
494 sheet->setPen(row, col, 0, penHorz); 465 }
495 466 for (row=row1; row<row2; ++row)
496 if (changedBrush)
497 {
498 for (row=row1; row<=row2; ++row)
499 for (col=col1; col<=col2; ++col) 467 for (col=col1; col<=col2; ++col)
500 sheet->setBrush(row, col, brushBackground); 468 if (sheet->getPen(row, col, 0)!=penHorz)
501 } 469 {
502 470 penHorz=penDefault;
503 if (changedAlign) 471 break;
504 { 472 }
505 for (row=row1; row<=row2; ++row) 473
506 for (col=col1; col<=col2; ++col) 474 borderEditor->setPen(penTop, BorderEditor::Top);
507 sheet->setTextAlign(row, col, textAlignment); 475 borderEditor->setPen(penBottom, BorderEditor::Bottom);
508 } 476 borderEditor->setPen(penLeft, BorderEditor::Left);
509 477 borderEditor->setPen(penRight, BorderEditor::Right);
510 if (changedFont) 478 borderEditor->setPen(penVert, BorderEditor::Vert);
479 borderEditor->setPen(penHorz, BorderEditor::Horz);
480
481 setBrushBackground(sheet->getBrush(row1, col1));
482 setTextFont(sheet->getFont(row1, col1), sheet->getFontColor(row1, col1));
483 setTextAlign(sheet->getAlignment(row1, col1));
484
485 if (QDialog::exec()==QDialog::Accepted)
511 { 486 {
512 for (row=row1; row<=row2; ++row) 487 penTop=borderEditor->getPen(BorderEditor::Top);
513 for (col=col1; col<=col2; ++col) 488 penBottom=borderEditor->getPen(BorderEditor::Bottom);
514 sheet->setTextFont(row, col, fontFont, fontColor); 489 penLeft=borderEditor->getPen(BorderEditor::Left);
490 penRight=borderEditor->getPen(BorderEditor::Right);
491 penVert=borderEditor->getPen(BorderEditor::Vert);
492 penHorz=borderEditor->getPen(BorderEditor::Horz);
493
494 if (penTop!=penDefault)
495 for (col=col1; col<=col2; ++col)
496 sheet->setPen(row1-1, col, 0, penTop);
497 if (penBottom!=penDefault)
498 for (col=col1; col<=col2; ++col)
499 sheet->setPen(row2, col, 0, penBottom);
500 if (penLeft!=penDefault)
501 for (row=row1; row<=row2; ++row)
502 sheet->setPen(row, col1-1, 1, penLeft);
503 if (penRight!=penDefault)
504 for (row=row1; row<=row2; ++row)
505 sheet->setPen(row, col2, 1, penRight);
506 if (penVert!=penDefault)
507 for (row=row1; row<=row2; ++row)
508 for (col=col1; col<col2; ++col)
509 sheet->setPen(row, col, 1, penVert);
510 if (penHorz!=penDefault)
511 for (row=row1; row<row2; ++row)
512 for (col=col1; col<=col2; ++col)
513 sheet->setPen(row, col, 0, penHorz);
514
515 if (changedBrush)
516 {
517 for (row=row1; row<=row2; ++row)
518 for (col=col1; col<=col2; ++col)
519 sheet->setBrush(row, col, brushBackground);
520 }
521
522 if (changedAlign)
523 {
524 for (row=row1; row<=row2; ++row)
525 for (col=col1; col<=col2; ++col)
526 sheet->setTextAlign(row, col, textAlignment);
527 }
528
529 if (changedFont)
530 {
531 for (row=row1; row<=row2; ++row)
532 for (col=col1; col<=col2; ++col)
533 sheet->setTextFont(row, col, fontFont, fontColor);
534 }
535 return QDialog::Accepted;
515 } 536 }
516 return QDialog::Accepted; 537 return QDialog::Rejected;
517 }
518 return QDialog::Rejected;
519} 538}
520 539
@@ -524,63 +543,62 @@ int CellFormat::exec(Sheet *s)
524 543
525BorderEditor::BorderEditor(QWidget *parent) 544BorderEditor::BorderEditor(QWidget *parent)
526 :QFrame(parent) 545 :QFrame(parent)
527{ 546{
528 setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); 547 setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
529} 548}
530 549
531BorderEditor::~BorderEditor() 550BorderEditor::~BorderEditor()
532{ 551{}
533}
534 552
535void BorderEditor::drawContents(QPainter *p) 553void BorderEditor::drawContents(QPainter *p)
536{ 554{
537 QFrame::drawContents(p); 555 QFrame::drawContents(p);
538 556
539 int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; 557 int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3;
540 int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6; 558 int lineFirstX=x+width/6, lineFirstY=y+height/6, lineLastX=contentsRect().right()-width/6, lineLastY=contentsRect().bottom()-height/6;
541 559
542 p->fillRect(contentsRect(), Qt::white); 560 p->fillRect(contentsRect(), Qt::white);
543 561
544 p->fillRect(x+width/3, y+height/3, width, height, Qt::gray); 562 p->fillRect(x+width/3, y+height/3, width, height, Qt::gray);
545 p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray); 563 p->fillRect(x+(5*width/3), y+height/3, width, height, Qt::gray);
546 p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray); 564 p->fillRect(x+width/3, y+(5*height)/3, width, height, Qt::gray);
547 p->fillRect(x+(5*width)/3, y+(5*height)/3, width, height, Qt::gray); 565 p->fillRect(x+(5*width)/3, y+(5*height)/3, width, height, Qt::gray);
548 566
549 if (penTop.width()>0) 567 if (penTop.width()>0)
550 { 568 {
551 p->setPen(penTop); 569 p->setPen(penTop);
552 p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY); 570 p->drawLine(lineFirstX, lineFirstY, lineLastX, lineFirstY);
553 } 571 }
554 if (penBottom.width()>0) 572 if (penBottom.width()>0)
555 { 573 {
556 p->setPen(penBottom); 574 p->setPen(penBottom);
557 p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY); 575 p->drawLine(lineFirstX, lineLastY, lineLastX, lineLastY);
558 } 576 }
559 if (penHorz.width()>0) 577 if (penHorz.width()>0)
560 { 578 {
561 p->setPen(penHorz); 579 p->setPen(penHorz);
562 p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2); 580 p->drawLine(lineFirstX, y+contentsRect().height()/2, lineLastX, y+contentsRect().height()/2);
563 } 581 }
564 if (penLeft.width()>0) 582 if (penLeft.width()>0)
565 { 583 {
566 p->setPen(penLeft); 584 p->setPen(penLeft);
567 p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY); 585 p->drawLine(lineFirstX, lineFirstY, lineFirstX, lineLastY);
568 } 586 }
569 if (penRight.width()>0) 587 if (penRight.width()>0)
570 { 588 {
571 p->setPen(penRight); 589 p->setPen(penRight);
572 p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY); 590 p->drawLine(lineLastX, lineFirstY, lineLastX, lineLastY);
573 } 591 }
574 if (penVert.width()>0) 592 if (penVert.width()>0)
575 { 593 {
576 p->setPen(penVert); 594 p->setPen(penVert);
577 p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY); 595 p->drawLine(x+contentsRect().width()/2, lineFirstY, x+contentsRect().width()/2, lineLastY);
578 } 596 }
579} 597}
580 598
581void BorderEditor::setPen(const QPen &pen, BorderArea area) 599void BorderEditor::setPen(const QPen &pen, BorderArea area)
582{ 600{
583 switch (area) 601 switch (area)
584 { 602 {
585 case Top: penTop=pen; break; 603 case Top: penTop=pen; break;
586 case Bottom: penBottom=pen; break; 604 case Bottom: penBottom=pen; break;
@@ -589,31 +607,31 @@ void BorderEditor::setPen(const QPen &pen, BorderArea area)
589 case Horz: penHorz=pen; break; 607 case Horz: penHorz=pen; break;
590 case Vert: penVert=pen; break; 608 case Vert: penVert=pen; break;
591 }; 609 };
592 update(); 610 update();
593} 611}
594 612
595void BorderEditor::mouseReleaseEvent(QMouseEvent *e) 613void BorderEditor::mouseReleaseEvent(QMouseEvent *e)
596{ 614{
597 QFrame::mouseReleaseEvent(e); 615 QFrame::mouseReleaseEvent(e);
598 616
599 int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3; 617 int x=contentsRect().x(), y=contentsRect().y(), width=contentsRect().width()/3, height=contentsRect().height()/3;
600 BorderArea area=None; 618 BorderArea area=None;
601 619
602 if (e->x()<x+width/3) area=Left; 620 if (e->x()<x+width/3) area=Left;
603 if (e->x()>x+(8*width)/3) area=Right; 621 if (e->x()>x+(8*width)/3) area=Right;
604 if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert; 622 if (e->x()>x+(4*width)/3 && e->x()<x+(5*width)/3) area=Vert;
605 623
606 if (e->y()<y+height/3) area=Top; 624 if (e->y()<y+height/3) area=Top;
607 if (e->y()>y+(8*height)/3) area=Bottom; 625 if (e->y()>y+(8*height)/3) area=Bottom;
608 if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz; 626 if (e->y()>y+(4*height)/3 && e->y()<y+(5*height)/3) area=Horz;
609 627
610 if (area!=None) 628 if (area!=None)
611 emit clicked(area); 629 emit clicked(area);
612} 630}
613 631
614QPen BorderEditor::getPen(BorderArea area) 632QPen BorderEditor::getPen(BorderArea area)
615{ 633{
616 switch (area) 634 switch (area)
617 { 635 {
618 case Top: return penTop; 636 case Top: return penTop;
619 case Bottom: return penBottom; 637 case Bottom: return penBottom;
@@ -622,5 +640,5 @@ QPen BorderEditor::getPen(BorderArea area)
622 case Horz: return penHorz; 640 case Horz: return penHorz;
623 case Vert: return penVert; 641 case Vert: return penVert;
624 }; 642 };
625 return getDefaultPen(); 643 return getDefaultPen();
626} 644}
diff --git a/noncore/apps/opie-sheet/cellformat.h b/noncore/apps/opie-sheet/cellformat.h
index b569b7f..e07af9c 100644
--- a/noncore/apps/opie-sheet/cellformat.h
+++ b/noncore/apps/opie-sheet/cellformat.h
@@ -1,10 +1,29 @@
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/*
@@ -16,5 +35,10 @@
16#define CELLFORMAT_H 35#define CELLFORMAT_H
17 36
37#include "sheet.h"
38
39/* OPIE */
18#include <qpe/fontdatabase.h> 40#include <qpe/fontdatabase.h>
41
42/* QT */
19#include <qdialog.h> 43#include <qdialog.h>
20#include <qtabwidget.h> 44#include <qtabwidget.h>
@@ -24,20 +48,18 @@
24#include <qpushbutton.h> 48#include <qpushbutton.h>
25 49
26#include "sheet.h"
27
28class BorderEditor: public QFrame 50class BorderEditor: public QFrame
29{ 51{
30 Q_OBJECT 52 Q_OBJECT
31 53
32 // QT objects 54 // QT objects
33 QPen penTop, penBottom, penLeft, penRight, penHorz, penVert; 55 QPen penTop, penBottom, penLeft, penRight, penHorz, penVert;
34 56
35 // Private functions 57 // Private functions
36 void drawContents(QPainter *p); 58 void drawContents(QPainter *p);
37 59
38 // Reimplemented QFrame functions 60 // Reimplemented QFrame functions
39 void mouseReleaseEvent(QMouseEvent *e); 61 void mouseReleaseEvent(QMouseEvent *e);
40 62
41 public: 63public:
42 // Definitions 64 // Definitions
43 enum BorderArea {None, Top, Bottom, Left, Right, Horz, Vert}; 65 enum BorderArea {None, Top, Bottom, Left, Right, Horz, Vert};
@@ -50,5 +72,5 @@ class BorderEditor: public QFrame
50 QPen getDefaultPen() { return QPen(Qt::black, 1, Qt::DotLine); } 72 QPen getDefaultPen() { return QPen(Qt::black, 1, Qt::DotLine); }
51 73
52 signals: 74signals:
53 void clicked(BorderEditor::BorderArea); 75 void clicked(BorderEditor::BorderArea);
54}; 76};
@@ -56,44 +78,44 @@ class BorderEditor: public QFrame
56class CellFormat: public QDialog 78class CellFormat: public QDialog
57{ 79{
58 Q_OBJECT 80 Q_OBJECT
59 81
60 enum comboType {COMBO_OTHER, COMBO_WIDTH, COMBO_FONT, COMBO_SIZE, COMBO_STYLE, COMBO_COLOR, COMBO_VALIGN, COMBO_HALIGN}; 82 enum comboType {COMBO_OTHER, COMBO_WIDTH, COMBO_FONT, COMBO_SIZE, COMBO_STYLE, COMBO_COLOR, COMBO_VALIGN, COMBO_HALIGN};
61 83
62 // QT objects 84 // QT objects
63 QBoxLayout *box; 85 QBoxLayout *box;
64 QTabWidget *tabs; 86 QTabWidget *tabs;
65 QWidget *widgetBorders, *widgetBackground, *widgetFont, *widgetAlignment; 87 QWidget *widgetBorders, *widgetBackground, *widgetFont, *widgetAlignment;
66 QComboBox *comboBordersWidth, *comboBordersColor, *comboBackgroundColor, *comboBackgroundStyle, *comboFontColor, *comboFontSize, *comboFontFamily, *comboAlignmentVertical, *comboAlignmentHorizontal; 88 QComboBox *comboBordersWidth, *comboBordersColor, *comboBackgroundColor, *comboBackgroundStyle, *comboFontColor, *comboFontSize, *comboFontFamily, *comboAlignmentVertical, *comboAlignmentHorizontal;
67 QCheckBox *checkFontBold, *checkFontItalic, *checkAlignmentWrap; 89 QCheckBox *checkFontBold, *checkFontItalic, *checkAlignmentWrap;
68 QPushButton *buttonBordersDefaults, *buttonBackgroundDefaults, *buttonFontDefaults, *buttonAlignmentDefaults; 90 QPushButton *buttonBordersDefaults, *buttonBackgroundDefaults, *buttonFontDefaults, *buttonAlignmentDefaults;
69 QFrame *frameBackground, *frameFont, *frameAlignment; 91 QFrame *frameBackground, *frameFont, *frameAlignment;
70 QBrush brushBackground; 92 QBrush brushBackground;
71 QFont fontFont; 93 QFont fontFont;
72 QColor fontColor; 94 QColor fontColor;
73 Qt::AlignmentFlags textAlignment; 95 Qt::AlignmentFlags textAlignment;
74 FontDatabase fontDB; 96 FontDatabase fontDB;
75 97
76 // Other objects & variables 98 // Other objects & variables
77 Sheet *sheet; 99 Sheet *sheet;
78 BorderEditor *borderEditor; 100 BorderEditor *borderEditor;
79 bool changedFont, changedAlign, changedBrush; 101 bool changedFont, changedAlign, changedBrush;
80 102
81 // Private functions 103 // Private functions
82 void createWidthCombo(QComboBox *combo); 104 void createWidthCombo(QComboBox *combo);
83 void createFontCombo(QComboBox *combo); 105 void createFontCombo(QComboBox *combo);
84 void createHAlignCombo(QComboBox *combo); 106 void createHAlignCombo(QComboBox *combo);
85 void createVAlignCombo(QComboBox *combo); 107 void createVAlignCombo(QComboBox *combo);
86 void createStyleCombo(QComboBox *combo); 108 void createStyleCombo(QComboBox *combo);
87 void createSizeCombo(QComboBox *combo); 109 void createSizeCombo(QComboBox *combo);
88 void createColorCombo(QComboBox *combo); 110 void createColorCombo(QComboBox *combo);
89 QComboBox *createCombo(comboType type, QWidget *parent, const QString &caption, int y); 111 QComboBox *createCombo(comboType type, QWidget *parent, const QString &caption, int y);
90 112
91 int findHAlignIndex(Qt::AlignmentFlags flag); 113 int findHAlignIndex(Qt::AlignmentFlags flag);
92 int findVAlignIndex(Qt::AlignmentFlags flag); 114 int findVAlignIndex(Qt::AlignmentFlags flag);
93 int findComboItemIndex(QComboBox *combo, const QString &item); 115 int findComboItemIndex(QComboBox *combo, const QString &item);
94 int findColorIndex(const QColor &color); 116 int findColorIndex(const QColor &color);
95 int findBrushStyleIndex(Qt::BrushStyle style); 117 int findBrushStyleIndex(Qt::BrushStyle style);
96 118
97 private slots: 119private slots:
98 void borderClicked(BorderEditor::BorderArea area); 120 void borderClicked(BorderEditor::BorderArea area);
99 void backgroundClicked(int index); 121 void backgroundClicked(int index);
@@ -107,5 +129,5 @@ class CellFormat: public QDialog
107 void slotAlignmentDefaults(); 129 void slotAlignmentDefaults();
108 130
109 public: 131public:
110 CellFormat(QWidget *parent=0); 132 CellFormat(QWidget *parent=0);
111 ~CellFormat(); 133 ~CellFormat();
diff --git a/noncore/apps/opie-sheet/finddlg.cpp b/noncore/apps/opie-sheet/finddlg.cpp
index e4c6ec8..c724159 100644
--- a/noncore/apps/opie-sheet/finddlg.cpp
+++ b/noncore/apps/opie-sheet/finddlg.cpp
@@ -1,10 +1,29 @@
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/*
@@ -13,72 +32,73 @@
13 */ 32 */
14 33
34#include "finddlg.h"
35
36/* QT */
15#include <qlabel.h> 37#include <qlabel.h>
16#include <qradiobutton.h> 38#include <qradiobutton.h>
17#include "finddlg.h"
18 39
19FindDialog::FindDialog(QWidget *parent) 40FindDialog::FindDialog(QWidget *parent)
20 :QDialog(parent, 0, TRUE) 41 :QDialog(parent, 0, TRUE)
21{ 42{
22 // Main widget 43 // Main widget
23 tabs=new QTabWidget(this); 44 tabs=new QTabWidget(this);
24 widgetFind=new QWidget(tabs); 45 widgetFind=new QWidget(tabs);
25 widgetOptions=new QWidget(tabs); 46 widgetOptions=new QWidget(tabs);
26 tabs->addTab(widgetFind, tr("&Find && Replace")); 47 tabs->addTab(widgetFind, tr("&Find && Replace"));
27 tabs->addTab(widgetOptions, tr("&Options")); 48 tabs->addTab(widgetOptions, tr("&Options"));
28 49
29 // Find tab 50 // Find tab
30 QLabel *label=new QLabel(tr("&Search for:"), widgetFind); 51 QLabel *label=new QLabel(tr("&Search for:"), widgetFind);
31 label->setGeometry(10, 10, 215, 20); 52 label->setGeometry(10, 10, 215, 20);
32 editFind=new QLineEdit(widgetFind); 53 editFind=new QLineEdit(widgetFind);
33 editFind->setGeometry(10, 40, 215, 20); 54 editFind->setGeometry(10, 40, 215, 20);
34 label->setBuddy(editFind); 55 label->setBuddy(editFind);
35 56
36 label=new QLabel(tr("&Replace with:"), widgetFind); 57 label=new QLabel(tr("&Replace with:"), widgetFind);
37 label->setGeometry(10, 80, 215, 20); 58 label->setGeometry(10, 80, 215, 20);
38 editReplace=new QLineEdit(widgetFind); 59 editReplace=new QLineEdit(widgetFind);
39 editReplace->setGeometry(10, 110, 215, 20); 60 editReplace->setGeometry(10, 110, 215, 20);
40 editReplace->setEnabled(FALSE); 61 editReplace->setEnabled(FALSE);
41 label->setBuddy(editReplace); 62 label->setBuddy(editReplace);
42 63
43 groupType=new QVButtonGroup(tr("&Type"), widgetFind); 64 groupType=new QVButtonGroup(tr("&Type"), widgetFind);
44 groupType->setGeometry(10, 150, 215, 90); 65 groupType->setGeometry(10, 150, 215, 90);
45 QRadioButton *radio=new QRadioButton(tr("&Find"), groupType); 66 QRadioButton *radio=new QRadioButton(tr("&Find"), groupType);
46 radio=new QRadioButton(tr("&Replace"), groupType); 67 radio=new QRadioButton(tr("&Replace"), groupType);
47 radio=new QRadioButton(tr("Replace &all"), groupType); 68 radio=new QRadioButton(tr("Replace &all"), groupType);
48 groupType->setButton(0); 69 groupType->setButton(0);
49 connect(groupType, SIGNAL(clicked(int)), this, SLOT(typeChanged(int))); 70 connect(groupType, SIGNAL(clicked(int)), this, SLOT(typeChanged(int)));
50 71
51 // Options tab 72 // Options tab
52 checkCase=new QCheckBox(tr("Match &case"), widgetOptions); 73 checkCase=new QCheckBox(tr("Match &case"), widgetOptions);
53 checkCase->setGeometry(10, 10, 215, 20); 74 checkCase->setGeometry(10, 10, 215, 20);
54 checkSelection=new QCheckBox(tr("Current &selection only"), widgetOptions); 75 checkSelection=new QCheckBox(tr("Current &selection only"), widgetOptions);
55 checkSelection->setGeometry(10, 40, 215, 20); 76 checkSelection->setGeometry(10, 40, 215, 20);
56 checkEntire=new QCheckBox(tr("&Entire cell"), widgetOptions); 77 checkEntire=new QCheckBox(tr("&Entire cell"), widgetOptions);
57 checkEntire->setGeometry(10, 70, 215, 20); 78 checkEntire->setGeometry(10, 70, 215, 20);
58 79
59 // Main widget 80 // Main widget
60 box=new QVBoxLayout(this); 81 box=new QVBoxLayout(this);
61 box->addWidget(tabs); 82 box->addWidget(tabs);
62 83
63 setCaption(tr("Find & Replace")); 84 setCaption(tr("Find & Replace"));
64} 85}
65 86
66FindDialog::~FindDialog() 87FindDialog::~FindDialog()
67{ 88{}
68}
69 89
70void FindDialog::typeChanged(int id) 90void FindDialog::typeChanged(int id)
71{ 91{
72 editReplace->setEnabled(id>0); 92 editReplace->setEnabled(id>0);
73} 93}
74 94
75int FindDialog::exec(Sheet *s) 95int FindDialog::exec(Sheet *s)
76{ 96{
77 if (QDialog::exec()==QDialog::Accepted) 97 if (QDialog::exec()==QDialog::Accepted)
78 { 98 {
79 int id=groupType->id(groupType->selected()); 99 int id=groupType->id(groupType->selected());
80 s->dataFindReplace(editFind->text(), editReplace->text(), checkCase->isChecked(), !checkSelection->isChecked(), checkEntire->isChecked(), id>0, id>1); 100 s->dataFindReplace(editFind->text(), editReplace->text(), checkCase->isChecked(), !checkSelection->isChecked(), checkEntire->isChecked(), id>0, id>1);
81 return QDialog::Accepted; 101 return QDialog::Accepted;
82 } 102 }
83 return QDialog::Rejected; 103 return QDialog::Rejected;
84} 104}
diff --git a/noncore/apps/opie-sheet/finddlg.h b/noncore/apps/opie-sheet/finddlg.h
index 1af2da5..b456f21 100644
--- a/noncore/apps/opie-sheet/finddlg.h
+++ b/noncore/apps/opie-sheet/finddlg.h
@@ -1,10 +1,29 @@
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/*
@@ -16,4 +35,7 @@
16#define FINDDLG_H 35#define FINDDLG_H
17 36
37#include "sheet.h"
38
39/* QT */
18#include <qdialog.h> 40#include <qdialog.h>
19#include <qtabwidget.h> 41#include <qtabwidget.h>
@@ -23,22 +45,21 @@
23#include <qpushbutton.h> 45#include <qpushbutton.h>
24#include <qvbuttongroup.h> 46#include <qvbuttongroup.h>
25#include "sheet.h"
26 47
27class FindDialog: public QDialog 48class FindDialog: public QDialog
28{ 49{
29 Q_OBJECT 50 Q_OBJECT
30 51
31 // QT objects 52 // QT objects
32 QBoxLayout *box; 53 QBoxLayout *box;
33 QTabWidget *tabs; 54 QTabWidget *tabs;
34 QWidget *widgetFind, *widgetOptions; 55 QWidget *widgetFind, *widgetOptions;
35 QCheckBox *checkCase, *checkSelection, *checkEntire; 56 QCheckBox *checkCase, *checkSelection, *checkEntire;
36 QLineEdit *editFind, *editReplace; 57 QLineEdit *editFind, *editReplace;
37 QVButtonGroup *groupType; 58 QVButtonGroup *groupType;
38 59
39 private slots: 60private slots:
40 void typeChanged(int id); 61 void typeChanged(int id);
41 62
42 public: 63public:
43 FindDialog(QWidget *parent=0); 64 FindDialog(QWidget *parent=0);
44 ~FindDialog(); 65 ~FindDialog();
diff --git a/noncore/apps/opie-sheet/main.cpp b/noncore/apps/opie-sheet/main.cpp
index 861473e..bf35908 100644
--- a/noncore/apps/opie-sheet/main.cpp
+++ b/noncore/apps/opie-sheet/main.cpp
@@ -1,10 +1,29 @@
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/*
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp
index 061748e..bb85a24 100644
--- a/noncore/apps/opie-sheet/mainwindow.cpp
+++ b/noncore/apps/opie-sheet/mainwindow.cpp
@@ -1,10 +1,29 @@
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/*
@@ -15,10 +34,13 @@
15#include "mainwindow.h" 34#include "mainwindow.h"
16 35
36/* OPIE */
17#include <qpe/resource.h> 37#include <qpe/resource.h>
18#include <qpe/qpeapplication.h> 38#include <qpe/qpeapplication.h>
19 39
40/* QT */
20#include <qmessagebox.h> 41#include <qmessagebox.h>
21#include <qradiobutton.h> 42#include <qradiobutton.h>
22 43
44/* STD */
23#include "cellformat.h" 45#include "cellformat.h"
24#include "numberdlg.h" 46#include "numberdlg.h"
@@ -32,886 +54,885 @@
32 54
33MainWindow::MainWindow(QWidget *parent, const char* n, WFlags fl) 55MainWindow::MainWindow(QWidget *parent, const char* n, WFlags fl)
34 :QMainWindow(parent, n, fl) 56 :QMainWindow(parent, n, fl)
35{ 57{
36 // initialize variables 58 // initialize variables
37 documentModified=FALSE; 59 documentModified=FALSE;
38
39 // construct objects
40 currentDoc=0;
41 fileSelector=new FileSelector("application/sheet-qt", this, QString::null);
42 ExcelSelector=new FileSelector("application/excel",this,QString::null,FALSE);
43 connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide()));
44 connect(fileSelector, SIGNAL(newSelected(const DocLnk&)), this, SLOT(selectorFileNew(const DocLnk&)));
45 connect(fileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(selectorFileOpen(const DocLnk&)));
46 connect(ExcelSelector,SIGNAL(fileSelected(const DocLnk&)),this,SLOT(slotImportExcel(const DocLnk&)));
47 connect(ExcelSelector,SIGNAL(closeMe()), this, SLOT(ExcelSelectorHide()));
48
49
50 listSheets.setAutoDelete(TRUE);
51
52 initActions();
53 initMenu();
54 initEditToolbar();
55 initFunctionsToolbar();
56 initStandardToolbar();
57 initSheet();
58
59 // set window title
60 setCaption(tr("Opie Sheet"));
61 60
62 // create sheets 61 // construct objects
63 selectorFileNew(DocLnk()); 62 currentDoc=0;
63 fileSelector=new FileSelector("application/opie-sheet", this, QString::null);
64 ExcelSelector=new FileSelector("application/excel",this,QString::null,FALSE);
65 connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide()));
66 connect(fileSelector, SIGNAL(newSelected(const DocLnk&)), this, SLOT(selectorFileNew(const DocLnk&)));
67 connect(fileSelector, SIGNAL(fileSelected(const DocLnk&)), this, SLOT(selectorFileOpen(const DocLnk&)));
68 connect(ExcelSelector,SIGNAL(fileSelected(const DocLnk&)),this,SLOT(slotImportExcel(const DocLnk&)));
69 connect(ExcelSelector,SIGNAL(closeMe()), this, SLOT(ExcelSelectorHide()));
70
71 listSheets.setAutoDelete(TRUE);
72
73 initActions();
74 initMenu();
75 initEditToolbar();
76 initFunctionsToolbar();
77 initStandardToolbar();
78 initSheet();
79
80 // set window title
81 setCaption(tr("Opie Sheet"));
82
83 // create sheets
84 selectorFileNew(DocLnk());
64} 85}
65 86
66MainWindow::~MainWindow() 87MainWindow::~MainWindow()
67{ 88{
68 if (currentDoc) delete currentDoc; 89 if (currentDoc) delete currentDoc;
69} 90}
70 91
71void MainWindow::documentSave(DocLnk *lnkDoc) 92void MainWindow::documentSave(DocLnk *lnkDoc)
72{ 93{
73 FileManager fm; 94 FileManager fm;
74 QByteArray streamBuffer; 95 QByteArray streamBuffer;
75 QDataStream stream(streamBuffer, IO_WriteOnly); 96 QDataStream stream(streamBuffer, IO_WriteOnly);
76 97
77 typeSheet *currentSheet=findSheet(sheet->getName()); 98 typeSheet *currentSheet=findSheet(sheet->getName());
78 if (!currentSheet) 99 if (!currentSheet)
79 { 100 {
80 QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); 101 QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!"));
81 return; 102 return;
82 } 103 }
83 sheet->copySheetData(&currentSheet->data); 104 sheet->copySheetData(&currentSheet->data);
84 stream.writeRawBytes("SQT100", 6); 105 stream.writeRawBytes("SQT100", 6);
85 stream << (Q_UINT32)listSheets.count(); 106 stream << (Q_UINT32)listSheets.count();
86 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) 107 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
87 { 108 {
88 stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); 109 stream << tempSheet->name << (Q_UINT32)tempSheet->data.count();
89 for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) 110 for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next())
90 stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data; 111 stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data;
91 } 112 }
92 113
93 lnkDoc->setType("application/sheet-qt"); 114 lnkDoc->setType("application/opie-sheet");
94 if (!fm.saveFile(*lnkDoc, streamBuffer)) 115 if (!fm.saveFile(*lnkDoc, streamBuffer))
95 { 116 {
96 QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); 117 QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!"));
97 return; 118 return;
98 } 119 }
99 documentModified=FALSE; 120 documentModified=FALSE;
100} 121}
101 122
102void MainWindow::documentOpen(const DocLnk &lnkDoc) 123void MainWindow::documentOpen(const DocLnk &lnkDoc)
103{ 124{
104 FileManager fm; 125 FileManager fm;
105 QByteArray streamBuffer; 126 QByteArray streamBuffer;
106 if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) 127 if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer))
107 { 128 {
108 QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); 129 QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!"));
109 documentModified=FALSE; 130 documentModified=FALSE;
110 selectorFileNew(DocLnk()); 131 selectorFileNew(DocLnk());
111 return; 132 return;
112 } 133 }
113 QDataStream stream(streamBuffer, IO_ReadOnly); 134 QDataStream stream(streamBuffer, IO_ReadOnly);
114
115 Q_UINT32 countSheet, countCell, i, j, row, col, alignment;
116 typeSheet *newSheet;
117 typeCellData *newCell;
118
119 char fileFormat[7];
120 stream.readRawBytes(fileFormat, 6);
121 fileFormat[6]=0;
122 if ((QString)fileFormat!="SQT100")
123 {
124 QMessageBox::critical(this, tr("Error"), tr("Invalid file format!"));
125 documentModified=FALSE;
126 selectorFileNew(DocLnk());
127 return;
128 }
129 135
130 stream >> countSheet; 136 Q_UINT32 countSheet, countCell, i, j, row, col, alignment;
131 for (i=0; i<countSheet; ++i) 137 typeSheet *newSheet;
132 { 138 typeCellData *newCell;
133 newSheet=new typeSheet;
134 newSheet->data.setAutoDelete(TRUE);
135 stream >> newSheet->name >> countCell;
136 comboSheets->insertItem(newSheet->name);
137 139
138 for (j=0; j<countCell; ++j) 140 char fileFormat[7];
141 stream.readRawBytes(fileFormat, 6);
142 fileFormat[6]=0;
143 if ((QString)fileFormat!="SQT100")
139 { 144 {
140 newCell=new typeCellData; 145 QMessageBox::critical(this, tr("Error"), tr("Invalid file format!"));
141 stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; 146 documentModified=FALSE;
142 newCell->col=col; 147 selectorFileNew(DocLnk());
143 newCell->row=row; 148 return;
144 newCell->alignment=(Qt::AlignmentFlags)alignment;
145 newSheet->data.append(newCell);
146 } 149 }
147 listSheets.append(newSheet);
148 150
149 if (i==0) 151 stream >> countSheet;
152 for (i=0; i<countSheet; ++i)
150 { 153 {
151 sheet->setName(newSheet->name); 154 newSheet=new typeSheet;
152 sheet->setSheetData(&newSheet->data); 155 newSheet->data.setAutoDelete(TRUE);
156 stream >> newSheet->name >> countCell;
157 comboSheets->insertItem(newSheet->name);
158
159 for (j=0; j<countCell; ++j)
160 {
161 newCell=new typeCellData;
162 stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data;
163 newCell->col=col;
164 newCell->row=row;
165 newCell->alignment=(Qt::AlignmentFlags)alignment;
166 newSheet->data.append(newCell);
167 }
168 listSheets.append(newSheet);
169
170 if (i==0)
171 {
172 sheet->setName(newSheet->name);
173 sheet->setSheetData(&newSheet->data);
174 }
153 } 175 }
154 }
155} 176}
156 177
157int MainWindow::saveCurrentFile(bool ask) 178int MainWindow::saveCurrentFile(bool ask)
158{ 179{
159 if (ask) 180 if (ask)
160 { 181 {
161 int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); 182 int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
162 if (result!=QMessageBox::Yes) return result; 183 if (result!=QMessageBox::Yes) return result;
163 } 184 }
164 185
165 if (!currentDoc->isValid()) 186 if (!currentDoc->isValid())
166 { 187 {
167 TextDialog dialogText(this); 188 TextDialog dialogText(this);
168 if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; 189 if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel;
169 190
170 currentDoc->setName(dialogText.getValue()); 191 currentDoc->setName(dialogText.getValue());
171 currentDoc->setFile(QString::null); 192 currentDoc->setFile(QString::null);
172 currentDoc->setLinkFile(QString::null); 193 currentDoc->setLinkFile(QString::null);
173 } 194 }
174 195
175 documentSave(currentDoc); 196 documentSave(currentDoc);
176 return QMessageBox::Yes; 197 return QMessageBox::Yes;
177} 198}
178 199
179void MainWindow::selectorFileNew(const DocLnk &lnkDoc) 200void MainWindow::selectorFileNew(const DocLnk &lnkDoc)
180{ 201{
181 selectorHide(); 202 selectorHide();
182 203
183 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; 204 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
184 if (currentDoc) delete currentDoc; 205 if (currentDoc) delete currentDoc;
185 currentDoc = new DocLnk(lnkDoc); 206 currentDoc = new DocLnk(lnkDoc);
186 editData->clear(); 207 editData->clear();
187 listSheets.clear(); 208 listSheets.clear();
188 comboSheets->clear(); 209 comboSheets->clear();
189 210
190 typeSheet *newSheet=createNewSheet(); 211 typeSheet *newSheet=createNewSheet();
191 newSheet->data.setAutoDelete(TRUE); 212 newSheet->data.setAutoDelete(TRUE);
192 sheet->setName(newSheet->name); 213 sheet->setName(newSheet->name);
193 sheet->setSheetData(&newSheet->data); 214 sheet->setSheetData(&newSheet->data);
194 for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) 215 for (int i=1; i<DEFAULT_NUM_SHEETS; ++i)
195 createNewSheet(); 216 createNewSheet();
196 documentModified=FALSE; 217 documentModified=FALSE;
197} 218}
198 219
199void MainWindow::closeEvent(QCloseEvent *e) 220void MainWindow::closeEvent(QCloseEvent *e)
200{ 221{
201 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); 222 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore();
202 else e->accept(); 223 else e->accept();
203} 224}
204 225
205void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) 226void MainWindow::selectorFileOpen(const DocLnk &lnkDoc)
206{ 227{
207 selectorHide(); 228 selectorHide();
208 229
209 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; 230 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
210 if (currentDoc) delete currentDoc; 231 if (currentDoc) delete currentDoc;
211 currentDoc = new DocLnk(); 232 currentDoc = new DocLnk();
212 listSheets.clear(); 233 listSheets.clear();
213 comboSheets->clear(); 234 comboSheets->clear();
214 235
215 documentOpen(lnkDoc); 236 documentOpen(lnkDoc);
216 documentModified=FALSE; 237 documentModified=FALSE;
217} 238}
218 239
219void MainWindow::selectorShow() 240void MainWindow::selectorShow()
220{ 241{
221 sheet->hide(); 242 sheet->hide();
222 setCentralWidget(fileSelector); 243 setCentralWidget(fileSelector);
223 fileSelector->show(); 244 fileSelector->show();
224 fileSelector->reread(); 245 fileSelector->reread();
225} 246}
226 247
227void MainWindow::selectorHide() 248void MainWindow::selectorHide()
228{ 249{
229 fileSelector->hide(); 250 fileSelector->hide();
230 setCentralWidget(sheet); 251 setCentralWidget(sheet);
231 sheet->show(); 252 sheet->show();
232} 253}
233 254
234void MainWindow::slotFileNew() 255void MainWindow::slotFileNew()
235{ 256{
236 selectorFileNew(DocLnk()); 257 selectorFileNew(DocLnk());
237} 258}
238 259
239void MainWindow::slotFileOpen() 260void MainWindow::slotFileOpen()
240{ 261{
241 selectorShow(); 262 selectorShow();
242} 263}
243 264
244void MainWindow::slotImportExcelOpen() 265void MainWindow::slotImportExcelOpen()
245{ 266{
246 sheet->hide(); 267 sheet->hide();
247 setCentralWidget(ExcelSelector); 268 setCentralWidget(ExcelSelector);
248 ExcelSelector->show(); 269 ExcelSelector->show();
249 ExcelSelector->reread(); 270 ExcelSelector->reread();
250} 271}
251 272
252void MainWindow::ExcelSelectorHide() 273void MainWindow::ExcelSelectorHide()
253{ 274{
254 ExcelSelector->hide(); 275 ExcelSelector->hide();
255 setCentralWidget(sheet); 276 setCentralWidget(sheet);
256 sheet->show(); 277 sheet->show();
257} 278}
258 279
259void MainWindow::slotFileSave() 280void MainWindow::slotFileSave()
260{ 281{
261 saveCurrentFile(FALSE); 282 saveCurrentFile(FALSE);
262} 283}
263 284
264void MainWindow::setDocument(const QString &applnk_filename) 285void MainWindow::setDocument(const QString &applnk_filename)
265{ 286{
266 selectorFileOpen(DocLnk(applnk_filename)); 287 selectorFileOpen(DocLnk(applnk_filename));
267} 288}
268 289
269void MainWindow::initActions() 290void MainWindow::initActions()
270{ 291{
271 fileNew=new QAction(tr("New File"), Resource::loadPixmap( "new" ), tr("&New"), 0, this); 292 fileNew=new QAction(tr("New File"), Resource::loadPixmap( "new" ), tr("&New"), 0, this);
272 connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); 293 connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
273 fileOpen=new QAction(tr("Open File"), Resource::loadPixmap( "fileopen" ), tr("&Open"), 0, this); 294 fileOpen=new QAction(tr("Open File"), Resource::loadPixmap( "fileopen" ), tr("&Open"), 0, this);
274 connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); 295 connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
275 fileSave=new QAction(tr("Save File"),Resource::loadPixmap( "save" ), tr("&Save"), 0, this); 296 fileSave=new QAction(tr("Save File"),Resource::loadPixmap( "save" ), tr("&Save"), 0, this);
276 connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); 297 connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
277 fileSaveAs=new QAction(tr("Save File As"), Resource::loadPixmap( "save" ), tr("Save &As"), 0, this); 298 fileSaveAs=new QAction(tr("Save File As"), Resource::loadPixmap( "save" ), tr("Save &As"), 0, this);
278 connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); 299 connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
279 300
280 //fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); 301 //fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this);
281 //connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); 302 //connect(fileQuit, SIGNAL(activated()), this, SLOT(close()));
282 fileExcelImport=new QAction(tr("Import Excel file"),Resource::loadPixmap( "opie-sheet/excel16" ),tr("Import E&xcel file"),0,this); 303 fileExcelImport=new QAction(tr("Import Excel file"),Resource::loadPixmap( "opie-sheet/excel16" ),tr("Import E&xcel file"),0,this);
283 connect(fileExcelImport, SIGNAL(activated()), this, SLOT(slotImportExcelOpen())); 304 connect(fileExcelImport, SIGNAL(activated()), this, SLOT(slotImportExcelOpen()));
284 305
285 // helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); 306 // helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this);
286 //connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); 307 //connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral()));
287 //helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); 308 //helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this);
288 //connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); 309 //connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
289 310
290 editAccept=new QAction(tr("Accept"),Resource::loadPixmap( "enter" ) , tr("&Accept"), 0, this); 311 editAccept=new QAction(tr("Accept"),Resource::loadPixmap( "enter" ) , tr("&Accept"), 0, this);
291 connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); 312 connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept()));
292 editCancel=new QAction(tr("Cancel"), Resource::loadPixmap( "close" ), tr("&Cancel"), 0, this); 313 editCancel=new QAction(tr("Cancel"), Resource::loadPixmap( "close" ), tr("&Cancel"), 0, this);
293 connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); 314 connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel()));
294 editCellSelect=new QAction(tr("Cell Selector"), Resource::loadPixmap( "opie-sheet/cell-select" ), tr("Cell &Selector"), 0, this); 315 editCellSelect=new QAction(tr("Cell Selector"), Resource::loadPixmap( "opie-sheet/cell-select" ), tr("Cell &Selector"), 0, this);
295 editCellSelect->setToggleAction(TRUE); 316 editCellSelect->setToggleAction(TRUE);
296 connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); 317 connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool)));
297 editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); 318 editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this);
298 editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); 319 editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this);
299 editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); 320 editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this);
300 connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); 321 connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste()));
301 editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); 322 editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this);
302 connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); 323 connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents()));
303 editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); 324 editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this);
304 325
305 insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this); 326 insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this);
306 connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells())); 327 connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells()));
307 insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this); 328 insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this);
308 connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows())); 329 connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows()));
309 insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this); 330 insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this);
310 connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols())); 331 connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols()));
311 insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this); 332 insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this);
312 connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets())); 333 connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets()));
313 334
314 formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this); 335 formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this);
315 connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells())); 336 connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells()));
316 337
317 rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this); 338 rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this);
318 connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight())); 339 connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight()));
319 rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this); 340 rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this);
320 connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust())); 341 connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust()));
321 rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this); 342 rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this);
322 connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow())); 343 connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow()));
323 rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this); 344 rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this);
324 connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide())); 345 connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide()));
325 346
326 colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this); 347 colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this);
327 connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth())); 348 connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth()));
328 colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this); 349 colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this);
329 connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust())); 350 connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust()));
330 colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this); 351 colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this);
331 connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow())); 352 connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow()));
332 colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this); 353 colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this);
333 connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide())); 354 connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide()));
334 355
335 sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this); 356 sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this);
336 connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename())); 357 connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename()));
337 sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this); 358 sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this);
338 connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove())); 359 connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove()));
339 360
340 dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this); 361 dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this);
341 connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort())); 362 connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort()));
342 dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this); 363 dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this);
343 connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace())); 364 connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace()));
344 365
345 funcEqual=new QAction(tr("Equal To"), Resource::loadPixmap( "opie-sheet/func-equal" ), tr("&Equal To"), 0, this); 366 funcEqual=new QAction(tr("Equal To"), Resource::loadPixmap( "opie-sheet/func-equal" ), tr("&Equal To"), 0, this);
346 funcEqual->setToolTip("="); 367 funcEqual->setToolTip("=");
347 connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 368 connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
348 funcPlus=new QAction(tr("Addition"), Resource::loadPixmap( "opie-sheet/func-plus" ), tr("&Addition"), 0, this); 369 funcPlus=new QAction(tr("Addition"), Resource::loadPixmap( "opie-sheet/func-plus" ), tr("&Addition"), 0, this);
349 funcPlus->setToolTip("+"); 370 funcPlus->setToolTip("+");
350 connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 371 connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
351 funcMinus=new QAction(tr("Subtraction"), Resource::loadPixmap( "opie-sheet/func-minus" ), tr("&Subtraction"), 0, this); 372 funcMinus=new QAction(tr("Subtraction"), Resource::loadPixmap( "opie-sheet/func-minus" ), tr("&Subtraction"), 0, this);
352 funcMinus->setToolTip("-"); 373 funcMinus->setToolTip("-");
353 connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 374 connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
354 funcCross=new QAction(tr("Multiplication"), Resource::loadPixmap ("opie-sheet/func-cross" ), tr("&Multiplication"), 0, this); 375 funcCross=new QAction(tr("Multiplication"), Resource::loadPixmap ("opie-sheet/func-cross" ), tr("&Multiplication"), 0, this);
355 funcCross->setToolTip("*"); 376 funcCross->setToolTip("*");
356 connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 377 connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
357 funcDivide=new QAction(tr("Division"), Resource::loadPixmap( "opie-sheet/func-divide" ), tr("&Division"), 0, this); 378 funcDivide=new QAction(tr("Division"), Resource::loadPixmap( "opie-sheet/func-divide" ), tr("&Division"), 0, this);
358 funcDivide->setToolTip("/"); 379 funcDivide->setToolTip("/");
359 connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 380 connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
360 funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), Resource::loadPixmap( "opie-sheet/func-paran-open" ), tr("&Open Paranthesis"), 0, this); 381 funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), Resource::loadPixmap( "opie-sheet/func-paran-open" ), tr("&Open Paranthesis"), 0, this);
361 funcParanOpen->setToolTip("("); 382 funcParanOpen->setToolTip("(");
362 connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 383 connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
363 funcParanClose=new QAction(tr("Close Paranthesis"), Resource::loadPixmap( "opie-sheet/func-paran-close" ), tr("&Close Paranthesis"), 0, this); 384 funcParanClose=new QAction(tr("Close Paranthesis"), Resource::loadPixmap( "opie-sheet/func-paran-close" ), tr("&Close Paranthesis"), 0, this);
364 funcParanClose->setToolTip(")"); 385 funcParanClose->setToolTip(")");
365 connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 386 connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
366 funcComma=new QAction(tr("Comma"), Resource::loadPixmap( "opie-sheet/func-comma" ), tr("&Comma"), 0, this); 387 funcComma=new QAction(tr("Comma"), Resource::loadPixmap( "opie-sheet/func-comma" ), tr("&Comma"), 0, this);
367 funcComma->setToolTip(","); 388 funcComma->setToolTip(",");
368 connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 389 connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
369} 390}
370 391
371void MainWindow::initMenu() 392void MainWindow::initMenu()
372{ 393{
373 menu=new QMenuBar(this); 394 menu=new QMenuBar(this);
374 395
375 menuFile=new QPopupMenu; 396 menuFile=new QPopupMenu;
376 fileNew->addTo(menuFile); 397 fileNew->addTo(menuFile);
377 fileOpen->addTo(menuFile); 398 fileOpen->addTo(menuFile);
378 fileSave->addTo(menuFile); 399 fileSave->addTo(menuFile);
379 fileSaveAs->addTo(menuFile); 400 fileSaveAs->addTo(menuFile);
380// menuFile->insertSeparator(); 401 // menuFile->insertSeparator();
381// fileQuit->addTo(menuFile); 402 // fileQuit->addTo(menuFile);
382 menuFile->insertSeparator(); 403 menuFile->insertSeparator();
383 fileExcelImport->addTo(menuFile); 404 fileExcelImport->addTo(menuFile);
384 menu->insertItem(tr("&File"), menuFile); 405 menu->insertItem(tr("&File"), menuFile);
385 406
386 menuEdit=new QPopupMenu; 407 menuEdit=new QPopupMenu;
387 editAccept->addTo(menuEdit); 408 editAccept->addTo(menuEdit);
388 editCancel->addTo(menuEdit); 409 editCancel->addTo(menuEdit);
389 editCellSelect->addTo(menuEdit); 410 editCellSelect->addTo(menuEdit);
390 menuEdit->insertSeparator(); 411 menuEdit->insertSeparator();
391 editCut->addTo(menuEdit); 412 editCut->addTo(menuEdit);
392 editCopy->addTo(menuEdit); 413 editCopy->addTo(menuEdit);
393 editPaste->addTo(menuEdit); 414 editPaste->addTo(menuEdit);
394 editPasteContents->addTo(menuEdit); 415 editPasteContents->addTo(menuEdit);
395 editClear->addTo(menuEdit); 416 editClear->addTo(menuEdit);
396 menu->insertItem(tr("&Edit"), menuEdit); 417 menu->insertItem(tr("&Edit"), menuEdit);
397 418
398 menuInsert=new QPopupMenu; 419 menuInsert=new QPopupMenu;
399 menu->insertItem(tr("&Insert"), menuInsert); 420 menu->insertItem(tr("&Insert"), menuInsert);
400 421
401 menuFormat=new QPopupMenu; 422 menuFormat=new QPopupMenu;
402 formatCells->addTo(menuFormat); 423 formatCells->addTo(menuFormat);
403 menu->insertItem(tr("&Format"), menuFormat); 424 menu->insertItem(tr("&Format"), menuFormat);
404 425
405 menuData=new QPopupMenu; 426 menuData=new QPopupMenu;
406 dataSort->addTo(menuData); 427 dataSort->addTo(menuData);
407 dataFindReplace->addTo(menuData); 428 dataFindReplace->addTo(menuData);
408 menu->insertItem(tr("&Data"), menuData); 429 menu->insertItem(tr("&Data"), menuData);
409 430
410// menuHelp=new QPopupMenu; 431 // menuHelp=new QPopupMenu;
411// helpGeneral->addTo(menuHelp); 432 // helpGeneral->addTo(menuHelp);
412// helpAbout->addTo(menuHelp); 433 // helpAbout->addTo(menuHelp);
413// menu->insertItem(tr("&Help"), menuHelp); 434 // menu->insertItem(tr("&Help"), menuHelp);
414 435
415 submenuRow=new QPopupMenu; 436 submenuRow=new QPopupMenu;
416 rowHeight->addTo(submenuRow); 437 rowHeight->addTo(submenuRow);
417 rowAdjust->addTo(submenuRow); 438 rowAdjust->addTo(submenuRow);
418 rowShow->addTo(submenuRow); 439 rowShow->addTo(submenuRow);
419 rowHide->addTo(submenuRow); 440 rowHide->addTo(submenuRow);
420 menuFormat->insertItem(tr("&Row"), submenuRow); 441 menuFormat->insertItem(tr("&Row"), submenuRow);
421 442
422 submenuCol=new QPopupMenu; 443 submenuCol=new QPopupMenu;
423 colWidth->addTo(submenuCol); 444 colWidth->addTo(submenuCol);
424 colAdjust->addTo(submenuCol); 445 colAdjust->addTo(submenuCol);
425 colShow->addTo(submenuCol); 446 colShow->addTo(submenuCol);
426 colHide->addTo(submenuCol); 447 colHide->addTo(submenuCol);
427 menuFormat->insertItem(tr("Colum&n"), submenuCol); 448 menuFormat->insertItem(tr("Colum&n"), submenuCol);
428 449
429 submenuSheet=new QPopupMenu; 450 submenuSheet=new QPopupMenu;
430 sheetRename->addTo(submenuSheet); 451 sheetRename->addTo(submenuSheet);
431 sheetRemove->addTo(submenuSheet); 452 sheetRemove->addTo(submenuSheet);
432 menuFormat->insertItem(tr("&Sheet"), submenuSheet); 453 menuFormat->insertItem(tr("&Sheet"), submenuSheet);
433 454
434 submenuFunc=new QPopupMenu; 455 submenuFunc=new QPopupMenu;
435 menuInsert->insertItem(tr("&Function"), submenuFunc); 456 menuInsert->insertItem(tr("&Function"), submenuFunc);
436 457
437 submenuFuncStd=new QPopupMenu; 458 submenuFuncStd=new QPopupMenu;
438 funcPlus->addTo(submenuFuncStd); 459 funcPlus->addTo(submenuFuncStd);
439 funcMinus->addTo(submenuFuncStd); 460 funcMinus->addTo(submenuFuncStd);
440 funcCross->addTo(submenuFuncStd); 461 funcCross->addTo(submenuFuncStd);
441 funcDivide->addTo(submenuFuncStd); 462 funcDivide->addTo(submenuFuncStd);
442 submenuFunc->insertItem(tr("&Simple"), submenuFuncStd); 463 submenuFunc->insertItem(tr("&Simple"), submenuFuncStd);
443 464
444 465
445 466
446 submenuFuncStandard=new QPopupMenu; 467 submenuFuncStandard=new QPopupMenu;
447 addFlyAction(tr("ABS(x)"), tr("ABS(x)"), "ABS(", submenuFuncStandard); 468 addFlyAction(tr("ABS(x)"), tr("ABS(x)"), "ABS(", submenuFuncStandard);
448 addFlyAction(tr("CEILING(x,acc)"), tr("CEILING(x,acc)"), "CEILING(", submenuFuncStandard); 469 addFlyAction(tr("CEILING(x,acc)"), tr("CEILING(x,acc)"), "CEILING(", submenuFuncStandard);
449 addFlyAction(tr("FACT(x)"), tr("FACT(x)"), "FACT(", submenuFuncStandard); 470 addFlyAction(tr("FACT(x)"), tr("FACT(x)"), "FACT(", submenuFuncStandard);
450 addFlyAction(tr("FLOOR(x,acc)"), tr("FLOOR(x,acc)"), "FLOOR(", submenuFuncStandard); 471 addFlyAction(tr("FLOOR(x,acc)"), tr("FLOOR(x,acc)"), "FLOOR(", submenuFuncStandard);
451 addFlyAction(tr("INT(x)"), tr("INT(x)"), "INT(", submenuFuncStandard); 472 addFlyAction(tr("INT(x)"), tr("INT(x)"), "INT(", submenuFuncStandard);
452 addFlyAction(tr("MOD(x,y)"), tr("MOD(x,y)"), "MOD(", submenuFuncStandard); 473 addFlyAction(tr("MOD(x,y)"), tr("MOD(x,y)"), "MOD(", submenuFuncStandard);
453 addFlyAction(tr("ROUND(x,digits)"), tr("ROUND(x,digits)"), "ROUND(", submenuFuncStandard); 474 addFlyAction(tr("ROUND(x,digits)"), tr("ROUND(x,digits)"), "ROUND(", submenuFuncStandard);
454 addFlyAction(tr("SIGN(x)"), tr("SIGN(x)"), "SIGN(", submenuFuncStandard); 475 addFlyAction(tr("SIGN(x)"), tr("SIGN(x)"), "SIGN(", submenuFuncStandard);
455 submenuFuncStandard->insertSeparator(); 476 submenuFuncStandard->insertSeparator();
456 addFlyAction(tr("EXP(x)"), tr("EXP(x)"), "EXP(", submenuFuncStandard); 477 addFlyAction(tr("EXP(x)"), tr("EXP(x)"), "EXP(", submenuFuncStandard);
457 addFlyAction(tr("LN(x)"), tr("LN(x)"), "LN(", submenuFuncStandard); 478 addFlyAction(tr("LN(x)"), tr("LN(x)"), "LN(", submenuFuncStandard);
458 addFlyAction(tr("LOG(x,b)"), tr("LOG(x,b)"), "LOG(", submenuFuncStandard); 479 addFlyAction(tr("LOG(x,b)"), tr("LOG(x,b)"), "LOG(", submenuFuncStandard);
459 addFlyAction(tr("LOG10(x)"), tr("LOG10(x)"), "LOG10(", submenuFuncStandard); 480 addFlyAction(tr("LOG10(x)"), tr("LOG10(x)"), "LOG10(", submenuFuncStandard);
460 addFlyAction(tr("POWER(x,y)"), tr("POWER(x,y)"), "POWER(", submenuFuncStandard); 481 addFlyAction(tr("POWER(x,y)"), tr("POWER(x,y)"), "POWER(", submenuFuncStandard);
461 addFlyAction(tr("SQRT(x)"), tr("SQRT(x)"), "SQRT(", submenuFuncStandard); 482 addFlyAction(tr("SQRT(x)"), tr("SQRT(x)"), "SQRT(", submenuFuncStandard);
462 submenuFuncStandard->insertSeparator(); 483 submenuFuncStandard->insertSeparator();
463 addFlyAction(tr("DEGREES(x)"), tr("DEGREES(x)"), "DEGREES(", submenuFuncStandard); 484 addFlyAction(tr("DEGREES(x)"), tr("DEGREES(x)"), "DEGREES(", submenuFuncStandard);
464 addFlyAction(tr("RADIANS(x)"), tr("RADIANS(x)"), "RADIANS(", submenuFuncStandard); 485 addFlyAction(tr("RADIANS(x)"), tr("RADIANS(x)"), "RADIANS(", submenuFuncStandard);
465 addFlyAction(tr("PI()"), tr("PI()"), "PI()", submenuFuncStandard); 486 addFlyAction(tr("PI()"), tr("PI()"), "PI()", submenuFuncStandard);
466 addFlyAction(tr("RAND()"), tr("RAND()"), "RAND(", submenuFuncStandard); 487 addFlyAction(tr("RAND()"), tr("RAND()"), "RAND(", submenuFuncStandard);
467 addFlyAction(tr("RANDBETWEEN(a,b)"), tr("RANDBETWEEN(a,b)"), "RANDBETWEEN(", submenuFuncStandard); 488 addFlyAction(tr("RANDBETWEEN(a,b)"), tr("RANDBETWEEN(a,b)"), "RANDBETWEEN(", submenuFuncStandard);
468 submenuFunc->insertItem(tr("S&tandard"), submenuFuncStandard); 489 submenuFunc->insertItem(tr("S&tandard"), submenuFuncStandard);
469 490
470 submenuFuncLogic=new QPopupMenu; 491 submenuFuncLogic=new QPopupMenu;
471 addFlyAction(tr("AND(x1,x2)"), tr("AND(x1,x2)"), "AND(", submenuFuncLogic); 492 addFlyAction(tr("AND(x1,x2)"), tr("AND(x1,x2)"), "AND(", submenuFuncLogic);
472 addFlyAction(tr("NOT(x)"), tr("NOT(x)"), "NOT(", submenuFuncLogic); 493 addFlyAction(tr("NOT(x)"), tr("NOT(x)"), "NOT(", submenuFuncLogic);
473 addFlyAction(tr("OR(x1,x2)"), tr("OR(x1,x2)"), "OR(", submenuFuncLogic); 494 addFlyAction(tr("OR(x1,x2)"), tr("OR(x1,x2)"), "OR(", submenuFuncLogic);
474 submenuFuncLogic->insertSeparator(); 495 submenuFuncLogic->insertSeparator();
475 addFlyAction(tr("IF(compare,val1,val2)"), tr("IF(compare,val1,val2)"), "IF(", submenuFuncLogic); 496 addFlyAction(tr("IF(compare,val1,val2)"), tr("IF(compare,val1,val2)"), "IF(", submenuFuncLogic);
476 addFlyAction(tr("INDEX(range,index)"),tr("INDEX(range,index)"), "INDEX(", submenuFuncLogic); 497 addFlyAction(tr("INDEX(range,index)"),tr("INDEX(range,index)"), "INDEX(", submenuFuncLogic);
477 addFlyAction(tr("ISBLANK(x)"), tr("ISBLANK(x)"), "ISBLANK(", submenuFuncLogic); 498 addFlyAction(tr("ISBLANK(x)"), tr("ISBLANK(x)"), "ISBLANK(", submenuFuncLogic);
478 addFlyAction(tr("ISNUMBER(x)"), tr("ISNUMBER(x)"), "ISNUMBER(", submenuFuncLogic); 499 addFlyAction(tr("ISNUMBER(x)"), tr("ISNUMBER(x)"), "ISNUMBER(", submenuFuncLogic);
479 addFlyAction(tr("EVEN(x)"), tr("EVEN(x)"), "EVEN(", submenuFuncLogic); 500 addFlyAction(tr("EVEN(x)"), tr("EVEN(x)"), "EVEN(", submenuFuncLogic);
480 addFlyAction(tr("ISEVEN(x)"), tr("ISEVEN(x)"), "ISEVEN(", submenuFuncLogic); 501 addFlyAction(tr("ISEVEN(x)"), tr("ISEVEN(x)"), "ISEVEN(", submenuFuncLogic);
481 addFlyAction(tr("ODD(x)"), tr("ODD(x)"), "ODD(", submenuFuncLogic); 502 addFlyAction(tr("ODD(x)"), tr("ODD(x)"), "ODD(", submenuFuncLogic);
482 addFlyAction(tr("ISODD(x)"), tr("ISODD(x)"), "ISODD(", submenuFuncLogic); 503 addFlyAction(tr("ISODD(x)"), tr("ISODD(x)"), "ISODD(", submenuFuncLogic);
483 submenuFunc->insertItem(tr("Logical-&Information"), submenuFuncLogic); 504 submenuFunc->insertItem(tr("Logical-&Information"), submenuFuncLogic);
484 505
485 submenuFuncTrig=new QPopupMenu; 506 submenuFuncTrig=new QPopupMenu;
486 addFlyAction(tr("SIN(x)"), tr("SIN(x)"), "SIN(", submenuFuncTrig); 507 addFlyAction(tr("SIN(x)"), tr("SIN(x)"), "SIN(", submenuFuncTrig);
487 addFlyAction(tr("COS(x)"), tr("COS(x)"), "COS(", submenuFuncTrig); 508 addFlyAction(tr("COS(x)"), tr("COS(x)"), "COS(", submenuFuncTrig);
488 addFlyAction(tr("TAN(x)"), tr("TAN(x)"), "TAN(", submenuFuncTrig); 509 addFlyAction(tr("TAN(x)"), tr("TAN(x)"), "TAN(", submenuFuncTrig);
489 addFlyAction(tr("ASIN(x)"), tr("ASIN(x)"), "ASIN(", submenuFuncTrig); 510 addFlyAction(tr("ASIN(x)"), tr("ASIN(x)"), "ASIN(", submenuFuncTrig);
490 addFlyAction(tr("ACOS(x)"), tr("ACOS(x)"), "ACOS(", submenuFuncTrig); 511 addFlyAction(tr("ACOS(x)"), tr("ACOS(x)"), "ACOS(", submenuFuncTrig);
491 addFlyAction(tr("ATAN(x)"), tr("ATAN(x)"), "ATAN(", submenuFuncTrig); 512 addFlyAction(tr("ATAN(x)"), tr("ATAN(x)"), "ATAN(", submenuFuncTrig);
492 addFlyAction(tr("ATAN2(x,y)"), tr("ATAN2(x,y)"), "ATAN2(", submenuFuncTrig); 513 addFlyAction(tr("ATAN2(x,y)"), tr("ATAN2(x,y)"), "ATAN2(", submenuFuncTrig);
493 submenuFuncTrig->insertSeparator(); 514 submenuFuncTrig->insertSeparator();
494 addFlyAction(tr("SINH(x)"), tr("SINH(x)"), "SINH(", submenuFuncTrig); 515 addFlyAction(tr("SINH(x)"), tr("SINH(x)"), "SINH(", submenuFuncTrig);
495 addFlyAction(tr("COSH(x)"), tr("COSH(x)"), "COSH(", submenuFuncTrig); 516 addFlyAction(tr("COSH(x)"), tr("COSH(x)"), "COSH(", submenuFuncTrig);
496 addFlyAction(tr("TANH(x)"), tr("TANH(x)"), "TANH(", submenuFuncTrig); 517 addFlyAction(tr("TANH(x)"), tr("TANH(x)"), "TANH(", submenuFuncTrig);
497 addFlyAction(tr("ACOSH(x)"), tr("ACOSH(x)"), "ACOSH(", submenuFuncTrig); 518 addFlyAction(tr("ACOSH(x)"), tr("ACOSH(x)"), "ACOSH(", submenuFuncTrig);
498 addFlyAction(tr("ASINH(x)"), tr("ASINH(x)"), "ASINH(", submenuFuncTrig); 519 addFlyAction(tr("ASINH(x)"), tr("ASINH(x)"), "ASINH(", submenuFuncTrig);
499 addFlyAction(tr("ATANH(x)"), tr("ATANH(x)"), "ATANH(", submenuFuncTrig); 520 addFlyAction(tr("ATANH(x)"), tr("ATANH(x)"), "ATANH(", submenuFuncTrig);
500 submenuFunc->insertItem(tr("&Trigonometric"), submenuFuncTrig); 521 submenuFunc->insertItem(tr("&Trigonometric"), submenuFuncTrig);
501 522
502 submenuFuncString=new QPopupMenu; 523 submenuFuncString=new QPopupMenu;
503 addFlyAction(tr("LEN(s)"), tr("LEN(s)"), "LEN(",submenuFuncString); 524 addFlyAction(tr("LEN(s)"), tr("LEN(s)"), "LEN(",submenuFuncString);
504 addFlyAction(tr("LEFT(s,num)"), tr("LEFT(s,num)"), "LEFT(",submenuFuncString); 525 addFlyAction(tr("LEFT(s,num)"), tr("LEFT(s,num)"), "LEFT(",submenuFuncString);
505 addFlyAction(tr("RIGHT(s,num)"), tr("RIGHT(s,num)"), "RIGHT(",submenuFuncString); 526 addFlyAction(tr("RIGHT(s,num)"), tr("RIGHT(s,num)"), "RIGHT(",submenuFuncString);
506 addFlyAction(tr("MID(s,pos,len)"), tr("MID(s,pos,len)"), "MID(",submenuFuncString); 527 addFlyAction(tr("MID(s,pos,len)"), tr("MID(s,pos,len)"), "MID(",submenuFuncString);
507 submenuFuncString->insertSeparator(); 528 submenuFuncString->insertSeparator();
508 addFlyAction(tr("CONCATENATE(s1,s2..)"), tr("CONCATENATE(s1,s2..)"), "CONCATENATE(",submenuFuncString); 529 addFlyAction(tr("CONCATENATE(s1,s2..)"), tr("CONCATENATE(s1,s2..)"), "CONCATENATE(",submenuFuncString);
509 addFlyAction(tr("EXACT(s1,s2)"), tr("EXACT(s1,s2)"), "EXACT(",submenuFuncString); 530 addFlyAction(tr("EXACT(s1,s2)"), tr("EXACT(s1,s2)"), "EXACT(",submenuFuncString);
510 addFlyAction(tr("FIND(what,where,pos)"), 531 addFlyAction(tr("FIND(what,where,pos)"),
511 tr("FIND(what,where,pos)"), "FIND(",submenuFuncString); 532 tr("FIND(what,where,pos)"), "FIND(",submenuFuncString);
512 addFlyAction(tr("REPLACE(s,pos,len,ns)"), tr("REPLACE(s,pos,len,ns)"), "REPLACE(",submenuFuncString); 533 addFlyAction(tr("REPLACE(s,pos,len,ns)"), tr("REPLACE(s,pos,len,ns)"), "REPLACE(",submenuFuncString);
513 addFlyAction(tr("REPT(s,n)"), tr("REPT(s,n)"), "REPT(",submenuFuncString); 534 addFlyAction(tr("REPT(s,n)"), tr("REPT(s,n)"), "REPT(",submenuFuncString);
514 submenuFuncString->insertSeparator(); 535 submenuFuncString->insertSeparator();
515 addFlyAction(tr("UPPER(s)"), tr("UPPER(s)"), "UPPER(",submenuFuncString); 536 addFlyAction(tr("UPPER(s)"), tr("UPPER(s)"), "UPPER(",submenuFuncString);
516 addFlyAction(tr("LOWER(s)"), tr("LOWER(s)"), "LOWER(",submenuFuncString); 537 addFlyAction(tr("LOWER(s)"), tr("LOWER(s)"), "LOWER(",submenuFuncString);
517 submenuFunc->insertItem(tr("&Strings"), submenuFuncString); 538 submenuFunc->insertItem(tr("&Strings"), submenuFuncString);
518 539
519 submenuFuncStat=new QPopupMenu; 540 submenuFuncStat=new QPopupMenu;
520 addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat); 541 addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat);
521 addFlyAction(tr("COUNT(range)"), tr("COUNT(range)"), "COUNT(",submenuFuncStat); 542 addFlyAction(tr("COUNT(range)"), tr("COUNT(range)"), "COUNT(",submenuFuncStat);
522 addFlyAction(tr("COUNTIF(range,eqls)"), tr("COUNTIF(range,eqls)"), "COUNTIF(",submenuFuncStat); 543 addFlyAction(tr("COUNTIF(range,eqls)"), tr("COUNTIF(range,eqls)"), "COUNTIF(",submenuFuncStat);
523 addFlyAction(tr("MAX(range)"), tr("MAX(range)"), "MAX(",submenuFuncStat); 544 addFlyAction(tr("MAX(range)"), tr("MAX(range)"), "MAX(",submenuFuncStat);
524 addFlyAction(tr("MIN(range)"), tr("MIN(range)"), "MIN(",submenuFuncStat); 545 addFlyAction(tr("MIN(range)"), tr("MIN(range)"), "MIN(",submenuFuncStat);
525 addFlyAction(tr("SUM(range)"), tr("SUM(range)"), "SUM(",submenuFuncStat); 546 addFlyAction(tr("SUM(range)"), tr("SUM(range)"), "SUM(",submenuFuncStat);
526 addFlyAction(tr("SUMSQ(range)"), tr("SUMSQ(range)"), "SUMSQ(",submenuFuncStat); 547 addFlyAction(tr("SUMSQ(range)"), tr("SUMSQ(range)"), "SUMSQ(",submenuFuncStat);
527 submenuFuncStat->insertSeparator(); 548 submenuFuncStat->insertSeparator();
528 addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat); 549 addFlyAction(tr("AVERAGE(range)"), tr("AVERAGE(range)"), "AVERAGE(",submenuFuncStat);
529 addFlyAction(tr("VAR(range)"), tr("VAR(range)"), "VAR(",submenuFuncStat); 550 addFlyAction(tr("VAR(range)"), tr("VAR(range)"), "VAR(",submenuFuncStat);
530 addFlyAction(tr("VARP(range)"), tr("VARP(range)"), "VARP(",submenuFuncStat); 551 addFlyAction(tr("VARP(range)"), tr("VARP(range)"), "VARP(",submenuFuncStat);
531 addFlyAction(tr("STDEV(range)"), tr("STDEV(range)"), "STDEV(",submenuFuncStat); 552 addFlyAction(tr("STDEV(range)"), tr("STDEV(range)"), "STDEV(",submenuFuncStat);
532 addFlyAction(tr("STDEVP(range)"), tr("STDEVP(range)"), "STDEVP(",submenuFuncStat); 553 addFlyAction(tr("STDEVP(range)"), tr("STDEVP(range)"), "STDEVP(",submenuFuncStat);
533 addFlyAction(tr("SKEW(range)"), tr("SKEW(range)"), "SKEW(",submenuFuncStat); 554 addFlyAction(tr("SKEW(range)"), tr("SKEW(range)"), "SKEW(",submenuFuncStat);
534 addFlyAction(tr("KURT(range)"), tr("KURT(range)"), "KURT(",submenuFuncStat); 555 addFlyAction(tr("KURT(range)"), tr("KURT(range)"), "KURT(",submenuFuncStat);
535 submenuFunc->insertItem(tr("Sta&tistical"), submenuFuncStat); 556 submenuFunc->insertItem(tr("Sta&tistical"), submenuFuncStat);
536 557
537 submenuFuncScientific=new QPopupMenu; 558 submenuFuncScientific=new QPopupMenu;
538 addFlyAction(tr("BESSELI(x,n)"), tr("BESSELI(x,n)"), "BESSELI(",submenuFuncScientific); 559 addFlyAction(tr("BESSELI(x,n)"), tr("BESSELI(x,n)"), "BESSELI(",submenuFuncScientific);
539 addFlyAction(tr("BESSELJ(x,n)"), tr("BESSELJ(x,n)"), "BESSELJ(",submenuFuncScientific); 560 addFlyAction(tr("BESSELJ(x,n)"), tr("BESSELJ(x,n)"), "BESSELJ(",submenuFuncScientific);
540 addFlyAction(tr("BESSELK(x,n)"), tr("BESSELK(x,n)"), "BESSELK(",submenuFuncScientific); 561 addFlyAction(tr("BESSELK(x,n)"), tr("BESSELK(x,n)"), "BESSELK(",submenuFuncScientific);
541 addFlyAction(tr("BESSELY(x,n)"), tr("BESSELY(x,n)"), "BESSELY(",submenuFuncScientific); 562 addFlyAction(tr("BESSELY(x,n)"), tr("BESSELY(x,n)"), "BESSELY(",submenuFuncScientific);
542 submenuFuncScientific->insertSeparator(); 563 submenuFuncScientific->insertSeparator();
543 addFlyAction(tr("BETAI(x,a,b)"), tr("BETAI(x,a,b)"), "BETAI(",submenuFuncScientific); 564 addFlyAction(tr("BETAI(x,a,b)"), tr("BETAI(x,a,b)"), "BETAI(",submenuFuncScientific);
544 addFlyAction(tr("ERF(a,b)"), tr("ERF(a,b)"), "ERF(",submenuFuncScientific); 565 addFlyAction(tr("ERF(a,b)"), tr("ERF(a,b)"), "ERF(",submenuFuncScientific);
545 addFlyAction(tr("ERFC(a,b)"), tr("ERFC(a,b)"), "ERFC(",submenuFuncScientific); 566 addFlyAction(tr("ERFC(a,b)"), tr("ERFC(a,b)"), "ERFC(",submenuFuncScientific);
546 addFlyAction(tr("GAMMALN(x)"), tr("GAMMALN(x)"), "GAMMALN(",submenuFuncScientific); 567 addFlyAction(tr("GAMMALN(x)"), tr("GAMMALN(x)"), "GAMMALN(",submenuFuncScientific);
547 addFlyAction(tr("GAMMAP(x,a)"), tr("GAMMAP(x,a)"), "GAMMAP(",submenuFuncScientific); 568 addFlyAction(tr("GAMMAP(x,a)"), tr("GAMMAP(x,a)"), "GAMMAP(",submenuFuncScientific);
548 addFlyAction(tr("GAMMAQ(x,a)"), tr("GAMMAQ(x,a)"), "GAMMAQ(",submenuFuncScientific); 569 addFlyAction(tr("GAMMAQ(x,a)"), tr("GAMMAQ(x,a)"), "GAMMAQ(",submenuFuncScientific);
549 submenuFunc->insertItem(tr("Scienti&fic"), submenuFuncScientific); 570 submenuFunc->insertItem(tr("Scienti&fic"), submenuFuncScientific);
550 571
551 submenuFuncDistr=new QPopupMenu; 572 submenuFuncDistr=new QPopupMenu;
552 addFlyAction(tr("BETADIST(z,a,b,Q?)"), tr("BETADIST(z,a,b,Q?)"), "BETADIST(",submenuFuncDistr); 573 addFlyAction(tr("BETADIST(z,a,b,Q?)"), tr("BETADIST(z,a,b,Q?)"), "BETADIST(",submenuFuncDistr);
553 addFlyAction(tr("CHI2DIST(x,n,Q?)"), tr("CHI2DIST(x,n,Q?)"), "CHI2DIST(",submenuFuncDistr); 574 addFlyAction(tr("CHI2DIST(x,n,Q?)"), tr("CHI2DIST(x,n,Q?)"), "CHI2DIST(",submenuFuncDistr);
554 addFlyAction(tr("CHIDIST(x,n,Q?)"), tr("CHIDIST(x,n,Q?)"), "CHIDIST(",submenuFuncDistr); 575 addFlyAction(tr("CHIDIST(x,n,Q?)"), tr("CHIDIST(x,n,Q?)"), "CHIDIST(",submenuFuncDistr);
555 addFlyAction(tr("FDIST(z,deg1,deg2,Q?)"), tr("FDIST(z,deg1,deg2,Q?)"), "FDIST(",submenuFuncDistr); 576 addFlyAction(tr("FDIST(z,deg1,deg2,Q?)"), tr("FDIST(z,deg1,deg2,Q?)"), "FDIST(",submenuFuncDistr);
556 addFlyAction(tr("GAMMADIST(x,a,b,Q?)"), tr("GAMMADIST(x,a,b,Q?)"), "GAMMADIST(",submenuFuncDistr); 577 addFlyAction(tr("GAMMADIST(x,a,b,Q?)"), tr("GAMMADIST(x,a,b,Q?)"), "GAMMADIST(",submenuFuncDistr);
557 addFlyAction(tr("NORMALDIST(x,m,s,Q?)"), tr("NORMALDIST(x,m,s,Q?)"), "NORMALDIST(",submenuFuncDistr); 578 addFlyAction(tr("NORMALDIST(x,m,s,Q?)"), tr("NORMALDIST(x,m,s,Q?)"), "NORMALDIST(",submenuFuncDistr);
558 addFlyAction(tr("PHI(x,Q?)"), tr("PHI(x,Q?)"), "PHI(",submenuFuncDistr); 579 addFlyAction(tr("PHI(x,Q?)"), tr("PHI(x,Q?)"), "PHI(",submenuFuncDistr);
559 addFlyAction(tr("POISSON(x,n,Q?)"), tr("POISSON(x,n,Q?)"), "POISSON(",submenuFuncDistr); 580 addFlyAction(tr("POISSON(x,n,Q?)"), tr("POISSON(x,n,Q?)"), "POISSON(",submenuFuncDistr);
560 submenuFunc->insertItem(tr("&Distributions"), submenuFuncDistr); 581 submenuFunc->insertItem(tr("&Distributions"), submenuFuncDistr);
561 582
562 583
563 584
564 menuInsert->insertSeparator(); 585 menuInsert->insertSeparator();
565 insertCells->addTo(menuInsert); 586 insertCells->addTo(menuInsert);
566 insertRows->addTo(menuInsert); 587 insertRows->addTo(menuInsert);
567 insertCols->addTo(menuInsert); 588 insertCols->addTo(menuInsert);
568 insertSheets->addTo(menuInsert); 589 insertSheets->addTo(menuInsert);
569} 590}
570 591
571void MainWindow::initStandardToolbar() 592void MainWindow::initStandardToolbar()
572{ 593{
573 toolbarStandard=new QToolBar(this); 594 toolbarStandard=new QToolBar(this);
574 toolbarStandard->setHorizontalStretchable(TRUE); 595 toolbarStandard->setHorizontalStretchable(TRUE);
575 moveToolBar(toolbarStandard, Top); 596 moveToolBar(toolbarStandard, Top);
576 597
577 fileNew->addTo(toolbarStandard); 598 fileNew->addTo(toolbarStandard);
578 fileOpen->addTo(toolbarStandard); 599 fileOpen->addTo(toolbarStandard);
579 fileSave->addTo(toolbarStandard); 600 fileSave->addTo(toolbarStandard);
580 601
581 comboSheets=new QComboBox(toolbarStandard); 602 comboSheets=new QComboBox(toolbarStandard);
582 toolbarStandard->setStretchableWidget(comboSheets); 603 toolbarStandard->setStretchableWidget(comboSheets);
583 connect(comboSheets, SIGNAL(activated(const QString&)), this, SLOT(slotSheetChanged(const QString&))); 604 connect(comboSheets, SIGNAL(activated(const QString&)), this, SLOT(slotSheetChanged(const QString&)));
584} 605}
585 606
586void MainWindow::initFunctionsToolbar() 607void MainWindow::initFunctionsToolbar()
587{ 608{
588 toolbarFunctions=new QToolBar(this); 609 toolbarFunctions=new QToolBar(this);
589 toolbarFunctions->setHorizontalStretchable(TRUE); 610 toolbarFunctions->setHorizontalStretchable(TRUE);
590 moveToolBar(toolbarFunctions, Bottom); 611 moveToolBar(toolbarFunctions, Bottom);
591 612
592 funcEqual->addTo(toolbarFunctions); 613 funcEqual->addTo(toolbarFunctions);
593 funcPlus->addTo(toolbarFunctions); 614 funcPlus->addTo(toolbarFunctions);
594 funcMinus->addTo(toolbarFunctions); 615 funcMinus->addTo(toolbarFunctions);
595 funcCross->addTo(toolbarFunctions); 616 funcCross->addTo(toolbarFunctions);
596 funcDivide->addTo(toolbarFunctions); 617 funcDivide->addTo(toolbarFunctions);
597 funcParanOpen->addTo(toolbarFunctions); 618 funcParanOpen->addTo(toolbarFunctions);
598 funcParanClose->addTo(toolbarFunctions); 619 funcParanClose->addTo(toolbarFunctions);
599 funcComma->addTo(toolbarFunctions); 620 funcComma->addTo(toolbarFunctions);
600 621
601 toolFunction=new QToolButton(toolbarFunctions); 622 toolFunction=new QToolButton(toolbarFunctions);
602 toolFunction->setPixmap(Resource::loadPixmap( "opie-sheet/func-func" )); 623 toolFunction->setPixmap(Resource::loadPixmap( "opie-sheet/func-func" ));
603 toolFunction->setTextLabel(tr("Functions")); 624 toolFunction->setTextLabel(tr("Functions"));
604 toolFunction->setPopup(submenuFunc); 625 toolFunction->setPopup(submenuFunc);
605 toolFunction->setPopupDelay(0); 626 toolFunction->setPopupDelay(0);
606} 627}
607 628
608void MainWindow::initEditToolbar() 629void MainWindow::initEditToolbar()
609{ 630{
610 toolbarEdit=new QToolBar(this); 631 toolbarEdit=new QToolBar(this);
611 toolbarEdit->setHorizontalStretchable(TRUE); 632 toolbarEdit->setHorizontalStretchable(TRUE);
612 moveToolBar(toolbarEdit, Bottom); 633 moveToolBar(toolbarEdit, Bottom);
613 634
614 editAccept->addTo(toolbarEdit); 635 editAccept->addTo(toolbarEdit);
615 editCancel->addTo(toolbarEdit); 636 editCancel->addTo(toolbarEdit);
616 637
617 editData=new QLineEdit(toolbarEdit); 638 editData=new QLineEdit(toolbarEdit);
618 toolbarEdit->setStretchableWidget(editData); 639 toolbarEdit->setStretchableWidget(editData);
619 connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); 640 connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept()));
620 641
621 editCellSelect->addTo(toolbarEdit); 642 editCellSelect->addTo(toolbarEdit);
622} 643}
623 644
624void MainWindow::slotHelpAbout() 645void MainWindow::slotHelpAbout()
625{ 646{
626 QDialog dialogAbout(this, 0, TRUE); 647 QDialog dialogAbout(this, 0, TRUE);
627 dialogAbout.resize(width()-40, height()-80); 648 dialogAbout.resize(width()-40, height()-80);
628 dialogAbout.setCaption(tr("About Opie Sheet")); 649 dialogAbout.setCaption(tr("About Opie Sheet"));
629 650
630 QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.2\nRelease Date: October 08, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout); 651 QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.2\nRelease Date: October 08, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout);
631 label.setGeometry(dialogAbout.rect()); 652 label.setGeometry(dialogAbout.rect());
632 label.setAlignment(Qt::AlignCenter | Qt::WordBreak); 653 label.setAlignment(Qt::AlignCenter | Qt::WordBreak);
633 654
634 dialogAbout.exec(); 655 dialogAbout.exec();
635} 656}
636 657
637void MainWindow::initSheet() 658void MainWindow::initSheet()
638{ 659{
639 sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); 660 sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this);
640 setCentralWidget(sheet); 661 setCentralWidget(sheet);
641 662
642 connect(sheet, SIGNAL(currentDataChanged(const QString&)), editData, SLOT(setText(const QString&))); 663 connect(sheet, SIGNAL(currentDataChanged(const QString&)), editData, SLOT(setText(const QString&)));
643 connect(sheet, SIGNAL(cellClicked(const QString&)), this, SLOT(slotCellClicked(const QString&))); 664 connect(sheet, SIGNAL(cellClicked(const QString&)), this, SLOT(slotCellClicked(const QString&)));
644 connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); 665 connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified()));
645 666
646 connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); 667 connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut()));
647 connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); 668 connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy()));
648 connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); 669 connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear()));
649} 670}
650 671
651void MainWindow::slotEditAccept() 672void MainWindow::slotEditAccept()
652{ 673{
653 sheet->setData(editData->text()); 674 sheet->setData(editData->text());
654} 675}
655 676
656void MainWindow::slotEditCancel() 677void MainWindow::slotEditCancel()
657{ 678{
658 editData->setText(sheet->getData()); 679 editData->setText(sheet->getData());
659} 680}
660 681
661void MainWindow::slotCellSelect(bool lock) 682void MainWindow::slotCellSelect(bool lock)
662{ 683{
663 sheet->lockClicks(lock); 684 sheet->lockClicks(lock);
664} 685}
665 686
666void MainWindow::addToData(const QString &data) 687void MainWindow::addToData(const QString &data)
667{ 688{
668 editData->setText(editData->text().insert(editData->cursorPosition(), data)); 689 editData->setText(editData->text().insert(editData->cursorPosition(), data));
669} 690}
670 691
671void MainWindow::slotFuncOutput() 692void MainWindow::slotFuncOutput()
672{ 693{
673 if (sender()->isA("QAction")) 694 if (sender()->isA("QAction"))
674 addToData(((QAction *)sender())->toolTip()); 695 addToData(((QAction *)sender())->toolTip());
675} 696}
676 697
677void MainWindow::slotInsertRows() 698void MainWindow::slotInsertRows()
678{ 699{
679 NumberDialog dialogNumber(this); 700 NumberDialog dialogNumber(this);
680 if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) 701 if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted)
681 sheet->insertRows(dialogNumber.getValue()); 702 sheet->insertRows(dialogNumber.getValue());
682} 703}
683 704
684void MainWindow::slotInsertCols() 705void MainWindow::slotInsertCols()
685{ 706{
686 NumberDialog dialogNumber(this); 707 NumberDialog dialogNumber(this);
687 if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) 708 if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted)
688 sheet->insertColumns(dialogNumber.getValue()); 709 sheet->insertColumns(dialogNumber.getValue());
689} 710}
690 711
691void MainWindow::slotInsertSheets() 712void MainWindow::slotInsertSheets()
692{ 713{
693 NumberDialog dialogNumber(this); 714 NumberDialog dialogNumber(this);
694 if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) 715 if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted)
695 for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); 716 for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet();
696} 717}
697 718
698void MainWindow::slotCellClicked(const QString &cell) 719void MainWindow::slotCellClicked(const QString &cell)
699{ 720{
700 editCellSelect->setOn(FALSE); 721 editCellSelect->setOn(FALSE);
701 addToData(cell); 722 addToData(cell);
702} 723}
703 724
704typeSheet *MainWindow::createNewSheet() 725typeSheet *MainWindow::createNewSheet()
705{ 726{
706 typeSheet *newSheet=new typeSheet; 727 typeSheet *newSheet=new typeSheet;
707 int currentNo=1, tempNo=0; 728 int currentNo=1, tempNo=0;
708 bool ok; 729 bool ok;
709 730
710 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) 731 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
711 if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) 732 if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok)
712 currentNo=tempNo+1; 733 currentNo=tempNo+1;
713 734
714 newSheet->name=tr("Sheet")+QString::number(currentNo); 735 newSheet->name=tr("Sheet")+QString::number(currentNo);
715 newSheet->data.setAutoDelete(TRUE); 736 newSheet->data.setAutoDelete(TRUE);
716 737
717 comboSheets->insertItem(newSheet->name); 738 comboSheets->insertItem(newSheet->name);
718 listSheets.append(newSheet); 739 listSheets.append(newSheet);
719 return newSheet; 740 return newSheet;
720} 741}
721 742
722typeSheet *MainWindow::findSheet(const QString &name) 743typeSheet *MainWindow::findSheet(const QString &name)
723{ 744{
724 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) 745 for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next())
725 if (tempSheet->name==name) 746 if (tempSheet->name==name)
726 return tempSheet; 747 return tempSheet;
727 return NULL; 748 return NULL;
728} 749}
729 750
730void MainWindow::slotSheetChanged(const QString &name) 751void MainWindow::slotSheetChanged(const QString &name)
731{ 752{
732 sheet->copySheetData(&findSheet(sheet->getName())->data); 753 sheet->copySheetData(&findSheet(sheet->getName())->data);
733 sheet->setName(name); 754 sheet->setName(name);
734 sheet->setSheetData(&findSheet(name)->data); 755 sheet->setSheetData(&findSheet(name)->data);
735 sheet->ReCalc(); 756 sheet->ReCalc();
736} 757}
737 758
738void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) 759void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w)
739{ 760{
740 QAction *action=new QAction(text, menuText, 0, this); 761 QAction *action=new QAction(text, menuText, 0, this);
741 action->setToolTip(tip); 762 action->setToolTip(tip);
742 connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput())); 763 connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput()));
743 action->addTo(w); 764 action->addTo(w);
744} 765}
745 766
746void MainWindow::slotFormatCells() 767void MainWindow::slotFormatCells()
747{ 768{
748 CellFormat dialogCellFormat(this); 769 CellFormat dialogCellFormat(this);
749 QPEApplication::showDialog( &dialogCellFormat ); 770 QPEApplication::showDialog( &dialogCellFormat );
750 dialogCellFormat.exec(sheet); 771 dialogCellFormat.exec(sheet);
751} 772}
752 773
753void MainWindow::slotEditPaste() 774void MainWindow::slotEditPaste()
754{ 775{
755 sheet->editPaste(); 776 sheet->editPaste();
756} 777}
757 778
758void MainWindow::slotEditPasteContents() 779void MainWindow::slotEditPasteContents()
759{ 780{
760 sheet->editPaste(TRUE); 781 sheet->editPaste(TRUE);
761} 782}
762 783
763void MainWindow::slotRowHeight() 784void MainWindow::slotRowHeight()
764{ 785{
765 int row1, row2, col1, col2; 786 int row1, row2, col1, col2;
766 sheet->getSelection(&row1, &col1, &row2, &col2); 787 sheet->getSelection(&row1, &col1, &row2, &col2);
767 788
768 NumberDialog dialogNumber(this); 789 NumberDialog dialogNumber(this);
769 if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted) 790 if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted)
770 { 791 {
771 int newHeight=dialogNumber.getValue(), row; 792 int newHeight=dialogNumber.getValue(), row;
772 for (row=row1; row<=row2; ++row) 793 for (row=row1; row<=row2; ++row)
773 sheet->setRowHeight(row, newHeight); 794 sheet->setRowHeight(row, newHeight);
774 } 795 }
775} 796}
776 797
777void MainWindow::slotRowAdjust() 798void MainWindow::slotRowAdjust()
778{ 799{
779 int row1, row2, col1, col2; 800 int row1, row2, col1, col2;
780 sheet->getSelection(&row1, &col1, &row2, &col2); 801 sheet->getSelection(&row1, &col1, &row2, &col2);
781 802
782 for (int row=row1; row<=row2; ++row) 803 for (int row=row1; row<=row2; ++row)
783 sheet->adjustRow(row); 804 sheet->adjustRow(row);
784} 805}
785 806
786void MainWindow::slotRowShow() 807void MainWindow::slotRowShow()
787{ 808{
788 int row1, row2, col1, col2; 809 int row1, row2, col1, col2;
789 sheet->getSelection(&row1, &col1, &row2, &col2); 810 sheet->getSelection(&row1, &col1, &row2, &col2);
790 811
791 for (int row=row1; row<=row2; ++row) 812 for (int row=row1; row<=row2; ++row)
792 sheet->showRow(row); 813 sheet->showRow(row);
793} 814}
794 815
795void MainWindow::slotRowHide() 816void MainWindow::slotRowHide()
796{ 817{
797 int row1, row2, col1, col2; 818 int row1, row2, col1, col2;
798 sheet->getSelection(&row1, &col1, &row2, &col2); 819 sheet->getSelection(&row1, &col1, &row2, &col2);
799 820
800 for (int row=row1; row<=row2; ++row) 821 for (int row=row1; row<=row2; ++row)
801 sheet->hideRow(row); 822 sheet->hideRow(row);
802} 823}
803 824
804void MainWindow::slotColumnWidth() 825void MainWindow::slotColumnWidth()
805{ 826{
806 int row1, row2, col1, col2; 827 int row1, row2, col1, col2;
807 sheet->getSelection(&row1, &col1, &row2, &col2); 828 sheet->getSelection(&row1, &col1, &row2, &col2);
808 829
809 NumberDialog dialogNumber(this); 830 NumberDialog dialogNumber(this);
810 if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted) 831 if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted)
811 { 832 {
812 int newWidth=dialogNumber.getValue(), col; 833 int newWidth=dialogNumber.getValue(), col;
813 for (col=col1; col<=col2; ++col) 834 for (col=col1; col<=col2; ++col)
814 sheet->setColumnWidth(col, newWidth); 835 sheet->setColumnWidth(col, newWidth);
815 } 836 }
816} 837}
817 838
818void MainWindow::slotColumnAdjust() 839void MainWindow::slotColumnAdjust()
819{ 840{
820 int row1, row2, col1, col2; 841 int row1, row2, col1, col2;
821 sheet->getSelection(&row1, &col1, &row2, &col2); 842 sheet->getSelection(&row1, &col1, &row2, &col2);
822 843
823 for (int col=col1; col<=col2; ++col) 844 for (int col=col1; col<=col2; ++col)
824 sheet->adjustColumn(col); 845 sheet->adjustColumn(col);
825} 846}
826 847
827void MainWindow::slotColumnShow() 848void MainWindow::slotColumnShow()
828{ 849{
829 int row1, row2, col1, col2; 850 int row1, row2, col1, col2;
830 sheet->getSelection(&row1, &col1, &row2, &col2); 851 sheet->getSelection(&row1, &col1, &row2, &col2);
831 852
832 for (int col=col1; col<=col2; ++col) 853 for (int col=col1; col<=col2; ++col)
833 sheet->showColumn(col); 854 sheet->showColumn(col);
834} 855}
835 856
836void MainWindow::slotColumnHide() 857void MainWindow::slotColumnHide()
837{ 858{
838 int row1, row2, col1, col2; 859 int row1, row2, col1, col2;
839 sheet->getSelection(&row1, &col1, &row2, &col2); 860 sheet->getSelection(&row1, &col1, &row2, &col2);
840 861
841 for (int col=col1; col<=col2; ++col) 862 for (int col=col1; col<=col2; ++col)
842 sheet->hideColumn(col); 863 sheet->hideColumn(col);
843} 864}
844 865
845void MainWindow::slotFileSaveAs() 866void MainWindow::slotFileSaveAs()
846{ 867{
847 TextDialog dialogText(this); 868 TextDialog dialogText(this);
848 if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; 869 if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
849 870
850 currentDoc->setName(dialogText.getValue()); 871 currentDoc->setName(dialogText.getValue());
851 currentDoc->setFile(QString::null); 872 currentDoc->setFile(QString::null);
852 currentDoc->setLinkFile(QString::null); 873 currentDoc->setLinkFile(QString::null);
853 documentSave(currentDoc); 874 documentSave(currentDoc);
854} 875}
855 876
856void MainWindow::slotImportExcel(const DocLnk &lnkDoc) 877void MainWindow::slotImportExcel(const DocLnk &lnkDoc)
857{ 878{
858 ExcelBook file1; 879 ExcelBook file1;
859 file1.ParseBook((char *)lnkDoc.file().ascii()); 880 file1.ParseBook((char *)lnkDoc.file().ascii());
860 int NumOfSheets=file1.Sheets.count(); 881 int NumOfSheets=file1.Sheets.count();
861 printf("OpieSheet::NumberOfSheets:%d\r\n",NumOfSheets); 882 printf("OpieSheet::NumberOfSheets:%d\r\n",NumOfSheets);
862 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; 883 if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return;
863 if (currentDoc) delete currentDoc; 884 if (currentDoc) delete currentDoc;
864 currentDoc = new DocLnk(); 885 currentDoc = new DocLnk();
865 listSheets.clear(); 886 listSheets.clear();
866 comboSheets->clear(); 887 comboSheets->clear();
867 int w1,r,c; 888 int w1,r,c;
868 ExcelSheet* sh1; 889 ExcelSheet* sh1;
869 typeSheet* newSheet; 890 typeSheet* newSheet;
870 QString* str; 891 QString* str;
871 typeCellData* newCell; 892 typeCellData* newCell;
872 for(w1=1;w1<=NumOfSheets;w1++) 893 for(w1=1;w1<=NumOfSheets;w1++)
873 { 894 {
874 sh1=file1.Sheets[w1-1]; 895 sh1=file1.Sheets[w1-1];
875 printf("OpieSheet:newSheet:%x,r=%d,c=%d\r\n",sh1,sh1->rows,sh1->cols); 896 printf("OpieSheet:newSheet:%x,r=%d,c=%d\r\n",sh1,sh1->rows,sh1->cols);
876 newSheet=new typeSheet; 897 newSheet=new typeSheet;
877 newSheet->data.setAutoDelete(TRUE); 898 newSheet->data.setAutoDelete(TRUE);
878 newSheet->name=sh1->name; 899 newSheet->name=sh1->name;
879 printf("OpieSheet:Sheetname:%s\r\n",sh1->name.ascii()); 900 printf("OpieSheet:Sheetname:%s\r\n",sh1->name.ascii());
880 comboSheets->insertItem(newSheet->name); 901 comboSheets->insertItem(newSheet->name);
881 for(r=1; r <= sh1->rows; r++) 902 for(r=1; r <= sh1->rows; r++)
882 { 903 {
883 for(c=1;c <= sh1->cols; c++) 904 for(c=1;c <= sh1->cols; c++)
884 { 905 {
885 str=file1.CellDataString(sh1,r-1,c-1); 906 str=file1.CellDataString(sh1,r-1,c-1);
886 if(str!=NULL && r<DEFAULT_NUM_ROWS && c<DEFAULT_NUM_COLS) 907 if(str!=NULL && r<DEFAULT_NUM_ROWS && c<DEFAULT_NUM_COLS)
887 { 908 {
888 newCell=new typeCellData; 909 newCell=new typeCellData;
889 newCell->row=r-1; 910 newCell->row=r-1;
890 newCell->col=c-1; 911 newCell->col=c-1;
891 if(str!=NULL) newCell->data=QString(*str); else newCell->data=QString(""); 912 if(str!=NULL) newCell->data=QString(*str); else newCell->data=QString("");
892 newCell->background=QBrush(Qt::white, Qt::SolidPattern); 913 newCell->background=QBrush(Qt::white, Qt::SolidPattern);
893 newCell->alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); 914 newCell->alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop);
894 newCell->fontColor=Qt::black; 915 newCell->fontColor=Qt::black;
895 newCell->font=font(); 916 newCell->font=font();
896 newCell->borders.right=QPen(Qt::gray, 1, Qt::SolidLine); 917 newCell->borders.right=QPen(Qt::gray, 1, Qt::SolidLine);
897 newCell->borders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); 918 newCell->borders.bottom=QPen(Qt::gray, 1, Qt::SolidLine);
898 newSheet->data.append(newCell); 919 newSheet->data.append(newCell);
899 //there is no format parsing at the moment or style parsing 920 //there is no format parsing at the moment or style parsing
900 //printf("OpieSheetNumber:row=%d,col=%d,val=%s\r\n",r,c,str->latin1()); 921 //printf("OpieSheetNumber:row=%d,col=%d,val=%s\r\n",r,c,str->latin1());
901 }; 922 };
902 }; 923 };
903 }; 924 };
904 listSheets.append(newSheet); 925 listSheets.append(newSheet);
905 if (w1==1)//if i==0 link sheet1 with sheetview 926 if (w1==1)//if i==0 link sheet1 with sheetview
906 { 927 {
907 sheet->setName(newSheet->name); 928 sheet->setName(newSheet->name);
908 sheet->setSheetData(&newSheet->data); 929 sheet->setSheetData(&newSheet->data);
909 sheet->ReCalc(); 930 sheet->ReCalc();
910 }; 931 };
911 932
912 }; 933 };
913 file1.CloseFile(); 934 file1.CloseFile();
914 printf("Excel FILE read OK\r\n"); 935 printf("Excel FILE read OK\r\n");
915 documentModified=TRUE; 936 documentModified=TRUE;
916 937
917 938
@@ -920,88 +941,88 @@ void MainWindow::slotImportExcel(const DocLnk &lnkDoc)
920void MainWindow::slotSheetRename() 941void MainWindow::slotSheetRename()
921{ 942{
922 TextDialog dialogText(this); 943 TextDialog dialogText(this);
923 if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; 944 if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return;
924 QString newName=dialogText.getValue(); 945 QString newName=dialogText.getValue();
925
926 typeSheet *tempSheet=findSheet(newName);
927 if (tempSheet)
928 {
929 QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\''));
930 return;
931 }
932 946
933 tempSheet=findSheet(sheet->getName()); 947 typeSheet *tempSheet=findSheet(newName);
934 for (int i=0; i<comboSheets->count(); ++i) 948 if (tempSheet)
935 if (comboSheets->text(i)==tempSheet->name)
936 { 949 {
937 comboSheets->changeItem(newName, i); 950 QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\''));
938 break; 951 return;
939 } 952 }
940 tempSheet->name=newName; 953
941 sheet->setName(newName); 954 tempSheet=findSheet(sheet->getName());
955 for (int i=0; i<comboSheets->count(); ++i)
956 if (comboSheets->text(i)==tempSheet->name)
957 {
958 comboSheets->changeItem(newName, i);
959 break;
960 }
961 tempSheet->name=newName;
962 sheet->setName(newName);
942} 963}
943 964
944void MainWindow::slotSheetRemove() 965void MainWindow::slotSheetRemove()
945{ 966{
946 if (comboSheets->count()<2) 967 if (comboSheets->count()<2)
947 { 968 {
948 QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!")); 969 QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!"));
949 return; 970 return;
950 } 971 }
951 if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) 972 if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes)
952 { 973 {
953 typeSheet *tempSheet=findSheet(sheet->getName()); 974 typeSheet *tempSheet=findSheet(sheet->getName());
954 for (int i=0; i<comboSheets->count(); ++i) 975 for (int i=0; i<comboSheets->count(); ++i)
955 if (comboSheets->text(i)==tempSheet->name) 976 if (comboSheets->text(i)==tempSheet->name)
956 { 977 {
957 comboSheets->removeItem(i); 978 comboSheets->removeItem(i);
958 break; 979 break;
959 } 980 }
960 comboSheets->setCurrentItem(0); 981 comboSheets->setCurrentItem(0);
961 slotSheetChanged(comboSheets->currentText()); 982 slotSheetChanged(comboSheets->currentText());
962 listSheets.remove(tempSheet); 983 listSheets.remove(tempSheet);
963 } 984 }
964} 985}
965 986
966void MainWindow::slotDataSort() 987void MainWindow::slotDataSort()
967{ 988{
968 SortDialog dialogSort(this); 989 SortDialog dialogSort(this);
969 QPEApplication::showDialog( &dialogSort ); 990 QPEApplication::showDialog( &dialogSort );
970 dialogSort.exec(sheet); 991 dialogSort.exec(sheet);
971} 992}
972 993
973void MainWindow::slotDocModified() 994void MainWindow::slotDocModified()
974{ 995{
975 documentModified=TRUE; 996 documentModified=TRUE;
976} 997}
977 998
978void MainWindow::slotInsertCells() 999void MainWindow::slotInsertCells()
979{ 1000{
980 QDialog dialogInsert(this, 0, TRUE); 1001 QDialog dialogInsert(this, 0, TRUE);
981 dialogInsert.resize(180, 130); 1002 dialogInsert.resize(180, 130);
982 dialogInsert.setCaption(tr("Insert Cells")); 1003 dialogInsert.setCaption(tr("Insert Cells"));
983 1004
984 QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert); 1005 QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert);
985 group->setGeometry(10, 10, 160, 110); 1006 group->setGeometry(10, 10, 160, 110);
986 QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group); 1007 QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group);
987 radio=new QRadioButton(tr("Shift cells &right"), group); 1008 radio=new QRadioButton(tr("Shift cells &right"), group);
988 radio=new QRadioButton(tr("Entire ro&w"), group); 1009 radio=new QRadioButton(tr("Entire ro&w"), group);
989 radio=new QRadioButton(tr("Entire &column"), group); 1010 radio=new QRadioButton(tr("Entire &column"), group);
990 group->setButton(0); 1011 group->setButton(0);
991 1012
992 if (dialogInsert.exec()==QDialog::Accepted) 1013 if (dialogInsert.exec()==QDialog::Accepted)
993 switch (group->id(group->selected())) 1014 switch (group->id(group->selected()))
994 { 1015 {
995 case 0: sheet->insertRows(1, FALSE); break; 1016 case 0: sheet->insertRows(1, FALSE); break;
996 case 1: sheet->insertColumns(1, FALSE); break; 1017 case 1: sheet->insertColumns(1, FALSE); break;
997 case 2: sheet->insertRows(1, TRUE); break; 1018 case 2: sheet->insertRows(1, TRUE); break;
998 case 3: sheet->insertColumns(1, TRUE); break; 1019 case 3: sheet->insertColumns(1, TRUE); break;
999 } 1020 }
1000} 1021}
1001 1022
1002void MainWindow::slotDataFindReplace() 1023void MainWindow::slotDataFindReplace()
1003{ 1024{
1004 FindDialog dialogFind(this); 1025 FindDialog dialogFind(this);
1005 QPEApplication::showDialog( &dialogFind ); 1026 QPEApplication::showDialog( &dialogFind );
1006 dialogFind.exec(sheet); 1027 dialogFind.exec(sheet);
1007} 1028}
diff --git a/noncore/apps/opie-sheet/mainwindow.h b/noncore/apps/opie-sheet/mainwindow.h
index eacbe36..642b7ae 100644
--- a/noncore/apps/opie-sheet/mainwindow.h
+++ b/noncore/apps/opie-sheet/mainwindow.h
@@ -1,10 +1,29 @@
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/*
@@ -16,6 +35,12 @@
16#define MAINWINDOW_H 35#define MAINWINDOW_H
17 36
37#include "Excel.h"
38#include "sheet.h"
39
40/* OPIE */
18#include <qpe/applnk.h> 41#include <qpe/applnk.h>
19#include <qpe/fileselector.h> 42#include <qpe/fileselector.h>
43
44/* QT */
20#include <qmenubar.h> 45#include <qmenubar.h>
21#include <qtoolbar.h> 46#include <qtoolbar.h>
@@ -26,65 +51,63 @@
26#include <qcombobox.h> 51#include <qcombobox.h>
27#include <qtoolbutton.h> 52#include <qtoolbutton.h>
28#include "Excel.h"
29#include "sheet.h"
30 53
31typedef struct typeSheet 54typedef struct typeSheet
32{ 55{
33 QString name; 56 QString name;
34 QList<typeCellData> data; 57 QList<typeCellData> data;
35}; 58};
36 59
37class MainWindow: public QMainWindow 60class MainWindow: public QMainWindow
38{ 61{
39 Q_OBJECT 62 Q_OBJECT
40 63
41 // QPE objects 64 // QPE objects
42 DocLnk* currentDoc; 65 DocLnk* currentDoc;
43 QMenuBar *menu; 66 QMenuBar *menu;
44 QToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard; 67 QToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard;
45 FileSelector *fileSelector; 68 FileSelector *fileSelector;
46 FileSelector *ExcelSelector; 69 FileSelector *ExcelSelector;
47 70
48 // QT objects 71 // QT objects
49 QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp, 72 QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp,
50 *submenuFunc, *submenuFuncStd, *submenuFuncStandard, *submenuFuncLogic, 73 *submenuFunc, *submenuFuncStd, *submenuFuncStandard, *submenuFuncLogic,
51 *submenuFuncTrig, *submenuFuncString, *submenuFuncScientific, *submenuFuncDistr, 74 *submenuFuncTrig, *submenuFuncString, *submenuFuncScientific, *submenuFuncDistr,
52 *submenuFuncStat, 75 *submenuFuncStat,
53 *submenuRow, *submenuCol, *submenuSheet; 76 *submenuRow, *submenuCol, *submenuSheet;
54 QAction *fileNew, *fileOpen, *fileSave, *fileSaveAs, *fileExcelImport, *fileQuit, *helpAbout, *editAccept, *editCancel, *formatCells, 77 QAction *fileNew, *fileOpen, *fileSave, *fileSaveAs, *fileExcelImport, *fileQuit, *helpAbout, *editAccept, *editCancel, *formatCells,
55 *funcPlus, *funcMinus, *funcCross, *funcDivide, *funcParanOpen, *funcParanClose, *funcComma, *funcEqual, 78 *funcPlus, *funcMinus, *funcCross, *funcDivide, *funcParanOpen, *funcParanClose, *funcComma, *funcEqual,
56 *editCut, *editCopy, *editPaste, *editPasteContents, *editClear, *insertCols, *insertRows, *insertSheets, *insertCells, 79 *editCut, *editCopy, *editPaste, *editPasteContents, *editClear, *insertCols, *insertRows, *insertSheets, *insertCells,
57 *rowHeight, *rowShow, *rowHide, *rowAdjust, *colWidth, *colShow, *colHide, *colAdjust, *sheetRename, *sheetRemove, 80 *rowHeight, *rowShow, *rowHide, *rowAdjust, *colWidth, *colShow, *colHide, *colAdjust, *sheetRename, *sheetRemove,
58 *dataSort, *dataFindReplace, *editCellSelect, *helpGeneral; 81 *dataSort, *dataFindReplace, *editCellSelect, *helpGeneral;
59 QLineEdit *editData; 82 QLineEdit *editData;
60 QButton *buttonUp, *buttonDown, *buttonLeft, *buttonRight; 83 QButton *buttonUp, *buttonDown, *buttonLeft, *buttonRight;
61 QComboBox *comboSheets; 84 QComboBox *comboSheets;
62 QToolButton *toolFunction; 85 QToolButton *toolFunction;
63 QList<typeSheet> listSheets; 86 QList<typeSheet> listSheets;
64 QString helpFile; 87 QString helpFile;
65 88
66 // Other objects 89 // Other objects
67 Sheet *sheet; 90 Sheet *sheet;
68 91
69 // Variables 92 // Variables
70 bool documentModified; 93 bool documentModified;
71 94
72 // Private functions 95 // Private functions
73 void initMenu(); 96 void initMenu();
74 void initActions(); 97 void initActions();
75 void initFunctionsToolbar(); 98 void initFunctionsToolbar();
76 void initEditToolbar(); 99 void initEditToolbar();
77 void initStandardToolbar(); 100 void initStandardToolbar();
78 void initSheet(); 101 void initSheet();
79 void addToData(const QString &data); 102 void addToData(const QString &data);
80 int saveCurrentFile(bool ask=TRUE); 103 int saveCurrentFile(bool ask=TRUE);
81 void documentOpen(const DocLnk &lnkDoc); 104 void documentOpen(const DocLnk &lnkDoc);
82 void documentSave(DocLnk *lnkDoc); 105 void documentSave(DocLnk *lnkDoc);
83 void closeEvent(QCloseEvent *e); 106 void closeEvent(QCloseEvent *e);
84 void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w); 107 void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w);
85 typeSheet *createNewSheet(); 108 typeSheet *createNewSheet();
86 typeSheet *findSheet(const QString &name); 109 typeSheet *findSheet(const QString &name);
87 110
88 private slots: 111private slots:
89 void slotFileNew(); 112 void slotFileNew();
90 void slotFileOpen(); 113 void slotFileOpen();
@@ -128,6 +151,6 @@ class MainWindow: public QMainWindow
128 void selectorFileOpen(const DocLnk &lnkDoc); 151 void selectorFileOpen(const DocLnk &lnkDoc);
129 152
130 public: 153public:
131 static QString appName() { return QString::fromLatin1("sheetqt"); } 154static QString appName() { return QString::fromLatin1("sheetqt"); }
132 MainWindow(QWidget *p, const char*, WFlags); 155 MainWindow(QWidget *p, const char*, WFlags);
133 ~MainWindow(); 156 ~MainWindow();
@@ -135,5 +158,5 @@ class MainWindow: public QMainWindow
135 void setHelpFile(const QString &help_filename) { helpFile=help_filename; } 158 void setHelpFile(const QString &help_filename) { helpFile=help_filename; }
136 159
137 public slots: 160public slots:
138 void setDocument(const QString &applnk_filename); 161 void setDocument(const QString &applnk_filename);
139}; 162};
diff --git a/noncore/apps/opie-sheet/numberdlg.cpp b/noncore/apps/opie-sheet/numberdlg.cpp
index 90fbaa2..43574e9 100644
--- a/noncore/apps/opie-sheet/numberdlg.cpp
+++ b/noncore/apps/opie-sheet/numberdlg.cpp
@@ -1,10 +1,29 @@
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/*
@@ -16,35 +35,34 @@
16 35
17NumberDialog::NumberDialog(QWidget *parent) 36NumberDialog::NumberDialog(QWidget *parent)
18 :QDialog(parent, 0, TRUE) 37 :QDialog(parent, 0, TRUE)
19{ 38{
20 edit=new QSpinBox(this); 39 edit=new QSpinBox(this);
21 edit->setGeometry(120, 10, 70, 25); 40 edit->setGeometry(120, 10, 70, 25);
22 41
23 label=new QLabel(this); 42 label=new QLabel(this);
24 label->setGeometry(10, 10, 100, 25); 43 label->setGeometry(10, 10, 100, 25);
25 label->setBuddy(edit); 44 label->setBuddy(edit);
26 45
27 resize(200, 45); 46 resize(200, 45);
28} 47}
29 48
30NumberDialog::~NumberDialog() 49NumberDialog::~NumberDialog()
31{ 50{}
32}
33 51
34int NumberDialog::exec(const QString &caption, const QString &text, 52int NumberDialog::exec(const QString &caption, const QString &text,
35 int value, int min, int max, int step) 53 int value, int min, int max, int step)
36{ 54{
37 setCaption(caption); 55 setCaption(caption);
38 label->setText(text); 56 label->setText(text);
39 edit->setValue(value); 57 edit->setValue(value);
40 edit->setMinValue(min); 58 edit->setMinValue(min);
41 edit->setMaxValue(max); 59 edit->setMaxValue(max);
42 edit->setLineStep(step); 60 edit->setLineStep(step);
43 61
44 return QDialog::exec(); 62 return QDialog::exec();
45} 63}
46 64
47int NumberDialog::getValue() 65int NumberDialog::getValue()
48{ 66{
49 return edit->value(); 67 return edit->value();
50} 68}
diff --git a/noncore/apps/opie-sheet/numberdlg.h b/noncore/apps/opie-sheet/numberdlg.h
index 81e3326..497c076 100644
--- a/noncore/apps/opie-sheet/numberdlg.h
+++ b/noncore/apps/opie-sheet/numberdlg.h
@@ -1,10 +1,29 @@
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/*
@@ -16,4 +35,5 @@
16#define NUMBERDLG_H 35#define NUMBERDLG_H
17 36
37/* QT */
18#include <qdialog.h> 38#include <qdialog.h>
19#include <qlabel.h> 39#include <qlabel.h>
@@ -22,11 +42,11 @@
22class NumberDialog: public QDialog 42class NumberDialog: public QDialog
23{ 43{
24 Q_OBJECT 44 Q_OBJECT
25 45
26 // QT objects 46 // QT objects
27 QLabel *label; 47 QLabel *label;
28 QSpinBox *edit; 48 QSpinBox *edit;
29 49
30 public: 50public:
31 NumberDialog(QWidget *parent=0); 51 NumberDialog(QWidget *parent=0);
32 ~NumberDialog(); 52 ~NumberDialog();
diff --git a/noncore/apps/opie-sheet/opie-sheet.pro b/noncore/apps/opie-sheet/opie-sheet.pro
index ced4daf..d0beb93 100644
--- a/noncore/apps/opie-sheet/opie-sheet.pro
+++ b/noncore/apps/opie-sheet/opie-sheet.pro
@@ -1,8 +1,23 @@
1CONFIG = qt warn_on quick-app 1CONFIG = qt warn_on quick-app
2HEADERS = mainwindow.h sheet.h cellformat.h finddlg.h numberdlg.h sortdlg.h textdlg.h Excel.h 2HEADERS = mainwindow.h \
3SOURCES = main.cpp mainwindow.cpp sheet.cpp cellformat.cpp finddlg.cpp numberdlg.cpp sortdlg.cpp textdlg.cpp Excel.cpp 3 sheet.h \
4INCLUDEPATH += $(OPIEDIR)/include 4 cellformat.h \
5 finddlg.h \
6 numberdlg.h \
7 sortdlg.h \
8 textdlg.h \
9 Excel.h
10SOURCES = main.cpp \
11 mainwindow.cpp \
12 sheet.cpp \
13 cellformat.cpp \
14 finddlg.cpp \
15 numberdlg.cpp \
16 sortdlg.cpp \
17 textdlg.cpp \
18 Excel.cpp
19INCLUDEPATH += $(OPIEDIR)/include
5DEPENDPATH += $(OPIEDIR)/include 20DEPENDPATH += $(OPIEDIR)/include
6LIBS += -lqpe -lopiecore2 21LIBS += -lqpe -lopiecore2
7TARGET = opie-sheet 22TARGET = opie-sheet
8 23
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp
index 88847da..477c982 100644
--- a/noncore/apps/opie-sheet/sheet.cpp
+++ b/noncore/apps/opie-sheet/sheet.cpp
@@ -1,10 +1,29 @@
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/*
@@ -15,5 +34,8 @@
15#include "sheet.h" 34#include "sheet.h"
16 35
36/* QT */
17#include <qmessagebox.h> 37#include <qmessagebox.h>
38
39/* STD */
18#include <math.h> 40#include <math.h>
19#include <stdlib.h> 41#include <stdlib.h>
@@ -24,89 +46,89 @@
24 46
25Sheet::Sheet(int numRows, int numCols, QWidget *parent) 47Sheet::Sheet(int numRows, int numCols, QWidget *parent)
26 :QTable(numRows, numCols, parent) 48 :QTable(numRows, numCols, parent)
27{ 49{
28 defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine); 50 defaultBorders.right=defaultBorders.bottom=QPen(Qt::gray, 1, Qt::SolidLine);
29 defaultCellData.data=""; 51 defaultCellData.data="";
30 defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern); 52 defaultCellData.background=QBrush(Qt::white, Qt::SolidPattern);
31 defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop); 53 defaultCellData.alignment=(Qt::AlignmentFlags)(Qt::AlignLeft | Qt::AlignTop);
32 defaultCellData.fontColor=Qt::black; 54 defaultCellData.fontColor=Qt::black;
33 defaultCellData.font=font(); 55 defaultCellData.font=font();
34 defaultCellData.borders=defaultBorders; 56 defaultCellData.borders=defaultBorders;
35 57
36 clicksLocked=FALSE; 58 clicksLocked=FALSE;
37 selectionNo=-1; 59 selectionNo=-1;
38 setSelectionMode(QTable::Single); 60 setSelectionMode(QTable::Single);
39 61
40 sheetData.setAutoDelete(TRUE); 62 sheetData.setAutoDelete(TRUE);
41 clipboardData.setAutoDelete(TRUE); 63 clipboardData.setAutoDelete(TRUE);
42 for (int i=0; i<numCols; ++i) 64 for (int i=0; i<numCols; ++i)
43 horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); 65 horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH);
44 66
45 67
46 connect(this, SIGNAL(currentChanged(int,int)), this, SLOT(slotCellSelected(int,int))); 68 connect(this, SIGNAL(currentChanged(int,int)), this, SLOT(slotCellSelected(int,int)));
47 connect(this, SIGNAL(valueChanged(int,int)), this, SLOT(slotCellChanged(int,int))); 69 connect(this, SIGNAL(valueChanged(int,int)), this, SLOT(slotCellChanged(int,int)));
48} 70}
49 71
50Sheet::~Sheet() 72Sheet::~Sheet()
51{ 73{}
52}
53 74
54typeCellData *Sheet::findCellData(int row, int col) 75typeCellData *Sheet::findCellData(int row, int col)
55{ 76{
56 typeCellData *tempCellData; 77 typeCellData *tempCellData;
57 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 78 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
58 { 79 {
59 if (tempCellData->row==row && tempCellData->col==col) return tempCellData; 80 if (tempCellData->row==row && tempCellData->col==col) return tempCellData;
60 } 81 }
61 return NULL; 82 return NULL;
62} 83}
63 84
64void Sheet::slotCellSelected(int row, int col) 85void Sheet::slotCellSelected(int row, int col)
65{ 86{
66 typeCellData *cellData=findCellData(row, col); 87 typeCellData *cellData=findCellData(row, col);
67 if (cellData) 88 if (cellData)
68 { 89 {
69 emit currentDataChanged(cellData->data); 90 emit currentDataChanged(cellData->data);
70 }else 91 }
71 emit currentDataChanged(""); 92 else
93 emit currentDataChanged("");
72} 94}
73 95
74typeCellData *Sheet::createCellData(int row, int col) 96typeCellData *Sheet::createCellData(int row, int col)
75{ 97{
76 if (row<0 || col<0) return NULL; 98 if (row<0 || col<0) return NULL;
77 typeCellData *cellData=new typeCellData; 99 typeCellData *cellData=new typeCellData;
78 cellData->row=row; 100 cellData->row=row;
79 cellData->col=col; 101 cellData->col=col;
80 cellData->data=defaultCellData.data; 102 cellData->data=defaultCellData.data;
81 cellData->borders=defaultCellData.borders; 103 cellData->borders=defaultCellData.borders;
82 cellData->alignment=defaultCellData.alignment; 104 cellData->alignment=defaultCellData.alignment;
83 cellData->font=defaultCellData.font; 105 cellData->font=defaultCellData.font;
84 cellData->fontColor=defaultCellData.fontColor; 106 cellData->fontColor=defaultCellData.fontColor;
85 cellData->background=defaultCellData.background; 107 cellData->background=defaultCellData.background;
86 sheetData.append(cellData); 108 sheetData.append(cellData);
87 return cellData; 109 return cellData;
88} 110}
89 111
90void Sheet::slotCellChanged(int row, int col) 112void Sheet::slotCellChanged(int row, int col)
91{ 113{
92 typeCellData *cellData=findCellData(row, col); 114 typeCellData *cellData=findCellData(row, col);
93 if (!cellData) cellData=createCellData(row, col); 115 if (!cellData) cellData=createCellData(row, col);
94 if (cellData) cellData->data=text(row, col); 116 if (cellData) cellData->data=text(row, col);
95 for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) 117 for (cellData=sheetData.first(); cellData; cellData=sheetData.next())
96 { 118 {
97 // modified by Toussis Manolis koppermind@panafonet.gr 119 // modified by Toussis Manolis koppermind@panafonet.gr
98 // the parser was crashing if there were no closed parenthesis. 120 // the parser was crashing if there were no closed parenthesis.
99 int w1,ii=0; 121 int w1,ii=0;
100 for(w1=0;w1<=(int)text(row, col).length();w1++) 122 for(w1=0;w1<=(int)text(row, col).length();w1++)
101 { 123 {
102 if(text(row,col)[w1]=='(') ii++; 124 if(text(row,col)[w1]=='(') ii++;
103 if(text(row,col)[w1]==')') ii--; 125 if(text(row,col)[w1]==')') ii--;
104 }; 126 };
105 if(ii==0) setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); 127 if(ii==0) setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data));
106 //end of modification 128 //end of modification
107 // old was plain: 129 // old was plain:
108 //setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); 130 //setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data));
109 }; 131 };
110 emit sheetModified(); 132 emit sheetModified();
111} 133}
112 134
@@ -114,11 +136,11 @@ void Sheet::slotCellChanged(int row, int col)
114void Sheet::ReCalc(void) 136void Sheet::ReCalc(void)
115{ 137{
116 typeCellData* cellData; 138 typeCellData* cellData;
117 for (cellData=sheetData.first(); cellData; cellData=sheetData.next()) 139 for (cellData=sheetData.first(); cellData; cellData=sheetData.next())
118 { 140 {
119 //printf("cellchanged:%d, %d\r\n",cellData->row,cellData->col); 141 //printf("cellchanged:%d, %d\r\n",cellData->row,cellData->col);
120 142
121 slotCellChanged(cellData->row,cellData->col); 143 slotCellChanged(cellData->row,cellData->col);
122 }; 144 };
123}; 145};
124 146
@@ -128,406 +150,416 @@ void Sheet::ReCalc(void)
128void Sheet::swapCells(int row1, int col1, int row2, int col2) 150void Sheet::swapCells(int row1, int col1, int row2, int col2)
129{ 151{
130 typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2); 152 typeCellData *cellData1=findCellData(row1, col1), *cellData2=findCellData(row2, col2);
131 if (!cellData1) cellData1=createCellData(row1, col1); 153 if (!cellData1) cellData1=createCellData(row1, col1);
132 if (!cellData2) cellData2=createCellData(row2, col2); 154 if (!cellData2) cellData2=createCellData(row2, col2);
133 if (cellData1 && cellData2) 155 if (cellData1 && cellData2)
134 { 156 {
135 QString tempData(cellData1->data); 157 QString tempData(cellData1->data);
136 cellData1->data=cellData2->data; 158 cellData1->data=cellData2->data;
137 cellData2->data=tempData; 159 cellData2->data=tempData;
138 setText(cellData1->row, cellData1->col, dataParser(findCellName(cellData1->row, cellData1->col), cellData1->data)); 160 setText(cellData1->row, cellData1->col, dataParser(findCellName(cellData1->row, cellData1->col), cellData1->data));
139 setText(cellData2->row, cellData2->col, dataParser(findCellName(cellData2->row, cellData2->col), cellData2->data)); 161 setText(cellData2->row, cellData2->col, dataParser(findCellName(cellData2->row, cellData2->col), cellData2->data));
140 emit sheetModified(); 162 emit sheetModified();
141 } 163 }
142} 164}
143 165
144QString Sheet::getParameter(const QString &parameters, int paramNo, bool giveError, const QString funcName) 166QString Sheet::getParameter(const QString &parameters, int paramNo, bool giveError, const QString funcName)
145{ 167{
146 QString params(parameters); 168 QString params(parameters);
147 int position; 169 int position;
148 for (int i=0; i<paramNo; ++i) 170 for (int i=0; i<paramNo; ++i)
149 {
150 position=params.find(',');
151 if (position<0)
152 { 171 {
153 if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\'')); 172 position=params.find(',');
154 //printf("params:%s\r\n",parameters.ascii()); 173 if (position<0)
155 return QString(NULL); 174 {
175 if (giveError) QMessageBox::critical(this, tr("Error"), tr("Too few arguments to function '"+funcName+'\''));
176 //printf("params:%s\r\n",parameters.ascii());
177 return QString(NULL);
178 }
179 params=params.mid(position+1);
156 } 180 }
157 params=params.mid(position+1); 181 position=params.find(',');
158 } 182 if (position<0) return params;
159 position=params.find(','); 183 return params.left(position);
160 if (position<0) return params;
161 return params.left(position);
162} 184}
163 185
164bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2) 186bool Sheet::findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2)
165{ 187{
166 int row, col; 188 int row, col;
167 if (!findRowColumn(variable1, row1, col1, FALSE) || !findRowColumn(variable2, row2, col2, FALSE)) return FALSE; 189 if (!findRowColumn(variable1, row1, col1, FALSE) || !findRowColumn(variable2, row2, col2, FALSE)) return FALSE;
168 if (*row1>*row2) 190 if (*row1>*row2)
169 { 191 {
170 row=*row1; 192 row=*row1;
171 *row1=*row2; 193 *row1=*row2;
172 *row2=row; 194 *row2=row;
173 } 195 }
174 if (*col1>*col2) 196 if (*col1>*col2)
175 { 197 {
176 col=*col1; 198 col=*col1;
177 *col1=*col2; 199 *col1=*col2;
178 *col2=col; 200 *col2=col;
179 } 201 }
180 return TRUE; 202 return TRUE;
181} 203}
182 204
183bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError) 205bool Sheet::findRowColumn(const QString &variable, int *row, int *col, bool giveError)
184{ 206{
185 int position=variable.find(QRegExp("\\d")); 207 int position=variable.find(QRegExp("\\d"));
186 if (position<1) 208 if (position<1)
187 { 209 {
188 if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\'')); 210 if (giveError) QMessageBox::critical(this, tr("Error"), tr("Invalid variable: '"+variable+'\''));
189 return FALSE; 211 return FALSE;
190 } 212 }
191 *row=variable.mid(position).toInt()-1; 213 *row=variable.mid(position).toInt()-1;
192 *col=getHeaderColumn(variable.left(position))-1; 214 *col=getHeaderColumn(variable.left(position))-1;
193 return TRUE; 215 return TRUE;
194} 216}
195 217
196QString Sheet::calculateVariable(const QString &variable) 218QString Sheet::calculateVariable(const QString &variable)
197{ 219{
198 bool ok; 220 bool ok;
199 printf("calculateVariable=%s,len=%d\r\n",variable.ascii(),variable.length()); 221 printf("calculateVariable=%s,len=%d\r\n",variable.ascii(),variable.length());
200 if(variable.left(1)=="\"") return QString(variable.mid(1,variable.length()-2)); 222 if(variable.left(1)=="\"") return QString(variable.mid(1,variable.length()-2));
201 double tempResult=variable.toDouble(&ok); 223 double tempResult=variable.toDouble(&ok);
202 if (ok) 224 if (ok)
203 { 225 {
204 if(tempResult!=0.0) 226 if(tempResult!=0.0)
205 { 227 {
206 return QString::number(tempResult); 228 return QString::number(tempResult);
207 } 229 }
208 else 230 else
209 { 231 {
210 if(variable!="0" || variable!="0.0") return QString(variable); // hereis a string variable 232 if(variable!="0" || variable!="0.0") return QString(variable); // hereis a string variable
211 return QString::number(tempResult); 233 return QString::number(tempResult);
212 }; 234 };
213 }; 235 };
214 236
215 int row, col; 237 int row, col;
216 if(findRowColumn(variable, &row, &col, FALSE)) return dataParser(variable, text(row,col)); 238 if(findRowColumn(variable, &row, &col, FALSE)) return dataParser(variable, text(row,col));
217 //return (findRowColumn(variable, &row, &col, TRUE) ? dataParser(variable, text(row, col)) : 0); 239 //return (findRowColumn(variable, &row, &col, TRUE) ? dataParser(variable, text(row, col)) : 0);
218 return QString(variable); 240 return QString(variable);
219} 241}
220 242
221double Sheet::BesselI0(double x) 243double Sheet::BesselI0(double x)
222{ 244{
223 //Returns the modi ed Bessel function I0(x) for any real x. 245 //Returns the modi ed Bessel function I0(x) for any real x.
224 double ax,ans; 246 double ax,ans;
225 double y; 247 double y;
226 if ((ax=fabs(x)) < 3.75) 248 if ((ax=fabs(x)) < 3.75)
227 { 249 {
228 y=x/3.75; 250 y=x/3.75;
229 y*=y; 251 y*=y;
230 ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2))))); 252 ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
231 }else 253 }
232 { 254 else
233 y=3.75/ax; 255 {
234 ans=(exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1 +y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2 +y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1 +y*0.392377e-2)))))))); 256 y=3.75/ax;
235 } 257 ans=(exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1 +y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2 +y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1 +y*0.392377e-2))))))));
236 return ans; 258 }
259 return ans;
237}; 260};
238 261
239double Sheet::BesselI1(double x) 262double Sheet::BesselI1(double x)
240{ 263{
241 double ax,ans; 264 double ax,ans;
242 double y; 265 double y;
243 if ((ax=fabs(x)) < 3.75) 266 if ((ax=fabs(x)) < 3.75)
244 { 267 {
245 y=x/3.75; 268 y=x/3.75;
246 y*=y; 269 y*=y;
247 ans=ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3)))))); 270 ans=ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3))))));
248 } else 271 }
249 { 272 else
250 y=3.75/ax; 273 {
251 ans=0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1 -y*0.420059e-2)); ans=0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans)))); 274 y=3.75/ax;
252 ans *= (exp(ax)/sqrt(ax)); 275 ans=0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1 -y*0.420059e-2)); ans=0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans))));
253 } 276 ans *= (exp(ax)/sqrt(ax));
254 return x < 0.0 ? -ans : ans; 277 }
278 return x < 0.0 ? -ans : ans;
255}; 279};
256 280
257double Sheet::BesselI(int n, double x) 281double Sheet::BesselI(int n, double x)
258{ 282{
259 double ACC=40.0; 283 double ACC=40.0;
260 double BIGNO=1.0e10; 284 double BIGNO=1.0e10;
261 double BIGNI=1.0e-10; 285 double BIGNI=1.0e-10;
262 int j; 286 int j;
263 double bi,bim,bip,tox,ans; 287 double bi,bim,bip,tox,ans;
264 if (n < 2) return 0.0; 288 if (n < 2) return 0.0;
265 if (x == 0.0) return 0.0; else 289 if (x == 0.0) return 0.0; else
266 { 290 {
267 tox=2.0/fabs(x); 291 tox=2.0/fabs(x);
268 bip=ans=0.0; 292 bip=ans=0.0;
269 bi=1.0; 293 bi=1.0;
270 for (j=2*(n+(int) sqrt(ACC*n));j>0;j--) 294 for (j=2*(n+(int) sqrt(ACC*n));j>0;j--)
271 { 295 {
272 bim=bip+j*tox*bi; 296 bim=bip+j*tox*bi;
273 bip=bi; 297 bip=bi;
274 bi=bim; 298 bi=bim;
275 if (fabs(bi) > BIGNO) 299 if (fabs(bi) > BIGNO)
276 { 300 {
277 ans *= BIGNI; 301 ans *= BIGNI;
278 bi *= BIGNI; 302 bi *= BIGNI;
279 bip *= BIGNI; 303 bip *= BIGNI;
280 } 304 }
281 if (j == n) ans=bip; 305 if (j == n) ans=bip;
282 } 306 }
283 ans *= BesselI0(x)/bi; 307 ans *= BesselI0(x)/bi;
284 return x < 0.0 && (n & 1) ? -ans : ans; 308 return x < 0.0 && (n & 1) ? -ans : ans;
285 } 309 }
286}; 310};
287 311
288double Sheet::BesselK0(double x) 312double Sheet::BesselK0(double x)
289{ 313{
290 double y,ans; 314 double y,ans;
291 if (x <= 2.0) 315 if (x <= 2.0)
292 { 316 {
293 y=x*x/4.0; 317 y=x*x/4.0;
294 ans=(-log(x/2.0)*BesselI0(x))+(-0.57721566+y*(0.42278420 +y*(0.23069756+y*(0.3488590e-1+y*(0.262698e-2 +y*(0.10750e-3+y*0.74e-5)))))); 318 ans=(-log(x/2.0)*BesselI0(x))+(-0.57721566+y*(0.42278420 +y*(0.23069756+y*(0.3488590e-1+y*(0.262698e-2 +y*(0.10750e-3+y*0.74e-5))))));
295 } else 319 }
296 { 320 else
297 y=2.0/x; 321 {
298 ans=(exp(-x)/sqrt(x))*(1.25331414+y*(-0.7832358e-1 +y*(0.2189568e-1+y*(-0.1062446e-1+y*(0.587872e-2 +y*(-0.251540e-2+y*0.53208e-3)))))); 322 y=2.0/x;
299 } 323 ans=(exp(-x)/sqrt(x))*(1.25331414+y*(-0.7832358e-1 +y*(0.2189568e-1+y*(-0.1062446e-1+y*(0.587872e-2 +y*(-0.251540e-2+y*0.53208e-3))))));
300return ans; 324 }
325 return ans;
301}; 326};
302 327
303double Sheet::BesselK1(double x) 328double Sheet::BesselK1(double x)
304{ 329{
305 double y,ans; 330 double y,ans;
306 if (x <= 2.0) 331 if (x <= 2.0)
307 { 332 {
308 y=x*x/4.0; 333 y=x*x/4.0;
309 ans=(log(x/2.0)*BesselI1(x))+(1.0/x)*(1.0+y*(0.15443144 +y*(-0.67278579+y*(-0.18156897+y*(-0.1919402e-1 +y*(-0.110404e-2+y*(-0.4686e-4))))))); 334 ans=(log(x/2.0)*BesselI1(x))+(1.0/x)*(1.0+y*(0.15443144 +y*(-0.67278579+y*(-0.18156897+y*(-0.1919402e-1 +y*(-0.110404e-2+y*(-0.4686e-4)))))));
310 } else 335 }
311 { 336 else
312 y=2.0/x; 337 {
313 ans=(exp(-x)/sqrt(x))*(1.25331414+y*(0.23498619 +y*(-0.3655620e-1+y*(0.1504268e-1+y*(-0.780353e-2 +y*(0.325614e-2+y*(-0.68245e-3))))))); 338 y=2.0/x;
314 } 339 ans=(exp(-x)/sqrt(x))*(1.25331414+y*(0.23498619 +y*(-0.3655620e-1+y*(0.1504268e-1+y*(-0.780353e-2 +y*(0.325614e-2+y*(-0.68245e-3)))))));
315 return ans; 340 }
341 return ans;
316}; 342};
317 343
318double Sheet::BesselK(int n, double x) 344double Sheet::BesselK(int n, double x)
319{ 345{
320 int j; 346 int j;
321 double bk,bkm,bkp,tox; 347 double bk,bkm,bkp,tox;
322 if (n < 2) return 0.0; 348 if (n < 2) return 0.0;
323 tox=2.0/x; 349 tox=2.0/x;
324 bkm=BesselK0(x); 350 bkm=BesselK0(x);
325 bk=BesselK1(x); 351 bk=BesselK1(x);
326 for (j=1;j<n;j++) 352 for (j=1;j<n;j++)
327 { 353 {
328 bkp=bkm+j*tox*bk; 354 bkp=bkm+j*tox*bk;
329 bkm=bk; 355 bkm=bk;
330 bk=bkp; 356 bk=bkp;
331 } 357 }
332 return bk; 358 return bk;
333}; 359};
334 360
335double Sheet::BesselJ0(double x) 361double Sheet::BesselJ0(double x)
336{ 362{
337 double ax,z; 363 double ax,z;
338 double xx,y,ans,ans1,ans2; 364 double xx,y,ans,ans1,ans2;
339 if ((ax=fabs(x)) < 8.0) 365 if ((ax=fabs(x)) < 8.0)
340 { 366 {
341 y=x*x; 367 y=x*x;
342 ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7 +y*(-11214424.18+y*(77392.33017+y*(-184.9052456))))); 368 ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7 +y*(-11214424.18+y*(77392.33017+y*(-184.9052456)))));
343 ans2=57568490411.0+y*(1029532985.0+y*(9494680.718 +y*(59272.64853+y*(267.8532712+y*1.0)))); 369 ans2=57568490411.0+y*(1029532985.0+y*(9494680.718 +y*(59272.64853+y*(267.8532712+y*1.0))));
344 ans=ans1/ans2; 370 ans=ans1/ans2;
345 } else 371 }
346 { 372 else
347 z=8.0/ax; 373 {
348 y=z*z; 374 z=8.0/ax;
349 xx=ax-0.785398164; 375 y=z*z;
350 ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6))); 376 xx=ax-0.785398164;
351 ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 -y*0.934935152e-7))); 377 ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6)));
352 ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2); 378 ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 -y*0.934935152e-7)));
353 } 379 ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
354 return ans; 380 }
381 return ans;
355}; 382};
356 383
357double Sheet::BesselY0(double x) 384double Sheet::BesselY0(double x)
358{ 385{
359 double z; 386 double z;
360 double xx,y,ans,ans1,ans2; 387 double xx,y,ans,ans1,ans2;
361 if (x < 8.0) 388 if (x < 8.0)
362 { 389 {
363 y=x*x; 390 y=x*x;
364 ans1 = -2957821389.0+y*(7062834065.0+y*(-512359803.6 +y*(10879881.29+y*(-86327.92757+y*228.4622733)))); 391 ans1 = -2957821389.0+y*(7062834065.0+y*(-512359803.6 +y*(10879881.29+y*(-86327.92757+y*228.4622733))));
365 ans2=40076544269.0+y*(745249964.8+y*(7189466.438 +y*(47447.26470+y*(226.1030244+y*1.0)))); 392 ans2=40076544269.0+y*(745249964.8+y*(7189466.438 +y*(47447.26470+y*(226.1030244+y*1.0))));
366 ans=(ans1/ans2)+0.636619772*BesselJ0(x)*log(x); 393 ans=(ans1/ans2)+0.636619772*BesselJ0(x)*log(x);
367 } else 394 }
368 { 395 else
369 z=8.0/x; 396 {
370 y=z*z; 397 z=8.0/x;
371 xx=x-0.785398164; 398 y=z*z;
372 ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6))); 399 xx=x-0.785398164;
373 ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 +y*(-0.934945152e-7)))); 400 ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6)));
374 ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2); 401 ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 +y*(-0.934945152e-7))));
375 } 402 ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2);
376 return ans; 403 }
404 return ans;
377}; 405};
378 406
379double Sheet::BesselJ1(double x) 407double Sheet::BesselJ1(double x)
380{ 408{
381 double ax,z; 409 double ax,z;
382 double xx,y,ans,ans1,ans2; 410 double xx,y,ans,ans1,ans2;
383 if ((ax=fabs(x)) < 8.0) 411 if ((ax=fabs(x)) < 8.0)
384 { 412 {
385 y=x*x; 413 y=x*x;
386 ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1 +y*(-2972611.439+y*(15704.48260+y*(-30.16036606)))))); 414 ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1 +y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
387 ans2=144725228442.0+y*(2300535178.0+y*(18583304.74 +y*(99447.43394+y*(376.9991397+y*1.0)))); 415 ans2=144725228442.0+y*(2300535178.0+y*(18583304.74 +y*(99447.43394+y*(376.9991397+y*1.0))));
388 ans=ans1/ans2; 416 ans=ans1/ans2;
389 } else 417 }
390 { 418 else
391 z=8.0/ax; y=z*z; xx=ax-2.356194491; 419 {
392 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6)))); 420 z=8.0/ax; y=z*z; xx=ax-2.356194491;
393 ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6))); 421 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6))));
394 ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2); 422 ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6)));
395 if (x < 0.0) ans = -ans; 423 ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
396 } 424 if (x < 0.0) ans = -ans;
397 return ans; 425 }
426 return ans;
398}; 427};
399 428
400double Sheet::BesselY1(double x) 429double Sheet::BesselY1(double x)
401{ 430{
402 double z; 431 double z;
403 double xx,y,ans,ans1,ans2; 432 double xx,y,ans,ans1,ans2;
404 if (x < 8.0) 433 if (x < 8.0)
405 { 434 {
406 y=x*x; 435 y=x*x;
407 ans1=x*(-0.4900604943e13+y*(0.1275274390e13 +y*(-0.5153438139e11+y*(0.7349264551e9 +y*(-0.4237922726e7+y*0.8511937935e4))))); 436 ans1=x*(-0.4900604943e13+y*(0.1275274390e13 +y*(-0.5153438139e11+y*(0.7349264551e9 +y*(-0.4237922726e7+y*0.8511937935e4)))));
408 ans2=0.2499580570e14+y*(0.4244419664e12 +y*(0.3733650367e10+y*(0.2245904002e8 +y*(0.1020426050e6+y*(0.3549632885e3+y))))); 437 ans2=0.2499580570e14+y*(0.4244419664e12 +y*(0.3733650367e10+y*(0.2245904002e8 +y*(0.1020426050e6+y*(0.3549632885e3+y)))));
409 ans=(ans1/ans2)+0.636619772*(BesselJ1(x)*log(x)-1.0/x); 438 ans=(ans1/ans2)+0.636619772*(BesselJ1(x)*log(x)-1.0/x);
410 } else 439 }
411 { 440 else
412 z=8.0/x; 441 {
413 y=z*z; 442 z=8.0/x;
414 xx=x-2.356194491; 443 y=z*z;
415 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6)))); 444 xx=x-2.356194491;
416 ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6))); 445 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6))));
417 ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2); 446 ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6)));
418 } 447 ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2);
419 return ans; 448 }
449 return ans;
420}; 450};
421 451
422double Sheet::BesselY(int n, double x) 452double Sheet::BesselY(int n, double x)
423{ 453{
424 int j; 454 int j;
425 double by,bym,byp,tox; 455 double by,bym,byp,tox;
426 if (n < 2) return 0.0; 456 if (n < 2) return 0.0;
427 tox=2.0/x; 457 tox=2.0/x;
428 by=BesselY1(x); 458 by=BesselY1(x);
429 bym=BesselY0(x); 459 bym=BesselY0(x);
430 for (j=1;j<n;j++) 460 for (j=1;j<n;j++)
431 { 461 {
432 byp=j*tox*by-bym; 462 byp=j*tox*by-bym;
433 bym=by; 463 bym=by;
434 by=byp; 464 by=byp;
435 } 465 }
436 return by; 466 return by;
437}; 467};
438 468
439double Sheet::BesselJ(int n, double x) 469double Sheet::BesselJ(int n, double x)
440{ 470{
441 double ACC=40.0; 471 double ACC=40.0;
442 double BIGNO=1.0e10; 472 double BIGNO=1.0e10;
443 double BIGNI=1.0e-10; 473 double BIGNI=1.0e-10;
444 int j,jsum,m; 474 int j,jsum,m;
445 double ax,bj,bjm,bjp,sum,tox,ans; 475 double ax,bj,bjm,bjp,sum,tox,ans;
446 if (n < 2) return 0.0; 476 if (n < 2) return 0.0;
447 ax=fabs(x); 477 ax=fabs(x);
448 if (ax == 0.0) return 0.0; 478 if (ax == 0.0) return 0.0;
449 else if (ax > (double) n) 479 else if (ax > (double) n)
450 { 480 {
451 tox=2.0/ax; 481 tox=2.0/ax;
452 bjm=BesselJ0(ax); 482 bjm=BesselJ0(ax);
453 bj=BesselJ1(ax); 483 bj=BesselJ1(ax);
454 for (j=1;j<n;j++) 484 for (j=1;j<n;j++)
455 { 485 {
456 bjp=j*tox*bj-bjm; 486 bjp=j*tox*bj-bjm;
457 bjm=bj; 487 bjm=bj;
458 bj=bjp; 488 bj=bjp;
459 } 489 }
460 ans=bj; 490 ans=bj;
461 } else 491 }
462 { 492 else
463 tox=2.0/ax; 493 {
464 m=2*((n+(int) sqrt(ACC*n))/2); 494 tox=2.0/ax;
465 jsum=0; 495 m=2*((n+(int) sqrt(ACC*n))/2);
466 bjp=ans=sum=0.0; 496 jsum=0;
467 bj=1.0; 497 bjp=ans=sum=0.0;
468 for (j=m;j>0;j--) 498 bj=1.0;
469 { 499 for (j=m;j>0;j--)
470 bjm=j*tox*bj-bjp; 500 {
471 bjp=bj; 501 bjm=j*tox*bj-bjp;
472 bj=bjm; 502 bjp=bj;
473 if (fabs(bj) > BIGNO) 503 bj=bjm;
474 { 504 if (fabs(bj) > BIGNO)
475 bj *= BIGNI; 505 {
476 bjp *= BIGNI; 506 bj *= BIGNI;
477 ans *= BIGNI; 507 bjp *= BIGNI;
478 sum *= BIGNI; 508 ans *= BIGNI;
479 } 509 sum *= BIGNI;
480 if (jsum) sum += bj; 510 }
481 jsum=!jsum; 511 if (jsum) sum += bj;
482 if (j == n) ans=bjp; 512 jsum=!jsum;
483 } 513 if (j == n) ans=bjp;
484 sum=2.0*sum-bj; 514 }
485 ans /= sum; 515 sum=2.0*sum-bj;
486 } 516 ans /= sum;
487 return x < 0.0 && (n & 1) ? -ans : ans; 517 }
518 return x < 0.0 && (n & 1) ? -ans : ans;
488}; 519};
489 520
490double Sheet::GammaLn(double xx) 521double Sheet::GammaLn(double xx)
491{ 522{
492 double x,y,tmp,ser; 523 double x,y,tmp,ser;
493 static double cof[6]={76.18009172947146,-86.50532032941677, 24.01409824083091,-1.231739572450155, 0.1208650973866179e-2,-0.5395239384953e-5}; 524 static double cof[6]={76.18009172947146,-86.50532032941677, 24.01409824083091,-1.231739572450155, 0.1208650973866179e-2,-0.5395239384953e-5};
494 int j; 525 int j;
495 y=x=xx; 526 y=x=xx;
496 tmp=x+5.5; 527 tmp=x+5.5;
497 tmp -= (x+0.5)*log(tmp); 528 tmp -= (x+0.5)*log(tmp);
498 ser=1.000000000190015; 529 ser=1.000000000190015;
499 for (j=0;j<=5;j++) ser += cof[j]/++y; 530 for (j=0;j<=5;j++) ser += cof[j]/++y;
500 return -tmp+log(2.5066282746310005*ser/x); 531 return -tmp+log(2.5066282746310005*ser/x);
501}; 532};
502 533
503double Sheet::Factorial(double n) 534double Sheet::Factorial(double n)
504{ 535{
505 if (n < 0) return 0.0; 536 if (n < 0) return 0.0;
506 if (n > 100) return 0.0; 537 if (n > 100) return 0.0;
507 return exp(GammaLn(n+1.0)); 538 return exp(GammaLn(n+1.0));
508}; 539};
509 540
510double Sheet::GammaP(double a, double x) 541double Sheet::GammaP(double a, double x)
511{ 542{
512// returns GammaP(a,x) 543 // returns GammaP(a,x)
513//void gcf(float *gammcf, float a, float x, float *gln); 544 //void gcf(float *gammcf, float a, float x, float *gln);
514//void gser(float *gamser, float a, float x, float *gln); 545 //void gser(float *gamser, float a, float x, float *gln);
515 double gamser,gammcf,gln; 546 double gamser,gammcf,gln;
516 if (x < 0.0 || a <= 0.0) return 0.0;//error 547 if (x < 0.0 || a <= 0.0) return 0.0;//error
517 if (x < (a+1.0)) 548 if (x < (a+1.0))
518 { 549 {
519 GammaSeries(&gamser,a,x,&gln); 550 GammaSeries(&gamser,a,x,&gln);
520 return gamser; 551 return gamser;
521 }else 552 }
522 { 553 else
523 GammaContinuedFraction(&gammcf,a,x,&gln); 554 {
524 return 1.0-gammcf; 555 GammaContinuedFraction(&gammcf,a,x,&gln);
525 } 556 return 1.0-gammcf;
557 }
526}; 558};
527 559
528double Sheet::GammaQ(double a,double x) 560double Sheet::GammaQ(double a,double x)
529{ 561{
530 //returns GammaQ(a,x)=1.0 - GammaP(a,x); 562 //returns GammaQ(a,x)=1.0 - GammaP(a,x);
531 return (1.0-GammaP(a,x)); 563 return (1.0-GammaP(a,x));
532}; 564};
533 565
@@ -535,31 +567,33 @@ double Sheet::GammaQ(double a,double x)
535void Sheet::GammaSeries(double *gamser, double a, double x, double *gln) 567void Sheet::GammaSeries(double *gamser, double a, double x, double *gln)
536{ 568{
537 double EPS=3.0e-7; 569 double EPS=3.0e-7;
538 int ITMAX=100; 570 int ITMAX=100;
539 int n; 571 int n;
540 double sum,del,ap; 572 double sum,del,ap;
541 *gln=GammaLn(a); 573 *gln=GammaLn(a);
542 if (x <= 0.0) 574 if (x <= 0.0)
543 { 575 {
544 if (x < 0.0) return;//error 576 if (x < 0.0) return;//error
545 *gamser=0.0; 577 *gamser=0.0;
546 return; 578 return;
547 } else 579 }
548 { 580 else
549 ap=a; 581 {
550 del=sum=1.0/a; 582 ap=a;
551 for (n=1;n<=ITMAX;n++) 583 del=sum=1.0/a;
552 { 584 for (n=1;n<=ITMAX;n++)
553 ++ap; 585 {
554 del *= x/ap; 586 ++ap;
555 sum += del; 587 del *= x/ap;
556 if (fabs(del) < fabs(sum)*EPS) 588 sum += del;
557 { 589 if (fabs(del) < fabs(sum)*EPS)
558 *gamser=sum*exp(-x+a*log(x)-(*gln)); 590 {
559 return; 591 *gamser=sum*exp(-x+a*log(x)-(*gln));
560 } 592 return;
561 } return; 593 }
562 return; 594 }
563 } 595 return;
596 return;
597 }
564}; 598};
565 599
@@ -567,40 +601,40 @@ void Sheet::GammaSeries(double *gamser, double a, double x, double *gln)
567void Sheet::GammaContinuedFraction(double *gammcf, double a, double x, double *gln) 601void Sheet::GammaContinuedFraction(double *gammcf, double a, double x, double *gln)
568{ 602{
569 double EPS=3.0e-7; 603 double EPS=3.0e-7;
570 double FPMIN=1.0e-30; 604 double FPMIN=1.0e-30;
571 int ITMAX=100; 605 int ITMAX=100;
572 int i; 606 int i;
573 double an,b,c,d,del,h; 607 double an,b,c,d,del,h;
574 *gln=GammaLn(a); 608 *gln=GammaLn(a);
575 b=x+1.0-a; 609 b=x+1.0-a;
576 c=1.0/FPMIN; 610 c=1.0/FPMIN;
577 d=1.0/b; h=d; 611 d=1.0/b; h=d;
578 for (i=1;i<=ITMAX;i++) 612 for (i=1;i<=ITMAX;i++)
579 { 613 {
580 an = -i*(i-a); 614 an = -i*(i-a);
581 b += 2.0; d=an*d+b; 615 b += 2.0; d=an*d+b;
582 if (fabs(d) < FPMIN) d=FPMIN; 616 if (fabs(d) < FPMIN) d=FPMIN;
583 c=b+an/c; 617 c=b+an/c;
584 if (fabs(c) < FPMIN) c=FPMIN; 618 if (fabs(c) < FPMIN) c=FPMIN;
585 d=1.0/d; del=d*c; h *= del; 619 d=1.0/d; del=d*c; h *= del;
586 if (fabs(del-1.0) < EPS) break; 620 if (fabs(del-1.0) < EPS) break;
587 } 621 }
588 if (i > ITMAX) return; 622 if (i > ITMAX) return;
589 *gammcf=exp(-x+a*log(x)-(*gln))*h; 623 *gammcf=exp(-x+a*log(x)-(*gln))*h;
590}; 624};
591 625
592double Sheet::ErrorFunction(double x) 626double Sheet::ErrorFunction(double x)
593{ 627{
594 return x < 0.0 ? -GammaP(0.5,x*x) : GammaP(0.5,x*x); 628 return x < 0.0 ? -GammaP(0.5,x*x) : GammaP(0.5,x*x);
595}; 629};
596 630
597double Sheet::ErrorFunctionComplementary(double x) 631double Sheet::ErrorFunctionComplementary(double x)
598{ 632{
599 return x < 0.0 ? 1.0+GammaP(0.5,x*x) : GammaQ(0.5,x*x); 633 return x < 0.0 ? 1.0+GammaP(0.5,x*x) : GammaQ(0.5,x*x);
600}; 634};
601 635
602double Sheet::Beta(double z, double w) 636double Sheet::Beta(double z, double w)
603{ 637{
604 return exp(GammaLn(z)+GammaLn(w)-GammaLn(z+w)); 638 return exp(GammaLn(z)+GammaLn(w)-GammaLn(z+w));
605}; 639};
606 640
@@ -608,41 +642,41 @@ double Sheet::Beta(double z, double w)
608double Sheet::BetaContinuedFraction(double a, double b, double x) 642double Sheet::BetaContinuedFraction(double a, double b, double x)
609{ 643{
610 int MAXIT=100; 644 int MAXIT=100;
611 double EPS=3.0e-7; 645 double EPS=3.0e-7;
612 double FPMIN=1.0e-30; 646 double FPMIN=1.0e-30;
613 int m,m2; 647 int m,m2;
614 double aa,c,d,del,h,qab,qam,qap; 648 double aa,c,d,del,h,qab,qam,qap;
615 qab=a+b; 649 qab=a+b;
616 qap=a+1.0; qam=a-1.0; c=1.0; 650 qap=a+1.0; qam=a-1.0; c=1.0;
617 d=1.0-qab*x/qap; 651 d=1.0-qab*x/qap;
618 if (fabs(d) < FPMIN) d=FPMIN; 652 if (fabs(d) < FPMIN) d=FPMIN;
619 d=1.0/d; h=d; 653 d=1.0/d; h=d;
620 for (m=1;m<=MAXIT;m++) 654 for (m=1;m<=MAXIT;m++)
621 { 655 {
622 m2=2*m; aa=m*(b-m)*x/((qam+m2)*(a+m2)); 656 m2=2*m; aa=m*(b-m)*x/((qam+m2)*(a+m2));
623 d=1.0+aa*d; 657 d=1.0+aa*d;
624 if (fabs(d) < FPMIN) d=FPMIN; 658 if (fabs(d) < FPMIN) d=FPMIN;
625 c=1.0+aa/c; 659 c=1.0+aa/c;
626 if (fabs(c) < FPMIN) c=FPMIN; 660 if (fabs(c) < FPMIN) c=FPMIN;
627 d=1.0/d; h *= d*c; 661 d=1.0/d; h *= d*c;
628 aa = -(a+m)*(qab+m)*x/((a+m2)*(qap+m2)); d=1.0+aa*d; 662 aa = -(a+m)*(qab+m)*x/((a+m2)*(qap+m2)); d=1.0+aa*d;
629 if (fabs(d) < FPMIN) d=FPMIN; 663 if (fabs(d) < FPMIN) d=FPMIN;
630 c=1.0+aa/c; 664 c=1.0+aa/c;
631 if (fabs(c) < FPMIN) c=FPMIN; d=1.0/d; 665 if (fabs(c) < FPMIN) c=FPMIN; d=1.0/d;
632 del=d*c; h *= del; 666 del=d*c; h *= del;
633 if (fabs(del-1.0) < EPS) break; 667 if (fabs(del-1.0) < EPS) break;
634 } 668 }
635 if (m > MAXIT) return 0.0; 669 if (m > MAXIT) return 0.0;
636 return h; 670 return h;
637}; 671};
638 672
639double Sheet::BetaIncomplete(double a, double b, double x) 673double Sheet::BetaIncomplete(double a, double b, double x)
640{ 674{
641 double bt; 675 double bt;
642 if (x < 0.0 || x > 1.0) return 0.0; 676 if (x < 0.0 || x > 1.0) return 0.0;
643 if (x == 0.0 || x == 1.0) bt=0.0; else 677 if (x == 0.0 || x == 1.0) bt=0.0; else
644 bt=exp(GammaLn(a+b)-GammaLn(a)-GammaLn(b)+a*log(x)+b*log(1.0-x)); 678 bt=exp(GammaLn(a+b)-GammaLn(a)-GammaLn(b)+a*log(x)+b*log(1.0-x));
645 if (x < (a+1.0)/(a+b+2.0)) return bt*BetaContinuedFraction(a,b,x)/a; else 679 if (x < (a+1.0)/(a+b+2.0)) return bt*BetaContinuedFraction(a,b,x)/a; else
646 return 1.0-bt*BetaContinuedFraction(b,a,1.0-x)/b; 680 return 1.0-bt*BetaContinuedFraction(b,a,1.0-x)/b;
647}; 681};
648 682
@@ -651,38 +685,39 @@ double Sheet::BetaIncomplete(double a, double b, double x)
651double Sheet::functionSum(const QString &param1, const QString &param2) 685double Sheet::functionSum(const QString &param1, const QString &param2)
652{ 686{
653 int row1, col1, row2, col2, row, col; 687 int row1, col1, row2, col2, row, col;
654 double result=0, tempResult; 688 double result=0, tempResult;
655 bool ok; 689 bool ok;
656 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 690 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
657 { 691 {
658 for (row=row1; row<=row2; ++row) 692 for (row=row1; row<=row2; ++row)
659 for (col=col1; col<=col2; ++col) 693 for (col=col1; col<=col2; ++col)
660 { 694 {
661 tempResult=text(row, col).toDouble(&ok); 695 tempResult=text(row, col).toDouble(&ok);
662 if (ok) result+=tempResult; 696 if (ok) result+=tempResult;
663 } 697 }
664 return result; 698 return result;
665 }else 699 }
666 { 700 else
667 double d1=0,d2=0; 701 {
668 d1=calculateVariable(param1).toDouble(&ok); 702 double d1=0,d2=0;
669 d2=calculateVariable(param2).toDouble(&ok); 703 d1=calculateVariable(param1).toDouble(&ok);
670 return(d1+d2); 704 d2=calculateVariable(param2).toDouble(&ok);
671 }; 705 return(d1+d2);
672 return 0; 706 };
707 return 0;
673} 708}
674 709
675QString Sheet::functionIndex(const QString &param1, const QString &param2, int indx) 710QString Sheet::functionIndex(const QString &param1, const QString &param2, int indx)
676{ 711{
677 int row1, col1, row2, col2, row, col; 712 int row1, col1, row2, col2, row, col;
678 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; 713 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
679 int ii=1; 714 int ii=1;
680 for (col=col1; col<=col2; ++col) 715 for (col=col1; col<=col2; ++col)
681 for (row=row1; row<=row2; ++row) 716 for (row=row1; row<=row2; ++row)
682 { 717 {
683 if(ii==indx) return text(row,col); 718 if(ii==indx) return text(row,col);
684 ii++; 719 ii++;
685 } 720 }
686 return QString(""); 721 return QString("");
687} 722}
688 723
@@ -691,85 +726,85 @@ QString Sheet::functionIndex(const QString &param1, const QString &param2, int i
691double Sheet::functionVariancePopulation(const QString &param1, const QString &param2) 726double Sheet::functionVariancePopulation(const QString &param1, const QString &param2)
692{ 727{
693 int row1, col1, row2, col2, row, col; 728 int row1, col1, row2, col2, row, col;
694 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; 729 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
695 double avg1=functionAvg(param1,param2); 730 double avg1=functionAvg(param1,param2);
696 double result=0, tempResult; 731 double result=0, tempResult;
697 int count1=0; 732 int count1=0;
698 bool ok; 733 bool ok;
699 for (row=row1; row<=row2; ++row) 734 for (row=row1; row<=row2; ++row)
700 for (col=col1; col<=col2; ++col) 735 for (col=col1; col<=col2; ++col)
701 { 736 {
702 tempResult=text(row, col).toDouble(&ok); 737 tempResult=text(row, col).toDouble(&ok);
703 if (ok) { result=result + (tempResult - avg1)*(tempResult - avg1); count1++;}; 738 if (ok) { result=result + (tempResult - avg1)*(tempResult - avg1); count1++;};
704 } 739 }
705 if(count1>0) result=result/double(count1); else result=0.0; 740 if(count1>0) result=result/double(count1); else result=0.0;
706 return result; 741 return result;
707}; 742};
708 743
709double Sheet::functionVariance(const QString &param1, const QString &param2) 744double Sheet::functionVariance(const QString &param1, const QString &param2)
710{ 745{
711 int row1, col1, row2, col2, row, col; 746 int row1, col1, row2, col2, row, col;
712 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; 747 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
713 double avg1=functionAvg(param1,param2); 748 double avg1=functionAvg(param1,param2);
714 double result=0, tempResult; 749 double result=0, tempResult;
715 int count1=0; 750 int count1=0;
716 bool ok; 751 bool ok;
717 for (row=row1; row<=row2; ++row) 752 for (row=row1; row<=row2; ++row)
718 for (col=col1; col<=col2; ++col) 753 for (col=col1; col<=col2; ++col)
719 { 754 {
720 tempResult=text(row, col).toDouble(&ok); 755 tempResult=text(row, col).toDouble(&ok);
721 if (ok) { result=result + (tempResult - avg1)*(tempResult - avg1); count1++;}; 756 if (ok) { result=result + (tempResult - avg1)*(tempResult - avg1); count1++;};
722 } 757 }
723 if(count1>1) result=result/double(count1-1); else result=0.0; 758 if(count1>1) result=result/double(count1-1); else result=0.0;
724 return result; 759 return result;
725}; 760};
726 761
727double Sheet::functionSkew(const QString &param1, const QString &param2) 762double Sheet::functionSkew(const QString &param1, const QString &param2)
728{ 763{
729 int row1, col1, row2, col2, row, col; 764 int row1, col1, row2, col2, row, col;
730 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; 765 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
731 double avg1=functionAvg(param1,param2); 766 double avg1=functionAvg(param1,param2);
732 double var1=sqrt(functionVariancePopulation(param1,param2)); 767 double var1=sqrt(functionVariancePopulation(param1,param2));
733 if(var1==0.0) return 0.0; 768 if(var1==0.0) return 0.0;
734 double result=0, tempResult; 769 double result=0, tempResult;
735 int count1=0; 770 int count1=0;
736 bool ok; 771 bool ok;
737 for (row=row1; row<=row2; ++row) 772 for (row=row1; row<=row2; ++row)
738 for (col=col1; col<=col2; ++col) 773 for (col=col1; col<=col2; ++col)
739 { 774 {
740 tempResult=text(row, col).toDouble(&ok); 775 tempResult=text(row, col).toDouble(&ok);
741 if (ok) 776 if (ok)
742 { 777 {
743 result=result + (tempResult - avg1)*(tempResult - avg1)*(tempResult - avg1)/(var1*var1*var1); 778 result=result + (tempResult - avg1)*(tempResult - avg1)*(tempResult - avg1)/(var1*var1*var1);
744 count1++; 779 count1++;
745 }; 780 };
746 } 781 }
747 if(count1>0) result=result/double(count1); else result=0.0; 782 if(count1>0) result=result/double(count1); else result=0.0;
748 return result; 783 return result;
749}; 784};
750 785
751double Sheet::functionKurt(const QString &param1, const QString &param2) 786double Sheet::functionKurt(const QString &param1, const QString &param2)
752{ 787{
753 int row1, col1, row2, col2, row, col; 788 int row1, col1, row2, col2, row, col;
754 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; 789 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
755 double avg1=functionAvg(param1,param2); 790 double avg1=functionAvg(param1,param2);
756 double var1=sqrt(functionVariancePopulation(param1,param2)); 791 double var1=sqrt(functionVariancePopulation(param1,param2));
757 if(var1==0.0) return 0.0; 792 if(var1==0.0) return 0.0;
758 double result=0, tempResult; 793 double result=0, tempResult;
759 int count1=0; 794 int count1=0;
760 bool ok; 795 bool ok;
761 for (row=row1; row<=row2; ++row) 796 for (row=row1; row<=row2; ++row)
762 for (col=col1; col<=col2; ++col) 797 for (col=col1; col<=col2; ++col)
763 { 798 {
764 tempResult=text(row, col).toDouble(&ok); 799 tempResult=text(row, col).toDouble(&ok);
765 if (ok) 800 if (ok)
766 { 801 {
767 result=result + (tempResult - avg1)*(tempResult - avg1)* 802 result=result + (tempResult - avg1)*(tempResult - avg1)*
768 (tempResult - avg1)*(tempResult - avg1)/(var1*var1*var1*var1); 803 (tempResult - avg1)*(tempResult - avg1)/(var1*var1*var1*var1);
769 count1++; 804 count1++;
770 }; 805 };
771 } 806 }
772 if(count1>0) result=result/double(count1)-3.0; else result=0.0; 807 if(count1>0) result=result/double(count1)-3.0; else result=0.0;
773 return result; 808 return result;
774}; 809};
775 810
@@ -778,24 +813,25 @@ double Sheet::functionKurt(const QString &param1, const QString &param2)
778double Sheet::functionSumSQ(const QString &param1, const QString &param2) 813double Sheet::functionSumSQ(const QString &param1, const QString &param2)
779{ 814{
780 int row1, col1, row2, col2, row, col; 815 int row1, col1, row2, col2, row, col;
781 double result=0, tempResult; 816 double result=0, tempResult;
782 bool ok; 817 bool ok;
783 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 818 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
784 { 819 {
785 for (row=row1; row<=row2; ++row) 820 for (row=row1; row<=row2; ++row)
786 for (col=col1; col<=col2; ++col) 821 for (col=col1; col<=col2; ++col)
787 { 822 {
788 tempResult=text(row, col).toDouble(&ok); 823 tempResult=text(row, col).toDouble(&ok);
789 if (ok) result+=tempResult*tempResult; 824 if (ok) result+=tempResult*tempResult;
790 } 825 }
791 return result; 826 return result;
792 }else 827 }
793 { 828 else
794 double d1=0,d2=0; 829 {
795 d1=calculateVariable(param1).toDouble(&ok); 830 double d1=0,d2=0;
796 d2=calculateVariable(param2).toDouble(&ok); 831 d1=calculateVariable(param1).toDouble(&ok);
797 return(d1*d1+d2*d2); 832 d2=calculateVariable(param2).toDouble(&ok);
798 }; 833 return(d1*d1+d2*d2);
799 return 0; 834 };
835 return 0;
800} 836}
801 837
@@ -804,106 +840,109 @@ double Sheet::functionSumSQ(const QString &param1, const QString &param2)
804double Sheet::functionMin(const QString &param1, const QString &param2) 840double Sheet::functionMin(const QString &param1, const QString &param2)
805{ 841{
806 int row1, col1, row2, col2, row, col; 842 int row1, col1, row2, col2, row, col;
807 double min=0, tempMin; 843 double min=0, tempMin;
808 bool ok, init=FALSE; 844 bool ok, init=FALSE;
809 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 845 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
810 { 846 {
811 for (row=row1; row<=row2; ++row) 847 for (row=row1; row<=row2; ++row)
812 for (col=col1; col<=col2; ++col) 848 for (col=col1; col<=col2; ++col)
813 { 849 {
814 tempMin=text(row, col).toDouble(&ok); 850 tempMin=text(row, col).toDouble(&ok);
815 if (ok && (!init || tempMin<min)) 851 if (ok && (!init || tempMin<min))
816 { 852 {
817 min=tempMin; 853 min=tempMin;
818 init=TRUE; 854 init=TRUE;
819 } 855 }
820 } 856 }
821 return min; 857 return min;
822 }else 858 }
823 { 859 else
824 double d1=0,d2=0; 860 {
825 d1=calculateVariable(param1).toDouble(&ok); 861 double d1=0,d2=0;
826 d2=calculateVariable(param2).toDouble(&ok); 862 d1=calculateVariable(param1).toDouble(&ok);
827 if(d1<d2) return(d1); else return(d2); 863 d2=calculateVariable(param2).toDouble(&ok);
828 }; 864 if(d1<d2) return(d1); else return(d2);
829 return 0; 865 };
866 return 0;
830} 867}
831 868
832double Sheet::functionMax(const QString &param1, const QString &param2) 869double Sheet::functionMax(const QString &param1, const QString &param2)
833{ 870{
834 int row1, col1, row2, col2, row, col; 871 int row1, col1, row2, col2, row, col;
835 double max=0, tempMax; 872 double max=0, tempMax;
836 bool ok, init=FALSE; 873 bool ok, init=FALSE;
837 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 874 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
838 { 875 {
839 for (row=row1; row<=row2; ++row) 876 for (row=row1; row<=row2; ++row)
840 for (col=col1; col<=col2; ++col) 877 for (col=col1; col<=col2; ++col)
841 { 878 {
842 tempMax=text(row, col).toDouble(&ok); 879 tempMax=text(row, col).toDouble(&ok);
843 if (ok && (!init || tempMax>max)) 880 if (ok && (!init || tempMax>max))
844 { 881 {
845 max=tempMax; 882 max=tempMax;
846 init=TRUE; 883 init=TRUE;
847 } 884 }
848 }; 885 };
849 return max; 886 return max;
850 }else 887 }
851 { 888 else
852 double d1=0,d2=0; 889 {
853 d1=calculateVariable(param1).toDouble(&ok); 890 double d1=0,d2=0;
854 d2=calculateVariable(param2).toDouble(&ok); 891 d1=calculateVariable(param1).toDouble(&ok);
855 if(d1>d2) return(d1); else return(d2); 892 d2=calculateVariable(param2).toDouble(&ok);
856 }; 893 if(d1>d2) return(d1); else return(d2);
857 return 0; 894 };
895 return 0;
858} 896}
859 897
860double Sheet::functionAvg(const QString &param1, const QString &param2) 898double Sheet::functionAvg(const QString &param1, const QString &param2)
861{ 899{
862 double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); 900 double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2);
863 return (resultCount>0 ? resultSum/resultCount : 0); 901 return (resultCount>0 ? resultSum/resultCount : 0);
864} 902}
865 903
866double Sheet::functionCount(const QString &param1, const QString &param2) 904double Sheet::functionCount(const QString &param1, const QString &param2)
867{ 905{
868 int row1, col1, row2, col2, row, col; 906 int row1, col1, row2, col2, row, col;
869 int divider=0; 907 int divider=0;
870 bool ok; 908 bool ok;
871 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 909 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
872 { 910 {
873 for (row=row1; row<=row2; ++row) 911 for (row=row1; row<=row2; ++row)
874 for (col=col1; col<=col2; ++col) 912 for (col=col1; col<=col2; ++col)
875 { 913 {
876 text(row, col).toDouble(&ok); 914 text(row, col).toDouble(&ok);
877 if (ok) ++divider; 915 if (ok) ++divider;
878 }; 916 };
879 return divider; 917 return divider;
880 }else 918 }
881 { 919 else
882 double d1=0,d2=0;int ii=0; 920 {
883 d1=calculateVariable(param1).toDouble(&ok); 921 double d1=0,d2=0;int ii=0;
884 if (ok) ii++; 922 d1=calculateVariable(param1).toDouble(&ok);
885 d2=calculateVariable(param2).toDouble(&ok); 923 if (ok) ii++;
886 if (ok) ii++; 924 d2=calculateVariable(param2).toDouble(&ok);
887 return(ii); 925 if (ok) ii++;
888 }; 926 return(ii);
889 return 0; 927 };
928 return 0;
890} 929}
891 930
892double Sheet::functionCountIf(const QString &param1, const QString &param2, const QString &param3) 931double Sheet::functionCountIf(const QString &param1, const QString &param2, const QString &param3)
893{ 932{
894 int row1, col1, row2, col2, row, col; 933 int row1, col1, row2, col2, row, col;
895 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; 934 if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0;
896 //same as count except check if each field is equal to param3 935 //same as count except check if each field is equal to param3
897 int divider=0; 936 int divider=0;
898 QString s2; 937 QString s2;
899 bool ok; 938 bool ok;
900 s2=calculateVariable(param3); 939 s2=calculateVariable(param3);
901 for (row=row1; row<=row2; ++row) 940 for (row=row1; row<=row2; ++row)
902 for (col=col1; col<=col2; ++col) 941 for (col=col1; col<=col2; ++col)
903 { 942 {
904 text(row, col).toDouble(&ok); 943 text(row, col).toDouble(&ok);
905 if (ok && (s2==text(row,col)) ) ++divider; 944 if (ok && (s2==text(row,col)) ) ++divider;
906 } 945 }
907 return divider; 946 return divider;
908} 947}
909 948
@@ -911,843 +950,851 @@ double Sheet::functionCountIf(const QString &param1, const QString &param2, cons
911QString Sheet::calculateFunction(const QString &func, const QString &parameters, int NumOfParams) 950QString Sheet::calculateFunction(const QString &func, const QString &parameters, int NumOfParams)
912{ 951{
913 bool ok; 952 bool ok;
914 double val1=0.0,val2=0.0,val3=0.0; 953 double val1=0.0,val2=0.0,val3=0.0;
915 long int vali=0; 954 long int vali=0;
916 int w1,w2; 955 int w1,w2;
917 int row,col; 956 int row,col;
918 QString s1,s2; 957 QString s1,s2;
919//basic functions 958 //basic functions
920 QString function; 959 QString function;
921 function=func.upper(); 960 function=func.upper();
922 if (function=="+") 961 if (function=="+")
923 { 962 {
924 s1=calculateVariable(getParameter(parameters, 0)); 963 s1=calculateVariable(getParameter(parameters, 0));
925 s2=calculateVariable(getParameter(parameters, 1)); 964 s2=calculateVariable(getParameter(parameters, 1));
926 val1=s1.toDouble(&ok)+s2.toDouble(&ok); 965 val1=s1.toDouble(&ok)+s2.toDouble(&ok);
927 return QString::number(val1); 966 return QString::number(val1);
928 967
929 }; 968 };
930 if (function=="-") 969 if (function=="-")
931 { 970 {
932 s1=calculateVariable(getParameter(parameters, 0)); 971 s1=calculateVariable(getParameter(parameters, 0));
933 s2=calculateVariable(getParameter(parameters, 1)); 972 s2=calculateVariable(getParameter(parameters, 1));
934 val1=s1.toDouble(&ok)-s2.toDouble(&ok); 973 val1=s1.toDouble(&ok)-s2.toDouble(&ok);
935 return QString::number(val1); 974 return QString::number(val1);
936 }; 975 };
937 if (function=="*") 976 if (function=="*")
938 { 977 {
939 val1=calculateVariable( 978 val1=calculateVariable(
940 getParameter(parameters, 0)).toDouble(&ok) 979 getParameter(parameters, 0)).toDouble(&ok)
941 *calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 980 *calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
942 return QString::number(val1); 981 return QString::number(val1);
943 }; 982 };
944 if (function=="/") 983 if (function=="/")
945 { 984 {
946 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 985 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
947 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 986 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
948 if(val2==0.0) return QString("Err101"); 987 if(val2==0.0) return QString("Err101");
949 val1=val1/val2; 988 val1=val1/val2;
950 return QString::number(val1); 989 return QString::number(val1);
951 }; 990 };
952 if (function==">") 991 if (function==">")
953 { 992 {
954 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 993 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
955 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 994 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
956 if(val1>val2) return QString::number(1); else return QString::number(0); 995 if(val1>val2) return QString::number(1); else return QString::number(0);
957 }; 996 };
958 if (function=="<") 997 if (function=="<")
959 { 998 {
960 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 999 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
961 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 1000 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
962 if(val1<val2) return QString::number(1); else return QString::number(0); 1001 if(val1<val2) return QString::number(1); else return QString::number(0);
963 }; 1002 };
964 if (function==">=") 1003 if (function==">=")
965 { 1004 {
966 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 1005 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
967 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 1006 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
968 if(val1>=val2) return QString::number(1); else return QString::number(0); 1007 if(val1>=val2) return QString::number(1); else return QString::number(0);
969 }; 1008 };
970 if (function=="<=") 1009 if (function=="<=")
971 { 1010 {
972 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 1011 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
973 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 1012 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
974 if(val1<=val2) return QString::number(1); else return QString::number(0); 1013 if(val1<=val2) return QString::number(1); else return QString::number(0);
975 }; 1014 };
976 if (function=="!=") 1015 if (function=="!=")
977 { 1016 {
978 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 1017 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
979 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 1018 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
980 if(val1!=val2) return QString::number(1); else return QString::number(0); 1019 if(val1!=val2) return QString::number(1); else return QString::number(0);
981 }; 1020 };
982 if (function=="=="||function=="=") 1021 if (function=="=="||function=="=")
983 { 1022 {
984 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 1023 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
985 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 1024 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
986 if(val1==val2) return QString::number(1); else return QString::number(0); 1025 if(val1==val2) return QString::number(1); else return QString::number(0);
987 }; 1026 };
988 1027
989 //LOGICAL / INFO 1028 //LOGICAL / INFO
990 if (function=="ISBLANK") 1029 if (function=="ISBLANK")
991 { 1030 {
992 if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE)) 1031 if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE))
993 { 1032 {
994 if(text(row,col).length()==0) val1=1; else val1=0; 1033 if(text(row,col).length()==0) val1=1; else val1=0;
995 }else 1034 }
996 { 1035 else
997 if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE)) 1036 {
998 { 1037 if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE))
999 if(text(row,col).length()==0) val1=1; else val1=0; 1038 {
1000 }else 1039 if(text(row,col).length()==0) val1=1; else val1=0;
1001 { 1040 }
1002 val1=0; 1041 else
1003 }; 1042 {
1004 }; 1043 val1=0;
1005 return QString::number(val1); 1044 };
1006 }; 1045 };
1007 1046 return QString::number(val1);
1008 1047 };
1009 if (function=="ISNUMBER") 1048
1010 { 1049
1011 if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE)) 1050 if (function=="ISNUMBER")
1012 { 1051 {
1013 val1=text(row,col).toDouble(&ok); 1052 if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE))
1014 if(ok) val1=1; else val1=0; 1053 {
1015 }else 1054 val1=text(row,col).toDouble(&ok);
1016 { 1055 if(ok) val1=1; else val1=0;
1017 if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE)) 1056 }
1018 { 1057 else
1019 val1=text(row,col).toDouble(&ok); 1058 {
1020 if(ok) val1=1; else val1=0; 1059 if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE))
1021 }else 1060 {
1022 { 1061 val1=text(row,col).toDouble(&ok);
1023 val1=0; 1062 if(ok) val1=1; else val1=0;
1024 }; 1063 }
1025 }; 1064 else
1026 return QString::number(val1); 1065 {
1027 }; 1066 val1=0;
1028 if (function=="AND") 1067 };
1029 { 1068 };
1030 vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok) 1069 return QString::number(val1);
1031 & calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1070 };
1032 return QString::number(vali); 1071 if (function=="AND")
1033 }; 1072 {
1034 if (function=="OR") 1073 vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok)
1035 { 1074 & calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1036 vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok) 1075 return QString::number(vali);
1037 | calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1076 };
1038 return QString::number(vali); 1077 if (function=="OR")
1039 }; 1078 {
1040 if (function=="NOT") 1079 vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok)
1041 { 1080 | calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1042 vali=!calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok); 1081 return QString::number(vali);
1043 return QString::number(vali); 1082 };
1044 }; 1083 if (function=="NOT")
1045 1084 {
1046 // MATHEMATICAL FUNCTIONS 1085 vali=!calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok);
1047 if (function=="ABS") 1086 return QString::number(vali);
1048 { 1087 };
1049 val1=fabs(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1088
1050 return QString::number(val1); 1089 // MATHEMATICAL FUNCTIONS
1051 }; 1090 if (function=="ABS")
1052 if (function=="ACOS") 1091 {
1053 { 1092 val1=fabs(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1054 val1=acos(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1093 return QString::number(val1);
1055 return QString::number(val1); 1094 };
1056 }; 1095 if (function=="ACOS")
1057 if (function=="ACOSH") 1096 {
1058 { 1097 val1=acos(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1059 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1098 return QString::number(val1);
1060 if(val1<1.0) return QString::number(0); 1099 };
1061 val1=acosh(val1); 1100 if (function=="ACOSH")
1062 return QString::number(val1); 1101 {
1063 }; 1102 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1064 if (function=="ASIN") 1103 if(val1<1.0) return QString::number(0);
1065 { 1104 val1=acosh(val1);
1066 val1=asin(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1105 return QString::number(val1);
1067 return QString::number(val1); 1106 };
1068 }; 1107 if (function=="ASIN")
1069 if (function=="ASINH") 1108 {
1070 { 1109 val1=asin(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1071 val1=asinh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1110 return QString::number(val1);
1072 return QString::number(val1); 1111 };
1073 }; 1112 if (function=="ASINH")
1074 if (function=="ATAN") 1113 {
1075 { 1114 val1=asinh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1076 val1=atan(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1115 return QString::number(val1);
1077 return QString::number(val1); 1116 };
1078 }; 1117 if (function=="ATAN")
1079 if (function=="ATAN2") 1118 {
1080 { 1119 val1=atan(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1081 val1=atan2(calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok), 1120 return QString::number(val1);
1082 calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1121 };
1083 return QString::number(val1); 1122 if (function=="ATAN2")
1084 }; 1123 {
1085 if (function=="ATANH") 1124 val1=atan2(calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok),
1086 { 1125 calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1087 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1126 return QString::number(val1);
1088 if(val1<=-1.0 || val1>=1.0) return QString("Err101"); 1127 };
1089 val1=atanh(val1); 1128 if (function=="ATANH")
1090 return QString::number(val1); 1129 {
1091 }; 1130 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1092 if (function=="CEILING") 1131 if(val1<=-1.0 || val1>=1.0) return QString("Err101");
1093 { 1132 val1=atanh(val1);
1094 // rounds up param1 to specified accuracy param2 1133 return QString::number(val1);
1095 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1134 };
1096 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1135 if (function=="CEILING")
1097 if(val2==0.0) return QString::number(val1); 1136 {
1098 val1=ceil(val1/val2)*val2; 1137 // rounds up param1 to specified accuracy param2
1099 return QString::number(val1); 1138 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1100 }; 1139 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1101 if (function=="COS") 1140 if(val2==0.0) return QString::number(val1);
1102 { 1141 val1=ceil(val1/val2)*val2;
1103 val1=cos(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1142 return QString::number(val1);
1104 return QString::number(val1); 1143 };
1105 }; 1144 if (function=="COS")
1106 if (function=="COSH") 1145 {
1107 { 1146 val1=cos(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1108 val1=cosh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1147 return QString::number(val1);
1109 return QString::number(val1); 1148 };
1110 }; 1149 if (function=="COSH")
1111 if (function=="DEGREES") 1150 {
1112 { 1151 val1=cosh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1113 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)*180.0/M_PI; 1152 return QString::number(val1);
1114 return QString::number(val1); 1153 };
1115 }; 1154 if (function=="DEGREES")
1116 if (function=="EXP") 1155 {
1117 { 1156 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)*180.0/M_PI;
1118 val1=exp(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1157 return QString::number(val1);
1119 return QString::number(val1); 1158 };
1120 }; 1159 if (function=="EXP")
1121 if (function=="FACT") 1160 {
1122 { 1161 val1=exp(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1123 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1162 return QString::number(val1);
1124 val2=Factorial(val1); 1163 };
1125 return QString::number(val2); 1164 if (function=="FACT")
1126 }; 1165 {
1127 if (function=="FLOOR") 1166 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1128 { 1167 val2=Factorial(val1);
1129 // rounds down param1 to specified accuracy param2 1168 return QString::number(val2);
1130 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1169 };
1131 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1170 if (function=="FLOOR")
1132 if(val2==0.0) return QString::number(val1); 1171 {
1133 val1=floor(val1/val2)*val2; 1172 // rounds down param1 to specified accuracy param2
1134 return QString::number(val1); 1173 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1135 }; 1174 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1136 if (function=="INT") 1175 if(val2==0.0) return QString::number(val1);
1137 { 1176 val1=floor(val1/val2)*val2;
1138 // rounds down param1 1177 return QString::number(val1);
1139 val1=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1178 };
1140 return QString::number(val1); 1179 if (function=="INT")
1141 }; 1180 {
1142 if (function=="EVEN") 1181 // rounds down param1
1143 { 1182 val1=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1144 //converts param1 to even 1183 return QString::number(val1);
1145 vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1184 };
1146 if(vali % 2 !=0) val1=vali+1; else val1=vali; 1185 if (function=="EVEN")
1147 return QString::number(val1); 1186 {
1148 }; 1187 //converts param1 to even
1149 if (function=="ODD") 1188 vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1150 { 1189 if(vali % 2 !=0) val1=vali+1; else val1=vali;
1151 //converts param1 to odd 1190 return QString::number(val1);
1152 vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1191 };
1153 if(vali % 2 !=0) val1=vali; else val1=vali+1; 1192 if (function=="ODD")
1154 return QString::number(val1); 1193 {
1155 }; 1194 //converts param1 to odd
1156 if (function=="ISEVEN") 1195 vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1157 { 1196 if(vali % 2 !=0) val1=vali; else val1=vali+1;
1158 //Is Even param1? 1197 return QString::number(val1);
1159 vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1198 };
1160 if(vali % 2 == 0) val1=1; else val1=0; 1199 if (function=="ISEVEN")
1161 return QString::number(val1); 1200 {
1162 }; 1201 //Is Even param1?
1163 if (function=="ISODD") 1202 vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1164 { 1203 if(vali % 2 == 0) val1=1; else val1=0;
1165 //Is odd param1? 1204 return QString::number(val1);
1166 vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1205 };
1167 if(vali % 2 == 0) val1=0; else val1=1; 1206 if (function=="ISODD")
1168 return QString::number(val1); 1207 {
1169 }; 1208 //Is odd param1?
1170 if (function=="LN") 1209 vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1171 { 1210 if(vali % 2 == 0) val1=0; else val1=1;
1172 // returns the natural logarithm of param1 1211 return QString::number(val1);
1173 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1212 };
1174 if(val1<=0.0) return QString("Err101"); 1213 if (function=="LN")
1175 val1=log(val1); 1214 {
1176 return QString::number(val1); 1215 // returns the natural logarithm of param1
1177 }; 1216 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1178 if (function=="LOG10") 1217 if(val1<=0.0) return QString("Err101");
1179 { 1218 val1=log(val1);
1180 // returns the base-10 logarithm of param1 1219 return QString::number(val1);
1181 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1220 };
1182 if(val1<=0.0) return QString("Err101"); 1221 if (function=="LOG10")
1183 val1=log10(val1); 1222 {
1184 return QString::number(val1); 1223 // returns the base-10 logarithm of param1
1185 }; 1224 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1186 if (function=="LOG") 1225 if(val1<=0.0) return QString("Err101");
1187 { 1226 val1=log10(val1);
1188 // return the base-param2 logarithm of param1 1227 return QString::number(val1);
1189 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1228 };
1190 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1229 if (function=="LOG")
1191 if(val1<=0.0 || val2<=0.0 ) return QString("Err101"); 1230 {
1192 val1=log(val1)/log(val2); 1231 // return the base-param2 logarithm of param1
1193 return QString::number(val1); 1232 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1194 }; 1233 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1195 if (function=="MOD") 1234 if(val1<=0.0 || val2<=0.0 ) return QString("Err101");
1196 { 1235 val1=log(val1)/log(val2);
1197 // return the modulus of param1/param2 1236 return QString::number(val1);
1198 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1237 };
1199 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1238 if (function=="MOD")
1200 if(val2==0.0) return QString("Err101"); 1239 {
1201 val1=(int(val1) % int(val2)); 1240 // return the modulus of param1/param2
1202 return QString::number(val1); 1241 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1203 }; 1242 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1204 if (function=="POWER") 1243 if(val2==0.0) return QString("Err101");
1205 { 1244 val1=(int(val1) % int(val2));
1206 // return the param1^param2 1245 return QString::number(val1);
1207 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1246 };
1208 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1247 if (function=="POWER")
1209 if(val1<0.0 && (floor(val2)!=val2)) return QString("Err101"); 1248 {
1210 val1=pow(val1,val2); 1249 // return the param1^param2
1211 return QString::number(val1); 1250 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1212 }; 1251 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1213 if (function=="PI") 1252 if(val1<0.0 && (floor(val2)!=val2)) return QString("Err101");
1214 { 1253 val1=pow(val1,val2);
1215 return QString::number(M_PI); 1254 return QString::number(val1);
1216 }; 1255 };
1217 if (function=="RADIANS") 1256 if (function=="PI")
1218 { 1257 {
1219 // param1 deg->rad 1258 return QString::number(M_PI);
1220 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)*M_PI/180.0; 1259 };
1221 return QString::number(val1); 1260 if (function=="RADIANS")
1222 }; 1261 {
1223 if (function=="RAND") 1262 // param1 deg->rad
1224 { 1263 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)*M_PI/180.0;
1225 // retuns random number 0>x>1 1264 return QString::number(val1);
1226 srand((unsigned int)time((time_t *)NULL)); 1265 };
1227 val1=double(rand())/double(RAND_MAX); 1266 if (function=="RAND")
1228 return QString::number(val1); 1267 {
1229 }; 1268 // retuns random number 0>x>1
1230 if (function=="RANDBETWEEN") 1269 srand((unsigned int)time((time_t *)NULL));
1231 { 1270 val1=double(rand())/double(RAND_MAX);
1232 // returns random number between param1>x>param2 1271 return QString::number(val1);
1233 //TOFIX: this is not ok because I think results is always int related. 1272 };
1234 srand((unsigned int)time((time_t *)NULL)); 1273 if (function=="RANDBETWEEN")
1235 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1274 {
1236 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1275 // returns random number between param1>x>param2
1237 val1=fmod(double(rand()),(val2-val1))+val1; 1276 //TOFIX: this is not ok because I think results is always int related.
1238 return QString::number(val1); 1277 srand((unsigned int)time((time_t *)NULL));
1239 }; 1278 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1240 if (function=="ROUND") 1279 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1241 { 1280 val1=fmod(double(rand()),(val2-val1))+val1;
1242 // rounds down param1 to specified digits param2 (positive decimal digits) 1281 return QString::number(val1);
1243 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1282 };
1244 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1283 if (function=="ROUND")
1245 val2=pow(10.0,-val2); 1284 {
1246 val1=floor(val1/val2)*val2; 1285 // rounds down param1 to specified digits param2 (positive decimal digits)
1247 return QString::number(val1); 1286 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1248 }; 1287 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1249 if (function=="SIGN") 1288 val2=pow(10.0,-val2);
1250 { 1289 val1=floor(val1/val2)*val2;
1251 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1290 return QString::number(val1);
1252 if(val1>=0.0) return QString::number(1.0); else return QString::number(-1.0); 1291 };
1253 }; 1292 if (function=="SIGN")
1254 if (function=="CHGSGN")//changes sign (for unary operator) 1293 {
1255 { 1294 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1256 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1295 if(val1>=0.0) return QString::number(1.0); else return QString::number(-1.0);
1257 return QString::number((-1.0)*val1); 1296 };
1258 }; 1297 if (function=="CHGSGN")//changes sign (for unary operator)
1259 if (function=="SIN") 1298 {
1260 { 1299 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1261 val1=sin(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1300 return QString::number((-1.0)*val1);
1262 return QString::number(val1); 1301 };
1263 }; 1302 if (function=="SIN")
1264 if (function=="SINH") 1303 {
1265 { 1304 val1=sin(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1266 val1=sinh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1305 return QString::number(val1);
1267 return QString::number(val1); 1306 };
1268 }; 1307 if (function=="SINH")
1269 if (function=="TAN") 1308 {
1270 { 1309 val1=sinh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1271 val1=tan(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1310 return QString::number(val1);
1272 return QString::number(val1); 1311 };
1273 }; 1312 if (function=="TAN")
1274 if (function=="TANH") 1313 {
1275 { 1314 val1=tan(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1276 val1=tanh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1315 return QString::number(val1);
1277 return QString::number(val1); 1316 };
1278 }; 1317 if (function=="TANH")
1279 if (function=="SQRT") 1318 {
1280 { 1319 val1=tanh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1281 val1=sqrt(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1320 return QString::number(val1);
1282 return QString::number(val1); 1321 };
1283 }; 1322 if (function=="SQRT")
1284 1323 {
1285 1324 val1=sqrt(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
1286// STRING FUNCTIONS 1325 return QString::number(val1);
1287 if (function=="CONCATENATE") 1326 };
1288 { 1327
1289 // concatenates strings together 1328
1290 w1=0; 1329 // STRING FUNCTIONS
1291 s1=""; 1330 if (function=="CONCATENATE")
1292 while(getParameter(parameters, w1, FALSE, function)!="") //parse all params; 1331 {
1293 { 1332 // concatenates strings together
1294 s1=s1+calculateVariable(getParameter(parameters, w1)); 1333 w1=0;
1295 w1++; 1334 s1="";
1296 }; 1335 while(getParameter(parameters, w1, FALSE, function)!="") //parse all params;
1297 return QString(s1); 1336 {
1298 }; 1337 s1=s1+calculateVariable(getParameter(parameters, w1));
1299 if (function=="EXACT") 1338 w1++;
1300 { 1339 };
1301 // compare two string if they are exactly the same 1340 return QString(s1);
1302 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1341 };
1303 s2=calculateVariable(getParameter(parameters, 1, TRUE, function)); 1342 if (function=="EXACT")
1304 if(s1==s2) return QString::number(1); else return QString::number(0); 1343 {
1305 }; 1344 // compare two string if they are exactly the same
1306 if (function=="FIND") 1345 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1307 { 1346 s2=calculateVariable(getParameter(parameters, 1, TRUE, function));
1308 // finds param1 in param2 from pos param3 and after 1347 if(s1==s2) return QString::number(1); else return QString::number(0);
1309 // returns -1 if not found 1348 };
1310 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1349 if (function=="FIND")
1311 s2=calculateVariable(getParameter(parameters, 1, TRUE, function)); 1350 {
1312 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1351 // finds param1 in param2 from pos param3 and after
1313 val1=s2.find(s1,vali); 1352 // returns -1 if not found
1314 return QString::number(val1); 1353 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1315 }; 1354 s2=calculateVariable(getParameter(parameters, 1, TRUE, function));
1316 if (function=="LEFT") 1355 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1317 { 1356 val1=s2.find(s1,vali);
1318 // returns the param2 left chars from param1 string 1357 return QString::number(val1);
1319 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1358 };
1320 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1359 if (function=="LEFT")
1321 s2=s1.left(vali); 1360 {
1322 return QString(s2); 1361 // returns the param2 left chars from param1 string
1323 }; 1362 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1324 if (function=="LEN") 1363 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1325 { 1364 s2=s1.left(vali);
1326 // return the length of a string(param1) 1365 return QString(s2);
1327 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1366 };
1328 return QString::number(s1.length()); 1367 if (function=="LEN")
1329 }; 1368 {
1330 if (function=="MID") 1369 // return the length of a string(param1)
1331 { 1370 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1332 // returns the mid word of string param1 with start param2 and len param3 1371 return QString::number(s1.length());
1333 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1372 };
1334 w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1373 if (function=="MID")
1335 w2=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1374 {
1336 s2=s1.mid(w1,w2); 1375 // returns the mid word of string param1 with start param2 and len param3
1337 return QString(s2); 1376 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1338 }; 1377 w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1339 if (function=="REPLACE") 1378 w2=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1340 { 1379 s2=s1.mid(w1,w2);
1341 //replace in param1 text in pos param2 and length param3 to newtext param4 1380 return QString(s2);
1342 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1381 };
1343 w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1382 if (function=="REPLACE")
1344 w2=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1383 {
1345 s2=calculateVariable(getParameter(parameters, 3, TRUE, function)); 1384 //replace in param1 text in pos param2 and length param3 to newtext param4
1346 if(w1<0 || w2<0) return QString(s1); 1385 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1347 s1=s1.left(w2-1)+s2+s1.right(s1.length()-w1-w2); 1386 w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1348 return QString(s1); 1387 w2=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1349 }; 1388 s2=calculateVariable(getParameter(parameters, 3, TRUE, function));
1350 if (function=="REPT") 1389 if(w1<0 || w2<0) return QString(s1);
1351 { 1390 s1=s1.left(w2-1)+s2+s1.right(s1.length()-w1-w2);
1352 //repeats param1 string param2 times 1391 return QString(s1);
1353 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1392 };
1354 w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1393 if (function=="REPT")
1355 for(w2=1;w2<=w1;w2++) 1394 {
1356 { 1395 //repeats param1 string param2 times
1357 s2=s2.append(s1); 1396 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1358 }; 1397 w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1359 return QString(s2); 1398 for(w2=1;w2<=w1;w2++)
1360 }; 1399 {
1361 if (function=="RIGHT") 1400 s2=s2.append(s1);
1362 { 1401 };
1363 // returns the param2 right chars from param1 string 1402 return QString(s2);
1364 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1403 };
1365 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1404 if (function=="RIGHT")
1366 s2=s1.right(vali); 1405 {
1367 return QString(s2); 1406 // returns the param2 right chars from param1 string
1368 }; 1407 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1369 if (function=="UPPER") 1408 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1370 { 1409 s2=s1.right(vali);
1371 // returns the upper param1 string 1410 return QString(s2);
1372 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1411 };
1373 s1=s1.upper(); 1412 if (function=="UPPER")
1374 return QString(s1); 1413 {
1375 }; 1414 // returns the upper param1 string
1376 if (function=="LOWER") 1415 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1377 { 1416 s1=s1.upper();
1378 // returns the lower param1 string 1417 return QString(s1);
1379 s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); 1418 };
1380 s1=s1.lower(); 1419 if (function=="LOWER")
1381 return QString(s1); 1420 {
1382 }; 1421 // returns the lower param1 string
1383 if (function=="IF") 1422 s1=calculateVariable(getParameter(parameters, 0, TRUE, function));
1384 { 1423 s1=s1.lower();
1385 //usage: IF(param1,param2,param3) 1424 return QString(s1);
1386 //returns param4 if true(param1)/ param5 if false(param1) 1425 };
1387 val1=getParameter(parameters, 0, TRUE, function).toDouble(&ok); 1426 if (function=="IF")
1388 if(val1==1.0) 1427 {
1389 { 1428 //usage: IF(param1,param2,param3)
1390 s1=calculateVariable(getParameter(parameters, 1, TRUE, function)); 1429 //returns param4 if true(param1)/ param5 if false(param1)
1391 return QString(s1); 1430 val1=getParameter(parameters, 0, TRUE, function).toDouble(&ok);
1392 }else 1431 if(val1==1.0)
1393 { 1432 {
1394 s1=calculateVariable(getParameter(parameters, 2, TRUE, function)); 1433 s1=calculateVariable(getParameter(parameters, 1, TRUE, function));
1395 return QString(s1); 1434 return QString(s1);
1396 }; 1435 }
1397 }; 1436 else
1398 if (function=="SUM") 1437 {
1399 { 1438 s1=calculateVariable(getParameter(parameters, 2, TRUE, function));
1400 //NumOfParams 1439 return QString(s1);
1401 val2=0.0; 1440 };
1402 for(w1=1;w1<=(NumOfParams/2);w1++) 1441 };
1403 { 1442 if (function=="SUM")
1404 val1=functionSum(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); 1443 {
1405 val2=val2+val1; 1444 //NumOfParams
1406 }; 1445 val2=0.0;
1407 if(NumOfParams%2==1) 1446 for(w1=1;w1<=(NumOfParams/2);w1++)
1408 { 1447 {
1409 val2=val2+calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); 1448 val1=functionSum(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function));
1410 }; 1449 val2=val2+val1;
1411 return QString::number(val2); 1450 };
1412 }; 1451 if(NumOfParams%2==1)
1413 if (function=="INDEX") 1452 {
1414 { 1453 val2=val2+calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok);
1415 s1=functionIndex(getParameter(parameters,0,TRUE,function), getParameter(parameters, 1, TRUE, function), getParameter(parameters,2,TRUE,function).toInt(&ok)); 1454 };
1416 return QString(s1); 1455 return QString::number(val2);
1417 }; 1456 };
1418 if (function=="SUMSQ") 1457 if (function=="INDEX")
1419 { 1458 {
1420 //NumOfParams 1459 s1=functionIndex(getParameter(parameters,0,TRUE,function), getParameter(parameters, 1, TRUE, function), getParameter(parameters,2,TRUE,function).toInt(&ok));
1421 val2=0.0; 1460 return QString(s1);
1422 for(w1=1;w1<=(NumOfParams/2);w1++) 1461 };
1423 { 1462 if (function=="SUMSQ")
1424 val1=functionSumSQ(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); 1463 {
1425 val2=val2+val1; 1464 //NumOfParams
1426 }; 1465 val2=0.0;
1427 if(NumOfParams%2==1) 1466 for(w1=1;w1<=(NumOfParams/2);w1++)
1428 { 1467 {
1429 val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); 1468 val1=functionSumSQ(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function));
1430 val2=val2+val1*val1; 1469 val2=val2+val1;
1431 }; 1470 };
1432 return QString::number(val2); 1471 if(NumOfParams%2==1)
1433 }; 1472 {
1434 if (function=="COUNT") 1473 val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok);
1435 { 1474 val2=val2+val1*val1;
1436 //NumOfParams 1475 };
1437 val2=0.0; 1476 return QString::number(val2);
1438 for(w1=1;w1<=(NumOfParams/2);w1++) 1477 };
1439 { 1478 if (function=="COUNT")
1440 val1=functionCount(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); 1479 {
1441 val2=val2+val1; 1480 //NumOfParams
1442 }; 1481 val2=0.0;
1443 if(NumOfParams%2==1) 1482 for(w1=1;w1<=(NumOfParams/2);w1++)
1444 { 1483 {
1445 val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); 1484 val1=functionCount(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function));
1446 if(ok) val2=val2+1; 1485 val2=val2+val1;
1447 }; 1486 };
1448 return QString::number(val2); 1487 if(NumOfParams%2==1)
1449 }; 1488 {
1450 if (function=="COUNTIF") 1489 val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok);
1451 { 1490 if(ok) val2=val2+1;
1452 //NumOfParams 1491 };
1453 val1=functionCountIf(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function), getParameter(parameters, 2, TRUE, function)); 1492 return QString::number(val2);
1454 return QString::number(val1); 1493 };
1455 }; 1494 if (function=="COUNTIF")
1456 if (function=="MIN") 1495 {
1457 { 1496 //NumOfParams
1458 //NumOfParams 1497 val1=functionCountIf(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function), getParameter(parameters, 2, TRUE, function));
1459 val2=0.0; 1498 return QString::number(val1);
1460 for(w1=1;w1<=(NumOfParams/2);w1++) 1499 };
1461 { 1500 if (function=="MIN")
1462 val1=functionMin(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); 1501 {
1463 val2=val1; 1502 //NumOfParams
1464 }; 1503 val2=0.0;
1465 if(NumOfParams%2==1) 1504 for(w1=1;w1<=(NumOfParams/2);w1++)
1466 { 1505 {
1467 val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); 1506 val1=functionMin(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function));
1468 if(val1<val2) val2=val1; 1507 val2=val1;
1469 }; 1508 };
1470 return QString::number(val2); 1509 if(NumOfParams%2==1)
1471 }; 1510 {
1472 if (function=="MAX") 1511 val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok);
1473 { 1512 if(val1<val2) val2=val1;
1474 //NumOfParams 1513 };
1475 val2=0.0; 1514 return QString::number(val2);
1476 for(w1=1;w1<=(NumOfParams/2);w1++) 1515 };
1477 { 1516 if (function=="MAX")
1478 val1=functionMax(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); 1517 {
1479 val2=val1; 1518 //NumOfParams
1480 }; 1519 val2=0.0;
1481 if(NumOfParams%2==1) 1520 for(w1=1;w1<=(NumOfParams/2);w1++)
1482 { 1521 {
1483 val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); 1522 val1=functionMax(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function));
1484 if(val1>val2) val2=val1; 1523 val2=val1;
1485 }; 1524 };
1486 return QString::number(val2); 1525 if(NumOfParams%2==1)
1487 }; 1526 {
1488 if (function=="AVERAGE") 1527 val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok);
1489 { 1528 if(val1>val2) val2=val1;
1490 val1=functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); 1529 };
1491 return QString::number(val1); 1530 return QString::number(val2);
1492 }; 1531 };
1493 1532 if (function=="AVERAGE")
1494 if(function=="BESSELI") 1533 {
1495 { 1534 val1=functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
1496 // BesselI (x,n) 1535 return QString::number(val1);
1497 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1536 };
1498 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1537
1499 val2=BesselI(vali,val1); 1538 if(function=="BESSELI")
1500 return QString::number(val2); 1539 {
1501 }; 1540 // BesselI (x,n)
1502 if(function=="BESSELJ") 1541 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1503 { 1542 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1504 // BesselJ (x,n) 1543 val2=BesselI(vali,val1);
1505 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1544 return QString::number(val2);
1506 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1545 };
1507 val2=BesselJ(vali,val1); 1546 if(function=="BESSELJ")
1508 return QString::number(val2); 1547 {
1509 }; 1548 // BesselJ (x,n)
1510 if(function=="BESSELK") 1549 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1511 { 1550 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1512 // BesselK (x,n) 1551 val2=BesselJ(vali,val1);
1513 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1552 return QString::number(val2);
1514 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1553 };
1515 val2=BesselK(vali,val1); 1554 if(function=="BESSELK")
1516 return QString::number(val2); 1555 {
1517 }; 1556 // BesselK (x,n)
1518 if(function=="BESSELY") 1557 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1519 { 1558 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1520 // BesselY (x,n) 1559 val2=BesselK(vali,val1);
1521 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1560 return QString::number(val2);
1522 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1561 };
1523 val2=BesselY(vali,val1); 1562 if(function=="BESSELY")
1524 return QString::number(val2); 1563 {
1525 }; 1564 // BesselY (x,n)
1526 if(function=="GAMMALN") 1565 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1527 { 1566 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1528 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1567 val2=BesselY(vali,val1);
1529 val2=GammaLn(val1); 1568 return QString::number(val2);
1530 return QString::number(val2); 1569 };
1531 }; 1570 if(function=="GAMMALN")
1532 if(function=="ERF") 1571 {
1533 { 1572 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1534 // ERF (a,b) 1573 val2=GammaLn(val1);
1535 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1574 return QString::number(val2);
1536 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1575 };
1537 return QString::number(ErrorFunction(val2)-ErrorFunction(val1)); 1576 if(function=="ERF")
1538 }; 1577 {
1539 if(function=="ERFC") 1578 // ERF (a,b)
1540 { 1579 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1541 // ERFC (a,b) 1580 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1542 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1581 return QString::number(ErrorFunction(val2)-ErrorFunction(val1));
1543 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1582 };
1544 return QString::number(ErrorFunctionComplementary(val2)-ErrorFunctionComplementary(val1)); 1583 if(function=="ERFC")
1545 }; 1584 {
1546 if(function=="POISSON") 1585 // ERFC (a,b)
1547 { 1586 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1548 // POISSON DISTR(x,n,distr/desnt) 1587 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1549 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1588 return QString::number(ErrorFunctionComplementary(val2)-ErrorFunctionComplementary(val1));
1550 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1589 };
1551 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1590 if(function=="POISSON")
1552 if(vali==1) 1591 {
1553 { 1592 // POISSON DISTR(x,n,distr/desnt)
1554 return QString::number(GammaQ(floor(val1)+1, val2)); 1593 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1555 }else 1594 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1556 { 1595 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1557 return QString::number(exp(-val2)*pow(val2,val1)/exp(GammaLn(val1+1.0))); 1596 if(vali==1)
1558 }; 1597 {
1559 }; 1598 return QString::number(GammaQ(floor(val1)+1, val2));
1560 if(function=="CHIDIST") 1599 }
1561 { 1600 else
1562 // POISSON CHIDIST(x,n,distr/density) 1601 {
1563 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1602 return QString::number(exp(-val2)*pow(val2,val1)/exp(GammaLn(val1+1.0)));
1564 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1603 };
1565 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1604 };
1566 if(vali==1) 1605 if(function=="CHIDIST")
1567 { 1606 {
1568 return QString::number(GammaP(val2/2.0,val1*val1/2.0)); 1607 // POISSON CHIDIST(x,n,distr/density)
1569 } else 1608 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1570 { 1609 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1571 return QString::number( 1610 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1572 pow(val1,val2-1.0)*exp(-val1*val1/2)/ ( pow(2,val2/2.0-1.0)*exp(GammaLn(val2/2.0))) 1611 if(vali==1)
1573 ); 1612 {
1574 }; 1613 return QString::number(GammaP(val2/2.0,val1*val1/2.0));
1575 }; 1614 }
1576 if(function=="CHI2DIST") 1615 else
1577 { 1616 {
1578 // POISSON CHISQUAREDIST(x,n,distr/density) 1617 return QString::number(
1579 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1618 pow(val1,val2-1.0)*exp(-val1*val1/2)/ ( pow(2,val2/2.0-1.0)*exp(GammaLn(val2/2.0)))
1580 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1619 );
1581 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); 1620 };
1582 if(vali==1) 1621 };
1583 { 1622 if(function=="CHI2DIST")
1584 return QString::number(GammaP(val2/2.0,val1/2.0)); 1623 {
1585 } else 1624 // POISSON CHISQUAREDIST(x,n,distr/density)
1586 { 1625 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1587 return QString::number( 1626 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1588 pow(val1,val2/2.0-1.0)/(exp(val1/2.0)*pow(sqrt(2.0),val2)*exp(GammaLn(val2/2.0))) 1627 vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
1589 ); 1628 if(vali==1)
1590 }; 1629 {
1591 }; 1630 return QString::number(GammaP(val2/2.0,val1/2.0));
1592 if(function=="BETAI") 1631 }
1593 { 1632 else
1594 // BETA INCOMPLETE BETA(x,a,b) 1633 {
1595 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1634 return QString::number(
1596 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1635 pow(val1,val2/2.0-1.0)/(exp(val1/2.0)*pow(sqrt(2.0),val2)*exp(GammaLn(val2/2.0)))
1597 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); 1636 );
1598 return QString::number(BetaIncomplete(val2,val3,val1)); 1637 };
1599 }; 1638 };
1600 if(function=="GAMMAP") 1639 if(function=="BETAI")
1601 { 1640 {
1602 // GammaP (x,a) 1641 // BETA INCOMPLETE BETA(x,a,b)
1603 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1642 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1604 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1643 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1605 return QString::number(GammaP(val2,val1)); 1644 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok);
1606 }; 1645 return QString::number(BetaIncomplete(val2,val3,val1));
1607 if(function=="GAMMAQ") 1646 };
1608 { 1647 if(function=="GAMMAP")
1609 // GammaQ (x,a) 1648 {
1610 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1649 // GammaP (x,a)
1611 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1650 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1612 return QString::number(GammaQ(val2,val1)); 1651 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1613 }; 1652 return QString::number(GammaP(val2,val1));
1614 if (function=="VAR") 1653 };
1615 { 1654 if(function=="GAMMAQ")
1616 val1=functionVariance(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); 1655 {
1617 return QString::number(val1); 1656 // GammaQ (x,a)
1618 }; 1657 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1619 if (function=="VARP") 1658 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1620 { 1659 return QString::number(GammaQ(val2,val1));
1621 val1=functionVariancePopulation(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); 1660 };
1622 return QString::number(val1); 1661 if (function=="VAR")
1623 }; 1662 {
1624 if (function=="STDEV") 1663 val1=functionVariance(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
1625 { 1664 return QString::number(val1);
1626 val1=functionVariance(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); 1665 };
1627 if(val1<=0.0) return QString::number(0.0); 1666 if (function=="VARP")
1628 return QString::number(sqrt(val1)); 1667 {
1629 }; 1668 val1=functionVariancePopulation(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
1630 if (function=="STDEVP") 1669 return QString::number(val1);
1631 { 1670 };
1632 val1=functionVariancePopulation(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); 1671 if (function=="STDEV")
1633 if(val1<=0.0) return QString::number(0.0); 1672 {
1634 return QString::number(sqrt(val1)); 1673 val1=functionVariance(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
1635 }; 1674 if(val1<=0.0) return QString::number(0.0);
1636 if (function=="SKEW") 1675 return QString::number(sqrt(val1));
1637 { 1676 };
1638 val1=functionSkew(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); 1677 if (function=="STDEVP")
1639 return QString::number(val1); 1678 {
1640 }; 1679 val1=functionVariancePopulation(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
1641 if (function=="KURT") 1680 if(val1<=0.0) return QString::number(0.0);
1642 { 1681 return QString::number(sqrt(val1));
1643 val1=functionKurt(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); 1682 };
1644 return QString::number(val1); 1683 if (function=="SKEW")
1645 }; 1684 {
1646 if(function=="GAMMADIST") 1685 val1=functionSkew(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
1647 { 1686 return QString::number(val1);
1648 // GAMMADIST (x,alpha,beta,distribution?density1:0) 1687 };
1649 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1688 if (function=="KURT")
1650 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1689 {
1651 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); 1690 val1=functionKurt(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function));
1652 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); 1691 return QString::number(val1);
1653 if(vali==1)//distribution 1692 };
1654 { 1693 if(function=="GAMMADIST")
1655 if(val3==0.0) return QString::number(0.0); 1694 {
1656 else 1695 // GAMMADIST (x,alpha,beta,distribution?density1:0)
1657 return QString::number(GammaP(val2,val1/val3)); 1696 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1658 }else //density 1697 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1659 { 1698 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok);
1660 return QString::number( 1699 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok);
1661 pow(val1,val2-1.0)*exp(-val1/val3) / (pow(val3,val2)*exp(GammaLn(val2))) 1700 if(vali==1)//distribution
1662 ); 1701 {
1663 }; 1702 if(val3==0.0) return QString::number(0.0);
1664 }; 1703 else
1665 if(function=="BETADIST") 1704 return QString::number(GammaP(val2,val1/val3));
1666 { 1705 }else //density
1667 // BETADIST (z,alpha,beta,distribution?density1:0) 1706 {
1668 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1707 return QString::number(
1669 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1708 pow(val1,val2-1.0)*exp(-val1/val3) / (pow(val3,val2)*exp(GammaLn(val2)))
1670 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); 1709 );
1671 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); 1710 };
1672 if(vali==1)//distribution 1711 };
1673 { 1712 if(function=="BETADIST")
1674 return QString::number(BetaIncomplete(val2,val3,val1)); 1713 {
1675 }else //density 1714 // BETADIST (z,alpha,beta,distribution?density1:0)
1676 { 1715 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1677 return QString::number( 1716 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1678 pow(val1,val2-1.0)*pow(1.0-val1,val3-1.0) / Beta(val2,val3) 1717 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok);
1679 ); 1718 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok);
1680 }; 1719 if(vali==1)//distribution
1681 }; 1720 {
1682 if(function=="FDIST") 1721 return QString::number(BetaIncomplete(val2,val3,val1));
1683 { 1722 }else //density
1684 // FDIST (z,d1,d2,distribution?density1:0) 1723 {
1685 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1724 return QString::number(
1686 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1725 pow(val1,val2-1.0)*pow(1.0-val1,val3-1.0) / Beta(val2,val3)
1687 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); 1726 );
1688 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); 1727 };
1689 if(vali==1)//distribution 1728 };
1690 { 1729 if(function=="FDIST")
1691 return QString::number( 1730 {
1692 -BetaIncomplete(val3/2,val2/2,val3/(val3+val2*val1)) 1731 // FDIST (z,d1,d2,distribution?density1:0)
1693 +BetaIncomplete(val3/2,val2/2,1) 1732 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1694 ); 1733 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1695 }else //density 1734 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok);
1696 { 1735 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok);
1697 return QString::number( 1736 if(vali==1)//distribution
1698 pow(val2,val2/2)*pow(val3,val3/2)*pow(val1,val2/2-1)/ 1737 {
1699 (pow(val3+val2*val1,(val2+val3)/2)*Beta(val2/2,val3/2)) 1738 return QString::number(
1700 ); 1739 -BetaIncomplete(val3/2,val2/2,val3/(val3+val2*val1))
1701 }; 1740 +BetaIncomplete(val3/2,val2/2,1)
1702 }; 1741 );
1703 if(function=="NORMALDIST") 1742 }else //density
1704 { 1743 {
1705 // NORMALDIST (x,m,s,distribution?density1:0) 1744 return QString::number(
1706 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1745 pow(val2,val2/2)*pow(val3,val3/2)*pow(val1,val2/2-1)/
1707 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1746 (pow(val3+val2*val1,(val2+val3)/2)*Beta(val2/2,val3/2))
1708 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); 1747 );
1709 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); 1748 };
1710 if(vali==1)//distribution 1749 };
1711 { 1750 if(function=="NORMALDIST")
1712 return QString::number( 1751 {
1713 (ErrorFunction((val1-val2)/(sqrt(2)*val3))+1)/2.0 1752 // NORMALDIST (x,m,s,distribution?density1:0)
1714 ); 1753 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1715 }else //density 1754 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1716 { 1755 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok);
1717 return QString::number( 1756 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok);
1718 exp(-pow(((val1-val2)/val3),2)/2)/(val3*sqrt(2*M_PI)) 1757 if(vali==1)//distribution
1719 ); 1758 {
1720 }; 1759 return QString::number(
1721 }; 1760 (ErrorFunction((val1-val2)/(sqrt(2)*val3))+1)/2.0
1722 if(function=="PHI") 1761 );
1723 { 1762 }else //density
1724 // NORMALDIST (x,distribution?density1:0) with mean=0 s=1.0 1763 {
1725 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1764 return QString::number(
1726 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1765 exp(-pow(((val1-val2)/val3),2)/2)/(val3*sqrt(2*M_PI))
1727 if(vali==1)//distribution 1766 );
1728 { 1767 };
1729 return QString::number( 1768 };
1730 (ErrorFunction(val1/(sqrt(2)))+1)/2.0 1769 if(function=="PHI")
1731 ); 1770 {
1732 }else //density 1771 // NORMALDIST (x,distribution?density1:0) with mean=0 s=1.0
1733 { 1772 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1734 return QString::number( 1773 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1735 exp(-pow(val1,2)/2)/(sqrt(2*M_PI)) 1774 if(vali==1)//distribution
1736 ); 1775 {
1737 }; 1776 return QString::number(
1738 }; 1777 (ErrorFunction(val1/(sqrt(2)))+1)/2.0
1739 /* 1778 );
1740 StudentTDistribution/: PDF[StudentTDistribution[n_], x_] := 1779 }else //density
1741 1/(Sqrt[n] Beta[n/2, 1/2]) Sqrt[n/(n+x^2)]^(n+1) /; 1780 {
1742 ParameterQ[StudentTDistribution[n]] 1781 return QString::number(
1743 1782 exp(-pow(val1,2)/2)/(sqrt(2*M_PI))
1744 StudentTDistribution/: CDF[StudentTDistribution[n_], x_] := 1783 );
1745 (1 + Sign[x] BetaRegularized[n/(n+x^2), 1, n/2, 1/2])/2 /; 1784 };
1746 ParameterQ[StudentTDistribution[n]] 1785 };
1747 */ 1786 /*
1748 1787 StudentTDistribution/: PDF[StudentTDistribution[n_], x_] :=
1749 1788 1/(Sqrt[n] Beta[n/2, 1/2]) Sqrt[n/(n+x^2)]^(n+1) /;
1750 1789 ParameterQ[StudentTDistribution[n]]
1751 return 0; 1790
1791 StudentTDistribution/: CDF[StudentTDistribution[n_], x_] :=
1792 (1 + Sign[x] BetaRegularized[n/(n+x^2), 1, n/2, 1/2])/2 /;
1793 ParameterQ[StudentTDistribution[n]]
1794 */
1795
1796
1797
1798 return 0;
1752}; 1799};
1753 1800
@@ -1757,62 +1804,62 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
1757QString Sheet::dataParserHelper(const QString &data) 1804QString Sheet::dataParserHelper(const QString &data)
1758{ 1805{
1759 if(data.left(1)=="""" && data.right(1)=="""") return QString(data); 1806 if(data.left(1)=="""" && data.right(1)=="""") return QString(data);
1760 Expression exp1(data); 1807 Expression exp1(data);
1761 exp1.Parse(); 1808 exp1.Parse();
1762 QStack<QString> stack1; 1809 QStack<QString> stack1;
1763 stack1.setAutoDelete(TRUE); 1810 stack1.setAutoDelete(TRUE);
1764 int i=0; 1811 int i=0;
1765 QString* s1; 1812 QString* s1;
1766 QString* s2=NULL; 1813 QString* s2=NULL;
1767 int* i1; 1814 int* i1;
1768 int args,tokentype; 1815 int args,tokentype;
1769 QString tempval; 1816 QString tempval;
1770 s1=exp1.CompiledBody.first();i1=exp1.CompiledBodyType.first(); 1817 s1=exp1.CompiledBody.first();i1=exp1.CompiledBodyType.first();
1771 while(i<=(int)exp1.CompiledBody.count()-1) 1818 while(i<=(int)exp1.CompiledBody.count()-1)
1772 { 1819 {
1773 args= ((*i1) & 0xFF00)>>8; tokentype=(*i1) & 0x00FF; 1820 args= ((*i1) & 0xFF00)>>8; tokentype=(*i1) & 0x00FF;
1774 if(tokentype==NUMBER_TOKEN) 1821 if(tokentype==NUMBER_TOKEN)
1775 { 1822 {
1776 stack1.push(new QString(*s1)); 1823 stack1.push(new QString(*s1));
1777 //printf("Parse:Number=%s\r\n",s1->latin1()); 1824 //printf("Parse:Number=%s\r\n",s1->latin1());
1778 } 1825 }
1779 else if(tokentype==VARIABLE_TOKEN) 1826 else if(tokentype==VARIABLE_TOKEN)
1780 { 1827 {
1781 stack1.push(new QString(QString(*s1).upper())); 1828 stack1.push(new QString(QString(*s1).upper()));
1782 //printf("Parse:Var=%s\r\n",s1->latin1()); 1829 //printf("Parse:Var=%s\r\n",s1->latin1());
1783 //here to put implementation of other types of variables except cell. 1830 //here to put implementation of other types of variables except cell.
1784 //for example names 1831 //for example names
1785 } 1832 }
1786 else if(tokentype==STRING_TOKEN) 1833 else if(tokentype==STRING_TOKEN)
1787 { 1834 {
1788 stack1.push(new QString(*s1)); 1835 stack1.push(new QString(*s1));
1789 //printf("Parse:String=%s\r\n",s1->ascii()); 1836 //printf("Parse:String=%s\r\n",s1->ascii());
1790 } 1837 }
1791 else if(tokentype==FUNCTION_TOKEN) 1838 else if(tokentype==FUNCTION_TOKEN)
1792 { 1839 {
1793 QString params=""; 1840 QString params="";
1794 for(int w1=1;w1<=args;w1++) 1841 for(int w1=1;w1<=args;w1++)
1795 { 1842 {
1796 if((int)stack1.count()!=0) s2=stack1.pop(); 1843 if((int)stack1.count()!=0) s2=stack1.pop();
1797 params=*s2+params;//args in reverse order 1844 params=*s2+params;//args in reverse order
1798 params=","+params; 1845 params=","+params;
1799 }; 1846 };
1800 params=params.mid(1); 1847 params=params.mid(1);
1801 if(params==NULL) params="0"; 1848 if(params==NULL) params="0";
1802 //printf("Parse:Func=%s, params=%s, stackcount=%d,args=%d\r\n" 1849 //printf("Parse:Func=%s, params=%s, stackcount=%d,args=%d\r\n"
1803 //,s1->latin1(),params.latin1(),stack1.count(),args); 1850 // ,s1->latin1(),params.latin1(),stack1.count(),args);
1804 tempval=calculateFunction(*s1,params,args); 1851 tempval=calculateFunction(*s1,params,args);
1805 tempval=tempval; 1852 tempval=tempval;
1806 stack1.push(new QString(tempval)); 1853 stack1.push(new QString(tempval));
1807 }; 1854 };
1808 1855
1809 //loops to next token 1856 //loops to next token
1810 if(exp1.CompiledBody.next()!=NULL) s1=exp1.CompiledBody.current(); else break; 1857 if(exp1.CompiledBody.next()!=NULL) s1=exp1.CompiledBody.current(); else break;
1811 if(exp1.CompiledBodyType.next()!=NULL) i1=exp1.CompiledBodyType.current(); else break; 1858 if(exp1.CompiledBodyType.next()!=NULL) i1=exp1.CompiledBodyType.current(); else break;
1812 i++; 1859 i++;
1813 }; 1860 };
1814 if((int)stack1.count()!=0)s2=stack1.pop(); else s2=new QString("!ERROR"); 1861 if((int)stack1.count()!=0)s2=stack1.pop(); else s2=new QString("!ERROR");
1815 tempval=*s2; 1862 tempval=*s2;
1816 return(tempval); 1863 return(tempval);
1817}; 1864};
1818 1865
@@ -1821,22 +1868,22 @@ QString Sheet::dataParserHelper(const QString &data)
1821QString Sheet::dataParser(const QString &cell, const QString &data) 1868QString Sheet::dataParser(const QString &cell, const QString &data)
1822{ 1869{
1823 QString strippedData(data); 1870 QString strippedData(data);
1824 strippedData.replace(QRegExp("\\s"), ""); 1871 strippedData.replace(QRegExp("\\s"), "");
1825 if (strippedData.isEmpty() || strippedData[0]!='=') return data; 1872 if (strippedData.isEmpty() || strippedData[0]!='=') return data;
1826 if (listDataParser.find(cell)!=listDataParser.end()) return "0"; 1873 if (listDataParser.find(cell)!=listDataParser.end()) return "0";
1827 listDataParser.append(cell); 1874 listDataParser.append(cell);
1828 // printf("DATAPARSER: data=%s, cell=%s\r\n",data.ascii(),cell.ascii()); 1875 // printf("DATAPARSER: data=%s, cell=%s\r\n",data.ascii(),cell.ascii());
1829 strippedData=dataParserHelper(strippedData.remove(0, 1).replace(QRegExp(":"), ",")); 1876 strippedData=dataParserHelper(strippedData.remove(0, 1).replace(QRegExp(":"), ","));
1830 1877
1831 int i=0; 1878 int i=0;
1832 QString tempParameter(getParameter(strippedData, i)), result=""; 1879 QString tempParameter(getParameter(strippedData, i)), result="";
1833 do 1880 do
1834 { 1881 {
1835 result+=","+calculateVariable(tempParameter); 1882 result+=","+calculateVariable(tempParameter);
1836 tempParameter=getParameter(strippedData, ++i); 1883 tempParameter=getParameter(strippedData, ++i);
1837 } 1884 }
1838 while (!tempParameter.isNull()); 1885 while (!tempParameter.isNull());
1839 listDataParser.remove(cell); 1886 listDataParser.remove(cell);
1840 return result.mid(1); 1887 return result.mid(1);
1841} 1888}
1842 1889
@@ -1844,415 +1891,415 @@ QString Sheet::dataParser(const QString &cell, const QString &data)
1844void Sheet::setData(const QString &data) 1891void Sheet::setData(const QString &data)
1845{ 1892{
1846 setText(currentRow(), currentColumn(), data); 1893 setText(currentRow(), currentColumn(), data);
1847 slotCellChanged(currentRow(), currentColumn()); 1894 slotCellChanged(currentRow(), currentColumn());
1848 activateNextCell(); 1895 activateNextCell();
1849} 1896}
1850 1897
1851QString Sheet::getData() 1898QString Sheet::getData()
1852{ 1899{
1853 typeCellData *cellData=findCellData(currentRow(), currentColumn()); 1900 typeCellData *cellData=findCellData(currentRow(), currentColumn());
1854 if (cellData) 1901 if (cellData)
1855 return cellData->data; 1902 return cellData->data;
1856 return ""; 1903 return "";
1857} 1904}
1858 1905
1859void Sheet::lockClicks(bool lock) 1906void Sheet::lockClicks(bool lock)
1860{ 1907{
1861 clicksLocked=lock; 1908 clicksLocked=lock;
1862} 1909}
1863 1910
1864void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected) 1911void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected)
1865{ 1912{
1866 if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; 1913 if (selected && row==currentRow() && col==currentColumn()) selected=FALSE;
1867 1914
1868 int sheetDataCurrent=sheetData.at(); 1915 int sheetDataCurrent=sheetData.at();
1869 typeCellData *cellData=findCellData(row, col); 1916 typeCellData *cellData=findCellData(row, col);
1870 if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); 1917 if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent);
1871 if (!cellData) cellData=&defaultCellData; 1918 if (!cellData) cellData=&defaultCellData;
1872 if (selected) 1919 if (selected)
1873 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); 1920 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight());
1874 else 1921 else
1875 { 1922 {
1876 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); 1923 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base());
1877 p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); 1924 p->fillRect(0, 0, cr.width(), cr.height(), cellData->background);
1878 } 1925 }
1879 1926
1880 QTableItem *cellItem=item(row, col); 1927 QTableItem *cellItem=item(row, col);
1881 if (cellItem) 1928 if (cellItem)
1882 { 1929 {
1883 p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); 1930 p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor);
1884 p->setFont(cellData->font); 1931 p->setFont(cellData->font);
1885 QString str=cellItem->text(); 1932 QString str=cellItem->text();
1886 p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text()); 1933 p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text());
1887 } 1934 }
1888 1935
1889 int rx=cr.width()-1, ry=cr.height()-1; 1936 int rx=cr.width()-1, ry=cr.height()-1;
1890 QPen pen(p->pen()); 1937 QPen pen(p->pen());
1891 p->setPen(cellData->borders.right); 1938 p->setPen(cellData->borders.right);
1892 p->drawLine(rx, 0, rx, ry); 1939 p->drawLine(rx, 0, rx, ry);
1893 p->setPen(cellData->borders.bottom); 1940 p->setPen(cellData->borders.bottom);
1894 p->drawLine(0, ry, rx, ry); 1941 p->drawLine(0, ry, rx, ry);
1895 p->setPen(pen); 1942 p->setPen(pen);
1896} 1943}
1897 1944
1898void Sheet::viewportMousePressEvent(QMouseEvent *e) 1945void Sheet::viewportMousePressEvent(QMouseEvent *e)
1899{ 1946{
1900 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); 1947 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
1901 if (clicksLocked) 1948 if (clicksLocked)
1902 {
1903 if (selectionNo<0)
1904 { 1949 {
1905 clearSelection(); 1950 if (selectionNo<0)
1906 QTableSelection newSelection; 1951 {
1907 newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); 1952 clearSelection();
1908 newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); 1953 QTableSelection newSelection;
1909 selectionNo=addSelection(newSelection); 1954 newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
1955 newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol());
1956 selectionNo=addSelection(newSelection);
1957 }
1910 } 1958 }
1911 } 1959 else
1912 else 1960 QTable::contentsMousePressEvent(&ce);
1913 QTable::contentsMousePressEvent(&ce);
1914} 1961}
1915 1962
1916void Sheet::viewportMouseMoveEvent(QMouseEvent *e) 1963void Sheet::viewportMouseMoveEvent(QMouseEvent *e)
1917{ 1964{
1918 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); 1965 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
1919 if (clicksLocked) 1966 if (clicksLocked)
1920 {
1921 if (selectionNo>=0)
1922 { 1967 {
1923 QTableSelection oldSelection(selection(selectionNo)); 1968 if (selectionNo>=0)
1924 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); 1969 {
1925 if (!(oldSelection==selection(selectionNo))) 1970 QTableSelection oldSelection(selection(selectionNo));
1926 { 1971 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
1927 removeSelection(selectionNo); 1972 if (!(oldSelection==selection(selectionNo)))
1928 selectionNo=addSelection(oldSelection); 1973 {
1929 } 1974 removeSelection(selectionNo);
1975 selectionNo=addSelection(oldSelection);
1976 }
1977 }
1930 } 1978 }
1931 } 1979 else
1932 else 1980 QTable::contentsMouseMoveEvent(&ce);
1933 QTable::contentsMouseMoveEvent(&ce);
1934} 1981}
1935 1982
1936void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) 1983void Sheet::viewportMouseReleaseEvent(QMouseEvent *e)
1937{ 1984{
1938 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); 1985 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
1939 if (clicksLocked && selectionNo>=0) 1986 if (clicksLocked && selectionNo>=0)
1940 { 1987 {
1941 QTableSelection oldSelection(selection(selectionNo)); 1988 QTableSelection oldSelection(selection(selectionNo));
1942 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); 1989 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
1943 removeSelection(selectionNo); 1990 removeSelection(selectionNo);
1944 selectionNo=-1; 1991 selectionNo=-1;
1945 if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) 1992 if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol())
1946 emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())); 1993 emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol()));
1994 else
1995 emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol()));
1996 }
1947 else 1997 else
1948 emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol())); 1998 QTable::contentsMouseReleaseEvent(&ce);
1949 }
1950 else
1951 QTable::contentsMouseReleaseEvent(&ce);
1952} 1999}
1953 2000
1954QString Sheet::findCellName(int row, int col) 2001QString Sheet::findCellName(int row, int col)
1955{ 2002{
1956 return (getHeaderString(col+1)+QString::number(row+1)); 2003 return (getHeaderString(col+1)+QString::number(row+1));
1957} 2004}
1958 2005
1959void Sheet::copySheetData(QList<typeCellData> *destSheetData) 2006void Sheet::copySheetData(QList<typeCellData> *destSheetData)
1960{ 2007{
1961 typeCellData *tempCellData, *newCellData; 2008 typeCellData *tempCellData, *newCellData;
1962 destSheetData->clear(); 2009 destSheetData->clear();
1963 2010
1964 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 2011 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
1965 { 2012 {
1966 newCellData=new typeCellData; 2013 newCellData=new typeCellData;
1967 *newCellData=*tempCellData; 2014 *newCellData=*tempCellData;
1968 destSheetData->append(newCellData); 2015 destSheetData->append(newCellData);
1969 } 2016 }
1970} 2017}
1971 2018
1972void Sheet::setSheetData(QList<typeCellData> *srcSheetData) 2019void Sheet::setSheetData(QList<typeCellData> *srcSheetData)
1973{ 2020{
1974 typeCellData *tempCellData, *newCellData; 2021 typeCellData *tempCellData, *newCellData;
1975 2022
1976 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 2023 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
1977 { 2024 {
1978 clearCell(tempCellData->row, tempCellData->col); 2025 clearCell(tempCellData->row, tempCellData->col);
1979 updateCell(tempCellData->row, tempCellData->col); 2026 updateCell(tempCellData->row, tempCellData->col);
1980 } 2027 }
1981 sheetData.clear(); 2028 sheetData.clear();
1982 2029
1983 for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) 2030 for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next())
1984 { 2031 {
1985 newCellData=new typeCellData; 2032 newCellData=new typeCellData;
1986 *newCellData=*tempCellData; 2033 *newCellData=*tempCellData;
1987 sheetData.append(newCellData); 2034 sheetData.append(newCellData);
1988 setText(newCellData->row, newCellData->col, dataParser(findCellName(newCellData->row, newCellData->col), newCellData->data)); 2035 setText(newCellData->row, newCellData->col, dataParser(findCellName(newCellData->row, newCellData->col), newCellData->data));
1989 } 2036 }
1990 emit sheetModified(); 2037 emit sheetModified();
1991} 2038}
1992 2039
1993void Sheet::setName(const QString &name) 2040void Sheet::setName(const QString &name)
1994{ 2041{
1995 sheetName=name; 2042 sheetName=name;
1996 emit sheetModified(); 2043 emit sheetModified();
1997} 2044}
1998 2045
1999QString Sheet::getName() 2046QString Sheet::getName()
2000{ 2047{
2001 return sheetName; 2048 return sheetName;
2002} 2049}
2003 2050
2004void Sheet::setBrush(int row, int col, const QBrush &brush) 2051void Sheet::setBrush(int row, int col, const QBrush &brush)
2005{ 2052{
2006 typeCellData *cellData=findCellData(row, col); 2053 typeCellData *cellData=findCellData(row, col);
2007 if (!cellData) cellData=createCellData(row, col); 2054 if (!cellData) cellData=createCellData(row, col);
2008 if (cellData) 2055 if (cellData)
2009 { 2056 {
2010 cellData->background=brush; 2057 cellData->background=brush;
2011 emit sheetModified(); 2058 emit sheetModified();
2012 } 2059 }
2013} 2060}
2014 2061
2015QBrush Sheet::getBrush(int row, int col) 2062QBrush Sheet::getBrush(int row, int col)
2016{ 2063{
2017 typeCellData *cellData=findCellData(row, col); 2064 typeCellData *cellData=findCellData(row, col);
2018 if (!cellData) cellData=&defaultCellData; 2065 if (!cellData) cellData=&defaultCellData;
2019 return cellData->background; 2066 return cellData->background;
2020} 2067}
2021 2068
2022void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) 2069void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags)
2023{ 2070{
2024 typeCellData *cellData=findCellData(row, col); 2071 typeCellData *cellData=findCellData(row, col);
2025 if (!cellData) cellData=createCellData(row, col); 2072 if (!cellData) cellData=createCellData(row, col);
2026 if (cellData) 2073 if (cellData)
2027 { 2074 {
2028 cellData->alignment=flags; 2075 cellData->alignment=flags;
2029 emit sheetModified(); 2076 emit sheetModified();
2030 } 2077 }
2031} 2078}
2032 2079
2033Qt::AlignmentFlags Sheet::getAlignment(int row, int col) 2080Qt::AlignmentFlags Sheet::getAlignment(int row, int col)
2034{ 2081{
2035 typeCellData *cellData=findCellData(row, col); 2082 typeCellData *cellData=findCellData(row, col);
2036 if (!cellData) cellData=&defaultCellData; 2083 if (!cellData) cellData=&defaultCellData;
2037 return cellData->alignment; 2084 return cellData->alignment;
2038} 2085}
2039 2086
2040void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color) 2087void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color)
2041{ 2088{
2042 typeCellData *cellData=findCellData(row, col); 2089 typeCellData *cellData=findCellData(row, col);
2043 if (!cellData) cellData=createCellData(row, col); 2090 if (!cellData) cellData=createCellData(row, col);
2044 if (cellData) 2091 if (cellData)
2045 { 2092 {
2046 cellData->font=font; 2093 cellData->font=font;
2047 cellData->fontColor=color; 2094 cellData->fontColor=color;
2048 emit sheetModified(); 2095 emit sheetModified();
2049 } 2096 }
2050} 2097}
2051 2098
2052QFont Sheet::getFont(int row, int col) 2099QFont Sheet::getFont(int row, int col)
2053{ 2100{
2054 typeCellData *cellData=findCellData(row, col); 2101 typeCellData *cellData=findCellData(row, col);
2055 if (!cellData) cellData=&defaultCellData; 2102 if (!cellData) cellData=&defaultCellData;
2056 return cellData->font; 2103 return cellData->font;
2057} 2104}
2058 2105
2059QColor Sheet::getFontColor(int row, int col) 2106QColor Sheet::getFontColor(int row, int col)
2060{ 2107{
2061 typeCellData *cellData=findCellData(row, col); 2108 typeCellData *cellData=findCellData(row, col);
2062 if (!cellData) cellData=&defaultCellData; 2109 if (!cellData) cellData=&defaultCellData;
2063 return cellData->fontColor; 2110 return cellData->fontColor;
2064} 2111}
2065 2112
2066void Sheet::setPen(int row, int col, int vertical, const QPen &pen) 2113void Sheet::setPen(int row, int col, int vertical, const QPen &pen)
2067{ 2114{
2068 typeCellData *cellData=findCellData(row, col); 2115 typeCellData *cellData=findCellData(row, col);
2069 if (!cellData) cellData=createCellData(row, col); 2116 if (!cellData) cellData=createCellData(row, col);
2070 if (cellData) 2117 if (cellData)
2071 { 2118 {
2072 if (vertical) 2119 if (vertical)
2073 cellData->borders.right=pen; 2120 cellData->borders.right=pen;
2074 else 2121 else
2075 cellData->borders.bottom=pen; 2122 cellData->borders.bottom=pen;
2076 emit sheetModified(); 2123 emit sheetModified();
2077 } 2124 }
2078} 2125}
2079 2126
2080QPen Sheet::getPen(int row, int col, int vertical) 2127QPen Sheet::getPen(int row, int col, int vertical)
2081{ 2128{
2082 typeCellData *cellData=findCellData(row, col); 2129 typeCellData *cellData=findCellData(row, col);
2083 if (!cellData) cellData=&defaultCellData; 2130 if (!cellData) cellData=&defaultCellData;
2084 return (vertical ? cellData->borders.right : cellData->borders.bottom); 2131 return (vertical ? cellData->borders.right : cellData->borders.bottom);
2085} 2132}
2086 2133
2087void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) 2134void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2)
2088{ 2135{
2089 int selectionNo=currentSelection(); 2136 int selectionNo=currentSelection();
2090 if (selectionNo>=0) 2137 if (selectionNo>=0)
2091 { 2138 {
2092 QTableSelection select(selection(selectionNo)); 2139 QTableSelection select(selection(selectionNo));
2093 *row1=select.topRow(); 2140 *row1=select.topRow();
2094 *row2=select.bottomRow(); 2141 *row2=select.bottomRow();
2095 *col1=select.leftCol(); 2142 *col1=select.leftCol();
2096 *col2=select.rightCol(); 2143 *col2=select.rightCol();
2097 } 2144 }
2098 else 2145 else
2099 { 2146 {
2100 *row1=*row2=currentRow(); 2147 *row1=*row2=currentRow();
2101 *col1=*col2=currentColumn(); 2148 *col1=*col2=currentColumn();
2102 } 2149 }
2103} 2150}
2104 2151
2105void Sheet::editClear() 2152void Sheet::editClear()
2106{ 2153{
2107 int row1, row2, col1, col2; 2154 int row1, row2, col1, col2;
2108 getSelection(&row1, &col1, &row2, &col2); 2155 getSelection(&row1, &col1, &row2, &col2);
2109 2156
2110 int row, col; 2157 int row, col;
2111 for (row=row1; row<=row2; ++row) 2158 for (row=row1; row<=row2; ++row)
2112 for (col=col1; col<=col2; ++col) 2159 for (col=col1; col<=col2; ++col)
2113 { 2160 {
2114 setText(row, col, ""); 2161 setText(row, col, "");
2115 slotCellChanged(row, col); 2162 slotCellChanged(row, col);
2116 } 2163 }
2117} 2164}
2118 2165
2119void Sheet::editCopy() 2166void Sheet::editCopy()
2120{ 2167{
2121 clipboardData.clear(); 2168 clipboardData.clear();
2122 2169
2123 int row1, row2, col1, col2; 2170 int row1, row2, col1, col2;
2124 getSelection(&row1, &col1, &row2, &col2); 2171 getSelection(&row1, &col1, &row2, &col2);
2125 2172
2126 typeCellData *cellData, *newCellData; 2173 typeCellData *cellData, *newCellData;
2127 int row, col; 2174 int row, col;
2128 for (row=row1; row<=row2; ++row) 2175 for (row=row1; row<=row2; ++row)
2129 for (col=col1; col<=col2; ++col) 2176 for (col=col1; col<=col2; ++col)
2130 { 2177 {
2131 cellData=findCellData(row, col); 2178 cellData=findCellData(row, col);
2132 if (cellData) 2179 if (cellData)
2133 { 2180 {
2134 newCellData=new typeCellData; 2181 newCellData=new typeCellData;
2135 *newCellData=*cellData; 2182 *newCellData=*cellData;
2136 newCellData->row-=row1; 2183 newCellData->row-=row1;
2137 newCellData->col-=col1; 2184 newCellData->col-=col1;
2138 clipboardData.append(newCellData); 2185 clipboardData.append(newCellData);
2139 } 2186 }
2140 } 2187 }
2141} 2188}
2142 2189
2143void Sheet::editCut() 2190void Sheet::editCut()
2144{ 2191{
2145 editCopy(); 2192 editCopy();
2146 editClear(); 2193 editClear();
2147} 2194}
2148 2195
2149void Sheet::editPaste(bool onlyContents) 2196void Sheet::editPaste(bool onlyContents)
2150{ 2197{
2151 int row1=currentRow(), col1=currentColumn(); 2198 int row1=currentRow(), col1=currentColumn();
2152 typeCellData *cellData, *tempCellData; 2199 typeCellData *cellData, *tempCellData;
2153 2200
2154 for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) 2201 for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next())
2155 {
2156 cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1);
2157 if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1);
2158 if (cellData)
2159 { 2202 {
2160 if (onlyContents) 2203 cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1);
2161 cellData->data=tempCellData->data; 2204 if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1);
2162 else 2205 if (cellData)
2163 { 2206 {
2164 *cellData=*tempCellData; 2207 if (onlyContents)
2165 cellData->row+=row1; 2208 cellData->data=tempCellData->data;
2166 cellData->col+=col1; 2209 else
2167 } 2210 {
2168 setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); 2211 *cellData=*tempCellData;
2169 emit sheetModified(); 2212 cellData->row+=row1;
2170 } 2213 cellData->col+=col1;
2171 } 2214 }
2215 setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data));
2216 emit sheetModified();
2217 }
2218 }
2172} 2219}
2173 2220
2174void Sheet::insertRows(int no, bool allColumns) 2221void Sheet::insertRows(int no, bool allColumns)
2175{ 2222{
2176 setNumRows(numRows()+no); 2223 setNumRows(numRows()+no);
2177 2224
2178 typeCellData *tempCellData; 2225 typeCellData *tempCellData;
2179 int row=currentRow(), col=currentColumn(); 2226 int row=currentRow(), col=currentColumn();
2180 2227
2181 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 2228 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
2182 if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) 2229 if (tempCellData->row>=row && (allColumns || tempCellData->col==col))
2183 { 2230 {
2184 clearCell(tempCellData->row, tempCellData->col); 2231 clearCell(tempCellData->row, tempCellData->col);
2185 tempCellData->row+=no; 2232 tempCellData->row+=no;
2186 } 2233 }
2187 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 2234 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
2188 if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) 2235 if (tempCellData->row>=row && (allColumns || tempCellData->col==col))
2189 { 2236 {
2190 updateCell(tempCellData->row-no, tempCellData->col); 2237 updateCell(tempCellData->row-no, tempCellData->col);
2191 setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); 2238 setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data));
2192 } 2239 }
2193 emit sheetModified(); 2240 emit sheetModified();
2194} 2241}
2195 2242
2196void Sheet::insertColumns(int no, bool allRows) 2243void Sheet::insertColumns(int no, bool allRows)
2197{ 2244{
2198 int noCols=numCols(); 2245 int noCols=numCols();
2199 int newCols=noCols+no; 2246 int newCols=noCols+no;
2200 setNumCols(newCols); 2247 setNumCols(newCols);
2201 for (int i=noCols; i<newCols; ++i) 2248 for (int i=noCols; i<newCols; ++i)
2202 horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); 2249 horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH);
2203 2250
2204 typeCellData *tempCellData; 2251 typeCellData *tempCellData;
2205 int col=currentColumn(), row=currentRow(); 2252 int col=currentColumn(), row=currentRow();
2206 2253
2207 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 2254 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
2208 if (tempCellData->col>=col && (allRows || tempCellData->row==row)) 2255 if (tempCellData->col>=col && (allRows || tempCellData->row==row))
2209 { 2256 {
2210 clearCell(tempCellData->row, tempCellData->col); 2257 clearCell(tempCellData->row, tempCellData->col);
2211 tempCellData->col+=no; 2258 tempCellData->col+=no;
2212 } 2259 }
2213 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 2260 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
2214 if (tempCellData->col>=col && (allRows || tempCellData->row==row)) 2261 if (tempCellData->col>=col && (allRows || tempCellData->row==row))
2215 { 2262 {
2216 updateCell(tempCellData->row, tempCellData->col-no); 2263 updateCell(tempCellData->row, tempCellData->col-no);
2217 setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); 2264 setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data));
2218 } 2265 }
2219 emit sheetModified(); 2266 emit sheetModified();
2220} 2267}
2221 2268
2222void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll) 2269void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll)
2223{ 2270{
2224 typeCellData *tempCellData; 2271 typeCellData *tempCellData;
2225 int row1, col1, row2, col2; 2272 int row1, col1, row2, col2;
2226 getSelection(&row1, &col1, &row2, &col2); 2273 getSelection(&row1, &col1, &row2, &col2);
2227 bool found=FALSE; 2274 bool found=FALSE;
2228 2275
2229 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) 2276 for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
2230 if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2)) 2277 if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2))
2231 {
2232 QTableItem *cellItem=item(tempCellData->row, tempCellData->col);
2233 if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0))
2234 {
2235 if (!found)
2236 { 2278 {
2237 found=TRUE; 2279 QTableItem *cellItem=item(tempCellData->row, tempCellData->col);
2238 clearSelection(); 2280 if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0))
2281 {
2282 if (!found)
2283 {
2284 found=TRUE;
2285 clearSelection();
2286 }
2287 setCurrentCell(tempCellData->row, tempCellData->col);
2288 if (replace)
2289 {
2290 tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr);
2291 setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data));
2292 }
2293 if (!replace || !replaceAll) break;
2294 }
2239 } 2295 }
2240 setCurrentCell(tempCellData->row, tempCellData->col); 2296
2297 if (found)
2298 {
2241 if (replace) 2299 if (replace)
2242 { 2300 slotCellChanged(currentRow(), currentColumn());
2243 tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr);
2244 setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data));
2245 }
2246 if (!replace || !replaceAll) break;
2247 }
2248 } 2301 }
2249 2302 else
2250 if (found) 2303 QMessageBox::warning(this, tr("Error"), tr("Search key not found!"));
2251 {
2252 if (replace)
2253 slotCellChanged(currentRow(), currentColumn());
2254 }
2255 else
2256 QMessageBox::warning(this, tr("Error"), tr("Search key not found!"));
2257} 2304}
2258 2305
@@ -2263,12 +2310,12 @@ void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, b
2263QString Sheet::getHeaderString(int section) 2310QString Sheet::getHeaderString(int section)
2264{ 2311{
2265 if (section<1) return ""; 2312 if (section<1) return "";
2266 return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); 2313 return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26);
2267} 2314}
2268 2315
2269int Sheet::getHeaderColumn(const QString &section) 2316int Sheet::getHeaderColumn(const QString &section)
2270{ 2317{
2271 if (section.isEmpty()) return 0; 2318 if (section.isEmpty()) return 0;
2272 return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26; 2319 return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26;
2273} 2320}
2274 2321
@@ -2279,204 +2326,205 @@ int Sheet::getHeaderColumn(const QString &section)
2279QChar Expression::chunk0(void) 2326QChar Expression::chunk0(void)
2280{ 2327{
2281 if(chunk.length()>0) return(chunk[0]); else return('\0'); 2328 if(chunk.length()>0) return(chunk[0]); else return('\0');
2282}; 2329};
2283 2330
2284Expression::Expression(QString expr1)// constructor 2331Expression::Expression(QString expr1)// constructor
2285{ 2332{
2286 Body=expr1; 2333 Body=expr1;
2287 SYMBOL="+-*/%^=()<>&|!,"; 2334 SYMBOL="+-*/%^=()<>&|!,";
2288 MATHSYMBOL="+-*/%^=<>&|!,"; 2335 MATHSYMBOL="+-*/%^=<>&|!,";
2289 // lnlim=1.0e-36; // Smallest number allowed 2336 // lnlim=1.0e-36; // Smallest number allowed
2290 // loglim=1.0e-10 ; // Smallest number allowed in call to log10() * 2337 // loglim=1.0e-10 ; // Smallest number allowed in call to log10() *
2291 ErrorFound=TRUE; 2338 ErrorFound=TRUE;
2292 n=0;chunk="";SymbGroup=NONE_TOKEN;InExpr=Body; 2339 n=0;chunk="";SymbGroup=NONE_TOKEN;InExpr=Body;
2293 ArgsOfFunc=0; 2340 ArgsOfFunc=0;
2294 CompiledBody.setAutoDelete(TRUE); 2341 CompiledBody.setAutoDelete(TRUE);
2295 CompiledBodyType.setAutoDelete(TRUE); 2342 CompiledBodyType.setAutoDelete(TRUE);
2296 //CompiledBody=QStringList(0); 2343 //CompiledBody=QStringList(0);
2297}; 2344};
2298 2345
2299bool Expression::isSymbol(QChar ch) 2346bool Expression::isSymbol(QChar ch)
2300{ 2347{
2301 int j = 0; 2348 int j = 0;
2302 while (j<=((int)SYMBOL.length()-1) && ch!=SYMBOL[j]) j++; 2349 while (j<=((int)SYMBOL.length()-1) && ch!=SYMBOL[j]) j++;
2303 if(j<((int)SYMBOL.length())) return true; else return false; 2350 if(j<((int)SYMBOL.length())) return true; else return false;
2304}; 2351};
2305 2352
2306bool Expression::isMathSymbol(QChar ch) 2353bool Expression::isMathSymbol(QChar ch)
2307{ 2354{
2308 int j = 0; 2355 int j = 0;
2309 while (j<=((int)MATHSYMBOL.length()-1) && ch!=MATHSYMBOL[j]) j++; 2356 while (j<=((int)MATHSYMBOL.length()-1) && ch!=MATHSYMBOL[j]) j++;
2310 if(j<((int)MATHSYMBOL.length())) return true; else return false; 2357 if(j<((int)MATHSYMBOL.length())) return true; else return false;
2311}; 2358};
2312 2359
2313void Expression::GetNext() 2360void Expression::GetNext()
2314{ 2361{
2315 chunk=""; 2362 chunk="";
2316 if(n>=(int)InExpr.length()) return; 2363 if(n>=(int)InExpr.length()) return;
2317 while (InExpr[n]==' ') n++; 2364 while (InExpr[n]==' ') n++;
2318 if(InExpr[n]=='\"') 2365 if(InExpr[n]=='\"')
2319 { 2366 {
2320 while ( (n<(int)InExpr.length()) && (InExpr[n+1]!='\"') ) 2367 while ( (n<(int)InExpr.length()) && (InExpr[n+1]!='\"') )
2321 { 2368 {
2322 printf("chunk=%s\r\n",chunk.latin1()); 2369 printf("chunk=%s\r\n",chunk.latin1());
2323 chunk+=InExpr[n]; 2370 chunk+=InExpr[n];
2324 n++; 2371 n++;
2325 }; 2372 };
2326 chunk+=InExpr[n]; 2373 chunk+=InExpr[n];
2327 printf("2\r\n"); 2374 printf("2\r\n");
2328 SymbGroup=STRING_TOKEN; 2375 SymbGroup=STRING_TOKEN;
2329 } 2376 }
2330 else if (isSymbol(InExpr[n])) 2377 else if (isSymbol(InExpr[n]))
2331 { 2378 {
2332 SymbGroup=SYMBOL_TOKEN; 2379 SymbGroup=SYMBOL_TOKEN;
2333 chunk+=InExpr[n]; 2380 chunk+=InExpr[n];
2334 n++; 2381 n++;
2335 if( (n<(int)InExpr.length()) && 2382 if( (n<(int)InExpr.length()) &&
2336 isMathSymbol(InExpr[n-1]) && 2383 isMathSymbol(InExpr[n-1]) &&
2337 isMathSymbol(InExpr[n]) ) 2384 isMathSymbol(InExpr[n]) )
2338 { 2385 {
2339 SymbGroup=SYMBOL_TOKEN; 2386 SymbGroup=SYMBOL_TOKEN;
2340 chunk+=InExpr[n]; 2387 chunk+=InExpr[n];
2341 n++; 2388 n++;
2342 }; 2389 };
2343 } 2390 }
2344 else if ((InExpr[n].isLetter())||(InExpr[n]=='#')) 2391 else if ((InExpr[n].isLetter())||(InExpr[n]=='#'))
2345 { 2392 {
2346 while ( (n<(int)InExpr.length()) && !isSymbol(InExpr[n]) ) 2393 while ( (n<(int)InExpr.length()) && !isSymbol(InExpr[n]) )
2347 { 2394 {
2348 if (!(InExpr[n]==' ')) chunk+=InExpr[n]; 2395 if (!(InExpr[n]==' ')) chunk+=InExpr[n];
2349 n++; 2396 n++;
2350 }; 2397 };
2351 if (InExpr[n]=='(') SymbGroup=FUNCTION_TOKEN; // function TOKEN 2398 if (InExpr[n]=='(') SymbGroup=FUNCTION_TOKEN; // function TOKEN
2352 else SymbGroup=VARIABLE_TOKEN; 2399 else SymbGroup=VARIABLE_TOKEN;
2353 } 2400 }
2354 else if((n<(int)InExpr.length()) && 2401 else if((n<(int)InExpr.length()) &&
2355 ((InExpr[n].isDigit()) || (InExpr[n]=='.'))) 2402 ((InExpr[n].isDigit()) || (InExpr[n]=='.')))
2356 { 2403 {
2357 while( n<(int)InExpr.length() ) 2404 while( n<(int)InExpr.length() )
2358 { 2405 {
2359 if((InExpr[n].isDigit()) || InExpr[n]=='.') 2406 if((InExpr[n].isDigit()) || InExpr[n]=='.')
2360 { 2407 {
2361 chunk+=InExpr[n]; 2408 chunk+=InExpr[n];
2362 SymbGroup=NUMBER_TOKEN; 2409 SymbGroup=NUMBER_TOKEN;
2363 n++; 2410 n++;
2364 } 2411 }
2365 else if(InExpr[n]=='e') 2412 else if(InExpr[n]=='e')
2366 { 2413 {
2367 if((n+1)<(int)InExpr.length()) 2414 if((n+1)<(int)InExpr.length())
2368 { 2415 {
2369 if(InExpr[n+1]=='-' || InExpr[n+1]=='+' || InExpr[n+1].isDigit()) 2416 if(InExpr[n+1]=='-' || InExpr[n+1]=='+' || InExpr[n+1].isDigit())
2370 { 2417 {
2371 chunk+=InExpr[n]; 2418 chunk+=InExpr[n];
2372 chunk+=InExpr[n+1]; 2419 chunk+=InExpr[n+1];
2373 SymbGroup=NUMBER_TOKEN; 2420 SymbGroup=NUMBER_TOKEN;
2374 n+=2; 2421 n+=2;
2375 } 2422 }
2376 } 2423 }
2377 else 2424 else
2378 { 2425 {
2379 break; 2426 break;
2380 } 2427 }
2381 } 2428 }
2382 else 2429 else
2383 { 2430 {
2384 break; 2431 break;
2385 } 2432 }
2386 }//while 2433 }//while
2387 }//else if 2434 }//else if
2388};//end function 2435}
2436;//end function
2389 2437
2390 2438
2391void Expression::First() 2439void Expression::First()
2392{ 2440{
2393 GetNext(); 2441 GetNext();
2394 if (!(chunk=="") && !ErrorFound) Third(); 2442 if (!(chunk=="") && !ErrorFound) Third();
2395 else ErrorFound = true; 2443 else ErrorFound = true;
2396}; 2444};
2397 2445
2398void Expression::Third() 2446void Expression::Third()
2399{ 2447{
2400 QChar sign, secS='\0'; 2448 QChar sign, secS='\0';
2401 Fourth(); 2449 Fourth();
2402 sign = chunk0(); 2450 sign = chunk0();
2403 if((int)chunk.length()>1) secS=chunk[1]; 2451 if((int)chunk.length()>1) secS=chunk[1];
2404 while( sign == '+' || sign == '-'|| 2452 while( sign == '+' || sign == '-'||
2405 sign == '<' || sign == '>'|| sign == '%'|| 2453 sign == '<' || sign == '>'|| sign == '%'||
2406 sign == '&' || sign == '|' || sign == '!' || sign == '=' 2454 sign == '&' || sign == '|' || sign == '!' || sign == '='
2407 ) 2455 )
2408 { 2456 {
2409 GetNext(); 2457 GetNext();
2410 Fourth(); 2458 Fourth();
2411 QString name; 2459 QString name;
2412 if( sign == '+' ) name= "+" ; 2460 if( sign == '+' ) name= "+" ;
2413 else if(sign=='-') name= "-" ; 2461 else if(sign=='-') name= "-" ;
2414 else if(sign=='>' && secS=='\0') name= ">" ; 2462 else if(sign=='>' && secS=='\0') name= ">" ;
2415 else if(sign=='<' && secS=='\0') name= "<" ; 2463 else if(sign=='<' && secS=='\0') name= "<" ;
2416 else if(sign=='=' && secS=='=') name= "==" ; 2464 else if(sign=='=' && secS=='=') name= "==" ;
2417 else if(sign=='!' && secS=='=') name= "!=" ; 2465 else if(sign=='!' && secS=='=') name= "!=" ;
2418 else if(sign=='>' && secS=='=') name= ">=" ; 2466 else if(sign=='>' && secS=='=') name= ">=" ;
2419 else if(sign=='<' && secS=='=') name= "<=" ; 2467 else if(sign=='<' && secS=='=') name= "<=" ;
2420 else if(sign=='&' && secS=='&') name= "AND" ; 2468 else if(sign=='&' && secS=='&') name= "AND" ;
2421 else if(sign=='|' && secS=='|') name= "OR" ; 2469 else if(sign=='|' && secS=='|') name= "OR" ;
2422 else if(sign=='%') name= "MOD" ; 2470 else if(sign=='%') name= "MOD" ;
2423 CompiledBody.append(new QString(name)); // not sure if pushed in the back. 2471 CompiledBody.append(new QString(name)); // not sure if pushed in the back.
2424 CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); //2 argument functions 2472 CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); //2 argument functions
2425 sign = chunk0(); 2473 sign = chunk0();
2426 } 2474 }
2427}; 2475};
2428 2476
2429void Expression::Fourth() 2477void Expression::Fourth()
2430{ 2478{
2431 QChar sign; 2479 QChar sign;
2432 Fifth(); 2480 Fifth();
2433 sign = chunk0(); 2481 sign = chunk0();
2434 while( sign == '*' || sign == '/' ) 2482 while( sign == '*' || sign == '/' )
2435 { 2483 {
2436 GetNext(); 2484 GetNext();
2437 Fifth(); 2485 Fifth();
2438 QString name; 2486 QString name;
2439 if( sign == '*' ) name= "*" ; 2487 if( sign == '*' ) name= "*" ;
2440 else name= "/" ; 2488 else name= "/" ;
2441 CompiledBody.append(new QString(name)); 2489 CompiledBody.append(new QString(name));
2442 CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); //2 arguments functions 2490 CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); //2 arguments functions
2443 sign = chunk0(); 2491 sign = chunk0();
2444 } 2492 }
2445}; 2493};
2446 2494
2447void Expression::Fifth() 2495void Expression::Fifth()
2448{ 2496{
2449 Sixth(); 2497 Sixth();
2450 //if(chunk.Length==0) return; 2498 //if(chunk.Length==0) return;
2451 if( chunk0() == '^' ) 2499 if( chunk0() == '^' )
2452 { 2500 {
2453 GetNext(); 2501 GetNext();
2454 Fifth(); 2502 Fifth();
2455 CompiledBody.append(new QString("POWER")); 2503 CompiledBody.append(new QString("POWER"));
2456 CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); // 2 argument functions 2504 CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); // 2 argument functions
2457 } 2505 }
2458}; 2506};
2459 2507
2460void Expression::Sixth() 2508void Expression::Sixth()
2461{ 2509{
2462 char sign; 2510 char sign;
2463 sign = ' '; 2511 sign = ' ';
2464 if(SymbGroup== SYMBOL_TOKEN && 2512 if(SymbGroup== SYMBOL_TOKEN &&
2465 chunk0() == '+' || chunk0() == '-' | chunk0() == '!') 2513 chunk0() == '+' || chunk0() == '-' | chunk0() == '!')
2466 { 2514 {
2467 sign = chunk0(); 2515 sign = chunk0();
2468 GetNext(); 2516 GetNext();
2469 } 2517 }
2470 Seventh(); 2518 Seventh();
2471 if( sign == '-' ) 2519 if( sign == '-' )
2472 { 2520 {
2473 CompiledBody.append(new QString("CHGSGN")); // unary minus 2521 CompiledBody.append(new QString("CHGSGN")); // unary minus
2474 CompiledBodyType.append(new int(FUNCTION_TOKEN | 1<<8)); //1 argument 2522 CompiledBodyType.append(new int(FUNCTION_TOKEN | 1<<8)); //1 argument
2475 } 2523 }
2476 if( sign == '!' ) 2524 if( sign == '!' )
2477 { 2525 {
2478 CompiledBody.append(new QString("NOT")); // unary minus 2526 CompiledBody.append(new QString("NOT")); // unary minus
2479 CompiledBodyType.append(new int(FUNCTION_TOKEN | 1<<8)); //1 argument 2527 CompiledBodyType.append(new int(FUNCTION_TOKEN | 1<<8)); //1 argument
2480 } 2528 }
2481}; 2529};
2482 2530
@@ -2484,82 +2532,82 @@ void Expression::Sixth()
2484void Expression::Seventh() 2532void Expression::Seventh()
2485{ 2533{
2486 if( chunk0() == '(' && SymbGroup==SYMBOL_TOKEN) 2534 if( chunk0() == '(' && SymbGroup==SYMBOL_TOKEN)
2487 { 2535 {
2488 GetNext(); 2536 GetNext();
2489 Third(); //parse the insides until we get a ')' 2537 Third(); //parse the insides until we get a ')'
2490 if (chunk0() != ')') ErrorFound = true; 2538 if (chunk0() != ')') ErrorFound = true;
2491 GetNext(); 2539 GetNext();
2492 } 2540 }
2493 else Eighth(); 2541 else Eighth();
2494}; 2542};
2495 2543
2496void Expression::Eighth() 2544void Expression::Eighth()
2497{ 2545{
2498 if ( SymbGroup== NUMBER_TOKEN ) 2546 if ( SymbGroup== NUMBER_TOKEN )
2499 { 2547 {
2500 CompiledBody.append(new QString(chunk)); 2548 CompiledBody.append(new QString(chunk));
2501 CompiledBodyType.append(new int(NUMBER_TOKEN)); 2549 CompiledBodyType.append(new int(NUMBER_TOKEN));
2502 GetNext(); 2550 GetNext();
2503 } 2551 }
2504 else if ( SymbGroup== VARIABLE_TOKEN ) 2552 else if ( SymbGroup== VARIABLE_TOKEN )
2505 { 2553 {
2506 CompiledBody.append(new QString(chunk)); 2554 CompiledBody.append(new QString(chunk));
2507 CompiledBodyType.append(new int(VARIABLE_TOKEN)); 2555 CompiledBodyType.append(new int(VARIABLE_TOKEN));
2508 GetNext(); 2556 GetNext();
2509 } 2557 }
2510 else if (SymbGroup== STRING_TOKEN ) 2558 else if (SymbGroup== STRING_TOKEN )
2511 { 2559 {
2512 CompiledBody.append(new QString(chunk+QString("\""))); 2560 CompiledBody.append(new QString(chunk+QString("\"")));
2513 CompiledBodyType.append(new int(STRING_TOKEN)); 2561 CompiledBodyType.append(new int(STRING_TOKEN));
2514 GetNext(); 2562 GetNext();
2515 } 2563 }
2516 else Ninth(); 2564 else Ninth();
2517}; 2565};
2518 2566
2519void Expression::Ninth() 2567void Expression::Ninth()
2520{ 2568{
2521 if ( SymbGroup== FUNCTION_TOKEN ) 2569 if ( SymbGroup== FUNCTION_TOKEN )
2522 { 2570 {
2523 QString TempFunk = chunk ; 2571 QString TempFunk = chunk ;
2524 GetNext(); 2572 GetNext();
2525 if(chunk0() == '(' ) 2573 if(chunk0() == '(' )
2526 { 2574 {
2527 FuncDepth++; 2575 FuncDepth++;
2528 ArgsOfFunc.resize(FuncDepth+1); 2576 ArgsOfFunc.resize(FuncDepth+1);
2529 ArgsOfFunc[FuncDepth]=1; 2577 ArgsOfFunc[FuncDepth]=1;
2530 //ArgsOfFunc=1; 2578 //ArgsOfFunc=1;
2531 GetNext(); 2579 GetNext();
2532 Third(); 2580 Third();
2533 while(chunk0()==',') //function arguments separator 2581 while(chunk0()==',') //function arguments separator
2534 { 2582 {
2535 //ArgsOfFunc++; 2583 //ArgsOfFunc++;
2536 ArgsOfFunc[FuncDepth]++; 2584 ArgsOfFunc[FuncDepth]++;
2537 GetNext(); 2585 GetNext();
2538 Third(); 2586 Third();
2539 }; 2587 };
2540 if (chunk0() != ')') ErrorFound = true; 2588 if (chunk0() != ')') ErrorFound = true;
2541 2589
2542 CompiledBody.append(new QString(TempFunk)); 2590 CompiledBody.append(new QString(TempFunk));
2543 if (TempFunk=="PI") ArgsOfFunc[FuncDepth]=0; 2591 if (TempFunk=="PI") ArgsOfFunc[FuncDepth]=0;
2544 // couldn't find a better way to parse function PI() with 0 args. :) 2592 // couldn't find a better way to parse function PI() with 0 args. :)
2545 CompiledBodyType.append(new int(FUNCTION_TOKEN | (ArgsOfFunc[FuncDepth]<<8) )); 2593 CompiledBodyType.append(new int(FUNCTION_TOKEN | (ArgsOfFunc[FuncDepth]<<8) ));
2546 //the mask &FF00 gives the arguments of the functions passed. 2594 //the mask &FF00 gives the arguments of the functions passed.
2547 FuncDepth--; 2595 FuncDepth--;
2548 ArgsOfFunc.resize(FuncDepth+1); 2596 ArgsOfFunc.resize(FuncDepth+1);
2549 GetNext(); 2597 GetNext();
2550 } 2598 }
2551 } 2599 }
2552 else 2600 else
2553 ErrorFound = true; 2601 ErrorFound = true;
2554}; 2602};
2555 2603
2556bool Expression::Parse() 2604bool Expression::Parse()
2557{ 2605{
2558 CompiledBody.clear(); 2606 CompiledBody.clear();
2559 ErrorFound = false; 2607 ErrorFound = false;
2560 n = 0;ArgsOfFunc.resize(0);FuncDepth=0; 2608 n = 0;ArgsOfFunc.resize(0);FuncDepth=0;
2561 InExpr=Body; 2609 InExpr=Body;
2562 First(); 2610 First();
2563 return(!ErrorFound); 2611 return(!ErrorFound);
2564}; 2612};
2565 2613
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,10 +1,29 @@
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/*
@@ -16,4 +35,5 @@
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>
@@ -21,16 +41,16 @@
21typedef struct typeCellBorders 41typedef struct typeCellBorders
22{ 42{
23 QPen right, bottom; 43 QPen right, bottom;
24}; 44};
25 45
26typedef struct typeCellData 46typedef 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
@@ -46,34 +66,34 @@ class Expression
46{ 66{
47public: 67public:
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};
@@ -83,81 +103,81 @@ public:
83class Sheet: public QTable 103class 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 &parameters, int NumOfParams); 123 QString calculateFunction(const QString &func, const QString &parameters, int NumOfParams);
104 QString getParameter(const QString &parameters, int paramNo, bool giveError=FALSE, const QString funcName=""); 124 QString getParameter(const QString &parameters, 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 &param1, const QString &param2, const QString &param3); 132 double functionCountIf(const QString &param1, const QString &param2, const QString &param3);
113 double functionSumSQ(const QString &param1, const QString &param2); //sum of squares 133 double functionSumSQ(const QString &param1, const QString &param2); //sum of squares
114 QString functionIndex(const QString &param1, const QString &param2, int indx); 134 QString functionIndex(const QString &param1, const QString &param2, 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 &param1, const QString &param2); 159 double functionVariance(const QString &param1, const QString &param2);
140 double functionVariancePopulation(const QString &param1, const QString &param2); 160 double functionVariancePopulation(const QString &param1, const QString &param2);
141 double functionSkew(const QString &param1, const QString &param2); 161 double functionSkew(const QString &param1, const QString &param2);
142 double functionKurt(const QString &param1, const QString &param2); 162 double functionKurt(const QString &param1, const QString &param2);
143 163
144 // Sheet/Qt parser functions 164 // Sheet/Qt parser functions
145 double functionSum(const QString &param1, const QString &param2); 165 double functionSum(const QString &param1, const QString &param2);
146 double functionAvg(const QString &param1, const QString &param2); 166 double functionAvg(const QString &param1, const QString &param2);
147 double functionMax(const QString &param1, const QString &param2); 167 double functionMax(const QString &param1, const QString &param2);
148 double functionMin(const QString &param1, const QString &param2); 168 double functionMin(const QString &param1, const QString &param2);
149 double functionCount(const QString &param1, const QString &param2); 169 double functionCount(const QString &param1, const QString &param2);
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: 177public 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: 181public:
162 Sheet(int numRows, int numCols, QWidget *parent); 182 Sheet(int numRows, int numCols, QWidget *parent);
163 ~Sheet(); 183 ~Sheet();
@@ -196,5 +216,5 @@ class Sheet: public QTable
196 static QString getHeaderString(int section); 216 static QString getHeaderString(int section);
197 217
198 public slots: 218public slots:
199 void editCut(); 219 void editCut();
200 void editCopy(); 220 void editCopy();
@@ -203,5 +223,5 @@ class Sheet: public QTable
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: 225signals:
206 void currentDataChanged(const QString &data); 226 void currentDataChanged(const QString &data);
207 void cellClicked(const QString &cell); 227 void cellClicked(const QString &cell);
diff --git a/noncore/apps/opie-sheet/sortdlg.cpp b/noncore/apps/opie-sheet/sortdlg.cpp
index c2cdec8..47d666f 100644
--- a/noncore/apps/opie-sheet/sortdlg.cpp
+++ b/noncore/apps/opie-sheet/sortdlg.cpp
@@ -1,10 +1,29 @@
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/*
@@ -13,168 +32,169 @@
13 */ 32 */
14 33
34#include "sortdlg.h"
35
36/* QT */
15#include <qlabel.h> 37#include <qlabel.h>
16#include <qradiobutton.h> 38#include <qradiobutton.h>
17#include <qmessagebox.h> 39#include <qmessagebox.h>
18#include "sortdlg.h"
19 40
20SortDialog::SortDialog(QWidget *parent) 41SortDialog::SortDialog(QWidget *parent)
21 :QDialog(parent, 0, TRUE) 42 :QDialog(parent, 0, TRUE)
22{ 43{
23 // Main widget 44 // Main widget
24 tabs=new QTabWidget(this); 45 tabs=new QTabWidget(this);
25 widgetSort=new QWidget(tabs); 46 widgetSort=new QWidget(tabs);
26 widgetOptions=new QWidget(tabs); 47 widgetOptions=new QWidget(tabs);
27 tabs->addTab(widgetSort, tr("&Sort")); 48 tabs->addTab(widgetSort, tr("&Sort"));
28 tabs->addTab(widgetOptions, tr("&Options")); 49 tabs->addTab(widgetOptions, tr("&Options"));
29 50
30 // Sort tab 51 // Sort tab
31 comboFieldA=createFieldCombo(tr("&Sort by"), 10); 52 comboFieldA=createFieldCombo(tr("&Sort by"), 10);
32 groupOrderA=createOrderButtons(10); 53 groupOrderA=createOrderButtons(10);
33 comboFieldB=createFieldCombo(tr("&Then by"), 90); 54 comboFieldB=createFieldCombo(tr("&Then by"), 90);
34 groupOrderB=createOrderButtons(90); 55 groupOrderB=createOrderButtons(90);
35 comboFieldC=createFieldCombo(tr("Then &by"), 170); 56 comboFieldC=createFieldCombo(tr("Then &by"), 170);
36 groupOrderC=createOrderButtons(170); 57 groupOrderC=createOrderButtons(170);
37 58
38 // Options tab 59 // Options tab
39 checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions); 60 checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions);
40 checkCase->setGeometry(10, 10, 215, 20); 61 checkCase->setGeometry(10, 10, 215, 20);
41 checkCase->setChecked(TRUE); 62 checkCase->setChecked(TRUE);
42 63
43 groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions); 64 groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions);
44 groupDirection->setGeometry(10, 40, 215, 70); 65 groupDirection->setGeometry(10, 40, 215, 70);
45 QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection); 66 QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection);
46 radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection); 67 radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection);
47 groupDirection->setButton(0); 68 groupDirection->setButton(0);
48 connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int))); 69 connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int)));
49 70
50 // Main widget 71 // Main widget
51 box=new QVBoxLayout(this); 72 box=new QVBoxLayout(this);
52 box->addWidget(tabs); 73 box->addWidget(tabs);
53 74
54 setCaption(tr("Sort")); 75 setCaption(tr("Sort"));
55} 76}
56 77
57SortDialog::~SortDialog() 78SortDialog::~SortDialog()
58{ 79{}
59}
60 80
61QComboBox *SortDialog::createFieldCombo(const QString &caption, int y) 81QComboBox *SortDialog::createFieldCombo(const QString &caption, int y)
62{ 82{
63 QLabel *label=new QLabel(caption, widgetSort); 83 QLabel *label=new QLabel(caption, widgetSort);
64 label->setGeometry(10, y+5, 215, 20); 84 label->setGeometry(10, y+5, 215, 20);
65 QComboBox *combo=new QComboBox(FALSE, widgetSort); 85 QComboBox *combo=new QComboBox(FALSE, widgetSort);
66 combo->setGeometry(10, y+35, 105, 20); 86 combo->setGeometry(10, y+35, 105, 20);
67 label->setBuddy(combo); 87 label->setBuddy(combo);
68 return combo; 88 return combo;
69} 89}
70 90
71QVButtonGroup *SortDialog::createOrderButtons(int y) 91QVButtonGroup *SortDialog::createOrderButtons(int y)
72{ 92{
73 QVButtonGroup *group=new QVButtonGroup(widgetSort); 93 QVButtonGroup *group=new QVButtonGroup(widgetSort);
74 group->setGeometry(125, y, 100, 60); 94 group->setGeometry(125, y, 100, 60);
75 QRadioButton *radio=new QRadioButton(tr("&Ascending"), group); 95 QRadioButton *radio=new QRadioButton(tr("&Ascending"), group);
76 radio=new QRadioButton(tr("&Descending"), group); 96 radio=new QRadioButton(tr("&Descending"), group);
77 group->setButton(0); 97 group->setButton(0);
78 return group; 98 return group;
79} 99}
80 100
81void SortDialog::directionChanged(int id) 101void SortDialog::directionChanged(int id)
82{ 102{
83 direction=id; 103 direction=id;
84 fillFieldCombo(comboFieldA); 104 fillFieldCombo(comboFieldA);
85 fillFieldCombo(comboFieldB); 105 fillFieldCombo(comboFieldB);
86 fillFieldCombo(comboFieldC); 106 fillFieldCombo(comboFieldC);
87} 107}
88 108
89void SortDialog::fillFieldCombo(QComboBox *combo) 109void SortDialog::fillFieldCombo(QComboBox *combo)
90{ 110{
91 combo->clear(); 111 combo->clear();
92 if (direction) 112 if (direction)
93 for (int row=row1; row<=row2; ++row) 113 for (int row=row1; row<=row2; ++row)
94 combo->insertItem("Row "+QString::number(row+1)); 114 combo->insertItem("Row "+QString::number(row+1));
95 else 115 else
96 for (int col=col1; col<=col2; ++col) 116 for (int col=col1; col<=col2; ++col)
97 combo->insertItem("Column "+Sheet::getHeaderString(col+1)); 117 combo->insertItem("Column "+Sheet::getHeaderString(col+1));
98} 118}
99 119
100int SortDialog::exec(Sheet *s) 120int SortDialog::exec(Sheet *s)
101{ 121{
102 sheet=s; 122 sheet=s;
103 sheet->getSelection(&row1, &col1, &row2, &col2); 123 sheet->getSelection(&row1, &col1, &row2, &col2);
104 124
105 direction=0; 125 direction=0;
106 fillFieldCombo(comboFieldA); 126 fillFieldCombo(comboFieldA);
107 fillFieldCombo(comboFieldB); 127 fillFieldCombo(comboFieldB);
108 fillFieldCombo(comboFieldC); 128 fillFieldCombo(comboFieldC);
109 129
110 if (row1==row2 && col1==col2) 130 if (row1==row2 && col1==col2)
111 {
112 QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!"));
113 return QDialog::Rejected;
114 }
115 if (QDialog::exec()==QDialog::Accepted)
116 {
117 QString field1S=comboFieldA->currentText(), field2S=comboFieldB->currentText(), field3S=comboFieldC->currentText();
118 field1S=field1S.mid(field1S.find(' ')+1);
119 field2S=field2S.mid(field2S.find(' ')+1);
120 field3S=field3S.mid(field3S.find(' ')+1);
121 int field1, field2, field3;
122 if (direction)
123 { 131 {
124 field1=field1S.toInt()-1; 132 QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!"));
125 field2=field2S.toInt()-1; 133 return QDialog::Rejected;
126 field3=field3S.toInt()-1;
127 int i, j;
128 for (i=col2; i>=col1; --i)
129 for (j=col1+1; j<=i; ++j)
130 {
131 bool swap=FALSE;
132 int compareResult=compareItems(s->item(field1, j-1), s->item(field1, j), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
133 if (compareResult>0) swap=TRUE;
134 else if (compareResult==0)
135 {
136 compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked());
137 if (compareResult>0) swap=TRUE;
138 else if (compareResult==0)
139 {
140 compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked());
141 if (compareResult>0) swap=TRUE;
142 }
143 }
144 if (swap)
145 for (int row=row1; row<=row2; ++row)
146 s->swapCells(row, j-1, row, j);
147 }
148 } 134 }
149 else 135 if (QDialog::exec()==QDialog::Accepted)
150 { 136 {
151 field1=Sheet::getHeaderColumn(field1S)-1; 137 QString field1S=comboFieldA->currentText(), field2S=comboFieldB->currentText(), field3S=comboFieldC->currentText();
152 field2=Sheet::getHeaderColumn(field2S)-1; 138 field1S=field1S.mid(field1S.find(' ')+1);
153 field3=Sheet::getHeaderColumn(field3S)-1; 139 field2S=field2S.mid(field2S.find(' ')+1);
154 int i, j; 140 field3S=field3S.mid(field3S.find(' ')+1);
155 for (i=row2; i>=row1; --i) 141 int field1, field2, field3;
156 for (j=row1+1; j<=i; ++j) 142 if (direction)
143 {
144 field1=field1S.toInt()-1;
145 field2=field2S.toInt()-1;
146 field3=field3S.toInt()-1;
147 int i, j;
148 for (i=col2; i>=col1; --i)
149 for (j=col1+1; j<=i; ++j)
150 {
151 bool swap=FALSE;
152 int compareResult=compareItems(s->item(field1, j-1), s->item(field1, j), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
153 if (compareResult>0) swap=TRUE;
154 else if (compareResult==0)
155 {
156 compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked());
157 if (compareResult>0) swap=TRUE;
158 else if (compareResult==0)
159 {
160 compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked());
161 if (compareResult>0) swap=TRUE;
162 }
163 }
164 if (swap)
165 for (int row=row1; row<=row2; ++row)
166 s->swapCells(row, j-1, row, j);
167 }
168 }
169 else
157 { 170 {
158 bool swap=FALSE; 171 field1=Sheet::getHeaderColumn(field1S)-1;
159 int compareResult=compareItems(s->item(j-1, field1), s->item(j, field1), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked()); 172 field2=Sheet::getHeaderColumn(field2S)-1;
160 if (compareResult>0) swap=TRUE; 173 field3=Sheet::getHeaderColumn(field3S)-1;
161 else if (compareResult==0) 174 int i, j;
162 { 175 for (i=row2; i>=row1; --i)
163 compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked()); 176 for (j=row1+1; j<=i; ++j)
164 if (compareResult>0) swap=TRUE; 177 {
165 else if (compareResult==0) 178 bool swap=FALSE;
166 { 179 int compareResult=compareItems(s->item(j-1, field1), s->item(j, field1), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
167 compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked()); 180 if (compareResult>0) swap=TRUE;
168 if (compareResult>0) swap=TRUE; 181 else if (compareResult==0)
169 } 182 {
170 } 183 compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked());
171 if (swap) 184 if (compareResult>0) swap=TRUE;
172 for (int col=col1; col<=col2; ++col) 185 else if (compareResult==0)
173 s->swapCells(j-1, col, j, col); 186 {
187 compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked());
188 if (compareResult>0) swap=TRUE;
189 }
190 }
191 if (swap)
192 for (int col=col1; col<=col2; ++col)
193 s->swapCells(j-1, col, j, col);
194 }
174 } 195 }
196 return QDialog::Accepted;
175 } 197 }
176 return QDialog::Accepted; 198 return QDialog::Rejected;
177 }
178 return QDialog::Rejected;
179} 199}
180 200
@@ -182,12 +202,12 @@ int SortDialog::compareItems(QTableItem *item1, QTableItem *item2,
182 int descending, bool caseSensitive) 202 int descending, bool caseSensitive)
183{ 203{
184 int result=0; 204 int result=0;
185 if (item1) 205 if (item1)
186 { 206 {
187 if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper())); 207 if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper()));
188 else result=-1; 208 else result=-1;
189 } 209 }
190 else 210 else
191 if (item2) result=1; 211 if (item2) result=1;
192 return (descending ? -result : result); 212 return (descending ? -result : result);
193} 213}
diff --git a/noncore/apps/opie-sheet/sortdlg.h b/noncore/apps/opie-sheet/sortdlg.h
index b3699a9..5a1025e 100644
--- a/noncore/apps/opie-sheet/sortdlg.h
+++ b/noncore/apps/opie-sheet/sortdlg.h
@@ -1,10 +1,29 @@
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/*
@@ -16,4 +35,7 @@
16#define SORTDLG_H 35#define SORTDLG_H
17 36
37#include "sheet.h"
38
39/* QT */
18#include <qdialog.h> 40#include <qdialog.h>
19#include <qtabwidget.h> 41#include <qtabwidget.h>
@@ -23,32 +45,31 @@
23#include <qpushbutton.h> 45#include <qpushbutton.h>
24#include <qvbuttongroup.h> 46#include <qvbuttongroup.h>
25#include "sheet.h"
26 47
27class SortDialog: public QDialog 48class SortDialog: public QDialog
28{ 49{
29 Q_OBJECT 50 Q_OBJECT
30 51
31 // QT objects 52 // QT objects
32 QBoxLayout *box; 53 QBoxLayout *box;
33 QTabWidget *tabs; 54 QTabWidget *tabs;
34 QWidget *widgetSort, *widgetOptions; 55 QWidget *widgetSort, *widgetOptions;
35 QVButtonGroup *groupOrderA, *groupOrderB, *groupOrderC, *groupDirection; 56 QVButtonGroup *groupOrderA, *groupOrderB, *groupOrderC, *groupDirection;
36 QCheckBox *checkCase; 57 QCheckBox *checkCase;
37 QComboBox *comboFieldA, *comboFieldB, *comboFieldC; 58 QComboBox *comboFieldA, *comboFieldB, *comboFieldC;
38 59
39 // Other objects & variables 60 // Other objects & variables
40 int row1, col1, row2, col2, direction; 61 int row1, col1, row2, col2, direction;
41 Sheet *sheet; 62 Sheet *sheet;
42 63
43 // Private functions 64 // Private functions
44 QVButtonGroup *createOrderButtons(int y); 65 QVButtonGroup *createOrderButtons(int y);
45 QComboBox *createFieldCombo(const QString &caption, int y); 66 QComboBox *createFieldCombo(const QString &caption, int y);
46 void fillFieldCombo(QComboBox *combo); 67 void fillFieldCombo(QComboBox *combo);
47 int compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE); 68 int compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE);
48 69
49 private slots: 70private slots:
50 void directionChanged(int id); 71 void directionChanged(int id);
51 72
52 public: 73public:
53 SortDialog(QWidget *parent=0); 74 SortDialog(QWidget *parent=0);
54 ~SortDialog(); 75 ~SortDialog();
diff --git a/noncore/apps/opie-sheet/textdlg.cpp b/noncore/apps/opie-sheet/textdlg.cpp
index 34cec29..020b9ae 100644
--- a/noncore/apps/opie-sheet/textdlg.cpp
+++ b/noncore/apps/opie-sheet/textdlg.cpp
@@ -1,10 +1,29 @@
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/*
@@ -16,32 +35,31 @@
16 35
17TextDialog::TextDialog(QWidget *parent) 36TextDialog::TextDialog(QWidget *parent)
18 :QDialog(parent, 0, TRUE) 37 :QDialog(parent, 0, TRUE)
19{ 38{
20 edit=new QLineEdit(this); 39 edit=new QLineEdit(this);
21 edit->setGeometry(90, 10, 100, 25); 40 edit->setGeometry(90, 10, 100, 25);
22 41
23 label=new QLabel(this); 42 label=new QLabel(this);
24 label->setGeometry(10, 10, 70, 25); 43 label->setGeometry(10, 10, 70, 25);
25 label->setBuddy(edit); 44 label->setBuddy(edit);
26 45
27 resize(200, 45); 46 resize(200, 45);
28} 47}
29 48
30TextDialog::~TextDialog() 49TextDialog::~TextDialog()
31{ 50{}
32}
33 51
34int TextDialog::exec(const QString &caption, const QString &text, 52int TextDialog::exec(const QString &caption, const QString &text,
35 const QString &value) 53 const QString &value)
36{ 54{
37 setCaption(caption); 55 setCaption(caption);
38 label->setText(text); 56 label->setText(text);
39 edit->setText(value); 57 edit->setText(value);
40 58
41 return QDialog::exec(); 59 return QDialog::exec();
42} 60}
43 61
44QString TextDialog::getValue() 62QString TextDialog::getValue()
45{ 63{
46 return edit->text(); 64 return edit->text();
47} 65}
diff --git a/noncore/apps/opie-sheet/textdlg.h b/noncore/apps/opie-sheet/textdlg.h
index 78ef580..d54da16 100644
--- a/noncore/apps/opie-sheet/textdlg.h
+++ b/noncore/apps/opie-sheet/textdlg.h
@@ -1,10 +1,29 @@
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/*
@@ -16,4 +35,5 @@
16#define TEXTDLG_H 35#define TEXTDLG_H
17 36
37/* QT */
18#include <qdialog.h> 38#include <qdialog.h>
19#include <qlabel.h> 39#include <qlabel.h>
@@ -22,11 +42,11 @@
22class TextDialog: public QDialog 42class TextDialog: public QDialog
23{ 43{
24 Q_OBJECT 44 Q_OBJECT
25 45
26 // QT objects 46 // QT objects
27 QLabel *label; 47 QLabel *label;
28 QLineEdit *edit; 48 QLineEdit *edit;
29 49
30 public: 50public:
31 TextDialog(QWidget *parent=0); 51 TextDialog(QWidget *parent=0);
32 ~TextDialog(); 52 ~TextDialog();