summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/ChangeLog4
-rw-r--r--noncore/apps/opie-sheet/sheet.cpp10
-rw-r--r--noncore/apps/opie-sheet/sheet.h2
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,64 +1,68 @@
1January 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
1January 7, 2004 5January 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:
25 -surelly a much full-stable excel importer. 29 -surelly a much full-stable excel importer.
26 -Cell Manipulation of many Data is really slow.... must change the QList data type. To a structure more efficient. 30 -Cell Manipulation of many Data is really slow.... must change the QList data type. To a structure more efficient.
27 -maybe some more functions. 31 -maybe some more functions.
28 -maybe some kind of charts drawing? 32 -maybe some kind of charts drawing?
29 -maybe kspread or ooffice files import/export. 33 -maybe kspread or ooffice files import/export.
30 34
31October 08, 2002 35October 08, 2002
32 36
33 * Release 1.0.2 (by thufir) 37 * Release 1.0.2 (by thufir)
34 - Fixed bug #250 (exhibiting re-calculation error in multi-level calculation). (by thufir) 38 - Fixed bug #250 (exhibiting re-calculation error in multi-level calculation). (by thufir)
35 39
36October 06, 2002 40October 06, 2002
37 41
38 - Fixed data edit box clear problem. (by thufir) 42 - Fixed data edit box clear problem. (by thufir)
39 43
40October 05, 2002 44October 05, 2002
41 45
42 - Fixed bug #252 (starting up in 'mouse button' mode). (by thufir) 46 - Fixed bug #252 (starting up in 'mouse button' mode). (by thufir)
43 47
44August 31, 2002 48August 31, 2002
45 49
46 - Fixed and updated opie-sheet.pro file. (by cniehaus) 50 - Fixed and updated opie-sheet.pro file. (by cniehaus)
47 51
48August 01, 2002 52August 01, 2002
49 53
50 - Fixed gcc3 compile problems. (by harlekin) 54 - Fixed gcc3 compile problems. (by harlekin)
51 55
52July 06, 2002 56July 06, 2002
53 57
54 - Fixed DocLnk management to save documents correctly. (by leseb) 58 - Fixed DocLnk management to save documents correctly. (by leseb)
55 59
56July 04, 2002 60July 04, 2002
57 61
58 * Release 1.0.1 (by thufir) 62 * Release 1.0.1 (by thufir)
59 - Sheet/Qt is now a part of Opie, so its name is changed to Opie Sheet. (by thufir) 63 - Sheet/Qt is now a part of Opie, so its name is changed to Opie Sheet. (by thufir)
60 - Fixed sorting bug. (by thufir) 64 - Fixed sorting bug. (by thufir)
61 65
62April 14, 2002 66April 14, 2002
63 67
64 * Release 1.0.0 (by thufir) 68 * Release 1.0.0 (by thufir)
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
@@ -784,265 +784,267 @@ double Sheet::functionSumSQ(const QString &param1, const QString &param2)
784 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 784 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
785 { 785 {
786 for (row=row1; row<=row2; ++row) 786 for (row=row1; row<=row2; ++row)
787 for (col=col1; col<=col2; ++col) 787 for (col=col1; col<=col2; ++col)
788 { 788 {
789 tempResult=text(row, col).toDouble(&ok); 789 tempResult=text(row, col).toDouble(&ok);
790 if (ok) result+=tempResult*tempResult; 790 if (ok) result+=tempResult*tempResult;
791 } 791 }
792 return result; 792 return result;
793 }else 793 }else
794 { 794 {
795 double d1=0,d2=0; 795 double d1=0,d2=0;
796 d1=calculateVariable(param1).toDouble(&ok); 796 d1=calculateVariable(param1).toDouble(&ok);
797 d2=calculateVariable(param2).toDouble(&ok); 797 d2=calculateVariable(param2).toDouble(&ok);
798 return(d1*d1+d2*d2); 798 return(d1*d1+d2*d2);
799 }; 799 };
800 return 0; 800 return 0;
801} 801}
802 802
803 803
804 804
805double Sheet::functionMin(const QString &param1, const QString &param2) 805double Sheet::functionMin(const QString &param1, const QString &param2)
806{ 806{
807 int row1, col1, row2, col2, row, col; 807 int row1, col1, row2, col2, row, col;
808 double min=0, tempMin; 808 double min=0, tempMin;
809 bool ok, init=FALSE; 809 bool ok, init=FALSE;
810 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 810 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
811 { 811 {
812 for (row=row1; row<=row2; ++row) 812 for (row=row1; row<=row2; ++row)
813 for (col=col1; col<=col2; ++col) 813 for (col=col1; col<=col2; ++col)
814 { 814 {
815 tempMin=text(row, col).toDouble(&ok); 815 tempMin=text(row, col).toDouble(&ok);
816 if (ok && (!init || tempMin<min)) 816 if (ok && (!init || tempMin<min))
817 { 817 {
818 min=tempMin; 818 min=tempMin;
819 init=TRUE; 819 init=TRUE;
820 } 820 }
821 } 821 }
822 return min; 822 return min;
823 }else 823 }else
824 { 824 {
825 double d1=0,d2=0; 825 double d1=0,d2=0;
826 d1=calculateVariable(param1).toDouble(&ok); 826 d1=calculateVariable(param1).toDouble(&ok);
827 d2=calculateVariable(param2).toDouble(&ok); 827 d2=calculateVariable(param2).toDouble(&ok);
828 if(d1<d2) return(d1); else return(d2); 828 if(d1<d2) return(d1); else return(d2);
829 }; 829 };
830 return 0; 830 return 0;
831} 831}
832 832
833double Sheet::functionMax(const QString &param1, const QString &param2) 833double Sheet::functionMax(const QString &param1, const QString &param2)
834{ 834{
835 int row1, col1, row2, col2, row, col; 835 int row1, col1, row2, col2, row, col;
836 double max=0, tempMax; 836 double max=0, tempMax;
837 bool ok, init=FALSE; 837 bool ok, init=FALSE;
838 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 838 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
839 { 839 {
840 for (row=row1; row<=row2; ++row) 840 for (row=row1; row<=row2; ++row)
841 for (col=col1; col<=col2; ++col) 841 for (col=col1; col<=col2; ++col)
842 { 842 {
843 tempMax=text(row, col).toDouble(&ok); 843 tempMax=text(row, col).toDouble(&ok);
844 if (ok && (!init || tempMax>max)) 844 if (ok && (!init || tempMax>max))
845 { 845 {
846 max=tempMax; 846 max=tempMax;
847 init=TRUE; 847 init=TRUE;
848 } 848 }
849 }; 849 };
850 return max; 850 return max;
851 }else 851 }else
852 { 852 {
853 double d1=0,d2=0; 853 double d1=0,d2=0;
854 d1=calculateVariable(param1).toDouble(&ok); 854 d1=calculateVariable(param1).toDouble(&ok);
855 d2=calculateVariable(param2).toDouble(&ok); 855 d2=calculateVariable(param2).toDouble(&ok);
856 if(d1>d2) return(d1); else return(d2); 856 if(d1>d2) return(d1); else return(d2);
857 }; 857 };
858 return 0; 858 return 0;
859} 859}
860 860
861double Sheet::functionAvg(const QString &param1, const QString &param2) 861double Sheet::functionAvg(const QString &param1, const QString &param2)
862{ 862{
863 double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); 863 double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2);
864 return (resultCount>0 ? resultSum/resultCount : 0); 864 return (resultCount>0 ? resultSum/resultCount : 0);
865} 865}
866 866
867double Sheet::functionCount(const QString &param1, const QString &param2) 867double Sheet::functionCount(const QString &param1, const QString &param2)
868{ 868{
869 int row1, col1, row2, col2, row, col; 869 int row1, col1, row2, col2, row, col;
870 int divider=0; 870 int divider=0;
871 bool ok; 871 bool ok;
872 if (findRange(param1, param2, &row1, &col1, &row2, &col2)) 872 if (findRange(param1, param2, &row1, &col1, &row2, &col2))
873 { 873 {
874 for (row=row1; row<=row2; ++row) 874 for (row=row1; row<=row2; ++row)
875 for (col=col1; col<=col2; ++col) 875 for (col=col1; col<=col2; ++col)
876 { 876 {
877 text(row, col).toDouble(&ok); 877 text(row, col).toDouble(&ok);
878 if (ok) ++divider; 878 if (ok) ++divider;
879 }; 879 };
880 return divider; 880 return divider;
881 }else 881 }else
882 { 882 {
883 double d1=0,d2=0;int ii=0; 883 double d1=0,d2=0;int ii=0;
884 d1=calculateVariable(param1).toDouble(&ok); 884 d1=calculateVariable(param1).toDouble(&ok);
885 if (ok) ii++; 885 if (ok) ii++;
886 d2=calculateVariable(param2).toDouble(&ok); 886 d2=calculateVariable(param2).toDouble(&ok);
887 if (ok) ii++; 887 if (ok) ii++;
888 return(ii); 888 return(ii);
889 }; 889 };
890 return 0; 890 return 0;
891} 891}
892 892
893double Sheet::functionCountIf(const QString &param1, const QString &param2, const QString &param3) 893double Sheet::functionCountIf(const QString &param1, const QString &param2, const QString &param3)
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
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));
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 {
945 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 947 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
946 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 948 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
947 if(val2==0.0) return QString("Err101"); 949 if(val2==0.0) return QString("Err101");
948 val1=val1/val2; 950 val1=val1/val2;
949 return QString::number(val1); 951 return QString::number(val1);
950 }; 952 };
951 if (function==">") 953 if (function==">")
952 { 954 {
953 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 955 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
954 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 956 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
955 if(val1>val2) return QString::number(1); else return QString::number(0); 957 if(val1>val2) return QString::number(1); else return QString::number(0);
956 }; 958 };
957 if (function=="<") 959 if (function=="<")
958 { 960 {
959 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 961 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
960 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 962 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
961 if(val1<val2) return QString::number(1); else return QString::number(0); 963 if(val1<val2) return QString::number(1); else return QString::number(0);
962 }; 964 };
963 if (function==">=") 965 if (function==">=")
964 { 966 {
965 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 967 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
966 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 968 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
967 if(val1>=val2) return QString::number(1); else return QString::number(0); 969 if(val1>=val2) return QString::number(1); else return QString::number(0);
968 }; 970 };
969 if (function=="<=") 971 if (function=="<=")
970 { 972 {
971 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 973 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
972 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 974 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
973 if(val1<=val2) return QString::number(1); else return QString::number(0); 975 if(val1<=val2) return QString::number(1); else return QString::number(0);
974 }; 976 };
975 if (function=="!=") 977 if (function=="!=")
976 { 978 {
977 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 979 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
978 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 980 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
979 if(val1!=val2) return QString::number(1); else return QString::number(0); 981 if(val1!=val2) return QString::number(1); else return QString::number(0);
980 }; 982 };
981 if (function=="=="||function=="=") 983 if (function=="=="||function=="=")
982 { 984 {
983 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); 985 val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok);
984 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); 986 val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok);
985 if(val1==val2) return QString::number(1); else return QString::number(0); 987 if(val1==val2) return QString::number(1); else return QString::number(0);
986 }; 988 };
987 989
988 //LOGICAL / INFO 990 //LOGICAL / INFO
989 if (function=="ISBLANK") 991 if (function=="ISBLANK")
990 { 992 {
991 if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE)) 993 if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE))
992 { 994 {
993 if(text(row,col).length()==0) val1=1; else val1=0; 995 if(text(row,col).length()==0) val1=1; else val1=0;
994 }else 996 }else
995 { 997 {
996 if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE)) 998 if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE))
997 { 999 {
998 if(text(row,col).length()==0) val1=1; else val1=0; 1000 if(text(row,col).length()==0) val1=1; else val1=0;
999 }else 1001 }else
1000 { 1002 {
1001 val1=0; 1003 val1=0;
1002 }; 1004 };
1003 }; 1005 };
1004 return QString::number(val1); 1006 return QString::number(val1);
1005 }; 1007 };
1006 1008
1007 1009
1008 if (function=="ISNUMBER") 1010 if (function=="ISNUMBER")
1009 { 1011 {
1010 if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE)) 1012 if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE))
1011 { 1013 {
1012 val1=text(row,col).toDouble(&ok); 1014 val1=text(row,col).toDouble(&ok);
1013 if(ok) val1=1; else val1=0; 1015 if(ok) val1=1; else val1=0;
1014 }else 1016 }else
1015 { 1017 {
1016 if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE)) 1018 if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE))
1017 { 1019 {
1018 val1=text(row,col).toDouble(&ok); 1020 val1=text(row,col).toDouble(&ok);
1019 if(ok) val1=1; else val1=0; 1021 if(ok) val1=1; else val1=0;
1020 }else 1022 }else
1021 { 1023 {
1022 val1=0; 1024 val1=0;
1023 }; 1025 };
1024 }; 1026 };
1025 return QString::number(val1); 1027 return QString::number(val1);
1026 }; 1028 };
1027 if (function=="AND") 1029 if (function=="AND")
1028 { 1030 {
1029 vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok) 1031 vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok)
1030 & calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1032 & calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1031 return QString::number(vali); 1033 return QString::number(vali);
1032 }; 1034 };
1033 if (function=="OR") 1035 if (function=="OR")
1034 { 1036 {
1035 vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok) 1037 vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok)
1036 | calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1038 | calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1037 return QString::number(vali); 1039 return QString::number(vali);
1038 }; 1040 };
1039 if (function=="NOT") 1041 if (function=="NOT")
1040 { 1042 {
1041 vali=!calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok); 1043 vali=!calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok);
1042 return QString::number(vali); 1044 return QString::number(vali);
1043 }; 1045 };
1044 1046
1045 // MATHEMATICAL FUNCTIONS 1047 // MATHEMATICAL FUNCTIONS
1046 if (function=="ABS") 1048 if (function=="ABS")
1047 { 1049 {
1048 val1=fabs(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); 1050 val1=fabs(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok));
@@ -1652,305 +1654,305 @@ QString Sheet::calculateFunction(const QString &function, const QString &paramet
1652 if(vali==1)//distribution 1654 if(vali==1)//distribution
1653 { 1655 {
1654 if(val3==0.0) return QString::number(0.0); 1656 if(val3==0.0) return QString::number(0.0);
1655 else 1657 else
1656 return QString::number(GammaP(val2,val1/val3)); 1658 return QString::number(GammaP(val2,val1/val3));
1657 }else //density 1659 }else //density
1658 { 1660 {
1659 return QString::number( 1661 return QString::number(
1660 pow(val1,val2-1.0)*exp(-val1/val3) / (pow(val3,val2)*exp(GammaLn(val2))) 1662 pow(val1,val2-1.0)*exp(-val1/val3) / (pow(val3,val2)*exp(GammaLn(val2)))
1661 ); 1663 );
1662 }; 1664 };
1663 }; 1665 };
1664 if(function=="BETADIST") 1666 if(function=="BETADIST")
1665 { 1667 {
1666 // BETADIST (z,alpha,beta,distribution?density1:0) 1668 // BETADIST (z,alpha,beta,distribution?density1:0)
1667 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1669 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1668 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1670 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1669 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); 1671 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok);
1670 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); 1672 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok);
1671 if(vali==1)//distribution 1673 if(vali==1)//distribution
1672 { 1674 {
1673 return QString::number(BetaIncomplete(val2,val3,val1)); 1675 return QString::number(BetaIncomplete(val2,val3,val1));
1674 }else //density 1676 }else //density
1675 { 1677 {
1676 return QString::number( 1678 return QString::number(
1677 pow(val1,val2-1.0)*pow(1.0-val1,val3-1.0) / Beta(val2,val3) 1679 pow(val1,val2-1.0)*pow(1.0-val1,val3-1.0) / Beta(val2,val3)
1678 ); 1680 );
1679 }; 1681 };
1680 }; 1682 };
1681 if(function=="FDIST") 1683 if(function=="FDIST")
1682 { 1684 {
1683 // FDIST (z,d1,d2,distribution?density1:0) 1685 // FDIST (z,d1,d2,distribution?density1:0)
1684 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1686 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1685 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1687 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1686 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); 1688 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok);
1687 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); 1689 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok);
1688 if(vali==1)//distribution 1690 if(vali==1)//distribution
1689 { 1691 {
1690 return QString::number( 1692 return QString::number(
1691 -BetaIncomplete(val3/2,val2/2,val3/(val3+val2*val1)) 1693 -BetaIncomplete(val3/2,val2/2,val3/(val3+val2*val1))
1692 +BetaIncomplete(val3/2,val2/2,1) 1694 +BetaIncomplete(val3/2,val2/2,1)
1693 ); 1695 );
1694 }else //density 1696 }else //density
1695 { 1697 {
1696 return QString::number( 1698 return QString::number(
1697 pow(val2,val2/2)*pow(val3,val3/2)*pow(val1,val2/2-1)/ 1699 pow(val2,val2/2)*pow(val3,val3/2)*pow(val1,val2/2-1)/
1698 (pow(val3+val2*val1,(val2+val3)/2)*Beta(val2/2,val3/2)) 1700 (pow(val3+val2*val1,(val2+val3)/2)*Beta(val2/2,val3/2))
1699 ); 1701 );
1700 }; 1702 };
1701 }; 1703 };
1702 if(function=="NORMALDIST") 1704 if(function=="NORMALDIST")
1703 { 1705 {
1704 // NORMALDIST (x,m,s,distribution?density1:0) 1706 // NORMALDIST (x,m,s,distribution?density1:0)
1705 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1707 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1706 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); 1708 val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok);
1707 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); 1709 val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok);
1708 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); 1710 vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok);
1709 if(vali==1)//distribution 1711 if(vali==1)//distribution
1710 { 1712 {
1711 return QString::number( 1713 return QString::number(
1712 (ErrorFunction((val1-val2)/(sqrt(2)*val3))+1)/2.0 1714 (ErrorFunction((val1-val2)/(sqrt(2)*val3))+1)/2.0
1713 ); 1715 );
1714 }else //density 1716 }else //density
1715 { 1717 {
1716 return QString::number( 1718 return QString::number(
1717 exp(-pow(((val1-val2)/val3),2)/2)/(val3*sqrt(2*M_PI)) 1719 exp(-pow(((val1-val2)/val3),2)/2)/(val3*sqrt(2*M_PI))
1718 ); 1720 );
1719 }; 1721 };
1720 }; 1722 };
1721 if(function=="PHI") 1723 if(function=="PHI")
1722 { 1724 {
1723 // NORMALDIST (x,distribution?density1:0) with mean=0 s=1.0 1725 // NORMALDIST (x,distribution?density1:0) with mean=0 s=1.0
1724 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); 1726 val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok);
1725 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); 1727 vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok);
1726 if(vali==1)//distribution 1728 if(vali==1)//distribution
1727 { 1729 {
1728 return QString::number( 1730 return QString::number(
1729 (ErrorFunction(val1/(sqrt(2)))+1)/2.0 1731 (ErrorFunction(val1/(sqrt(2)))+1)/2.0
1730 ); 1732 );
1731 }else //density 1733 }else //density
1732 { 1734 {
1733 return QString::number( 1735 return QString::number(
1734 exp(-pow(val1,2)/2)/(sqrt(2*M_PI)) 1736 exp(-pow(val1,2)/2)/(sqrt(2*M_PI))
1735 ); 1737 );
1736 }; 1738 };
1737 }; 1739 };
1738 /* 1740 /*
1739 StudentTDistribution/: PDF[StudentTDistribution[n_], x_] := 1741 StudentTDistribution/: PDF[StudentTDistribution[n_], x_] :=
1740 1/(Sqrt[n] Beta[n/2, 1/2]) Sqrt[n/(n+x^2)]^(n+1) /; 1742 1/(Sqrt[n] Beta[n/2, 1/2]) Sqrt[n/(n+x^2)]^(n+1) /;
1741 ParameterQ[StudentTDistribution[n]] 1743 ParameterQ[StudentTDistribution[n]]
1742 1744
1743 StudentTDistribution/: CDF[StudentTDistribution[n_], x_] := 1745 StudentTDistribution/: CDF[StudentTDistribution[n_], x_] :=
1744 (1 + Sign[x] BetaRegularized[n/(n+x^2), 1, n/2, 1/2])/2 /; 1746 (1 + Sign[x] BetaRegularized[n/(n+x^2), 1, n/2, 1/2])/2 /;
1745 ParameterQ[StudentTDistribution[n]] 1747 ParameterQ[StudentTDistribution[n]]
1746 */ 1748 */
1747 1749
1748 1750
1749 1751
1750 return 0; 1752 return 0;
1751}; 1753};
1752 1754
1753 1755
1754 1756
1755 1757
1756QString Sheet::dataParserHelper(const QString &data) 1758QString 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
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}
1841 1843
1842 1844
1843void Sheet::setData(const QString &data) 1845void 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
1850QString Sheet::getData() 1852QString Sheet::getData()
1851{ 1853{
1852 typeCellData *cellData=findCellData(currentRow(), currentColumn()); 1854 typeCellData *cellData=findCellData(currentRow(), currentColumn());
1853 if (cellData) 1855 if (cellData)
1854 return cellData->data; 1856 return cellData->data;
1855 return ""; 1857 return "";
1856} 1858}
1857 1859
1858void Sheet::lockClicks(bool lock) 1860void Sheet::lockClicks(bool lock)
1859{ 1861{
1860 clicksLocked=lock; 1862 clicksLocked=lock;
1861} 1863}
1862 1864
1863void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected) 1865void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected)
1864{ 1866{
1865 if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; 1867 if (selected && row==currentRow() && col==currentColumn()) selected=FALSE;
1866 1868
1867 int sheetDataCurrent=sheetData.at(); 1869 int sheetDataCurrent=sheetData.at();
1868 typeCellData *cellData=findCellData(row, col); 1870 typeCellData *cellData=findCellData(row, col);
1869 if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); 1871 if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent);
1870 if (!cellData) cellData=&defaultCellData; 1872 if (!cellData) cellData=&defaultCellData;
1871 if (selected) 1873 if (selected)
1872 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); 1874 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight());
1873 else 1875 else
1874 { 1876 {
1875 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); 1877 p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base());
1876 p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); 1878 p->fillRect(0, 0, cr.width(), cr.height(), cellData->background);
1877 } 1879 }
1878 1880
1879 QTableItem *cellItem=item(row, col); 1881 QTableItem *cellItem=item(row, col);
1880 if (cellItem) 1882 if (cellItem)
1881 { 1883 {
1882 p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); 1884 p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor);
1883 p->setFont(cellData->font); 1885 p->setFont(cellData->font);
1884 QString str=cellItem->text(); 1886 QString str=cellItem->text();
1885 p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text()); 1887 p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text());
1886 } 1888 }
1887 1889
1888 int rx=cr.width()-1, ry=cr.height()-1; 1890 int rx=cr.width()-1, ry=cr.height()-1;
1889 QPen pen(p->pen()); 1891 QPen pen(p->pen());
1890 p->setPen(cellData->borders.right); 1892 p->setPen(cellData->borders.right);
1891 p->drawLine(rx, 0, rx, ry); 1893 p->drawLine(rx, 0, rx, ry);
1892 p->setPen(cellData->borders.bottom); 1894 p->setPen(cellData->borders.bottom);
1893 p->drawLine(0, ry, rx, ry); 1895 p->drawLine(0, ry, rx, ry);
1894 p->setPen(pen); 1896 p->setPen(pen);
1895} 1897}
1896 1898
1897void Sheet::viewportMousePressEvent(QMouseEvent *e) 1899void Sheet::viewportMousePressEvent(QMouseEvent *e)
1898{ 1900{
1899 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); 1901 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
1900 if (clicksLocked) 1902 if (clicksLocked)
1901 { 1903 {
1902 if (selectionNo<0) 1904 if (selectionNo<0)
1903 { 1905 {
1904 clearSelection(); 1906 clearSelection();
1905 QTableSelection newSelection; 1907 QTableSelection newSelection;
1906 newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); 1908 newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
1907 newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); 1909 newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol());
1908 selectionNo=addSelection(newSelection); 1910 selectionNo=addSelection(newSelection);
1909 } 1911 }
1910 } 1912 }
1911 else 1913 else
1912 QTable::contentsMousePressEvent(&ce); 1914 QTable::contentsMousePressEvent(&ce);
1913} 1915}
1914 1916
1915void Sheet::viewportMouseMoveEvent(QMouseEvent *e) 1917void Sheet::viewportMouseMoveEvent(QMouseEvent *e)
1916{ 1918{
1917 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); 1919 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
1918 if (clicksLocked) 1920 if (clicksLocked)
1919 { 1921 {
1920 if (selectionNo>=0) 1922 if (selectionNo>=0)
1921 { 1923 {
1922 QTableSelection oldSelection(selection(selectionNo)); 1924 QTableSelection oldSelection(selection(selectionNo));
1923 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); 1925 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
1924 if (!(oldSelection==selection(selectionNo))) 1926 if (!(oldSelection==selection(selectionNo)))
1925 { 1927 {
1926 removeSelection(selectionNo); 1928 removeSelection(selectionNo);
1927 selectionNo=addSelection(oldSelection); 1929 selectionNo=addSelection(oldSelection);
1928 } 1930 }
1929 } 1931 }
1930 } 1932 }
1931 else 1933 else
1932 QTable::contentsMouseMoveEvent(&ce); 1934 QTable::contentsMouseMoveEvent(&ce);
1933} 1935}
1934 1936
1935void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) 1937void Sheet::viewportMouseReleaseEvent(QMouseEvent *e)
1936{ 1938{
1937 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); 1939 QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state());
1938 if (clicksLocked && selectionNo>=0) 1940 if (clicksLocked && selectionNo>=0)
1939 { 1941 {
1940 QTableSelection oldSelection(selection(selectionNo)); 1942 QTableSelection oldSelection(selection(selectionNo));
1941 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); 1943 oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x()));
1942 removeSelection(selectionNo); 1944 removeSelection(selectionNo);
1943 selectionNo=-1; 1945 selectionNo=-1;
1944 if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) 1946 if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol())
1945 emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())); 1947 emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol()));
1946 else 1948 else
1947 emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol())); 1949 emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol()));
1948 } 1950 }
1949 else 1951 else
1950 QTable::contentsMouseReleaseEvent(&ce); 1952 QTable::contentsMouseReleaseEvent(&ce);
1951} 1953}
1952 1954
1953QString Sheet::findCellName(int row, int col) 1955QString Sheet::findCellName(int row, int col)
1954{ 1956{
1955 return (getHeaderString(col+1)+QString::number(row+1)); 1957 return (getHeaderString(col+1)+QString::number(row+1));
1956} 1958}
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
@@ -1,211 +1,211 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10/* 10/*
11 * Opie Sheet (formerly Sheet/Qt) 11 * Opie Sheet (formerly Sheet/Qt)
12 * by Serdar Ozler <sozler@sitebest.com> 12 * by Serdar Ozler <sozler@sitebest.com>
13 */ 13 */
14 14
15#ifndef SHEET_H 15#ifndef SHEET_H
16#define SHEET_H 16#define SHEET_H
17 17
18#include <qtable.h> 18#include <qtable.h>
19#include <qstack.h> 19#include <qstack.h>
20 20
21typedef struct typeCellBorders 21typedef struct typeCellBorders
22{ 22{
23 QPen right, bottom; 23 QPen right, bottom;
24}; 24};
25 25
26typedef struct typeCellData 26typedef struct typeCellData
27{ 27{
28 int col, row; 28 int col, row;
29 typeCellBorders borders; 29 typeCellBorders borders;
30 QBrush background; 30 QBrush background;
31 Qt::AlignmentFlags alignment; 31 Qt::AlignmentFlags alignment;
32 QColor fontColor; 32 QColor fontColor;
33 QFont font; 33 QFont font;
34 QString data; 34 QString data;
35}; 35};
36 36
37 37
38#define NONE_TOKEN 0 38#define NONE_TOKEN 0
39#define NUMBER_TOKEN 1 39#define NUMBER_TOKEN 1
40#define VARIABLE_TOKEN 2 40#define VARIABLE_TOKEN 2
41#define FUNCTION_TOKEN 3 41#define FUNCTION_TOKEN 3
42#define SYMBOL_TOKEN 4 42#define SYMBOL_TOKEN 4
43#define STRING_TOKEN 5 43#define STRING_TOKEN 5
44 44
45class Expression 45class Expression
46{ 46{
47public: 47public:
48 QString Body; 48 QString Body;
49 QList<QString> CompiledBody; 49 QList<QString> CompiledBody;
50 QList<int> CompiledBodyType; 50 QList<int> CompiledBodyType;
51 QString SYMBOL; 51 QString SYMBOL;
52 QString MATHSYMBOL; 52 QString MATHSYMBOL;
53 QArray<int> ArgsOfFunc; 53 QArray<int> ArgsOfFunc;
54 int FuncDepth; 54 int FuncDepth;
55 bool ErrorFound; 55 bool ErrorFound;
56 int n; // holds the current parser position 56 int n; // holds the current parser position
57 QString chunk; // the piece in the parser we are on 57 QString chunk; // the piece in the parser we are on
58 int SymbGroup; // the current type 58 int SymbGroup; // the current type
59 59
60 QString InExpr; 60 QString InExpr;
61 61
62 QChar chunk0(void); // retunrs the first char of expression; 62 QChar chunk0(void); // retunrs the first char of expression;
63 Expression(QString expr1);// constructor 63 Expression(QString expr1);// constructor
64 64
65 bool isSymbol(QChar ch); 65 bool isSymbol(QChar ch);
66 bool isMathSymbol(QChar ch); 66 bool isMathSymbol(QChar ch);
67 void GetNext(); 67 void GetNext();
68 void First(); 68 void First();
69 void Third(); 69 void Third();
70 void Fourth(); 70 void Fourth();
71 void Fifth(); 71 void Fifth();
72 void Sixth(); 72 void Sixth();
73 void Seventh(); 73 void Seventh();
74 void Eighth(); 74 void Eighth();
75 void Ninth(); 75 void Ninth();
76 76
77 bool Expression::Parse(); //parses the expression in RPN format; 77 bool Expression::Parse(); //parses the expression in RPN format;
78 78
79}; 79};
80 80
81 81
82 82
83class Sheet: public QTable 83class 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 &parameters, int NumOfParams); 103 QString calculateFunction(const QString &func, const QString &parameters, int NumOfParams);
104 QString getParameter(const QString &parameters, int paramNo, bool giveError=FALSE, const QString funcName=""); 104 QString getParameter(const QString &parameters, 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 &param1, const QString &param2, const QString &param3); 112 double functionCountIf(const QString &param1, const QString &param2, const QString &param3);
113 double functionSumSQ(const QString &param1, const QString &param2); //sum of squares 113 double functionSumSQ(const QString &param1, const QString &param2); //sum of squares
114 QString functionIndex(const QString &param1, const QString &param2, int indx); 114 QString functionIndex(const QString &param1, const QString &param2, 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);
128 double GammaLn(double xx); 128 double GammaLn(double xx);
129 double Factorial(double n); 129 double Factorial(double n);
130 double GammaP(double a, double x); 130 double GammaP(double a, double x);
131 double GammaQ(double a,double x); 131 double GammaQ(double a,double x);
132 void GammaSeries(double *gamser, double a, double x, double *gln); 132 void GammaSeries(double *gamser, double a, double x, double *gln);
133 void GammaContinuedFraction(double *gammcf, double a, double x, double *gln); 133 void GammaContinuedFraction(double *gammcf, double a, double x, double *gln);
134 double ErrorFunction(double x); 134 double ErrorFunction(double x);
135 double ErrorFunctionComplementary(double x); 135 double ErrorFunctionComplementary(double x);
136 double Beta(double z, double w); 136 double Beta(double z, double w);
137 double BetaContinuedFraction(double a, double b, double x); 137 double BetaContinuedFraction(double a, double b, double x);
138 double BetaIncomplete(double a, double b, double x); 138 double BetaIncomplete(double a, double b, double x);
139 double functionVariance(const QString &param1, const QString &param2); 139 double functionVariance(const QString &param1, const QString &param2);
140 double functionVariancePopulation(const QString &param1, const QString &param2); 140 double functionVariancePopulation(const QString &param1, const QString &param2);
141 double functionSkew(const QString &param1, const QString &param2); 141 double functionSkew(const QString &param1, const QString &param2);
142 double functionKurt(const QString &param1, const QString &param2); 142 double functionKurt(const QString &param1, const QString &param2);
143 143
144 // Sheet/Qt parser functions 144 // Sheet/Qt parser functions
145 double functionSum(const QString &param1, const QString &param2); 145 double functionSum(const QString &param1, const QString &param2);
146 double functionAvg(const QString &param1, const QString &param2); 146 double functionAvg(const QString &param1, const QString &param2);
147 double functionMax(const QString &param1, const QString &param2); 147 double functionMax(const QString &param1, const QString &param2);
148 double functionMin(const QString &param1, const QString &param2); 148 double functionMin(const QString &param1, const QString &param2);
149 double functionCount(const QString &param1, const QString &param2); 149 double functionCount(const QString &param1, const QString &param2);
150 150
151 // Reimplemented QTable functions 151 // Reimplemented QTable functions
152 void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected); 152 void paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected);
153 void viewportMousePressEvent(QMouseEvent *e); 153 void viewportMousePressEvent(QMouseEvent *e);
154 void viewportMouseMoveEvent(QMouseEvent *e); 154 void viewportMouseMoveEvent(QMouseEvent *e);
155 void viewportMouseReleaseEvent(QMouseEvent *e); 155 void viewportMouseReleaseEvent(QMouseEvent *e);
156 156
157 public slots: 157 public slots:
158 void slotCellSelected(int row, int col); 158 void slotCellSelected(int row, int col);
159 void slotCellChanged(int row, int col); 159 void slotCellChanged(int row, int col);
160 160
161 public: 161 public:
162 Sheet(int numRows, int numCols, QWidget *parent); 162 Sheet(int numRows, int numCols, QWidget *parent);
163 ~Sheet(); 163 ~Sheet();
164 void ReCalc(void); 164 void ReCalc(void);
165 void setData(const QString &data); 165 void setData(const QString &data);
166 QString getData(); 166 QString getData();
167 167
168 void setName(const QString &data); 168 void setName(const QString &data);
169 QString getName(); 169 QString getName();
170 170
171 void setPen(int row, int col, int vertical, const QPen &pen); 171 void setPen(int row, int col, int vertical, const QPen &pen);
172 QPen getPen(int row, int col, int vertical); 172 QPen getPen(int row, int col, int vertical);
173 173
174 void setBrush(int row, int col, const QBrush &brush); 174 void setBrush(int row, int col, const QBrush &brush);
175 QBrush getBrush(int row, int col); 175 QBrush getBrush(int row, int col);
176 176
177 void setTextAlign(int row, int col, Qt::AlignmentFlags flags); 177 void setTextAlign(int row, int col, Qt::AlignmentFlags flags);
178 Qt::AlignmentFlags getAlignment(int row, int col); 178 Qt::AlignmentFlags getAlignment(int row, int col);
179 179
180 void setTextFont(int row, int col, const QFont &font, const QColor &color); 180 void setTextFont(int row, int col, const QFont &font, const QColor &color);
181 QFont getFont(int row, int col); 181 QFont getFont(int row, int col);
182 QColor getFontColor(int row, int col); 182 QColor getFontColor(int row, int col);
183 183
184 void lockClicks(bool lock=TRUE); 184 void lockClicks(bool lock=TRUE);
185 void copySheetData(QList<typeCellData> *destSheetData); 185 void copySheetData(QList<typeCellData> *destSheetData);
186 void setSheetData(QList<typeCellData> *srcSheetData); 186 void setSheetData(QList<typeCellData> *srcSheetData);
187 void getSelection(int *row1, int *col1, int *row2, int *col2); 187 void getSelection(int *row1, int *col1, int *row2, int *col2);
188 188
189 void insertRows(int no=1, bool allColumns=TRUE); 189 void insertRows(int no=1, bool allColumns=TRUE);
190 void insertColumns(int no=1, bool allRows=TRUE); 190 void insertColumns(int no=1, bool allRows=TRUE);
191 191
192 void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE); 192 void dataFindReplace(const QString &find, const QString &replace, bool matchCase=TRUE, bool allCells=TRUE, bool entireCell=FALSE, bool replace=FALSE, bool replaceAll=FALSE);
193 193
194 // Static functions 194 // Static functions
195 static int getHeaderColumn(const QString &section); 195 static int getHeaderColumn(const QString &section);
196 static QString getHeaderString(int section); 196 static QString getHeaderString(int section);
197 197
198 public slots: 198 public slots:
199 void editCut(); 199 void editCut();
200 void editCopy(); 200 void editCopy();
201 void editPaste(bool onlyContents=FALSE); 201 void editPaste(bool onlyContents=FALSE);
202 void editClear(); 202 void editClear();
203 void swapCells(int row1, int col1, int row2, int col2); 203 void swapCells(int row1, int col1, int row2, int col2);
204 204
205 signals: 205 signals:
206 void currentDataChanged(const QString &data); 206 void currentDataChanged(const QString &data);
207 void cellClicked(const QString &cell); 207 void cellClicked(const QString &cell);
208 void sheetModified(); 208 void sheetModified();
209}; 209};
210 210
211#endif 211#endif