summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/sheet.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-sheet/sheet.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp122
1 files changed, 85 insertions, 37 deletions
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,23 +1,45 @@
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
+/*
+ =. This file is part of the Opie Project
+ .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
+ .>+-=
+ _;:, .> :=|. This program is free software; you can
+.> <`_, > . <= redistribute it and/or modify it under
+:`=1 )Y*s>-.-- : the terms of the GNU General Public
+.="- .-=="i, .._ License as published by the Free Software
+ - . .-<_> .<> Foundation; either version 2 of the License,
+ ._= =} : or (at your option) any later version.
+ .%`+i> _;_.
+ .i_,=:_. -<s. This program is distributed in the hope that
+ + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
+ : .. .:, . . . without even the implied warranty of
+ =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
+ _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.= = ; Library General Public License for more
+++= -. .` .: details.
+ : = ...= . :.=-
+ -. .:....=;==+<; You should have received a copy of the GNU
+ -_. . . )=. = Library General Public License along with
+ -- :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
/*
* Opie Sheet (formerly Sheet/Qt)
* by Serdar Ozler <sozler@sitebest.com>
*/
#include "sheet.h"
+/* QT */
#include <qmessagebox.h>
+
+/* STD */
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define DEFAULT_COL_WIDTH 50
@@ -45,14 +67,13 @@ Sheet::Sheet(int numRows, int numCols, QWidget *parent)
connect(this, SIGNAL(currentChanged(int,int)), this, SLOT(slotCellSelected(int,int)));
connect(this, SIGNAL(valueChanged(int,int)), this, SLOT(slotCellChanged(int,int)));
}
Sheet::~Sheet()
-{
-}
+{}
typeCellData *Sheet::findCellData(int row, int col)
{
typeCellData *tempCellData;
for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next())
{
@@ -64,13 +85,14 @@ typeCellData *Sheet::findCellData(int row, int col)
void Sheet::slotCellSelected(int row, int col)
{
typeCellData *cellData=findCellData(row, col);
if (cellData)
{
emit currentDataChanged(cellData->data);
- }else
+ }
+ else
emit currentDataChanged("");
}
typeCellData *Sheet::createCellData(int row, int col)
{
if (row<0 || col<0) return NULL;
@@ -225,13 +247,14 @@ double Sheet::BesselI0(double x)
double y;
if ((ax=fabs(x)) < 3.75)
{
y=x/3.75;
y*=y;
ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492 +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
- }else
+ }
+ else
{
y=3.75/ax;
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))))))));
}
return ans;
};
@@ -242,13 +265,14 @@ double Sheet::BesselI1(double x)
double y;
if ((ax=fabs(x)) < 3.75)
{
y=x/3.75;
y*=y;
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))))));
- } else
+ }
+ else
{
y=3.75/ax;
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))));
ans *= (exp(ax)/sqrt(ax));
}
return x < 0.0 ? -ans : ans;
@@ -289,13 +313,14 @@ double Sheet::BesselK0(double x)
{
double y,ans;
if (x <= 2.0)
{
y=x*x/4.0;
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))))));
- } else
+ }
+ else
{
y=2.0/x;
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))))));
}
return ans;
};
@@ -304,13 +329,14 @@ double Sheet::BesselK1(double x)
{
double y,ans;
if (x <= 2.0)
{
y=x*x/4.0;
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)))))));
- } else
+ }
+ else
{
y=2.0/x;
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)))))));
}
return ans;
};
@@ -339,13 +365,14 @@ double Sheet::BesselJ0(double x)
if ((ax=fabs(x)) < 8.0)
{
y=x*x;
ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7 +y*(-11214424.18+y*(77392.33017+y*(-184.9052456)))));
ans2=57568490411.0+y*(1029532985.0+y*(9494680.718 +y*(59272.64853+y*(267.8532712+y*1.0))));
ans=ans1/ans2;
- } else
+ }
+ else
{
z=8.0/ax;
y=z*z;
xx=ax-0.785398164;
ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6)));
ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 -y*0.934935152e-7)));
@@ -361,13 +388,14 @@ double Sheet::BesselY0(double x)
if (x < 8.0)
{
y=x*x;
ans1 = -2957821389.0+y*(7062834065.0+y*(-512359803.6 +y*(10879881.29+y*(-86327.92757+y*228.4622733))));
ans2=40076544269.0+y*(745249964.8+y*(7189466.438 +y*(47447.26470+y*(226.1030244+y*1.0))));
ans=(ans1/ans2)+0.636619772*BesselJ0(x)*log(x);
- } else
+ }
+ else
{
z=8.0/x;
y=z*z;
xx=x-0.785398164;
ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6)));
ans2 = -0.1562499995e-1+y*(0.1430488765e-3 +y*(-0.6911147651e-5+y*(0.7621095161e-6 +y*(-0.934945152e-7))));
@@ -383,13 +411,14 @@ double Sheet::BesselJ1(double x)
if ((ax=fabs(x)) < 8.0)
{
y=x*x;
ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1 +y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
ans2=144725228442.0+y*(2300535178.0+y*(18583304.74 +y*(99447.43394+y*(376.9991397+y*1.0))));
ans=ans1/ans2;
- } else
+ }
+ else
{
z=8.0/ax; y=z*z; xx=ax-2.356194491;
ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6))));
ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6)));
ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
if (x < 0.0) ans = -ans;
@@ -404,13 +433,14 @@ double Sheet::BesselY1(double x)
if (x < 8.0)
{
y=x*x;
ans1=x*(-0.4900604943e13+y*(0.1275274390e13 +y*(-0.5153438139e11+y*(0.7349264551e9 +y*(-0.4237922726e7+y*0.8511937935e4)))));
ans2=0.2499580570e14+y*(0.4244419664e12 +y*(0.3733650367e10+y*(0.2245904002e8 +y*(0.1020426050e6+y*(0.3549632885e3+y)))));
ans=(ans1/ans2)+0.636619772*(BesselJ1(x)*log(x)-1.0/x);
- } else
+ }
+ else
{
z=8.0/x;
y=z*z;
xx=x-2.356194491;
ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6))));
ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6)));
@@ -455,13 +485,14 @@ double Sheet::BesselJ(int n, double x)
{
bjp=j*tox*bj-bjm;
bjm=bj;
bj=bjp;
}
ans=bj;
- } else
+ }
+ else
{
tox=2.0/ax;
m=2*((n+(int) sqrt(ACC*n))/2);
jsum=0;
bjp=ans=sum=0.0;
bj=1.0;
@@ -515,13 +546,14 @@ double Sheet::GammaP(double a, double x)
double gamser,gammcf,gln;
if (x < 0.0 || a <= 0.0) return 0.0;//error
if (x < (a+1.0))
{
GammaSeries(&gamser,a,x,&gln);
return gamser;
- }else
+ }
+ else
{
GammaContinuedFraction(&gammcf,a,x,&gln);
return 1.0-gammcf;
}
};
@@ -541,13 +573,14 @@ void Sheet::GammaSeries(double *gamser, double a, double x, double *gln)
*gln=GammaLn(a);
if (x <= 0.0)
{
if (x < 0.0) return;//error
*gamser=0.0;
return;
- } else
+ }
+ else
{
ap=a;
del=sum=1.0/a;
for (n=1;n<=ITMAX;n++)
{
++ap;
@@ -555,13 +588,14 @@ void Sheet::GammaSeries(double *gamser, double a, double x, double *gln)
sum += del;
if (fabs(del) < fabs(sum)*EPS)
{
*gamser=sum*exp(-x+a*log(x)-(*gln));
return;
}
- } return;
+ }
+ return;
return;
}
};
void Sheet::GammaContinuedFraction(double *gammcf, double a, double x, double *gln)
@@ -659,13 +693,14 @@ double Sheet::functionSum(const QString &param1, const QString &param2)
for (col=col1; col<=col2; ++col)
{
tempResult=text(row, col).toDouble(&ok);
if (ok) result+=tempResult;
}
return result;
- }else
+ }
+ else
{
double d1=0,d2=0;
d1=calculateVariable(param1).toDouble(&ok);
d2=calculateVariable(param2).toDouble(&ok);
return(d1+d2);
};
@@ -786,13 +821,14 @@ double Sheet::functionSumSQ(const QString &param1, const QString &param2)
for (col=col1; col<=col2; ++col)
{
tempResult=text(row, col).toDouble(&ok);
if (ok) result+=tempResult*tempResult;
}
return result;
- }else
+ }
+ else
{
double d1=0,d2=0;
d1=calculateVariable(param1).toDouble(&ok);
d2=calculateVariable(param2).toDouble(&ok);
return(d1*d1+d2*d2);
};
@@ -816,13 +852,14 @@ double Sheet::functionMin(const QString &param1, const QString &param2)
{
min=tempMin;
init=TRUE;
}
}
return min;
- }else
+ }
+ else
{
double d1=0,d2=0;
d1=calculateVariable(param1).toDouble(&ok);
d2=calculateVariable(param2).toDouble(&ok);
if(d1<d2) return(d1); else return(d2);
};
@@ -844,13 +881,14 @@ double Sheet::functionMax(const QString &param1, const QString &param2)
{
max=tempMax;
init=TRUE;
}
};
return max;
- }else
+ }
+ else
{
double d1=0,d2=0;
d1=calculateVariable(param1).toDouble(&ok);
d2=calculateVariable(param2).toDouble(&ok);
if(d1>d2) return(d1); else return(d2);
};
@@ -874,13 +912,14 @@ double Sheet::functionCount(const QString &param1, const QString &param2)
for (col=col1; col<=col2; ++col)
{
text(row, col).toDouble(&ok);
if (ok) ++divider;
};
return divider;
- }else
+ }
+ else
{
double d1=0,d2=0;int ii=0;
d1=calculateVariable(param1).toDouble(&ok);
if (ok) ii++;
d2=calculateVariable(param2).toDouble(&ok);
if (ok) ii++;
@@ -989,18 +1028,20 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
//LOGICAL / INFO
if (function=="ISBLANK")
{
if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE))
{
if(text(row,col).length()==0) val1=1; else val1=0;
- }else
+ }
+ else
{
if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE))
{
if(text(row,col).length()==0) val1=1; else val1=0;
- }else
+ }
+ else
{
val1=0;
};
};
return QString::number(val1);
};
@@ -1009,19 +1050,21 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
if (function=="ISNUMBER")
{
if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE))
{
val1=text(row,col).toDouble(&ok);
if(ok) val1=1; else val1=0;
- }else
+ }
+ else
{
if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE))
{
val1=text(row,col).toDouble(&ok);
if(ok) val1=1; else val1=0;
- }else
+ }
+ else
{
val1=0;
};
};
return QString::number(val1);
};
@@ -1386,13 +1429,14 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
//returns param4 if true(param1)/ param5 if false(param1)
val1=getParameter(parameters, 0, TRUE, function).toDouble(&ok);
if(val1==1.0)
{
s1=calculateVariable(getParameter(parameters, 1, TRUE, function));
return QString(s1);
- }else
+ }
+ else
{
s1=calculateVariable(getParameter(parameters, 2, TRUE, function));
return QString(s1);
};
};
if (function=="SUM")
@@ -1549,13 +1593,14 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
if(vali==1)
{
return QString::number(GammaQ(floor(val1)+1, val2));
- }else
+ }
+ else
{
return QString::number(exp(-val2)*pow(val2,val1)/exp(GammaLn(val1+1.0)));
};
};
if(function=="CHIDIST")
{
@@ -1563,13 +1608,14 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
if(vali==1)
{
return QString::number(GammaP(val2/2.0,val1*val1/2.0));
- } else
+ }
+ else
{
return QString::number(
pow(val1,val2-1.0)*exp(-val1*val1/2)/ ( pow(2,val2/2.0-1.0)*exp(GammaLn(val2/2.0)))
);
};
};
@@ -1579,13 +1625,14 @@ QString Sheet::calculateFunction(const QString &func, const QString &parameters,
val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok);
if(vali==1)
{
return QString::number(GammaP(val2/2.0,val1/2.0));
- } else
+ }
+ else
{
return QString::number(
pow(val1,val2/2.0-1.0)/(exp(val1/2.0)*pow(sqrt(2.0),val2)*exp(GammaLn(val2/2.0)))
);
};
};
@@ -2382,13 +2429,14 @@ void Expression::GetNext()
else
{
break;
}
}//while
}//else if
-};//end function
+}
+;//end function
void Expression::First()
{
GetNext();
if (!(chunk=="") && !ErrorFound) Third();