summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/sheet.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-sheet/sheet.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp10
1 files changed, 6 insertions, 4 deletions
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
@@ -900,33 +900,35 @@ double Sheet::functionCountIf(const QString &param1, const QString &param2, cons
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
912QString Sheet::calculateFunction(const QString &function, const QString &parameters, int NumOfParams) 912QString Sheet::calculateFunction(const QString &func, const QString &parameters, 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));
@@ -1768,73 +1770,73 @@ QString Sheet::dataParserHelper(const QString &data)
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
1820QString Sheet::dataParser(const QString &cell, const QString &data) 1822QString 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}