author | hayzel <hayzel> | 2004-01-08 12:12:30 (UTC) |
---|---|---|
committer | hayzel <hayzel> | 2004-01-08 12:12:30 (UTC) |
commit | 3cb4363abdb17d2898b4792390672375ffcd2493 (patch) (unidiff) | |
tree | a4debe153e781bb76a87b42362215800c81704d4 | |
parent | b25818faa882c1eb040f74e485cd981b94871a61 (diff) | |
download | opie-3cb4363abdb17d2898b4792390672375ffcd2493.zip opie-3cb4363abdb17d2898b4792390672375ffcd2493.tar.gz opie-3cb4363abdb17d2898b4792390672375ffcd2493.tar.bz2 |
*** empty log message ***
-rw-r--r-- | noncore/apps/opie-sheet/ChangeLog | 4 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 10 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/sheet.h | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/noncore/apps/opie-sheet/ChangeLog b/noncore/apps/opie-sheet/ChangeLog index 56887c5..e8a31ee 100644 --- a/noncore/apps/opie-sheet/ChangeLog +++ b/noncore/apps/opie-sheet/ChangeLog | |||
@@ -1,24 +1,28 @@ | |||
1 | January 8, 2004 | ||
2 | - fixed issue : "-if someone enters directly text as parameter to a string function the text renders as uppercase due to the calculation engine that uppercases all the parsing sentence." | ||
3 | now the text is handled correctly. | ||
4 | |||
1 | January 7, 2004 | 5 | January 7, 2004 |
2 | * Release by hayzel (koppermind@panafonet.gr) | 6 | * Release by hayzel (koppermind@panafonet.gr) |
3 | This version has many valuable changes, though It may have some annoying bugs. Please if you are interested in opie-sheet try it hard, so I can fix some of them. Also If you want some other functions that must be here and are missing feel free to ask them. (no financial functions please. :) I really hate them ) | 7 | This version has many valuable changes, though It may have some annoying bugs. Please if you are interested in opie-sheet try it hard, so I can fix some of them. Also If you want some other functions that must be here and are missing feel free to ask them. (no financial functions please. :) I really hate them ) |
4 | -Fixed a bug with non closed parenthesis editing&recalculation infinite loop. | 8 | -Fixed a bug with non closed parenthesis editing&recalculation infinite loop. |
5 | -Added support for functions that can parse parameters not ONLY as numbers but also as strings. | 9 | -Added support for functions that can parse parameters not ONLY as numbers but also as strings. |
6 | -Added many functions that cover many computational topics rendering opie-sheet a computational tool-spreadsheet at last. (total 90 functions!) | 10 | -Added many functions that cover many computational topics rendering opie-sheet a computational tool-spreadsheet at last. (total 90 functions!) |
7 | -Maintained compatibility with the opie-fileformat. | 11 | -Maintained compatibility with the opie-fileformat. |
8 | -New icons. | 12 | -New icons. |
9 | -Found that the DataParser was not a real RPN compiler of the expressions. In fact it was returning faulty results in calculations, in both binary or unary operations. A1-A2-A3 was parsed as A1-(A2-A3). -A1 was parsed as A1. | 13 | -Found that the DataParser was not a real RPN compiler of the expressions. In fact it was returning faulty results in calculations, in both binary or unary operations. A1-A2-A3 was parsed as A1-(A2-A3). -A1 was parsed as A1. |
10 | -Added new class "Expression" a general Parser for spreadsheet-expression. Imported from an old C# project of mine. | 14 | -Added new class "Expression" a general Parser for spreadsheet-expression. Imported from an old C# project of mine. |
11 | -Now can also parse <>=!%&^|"" in expressions. | 15 | -Now can also parse <>=!%&^|"" in expressions. |
12 | -Added experimental Excel File format import!. The opie-sheet can import any excel file in BIFF7/BIFF8 format. These formats are used in Excel XP,2000,95. The Excel Importer class is in a good coding level.. BUT it is not complete. Only strings,numbers,formulas are imported. Not formatting rules. Not all the functions are converted in the functions of opie-sheet. Infact FEW functions are converted. | 16 | -Added experimental Excel File format import!. The opie-sheet can import any excel file in BIFF7/BIFF8 format. These formats are used in Excel XP,2000,95. The Excel Importer class is in a good coding level.. BUT it is not complete. Only strings,numbers,formulas are imported. Not formatting rules. Not all the functions are converted in the functions of opie-sheet. Infact FEW functions are converted. |
13 | -Fixed a bug with Sheet Recalculation. Added ReCalc() function. Opie-sheet was calculating wrong the values of expression in opening/importing. if a value needed was not loaded yet in the time of calculation. Solved with ReCalc() each time the active sheet is changing. | 17 | -Fixed a bug with Sheet Recalculation. Added ReCalc() function. Opie-sheet was calculating wrong the values of expression in opening/importing. if a value needed was not loaded yet in the time of calculation. Solved with ReCalc() each time the active sheet is changing. |
14 | 18 | ||
15 | 19 | ||
16 | *known issues: | 20 | *known issues: |
17 | -if someone enters directly text as parameter to a string function the text renders as uppercase due to the calculation engine that uppercases all the parsing sentence. | 21 | -if someone enters directly text as parameter to a string function the text renders as uppercase due to the calculation engine that uppercases all the parsing sentence. |
18 | -randbetween return only integer part random... if both limit numbers are integers. | 22 | -randbetween return only integer part random... if both limit numbers are integers. |
19 | -skew and kurt function give different results compared to kspread-oofice equivalents. | 23 | -skew and kurt function give different results compared to kspread-oofice equivalents. |
20 | -unstable parser Excel Class | 24 | -unstable parser Excel Class |
21 | -string vars and string functions are not correctly handled by excel importer. | 25 | -string vars and string functions are not correctly handled by excel importer. |
22 | -unicode strings are converted FINE in QString unicode format, but cannot be rendered fine if a suitable unicode font is not setuped as the default string. So the string is junked in the opie-sheet and may crash the parser. | 26 | -unicode strings are converted FINE in QString unicode format, but cannot be rendered fine if a suitable unicode font is not setuped as the default string. So the string is junked in the opie-sheet and may crash the parser. |
23 | 27 | ||
24 | *TODOs: | 28 | *TODOs: |
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index 103b83b..e1e4744 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp | |||
@@ -888,57 +888,59 @@ double Sheet::functionCount(const QString ¶m1, const QString ¶m2) | |||
888 | return(ii); | 888 | return(ii); |
889 | }; | 889 | }; |
890 | return 0; | 890 | return 0; |
891 | } | 891 | } |
892 | 892 | ||
893 | double Sheet::functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3) | 893 | double Sheet::functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3) |
894 | { | 894 | { |
895 | int row1, col1, row2, col2, row, col; | 895 | int row1, col1, row2, col2, row, col; |
896 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 896 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
897 | //same as count except check if each field is equal to param3 | 897 | //same as count except check if each field is equal to param3 |
898 | int divider=0; | 898 | int divider=0; |
899 | QString s2; | 899 | QString s2; |
900 | bool ok; | 900 | bool ok; |
901 | s2=calculateVariable(param3); | 901 | s2=calculateVariable(param3); |
902 | for (row=row1; row<=row2; ++row) | 902 | for (row=row1; row<=row2; ++row) |
903 | for (col=col1; col<=col2; ++col) | 903 | for (col=col1; col<=col2; ++col) |
904 | { | 904 | { |
905 | text(row, col).toDouble(&ok); | 905 | text(row, col).toDouble(&ok); |
906 | if (ok && (s2==text(row,col)) ) ++divider; | 906 | if (ok && (s2==text(row,col)) ) ++divider; |
907 | } | 907 | } |
908 | return divider; | 908 | return divider; |
909 | } | 909 | } |
910 | 910 | ||
911 | 911 | ||
912 | QString Sheet::calculateFunction(const QString &function, const QString ¶meters, int NumOfParams) | 912 | QString Sheet::calculateFunction(const QString &func, const QString ¶meters, int NumOfParams) |
913 | { | 913 | { |
914 | bool ok; | 914 | bool ok; |
915 | double val1=0.0,val2=0.0,val3=0.0; | 915 | double val1=0.0,val2=0.0,val3=0.0; |
916 | long int vali=0; | 916 | long int vali=0; |
917 | int w1,w2; | 917 | int w1,w2; |
918 | int row,col; | 918 | int row,col; |
919 | QString s1,s2; | 919 | QString s1,s2; |
920 | //basic functions | 920 | //basic functions |
921 | QString function; | ||
922 | function=func.upper(); | ||
921 | if (function=="+") | 923 | if (function=="+") |
922 | { | 924 | { |
923 | s1=calculateVariable(getParameter(parameters, 0)); | 925 | s1=calculateVariable(getParameter(parameters, 0)); |
924 | s2=calculateVariable(getParameter(parameters, 1)); | 926 | s2=calculateVariable(getParameter(parameters, 1)); |
925 | val1=s1.toDouble(&ok)+s2.toDouble(&ok); | 927 | val1=s1.toDouble(&ok)+s2.toDouble(&ok); |
926 | return QString::number(val1); | 928 | return QString::number(val1); |
927 | 929 | ||
928 | }; | 930 | }; |
929 | if (function=="-") | 931 | if (function=="-") |
930 | { | 932 | { |
931 | s1=calculateVariable(getParameter(parameters, 0)); | 933 | s1=calculateVariable(getParameter(parameters, 0)); |
932 | s2=calculateVariable(getParameter(parameters, 1)); | 934 | s2=calculateVariable(getParameter(parameters, 1)); |
933 | val1=s1.toDouble(&ok)-s2.toDouble(&ok); | 935 | val1=s1.toDouble(&ok)-s2.toDouble(&ok); |
934 | return QString::number(val1); | 936 | return QString::number(val1); |
935 | }; | 937 | }; |
936 | if (function=="*") | 938 | if (function=="*") |
937 | { | 939 | { |
938 | val1=calculateVariable( | 940 | val1=calculateVariable( |
939 | getParameter(parameters, 0)).toDouble(&ok) | 941 | getParameter(parameters, 0)).toDouble(&ok) |
940 | *calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 942 | *calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
941 | return QString::number(val1); | 943 | return QString::number(val1); |
942 | }; | 944 | }; |
943 | if (function=="/") | 945 | if (function=="/") |
944 | { | 946 | { |
@@ -1756,97 +1758,97 @@ QString Sheet::calculateFunction(const QString &function, const QString ¶met | |||
1756 | QString Sheet::dataParserHelper(const QString &data) | 1758 | QString Sheet::dataParserHelper(const QString &data) |
1757 | { | 1759 | { |
1758 | if(data.left(1)=="""" && data.right(1)=="""") return QString(data); | 1760 | if(data.left(1)=="""" && data.right(1)=="""") return QString(data); |
1759 | Expression exp1(data); | 1761 | Expression exp1(data); |
1760 | exp1.Parse(); | 1762 | exp1.Parse(); |
1761 | QStack<QString> stack1; | 1763 | QStack<QString> stack1; |
1762 | stack1.setAutoDelete(TRUE); | 1764 | stack1.setAutoDelete(TRUE); |
1763 | int i=0; | 1765 | int i=0; |
1764 | QString* s1; | 1766 | QString* s1; |
1765 | QString* s2=NULL; | 1767 | QString* s2=NULL; |
1766 | int* i1; | 1768 | int* i1; |
1767 | int args,tokentype; | 1769 | int args,tokentype; |
1768 | QString tempval; | 1770 | QString tempval; |
1769 | s1=exp1.CompiledBody.first();i1=exp1.CompiledBodyType.first(); | 1771 | s1=exp1.CompiledBody.first();i1=exp1.CompiledBodyType.first(); |
1770 | while(i<=(int)exp1.CompiledBody.count()-1) | 1772 | while(i<=(int)exp1.CompiledBody.count()-1) |
1771 | { | 1773 | { |
1772 | args= ((*i1) & 0xFF00)>>8; tokentype=(*i1) & 0x00FF; | 1774 | args= ((*i1) & 0xFF00)>>8; tokentype=(*i1) & 0x00FF; |
1773 | if(tokentype==NUMBER_TOKEN) | 1775 | if(tokentype==NUMBER_TOKEN) |
1774 | { | 1776 | { |
1775 | stack1.push(new QString(*s1)); | 1777 | stack1.push(new QString(*s1)); |
1776 | //printf("Parse:Number=%s\r\n",s1->latin1()); | 1778 | //printf("Parse:Number=%s\r\n",s1->latin1()); |
1777 | } | 1779 | } |
1778 | else if(tokentype==VARIABLE_TOKEN) | 1780 | else if(tokentype==VARIABLE_TOKEN) |
1779 | { | 1781 | { |
1780 | stack1.push(new QString(*s1)); | 1782 | stack1.push(new QString(QString(*s1).upper())); |
1781 | //printf("Parse:Var=%s\r\n",s1->latin1()); | 1783 | //printf("Parse:Var=%s\r\n",s1->latin1()); |
1782 | //here to put implementation of other types of variables except cell. | 1784 | //here to put implementation of other types of variables except cell. |
1783 | //for example names | 1785 | //for example names |
1784 | } | 1786 | } |
1785 | else if(tokentype==STRING_TOKEN) | 1787 | else if(tokentype==STRING_TOKEN) |
1786 | { | 1788 | { |
1787 | stack1.push(new QString(*s1)); | 1789 | stack1.push(new QString(*s1)); |
1788 | //printf("Parse:String=%s\r\n",s1->ascii()); | 1790 | //printf("Parse:String=%s\r\n",s1->ascii()); |
1789 | } | 1791 | } |
1790 | else if(tokentype==FUNCTION_TOKEN) | 1792 | else if(tokentype==FUNCTION_TOKEN) |
1791 | { | 1793 | { |
1792 | QString params=""; | 1794 | QString params=""; |
1793 | for(int w1=1;w1<=args;w1++) | 1795 | for(int w1=1;w1<=args;w1++) |
1794 | { | 1796 | { |
1795 | if((int)stack1.count()!=0) s2=stack1.pop(); | 1797 | if((int)stack1.count()!=0) s2=stack1.pop(); |
1796 | params=*s2+params;//args in reverse order | 1798 | params=*s2+params;//args in reverse order |
1797 | params=","+params; | 1799 | params=","+params; |
1798 | }; | 1800 | }; |
1799 | params=params.mid(1); | 1801 | params=params.mid(1); |
1800 | if(params==NULL) params="0"; | 1802 | if(params==NULL) params="0"; |
1801 | //printf("Parse:Func=%s, params=%s, stackcount=%d,args=%d\r\n" | 1803 | //printf("Parse:Func=%s, params=%s, stackcount=%d,args=%d\r\n" |
1802 | //,s1->latin1(),params.latin1(),stack1.count(),args); | 1804 | //,s1->latin1(),params.latin1(),stack1.count(),args); |
1803 | tempval=calculateFunction(*s1,params,args); | 1805 | tempval=calculateFunction(*s1,params,args); |
1804 | tempval=tempval.upper(); | 1806 | tempval=tempval; |
1805 | stack1.push(new QString(tempval)); | 1807 | stack1.push(new QString(tempval)); |
1806 | }; | 1808 | }; |
1807 | 1809 | ||
1808 | //loops to next token | 1810 | //loops to next token |
1809 | if(exp1.CompiledBody.next()!=NULL) s1=exp1.CompiledBody.current(); else break; | 1811 | if(exp1.CompiledBody.next()!=NULL) s1=exp1.CompiledBody.current(); else break; |
1810 | if(exp1.CompiledBodyType.next()!=NULL) i1=exp1.CompiledBodyType.current(); else break; | 1812 | if(exp1.CompiledBodyType.next()!=NULL) i1=exp1.CompiledBodyType.current(); else break; |
1811 | i++; | 1813 | i++; |
1812 | }; | 1814 | }; |
1813 | if((int)stack1.count()!=0)s2=stack1.pop(); else s2=new QString("!ERROR"); | 1815 | if((int)stack1.count()!=0)s2=stack1.pop(); else s2=new QString("!ERROR"); |
1814 | tempval=*s2; | 1816 | tempval=*s2; |
1815 | return(tempval); | 1817 | return(tempval); |
1816 | }; | 1818 | }; |
1817 | 1819 | ||
1818 | 1820 | ||
1819 | 1821 | ||
1820 | QString Sheet::dataParser(const QString &cell, const QString &data) | 1822 | QString Sheet::dataParser(const QString &cell, const QString &data) |
1821 | { | 1823 | { |
1822 | QString strippedData(data); | 1824 | QString strippedData(data); |
1823 | strippedData.replace(QRegExp("\\s"), ""); | 1825 | strippedData.replace(QRegExp("\\s"), ""); |
1824 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; | 1826 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; |
1825 | if (listDataParser.find(cell)!=listDataParser.end()) return "0"; | 1827 | if (listDataParser.find(cell)!=listDataParser.end()) return "0"; |
1826 | listDataParser.append(cell); | 1828 | listDataParser.append(cell); |
1827 | // printf("DATAPARSER: data=%s, cell=%s\r\n",data.ascii(),cell.ascii()); | 1829 | // printf("DATAPARSER: data=%s, cell=%s\r\n",data.ascii(),cell.ascii()); |
1828 | strippedData=dataParserHelper(strippedData.remove(0, 1).upper().replace(QRegExp(":"), ",")); | 1830 | strippedData=dataParserHelper(strippedData.remove(0, 1).replace(QRegExp(":"), ",")); |
1829 | 1831 | ||
1830 | int i=0; | 1832 | int i=0; |
1831 | QString tempParameter(getParameter(strippedData, i)), result=""; | 1833 | QString tempParameter(getParameter(strippedData, i)), result=""; |
1832 | do | 1834 | do |
1833 | { | 1835 | { |
1834 | result+=","+calculateVariable(tempParameter); | 1836 | result+=","+calculateVariable(tempParameter); |
1835 | tempParameter=getParameter(strippedData, ++i); | 1837 | tempParameter=getParameter(strippedData, ++i); |
1836 | } | 1838 | } |
1837 | while (!tempParameter.isNull()); | 1839 | while (!tempParameter.isNull()); |
1838 | listDataParser.remove(cell); | 1840 | listDataParser.remove(cell); |
1839 | return result.mid(1); | 1841 | return result.mid(1); |
1840 | } | 1842 | } |
1841 | 1843 | ||
1842 | 1844 | ||
1843 | void Sheet::setData(const QString &data) | 1845 | void Sheet::setData(const QString &data) |
1844 | { | 1846 | { |
1845 | setText(currentRow(), currentColumn(), data); | 1847 | setText(currentRow(), currentColumn(), data); |
1846 | slotCellChanged(currentRow(), currentColumn()); | 1848 | slotCellChanged(currentRow(), currentColumn()); |
1847 | activateNextCell(); | 1849 | activateNextCell(); |
1848 | } | 1850 | } |
1849 | 1851 | ||
1850 | QString Sheet::getData() | 1852 | QString Sheet::getData() |
1851 | { | 1853 | { |
1852 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); | 1854 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); |
diff --git a/noncore/apps/opie-sheet/sheet.h b/noncore/apps/opie-sheet/sheet.h index 41f1b86..f705cd0 100644 --- a/noncore/apps/opie-sheet/sheet.h +++ b/noncore/apps/opie-sheet/sheet.h | |||
@@ -79,49 +79,49 @@ public: | |||
79 | }; | 79 | }; |
80 | 80 | ||
81 | 81 | ||
82 | 82 | ||
83 | class Sheet: public QTable | 83 | class Sheet: public QTable |
84 | { | 84 | { |
85 | Q_OBJECT | 85 | Q_OBJECT |
86 | 86 | ||
87 | // Variables | 87 | // Variables |
88 | bool clicksLocked; | 88 | bool clicksLocked; |
89 | int selectionNo; | 89 | int selectionNo; |
90 | typeCellBorders defaultBorders; | 90 | typeCellBorders defaultBorders; |
91 | typeCellData defaultCellData; | 91 | typeCellData defaultCellData; |
92 | 92 | ||
93 | // QT objects | 93 | // QT objects |
94 | QList<typeCellData> sheetData, clipboardData; | 94 | QList<typeCellData> sheetData, clipboardData; |
95 | QString pressedCell, releasedCell, sheetName; | 95 | QString pressedCell, releasedCell, sheetName; |
96 | QStringList listDataParser; | 96 | QStringList listDataParser; |
97 | 97 | ||
98 | // Private functions | 98 | // Private functions |
99 | bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE); | 99 | bool findRowColumn(const QString &variable, int *row, int *col, bool giveError=FALSE); |
100 | QString findCellName(int row, int col); | 100 | QString findCellName(int row, int col); |
101 | bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2); | 101 | bool findRange(const QString &variable1, const QString &variable2, int *row1, int *col1, int *row2, int *col2); |
102 | QString calculateVariable(const QString &variable); | 102 | QString calculateVariable(const QString &variable); |
103 | QString calculateFunction(const QString &function, const QString ¶meters, int NumOfParams); | 103 | QString calculateFunction(const QString &func, const QString ¶meters, int NumOfParams); |
104 | QString getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName=""); | 104 | QString getParameter(const QString ¶meters, int paramNo, bool giveError=FALSE, const QString funcName=""); |
105 | QString dataParser(const QString &cell, const QString &data); | 105 | QString dataParser(const QString &cell, const QString &data); |
106 | QString dataParserHelper(const QString &data); | 106 | QString dataParserHelper(const QString &data); |
107 | typeCellData *createCellData(int row, int col); | 107 | typeCellData *createCellData(int row, int col); |
108 | typeCellData *findCellData(int row, int col); | 108 | typeCellData *findCellData(int row, int col); |
109 | 109 | ||
110 | 110 | ||
111 | //LOGICAL / INFO | 111 | //LOGICAL / INFO |
112 | double functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3); | 112 | double functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3); |
113 | double functionSumSQ(const QString ¶m1, const QString ¶m2); //sum of squares | 113 | double functionSumSQ(const QString ¶m1, const QString ¶m2); //sum of squares |
114 | QString functionIndex(const QString ¶m1, const QString ¶m2, int indx); | 114 | QString functionIndex(const QString ¶m1, const QString ¶m2, int indx); |
115 | //math functions computations | 115 | //math functions computations |
116 | double BesselI0(double x); | 116 | double BesselI0(double x); |
117 | double BesselI(int n, double x); | 117 | double BesselI(int n, double x); |
118 | double BesselK0(double x); | 118 | double BesselK0(double x); |
119 | double BesselI1(double x); | 119 | double BesselI1(double x); |
120 | double BesselK1(double x); | 120 | double BesselK1(double x); |
121 | double BesselK(int n, double x); | 121 | double BesselK(int n, double x); |
122 | double BesselJ0(double x); | 122 | double BesselJ0(double x); |
123 | double BesselY0(double x); | 123 | double BesselY0(double x); |
124 | double BesselJ1(double x); | 124 | double BesselJ1(double x); |
125 | double BesselY1(double x); | 125 | double BesselY1(double x); |
126 | double BesselY(int n, double x); | 126 | double BesselY(int n, double x); |
127 | double BesselJ(int n, double x); | 127 | double BesselJ(int n, double x); |