author | mickeyl <mickeyl> | 2004-04-24 13:50:11 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-24 13:50:11 (UTC) |
commit | 0e24210ea7aa2deaf2facf29c366413aa93d0482 (patch) (unidiff) | |
tree | 1adae72f49c3f5005be836e6e7525dc79fb098cd | |
parent | 9ac401fbe5c80f710757926920d734e93a7e159b (diff) | |
download | opie-0e24210ea7aa2deaf2facf29c366413aa93d0482.zip opie-0e24210ea7aa2deaf2facf29c366413aa93d0482.tar.gz opie-0e24210ea7aa2deaf2facf29c366413aa93d0482.tar.bz2 |
gcc 3.4 fixlet
-rw-r--r-- | noncore/apps/opie-sheet/sheet.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/noncore/apps/opie-sheet/sheet.cpp b/noncore/apps/opie-sheet/sheet.cpp index d4419af..88847da 100644 --- a/noncore/apps/opie-sheet/sheet.cpp +++ b/noncore/apps/opie-sheet/sheet.cpp | |||
@@ -556,2011 +556,2011 @@ void Sheet::GammaSeries(double *gamser, double a, double x, double *gln) | |||
556 | if (fabs(del) < fabs(sum)*EPS) | 556 | if (fabs(del) < fabs(sum)*EPS) |
557 | { | 557 | { |
558 | *gamser=sum*exp(-x+a*log(x)-(*gln)); | 558 | *gamser=sum*exp(-x+a*log(x)-(*gln)); |
559 | return; | 559 | return; |
560 | } | 560 | } |
561 | } return; | 561 | } return; |
562 | return; | 562 | return; |
563 | } | 563 | } |
564 | }; | 564 | }; |
565 | 565 | ||
566 | 566 | ||
567 | void Sheet::GammaContinuedFraction(double *gammcf, double a, double x, double *gln) | 567 | void Sheet::GammaContinuedFraction(double *gammcf, double a, double x, double *gln) |
568 | { | 568 | { |
569 | double EPS=3.0e-7; | 569 | double EPS=3.0e-7; |
570 | double FPMIN=1.0e-30; | 570 | double FPMIN=1.0e-30; |
571 | int ITMAX=100; | 571 | int ITMAX=100; |
572 | int i; | 572 | int i; |
573 | double an,b,c,d,del,h; | 573 | double an,b,c,d,del,h; |
574 | *gln=GammaLn(a); | 574 | *gln=GammaLn(a); |
575 | b=x+1.0-a; | 575 | b=x+1.0-a; |
576 | c=1.0/FPMIN; | 576 | c=1.0/FPMIN; |
577 | d=1.0/b; h=d; | 577 | d=1.0/b; h=d; |
578 | for (i=1;i<=ITMAX;i++) | 578 | for (i=1;i<=ITMAX;i++) |
579 | { | 579 | { |
580 | an = -i*(i-a); | 580 | an = -i*(i-a); |
581 | b += 2.0; d=an*d+b; | 581 | b += 2.0; d=an*d+b; |
582 | if (fabs(d) < FPMIN) d=FPMIN; | 582 | if (fabs(d) < FPMIN) d=FPMIN; |
583 | c=b+an/c; | 583 | c=b+an/c; |
584 | if (fabs(c) < FPMIN) c=FPMIN; | 584 | if (fabs(c) < FPMIN) c=FPMIN; |
585 | d=1.0/d; del=d*c; h *= del; | 585 | d=1.0/d; del=d*c; h *= del; |
586 | if (fabs(del-1.0) < EPS) break; | 586 | if (fabs(del-1.0) < EPS) break; |
587 | } | 587 | } |
588 | if (i > ITMAX) return; | 588 | if (i > ITMAX) return; |
589 | *gammcf=exp(-x+a*log(x)-(*gln))*h; | 589 | *gammcf=exp(-x+a*log(x)-(*gln))*h; |
590 | }; | 590 | }; |
591 | 591 | ||
592 | double Sheet::ErrorFunction(double x) | 592 | double Sheet::ErrorFunction(double x) |
593 | { | 593 | { |
594 | return x < 0.0 ? -GammaP(0.5,x*x) : GammaP(0.5,x*x); | 594 | return x < 0.0 ? -GammaP(0.5,x*x) : GammaP(0.5,x*x); |
595 | }; | 595 | }; |
596 | 596 | ||
597 | double Sheet::ErrorFunctionComplementary(double x) | 597 | double Sheet::ErrorFunctionComplementary(double x) |
598 | { | 598 | { |
599 | return x < 0.0 ? 1.0+GammaP(0.5,x*x) : GammaQ(0.5,x*x); | 599 | return x < 0.0 ? 1.0+GammaP(0.5,x*x) : GammaQ(0.5,x*x); |
600 | }; | 600 | }; |
601 | 601 | ||
602 | double Sheet::Beta(double z, double w) | 602 | double Sheet::Beta(double z, double w) |
603 | { | 603 | { |
604 | return exp(GammaLn(z)+GammaLn(w)-GammaLn(z+w)); | 604 | return exp(GammaLn(z)+GammaLn(w)-GammaLn(z+w)); |
605 | }; | 605 | }; |
606 | 606 | ||
607 | 607 | ||
608 | double Sheet::BetaContinuedFraction(double a, double b, double x) | 608 | double Sheet::BetaContinuedFraction(double a, double b, double x) |
609 | { | 609 | { |
610 | int MAXIT=100; | 610 | int MAXIT=100; |
611 | double EPS=3.0e-7; | 611 | double EPS=3.0e-7; |
612 | double FPMIN=1.0e-30; | 612 | double FPMIN=1.0e-30; |
613 | int m,m2; | 613 | int m,m2; |
614 | double aa,c,d,del,h,qab,qam,qap; | 614 | double aa,c,d,del,h,qab,qam,qap; |
615 | qab=a+b; | 615 | qab=a+b; |
616 | qap=a+1.0; qam=a-1.0; c=1.0; | 616 | qap=a+1.0; qam=a-1.0; c=1.0; |
617 | d=1.0-qab*x/qap; | 617 | d=1.0-qab*x/qap; |
618 | if (fabs(d) < FPMIN) d=FPMIN; | 618 | if (fabs(d) < FPMIN) d=FPMIN; |
619 | d=1.0/d; h=d; | 619 | d=1.0/d; h=d; |
620 | for (m=1;m<=MAXIT;m++) | 620 | for (m=1;m<=MAXIT;m++) |
621 | { | 621 | { |
622 | m2=2*m; aa=m*(b-m)*x/((qam+m2)*(a+m2)); | 622 | m2=2*m; aa=m*(b-m)*x/((qam+m2)*(a+m2)); |
623 | d=1.0+aa*d; | 623 | d=1.0+aa*d; |
624 | if (fabs(d) < FPMIN) d=FPMIN; | 624 | if (fabs(d) < FPMIN) d=FPMIN; |
625 | c=1.0+aa/c; | 625 | c=1.0+aa/c; |
626 | if (fabs(c) < FPMIN) c=FPMIN; | 626 | if (fabs(c) < FPMIN) c=FPMIN; |
627 | d=1.0/d; h *= d*c; | 627 | d=1.0/d; h *= d*c; |
628 | aa = -(a+m)*(qab+m)*x/((a+m2)*(qap+m2)); d=1.0+aa*d; | 628 | aa = -(a+m)*(qab+m)*x/((a+m2)*(qap+m2)); d=1.0+aa*d; |
629 | if (fabs(d) < FPMIN) d=FPMIN; | 629 | if (fabs(d) < FPMIN) d=FPMIN; |
630 | c=1.0+aa/c; | 630 | c=1.0+aa/c; |
631 | if (fabs(c) < FPMIN) c=FPMIN; d=1.0/d; | 631 | if (fabs(c) < FPMIN) c=FPMIN; d=1.0/d; |
632 | del=d*c; h *= del; | 632 | del=d*c; h *= del; |
633 | if (fabs(del-1.0) < EPS) break; | 633 | if (fabs(del-1.0) < EPS) break; |
634 | } | 634 | } |
635 | if (m > MAXIT) return 0.0; | 635 | if (m > MAXIT) return 0.0; |
636 | return h; | 636 | return h; |
637 | }; | 637 | }; |
638 | 638 | ||
639 | double Sheet::BetaIncomplete(double a, double b, double x) | 639 | double Sheet::BetaIncomplete(double a, double b, double x) |
640 | { | 640 | { |
641 | double bt; | 641 | double bt; |
642 | if (x < 0.0 || x > 1.0) return 0.0; | 642 | if (x < 0.0 || x > 1.0) return 0.0; |
643 | if (x == 0.0 || x == 1.0) bt=0.0; else | 643 | if (x == 0.0 || x == 1.0) bt=0.0; else |
644 | bt=exp(GammaLn(a+b)-GammaLn(a)-GammaLn(b)+a*log(x)+b*log(1.0-x)); | 644 | bt=exp(GammaLn(a+b)-GammaLn(a)-GammaLn(b)+a*log(x)+b*log(1.0-x)); |
645 | if (x < (a+1.0)/(a+b+2.0)) return bt*BetaContinuedFraction(a,b,x)/a; else | 645 | if (x < (a+1.0)/(a+b+2.0)) return bt*BetaContinuedFraction(a,b,x)/a; else |
646 | return 1.0-bt*BetaContinuedFraction(b,a,1.0-x)/b; | 646 | return 1.0-bt*BetaContinuedFraction(b,a,1.0-x)/b; |
647 | }; | 647 | }; |
648 | 648 | ||
649 | 649 | ||
650 | 650 | ||
651 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) | 651 | double Sheet::functionSum(const QString ¶m1, const QString ¶m2) |
652 | { | 652 | { |
653 | int row1, col1, row2, col2, row, col; | 653 | int row1, col1, row2, col2, row, col; |
654 | double result=0, tempResult; | 654 | double result=0, tempResult; |
655 | bool ok; | 655 | bool ok; |
656 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) | 656 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) |
657 | { | 657 | { |
658 | for (row=row1; row<=row2; ++row) | 658 | for (row=row1; row<=row2; ++row) |
659 | for (col=col1; col<=col2; ++col) | 659 | for (col=col1; col<=col2; ++col) |
660 | { | 660 | { |
661 | tempResult=text(row, col).toDouble(&ok); | 661 | tempResult=text(row, col).toDouble(&ok); |
662 | if (ok) result+=tempResult; | 662 | if (ok) result+=tempResult; |
663 | } | 663 | } |
664 | return result; | 664 | return result; |
665 | }else | 665 | }else |
666 | { | 666 | { |
667 | double d1=0,d2=0; | 667 | double d1=0,d2=0; |
668 | d1=calculateVariable(param1).toDouble(&ok); | 668 | d1=calculateVariable(param1).toDouble(&ok); |
669 | d2=calculateVariable(param2).toDouble(&ok); | 669 | d2=calculateVariable(param2).toDouble(&ok); |
670 | return(d1+d2); | 670 | return(d1+d2); |
671 | }; | 671 | }; |
672 | return 0; | 672 | return 0; |
673 | } | 673 | } |
674 | 674 | ||
675 | QString Sheet::functionIndex(const QString ¶m1, const QString ¶m2, int indx) | 675 | QString Sheet::functionIndex(const QString ¶m1, const QString ¶m2, int indx) |
676 | { | 676 | { |
677 | int row1, col1, row2, col2, row, col; | 677 | int row1, col1, row2, col2, row, col; |
678 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 678 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
679 | int ii=1; | 679 | int ii=1; |
680 | for (col=col1; col<=col2; ++col) | 680 | for (col=col1; col<=col2; ++col) |
681 | for (row=row1; row<=row2; ++row) | 681 | for (row=row1; row<=row2; ++row) |
682 | { | 682 | { |
683 | if(ii==indx) return text(row,col); | 683 | if(ii==indx) return text(row,col); |
684 | ii++; | 684 | ii++; |
685 | } | 685 | } |
686 | return QString(""); | 686 | return QString(""); |
687 | } | 687 | } |
688 | 688 | ||
689 | 689 | ||
690 | 690 | ||
691 | double Sheet::functionVariancePopulation(const QString ¶m1, const QString ¶m2) | 691 | double Sheet::functionVariancePopulation(const QString ¶m1, const QString ¶m2) |
692 | { | 692 | { |
693 | int row1, col1, row2, col2, row, col; | 693 | int row1, col1, row2, col2, row, col; |
694 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 694 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
695 | double avg1=functionAvg(param1,param2); | 695 | double avg1=functionAvg(param1,param2); |
696 | double result=0, tempResult; | 696 | double result=0, tempResult; |
697 | int count1=0; | 697 | int count1=0; |
698 | bool ok; | 698 | bool ok; |
699 | for (row=row1; row<=row2; ++row) | 699 | for (row=row1; row<=row2; ++row) |
700 | for (col=col1; col<=col2; ++col) | 700 | for (col=col1; col<=col2; ++col) |
701 | { | 701 | { |
702 | tempResult=text(row, col).toDouble(&ok); | 702 | tempResult=text(row, col).toDouble(&ok); |
703 | if (ok) { result=result + (tempResult - avg1)*(tempResult - avg1); count1++;}; | 703 | if (ok) { result=result + (tempResult - avg1)*(tempResult - avg1); count1++;}; |
704 | } | 704 | } |
705 | if(count1>0) result=result/double(count1); else result=0.0; | 705 | if(count1>0) result=result/double(count1); else result=0.0; |
706 | return result; | 706 | return result; |
707 | }; | 707 | }; |
708 | 708 | ||
709 | double Sheet::functionVariance(const QString ¶m1, const QString ¶m2) | 709 | double Sheet::functionVariance(const QString ¶m1, const QString ¶m2) |
710 | { | 710 | { |
711 | int row1, col1, row2, col2, row, col; | 711 | int row1, col1, row2, col2, row, col; |
712 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 712 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
713 | double avg1=functionAvg(param1,param2); | 713 | double avg1=functionAvg(param1,param2); |
714 | double result=0, tempResult; | 714 | double result=0, tempResult; |
715 | int count1=0; | 715 | int count1=0; |
716 | bool ok; | 716 | bool ok; |
717 | for (row=row1; row<=row2; ++row) | 717 | for (row=row1; row<=row2; ++row) |
718 | for (col=col1; col<=col2; ++col) | 718 | for (col=col1; col<=col2; ++col) |
719 | { | 719 | { |
720 | tempResult=text(row, col).toDouble(&ok); | 720 | tempResult=text(row, col).toDouble(&ok); |
721 | if (ok) { result=result + (tempResult - avg1)*(tempResult - avg1); count1++;}; | 721 | if (ok) { result=result + (tempResult - avg1)*(tempResult - avg1); count1++;}; |
722 | } | 722 | } |
723 | if(count1>1) result=result/double(count1-1); else result=0.0; | 723 | if(count1>1) result=result/double(count1-1); else result=0.0; |
724 | return result; | 724 | return result; |
725 | }; | 725 | }; |
726 | 726 | ||
727 | double Sheet::functionSkew(const QString ¶m1, const QString ¶m2) | 727 | double Sheet::functionSkew(const QString ¶m1, const QString ¶m2) |
728 | { | 728 | { |
729 | int row1, col1, row2, col2, row, col; | 729 | int row1, col1, row2, col2, row, col; |
730 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 730 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
731 | double avg1=functionAvg(param1,param2); | 731 | double avg1=functionAvg(param1,param2); |
732 | double var1=sqrt(functionVariancePopulation(param1,param2)); | 732 | double var1=sqrt(functionVariancePopulation(param1,param2)); |
733 | if(var1==0.0) return 0.0; | 733 | if(var1==0.0) return 0.0; |
734 | double result=0, tempResult; | 734 | double result=0, tempResult; |
735 | int count1=0; | 735 | int count1=0; |
736 | bool ok; | 736 | bool ok; |
737 | for (row=row1; row<=row2; ++row) | 737 | for (row=row1; row<=row2; ++row) |
738 | for (col=col1; col<=col2; ++col) | 738 | for (col=col1; col<=col2; ++col) |
739 | { | 739 | { |
740 | tempResult=text(row, col).toDouble(&ok); | 740 | tempResult=text(row, col).toDouble(&ok); |
741 | if (ok) | 741 | if (ok) |
742 | { | 742 | { |
743 | result=result + (tempResult - avg1)*(tempResult - avg1)*(tempResult - avg1)/(var1*var1*var1); | 743 | result=result + (tempResult - avg1)*(tempResult - avg1)*(tempResult - avg1)/(var1*var1*var1); |
744 | count1++; | 744 | count1++; |
745 | }; | 745 | }; |
746 | } | 746 | } |
747 | if(count1>0) result=result/double(count1); else result=0.0; | 747 | if(count1>0) result=result/double(count1); else result=0.0; |
748 | return result; | 748 | return result; |
749 | }; | 749 | }; |
750 | 750 | ||
751 | double Sheet::functionKurt(const QString ¶m1, const QString ¶m2) | 751 | double Sheet::functionKurt(const QString ¶m1, const QString ¶m2) |
752 | { | 752 | { |
753 | int row1, col1, row2, col2, row, col; | 753 | int row1, col1, row2, col2, row, col; |
754 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 754 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
755 | double avg1=functionAvg(param1,param2); | 755 | double avg1=functionAvg(param1,param2); |
756 | double var1=sqrt(functionVariancePopulation(param1,param2)); | 756 | double var1=sqrt(functionVariancePopulation(param1,param2)); |
757 | if(var1==0.0) return 0.0; | 757 | if(var1==0.0) return 0.0; |
758 | double result=0, tempResult; | 758 | double result=0, tempResult; |
759 | int count1=0; | 759 | int count1=0; |
760 | bool ok; | 760 | bool ok; |
761 | for (row=row1; row<=row2; ++row) | 761 | for (row=row1; row<=row2; ++row) |
762 | for (col=col1; col<=col2; ++col) | 762 | for (col=col1; col<=col2; ++col) |
763 | { | 763 | { |
764 | tempResult=text(row, col).toDouble(&ok); | 764 | tempResult=text(row, col).toDouble(&ok); |
765 | if (ok) | 765 | if (ok) |
766 | { | 766 | { |
767 | result=result + (tempResult - avg1)*(tempResult - avg1)* | 767 | result=result + (tempResult - avg1)*(tempResult - avg1)* |
768 | (tempResult - avg1)*(tempResult - avg1)/(var1*var1*var1*var1); | 768 | (tempResult - avg1)*(tempResult - avg1)/(var1*var1*var1*var1); |
769 | count1++; | 769 | count1++; |
770 | }; | 770 | }; |
771 | } | 771 | } |
772 | if(count1>0) result=result/double(count1)-3.0; else result=0.0; | 772 | if(count1>0) result=result/double(count1)-3.0; else result=0.0; |
773 | return result; | 773 | return result; |
774 | }; | 774 | }; |
775 | 775 | ||
776 | 776 | ||
777 | 777 | ||
778 | double Sheet::functionSumSQ(const QString ¶m1, const QString ¶m2) | 778 | double Sheet::functionSumSQ(const QString ¶m1, const QString ¶m2) |
779 | { | 779 | { |
780 | int row1, col1, row2, col2, row, col; | 780 | int row1, col1, row2, col2, row, col; |
781 | double result=0, tempResult; | 781 | double result=0, tempResult; |
782 | bool ok; | 782 | bool ok; |
783 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) | 783 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) |
784 | { | 784 | { |
785 | for (row=row1; row<=row2; ++row) | 785 | for (row=row1; row<=row2; ++row) |
786 | for (col=col1; col<=col2; ++col) | 786 | for (col=col1; col<=col2; ++col) |
787 | { | 787 | { |
788 | tempResult=text(row, col).toDouble(&ok); | 788 | tempResult=text(row, col).toDouble(&ok); |
789 | if (ok) result+=tempResult*tempResult; | 789 | if (ok) result+=tempResult*tempResult; |
790 | } | 790 | } |
791 | return result; | 791 | return result; |
792 | }else | 792 | }else |
793 | { | 793 | { |
794 | double d1=0,d2=0; | 794 | double d1=0,d2=0; |
795 | d1=calculateVariable(param1).toDouble(&ok); | 795 | d1=calculateVariable(param1).toDouble(&ok); |
796 | d2=calculateVariable(param2).toDouble(&ok); | 796 | d2=calculateVariable(param2).toDouble(&ok); |
797 | return(d1*d1+d2*d2); | 797 | return(d1*d1+d2*d2); |
798 | }; | 798 | }; |
799 | return 0; | 799 | return 0; |
800 | } | 800 | } |
801 | 801 | ||
802 | 802 | ||
803 | 803 | ||
804 | double Sheet::functionMin(const QString ¶m1, const QString ¶m2) | 804 | double Sheet::functionMin(const QString ¶m1, const QString ¶m2) |
805 | { | 805 | { |
806 | int row1, col1, row2, col2, row, col; | 806 | int row1, col1, row2, col2, row, col; |
807 | double min=0, tempMin; | 807 | double min=0, tempMin; |
808 | bool ok, init=FALSE; | 808 | bool ok, init=FALSE; |
809 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) | 809 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) |
810 | { | 810 | { |
811 | for (row=row1; row<=row2; ++row) | 811 | for (row=row1; row<=row2; ++row) |
812 | for (col=col1; col<=col2; ++col) | 812 | for (col=col1; col<=col2; ++col) |
813 | { | 813 | { |
814 | tempMin=text(row, col).toDouble(&ok); | 814 | tempMin=text(row, col).toDouble(&ok); |
815 | if (ok && (!init || tempMin<min)) | 815 | if (ok && (!init || tempMin<min)) |
816 | { | 816 | { |
817 | min=tempMin; | 817 | min=tempMin; |
818 | init=TRUE; | 818 | init=TRUE; |
819 | } | 819 | } |
820 | } | 820 | } |
821 | return min; | 821 | return min; |
822 | }else | 822 | }else |
823 | { | 823 | { |
824 | double d1=0,d2=0; | 824 | double d1=0,d2=0; |
825 | d1=calculateVariable(param1).toDouble(&ok); | 825 | d1=calculateVariable(param1).toDouble(&ok); |
826 | d2=calculateVariable(param2).toDouble(&ok); | 826 | d2=calculateVariable(param2).toDouble(&ok); |
827 | if(d1<d2) return(d1); else return(d2); | 827 | if(d1<d2) return(d1); else return(d2); |
828 | }; | 828 | }; |
829 | return 0; | 829 | return 0; |
830 | } | 830 | } |
831 | 831 | ||
832 | double Sheet::functionMax(const QString ¶m1, const QString ¶m2) | 832 | double Sheet::functionMax(const QString ¶m1, const QString ¶m2) |
833 | { | 833 | { |
834 | int row1, col1, row2, col2, row, col; | 834 | int row1, col1, row2, col2, row, col; |
835 | double max=0, tempMax; | 835 | double max=0, tempMax; |
836 | bool ok, init=FALSE; | 836 | bool ok, init=FALSE; |
837 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) | 837 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) |
838 | { | 838 | { |
839 | for (row=row1; row<=row2; ++row) | 839 | for (row=row1; row<=row2; ++row) |
840 | for (col=col1; col<=col2; ++col) | 840 | for (col=col1; col<=col2; ++col) |
841 | { | 841 | { |
842 | tempMax=text(row, col).toDouble(&ok); | 842 | tempMax=text(row, col).toDouble(&ok); |
843 | if (ok && (!init || tempMax>max)) | 843 | if (ok && (!init || tempMax>max)) |
844 | { | 844 | { |
845 | max=tempMax; | 845 | max=tempMax; |
846 | init=TRUE; | 846 | init=TRUE; |
847 | } | 847 | } |
848 | }; | 848 | }; |
849 | return max; | 849 | return max; |
850 | }else | 850 | }else |
851 | { | 851 | { |
852 | double d1=0,d2=0; | 852 | double d1=0,d2=0; |
853 | d1=calculateVariable(param1).toDouble(&ok); | 853 | d1=calculateVariable(param1).toDouble(&ok); |
854 | d2=calculateVariable(param2).toDouble(&ok); | 854 | d2=calculateVariable(param2).toDouble(&ok); |
855 | if(d1>d2) return(d1); else return(d2); | 855 | if(d1>d2) return(d1); else return(d2); |
856 | }; | 856 | }; |
857 | return 0; | 857 | return 0; |
858 | } | 858 | } |
859 | 859 | ||
860 | double Sheet::functionAvg(const QString ¶m1, const QString ¶m2) | 860 | double Sheet::functionAvg(const QString ¶m1, const QString ¶m2) |
861 | { | 861 | { |
862 | double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); | 862 | double resultSum=functionSum(param1, param2), resultCount=functionCount(param1, param2); |
863 | return (resultCount>0 ? resultSum/resultCount : 0); | 863 | return (resultCount>0 ? resultSum/resultCount : 0); |
864 | } | 864 | } |
865 | 865 | ||
866 | double Sheet::functionCount(const QString ¶m1, const QString ¶m2) | 866 | double Sheet::functionCount(const QString ¶m1, const QString ¶m2) |
867 | { | 867 | { |
868 | int row1, col1, row2, col2, row, col; | 868 | int row1, col1, row2, col2, row, col; |
869 | int divider=0; | 869 | int divider=0; |
870 | bool ok; | 870 | bool ok; |
871 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) | 871 | if (findRange(param1, param2, &row1, &col1, &row2, &col2)) |
872 | { | 872 | { |
873 | for (row=row1; row<=row2; ++row) | 873 | for (row=row1; row<=row2; ++row) |
874 | for (col=col1; col<=col2; ++col) | 874 | for (col=col1; col<=col2; ++col) |
875 | { | 875 | { |
876 | text(row, col).toDouble(&ok); | 876 | text(row, col).toDouble(&ok); |
877 | if (ok) ++divider; | 877 | if (ok) ++divider; |
878 | }; | 878 | }; |
879 | return divider; | 879 | return divider; |
880 | }else | 880 | }else |
881 | { | 881 | { |
882 | double d1=0,d2=0;int ii=0; | 882 | double d1=0,d2=0;int ii=0; |
883 | d1=calculateVariable(param1).toDouble(&ok); | 883 | d1=calculateVariable(param1).toDouble(&ok); |
884 | if (ok) ii++; | 884 | if (ok) ii++; |
885 | d2=calculateVariable(param2).toDouble(&ok); | 885 | d2=calculateVariable(param2).toDouble(&ok); |
886 | if (ok) ii++; | 886 | if (ok) ii++; |
887 | return(ii); | 887 | return(ii); |
888 | }; | 888 | }; |
889 | return 0; | 889 | return 0; |
890 | } | 890 | } |
891 | 891 | ||
892 | double Sheet::functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3) | 892 | double Sheet::functionCountIf(const QString ¶m1, const QString ¶m2, const QString ¶m3) |
893 | { | 893 | { |
894 | int row1, col1, row2, col2, row, col; | 894 | int row1, col1, row2, col2, row, col; |
895 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; | 895 | if (!findRange(param1, param2, &row1, &col1, &row2, &col2)) return 0; |
896 | //same as count except check if each field is equal to param3 | 896 | //same as count except check if each field is equal to param3 |
897 | int divider=0; | 897 | int divider=0; |
898 | QString s2; | 898 | QString s2; |
899 | bool ok; | 899 | bool ok; |
900 | s2=calculateVariable(param3); | 900 | s2=calculateVariable(param3); |
901 | for (row=row1; row<=row2; ++row) | 901 | for (row=row1; row<=row2; ++row) |
902 | for (col=col1; col<=col2; ++col) | 902 | for (col=col1; col<=col2; ++col) |
903 | { | 903 | { |
904 | text(row, col).toDouble(&ok); | 904 | text(row, col).toDouble(&ok); |
905 | if (ok && (s2==text(row,col)) ) ++divider; | 905 | if (ok && (s2==text(row,col)) ) ++divider; |
906 | } | 906 | } |
907 | return divider; | 907 | return divider; |
908 | } | 908 | } |
909 | 909 | ||
910 | 910 | ||
911 | QString Sheet::calculateFunction(const QString &func, const QString ¶meters, int NumOfParams) | 911 | QString Sheet::calculateFunction(const QString &func, const QString ¶meters, int NumOfParams) |
912 | { | 912 | { |
913 | bool ok; | 913 | bool ok; |
914 | double val1=0.0,val2=0.0,val3=0.0; | 914 | double val1=0.0,val2=0.0,val3=0.0; |
915 | long int vali=0; | 915 | long int vali=0; |
916 | int w1,w2; | 916 | int w1,w2; |
917 | int row,col; | 917 | int row,col; |
918 | QString s1,s2; | 918 | QString s1,s2; |
919 | //basic functions | 919 | //basic functions |
920 | QString function; | 920 | QString function; |
921 | function=func.upper(); | 921 | function=func.upper(); |
922 | if (function=="+") | 922 | if (function=="+") |
923 | { | 923 | { |
924 | s1=calculateVariable(getParameter(parameters, 0)); | 924 | s1=calculateVariable(getParameter(parameters, 0)); |
925 | s2=calculateVariable(getParameter(parameters, 1)); | 925 | s2=calculateVariable(getParameter(parameters, 1)); |
926 | val1=s1.toDouble(&ok)+s2.toDouble(&ok); | 926 | val1=s1.toDouble(&ok)+s2.toDouble(&ok); |
927 | return QString::number(val1); | 927 | return QString::number(val1); |
928 | 928 | ||
929 | }; | 929 | }; |
930 | if (function=="-") | 930 | if (function=="-") |
931 | { | 931 | { |
932 | s1=calculateVariable(getParameter(parameters, 0)); | 932 | s1=calculateVariable(getParameter(parameters, 0)); |
933 | s2=calculateVariable(getParameter(parameters, 1)); | 933 | s2=calculateVariable(getParameter(parameters, 1)); |
934 | val1=s1.toDouble(&ok)-s2.toDouble(&ok); | 934 | val1=s1.toDouble(&ok)-s2.toDouble(&ok); |
935 | return QString::number(val1); | 935 | return QString::number(val1); |
936 | }; | 936 | }; |
937 | if (function=="*") | 937 | if (function=="*") |
938 | { | 938 | { |
939 | val1=calculateVariable( | 939 | val1=calculateVariable( |
940 | getParameter(parameters, 0)).toDouble(&ok) | 940 | getParameter(parameters, 0)).toDouble(&ok) |
941 | *calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 941 | *calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
942 | return QString::number(val1); | 942 | return QString::number(val1); |
943 | }; | 943 | }; |
944 | if (function=="/") | 944 | if (function=="/") |
945 | { | 945 | { |
946 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); | 946 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); |
947 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 947 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
948 | if(val2==0.0) return QString("Err101"); | 948 | if(val2==0.0) return QString("Err101"); |
949 | val1=val1/val2; | 949 | val1=val1/val2; |
950 | return QString::number(val1); | 950 | return QString::number(val1); |
951 | }; | 951 | }; |
952 | if (function==">") | 952 | if (function==">") |
953 | { | 953 | { |
954 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); | 954 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); |
955 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 955 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
956 | if(val1>val2) return QString::number(1); else return QString::number(0); | 956 | if(val1>val2) return QString::number(1); else return QString::number(0); |
957 | }; | 957 | }; |
958 | if (function=="<") | 958 | if (function=="<") |
959 | { | 959 | { |
960 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); | 960 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); |
961 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 961 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
962 | if(val1<val2) return QString::number(1); else return QString::number(0); | 962 | if(val1<val2) return QString::number(1); else return QString::number(0); |
963 | }; | 963 | }; |
964 | if (function==">=") | 964 | if (function==">=") |
965 | { | 965 | { |
966 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); | 966 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); |
967 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 967 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
968 | if(val1>=val2) return QString::number(1); else return QString::number(0); | 968 | if(val1>=val2) return QString::number(1); else return QString::number(0); |
969 | }; | 969 | }; |
970 | if (function=="<=") | 970 | if (function=="<=") |
971 | { | 971 | { |
972 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); | 972 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); |
973 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 973 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
974 | if(val1<=val2) return QString::number(1); else return QString::number(0); | 974 | if(val1<=val2) return QString::number(1); else return QString::number(0); |
975 | }; | 975 | }; |
976 | if (function=="!=") | 976 | if (function=="!=") |
977 | { | 977 | { |
978 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); | 978 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); |
979 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 979 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
980 | if(val1!=val2) return QString::number(1); else return QString::number(0); | 980 | if(val1!=val2) return QString::number(1); else return QString::number(0); |
981 | }; | 981 | }; |
982 | if (function=="=="||function=="=") | 982 | if (function=="=="||function=="=") |
983 | { | 983 | { |
984 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); | 984 | val1=calculateVariable(getParameter(parameters, 0)).toDouble(&ok); |
985 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); | 985 | val2=calculateVariable(getParameter(parameters, 1)).toDouble(&ok); |
986 | if(val1==val2) return QString::number(1); else return QString::number(0); | 986 | if(val1==val2) return QString::number(1); else return QString::number(0); |
987 | }; | 987 | }; |
988 | 988 | ||
989 | //LOGICAL / INFO | 989 | //LOGICAL / INFO |
990 | if (function=="ISBLANK") | 990 | if (function=="ISBLANK") |
991 | { | 991 | { |
992 | if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE)) | 992 | if(findRowColumn(getParameter(parameters, 0), &row, &col, FALSE)) |
993 | { | 993 | { |
994 | if(text(row,col).length()==0) val1=1; else val1=0; | 994 | if(text(row,col).length()==0) val1=1; else val1=0; |
995 | }else | 995 | }else |
996 | { | 996 | { |
997 | if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE)) | 997 | if(findRowColumn(calculateVariable(getParameter(parameters, 0)), &row,&col, FALSE)) |
998 | { | 998 | { |
999 | if(text(row,col).length()==0) val1=1; else val1=0; | 999 | if(text(row,col).length()==0) val1=1; else val1=0; |
1000 | }else | 1000 | }else |
1001 | { | 1001 | { |
1002 | val1=0; | 1002 | val1=0; |
1003 | }; | 1003 | }; |
1004 | }; | 1004 | }; |
1005 | return QString::number(val1); | 1005 | return QString::number(val1); |
1006 | }; | 1006 | }; |
1007 | 1007 | ||
1008 | 1008 | ||
1009 | if (function=="ISNUMBER") | 1009 | if (function=="ISNUMBER") |
1010 | { | 1010 | { |
1011 | if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE)) | 1011 | if(findRowColumn(getParameter(parameters, 0, TRUE, function), &row, &col, FALSE)) |
1012 | { | 1012 | { |
1013 | val1=text(row,col).toDouble(&ok); | 1013 | val1=text(row,col).toDouble(&ok); |
1014 | if(ok) val1=1; else val1=0; | 1014 | if(ok) val1=1; else val1=0; |
1015 | }else | 1015 | }else |
1016 | { | 1016 | { |
1017 | if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE)) | 1017 | if(findRowColumn(calculateVariable(getParameter(parameters, 0, TRUE, function)), &row,&col, FALSE)) |
1018 | { | 1018 | { |
1019 | val1=text(row,col).toDouble(&ok); | 1019 | val1=text(row,col).toDouble(&ok); |
1020 | if(ok) val1=1; else val1=0; | 1020 | if(ok) val1=1; else val1=0; |
1021 | }else | 1021 | }else |
1022 | { | 1022 | { |
1023 | val1=0; | 1023 | val1=0; |
1024 | }; | 1024 | }; |
1025 | }; | 1025 | }; |
1026 | return QString::number(val1); | 1026 | return QString::number(val1); |
1027 | }; | 1027 | }; |
1028 | if (function=="AND") | 1028 | if (function=="AND") |
1029 | { | 1029 | { |
1030 | vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok) | 1030 | vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok) |
1031 | & calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1031 | & calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1032 | return QString::number(vali); | 1032 | return QString::number(vali); |
1033 | }; | 1033 | }; |
1034 | if (function=="OR") | 1034 | if (function=="OR") |
1035 | { | 1035 | { |
1036 | vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok) | 1036 | vali=calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok) |
1037 | | calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1037 | | calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1038 | return QString::number(vali); | 1038 | return QString::number(vali); |
1039 | }; | 1039 | }; |
1040 | if (function=="NOT") | 1040 | if (function=="NOT") |
1041 | { | 1041 | { |
1042 | vali=!calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok); | 1042 | vali=!calculateVariable(getParameter(parameters, 0, TRUE, function)).toInt(&ok); |
1043 | return QString::number(vali); | 1043 | return QString::number(vali); |
1044 | }; | 1044 | }; |
1045 | 1045 | ||
1046 | // MATHEMATICAL FUNCTIONS | 1046 | // MATHEMATICAL FUNCTIONS |
1047 | if (function=="ABS") | 1047 | if (function=="ABS") |
1048 | { | 1048 | { |
1049 | val1=fabs(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1049 | val1=fabs(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1050 | return QString::number(val1); | 1050 | return QString::number(val1); |
1051 | }; | 1051 | }; |
1052 | if (function=="ACOS") | 1052 | if (function=="ACOS") |
1053 | { | 1053 | { |
1054 | val1=acos(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1054 | val1=acos(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1055 | return QString::number(val1); | 1055 | return QString::number(val1); |
1056 | }; | 1056 | }; |
1057 | if (function=="ACOSH") | 1057 | if (function=="ACOSH") |
1058 | { | 1058 | { |
1059 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1059 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1060 | if(val1<1.0) return QString::number(0); | 1060 | if(val1<1.0) return QString::number(0); |
1061 | val1=acosh(val1); | 1061 | val1=acosh(val1); |
1062 | return QString::number(val1); | 1062 | return QString::number(val1); |
1063 | }; | 1063 | }; |
1064 | if (function=="ASIN") | 1064 | if (function=="ASIN") |
1065 | { | 1065 | { |
1066 | val1=asin(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1066 | val1=asin(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1067 | return QString::number(val1); | 1067 | return QString::number(val1); |
1068 | }; | 1068 | }; |
1069 | if (function=="ASINH") | 1069 | if (function=="ASINH") |
1070 | { | 1070 | { |
1071 | val1=asinh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1071 | val1=asinh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1072 | return QString::number(val1); | 1072 | return QString::number(val1); |
1073 | }; | 1073 | }; |
1074 | if (function=="ATAN") | 1074 | if (function=="ATAN") |
1075 | { | 1075 | { |
1076 | val1=atan(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1076 | val1=atan(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1077 | return QString::number(val1); | 1077 | return QString::number(val1); |
1078 | }; | 1078 | }; |
1079 | if (function=="ATAN2") | 1079 | if (function=="ATAN2") |
1080 | { | 1080 | { |
1081 | val1=atan2(calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok), | 1081 | val1=atan2(calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok), |
1082 | calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1082 | calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1083 | return QString::number(val1); | 1083 | return QString::number(val1); |
1084 | }; | 1084 | }; |
1085 | if (function=="ATANH") | 1085 | if (function=="ATANH") |
1086 | { | 1086 | { |
1087 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1087 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1088 | if(val1<=-1.0 || val1>=1.0) return QString("Err101"); | 1088 | if(val1<=-1.0 || val1>=1.0) return QString("Err101"); |
1089 | val1=atanh(val1); | 1089 | val1=atanh(val1); |
1090 | return QString::number(val1); | 1090 | return QString::number(val1); |
1091 | }; | 1091 | }; |
1092 | if (function=="CEILING") | 1092 | if (function=="CEILING") |
1093 | { | 1093 | { |
1094 | // rounds up param1 to specified accuracy param2 | 1094 | // rounds up param1 to specified accuracy param2 |
1095 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1095 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1096 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1096 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1097 | if(val2==0.0) return QString::number(val1); | 1097 | if(val2==0.0) return QString::number(val1); |
1098 | val1=ceil(val1/val2)*val2; | 1098 | val1=ceil(val1/val2)*val2; |
1099 | return QString::number(val1); | 1099 | return QString::number(val1); |
1100 | }; | 1100 | }; |
1101 | if (function=="COS") | 1101 | if (function=="COS") |
1102 | { | 1102 | { |
1103 | val1=cos(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1103 | val1=cos(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1104 | return QString::number(val1); | 1104 | return QString::number(val1); |
1105 | }; | 1105 | }; |
1106 | if (function=="COSH") | 1106 | if (function=="COSH") |
1107 | { | 1107 | { |
1108 | val1=cosh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1108 | val1=cosh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1109 | return QString::number(val1); | 1109 | return QString::number(val1); |
1110 | }; | 1110 | }; |
1111 | if (function=="DEGREES") | 1111 | if (function=="DEGREES") |
1112 | { | 1112 | { |
1113 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)*180.0/M_PI; | 1113 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)*180.0/M_PI; |
1114 | return QString::number(val1); | 1114 | return QString::number(val1); |
1115 | }; | 1115 | }; |
1116 | if (function=="EXP") | 1116 | if (function=="EXP") |
1117 | { | 1117 | { |
1118 | val1=exp(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1118 | val1=exp(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1119 | return QString::number(val1); | 1119 | return QString::number(val1); |
1120 | }; | 1120 | }; |
1121 | if (function=="FACT") | 1121 | if (function=="FACT") |
1122 | { | 1122 | { |
1123 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1123 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1124 | val2=Factorial(val1); | 1124 | val2=Factorial(val1); |
1125 | return QString::number(val2); | 1125 | return QString::number(val2); |
1126 | }; | 1126 | }; |
1127 | if (function=="FLOOR") | 1127 | if (function=="FLOOR") |
1128 | { | 1128 | { |
1129 | // rounds down param1 to specified accuracy param2 | 1129 | // rounds down param1 to specified accuracy param2 |
1130 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1130 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1131 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1131 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1132 | if(val2==0.0) return QString::number(val1); | 1132 | if(val2==0.0) return QString::number(val1); |
1133 | val1=floor(val1/val2)*val2; | 1133 | val1=floor(val1/val2)*val2; |
1134 | return QString::number(val1); | 1134 | return QString::number(val1); |
1135 | }; | 1135 | }; |
1136 | if (function=="INT") | 1136 | if (function=="INT") |
1137 | { | 1137 | { |
1138 | // rounds down param1 | 1138 | // rounds down param1 |
1139 | val1=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1139 | val1=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1140 | return QString::number(val1); | 1140 | return QString::number(val1); |
1141 | }; | 1141 | }; |
1142 | if (function=="EVEN") | 1142 | if (function=="EVEN") |
1143 | { | 1143 | { |
1144 | //converts param1 to even | 1144 | //converts param1 to even |
1145 | vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1145 | vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1146 | if(vali % 2 !=0) val1=vali+1; else val1=vali; | 1146 | if(vali % 2 !=0) val1=vali+1; else val1=vali; |
1147 | return QString::number(val1); | 1147 | return QString::number(val1); |
1148 | }; | 1148 | }; |
1149 | if (function=="ODD") | 1149 | if (function=="ODD") |
1150 | { | 1150 | { |
1151 | //converts param1 to odd | 1151 | //converts param1 to odd |
1152 | vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1152 | vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1153 | if(vali % 2 !=0) val1=vali; else val1=vali+1; | 1153 | if(vali % 2 !=0) val1=vali; else val1=vali+1; |
1154 | return QString::number(val1); | 1154 | return QString::number(val1); |
1155 | }; | 1155 | }; |
1156 | if (function=="ISEVEN") | 1156 | if (function=="ISEVEN") |
1157 | { | 1157 | { |
1158 | //Is Even param1? | 1158 | //Is Even param1? |
1159 | vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1159 | vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1160 | if(vali % 2 == 0) val1=1; else val1=0; | 1160 | if(vali % 2 == 0) val1=1; else val1=0; |
1161 | return QString::number(val1); | 1161 | return QString::number(val1); |
1162 | }; | 1162 | }; |
1163 | if (function=="ISODD") | 1163 | if (function=="ISODD") |
1164 | { | 1164 | { |
1165 | //Is odd param1? | 1165 | //Is odd param1? |
1166 | vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1166 | vali=int(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1167 | if(vali % 2 == 0) val1=0; else val1=1; | 1167 | if(vali % 2 == 0) val1=0; else val1=1; |
1168 | return QString::number(val1); | 1168 | return QString::number(val1); |
1169 | }; | 1169 | }; |
1170 | if (function=="LN") | 1170 | if (function=="LN") |
1171 | { | 1171 | { |
1172 | // returns the natural logarithm of param1 | 1172 | // returns the natural logarithm of param1 |
1173 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1173 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1174 | if(val1<=0.0) return QString("Err101"); | 1174 | if(val1<=0.0) return QString("Err101"); |
1175 | val1=log(val1); | 1175 | val1=log(val1); |
1176 | return QString::number(val1); | 1176 | return QString::number(val1); |
1177 | }; | 1177 | }; |
1178 | if (function=="LOG10") | 1178 | if (function=="LOG10") |
1179 | { | 1179 | { |
1180 | // returns the base-10 logarithm of param1 | 1180 | // returns the base-10 logarithm of param1 |
1181 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1181 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1182 | if(val1<=0.0) return QString("Err101"); | 1182 | if(val1<=0.0) return QString("Err101"); |
1183 | val1=log10(val1); | 1183 | val1=log10(val1); |
1184 | return QString::number(val1); | 1184 | return QString::number(val1); |
1185 | }; | 1185 | }; |
1186 | if (function=="LOG") | 1186 | if (function=="LOG") |
1187 | { | 1187 | { |
1188 | // return the base-param2 logarithm of param1 | 1188 | // return the base-param2 logarithm of param1 |
1189 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1189 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1190 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1190 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1191 | if(val1<=0.0 || val2<=0.0 ) return QString("Err101"); | 1191 | if(val1<=0.0 || val2<=0.0 ) return QString("Err101"); |
1192 | val1=log(val1)/log(val2); | 1192 | val1=log(val1)/log(val2); |
1193 | return QString::number(val1); | 1193 | return QString::number(val1); |
1194 | }; | 1194 | }; |
1195 | if (function=="MOD") | 1195 | if (function=="MOD") |
1196 | { | 1196 | { |
1197 | // return the modulus of param1/param2 | 1197 | // return the modulus of param1/param2 |
1198 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1198 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1199 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1199 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1200 | if(val2==0.0) return QString("Err101"); | 1200 | if(val2==0.0) return QString("Err101"); |
1201 | val1=(int(val1) % int(val2)); | 1201 | val1=(int(val1) % int(val2)); |
1202 | return QString::number(val1); | 1202 | return QString::number(val1); |
1203 | }; | 1203 | }; |
1204 | if (function=="POWER") | 1204 | if (function=="POWER") |
1205 | { | 1205 | { |
1206 | // return the param1^param2 | 1206 | // return the param1^param2 |
1207 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1207 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1208 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1208 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1209 | if(val1<0.0 && (floor(val2)!=val2)) return QString("Err101"); | 1209 | if(val1<0.0 && (floor(val2)!=val2)) return QString("Err101"); |
1210 | val1=pow(val1,val2); | 1210 | val1=pow(val1,val2); |
1211 | return QString::number(val1); | 1211 | return QString::number(val1); |
1212 | }; | 1212 | }; |
1213 | if (function=="PI") | 1213 | if (function=="PI") |
1214 | { | 1214 | { |
1215 | return QString::number(M_PI); | 1215 | return QString::number(M_PI); |
1216 | }; | 1216 | }; |
1217 | if (function=="RADIANS") | 1217 | if (function=="RADIANS") |
1218 | { | 1218 | { |
1219 | // param1 deg->rad | 1219 | // param1 deg->rad |
1220 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)*M_PI/180.0; | 1220 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)*M_PI/180.0; |
1221 | return QString::number(val1); | 1221 | return QString::number(val1); |
1222 | }; | 1222 | }; |
1223 | if (function=="RAND") | 1223 | if (function=="RAND") |
1224 | { | 1224 | { |
1225 | // retuns random number 0>x>1 | 1225 | // retuns random number 0>x>1 |
1226 | srand((unsigned int)time((time_t *)NULL)); | 1226 | srand((unsigned int)time((time_t *)NULL)); |
1227 | val1=double(rand())/double(RAND_MAX); | 1227 | val1=double(rand())/double(RAND_MAX); |
1228 | return QString::number(val1); | 1228 | return QString::number(val1); |
1229 | }; | 1229 | }; |
1230 | if (function=="RANDBETWEEN") | 1230 | if (function=="RANDBETWEEN") |
1231 | { | 1231 | { |
1232 | // returns random number between param1>x>param2 | 1232 | // returns random number between param1>x>param2 |
1233 | //TOFIX: this is not ok because I think results is always int related. | 1233 | //TOFIX: this is not ok because I think results is always int related. |
1234 | srand((unsigned int)time((time_t *)NULL)); | 1234 | srand((unsigned int)time((time_t *)NULL)); |
1235 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1235 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1236 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1236 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1237 | val1=fmod(double(rand()),(val2-val1))+val1; | 1237 | val1=fmod(double(rand()),(val2-val1))+val1; |
1238 | return QString::number(val1); | 1238 | return QString::number(val1); |
1239 | }; | 1239 | }; |
1240 | if (function=="ROUND") | 1240 | if (function=="ROUND") |
1241 | { | 1241 | { |
1242 | // rounds down param1 to specified digits param2 (positive decimal digits) | 1242 | // rounds down param1 to specified digits param2 (positive decimal digits) |
1243 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1243 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1244 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1244 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1245 | val2=pow(10.0,-val2); | 1245 | val2=pow(10.0,-val2); |
1246 | val1=floor(val1/val2)*val2; | 1246 | val1=floor(val1/val2)*val2; |
1247 | return QString::number(val1); | 1247 | return QString::number(val1); |
1248 | }; | 1248 | }; |
1249 | if (function=="SIGN") | 1249 | if (function=="SIGN") |
1250 | { | 1250 | { |
1251 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1251 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1252 | if(val1>=0.0) return QString::number(1.0); else return QString::number(-1.0); | 1252 | if(val1>=0.0) return QString::number(1.0); else return QString::number(-1.0); |
1253 | }; | 1253 | }; |
1254 | if (function=="CHGSGN")//changes sign (for unary operator) | 1254 | if (function=="CHGSGN")//changes sign (for unary operator) |
1255 | { | 1255 | { |
1256 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1256 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1257 | return QString::number((-1.0)*val1); | 1257 | return QString::number((-1.0)*val1); |
1258 | }; | 1258 | }; |
1259 | if (function=="SIN") | 1259 | if (function=="SIN") |
1260 | { | 1260 | { |
1261 | val1=sin(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1261 | val1=sin(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1262 | return QString::number(val1); | 1262 | return QString::number(val1); |
1263 | }; | 1263 | }; |
1264 | if (function=="SINH") | 1264 | if (function=="SINH") |
1265 | { | 1265 | { |
1266 | val1=sinh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1266 | val1=sinh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1267 | return QString::number(val1); | 1267 | return QString::number(val1); |
1268 | }; | 1268 | }; |
1269 | if (function=="TAN") | 1269 | if (function=="TAN") |
1270 | { | 1270 | { |
1271 | val1=tan(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1271 | val1=tan(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1272 | return QString::number(val1); | 1272 | return QString::number(val1); |
1273 | }; | 1273 | }; |
1274 | if (function=="TANH") | 1274 | if (function=="TANH") |
1275 | { | 1275 | { |
1276 | val1=tanh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1276 | val1=tanh(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1277 | return QString::number(val1); | 1277 | return QString::number(val1); |
1278 | }; | 1278 | }; |
1279 | if (function=="SQRT") | 1279 | if (function=="SQRT") |
1280 | { | 1280 | { |
1281 | val1=sqrt(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); | 1281 | val1=sqrt(calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok)); |
1282 | return QString::number(val1); | 1282 | return QString::number(val1); |
1283 | }; | 1283 | }; |
1284 | 1284 | ||
1285 | 1285 | ||
1286 | // STRING FUNCTIONS | 1286 | // STRING FUNCTIONS |
1287 | if (function=="CONCATENATE") | 1287 | if (function=="CONCATENATE") |
1288 | { | 1288 | { |
1289 | // concatenates strings together | 1289 | // concatenates strings together |
1290 | w1=0; | 1290 | w1=0; |
1291 | s1=""; | 1291 | s1=""; |
1292 | while(getParameter(parameters, w1, FALSE, function)!="") //parse all params; | 1292 | while(getParameter(parameters, w1, FALSE, function)!="") //parse all params; |
1293 | { | 1293 | { |
1294 | s1=s1+calculateVariable(getParameter(parameters, w1)); | 1294 | s1=s1+calculateVariable(getParameter(parameters, w1)); |
1295 | w1++; | 1295 | w1++; |
1296 | }; | 1296 | }; |
1297 | return QString(s1); | 1297 | return QString(s1); |
1298 | }; | 1298 | }; |
1299 | if (function=="EXACT") | 1299 | if (function=="EXACT") |
1300 | { | 1300 | { |
1301 | // compare two string if they are exactly the same | 1301 | // compare two string if they are exactly the same |
1302 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1302 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1303 | s2=calculateVariable(getParameter(parameters, 1, TRUE, function)); | 1303 | s2=calculateVariable(getParameter(parameters, 1, TRUE, function)); |
1304 | if(s1==s2) return QString::number(1); else return QString::number(0); | 1304 | if(s1==s2) return QString::number(1); else return QString::number(0); |
1305 | }; | 1305 | }; |
1306 | if (function=="FIND") | 1306 | if (function=="FIND") |
1307 | { | 1307 | { |
1308 | // finds param1 in param2 from pos param3 and after | 1308 | // finds param1 in param2 from pos param3 and after |
1309 | // returns -1 if not found | 1309 | // returns -1 if not found |
1310 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1310 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1311 | s2=calculateVariable(getParameter(parameters, 1, TRUE, function)); | 1311 | s2=calculateVariable(getParameter(parameters, 1, TRUE, function)); |
1312 | vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); | 1312 | vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); |
1313 | val1=s2.find(s1,vali); | 1313 | val1=s2.find(s1,vali); |
1314 | return QString::number(val1); | 1314 | return QString::number(val1); |
1315 | }; | 1315 | }; |
1316 | if (function=="LEFT") | 1316 | if (function=="LEFT") |
1317 | { | 1317 | { |
1318 | // returns the param2 left chars from param1 string | 1318 | // returns the param2 left chars from param1 string |
1319 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1319 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1320 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1320 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1321 | s2=s1.left(vali); | 1321 | s2=s1.left(vali); |
1322 | return QString(s2); | 1322 | return QString(s2); |
1323 | }; | 1323 | }; |
1324 | if (function=="LEN") | 1324 | if (function=="LEN") |
1325 | { | 1325 | { |
1326 | // return the length of a string(param1) | 1326 | // return the length of a string(param1) |
1327 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1327 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1328 | return QString::number(s1.length()); | 1328 | return QString::number(s1.length()); |
1329 | }; | 1329 | }; |
1330 | if (function=="MID") | 1330 | if (function=="MID") |
1331 | { | 1331 | { |
1332 | // returns the mid word of string param1 with start param2 and len param3 | 1332 | // returns the mid word of string param1 with start param2 and len param3 |
1333 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1333 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1334 | w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1334 | w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1335 | w2=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); | 1335 | w2=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); |
1336 | s2=s1.mid(w1,w2); | 1336 | s2=s1.mid(w1,w2); |
1337 | return QString(s2); | 1337 | return QString(s2); |
1338 | }; | 1338 | }; |
1339 | if (function=="REPLACE") | 1339 | if (function=="REPLACE") |
1340 | { | 1340 | { |
1341 | //replace in param1 text in pos param2 and length param3 to newtext param4 | 1341 | //replace in param1 text in pos param2 and length param3 to newtext param4 |
1342 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1342 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1343 | w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1343 | w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1344 | w2=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); | 1344 | w2=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); |
1345 | s2=calculateVariable(getParameter(parameters, 3, TRUE, function)); | 1345 | s2=calculateVariable(getParameter(parameters, 3, TRUE, function)); |
1346 | if(w1<0 || w2<0) return QString(s1); | 1346 | if(w1<0 || w2<0) return QString(s1); |
1347 | s1=s1.left(w2-1)+s2+s1.right(s1.length()-w1-w2); | 1347 | s1=s1.left(w2-1)+s2+s1.right(s1.length()-w1-w2); |
1348 | return QString(s1); | 1348 | return QString(s1); |
1349 | }; | 1349 | }; |
1350 | if (function=="REPT") | 1350 | if (function=="REPT") |
1351 | { | 1351 | { |
1352 | //repeats param1 string param2 times | 1352 | //repeats param1 string param2 times |
1353 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1353 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1354 | w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1354 | w1=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1355 | for(w2=1;w2<=w1;w2++) | 1355 | for(w2=1;w2<=w1;w2++) |
1356 | { | 1356 | { |
1357 | s2=s2.append(s1); | 1357 | s2=s2.append(s1); |
1358 | }; | 1358 | }; |
1359 | return QString(s2); | 1359 | return QString(s2); |
1360 | }; | 1360 | }; |
1361 | if (function=="RIGHT") | 1361 | if (function=="RIGHT") |
1362 | { | 1362 | { |
1363 | // returns the param2 right chars from param1 string | 1363 | // returns the param2 right chars from param1 string |
1364 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1364 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1365 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1365 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1366 | s2=s1.right(vali); | 1366 | s2=s1.right(vali); |
1367 | return QString(s2); | 1367 | return QString(s2); |
1368 | }; | 1368 | }; |
1369 | if (function=="UPPER") | 1369 | if (function=="UPPER") |
1370 | { | 1370 | { |
1371 | // returns the upper param1 string | 1371 | // returns the upper param1 string |
1372 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1372 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1373 | s1=s1.upper(); | 1373 | s1=s1.upper(); |
1374 | return QString(s1); | 1374 | return QString(s1); |
1375 | }; | 1375 | }; |
1376 | if (function=="LOWER") | 1376 | if (function=="LOWER") |
1377 | { | 1377 | { |
1378 | // returns the lower param1 string | 1378 | // returns the lower param1 string |
1379 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); | 1379 | s1=calculateVariable(getParameter(parameters, 0, TRUE, function)); |
1380 | s1=s1.lower(); | 1380 | s1=s1.lower(); |
1381 | return QString(s1); | 1381 | return QString(s1); |
1382 | }; | 1382 | }; |
1383 | if (function=="IF") | 1383 | if (function=="IF") |
1384 | { | 1384 | { |
1385 | //usage: IF(param1,param2,param3) | 1385 | //usage: IF(param1,param2,param3) |
1386 | //returns param4 if true(param1)/ param5 if false(param1) | 1386 | //returns param4 if true(param1)/ param5 if false(param1) |
1387 | val1=getParameter(parameters, 0, TRUE, function).toDouble(&ok); | 1387 | val1=getParameter(parameters, 0, TRUE, function).toDouble(&ok); |
1388 | if(val1==1.0) | 1388 | if(val1==1.0) |
1389 | { | 1389 | { |
1390 | s1=calculateVariable(getParameter(parameters, 1, TRUE, function)); | 1390 | s1=calculateVariable(getParameter(parameters, 1, TRUE, function)); |
1391 | return QString(s1); | 1391 | return QString(s1); |
1392 | }else | 1392 | }else |
1393 | { | 1393 | { |
1394 | s1=calculateVariable(getParameter(parameters, 2, TRUE, function)); | 1394 | s1=calculateVariable(getParameter(parameters, 2, TRUE, function)); |
1395 | return QString(s1); | 1395 | return QString(s1); |
1396 | }; | 1396 | }; |
1397 | }; | 1397 | }; |
1398 | if (function=="SUM") | 1398 | if (function=="SUM") |
1399 | { | 1399 | { |
1400 | //NumOfParams | 1400 | //NumOfParams |
1401 | val2=0.0; | 1401 | val2=0.0; |
1402 | for(w1=1;w1<=(NumOfParams/2);w1++) | 1402 | for(w1=1;w1<=(NumOfParams/2);w1++) |
1403 | { | 1403 | { |
1404 | val1=functionSum(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); | 1404 | val1=functionSum(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); |
1405 | val2=val2+val1; | 1405 | val2=val2+val1; |
1406 | }; | 1406 | }; |
1407 | if(NumOfParams%2==1) | 1407 | if(NumOfParams%2==1) |
1408 | { | 1408 | { |
1409 | val2=val2+calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); | 1409 | val2=val2+calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); |
1410 | }; | 1410 | }; |
1411 | return QString::number(val2); | 1411 | return QString::number(val2); |
1412 | }; | 1412 | }; |
1413 | if (function=="INDEX") | 1413 | if (function=="INDEX") |
1414 | { | 1414 | { |
1415 | s1=functionIndex(getParameter(parameters,0,TRUE,function), getParameter(parameters, 1, TRUE, function), getParameter(parameters,2,TRUE,function).toInt(&ok)); | 1415 | s1=functionIndex(getParameter(parameters,0,TRUE,function), getParameter(parameters, 1, TRUE, function), getParameter(parameters,2,TRUE,function).toInt(&ok)); |
1416 | return QString(s1); | 1416 | return QString(s1); |
1417 | }; | 1417 | }; |
1418 | if (function=="SUMSQ") | 1418 | if (function=="SUMSQ") |
1419 | { | 1419 | { |
1420 | //NumOfParams | 1420 | //NumOfParams |
1421 | val2=0.0; | 1421 | val2=0.0; |
1422 | for(w1=1;w1<=(NumOfParams/2);w1++) | 1422 | for(w1=1;w1<=(NumOfParams/2);w1++) |
1423 | { | 1423 | { |
1424 | val1=functionSumSQ(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); | 1424 | val1=functionSumSQ(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); |
1425 | val2=val2+val1; | 1425 | val2=val2+val1; |
1426 | }; | 1426 | }; |
1427 | if(NumOfParams%2==1) | 1427 | if(NumOfParams%2==1) |
1428 | { | 1428 | { |
1429 | val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); | 1429 | val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); |
1430 | val2=val2+val1*val1; | 1430 | val2=val2+val1*val1; |
1431 | }; | 1431 | }; |
1432 | return QString::number(val2); | 1432 | return QString::number(val2); |
1433 | }; | 1433 | }; |
1434 | if (function=="COUNT") | 1434 | if (function=="COUNT") |
1435 | { | 1435 | { |
1436 | //NumOfParams | 1436 | //NumOfParams |
1437 | val2=0.0; | 1437 | val2=0.0; |
1438 | for(w1=1;w1<=(NumOfParams/2);w1++) | 1438 | for(w1=1;w1<=(NumOfParams/2);w1++) |
1439 | { | 1439 | { |
1440 | val1=functionCount(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); | 1440 | val1=functionCount(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); |
1441 | val2=val2+val1; | 1441 | val2=val2+val1; |
1442 | }; | 1442 | }; |
1443 | if(NumOfParams%2==1) | 1443 | if(NumOfParams%2==1) |
1444 | { | 1444 | { |
1445 | val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); | 1445 | val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); |
1446 | if(ok) val2=val2+1; | 1446 | if(ok) val2=val2+1; |
1447 | }; | 1447 | }; |
1448 | return QString::number(val2); | 1448 | return QString::number(val2); |
1449 | }; | 1449 | }; |
1450 | if (function=="COUNTIF") | 1450 | if (function=="COUNTIF") |
1451 | { | 1451 | { |
1452 | //NumOfParams | 1452 | //NumOfParams |
1453 | val1=functionCountIf(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function), getParameter(parameters, 2, TRUE, function)); | 1453 | val1=functionCountIf(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function), getParameter(parameters, 2, TRUE, function)); |
1454 | return QString::number(val1); | 1454 | return QString::number(val1); |
1455 | }; | 1455 | }; |
1456 | if (function=="MIN") | 1456 | if (function=="MIN") |
1457 | { | 1457 | { |
1458 | //NumOfParams | 1458 | //NumOfParams |
1459 | val2=0.0; | 1459 | val2=0.0; |
1460 | for(w1=1;w1<=(NumOfParams/2);w1++) | 1460 | for(w1=1;w1<=(NumOfParams/2);w1++) |
1461 | { | 1461 | { |
1462 | val1=functionMin(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); | 1462 | val1=functionMin(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); |
1463 | val2=val1; | 1463 | val2=val1; |
1464 | }; | 1464 | }; |
1465 | if(NumOfParams%2==1) | 1465 | if(NumOfParams%2==1) |
1466 | { | 1466 | { |
1467 | val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); | 1467 | val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); |
1468 | if(val1<val2) val2=val1; | 1468 | if(val1<val2) val2=val1; |
1469 | }; | 1469 | }; |
1470 | return QString::number(val2); | 1470 | return QString::number(val2); |
1471 | }; | 1471 | }; |
1472 | if (function=="MAX") | 1472 | if (function=="MAX") |
1473 | { | 1473 | { |
1474 | //NumOfParams | 1474 | //NumOfParams |
1475 | val2=0.0; | 1475 | val2=0.0; |
1476 | for(w1=1;w1<=(NumOfParams/2);w1++) | 1476 | for(w1=1;w1<=(NumOfParams/2);w1++) |
1477 | { | 1477 | { |
1478 | val1=functionMax(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); | 1478 | val1=functionMax(getParameter(parameters, (w1-1)*2, FALSE, function), getParameter(parameters, (w1-1)*2+1, TRUE, function)); |
1479 | val2=val1; | 1479 | val2=val1; |
1480 | }; | 1480 | }; |
1481 | if(NumOfParams%2==1) | 1481 | if(NumOfParams%2==1) |
1482 | { | 1482 | { |
1483 | val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); | 1483 | val1=calculateVariable(getParameter(parameters,NumOfParams-1,FALSE, function)).toDouble(&ok); |
1484 | if(val1>val2) val2=val1; | 1484 | if(val1>val2) val2=val1; |
1485 | }; | 1485 | }; |
1486 | return QString::number(val2); | 1486 | return QString::number(val2); |
1487 | }; | 1487 | }; |
1488 | if (function=="AVERAGE") | 1488 | if (function=="AVERAGE") |
1489 | { | 1489 | { |
1490 | val1=functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 1490 | val1=functionAvg(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
1491 | return QString::number(val1); | 1491 | return QString::number(val1); |
1492 | }; | 1492 | }; |
1493 | 1493 | ||
1494 | if(function=="BESSELI") | 1494 | if(function=="BESSELI") |
1495 | { | 1495 | { |
1496 | // BesselI (x,n) | 1496 | // BesselI (x,n) |
1497 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1497 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1498 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1498 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1499 | val2=BesselI(vali,val1); | 1499 | val2=BesselI(vali,val1); |
1500 | return QString::number(val2); | 1500 | return QString::number(val2); |
1501 | }; | 1501 | }; |
1502 | if(function=="BESSELJ") | 1502 | if(function=="BESSELJ") |
1503 | { | 1503 | { |
1504 | // BesselJ (x,n) | 1504 | // BesselJ (x,n) |
1505 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1505 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1506 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1506 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1507 | val2=BesselJ(vali,val1); | 1507 | val2=BesselJ(vali,val1); |
1508 | return QString::number(val2); | 1508 | return QString::number(val2); |
1509 | }; | 1509 | }; |
1510 | if(function=="BESSELK") | 1510 | if(function=="BESSELK") |
1511 | { | 1511 | { |
1512 | // BesselK (x,n) | 1512 | // BesselK (x,n) |
1513 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1513 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1514 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1514 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1515 | val2=BesselK(vali,val1); | 1515 | val2=BesselK(vali,val1); |
1516 | return QString::number(val2); | 1516 | return QString::number(val2); |
1517 | }; | 1517 | }; |
1518 | if(function=="BESSELY") | 1518 | if(function=="BESSELY") |
1519 | { | 1519 | { |
1520 | // BesselY (x,n) | 1520 | // BesselY (x,n) |
1521 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1521 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1522 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1522 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1523 | val2=BesselY(vali,val1); | 1523 | val2=BesselY(vali,val1); |
1524 | return QString::number(val2); | 1524 | return QString::number(val2); |
1525 | }; | 1525 | }; |
1526 | if(function=="GAMMALN") | 1526 | if(function=="GAMMALN") |
1527 | { | 1527 | { |
1528 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1528 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1529 | val2=GammaLn(val1); | 1529 | val2=GammaLn(val1); |
1530 | return QString::number(val2); | 1530 | return QString::number(val2); |
1531 | }; | 1531 | }; |
1532 | if(function=="ERF") | 1532 | if(function=="ERF") |
1533 | { | 1533 | { |
1534 | // ERF (a,b) | 1534 | // ERF (a,b) |
1535 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1535 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1536 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1536 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1537 | return QString::number(ErrorFunction(val2)-ErrorFunction(val1)); | 1537 | return QString::number(ErrorFunction(val2)-ErrorFunction(val1)); |
1538 | }; | 1538 | }; |
1539 | if(function=="ERFC") | 1539 | if(function=="ERFC") |
1540 | { | 1540 | { |
1541 | // ERFC (a,b) | 1541 | // ERFC (a,b) |
1542 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1542 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1543 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1543 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1544 | return QString::number(ErrorFunctionComplementary(val2)-ErrorFunctionComplementary(val1)); | 1544 | return QString::number(ErrorFunctionComplementary(val2)-ErrorFunctionComplementary(val1)); |
1545 | }; | 1545 | }; |
1546 | if(function=="POISSON") | 1546 | if(function=="POISSON") |
1547 | { | 1547 | { |
1548 | // POISSON DISTR(x,n,distr/desnt) | 1548 | // POISSON DISTR(x,n,distr/desnt) |
1549 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1549 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1550 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1550 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1551 | vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); | 1551 | vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); |
1552 | if(vali==1) | 1552 | if(vali==1) |
1553 | { | 1553 | { |
1554 | return QString::number(GammaQ(floor(val1)+1, val2)); | 1554 | return QString::number(GammaQ(floor(val1)+1, val2)); |
1555 | }else | 1555 | }else |
1556 | { | 1556 | { |
1557 | return QString::number(exp(-val2)*pow(val2,val1)/exp(GammaLn(val1+1.0))); | 1557 | return QString::number(exp(-val2)*pow(val2,val1)/exp(GammaLn(val1+1.0))); |
1558 | }; | 1558 | }; |
1559 | }; | 1559 | }; |
1560 | if(function=="CHIDIST") | 1560 | if(function=="CHIDIST") |
1561 | { | 1561 | { |
1562 | // POISSON CHIDIST(x,n,distr/density) | 1562 | // POISSON CHIDIST(x,n,distr/density) |
1563 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1563 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1564 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1564 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1565 | vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); | 1565 | vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); |
1566 | if(vali==1) | 1566 | if(vali==1) |
1567 | { | 1567 | { |
1568 | return QString::number(GammaP(val2/2.0,val1*val1/2.0)); | 1568 | return QString::number(GammaP(val2/2.0,val1*val1/2.0)); |
1569 | } else | 1569 | } else |
1570 | { | 1570 | { |
1571 | return QString::number( | 1571 | return QString::number( |
1572 | pow(val1,val2-1.0)*exp(-val1*val1/2)/ ( pow(2,val2/2.0-1.0)*exp(GammaLn(val2/2.0))) | 1572 | pow(val1,val2-1.0)*exp(-val1*val1/2)/ ( pow(2,val2/2.0-1.0)*exp(GammaLn(val2/2.0))) |
1573 | ); | 1573 | ); |
1574 | }; | 1574 | }; |
1575 | }; | 1575 | }; |
1576 | if(function=="CHI2DIST") | 1576 | if(function=="CHI2DIST") |
1577 | { | 1577 | { |
1578 | // POISSON CHISQUAREDIST(x,n,distr/density) | 1578 | // POISSON CHISQUAREDIST(x,n,distr/density) |
1579 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1579 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1580 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1580 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1581 | vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); | 1581 | vali=calculateVariable(getParameter(parameters, 2, TRUE, function)).toInt(&ok); |
1582 | if(vali==1) | 1582 | if(vali==1) |
1583 | { | 1583 | { |
1584 | return QString::number(GammaP(val2/2.0,val1/2.0)); | 1584 | return QString::number(GammaP(val2/2.0,val1/2.0)); |
1585 | } else | 1585 | } else |
1586 | { | 1586 | { |
1587 | return QString::number( | 1587 | return QString::number( |
1588 | pow(val1,val2/2.0-1.0)/(exp(val1/2.0)*pow(sqrt(2.0),val2)*exp(GammaLn(val2/2.0))) | 1588 | pow(val1,val2/2.0-1.0)/(exp(val1/2.0)*pow(sqrt(2.0),val2)*exp(GammaLn(val2/2.0))) |
1589 | ); | 1589 | ); |
1590 | }; | 1590 | }; |
1591 | }; | 1591 | }; |
1592 | if(function=="BETAI") | 1592 | if(function=="BETAI") |
1593 | { | 1593 | { |
1594 | // BETA INCOMPLETE BETA(x,a,b) | 1594 | // BETA INCOMPLETE BETA(x,a,b) |
1595 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1595 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1596 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1596 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1597 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); | 1597 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); |
1598 | return QString::number(BetaIncomplete(val2,val3,val1)); | 1598 | return QString::number(BetaIncomplete(val2,val3,val1)); |
1599 | }; | 1599 | }; |
1600 | if(function=="GAMMAP") | 1600 | if(function=="GAMMAP") |
1601 | { | 1601 | { |
1602 | // GammaP (x,a) | 1602 | // GammaP (x,a) |
1603 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1603 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1604 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1604 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1605 | return QString::number(GammaP(val2,val1)); | 1605 | return QString::number(GammaP(val2,val1)); |
1606 | }; | 1606 | }; |
1607 | if(function=="GAMMAQ") | 1607 | if(function=="GAMMAQ") |
1608 | { | 1608 | { |
1609 | // GammaQ (x,a) | 1609 | // GammaQ (x,a) |
1610 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1610 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1611 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1611 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1612 | return QString::number(GammaQ(val2,val1)); | 1612 | return QString::number(GammaQ(val2,val1)); |
1613 | }; | 1613 | }; |
1614 | if (function=="VAR") | 1614 | if (function=="VAR") |
1615 | { | 1615 | { |
1616 | val1=functionVariance(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 1616 | val1=functionVariance(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
1617 | return QString::number(val1); | 1617 | return QString::number(val1); |
1618 | }; | 1618 | }; |
1619 | if (function=="VARP") | 1619 | if (function=="VARP") |
1620 | { | 1620 | { |
1621 | val1=functionVariancePopulation(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 1621 | val1=functionVariancePopulation(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
1622 | return QString::number(val1); | 1622 | return QString::number(val1); |
1623 | }; | 1623 | }; |
1624 | if (function=="STDEV") | 1624 | if (function=="STDEV") |
1625 | { | 1625 | { |
1626 | val1=functionVariance(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 1626 | val1=functionVariance(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
1627 | if(val1<=0.0) return QString::number(0.0); | 1627 | if(val1<=0.0) return QString::number(0.0); |
1628 | return QString::number(sqrt(val1)); | 1628 | return QString::number(sqrt(val1)); |
1629 | }; | 1629 | }; |
1630 | if (function=="STDEVP") | 1630 | if (function=="STDEVP") |
1631 | { | 1631 | { |
1632 | val1=functionVariancePopulation(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 1632 | val1=functionVariancePopulation(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
1633 | if(val1<=0.0) return QString::number(0.0); | 1633 | if(val1<=0.0) return QString::number(0.0); |
1634 | return QString::number(sqrt(val1)); | 1634 | return QString::number(sqrt(val1)); |
1635 | }; | 1635 | }; |
1636 | if (function=="SKEW") | 1636 | if (function=="SKEW") |
1637 | { | 1637 | { |
1638 | val1=functionSkew(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 1638 | val1=functionSkew(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
1639 | return QString::number(val1); | 1639 | return QString::number(val1); |
1640 | }; | 1640 | }; |
1641 | if (function=="KURT") | 1641 | if (function=="KURT") |
1642 | { | 1642 | { |
1643 | val1=functionKurt(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); | 1643 | val1=functionKurt(getParameter(parameters, 0, TRUE, function), getParameter(parameters, 1, TRUE, function)); |
1644 | return QString::number(val1); | 1644 | return QString::number(val1); |
1645 | }; | 1645 | }; |
1646 | if(function=="GAMMADIST") | 1646 | if(function=="GAMMADIST") |
1647 | { | 1647 | { |
1648 | // GAMMADIST (x,alpha,beta,distribution?density1:0) | 1648 | // GAMMADIST (x,alpha,beta,distribution?density1:0) |
1649 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1649 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1650 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1650 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1651 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); | 1651 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); |
1652 | vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); | 1652 | vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); |
1653 | if(vali==1)//distribution | 1653 | if(vali==1)//distribution |
1654 | { | 1654 | { |
1655 | if(val3==0.0) return QString::number(0.0); | 1655 | if(val3==0.0) return QString::number(0.0); |
1656 | else | 1656 | else |
1657 | return QString::number(GammaP(val2,val1/val3)); | 1657 | return QString::number(GammaP(val2,val1/val3)); |
1658 | }else //density | 1658 | }else //density |
1659 | { | 1659 | { |
1660 | return QString::number( | 1660 | return QString::number( |
1661 | pow(val1,val2-1.0)*exp(-val1/val3) / (pow(val3,val2)*exp(GammaLn(val2))) | 1661 | pow(val1,val2-1.0)*exp(-val1/val3) / (pow(val3,val2)*exp(GammaLn(val2))) |
1662 | ); | 1662 | ); |
1663 | }; | 1663 | }; |
1664 | }; | 1664 | }; |
1665 | if(function=="BETADIST") | 1665 | if(function=="BETADIST") |
1666 | { | 1666 | { |
1667 | // BETADIST (z,alpha,beta,distribution?density1:0) | 1667 | // BETADIST (z,alpha,beta,distribution?density1:0) |
1668 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1668 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1669 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1669 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1670 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); | 1670 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); |
1671 | vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); | 1671 | vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); |
1672 | if(vali==1)//distribution | 1672 | if(vali==1)//distribution |
1673 | { | 1673 | { |
1674 | return QString::number(BetaIncomplete(val2,val3,val1)); | 1674 | return QString::number(BetaIncomplete(val2,val3,val1)); |
1675 | }else //density | 1675 | }else //density |
1676 | { | 1676 | { |
1677 | return QString::number( | 1677 | return QString::number( |
1678 | pow(val1,val2-1.0)*pow(1.0-val1,val3-1.0) / Beta(val2,val3) | 1678 | pow(val1,val2-1.0)*pow(1.0-val1,val3-1.0) / Beta(val2,val3) |
1679 | ); | 1679 | ); |
1680 | }; | 1680 | }; |
1681 | }; | 1681 | }; |
1682 | if(function=="FDIST") | 1682 | if(function=="FDIST") |
1683 | { | 1683 | { |
1684 | // FDIST (z,d1,d2,distribution?density1:0) | 1684 | // FDIST (z,d1,d2,distribution?density1:0) |
1685 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1685 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1686 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1686 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1687 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); | 1687 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); |
1688 | vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); | 1688 | vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); |
1689 | if(vali==1)//distribution | 1689 | if(vali==1)//distribution |
1690 | { | 1690 | { |
1691 | return QString::number( | 1691 | return QString::number( |
1692 | -BetaIncomplete(val3/2,val2/2,val3/(val3+val2*val1)) | 1692 | -BetaIncomplete(val3/2,val2/2,val3/(val3+val2*val1)) |
1693 | +BetaIncomplete(val3/2,val2/2,1) | 1693 | +BetaIncomplete(val3/2,val2/2,1) |
1694 | ); | 1694 | ); |
1695 | }else //density | 1695 | }else //density |
1696 | { | 1696 | { |
1697 | return QString::number( | 1697 | return QString::number( |
1698 | pow(val2,val2/2)*pow(val3,val3/2)*pow(val1,val2/2-1)/ | 1698 | pow(val2,val2/2)*pow(val3,val3/2)*pow(val1,val2/2-1)/ |
1699 | (pow(val3+val2*val1,(val2+val3)/2)*Beta(val2/2,val3/2)) | 1699 | (pow(val3+val2*val1,(val2+val3)/2)*Beta(val2/2,val3/2)) |
1700 | ); | 1700 | ); |
1701 | }; | 1701 | }; |
1702 | }; | 1702 | }; |
1703 | if(function=="NORMALDIST") | 1703 | if(function=="NORMALDIST") |
1704 | { | 1704 | { |
1705 | // NORMALDIST (x,m,s,distribution?density1:0) | 1705 | // NORMALDIST (x,m,s,distribution?density1:0) |
1706 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1706 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1707 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); | 1707 | val2=calculateVariable(getParameter(parameters, 1, TRUE, function)).toDouble(&ok); |
1708 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); | 1708 | val3=calculateVariable(getParameter(parameters, 2, TRUE, function)).toDouble(&ok); |
1709 | vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); | 1709 | vali=calculateVariable(getParameter(parameters, 3, TRUE, function)).toInt(&ok); |
1710 | if(vali==1)//distribution | 1710 | if(vali==1)//distribution |
1711 | { | 1711 | { |
1712 | return QString::number( | 1712 | return QString::number( |
1713 | (ErrorFunction((val1-val2)/(sqrt(2)*val3))+1)/2.0 | 1713 | (ErrorFunction((val1-val2)/(sqrt(2)*val3))+1)/2.0 |
1714 | ); | 1714 | ); |
1715 | }else //density | 1715 | }else //density |
1716 | { | 1716 | { |
1717 | return QString::number( | 1717 | return QString::number( |
1718 | exp(-pow(((val1-val2)/val3),2)/2)/(val3*sqrt(2*M_PI)) | 1718 | exp(-pow(((val1-val2)/val3),2)/2)/(val3*sqrt(2*M_PI)) |
1719 | ); | 1719 | ); |
1720 | }; | 1720 | }; |
1721 | }; | 1721 | }; |
1722 | if(function=="PHI") | 1722 | if(function=="PHI") |
1723 | { | 1723 | { |
1724 | // NORMALDIST (x,distribution?density1:0) with mean=0 s=1.0 | 1724 | // NORMALDIST (x,distribution?density1:0) with mean=0 s=1.0 |
1725 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); | 1725 | val1=calculateVariable(getParameter(parameters, 0, TRUE, function)).toDouble(&ok); |
1726 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); | 1726 | vali=calculateVariable(getParameter(parameters, 1, TRUE, function)).toInt(&ok); |
1727 | if(vali==1)//distribution | 1727 | if(vali==1)//distribution |
1728 | { | 1728 | { |
1729 | return QString::number( | 1729 | return QString::number( |
1730 | (ErrorFunction(val1/(sqrt(2)))+1)/2.0 | 1730 | (ErrorFunction(val1/(sqrt(2)))+1)/2.0 |
1731 | ); | 1731 | ); |
1732 | }else //density | 1732 | }else //density |
1733 | { | 1733 | { |
1734 | return QString::number( | 1734 | return QString::number( |
1735 | exp(-pow(val1,2)/2)/(sqrt(2*M_PI)) | 1735 | exp(-pow(val1,2)/2)/(sqrt(2*M_PI)) |
1736 | ); | 1736 | ); |
1737 | }; | 1737 | }; |
1738 | }; | 1738 | }; |
1739 | /* | 1739 | /* |
1740 | StudentTDistribution/: PDF[StudentTDistribution[n_], x_] := | 1740 | StudentTDistribution/: PDF[StudentTDistribution[n_], x_] := |
1741 | 1/(Sqrt[n] Beta[n/2, 1/2]) Sqrt[n/(n+x^2)]^(n+1) /; | 1741 | 1/(Sqrt[n] Beta[n/2, 1/2]) Sqrt[n/(n+x^2)]^(n+1) /; |
1742 | ParameterQ[StudentTDistribution[n]] | 1742 | ParameterQ[StudentTDistribution[n]] |
1743 | 1743 | ||
1744 | StudentTDistribution/: CDF[StudentTDistribution[n_], x_] := | 1744 | StudentTDistribution/: CDF[StudentTDistribution[n_], x_] := |
1745 | (1 + Sign[x] BetaRegularized[n/(n+x^2), 1, n/2, 1/2])/2 /; | 1745 | (1 + Sign[x] BetaRegularized[n/(n+x^2), 1, n/2, 1/2])/2 /; |
1746 | ParameterQ[StudentTDistribution[n]] | 1746 | ParameterQ[StudentTDistribution[n]] |
1747 | */ | 1747 | */ |
1748 | 1748 | ||
1749 | 1749 | ||
1750 | 1750 | ||
1751 | return 0; | 1751 | return 0; |
1752 | }; | 1752 | }; |
1753 | 1753 | ||
1754 | 1754 | ||
1755 | 1755 | ||
1756 | 1756 | ||
1757 | QString Sheet::dataParserHelper(const QString &data) | 1757 | QString Sheet::dataParserHelper(const QString &data) |
1758 | { | 1758 | { |
1759 | if(data.left(1)=="""" && data.right(1)=="""") return QString(data); | 1759 | if(data.left(1)=="""" && data.right(1)=="""") return QString(data); |
1760 | Expression exp1(data); | 1760 | Expression exp1(data); |
1761 | exp1.Parse(); | 1761 | exp1.Parse(); |
1762 | QStack<QString> stack1; | 1762 | QStack<QString> stack1; |
1763 | stack1.setAutoDelete(TRUE); | 1763 | stack1.setAutoDelete(TRUE); |
1764 | int i=0; | 1764 | int i=0; |
1765 | QString* s1; | 1765 | QString* s1; |
1766 | QString* s2=NULL; | 1766 | QString* s2=NULL; |
1767 | int* i1; | 1767 | int* i1; |
1768 | int args,tokentype; | 1768 | int args,tokentype; |
1769 | QString tempval; | 1769 | QString tempval; |
1770 | s1=exp1.CompiledBody.first();i1=exp1.CompiledBodyType.first(); | 1770 | s1=exp1.CompiledBody.first();i1=exp1.CompiledBodyType.first(); |
1771 | while(i<=(int)exp1.CompiledBody.count()-1) | 1771 | while(i<=(int)exp1.CompiledBody.count()-1) |
1772 | { | 1772 | { |
1773 | args= ((*i1) & 0xFF00)>>8; tokentype=(*i1) & 0x00FF; | 1773 | args= ((*i1) & 0xFF00)>>8; tokentype=(*i1) & 0x00FF; |
1774 | if(tokentype==NUMBER_TOKEN) | 1774 | if(tokentype==NUMBER_TOKEN) |
1775 | { | 1775 | { |
1776 | stack1.push(new QString(*s1)); | 1776 | stack1.push(new QString(*s1)); |
1777 | //printf("Parse:Number=%s\r\n",s1->latin1()); | 1777 | //printf("Parse:Number=%s\r\n",s1->latin1()); |
1778 | } | 1778 | } |
1779 | else if(tokentype==VARIABLE_TOKEN) | 1779 | else if(tokentype==VARIABLE_TOKEN) |
1780 | { | 1780 | { |
1781 | stack1.push(new QString(QString(*s1).upper())); | 1781 | stack1.push(new QString(QString(*s1).upper())); |
1782 | //printf("Parse:Var=%s\r\n",s1->latin1()); | 1782 | //printf("Parse:Var=%s\r\n",s1->latin1()); |
1783 | //here to put implementation of other types of variables except cell. | 1783 | //here to put implementation of other types of variables except cell. |
1784 | //for example names | 1784 | //for example names |
1785 | } | 1785 | } |
1786 | else if(tokentype==STRING_TOKEN) | 1786 | else if(tokentype==STRING_TOKEN) |
1787 | { | 1787 | { |
1788 | stack1.push(new QString(*s1)); | 1788 | stack1.push(new QString(*s1)); |
1789 | //printf("Parse:String=%s\r\n",s1->ascii()); | 1789 | //printf("Parse:String=%s\r\n",s1->ascii()); |
1790 | } | 1790 | } |
1791 | else if(tokentype==FUNCTION_TOKEN) | 1791 | else if(tokentype==FUNCTION_TOKEN) |
1792 | { | 1792 | { |
1793 | QString params=""; | 1793 | QString params=""; |
1794 | for(int w1=1;w1<=args;w1++) | 1794 | for(int w1=1;w1<=args;w1++) |
1795 | { | 1795 | { |
1796 | if((int)stack1.count()!=0) s2=stack1.pop(); | 1796 | if((int)stack1.count()!=0) s2=stack1.pop(); |
1797 | params=*s2+params;//args in reverse order | 1797 | params=*s2+params;//args in reverse order |
1798 | params=","+params; | 1798 | params=","+params; |
1799 | }; | 1799 | }; |
1800 | params=params.mid(1); | 1800 | params=params.mid(1); |
1801 | if(params==NULL) params="0"; | 1801 | if(params==NULL) params="0"; |
1802 | //printf("Parse:Func=%s, params=%s, stackcount=%d,args=%d\r\n" | 1802 | //printf("Parse:Func=%s, params=%s, stackcount=%d,args=%d\r\n" |
1803 | //,s1->latin1(),params.latin1(),stack1.count(),args); | 1803 | //,s1->latin1(),params.latin1(),stack1.count(),args); |
1804 | tempval=calculateFunction(*s1,params,args); | 1804 | tempval=calculateFunction(*s1,params,args); |
1805 | tempval=tempval; | 1805 | tempval=tempval; |
1806 | stack1.push(new QString(tempval)); | 1806 | stack1.push(new QString(tempval)); |
1807 | }; | 1807 | }; |
1808 | 1808 | ||
1809 | //loops to next token | 1809 | //loops to next token |
1810 | if(exp1.CompiledBody.next()!=NULL) s1=exp1.CompiledBody.current(); else break; | 1810 | if(exp1.CompiledBody.next()!=NULL) s1=exp1.CompiledBody.current(); else break; |
1811 | if(exp1.CompiledBodyType.next()!=NULL) i1=exp1.CompiledBodyType.current(); else break; | 1811 | if(exp1.CompiledBodyType.next()!=NULL) i1=exp1.CompiledBodyType.current(); else break; |
1812 | i++; | 1812 | i++; |
1813 | }; | 1813 | }; |
1814 | if((int)stack1.count()!=0)s2=stack1.pop(); else s2=new QString("!ERROR"); | 1814 | if((int)stack1.count()!=0)s2=stack1.pop(); else s2=new QString("!ERROR"); |
1815 | tempval=*s2; | 1815 | tempval=*s2; |
1816 | return(tempval); | 1816 | return(tempval); |
1817 | }; | 1817 | }; |
1818 | 1818 | ||
1819 | 1819 | ||
1820 | 1820 | ||
1821 | QString Sheet::dataParser(const QString &cell, const QString &data) | 1821 | QString Sheet::dataParser(const QString &cell, const QString &data) |
1822 | { | 1822 | { |
1823 | QString strippedData(data); | 1823 | QString strippedData(data); |
1824 | strippedData.replace(QRegExp("\\s"), ""); | 1824 | strippedData.replace(QRegExp("\\s"), ""); |
1825 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; | 1825 | if (strippedData.isEmpty() || strippedData[0]!='=') return data; |
1826 | if (listDataParser.find(cell)!=listDataParser.end()) return "0"; | 1826 | if (listDataParser.find(cell)!=listDataParser.end()) return "0"; |
1827 | listDataParser.append(cell); | 1827 | listDataParser.append(cell); |
1828 | // printf("DATAPARSER: data=%s, cell=%s\r\n",data.ascii(),cell.ascii()); | 1828 | // printf("DATAPARSER: data=%s, cell=%s\r\n",data.ascii(),cell.ascii()); |
1829 | strippedData=dataParserHelper(strippedData.remove(0, 1).replace(QRegExp(":"), ",")); | 1829 | strippedData=dataParserHelper(strippedData.remove(0, 1).replace(QRegExp(":"), ",")); |
1830 | 1830 | ||
1831 | int i=0; | 1831 | int i=0; |
1832 | QString tempParameter(getParameter(strippedData, i)), result=""; | 1832 | QString tempParameter(getParameter(strippedData, i)), result=""; |
1833 | do | 1833 | do |
1834 | { | 1834 | { |
1835 | result+=","+calculateVariable(tempParameter); | 1835 | result+=","+calculateVariable(tempParameter); |
1836 | tempParameter=getParameter(strippedData, ++i); | 1836 | tempParameter=getParameter(strippedData, ++i); |
1837 | } | 1837 | } |
1838 | while (!tempParameter.isNull()); | 1838 | while (!tempParameter.isNull()); |
1839 | listDataParser.remove(cell); | 1839 | listDataParser.remove(cell); |
1840 | return result.mid(1); | 1840 | return result.mid(1); |
1841 | } | 1841 | } |
1842 | 1842 | ||
1843 | 1843 | ||
1844 | void Sheet::setData(const QString &data) | 1844 | void Sheet::setData(const QString &data) |
1845 | { | 1845 | { |
1846 | setText(currentRow(), currentColumn(), data); | 1846 | setText(currentRow(), currentColumn(), data); |
1847 | slotCellChanged(currentRow(), currentColumn()); | 1847 | slotCellChanged(currentRow(), currentColumn()); |
1848 | activateNextCell(); | 1848 | activateNextCell(); |
1849 | } | 1849 | } |
1850 | 1850 | ||
1851 | QString Sheet::getData() | 1851 | QString Sheet::getData() |
1852 | { | 1852 | { |
1853 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); | 1853 | typeCellData *cellData=findCellData(currentRow(), currentColumn()); |
1854 | if (cellData) | 1854 | if (cellData) |
1855 | return cellData->data; | 1855 | return cellData->data; |
1856 | return ""; | 1856 | return ""; |
1857 | } | 1857 | } |
1858 | 1858 | ||
1859 | void Sheet::lockClicks(bool lock) | 1859 | void Sheet::lockClicks(bool lock) |
1860 | { | 1860 | { |
1861 | clicksLocked=lock; | 1861 | clicksLocked=lock; |
1862 | } | 1862 | } |
1863 | 1863 | ||
1864 | void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected) | 1864 | void Sheet::paintCell(QPainter *p, int row, int col, const QRect & cr, bool selected) |
1865 | { | 1865 | { |
1866 | if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; | 1866 | if (selected && row==currentRow() && col==currentColumn()) selected=FALSE; |
1867 | 1867 | ||
1868 | int sheetDataCurrent=sheetData.at(); | 1868 | int sheetDataCurrent=sheetData.at(); |
1869 | typeCellData *cellData=findCellData(row, col); | 1869 | typeCellData *cellData=findCellData(row, col); |
1870 | if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); | 1870 | if (sheetDataCurrent>=0) sheetData.at(sheetDataCurrent); |
1871 | if (!cellData) cellData=&defaultCellData; | 1871 | if (!cellData) cellData=&defaultCellData; |
1872 | if (selected) | 1872 | if (selected) |
1873 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); | 1873 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().highlight()); |
1874 | else | 1874 | else |
1875 | { | 1875 | { |
1876 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); | 1876 | p->fillRect(0, 0, cr.width(), cr.height(), colorGroup().base()); |
1877 | p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); | 1877 | p->fillRect(0, 0, cr.width(), cr.height(), cellData->background); |
1878 | } | 1878 | } |
1879 | 1879 | ||
1880 | QTableItem *cellItem=item(row, col); | 1880 | QTableItem *cellItem=item(row, col); |
1881 | if (cellItem) | 1881 | if (cellItem) |
1882 | { | 1882 | { |
1883 | p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); | 1883 | p->setPen(selected ? colorGroup().highlightedText() : cellData->fontColor); |
1884 | p->setFont(cellData->font); | 1884 | p->setFont(cellData->font); |
1885 | QString str=cellItem->text(); | 1885 | QString str=cellItem->text(); |
1886 | p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text()); | 1886 | p->drawText(2, 2, cr.width()-4, cr.height()-4, cellData->alignment, cellItem->text()); |
1887 | } | 1887 | } |
1888 | 1888 | ||
1889 | int rx=cr.width()-1, ry=cr.height()-1; | 1889 | int rx=cr.width()-1, ry=cr.height()-1; |
1890 | QPen pen(p->pen()); | 1890 | QPen pen(p->pen()); |
1891 | p->setPen(cellData->borders.right); | 1891 | p->setPen(cellData->borders.right); |
1892 | p->drawLine(rx, 0, rx, ry); | 1892 | p->drawLine(rx, 0, rx, ry); |
1893 | p->setPen(cellData->borders.bottom); | 1893 | p->setPen(cellData->borders.bottom); |
1894 | p->drawLine(0, ry, rx, ry); | 1894 | p->drawLine(0, ry, rx, ry); |
1895 | p->setPen(pen); | 1895 | p->setPen(pen); |
1896 | } | 1896 | } |
1897 | 1897 | ||
1898 | void Sheet::viewportMousePressEvent(QMouseEvent *e) | 1898 | void Sheet::viewportMousePressEvent(QMouseEvent *e) |
1899 | { | 1899 | { |
1900 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 1900 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
1901 | if (clicksLocked) | 1901 | if (clicksLocked) |
1902 | { | 1902 | { |
1903 | if (selectionNo<0) | 1903 | if (selectionNo<0) |
1904 | { | 1904 | { |
1905 | clearSelection(); | 1905 | clearSelection(); |
1906 | QTableSelection newSelection; | 1906 | QTableSelection newSelection; |
1907 | newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 1907 | newSelection.init(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
1908 | newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); | 1908 | newSelection.expandTo(newSelection.anchorRow(), newSelection.anchorCol()); |
1909 | selectionNo=addSelection(newSelection); | 1909 | selectionNo=addSelection(newSelection); |
1910 | } | 1910 | } |
1911 | } | 1911 | } |
1912 | else | 1912 | else |
1913 | QTable::contentsMousePressEvent(&ce); | 1913 | QTable::contentsMousePressEvent(&ce); |
1914 | } | 1914 | } |
1915 | 1915 | ||
1916 | void Sheet::viewportMouseMoveEvent(QMouseEvent *e) | 1916 | void Sheet::viewportMouseMoveEvent(QMouseEvent *e) |
1917 | { | 1917 | { |
1918 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 1918 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
1919 | if (clicksLocked) | 1919 | if (clicksLocked) |
1920 | { | 1920 | { |
1921 | if (selectionNo>=0) | 1921 | if (selectionNo>=0) |
1922 | { | 1922 | { |
1923 | QTableSelection oldSelection(selection(selectionNo)); | 1923 | QTableSelection oldSelection(selection(selectionNo)); |
1924 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 1924 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
1925 | if (!(oldSelection==selection(selectionNo))) | 1925 | if (!(oldSelection==selection(selectionNo))) |
1926 | { | 1926 | { |
1927 | removeSelection(selectionNo); | 1927 | removeSelection(selectionNo); |
1928 | selectionNo=addSelection(oldSelection); | 1928 | selectionNo=addSelection(oldSelection); |
1929 | } | 1929 | } |
1930 | } | 1930 | } |
1931 | } | 1931 | } |
1932 | else | 1932 | else |
1933 | QTable::contentsMouseMoveEvent(&ce); | 1933 | QTable::contentsMouseMoveEvent(&ce); |
1934 | } | 1934 | } |
1935 | 1935 | ||
1936 | void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) | 1936 | void Sheet::viewportMouseReleaseEvent(QMouseEvent *e) |
1937 | { | 1937 | { |
1938 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); | 1938 | QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); |
1939 | if (clicksLocked && selectionNo>=0) | 1939 | if (clicksLocked && selectionNo>=0) |
1940 | { | 1940 | { |
1941 | QTableSelection oldSelection(selection(selectionNo)); | 1941 | QTableSelection oldSelection(selection(selectionNo)); |
1942 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); | 1942 | oldSelection.expandTo(rowAt(ce.pos().y()), columnAt(ce.pos().x())); |
1943 | removeSelection(selectionNo); | 1943 | removeSelection(selectionNo); |
1944 | selectionNo=-1; | 1944 | selectionNo=-1; |
1945 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) | 1945 | if (oldSelection.topRow()==oldSelection.bottomRow() && oldSelection.leftCol()==oldSelection.rightCol()) |
1946 | emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())); | 1946 | emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())); |
1947 | else | 1947 | else |
1948 | emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol())); | 1948 | emit cellClicked(findCellName(oldSelection.topRow(), oldSelection.leftCol())+','+findCellName(oldSelection.bottomRow(), oldSelection.rightCol())); |
1949 | } | 1949 | } |
1950 | else | 1950 | else |
1951 | QTable::contentsMouseReleaseEvent(&ce); | 1951 | QTable::contentsMouseReleaseEvent(&ce); |
1952 | } | 1952 | } |
1953 | 1953 | ||
1954 | QString Sheet::findCellName(int row, int col) | 1954 | QString Sheet::findCellName(int row, int col) |
1955 | { | 1955 | { |
1956 | return (getHeaderString(col+1)+QString::number(row+1)); | 1956 | return (getHeaderString(col+1)+QString::number(row+1)); |
1957 | } | 1957 | } |
1958 | 1958 | ||
1959 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) | 1959 | void Sheet::copySheetData(QList<typeCellData> *destSheetData) |
1960 | { | 1960 | { |
1961 | typeCellData *tempCellData, *newCellData; | 1961 | typeCellData *tempCellData, *newCellData; |
1962 | destSheetData->clear(); | 1962 | destSheetData->clear(); |
1963 | 1963 | ||
1964 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 1964 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
1965 | { | 1965 | { |
1966 | newCellData=new typeCellData; | 1966 | newCellData=new typeCellData; |
1967 | *newCellData=*tempCellData; | 1967 | *newCellData=*tempCellData; |
1968 | destSheetData->append(newCellData); | 1968 | destSheetData->append(newCellData); |
1969 | } | 1969 | } |
1970 | } | 1970 | } |
1971 | 1971 | ||
1972 | void Sheet::setSheetData(QList<typeCellData> *srcSheetData) | 1972 | void Sheet::setSheetData(QList<typeCellData> *srcSheetData) |
1973 | { | 1973 | { |
1974 | typeCellData *tempCellData, *newCellData; | 1974 | typeCellData *tempCellData, *newCellData; |
1975 | 1975 | ||
1976 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 1976 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
1977 | { | 1977 | { |
1978 | clearCell(tempCellData->row, tempCellData->col); | 1978 | clearCell(tempCellData->row, tempCellData->col); |
1979 | updateCell(tempCellData->row, tempCellData->col); | 1979 | updateCell(tempCellData->row, tempCellData->col); |
1980 | } | 1980 | } |
1981 | sheetData.clear(); | 1981 | sheetData.clear(); |
1982 | 1982 | ||
1983 | for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) | 1983 | for (tempCellData=srcSheetData->first(); tempCellData; tempCellData=srcSheetData->next()) |
1984 | { | 1984 | { |
1985 | newCellData=new typeCellData; | 1985 | newCellData=new typeCellData; |
1986 | *newCellData=*tempCellData; | 1986 | *newCellData=*tempCellData; |
1987 | sheetData.append(newCellData); | 1987 | sheetData.append(newCellData); |
1988 | setText(newCellData->row, newCellData->col, dataParser(findCellName(newCellData->row, newCellData->col), newCellData->data)); | 1988 | setText(newCellData->row, newCellData->col, dataParser(findCellName(newCellData->row, newCellData->col), newCellData->data)); |
1989 | } | 1989 | } |
1990 | emit sheetModified(); | 1990 | emit sheetModified(); |
1991 | } | 1991 | } |
1992 | 1992 | ||
1993 | void Sheet::setName(const QString &name) | 1993 | void Sheet::setName(const QString &name) |
1994 | { | 1994 | { |
1995 | sheetName=name; | 1995 | sheetName=name; |
1996 | emit sheetModified(); | 1996 | emit sheetModified(); |
1997 | } | 1997 | } |
1998 | 1998 | ||
1999 | QString Sheet::getName() | 1999 | QString Sheet::getName() |
2000 | { | 2000 | { |
2001 | return sheetName; | 2001 | return sheetName; |
2002 | } | 2002 | } |
2003 | 2003 | ||
2004 | void Sheet::setBrush(int row, int col, const QBrush &brush) | 2004 | void Sheet::setBrush(int row, int col, const QBrush &brush) |
2005 | { | 2005 | { |
2006 | typeCellData *cellData=findCellData(row, col); | 2006 | typeCellData *cellData=findCellData(row, col); |
2007 | if (!cellData) cellData=createCellData(row, col); | 2007 | if (!cellData) cellData=createCellData(row, col); |
2008 | if (cellData) | 2008 | if (cellData) |
2009 | { | 2009 | { |
2010 | cellData->background=brush; | 2010 | cellData->background=brush; |
2011 | emit sheetModified(); | 2011 | emit sheetModified(); |
2012 | } | 2012 | } |
2013 | } | 2013 | } |
2014 | 2014 | ||
2015 | QBrush Sheet::getBrush(int row, int col) | 2015 | QBrush Sheet::getBrush(int row, int col) |
2016 | { | 2016 | { |
2017 | typeCellData *cellData=findCellData(row, col); | 2017 | typeCellData *cellData=findCellData(row, col); |
2018 | if (!cellData) cellData=&defaultCellData; | 2018 | if (!cellData) cellData=&defaultCellData; |
2019 | return cellData->background; | 2019 | return cellData->background; |
2020 | } | 2020 | } |
2021 | 2021 | ||
2022 | void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) | 2022 | void Sheet::setTextAlign(int row, int col, Qt::AlignmentFlags flags) |
2023 | { | 2023 | { |
2024 | typeCellData *cellData=findCellData(row, col); | 2024 | typeCellData *cellData=findCellData(row, col); |
2025 | if (!cellData) cellData=createCellData(row, col); | 2025 | if (!cellData) cellData=createCellData(row, col); |
2026 | if (cellData) | 2026 | if (cellData) |
2027 | { | 2027 | { |
2028 | cellData->alignment=flags; | 2028 | cellData->alignment=flags; |
2029 | emit sheetModified(); | 2029 | emit sheetModified(); |
2030 | } | 2030 | } |
2031 | } | 2031 | } |
2032 | 2032 | ||
2033 | Qt::AlignmentFlags Sheet::getAlignment(int row, int col) | 2033 | Qt::AlignmentFlags Sheet::getAlignment(int row, int col) |
2034 | { | 2034 | { |
2035 | typeCellData *cellData=findCellData(row, col); | 2035 | typeCellData *cellData=findCellData(row, col); |
2036 | if (!cellData) cellData=&defaultCellData; | 2036 | if (!cellData) cellData=&defaultCellData; |
2037 | return cellData->alignment; | 2037 | return cellData->alignment; |
2038 | } | 2038 | } |
2039 | 2039 | ||
2040 | void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color) | 2040 | void Sheet::setTextFont(int row, int col, const QFont &font, const QColor &color) |
2041 | { | 2041 | { |
2042 | typeCellData *cellData=findCellData(row, col); | 2042 | typeCellData *cellData=findCellData(row, col); |
2043 | if (!cellData) cellData=createCellData(row, col); | 2043 | if (!cellData) cellData=createCellData(row, col); |
2044 | if (cellData) | 2044 | if (cellData) |
2045 | { | 2045 | { |
2046 | cellData->font=font; | 2046 | cellData->font=font; |
2047 | cellData->fontColor=color; | 2047 | cellData->fontColor=color; |
2048 | emit sheetModified(); | 2048 | emit sheetModified(); |
2049 | } | 2049 | } |
2050 | } | 2050 | } |
2051 | 2051 | ||
2052 | QFont Sheet::getFont(int row, int col) | 2052 | QFont Sheet::getFont(int row, int col) |
2053 | { | 2053 | { |
2054 | typeCellData *cellData=findCellData(row, col); | 2054 | typeCellData *cellData=findCellData(row, col); |
2055 | if (!cellData) cellData=&defaultCellData; | 2055 | if (!cellData) cellData=&defaultCellData; |
2056 | return cellData->font; | 2056 | return cellData->font; |
2057 | } | 2057 | } |
2058 | 2058 | ||
2059 | QColor Sheet::getFontColor(int row, int col) | 2059 | QColor Sheet::getFontColor(int row, int col) |
2060 | { | 2060 | { |
2061 | typeCellData *cellData=findCellData(row, col); | 2061 | typeCellData *cellData=findCellData(row, col); |
2062 | if (!cellData) cellData=&defaultCellData; | 2062 | if (!cellData) cellData=&defaultCellData; |
2063 | return cellData->fontColor; | 2063 | return cellData->fontColor; |
2064 | } | 2064 | } |
2065 | 2065 | ||
2066 | void Sheet::setPen(int row, int col, int vertical, const QPen &pen) | 2066 | void Sheet::setPen(int row, int col, int vertical, const QPen &pen) |
2067 | { | 2067 | { |
2068 | typeCellData *cellData=findCellData(row, col); | 2068 | typeCellData *cellData=findCellData(row, col); |
2069 | if (!cellData) cellData=createCellData(row, col); | 2069 | if (!cellData) cellData=createCellData(row, col); |
2070 | if (cellData) | 2070 | if (cellData) |
2071 | { | 2071 | { |
2072 | if (vertical) | 2072 | if (vertical) |
2073 | cellData->borders.right=pen; | 2073 | cellData->borders.right=pen; |
2074 | else | 2074 | else |
2075 | cellData->borders.bottom=pen; | 2075 | cellData->borders.bottom=pen; |
2076 | emit sheetModified(); | 2076 | emit sheetModified(); |
2077 | } | 2077 | } |
2078 | } | 2078 | } |
2079 | 2079 | ||
2080 | QPen Sheet::getPen(int row, int col, int vertical) | 2080 | QPen Sheet::getPen(int row, int col, int vertical) |
2081 | { | 2081 | { |
2082 | typeCellData *cellData=findCellData(row, col); | 2082 | typeCellData *cellData=findCellData(row, col); |
2083 | if (!cellData) cellData=&defaultCellData; | 2083 | if (!cellData) cellData=&defaultCellData; |
2084 | return (vertical ? cellData->borders.right : cellData->borders.bottom); | 2084 | return (vertical ? cellData->borders.right : cellData->borders.bottom); |
2085 | } | 2085 | } |
2086 | 2086 | ||
2087 | void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) | 2087 | void Sheet::getSelection(int *row1, int *col1, int *row2, int *col2) |
2088 | { | 2088 | { |
2089 | int selectionNo=currentSelection(); | 2089 | int selectionNo=currentSelection(); |
2090 | if (selectionNo>=0) | 2090 | if (selectionNo>=0) |
2091 | { | 2091 | { |
2092 | QTableSelection selection(selection(selectionNo)); | 2092 | QTableSelection select(selection(selectionNo)); |
2093 | *row1=selection.topRow(); | 2093 | *row1=select.topRow(); |
2094 | *row2=selection.bottomRow(); | 2094 | *row2=select.bottomRow(); |
2095 | *col1=selection.leftCol(); | 2095 | *col1=select.leftCol(); |
2096 | *col2=selection.rightCol(); | 2096 | *col2=select.rightCol(); |
2097 | } | 2097 | } |
2098 | else | 2098 | else |
2099 | { | 2099 | { |
2100 | *row1=*row2=currentRow(); | 2100 | *row1=*row2=currentRow(); |
2101 | *col1=*col2=currentColumn(); | 2101 | *col1=*col2=currentColumn(); |
2102 | } | 2102 | } |
2103 | } | 2103 | } |
2104 | 2104 | ||
2105 | void Sheet::editClear() | 2105 | void Sheet::editClear() |
2106 | { | 2106 | { |
2107 | int row1, row2, col1, col2; | 2107 | int row1, row2, col1, col2; |
2108 | getSelection(&row1, &col1, &row2, &col2); | 2108 | getSelection(&row1, &col1, &row2, &col2); |
2109 | 2109 | ||
2110 | int row, col; | 2110 | int row, col; |
2111 | for (row=row1; row<=row2; ++row) | 2111 | for (row=row1; row<=row2; ++row) |
2112 | for (col=col1; col<=col2; ++col) | 2112 | for (col=col1; col<=col2; ++col) |
2113 | { | 2113 | { |
2114 | setText(row, col, ""); | 2114 | setText(row, col, ""); |
2115 | slotCellChanged(row, col); | 2115 | slotCellChanged(row, col); |
2116 | } | 2116 | } |
2117 | } | 2117 | } |
2118 | 2118 | ||
2119 | void Sheet::editCopy() | 2119 | void Sheet::editCopy() |
2120 | { | 2120 | { |
2121 | clipboardData.clear(); | 2121 | clipboardData.clear(); |
2122 | 2122 | ||
2123 | int row1, row2, col1, col2; | 2123 | int row1, row2, col1, col2; |
2124 | getSelection(&row1, &col1, &row2, &col2); | 2124 | getSelection(&row1, &col1, &row2, &col2); |
2125 | 2125 | ||
2126 | typeCellData *cellData, *newCellData; | 2126 | typeCellData *cellData, *newCellData; |
2127 | int row, col; | 2127 | int row, col; |
2128 | for (row=row1; row<=row2; ++row) | 2128 | for (row=row1; row<=row2; ++row) |
2129 | for (col=col1; col<=col2; ++col) | 2129 | for (col=col1; col<=col2; ++col) |
2130 | { | 2130 | { |
2131 | cellData=findCellData(row, col); | 2131 | cellData=findCellData(row, col); |
2132 | if (cellData) | 2132 | if (cellData) |
2133 | { | 2133 | { |
2134 | newCellData=new typeCellData; | 2134 | newCellData=new typeCellData; |
2135 | *newCellData=*cellData; | 2135 | *newCellData=*cellData; |
2136 | newCellData->row-=row1; | 2136 | newCellData->row-=row1; |
2137 | newCellData->col-=col1; | 2137 | newCellData->col-=col1; |
2138 | clipboardData.append(newCellData); | 2138 | clipboardData.append(newCellData); |
2139 | } | 2139 | } |
2140 | } | 2140 | } |
2141 | } | 2141 | } |
2142 | 2142 | ||
2143 | void Sheet::editCut() | 2143 | void Sheet::editCut() |
2144 | { | 2144 | { |
2145 | editCopy(); | 2145 | editCopy(); |
2146 | editClear(); | 2146 | editClear(); |
2147 | } | 2147 | } |
2148 | 2148 | ||
2149 | void Sheet::editPaste(bool onlyContents) | 2149 | void Sheet::editPaste(bool onlyContents) |
2150 | { | 2150 | { |
2151 | int row1=currentRow(), col1=currentColumn(); | 2151 | int row1=currentRow(), col1=currentColumn(); |
2152 | typeCellData *cellData, *tempCellData; | 2152 | typeCellData *cellData, *tempCellData; |
2153 | 2153 | ||
2154 | for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) | 2154 | for (tempCellData=clipboardData.first(); tempCellData; tempCellData=clipboardData.next()) |
2155 | { | 2155 | { |
2156 | cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1); | 2156 | cellData=findCellData(tempCellData->row+row1, tempCellData->col+col1); |
2157 | if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1); | 2157 | if (!cellData) cellData=createCellData(tempCellData->row+row1, tempCellData->col+col1); |
2158 | if (cellData) | 2158 | if (cellData) |
2159 | { | 2159 | { |
2160 | if (onlyContents) | 2160 | if (onlyContents) |
2161 | cellData->data=tempCellData->data; | 2161 | cellData->data=tempCellData->data; |
2162 | else | 2162 | else |
2163 | { | 2163 | { |
2164 | *cellData=*tempCellData; | 2164 | *cellData=*tempCellData; |
2165 | cellData->row+=row1; | 2165 | cellData->row+=row1; |
2166 | cellData->col+=col1; | 2166 | cellData->col+=col1; |
2167 | } | 2167 | } |
2168 | setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); | 2168 | setText(cellData->row, cellData->col, dataParser(findCellName(cellData->row, cellData->col), cellData->data)); |
2169 | emit sheetModified(); | 2169 | emit sheetModified(); |
2170 | } | 2170 | } |
2171 | } | 2171 | } |
2172 | } | 2172 | } |
2173 | 2173 | ||
2174 | void Sheet::insertRows(int no, bool allColumns) | 2174 | void Sheet::insertRows(int no, bool allColumns) |
2175 | { | 2175 | { |
2176 | setNumRows(numRows()+no); | 2176 | setNumRows(numRows()+no); |
2177 | 2177 | ||
2178 | typeCellData *tempCellData; | 2178 | typeCellData *tempCellData; |
2179 | int row=currentRow(), col=currentColumn(); | 2179 | int row=currentRow(), col=currentColumn(); |
2180 | 2180 | ||
2181 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 2181 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
2182 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 2182 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
2183 | { | 2183 | { |
2184 | clearCell(tempCellData->row, tempCellData->col); | 2184 | clearCell(tempCellData->row, tempCellData->col); |
2185 | tempCellData->row+=no; | 2185 | tempCellData->row+=no; |
2186 | } | 2186 | } |
2187 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 2187 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
2188 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) | 2188 | if (tempCellData->row>=row && (allColumns || tempCellData->col==col)) |
2189 | { | 2189 | { |
2190 | updateCell(tempCellData->row-no, tempCellData->col); | 2190 | updateCell(tempCellData->row-no, tempCellData->col); |
2191 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); | 2191 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
2192 | } | 2192 | } |
2193 | emit sheetModified(); | 2193 | emit sheetModified(); |
2194 | } | 2194 | } |
2195 | 2195 | ||
2196 | void Sheet::insertColumns(int no, bool allRows) | 2196 | void Sheet::insertColumns(int no, bool allRows) |
2197 | { | 2197 | { |
2198 | int noCols=numCols(); | 2198 | int noCols=numCols(); |
2199 | int newCols=noCols+no; | 2199 | int newCols=noCols+no; |
2200 | setNumCols(newCols); | 2200 | setNumCols(newCols); |
2201 | for (int i=noCols; i<newCols; ++i) | 2201 | for (int i=noCols; i<newCols; ++i) |
2202 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); | 2202 | horizontalHeader()->setLabel(i, getHeaderString(i+1), DEFAULT_COL_WIDTH); |
2203 | 2203 | ||
2204 | typeCellData *tempCellData; | 2204 | typeCellData *tempCellData; |
2205 | int col=currentColumn(), row=currentRow(); | 2205 | int col=currentColumn(), row=currentRow(); |
2206 | 2206 | ||
2207 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 2207 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
2208 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 2208 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
2209 | { | 2209 | { |
2210 | clearCell(tempCellData->row, tempCellData->col); | 2210 | clearCell(tempCellData->row, tempCellData->col); |
2211 | tempCellData->col+=no; | 2211 | tempCellData->col+=no; |
2212 | } | 2212 | } |
2213 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 2213 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
2214 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) | 2214 | if (tempCellData->col>=col && (allRows || tempCellData->row==row)) |
2215 | { | 2215 | { |
2216 | updateCell(tempCellData->row, tempCellData->col-no); | 2216 | updateCell(tempCellData->row, tempCellData->col-no); |
2217 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); | 2217 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
2218 | } | 2218 | } |
2219 | emit sheetModified(); | 2219 | emit sheetModified(); |
2220 | } | 2220 | } |
2221 | 2221 | ||
2222 | void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll) | 2222 | void Sheet::dataFindReplace(const QString &findStr, const QString &replaceStr, bool matchCase, bool allCells, bool entireCell, bool replace, bool replaceAll) |
2223 | { | 2223 | { |
2224 | typeCellData *tempCellData; | 2224 | typeCellData *tempCellData; |
2225 | int row1, col1, row2, col2; | 2225 | int row1, col1, row2, col2; |
2226 | getSelection(&row1, &col1, &row2, &col2); | 2226 | getSelection(&row1, &col1, &row2, &col2); |
2227 | bool found=FALSE; | 2227 | bool found=FALSE; |
2228 | 2228 | ||
2229 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) | 2229 | for (tempCellData=sheetData.first(); tempCellData; tempCellData=sheetData.next()) |
2230 | if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2)) | 2230 | if (allCells || (tempCellData->row>=row1 && tempCellData->row<=row2 && tempCellData->col>=col1 && tempCellData->col<=col2)) |
2231 | { | 2231 | { |
2232 | QTableItem *cellItem=item(tempCellData->row, tempCellData->col); | 2232 | QTableItem *cellItem=item(tempCellData->row, tempCellData->col); |
2233 | if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0)) | 2233 | if (cellItem && (entireCell ? (matchCase ? cellItem->text()==findStr : cellItem->text().upper()==findStr.upper()) : cellItem->text().find(findStr, 0, matchCase)>=0)) |
2234 | { | 2234 | { |
2235 | if (!found) | 2235 | if (!found) |
2236 | { | 2236 | { |
2237 | found=TRUE; | 2237 | found=TRUE; |
2238 | clearSelection(); | 2238 | clearSelection(); |
2239 | } | 2239 | } |
2240 | setCurrentCell(tempCellData->row, tempCellData->col); | 2240 | setCurrentCell(tempCellData->row, tempCellData->col); |
2241 | if (replace) | 2241 | if (replace) |
2242 | { | 2242 | { |
2243 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); | 2243 | tempCellData->data=cellItem->text().replace(QRegExp(findStr, matchCase), replaceStr); |
2244 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); | 2244 | setText(tempCellData->row, tempCellData->col, dataParser(findCellName(tempCellData->row, tempCellData->col), tempCellData->data)); |
2245 | } | 2245 | } |
2246 | if (!replace || !replaceAll) break; | 2246 | if (!replace || !replaceAll) break; |
2247 | } | 2247 | } |
2248 | } | 2248 | } |
2249 | 2249 | ||
2250 | if (found) | 2250 | if (found) |
2251 | { | 2251 | { |
2252 | if (replace) | 2252 | if (replace) |
2253 | slotCellChanged(currentRow(), currentColumn()); | 2253 | slotCellChanged(currentRow(), currentColumn()); |
2254 | } | 2254 | } |
2255 | else | 2255 | else |
2256 | QMessageBox::warning(this, tr("Error"), tr("Search key not found!")); | 2256 | QMessageBox::warning(this, tr("Error"), tr("Search key not found!")); |
2257 | } | 2257 | } |
2258 | 2258 | ||
2259 | // | 2259 | // |
2260 | // Static functions | 2260 | // Static functions |
2261 | // | 2261 | // |
2262 | 2262 | ||
2263 | QString Sheet::getHeaderString(int section) | 2263 | QString Sheet::getHeaderString(int section) |
2264 | { | 2264 | { |
2265 | if (section<1) return ""; | 2265 | if (section<1) return ""; |
2266 | return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); | 2266 | return getHeaderString((section-1)/26)+QChar('A'+(section-1)%26); |
2267 | } | 2267 | } |
2268 | 2268 | ||
2269 | int Sheet::getHeaderColumn(const QString §ion) | 2269 | int Sheet::getHeaderColumn(const QString §ion) |
2270 | { | 2270 | { |
2271 | if (section.isEmpty()) return 0; | 2271 | if (section.isEmpty()) return 0; |
2272 | return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26; | 2272 | return (section[section.length()-1]-'A'+1)+getHeaderColumn(section.left(section.length()-1))*26; |
2273 | } | 2273 | } |
2274 | 2274 | ||
2275 | 2275 | ||
2276 | //Expression Parser Class Definition | 2276 | //Expression Parser Class Definition |
2277 | 2277 | ||
2278 | 2278 | ||
2279 | QChar Expression::chunk0(void) | 2279 | QChar Expression::chunk0(void) |
2280 | { | 2280 | { |
2281 | if(chunk.length()>0) return(chunk[0]); else return('\0'); | 2281 | if(chunk.length()>0) return(chunk[0]); else return('\0'); |
2282 | }; | 2282 | }; |
2283 | 2283 | ||
2284 | Expression::Expression(QString expr1)// constructor | 2284 | Expression::Expression(QString expr1)// constructor |
2285 | { | 2285 | { |
2286 | Body=expr1; | 2286 | Body=expr1; |
2287 | SYMBOL="+-*/%^=()<>&|!,"; | 2287 | SYMBOL="+-*/%^=()<>&|!,"; |
2288 | MATHSYMBOL="+-*/%^=<>&|!,"; | 2288 | MATHSYMBOL="+-*/%^=<>&|!,"; |
2289 | // lnlim=1.0e-36; // Smallest number allowed | 2289 | // lnlim=1.0e-36; // Smallest number allowed |
2290 | // loglim=1.0e-10 ; // Smallest number allowed in call to log10() * | 2290 | // loglim=1.0e-10 ; // Smallest number allowed in call to log10() * |
2291 | ErrorFound=TRUE; | 2291 | ErrorFound=TRUE; |
2292 | n=0;chunk="";SymbGroup=NONE_TOKEN;InExpr=Body; | 2292 | n=0;chunk="";SymbGroup=NONE_TOKEN;InExpr=Body; |
2293 | ArgsOfFunc=0; | 2293 | ArgsOfFunc=0; |
2294 | CompiledBody.setAutoDelete(TRUE); | 2294 | CompiledBody.setAutoDelete(TRUE); |
2295 | CompiledBodyType.setAutoDelete(TRUE); | 2295 | CompiledBodyType.setAutoDelete(TRUE); |
2296 | //CompiledBody=QStringList(0); | 2296 | //CompiledBody=QStringList(0); |
2297 | }; | 2297 | }; |
2298 | 2298 | ||
2299 | bool Expression::isSymbol(QChar ch) | 2299 | bool Expression::isSymbol(QChar ch) |
2300 | { | 2300 | { |
2301 | int j = 0; | 2301 | int j = 0; |
2302 | while (j<=((int)SYMBOL.length()-1) && ch!=SYMBOL[j]) j++; | 2302 | while (j<=((int)SYMBOL.length()-1) && ch!=SYMBOL[j]) j++; |
2303 | if(j<((int)SYMBOL.length())) return true; else return false; | 2303 | if(j<((int)SYMBOL.length())) return true; else return false; |
2304 | }; | 2304 | }; |
2305 | 2305 | ||
2306 | bool Expression::isMathSymbol(QChar ch) | 2306 | bool Expression::isMathSymbol(QChar ch) |
2307 | { | 2307 | { |
2308 | int j = 0; | 2308 | int j = 0; |
2309 | while (j<=((int)MATHSYMBOL.length()-1) && ch!=MATHSYMBOL[j]) j++; | 2309 | while (j<=((int)MATHSYMBOL.length()-1) && ch!=MATHSYMBOL[j]) j++; |
2310 | if(j<((int)MATHSYMBOL.length())) return true; else return false; | 2310 | if(j<((int)MATHSYMBOL.length())) return true; else return false; |
2311 | }; | 2311 | }; |
2312 | 2312 | ||
2313 | void Expression::GetNext() | 2313 | void Expression::GetNext() |
2314 | { | 2314 | { |
2315 | chunk=""; | 2315 | chunk=""; |
2316 | if(n>=(int)InExpr.length()) return; | 2316 | if(n>=(int)InExpr.length()) return; |
2317 | while (InExpr[n]==' ') n++; | 2317 | while (InExpr[n]==' ') n++; |
2318 | if(InExpr[n]=='\"') | 2318 | if(InExpr[n]=='\"') |
2319 | { | 2319 | { |
2320 | while ( (n<(int)InExpr.length()) && (InExpr[n+1]!='\"') ) | 2320 | while ( (n<(int)InExpr.length()) && (InExpr[n+1]!='\"') ) |
2321 | { | 2321 | { |
2322 | printf("chunk=%s\r\n",chunk.latin1()); | 2322 | printf("chunk=%s\r\n",chunk.latin1()); |
2323 | chunk+=InExpr[n]; | 2323 | chunk+=InExpr[n]; |
2324 | n++; | 2324 | n++; |
2325 | }; | 2325 | }; |
2326 | chunk+=InExpr[n]; | 2326 | chunk+=InExpr[n]; |
2327 | printf("2\r\n"); | 2327 | printf("2\r\n"); |
2328 | SymbGroup=STRING_TOKEN; | 2328 | SymbGroup=STRING_TOKEN; |
2329 | } | 2329 | } |
2330 | else if (isSymbol(InExpr[n])) | 2330 | else if (isSymbol(InExpr[n])) |
2331 | { | 2331 | { |
2332 | SymbGroup=SYMBOL_TOKEN; | 2332 | SymbGroup=SYMBOL_TOKEN; |
2333 | chunk+=InExpr[n]; | 2333 | chunk+=InExpr[n]; |
2334 | n++; | 2334 | n++; |
2335 | if( (n<(int)InExpr.length()) && | 2335 | if( (n<(int)InExpr.length()) && |
2336 | isMathSymbol(InExpr[n-1]) && | 2336 | isMathSymbol(InExpr[n-1]) && |
2337 | isMathSymbol(InExpr[n]) ) | 2337 | isMathSymbol(InExpr[n]) ) |
2338 | { | 2338 | { |
2339 | SymbGroup=SYMBOL_TOKEN; | 2339 | SymbGroup=SYMBOL_TOKEN; |
2340 | chunk+=InExpr[n]; | 2340 | chunk+=InExpr[n]; |
2341 | n++; | 2341 | n++; |
2342 | }; | 2342 | }; |
2343 | } | 2343 | } |
2344 | else if ((InExpr[n].isLetter())||(InExpr[n]=='#')) | 2344 | else if ((InExpr[n].isLetter())||(InExpr[n]=='#')) |
2345 | { | 2345 | { |
2346 | while ( (n<(int)InExpr.length()) && !isSymbol(InExpr[n]) ) | 2346 | while ( (n<(int)InExpr.length()) && !isSymbol(InExpr[n]) ) |
2347 | { | 2347 | { |
2348 | if (!(InExpr[n]==' ')) chunk+=InExpr[n]; | 2348 | if (!(InExpr[n]==' ')) chunk+=InExpr[n]; |
2349 | n++; | 2349 | n++; |
2350 | }; | 2350 | }; |
2351 | if (InExpr[n]=='(') SymbGroup=FUNCTION_TOKEN; // function TOKEN | 2351 | if (InExpr[n]=='(') SymbGroup=FUNCTION_TOKEN; // function TOKEN |
2352 | else SymbGroup=VARIABLE_TOKEN; | 2352 | else SymbGroup=VARIABLE_TOKEN; |
2353 | } | 2353 | } |
2354 | else if((n<(int)InExpr.length()) && | 2354 | else if((n<(int)InExpr.length()) && |
2355 | ((InExpr[n].isDigit()) || (InExpr[n]=='.'))) | 2355 | ((InExpr[n].isDigit()) || (InExpr[n]=='.'))) |
2356 | { | 2356 | { |
2357 | while( n<(int)InExpr.length() ) | 2357 | while( n<(int)InExpr.length() ) |
2358 | { | 2358 | { |
2359 | if((InExpr[n].isDigit()) || InExpr[n]=='.') | 2359 | if((InExpr[n].isDigit()) || InExpr[n]=='.') |
2360 | { | 2360 | { |
2361 | chunk+=InExpr[n]; | 2361 | chunk+=InExpr[n]; |
2362 | SymbGroup=NUMBER_TOKEN; | 2362 | SymbGroup=NUMBER_TOKEN; |
2363 | n++; | 2363 | n++; |
2364 | } | 2364 | } |
2365 | else if(InExpr[n]=='e') | 2365 | else if(InExpr[n]=='e') |
2366 | { | 2366 | { |
2367 | if((n+1)<(int)InExpr.length()) | 2367 | if((n+1)<(int)InExpr.length()) |
2368 | { | 2368 | { |
2369 | if(InExpr[n+1]=='-' || InExpr[n+1]=='+' || InExpr[n+1].isDigit()) | 2369 | if(InExpr[n+1]=='-' || InExpr[n+1]=='+' || InExpr[n+1].isDigit()) |
2370 | { | 2370 | { |
2371 | chunk+=InExpr[n]; | 2371 | chunk+=InExpr[n]; |
2372 | chunk+=InExpr[n+1]; | 2372 | chunk+=InExpr[n+1]; |
2373 | SymbGroup=NUMBER_TOKEN; | 2373 | SymbGroup=NUMBER_TOKEN; |
2374 | n+=2; | 2374 | n+=2; |
2375 | } | 2375 | } |
2376 | } | 2376 | } |
2377 | else | 2377 | else |
2378 | { | 2378 | { |
2379 | break; | 2379 | break; |
2380 | } | 2380 | } |
2381 | } | 2381 | } |
2382 | else | 2382 | else |
2383 | { | 2383 | { |
2384 | break; | 2384 | break; |
2385 | } | 2385 | } |
2386 | }//while | 2386 | }//while |
2387 | }//else if | 2387 | }//else if |
2388 | };//end function | 2388 | };//end function |
2389 | 2389 | ||
2390 | 2390 | ||
2391 | void Expression::First() | 2391 | void Expression::First() |
2392 | { | 2392 | { |
2393 | GetNext(); | 2393 | GetNext(); |
2394 | if (!(chunk=="") && !ErrorFound) Third(); | 2394 | if (!(chunk=="") && !ErrorFound) Third(); |
2395 | else ErrorFound = true; | 2395 | else ErrorFound = true; |
2396 | }; | 2396 | }; |
2397 | 2397 | ||
2398 | void Expression::Third() | 2398 | void Expression::Third() |
2399 | { | 2399 | { |
2400 | QChar sign, secS='\0'; | 2400 | QChar sign, secS='\0'; |
2401 | Fourth(); | 2401 | Fourth(); |
2402 | sign = chunk0(); | 2402 | sign = chunk0(); |
2403 | if((int)chunk.length()>1) secS=chunk[1]; | 2403 | if((int)chunk.length()>1) secS=chunk[1]; |
2404 | while( sign == '+' || sign == '-'|| | 2404 | while( sign == '+' || sign == '-'|| |
2405 | sign == '<' || sign == '>'|| sign == '%'|| | 2405 | sign == '<' || sign == '>'|| sign == '%'|| |
2406 | sign == '&' || sign == '|' || sign == '!' || sign == '=' | 2406 | sign == '&' || sign == '|' || sign == '!' || sign == '=' |
2407 | ) | 2407 | ) |
2408 | { | 2408 | { |
2409 | GetNext(); | 2409 | GetNext(); |
2410 | Fourth(); | 2410 | Fourth(); |
2411 | QString name; | 2411 | QString name; |
2412 | if( sign == '+' ) name= "+" ; | 2412 | if( sign == '+' ) name= "+" ; |
2413 | else if(sign=='-') name= "-" ; | 2413 | else if(sign=='-') name= "-" ; |
2414 | else if(sign=='>' && secS=='\0') name= ">" ; | 2414 | else if(sign=='>' && secS=='\0') name= ">" ; |
2415 | else if(sign=='<' && secS=='\0') name= "<" ; | 2415 | else if(sign=='<' && secS=='\0') name= "<" ; |
2416 | else if(sign=='=' && secS=='=') name= "==" ; | 2416 | else if(sign=='=' && secS=='=') name= "==" ; |
2417 | else if(sign=='!' && secS=='=') name= "!=" ; | 2417 | else if(sign=='!' && secS=='=') name= "!=" ; |
2418 | else if(sign=='>' && secS=='=') name= ">=" ; | 2418 | else if(sign=='>' && secS=='=') name= ">=" ; |
2419 | else if(sign=='<' && secS=='=') name= "<=" ; | 2419 | else if(sign=='<' && secS=='=') name= "<=" ; |
2420 | else if(sign=='&' && secS=='&') name= "AND" ; | 2420 | else if(sign=='&' && secS=='&') name= "AND" ; |
2421 | else if(sign=='|' && secS=='|') name= "OR" ; | 2421 | else if(sign=='|' && secS=='|') name= "OR" ; |
2422 | else if(sign=='%') name= "MOD" ; | 2422 | else if(sign=='%') name= "MOD" ; |
2423 | CompiledBody.append(new QString(name)); // not sure if pushed in the back. | 2423 | CompiledBody.append(new QString(name)); // not sure if pushed in the back. |
2424 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); //2 argument functions | 2424 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); //2 argument functions |
2425 | sign = chunk0(); | 2425 | sign = chunk0(); |
2426 | } | 2426 | } |
2427 | }; | 2427 | }; |
2428 | 2428 | ||
2429 | void Expression::Fourth() | 2429 | void Expression::Fourth() |
2430 | { | 2430 | { |
2431 | QChar sign; | 2431 | QChar sign; |
2432 | Fifth(); | 2432 | Fifth(); |
2433 | sign = chunk0(); | 2433 | sign = chunk0(); |
2434 | while( sign == '*' || sign == '/' ) | 2434 | while( sign == '*' || sign == '/' ) |
2435 | { | 2435 | { |
2436 | GetNext(); | 2436 | GetNext(); |
2437 | Fifth(); | 2437 | Fifth(); |
2438 | QString name; | 2438 | QString name; |
2439 | if( sign == '*' ) name= "*" ; | 2439 | if( sign == '*' ) name= "*" ; |
2440 | else name= "/" ; | 2440 | else name= "/" ; |
2441 | CompiledBody.append(new QString(name)); | 2441 | CompiledBody.append(new QString(name)); |
2442 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); //2 arguments functions | 2442 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); //2 arguments functions |
2443 | sign = chunk0(); | 2443 | sign = chunk0(); |
2444 | } | 2444 | } |
2445 | }; | 2445 | }; |
2446 | 2446 | ||
2447 | void Expression::Fifth() | 2447 | void Expression::Fifth() |
2448 | { | 2448 | { |
2449 | Sixth(); | 2449 | Sixth(); |
2450 | //if(chunk.Length==0) return; | 2450 | //if(chunk.Length==0) return; |
2451 | if( chunk0() == '^' ) | 2451 | if( chunk0() == '^' ) |
2452 | { | 2452 | { |
2453 | GetNext(); | 2453 | GetNext(); |
2454 | Fifth(); | 2454 | Fifth(); |
2455 | CompiledBody.append(new QString("POWER")); | 2455 | CompiledBody.append(new QString("POWER")); |
2456 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); // 2 argument functions | 2456 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 2<<8)); // 2 argument functions |
2457 | } | 2457 | } |
2458 | }; | 2458 | }; |
2459 | 2459 | ||
2460 | void Expression::Sixth() | 2460 | void Expression::Sixth() |
2461 | { | 2461 | { |
2462 | char sign; | 2462 | char sign; |
2463 | sign = ' '; | 2463 | sign = ' '; |
2464 | if(SymbGroup== SYMBOL_TOKEN && | 2464 | if(SymbGroup== SYMBOL_TOKEN && |
2465 | chunk0() == '+' || chunk0() == '-' | chunk0() == '!') | 2465 | chunk0() == '+' || chunk0() == '-' | chunk0() == '!') |
2466 | { | 2466 | { |
2467 | sign = chunk0(); | 2467 | sign = chunk0(); |
2468 | GetNext(); | 2468 | GetNext(); |
2469 | } | 2469 | } |
2470 | Seventh(); | 2470 | Seventh(); |
2471 | if( sign == '-' ) | 2471 | if( sign == '-' ) |
2472 | { | 2472 | { |
2473 | CompiledBody.append(new QString("CHGSGN")); // unary minus | 2473 | CompiledBody.append(new QString("CHGSGN")); // unary minus |
2474 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 1<<8)); //1 argument | 2474 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 1<<8)); //1 argument |
2475 | } | 2475 | } |
2476 | if( sign == '!' ) | 2476 | if( sign == '!' ) |
2477 | { | 2477 | { |
2478 | CompiledBody.append(new QString("NOT")); // unary minus | 2478 | CompiledBody.append(new QString("NOT")); // unary minus |
2479 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 1<<8)); //1 argument | 2479 | CompiledBodyType.append(new int(FUNCTION_TOKEN | 1<<8)); //1 argument |
2480 | } | 2480 | } |
2481 | }; | 2481 | }; |
2482 | 2482 | ||
2483 | 2483 | ||
2484 | void Expression::Seventh() | 2484 | void Expression::Seventh() |
2485 | { | 2485 | { |
2486 | if( chunk0() == '(' && SymbGroup==SYMBOL_TOKEN) | 2486 | if( chunk0() == '(' && SymbGroup==SYMBOL_TOKEN) |
2487 | { | 2487 | { |
2488 | GetNext(); | 2488 | GetNext(); |
2489 | Third(); //parse the insides until we get a ')' | 2489 | Third(); //parse the insides until we get a ')' |
2490 | if (chunk0() != ')') ErrorFound = true; | 2490 | if (chunk0() != ')') ErrorFound = true; |
2491 | GetNext(); | 2491 | GetNext(); |
2492 | } | 2492 | } |
2493 | else Eighth(); | 2493 | else Eighth(); |
2494 | }; | 2494 | }; |
2495 | 2495 | ||
2496 | void Expression::Eighth() | 2496 | void Expression::Eighth() |
2497 | { | 2497 | { |
2498 | if ( SymbGroup== NUMBER_TOKEN ) | 2498 | if ( SymbGroup== NUMBER_TOKEN ) |
2499 | { | 2499 | { |
2500 | CompiledBody.append(new QString(chunk)); | 2500 | CompiledBody.append(new QString(chunk)); |
2501 | CompiledBodyType.append(new int(NUMBER_TOKEN)); | 2501 | CompiledBodyType.append(new int(NUMBER_TOKEN)); |
2502 | GetNext(); | 2502 | GetNext(); |
2503 | } | 2503 | } |
2504 | else if ( SymbGroup== VARIABLE_TOKEN ) | 2504 | else if ( SymbGroup== VARIABLE_TOKEN ) |
2505 | { | 2505 | { |
2506 | CompiledBody.append(new QString(chunk)); | 2506 | CompiledBody.append(new QString(chunk)); |
2507 | CompiledBodyType.append(new int(VARIABLE_TOKEN)); | 2507 | CompiledBodyType.append(new int(VARIABLE_TOKEN)); |
2508 | GetNext(); | 2508 | GetNext(); |
2509 | } | 2509 | } |
2510 | else if (SymbGroup== STRING_TOKEN ) | 2510 | else if (SymbGroup== STRING_TOKEN ) |
2511 | { | 2511 | { |
2512 | CompiledBody.append(new QString(chunk+QString("\""))); | 2512 | CompiledBody.append(new QString(chunk+QString("\""))); |
2513 | CompiledBodyType.append(new int(STRING_TOKEN)); | 2513 | CompiledBodyType.append(new int(STRING_TOKEN)); |
2514 | GetNext(); | 2514 | GetNext(); |
2515 | } | 2515 | } |
2516 | else Ninth(); | 2516 | else Ninth(); |
2517 | }; | 2517 | }; |
2518 | 2518 | ||
2519 | void Expression::Ninth() | 2519 | void Expression::Ninth() |
2520 | { | 2520 | { |
2521 | if ( SymbGroup== FUNCTION_TOKEN ) | 2521 | if ( SymbGroup== FUNCTION_TOKEN ) |
2522 | { | 2522 | { |
2523 | QString TempFunk = chunk ; | 2523 | QString TempFunk = chunk ; |
2524 | GetNext(); | 2524 | GetNext(); |
2525 | if(chunk0() == '(' ) | 2525 | if(chunk0() == '(' ) |
2526 | { | 2526 | { |
2527 | FuncDepth++; | 2527 | FuncDepth++; |
2528 | ArgsOfFunc.resize(FuncDepth+1); | 2528 | ArgsOfFunc.resize(FuncDepth+1); |
2529 | ArgsOfFunc[FuncDepth]=1; | 2529 | ArgsOfFunc[FuncDepth]=1; |
2530 | //ArgsOfFunc=1; | 2530 | //ArgsOfFunc=1; |
2531 | GetNext(); | 2531 | GetNext(); |
2532 | Third(); | 2532 | Third(); |
2533 | while(chunk0()==',') //function arguments separator | 2533 | while(chunk0()==',') //function arguments separator |
2534 | { | 2534 | { |
2535 | //ArgsOfFunc++; | 2535 | //ArgsOfFunc++; |
2536 | ArgsOfFunc[FuncDepth]++; | 2536 | ArgsOfFunc[FuncDepth]++; |
2537 | GetNext(); | 2537 | GetNext(); |
2538 | Third(); | 2538 | Third(); |
2539 | }; | 2539 | }; |
2540 | if (chunk0() != ')') ErrorFound = true; | 2540 | if (chunk0() != ')') ErrorFound = true; |
2541 | 2541 | ||
2542 | CompiledBody.append(new QString(TempFunk)); | 2542 | CompiledBody.append(new QString(TempFunk)); |
2543 | if (TempFunk=="PI") ArgsOfFunc[FuncDepth]=0; | 2543 | if (TempFunk=="PI") ArgsOfFunc[FuncDepth]=0; |
2544 | // couldn't find a better way to parse function PI() with 0 args. :) | 2544 | // couldn't find a better way to parse function PI() with 0 args. :) |
2545 | CompiledBodyType.append(new int(FUNCTION_TOKEN | (ArgsOfFunc[FuncDepth]<<8) )); | 2545 | CompiledBodyType.append(new int(FUNCTION_TOKEN | (ArgsOfFunc[FuncDepth]<<8) )); |
2546 | //the mask &FF00 gives the arguments of the functions passed. | 2546 | //the mask &FF00 gives the arguments of the functions passed. |
2547 | FuncDepth--; | 2547 | FuncDepth--; |
2548 | ArgsOfFunc.resize(FuncDepth+1); | 2548 | ArgsOfFunc.resize(FuncDepth+1); |
2549 | GetNext(); | 2549 | GetNext(); |
2550 | } | 2550 | } |
2551 | } | 2551 | } |
2552 | else | 2552 | else |
2553 | ErrorFound = true; | 2553 | ErrorFound = true; |
2554 | }; | 2554 | }; |
2555 | 2555 | ||
2556 | bool Expression::Parse() | 2556 | bool Expression::Parse() |
2557 | { | 2557 | { |
2558 | CompiledBody.clear(); | 2558 | CompiledBody.clear(); |
2559 | ErrorFound = false; | 2559 | ErrorFound = false; |
2560 | n = 0;ArgsOfFunc.resize(0);FuncDepth=0; | 2560 | n = 0;ArgsOfFunc.resize(0);FuncDepth=0; |
2561 | InExpr=Body; | 2561 | InExpr=Body; |
2562 | First(); | 2562 | First(); |
2563 | return(!ErrorFound); | 2563 | return(!ErrorFound); |
2564 | }; | 2564 | }; |
2565 | 2565 | ||
2566 | 2566 | ||