From f33f6ab85a1968e65226047916cb2fa517a69cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Thu, 14 Oct 2010 20:49:49 +0200 Subject: [PATCH] * Add formula support * Fix a bug (cannot add new operations due to bug in FormulaEditor) --- Makefile | 2 +- ressources/po/french.mo | Bin 6625 -> 6932 bytes ressources/po/french.po | 182 +++++---- ressources/po/kisscount.pot | 162 ++++---- src/ParseExp.cpp | 449 ++++++++++++++++++++++ src/ParseExp.h | 29 ++ src/view/grid/wxGridCellFormulaEditor.cpp | 32 +- src/view/grid/wxGridCellFormulaEditor.h | 2 +- 8 files changed, 703 insertions(+), 155 deletions(-) create mode 100644 src/ParseExp.cpp create mode 100644 src/ParseExp.h diff --git a/Makefile b/Makefile index 80e282f..cd69603 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ SOURCES=$(wildcard src/model/*.cpp) SOURCES+=$(wildcard src/view/*.cpp) SOURCES+=$(wildcard src/view/grid/*.cpp) SOURCES+=$(wildcard src/controller/*.cpp) -SOURCES+=src/main.cpp src/sha1.cpp +SOURCES+=src/main.cpp src/sha1.cpp src/ParseExp.cpp HEADERS=$(wildcard src/model/*.h) HEADERS+=$(wildcard src/view/*.h) HEADERS+=$(wildcard src/view/grid/*.h) diff --git a/ressources/po/french.mo b/ressources/po/french.mo index 4a87544c263ee919a4b887fe67500bf2d1e0fd94..1787d5b2847aef32b4799914271582c9f7b83e06 100644 GIT binary patch delta 2972 zcmZwJe@xVM9LMnwKm2uoAV>lE zt|Vi|a9n_DavqMyMVM?%$dpr2gKO=DYUE=Y_)>%IsKoZ*bbQ{P@53~X`*AFu#i{re z>b}2_9LzL&QHQfo?G+)H%tB11f3rMNF=oBJP=|W31t(z$)lmnkqnGUU9#n&Gp=O{D znLKmGp8pgz;z865T(HOAquTie9rSO0r=pA!Xhk=sq7ySw=ZjHGP>SlH9F@>Yd%O|# zoCh_NwW!3}?D^fOL>@yv<^W$AcnCvU!#AjCq#s~9er}J4klf5D>b?oIu8yan8Yn;) zE=5hb7uC_Ds08+-rv4!6`NKFL-$o7O=ZVa}I{4Mz7{?ByFXKSnn1x(2Yfw|>!Fa4g z-PeFhcn9(^Px7UuJA|5%qo_oVqZ04MQtZbZOiE+^HN`Wy$~jYn%B&RiKm}hK(Rx$@ zo9%I}J@%tIY(pis2enj>pa!-V)qWSMofq*+>_I(uDr7I5K|ba)zLdZ>s1XcVhpi*1 zL`G3lo4~rsWK;*4sOP6zb5ZT&p%TkS-S0--A1a}uDJsQ{amK7d-Ppst(uX;YTI)X4 z8V;bAYxsl=r+_yx1*NqVWbPwfg}(z-BdJ1$E>}04acW34=wX+Y^VVCtVD&b?O=TBG%FjMdU5EW(4k;#S()Q$P5j>=FC zSE3r;fZ8iHsHtv2jd+LkA=Jp9Kt2ByY5>oo_QcDm_TI#?djH?0QiAWJrsxu?;gl<) z4W%PFnrzf2n~iG7jT+fvR7aK8D(faxqF&VVt?0zZ?eQ@T>8JH170tjoRKvrl^M4|_ zm>i}<$Aze+sl;g*Ky}=K8sRgjk#{4jW?seB*oWFvDOu5xPeS!KHH-OIW`&$sj%7%n z<^XDw96^n^7uDbiq%HF?DzR@-Q#p$2cs%Q;0i>eZoq{XTjeN{5zBI!JQSbkeZ027h zILQfh(2qL)0=1@JTYs{SpgOpOyeuY}R`hyJL^V7abv+lgR|+r>OYHe-RQrCMj_n~T z8o@zpH>!cxQ4POieGfIo{iwtSPz?=QFQE3!57uGSl>dgh{}0st@mEFLai9jE{b!nq z6~sCnP<9YE5LybY`z%7Q+VzA+Swxf*PD14YLd&<1P$yd3MMN=CLTG7jCVWJ!C^>Qp zncUbJyvNobyzE>a^_j$4;#OikF^6a;Ttq#wkED3KpERxk2* zz>c3kH1?wY3)*VyUc8g=6H5p;p`vBEiD=OQw0BgtMKQPFGF!hI=M&n9bBV=- z-kQrxWc~H3sOX)(k0>J=iMxmZ5i1L*Y$8?>`d4cyq0JgA+Mp^0QOpbs+WK^yN9YIX zMtg3ywwQLU3LDbY5u1tDu*>0zTj2BgTb#84e`~X|rOq4lI{nSwfTyM2?+coxp2*c! z-~V3^hmy9$jj7PHo#&IACT#Twnpzt@PFJ`r<&}7QVJP)tlDjb9J=a-OSTeUbd@k*U z_|+?#n*G6GeRZSPS>uiN?hQD%c!TtQx+m8CzwfF!-4jXUzc+?=W_%PkE|P~g&{>hW hC%rt9iPu^0Yx6YL(}gSiVdjzq$FhIg=p36p_%~OtE#LqE delta 2676 zcmYk+drVek0LSqM1Vur-WN4Q8QW|QaC~828W}+l!<|WHe(Y%(0rlcidO<&1d}1=XuV1&T~8Guyxew;^a5o zGqwfFI&ua1x?Kn_;;s%HC<8i$z^O10yI>*a;u!3KQ?N5Gz>ZjplW=`J{~l)2ZbG{} zj#+pLb3#alW-4}gA^wn_9RhzLn}Z$pL?@PyeX%^ApNCy(FT?h@9_b=%L+RXAaVJSd5vBA68LG;M(}ZPISxnq66$hCv+gT52FJdL3i#WbYfqk6ZjsT;90x` z|3)8G4kuk;K6b}qO!8ZpNW}|gV9S=GH?GHg+>CDh%jf`2=zu5Dtv-$3e-=yeKXl@y z%+CJH(d(*^pTbP^x`nwsf9hcu2e)WHrsJ#Vg|DMCJ%T>F6X+H;qdV|BI+4H7iKlVV zc)X-0{p6wp<#BM}0(9boqr;Q2Qi4vP9Nnsl=v1_$*=Pszql?gvmZKA@MekdU zUSE&y%%fPH7Q)l$b?0~isD@wBN1SwjeRe&NT?_-!8%uB|jz|8&4h{~`h)y(xuJjQ4 zsE(p9*XQU2&Y(N~^I3vduJPBKiV;?`B8H?Bc%tVaiUBHDmXa5sAWf#^}Z zl=dlPjBo)j!}hGo>k??cC1}6n(0-?27sd~>skpUE(G{+U)}bqX2<_l8bZ0iB&wdBm z;a>E*gII=dpgVFN?bq4)dnR%!be!dwbVaMEIKu~#-3yQ4RNRifG-uG2{)BGv zpXh|L*xyR*gPaOW(05=1y234Jf6pR+;Ux}E>@eEj7d_d32mX!|uHZ+s<3F$pJN9aQ zmb1_;twq1<4d@DXq60i1+pnRI@a^c)=rOealgP&qen7vT=3eZ-9se9J_!kRkci;{3 zhN0*{qp>eeKxe)vx)Qyv9_?^bbPKw(+t3N^LHpSkJ&3*=Zzf~q9dxVTM{oE5y`c&1 z=p;IGi#v2HnMnMWeRu95x04~n>)XoEwhFF{b$8H3myo2ZVbLw0#00#aSQszdLps7K%b=EH>tPb`_`}`gHgX;5 zLspSF#K&Oq{iv}*xq&Pr18h+0S_wtbG12}wg)AZoGTHI3p<)?N7L(Ov2`MDgiEpgs zUh)8`CcfnspSh)&EGM-#D6`32vV!_oO%M?|LS?sI;)CG%>uWY(z=wxo&&XQ=58x Un$|EkZ)57Wys_;X%6fnGKLh&NVE_OC diff --git a/ressources/po/french.po b/ressources/po/french.po index 90dbd6a..485811e 100644 --- a/ressources/po/french.po +++ b/ressources/po/french.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-09-09 20:48+0200\n" +"POT-Creation-Date: 2010-10-14 20:46+0200\n" "PO-Revision-Date: \n" "Last-Translator: Soutadé \n" "Language-Team: \n" @@ -19,21 +19,21 @@ msgstr "" # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#: src/view/PreferencesPanel.cpp:660 #: src/view/StatsPanel.cpp:282 +#: src/view/PreferencesPanel.cpp:660 msgid " - " msgstr " - " +#: src/view/UsersDialog.cpp:118 #: src/view/PreferencesPanel.cpp:384 #: src/view/PreferencesPanel.cpp:403 #: src/view/PreferencesPanel.cpp:553 #: src/view/PreferencesPanel.cpp:572 #: src/view/PreferencesPanel.cpp:618 -#: src/view/UsersDialog.cpp:116 msgid " already exists" msgstr " existe déjà " -#: src/view/SearchPanel.cpp:219 +#: src/view/SearchPanel.cpp:215 msgid " entries found" msgstr " entrées trouvées" @@ -41,7 +41,7 @@ msgstr " entrées trouvées" msgid " not found, aborting" msgstr " non trouvé, arrêt" -#: src/view/AccountPanel.cpp:996 +#: src/view/AccountPanel.cpp:705 msgid " operations ?" msgstr " opérations ?" @@ -53,7 +53,7 @@ msgstr " profil ?" msgid "!! Warning !! If there was a bug, the old database will be suppressed !" msgstr "!! Attention !! S'il y a eu un bug, l'ancienne base de donnée va être supprimée !" -#: src/view/SearchPanel.cpp:221 +#: src/view/SearchPanel.cpp:217 msgid "1 entry found" msgstr "1 entrée trouvée" @@ -61,8 +61,8 @@ msgstr "1 entrée trouvée" msgid "About" msgstr "A propos" -#: src/view/grid/GridAccount.cpp:61 -#: src/view/SearchPanel.cpp:89 +#: src/view/SearchPanel.cpp:85 +#: src/view/grid/GridAccount.cpp:63 msgid "Account" msgstr "Compte" @@ -71,36 +71,35 @@ msgstr "Compte" msgid "Account " msgstr "Le compte " -#: src/view/AccountPanel.cpp:102 +#: src/view/AccountPanel.cpp:106 msgid "Account name" msgstr "Nom du compte" -#: src/view/AccountPanel.cpp:101 +#: src/view/AccountPanel.cpp:105 msgid "Account number" msgstr "Numéro de compte" -#: src/view/PreferencesPanel.cpp:55 #: src/view/StatsPanel.cpp:247 +#: src/view/PreferencesPanel.cpp:55 msgid "Accounts" msgstr "Comptes" -#: src/view/SearchPanel.cpp:86 +#: src/view/SearchPanel.cpp:82 msgid "Amount from" msgstr "Montant min" -#: src/view/SearchPanel.cpp:87 +#: src/view/SearchPanel.cpp:83 msgid "Amount to" msgstr "Montant max" #: src/view/PreferencesPanel.cpp:365 #: src/view/PreferencesPanel.cpp:667 -#: src/view/AccountPanel.cpp:991 +#: src/view/AccountPanel.cpp:700 msgid "Are you sure want to delete " msgstr "Etes vous sûr de vouloir supprimer " #: src/view/PreferencesPanel.cpp:534 -#: src/view/AccountPanel.cpp:675 -#: src/view/SearchPanel.cpp:350 +#: src/view/grid/GridAccount.cpp:743 msgid "Are you sure want to delete : \n" msgstr "Etes vous sûr de vouloir supprimer : \n" @@ -112,18 +111,28 @@ msgstr "Croissant" msgid "Background color" msgstr "Couleur d'arrière plan" -#: src/view/PasswordDialog.cpp:56 -#: src/view/GenerateDialog.cpp:60 #: src/view/UsersDialog.cpp:51 +#: src/view/GenerateDialog.cpp:60 +#: src/view/PasswordDialog.cpp:56 msgid "Cancel" msgstr "Annuler" +#: src/view/grid/GridAccount.cpp:1067 +#: src/view/grid/GridAccount.cpp:1074 +msgid "Cannot group these operations" +msgstr "Impossible de grouper ces opérations" + +#: src/view/grid/GridAccount.cpp:1202 +#: src/view/grid/GridAccount.cpp:1208 +msgid "Cannot ungroup these operations" +msgstr "Impossible de dégrouper ces opérations" + #: src/view/PreferencesPanel.cpp:56 msgid "Categories" msgstr "Catégories" -#: src/view/grid/GridAccount.cpp:61 -#: src/view/SearchPanel.cpp:88 +#: src/view/SearchPanel.cpp:84 +#: src/view/grid/GridAccount.cpp:63 msgid "Category" msgstr "Catégorie" @@ -148,7 +157,7 @@ msgstr "Changer le mot de passe" msgid "Change user" msgstr "Changer d'utilisateur" -#: src/view/AccountPanel.cpp:118 +#: src/view/AccountPanel.cpp:122 msgid "Check mode" msgstr "Mode rapprochement" @@ -157,39 +166,39 @@ msgid "Confirm password " msgstr "Confirmer le mot de passe" #: src/view/StatsPanel.cpp:130 -#: src/view/AccountPanel.cpp:112 +#: src/view/AccountPanel.cpp:116 msgid "Cost repartition" msgstr "Répartition des coûts" -#: src/view/grid/GridAccount.cpp:61 +#: src/view/grid/GridAccount.cpp:63 msgid "Credit" msgstr "Crédit" -#: src/view/AccountPanel.cpp:189 +#: src/view/AccountPanel.cpp:202 msgid "Cur Credit" msgstr "Cur Crédit" -#: src/view/AccountPanel.cpp:190 +#: src/view/AccountPanel.cpp:203 msgid "Cur Debit" msgstr "Cur Débit" -#: src/view/AccountPanel.cpp:104 +#: src/view/AccountPanel.cpp:108 msgid "Current value" msgstr "Valeur courante" -#: src/view/grid/GridAccount.cpp:61 +#: src/view/grid/GridAccount.cpp:63 msgid "Date" msgstr "Date" -#: src/view/SearchPanel.cpp:53 +#: src/view/SearchPanel.cpp:49 msgid "Date from" msgstr "Date min" -#: src/view/SearchPanel.cpp:54 +#: src/view/SearchPanel.cpp:50 msgid "Date to" msgstr "Date max" -#: src/view/grid/GridAccount.cpp:61 +#: src/view/grid/GridAccount.cpp:63 msgid "Debit" msgstr "Débit" @@ -199,7 +208,7 @@ msgstr "Défaut" #: src/view/PreferencesPanel.cpp:167 #: src/view/PreferencesPanel.cpp:224 -#: src/view/AccountPanel.cpp:850 +#: src/view/AccountPanel.cpp:559 msgid "Delete" msgstr "Supprimer" @@ -207,11 +216,32 @@ msgstr "Supprimer" msgid "Descending" msgstr "Décroissant" -#: src/view/grid/GridAccount.cpp:61 -#: src/view/SearchPanel.cpp:85 +#: src/view/SearchPanel.cpp:81 +#: src/view/grid/GridAccount.cpp:63 msgid "Description" msgstr "Description" +#: src/view/UsersDialog.cpp:88 +#: src/view/UsersDialog.cpp:118 +#: src/view/SearchPanel.cpp:135 +#: src/view/SearchPanel.cpp:145 +#: src/view/SearchPanel.cpp:159 +#: src/view/SearchPanel.cpp:170 +#: src/view/PreferencesPanel.cpp:361 +#: src/view/PreferencesPanel.cpp:384 +#: src/view/PreferencesPanel.cpp:403 +#: src/view/PreferencesPanel.cpp:553 +#: src/view/PreferencesPanel.cpp:572 +#: src/view/PreferencesPanel.cpp:612 +#: src/view/PreferencesPanel.cpp:618 +#: src/view/PasswordDialog.cpp:72 +#: src/view/PasswordDialog.cpp:78 +#: src/view/AccountPanel.cpp:696 +#: src/view/grid/GridAccount.cpp:1067 +#: src/view/grid/GridAccount.cpp:1074 +#: src/view/grid/GridAccount.cpp:1202 +#: src/view/grid/GridAccount.cpp:1208 +#: src/view/grid/wxGridCellFormulaEditor.cpp:68 #: src/model/Database.cpp:38 #: src/model/Database.cpp:55 #: src/model/Database.cpp:95 @@ -220,22 +250,6 @@ msgstr "Description" #: src/model/Database.cpp:147 #: src/model/Database.cpp:155 #: src/model/Database.cpp:176 -#: src/view/PasswordDialog.cpp:72 -#: src/view/PasswordDialog.cpp:78 -#: src/view/PreferencesPanel.cpp:361 -#: src/view/PreferencesPanel.cpp:384 -#: src/view/PreferencesPanel.cpp:403 -#: src/view/PreferencesPanel.cpp:553 -#: src/view/PreferencesPanel.cpp:572 -#: src/view/PreferencesPanel.cpp:612 -#: src/view/PreferencesPanel.cpp:618 -#: src/view/AccountPanel.cpp:987 -#: src/view/UsersDialog.cpp:88 -#: src/view/UsersDialog.cpp:116 -#: src/view/SearchPanel.cpp:139 -#: src/view/SearchPanel.cpp:149 -#: src/view/SearchPanel.cpp:163 -#: src/view/SearchPanel.cpp:174 msgid "Error" msgstr "Erreur" @@ -243,13 +257,13 @@ msgstr "Erreur" msgid "Error creating original database" msgstr "Erreur durant la création de la base de données initiale" -#: src/view/AccountPanel.cpp:105 +#: src/view/AccountPanel.cpp:109 msgid "Final value" msgstr "Valeur finale" +#: src/view/grid/GridAccount.cpp:300 #: src/model/Database.cpp:312 -#: src/controller/KissCount.cpp:278 -#: src/view/grid/GridAccount.cpp:144 +#: src/controller/KissCount.cpp:305 msgid "Fix" msgstr "Fixe" @@ -270,38 +284,46 @@ msgid "From " msgstr "A partir de " #: src/view/GenerateDialog.cpp:31 -#: src/view/AccountPanel.cpp:847 +#: src/view/AccountPanel.cpp:556 msgid "Generate month" msgstr "Générer mois" -#: src/controller/KissCount.cpp:280 +#: src/controller/KissCount.cpp:307 msgid "Groceries" msgstr "Courses" -#: src/controller/KissCount.cpp:282 +#: src/view/AccountPanel.cpp:126 +msgid "Group" +msgstr "Grouper" + +#: src/controller/KissCount.cpp:309 msgid "Hobbies" msgstr "Loisirs" -#: src/view/AccountPanel.cpp:103 +#: src/view/AccountPanel.cpp:107 msgid "Initial value" msgstr "Valeur initiale" -#: src/view/SearchPanel.cpp:149 +#: src/view/SearchPanel.cpp:145 msgid "Invalid amount from" msgstr "Montant min invalide" -#: src/view/SearchPanel.cpp:174 +#: src/view/SearchPanel.cpp:170 msgid "Invalid amount range" msgstr "Intervalle des montants invalide" -#: src/view/SearchPanel.cpp:163 +#: src/view/SearchPanel.cpp:159 msgid "Invalid amount to" msgstr "Montant max invalide" -#: src/view/SearchPanel.cpp:139 +#: src/view/SearchPanel.cpp:135 msgid "Invalid date range" msgstr "Intervalle de temps invalide" +#: src/view/grid/wxGridCellFormulaEditor.cpp:68 +msgid "Invalid formula !" +msgstr "Formule invalide !" + #: src/view/PreferencesPanel.cpp:612 msgid "Invalid name" msgstr "Nom invalide" @@ -314,7 +336,7 @@ msgstr "Ancien mot de passe invalide" msgid "Invalid password" msgstr "Mot de passe invalide" -#: src/view/StatsPanel.cpp:297 +#: src/view/StatsPanel.cpp:302 msgid "Invalide date range" msgstr "Intervalle de temps invalide" @@ -322,7 +344,7 @@ msgstr "Intervalle de temps invalide" msgid "It must be at least one account !" msgstr "Il doit y avoir au moins un compte !" -#: src/view/AccountPanel.cpp:987 +#: src/view/AccountPanel.cpp:696 msgid "It must be at least one month !" msgstr "Il doit rester au mois un mois" @@ -330,9 +352,9 @@ msgstr "Il doit rester au mois un mois" msgid "Kill me" msgstr "Kill me" +#: src/view/StatsPanel.cpp:302 #: src/view/PreferencesPanel.cpp:652 #: src/view/PreferencesPanel.cpp:655 -#: src/view/StatsPanel.cpp:297 msgid "KissCount" msgstr "KissCount" @@ -359,7 +381,7 @@ msgid "Name changed" msgstr "Nom changé" #: src/view/UsersDialog.cpp:52 -#: src/view/UsersDialog.cpp:105 +#: src/view/UsersDialog.cpp:107 msgid "New User" msgstr "Nouvel utilisateur" @@ -375,7 +397,7 @@ msgstr "" "Aucune base de données trouvée, voulez vous en créer une nouvelle ?\n" "\n" -#: src/view/SearchPanel.cpp:224 +#: src/view/SearchPanel.cpp:220 msgid "No entry found" msgstr "Pas d'entrée trouvée" @@ -383,9 +405,9 @@ msgstr "Pas d'entrée trouvée" msgid "Number" msgstr "Numéro de compte" -#: src/view/PasswordDialog.cpp:55 -#: src/view/GenerateDialog.cpp:59 #: src/view/UsersDialog.cpp:50 +#: src/view/GenerateDialog.cpp:59 +#: src/view/PasswordDialog.cpp:55 msgid "OK" msgstr "OK" @@ -393,7 +415,7 @@ msgstr "OK" msgid "Old password " msgstr "Ancien mot de passe" -#: src/controller/KissCount.cpp:284 +#: src/controller/KissCount.cpp:311 msgid "Operating exepense" msgstr "Frais de fonctionnement" @@ -405,7 +427,7 @@ msgstr "Ordre des opérations" msgid "Operations" msgstr "Opérations" -#: src/controller/KissCount.cpp:288 +#: src/controller/KissCount.cpp:315 msgid "Other" msgstr "Autres" @@ -449,18 +471,18 @@ msgstr "Quitter" msgid "Quit KissCount ?" msgstr "Quitter KissCount ?" -#: src/view/AccountPanel.cpp:191 +#: src/view/AccountPanel.cpp:204 msgid "Remains" msgstr "Restant" -#: src/view/SearchPanel.cpp:83 -#: src/view/SearchPanel.cpp:244 +#: src/view/SearchPanel.cpp:79 +#: src/view/SearchPanel.cpp:231 #: src/view/ButtonPanel.cpp:71 msgid "Search" msgstr "Chercher" #: src/view/StatsPanel.cpp:122 -#: src/view/AccountPanel.cpp:86 +#: src/view/AccountPanel.cpp:90 msgid "Serie 1" msgstr "Série 1" @@ -481,14 +503,18 @@ msgstr "A" msgid "To " msgstr "Vers " -#: src/view/AccountPanel.cpp:173 +#: src/view/AccountPanel.cpp:186 msgid "Total Credit" msgstr "Total Crédit" -#: src/view/AccountPanel.cpp:174 +#: src/view/AccountPanel.cpp:187 msgid "Total Debit" msgstr "Total Débit" +#: src/view/AccountPanel.cpp:127 +msgid "UnGroup" +msgstr "Dégrouper" + #: src/model/Database.cpp:95 #: src/model/Database.cpp:102 #: src/model/Database.cpp:120 @@ -496,7 +522,7 @@ msgstr "Total Débit" msgid "Unable to open Database" msgstr "Impossible d'ouvrir la base de données" -#: src/controller/KissCount.cpp:286 +#: src/controller/KissCount.cpp:313 msgid "Unexpected" msgstr "Exceptionnel" @@ -514,9 +540,9 @@ msgstr "La mise à jour à échouée !\n" msgid "User" msgstr "Utilisateur" -#: src/view/PreferencesPanel.cpp:618 #: src/view/UsersDialog.cpp:38 -#: src/view/UsersDialog.cpp:116 +#: src/view/UsersDialog.cpp:118 +#: src/view/PreferencesPanel.cpp:618 msgid "User " msgstr "Utilisateur" diff --git a/ressources/po/kisscount.pot b/ressources/po/kisscount.pot index eafc644..1005abc 100644 --- a/ressources/po/kisscount.pot +++ b/ressources/po/kisscount.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-09-09 20:48+0200\n" +"POT-Creation-Date: 2010-10-14 20:46+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,17 +17,17 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: src/view/PreferencesPanel.cpp:660 src/view/StatsPanel.cpp:282 +#: src/view/StatsPanel.cpp:282 src/view/PreferencesPanel.cpp:660 msgid " - " msgstr "" -#: src/view/PreferencesPanel.cpp:384 src/view/PreferencesPanel.cpp:403 -#: src/view/PreferencesPanel.cpp:553 src/view/PreferencesPanel.cpp:572 -#: src/view/PreferencesPanel.cpp:618 src/view/UsersDialog.cpp:116 +#: src/view/UsersDialog.cpp:118 src/view/PreferencesPanel.cpp:384 +#: src/view/PreferencesPanel.cpp:403 src/view/PreferencesPanel.cpp:553 +#: src/view/PreferencesPanel.cpp:572 src/view/PreferencesPanel.cpp:618 msgid " already exists" msgstr "" -#: src/view/SearchPanel.cpp:219 +#: src/view/SearchPanel.cpp:215 msgid " entries found" msgstr "" @@ -35,7 +35,7 @@ msgstr "" msgid " not found, aborting" msgstr "" -#: src/view/AccountPanel.cpp:996 +#: src/view/AccountPanel.cpp:705 msgid " operations ?" msgstr "" @@ -47,7 +47,7 @@ msgstr "" msgid "!! Warning !! If there was a bug, the old database will be suppressed !" msgstr "" -#: src/view/SearchPanel.cpp:221 +#: src/view/SearchPanel.cpp:217 msgid "1 entry found" msgstr "" @@ -55,7 +55,7 @@ msgstr "" msgid "About" msgstr "" -#: src/view/grid/GridAccount.cpp:61 src/view/SearchPanel.cpp:89 +#: src/view/SearchPanel.cpp:85 src/view/grid/GridAccount.cpp:63 msgid "Account" msgstr "" @@ -63,33 +63,32 @@ msgstr "" msgid "Account " msgstr "" -#: src/view/AccountPanel.cpp:102 +#: src/view/AccountPanel.cpp:106 msgid "Account name" msgstr "" -#: src/view/AccountPanel.cpp:101 +#: src/view/AccountPanel.cpp:105 msgid "Account number" msgstr "" -#: src/view/PreferencesPanel.cpp:55 src/view/StatsPanel.cpp:247 +#: src/view/StatsPanel.cpp:247 src/view/PreferencesPanel.cpp:55 msgid "Accounts" msgstr "" -#: src/view/SearchPanel.cpp:86 +#: src/view/SearchPanel.cpp:82 msgid "Amount from" msgstr "" -#: src/view/SearchPanel.cpp:87 +#: src/view/SearchPanel.cpp:83 msgid "Amount to" msgstr "" #: src/view/PreferencesPanel.cpp:365 src/view/PreferencesPanel.cpp:667 -#: src/view/AccountPanel.cpp:991 +#: src/view/AccountPanel.cpp:700 msgid "Are you sure want to delete " msgstr "" -#: src/view/PreferencesPanel.cpp:534 src/view/AccountPanel.cpp:675 -#: src/view/SearchPanel.cpp:350 +#: src/view/PreferencesPanel.cpp:534 src/view/grid/GridAccount.cpp:743 msgid "Are you sure want to delete : \n" msgstr "" @@ -101,16 +100,24 @@ msgstr "" msgid "Background color" msgstr "" -#: src/view/PasswordDialog.cpp:56 src/view/GenerateDialog.cpp:60 -#: src/view/UsersDialog.cpp:51 +#: src/view/UsersDialog.cpp:51 src/view/GenerateDialog.cpp:60 +#: src/view/PasswordDialog.cpp:56 msgid "Cancel" msgstr "" +#: src/view/grid/GridAccount.cpp:1067 src/view/grid/GridAccount.cpp:1074 +msgid "Cannot group these operations" +msgstr "" + +#: src/view/grid/GridAccount.cpp:1202 src/view/grid/GridAccount.cpp:1208 +msgid "Cannot ungroup these operations" +msgstr "" + #: src/view/PreferencesPanel.cpp:56 msgid "Categories" msgstr "" -#: src/view/grid/GridAccount.cpp:61 src/view/SearchPanel.cpp:88 +#: src/view/SearchPanel.cpp:84 src/view/grid/GridAccount.cpp:63 msgid "Category" msgstr "" @@ -134,7 +141,7 @@ msgstr "" msgid "Change user" msgstr "" -#: src/view/AccountPanel.cpp:118 +#: src/view/AccountPanel.cpp:122 msgid "Check mode" msgstr "" @@ -142,39 +149,39 @@ msgstr "" msgid "Confirm password " msgstr "" -#: src/view/StatsPanel.cpp:130 src/view/AccountPanel.cpp:112 +#: src/view/StatsPanel.cpp:130 src/view/AccountPanel.cpp:116 msgid "Cost repartition" msgstr "" -#: src/view/grid/GridAccount.cpp:61 +#: src/view/grid/GridAccount.cpp:63 msgid "Credit" msgstr "" -#: src/view/AccountPanel.cpp:189 +#: src/view/AccountPanel.cpp:202 msgid "Cur Credit" msgstr "" -#: src/view/AccountPanel.cpp:190 +#: src/view/AccountPanel.cpp:203 msgid "Cur Debit" msgstr "" -#: src/view/AccountPanel.cpp:104 +#: src/view/AccountPanel.cpp:108 msgid "Current value" msgstr "" -#: src/view/grid/GridAccount.cpp:61 +#: src/view/grid/GridAccount.cpp:63 msgid "Date" msgstr "" -#: src/view/SearchPanel.cpp:53 +#: src/view/SearchPanel.cpp:49 msgid "Date from" msgstr "" -#: src/view/SearchPanel.cpp:54 +#: src/view/SearchPanel.cpp:50 msgid "Date to" msgstr "" -#: src/view/grid/GridAccount.cpp:61 +#: src/view/grid/GridAccount.cpp:63 msgid "Debit" msgstr "" @@ -183,7 +190,7 @@ msgid "Default" msgstr "" #: src/view/PreferencesPanel.cpp:167 src/view/PreferencesPanel.cpp:224 -#: src/view/AccountPanel.cpp:850 +#: src/view/AccountPanel.cpp:559 msgid "Delete" msgstr "" @@ -191,22 +198,25 @@ msgstr "" msgid "Descending" msgstr "" -#: src/view/grid/GridAccount.cpp:61 src/view/SearchPanel.cpp:85 +#: src/view/SearchPanel.cpp:81 src/view/grid/GridAccount.cpp:63 msgid "Description" msgstr "" -#: src/model/Database.cpp:38 src/model/Database.cpp:55 -#: src/model/Database.cpp:95 src/model/Database.cpp:102 -#: src/model/Database.cpp:120 src/model/Database.cpp:147 -#: src/model/Database.cpp:155 src/model/Database.cpp:176 -#: src/view/PasswordDialog.cpp:72 src/view/PasswordDialog.cpp:78 +#: src/view/UsersDialog.cpp:88 src/view/UsersDialog.cpp:118 +#: src/view/SearchPanel.cpp:135 src/view/SearchPanel.cpp:145 +#: src/view/SearchPanel.cpp:159 src/view/SearchPanel.cpp:170 #: src/view/PreferencesPanel.cpp:361 src/view/PreferencesPanel.cpp:384 #: src/view/PreferencesPanel.cpp:403 src/view/PreferencesPanel.cpp:553 #: src/view/PreferencesPanel.cpp:572 src/view/PreferencesPanel.cpp:612 -#: src/view/PreferencesPanel.cpp:618 src/view/AccountPanel.cpp:987 -#: src/view/UsersDialog.cpp:88 src/view/UsersDialog.cpp:116 -#: src/view/SearchPanel.cpp:139 src/view/SearchPanel.cpp:149 -#: src/view/SearchPanel.cpp:163 src/view/SearchPanel.cpp:174 +#: src/view/PreferencesPanel.cpp:618 src/view/PasswordDialog.cpp:72 +#: src/view/PasswordDialog.cpp:78 src/view/AccountPanel.cpp:696 +#: src/view/grid/GridAccount.cpp:1067 src/view/grid/GridAccount.cpp:1074 +#: src/view/grid/GridAccount.cpp:1202 src/view/grid/GridAccount.cpp:1208 +#: src/view/grid/wxGridCellFormulaEditor.cpp:68 src/model/Database.cpp:38 +#: src/model/Database.cpp:55 src/model/Database.cpp:95 +#: src/model/Database.cpp:102 src/model/Database.cpp:120 +#: src/model/Database.cpp:147 src/model/Database.cpp:155 +#: src/model/Database.cpp:176 msgid "Error" msgstr "" @@ -214,12 +224,12 @@ msgstr "" msgid "Error creating original database" msgstr "" -#: src/view/AccountPanel.cpp:105 +#: src/view/AccountPanel.cpp:109 msgid "Final value" msgstr "" -#: src/model/Database.cpp:312 src/controller/KissCount.cpp:278 -#: src/view/grid/GridAccount.cpp:144 +#: src/view/grid/GridAccount.cpp:300 src/model/Database.cpp:312 +#: src/controller/KissCount.cpp:305 msgid "Fix" msgstr "" @@ -239,38 +249,46 @@ msgstr "" msgid "From " msgstr "" -#: src/view/GenerateDialog.cpp:31 src/view/AccountPanel.cpp:847 +#: src/view/GenerateDialog.cpp:31 src/view/AccountPanel.cpp:556 msgid "Generate month" msgstr "" -#: src/controller/KissCount.cpp:280 +#: src/controller/KissCount.cpp:307 msgid "Groceries" msgstr "" -#: src/controller/KissCount.cpp:282 +#: src/view/AccountPanel.cpp:126 +msgid "Group" +msgstr "" + +#: src/controller/KissCount.cpp:309 msgid "Hobbies" msgstr "" -#: src/view/AccountPanel.cpp:103 +#: src/view/AccountPanel.cpp:107 msgid "Initial value" msgstr "" -#: src/view/SearchPanel.cpp:149 +#: src/view/SearchPanel.cpp:145 msgid "Invalid amount from" msgstr "" -#: src/view/SearchPanel.cpp:174 +#: src/view/SearchPanel.cpp:170 msgid "Invalid amount range" msgstr "" -#: src/view/SearchPanel.cpp:163 +#: src/view/SearchPanel.cpp:159 msgid "Invalid amount to" msgstr "" -#: src/view/SearchPanel.cpp:139 +#: src/view/SearchPanel.cpp:135 msgid "Invalid date range" msgstr "" +#: src/view/grid/wxGridCellFormulaEditor.cpp:68 +msgid "Invalid formula !" +msgstr "" + #: src/view/PreferencesPanel.cpp:612 msgid "Invalid name" msgstr "" @@ -283,7 +301,7 @@ msgstr "" msgid "Invalid password" msgstr "" -#: src/view/StatsPanel.cpp:297 +#: src/view/StatsPanel.cpp:302 msgid "Invalide date range" msgstr "" @@ -291,7 +309,7 @@ msgstr "" msgid "It must be at least one account !" msgstr "" -#: src/view/AccountPanel.cpp:987 +#: src/view/AccountPanel.cpp:696 msgid "It must be at least one month !" msgstr "" @@ -299,8 +317,8 @@ msgstr "" msgid "Kill me" msgstr "" -#: src/view/PreferencesPanel.cpp:652 src/view/PreferencesPanel.cpp:655 -#: src/view/StatsPanel.cpp:297 +#: src/view/StatsPanel.cpp:302 src/view/PreferencesPanel.cpp:652 +#: src/view/PreferencesPanel.cpp:655 msgid "KissCount" msgstr "" @@ -325,7 +343,7 @@ msgstr "" msgid "Name changed" msgstr "" -#: src/view/UsersDialog.cpp:52 src/view/UsersDialog.cpp:105 +#: src/view/UsersDialog.cpp:52 src/view/UsersDialog.cpp:107 msgid "New User" msgstr "" @@ -339,7 +357,7 @@ msgid "" "\n" msgstr "" -#: src/view/SearchPanel.cpp:224 +#: src/view/SearchPanel.cpp:220 msgid "No entry found" msgstr "" @@ -347,8 +365,8 @@ msgstr "" msgid "Number" msgstr "" -#: src/view/PasswordDialog.cpp:55 src/view/GenerateDialog.cpp:59 -#: src/view/UsersDialog.cpp:50 +#: src/view/UsersDialog.cpp:50 src/view/GenerateDialog.cpp:59 +#: src/view/PasswordDialog.cpp:55 msgid "OK" msgstr "" @@ -356,7 +374,7 @@ msgstr "" msgid "Old password " msgstr "" -#: src/controller/KissCount.cpp:284 +#: src/controller/KissCount.cpp:311 msgid "Operating exepense" msgstr "" @@ -368,7 +386,7 @@ msgstr "" msgid "Operations" msgstr "" -#: src/controller/KissCount.cpp:288 +#: src/controller/KissCount.cpp:315 msgid "Other" msgstr "" @@ -408,16 +426,16 @@ msgstr "" msgid "Quit KissCount ?" msgstr "" -#: src/view/AccountPanel.cpp:191 +#: src/view/AccountPanel.cpp:204 msgid "Remains" msgstr "" -#: src/view/SearchPanel.cpp:83 src/view/SearchPanel.cpp:244 +#: src/view/SearchPanel.cpp:79 src/view/SearchPanel.cpp:231 #: src/view/ButtonPanel.cpp:71 msgid "Search" msgstr "" -#: src/view/StatsPanel.cpp:122 src/view/AccountPanel.cpp:86 +#: src/view/StatsPanel.cpp:122 src/view/AccountPanel.cpp:90 msgid "Serie 1" msgstr "" @@ -437,20 +455,24 @@ msgstr "" msgid "To " msgstr "" -#: src/view/AccountPanel.cpp:173 +#: src/view/AccountPanel.cpp:186 msgid "Total Credit" msgstr "" -#: src/view/AccountPanel.cpp:174 +#: src/view/AccountPanel.cpp:187 msgid "Total Debit" msgstr "" +#: src/view/AccountPanel.cpp:127 +msgid "UnGroup" +msgstr "" + #: src/model/Database.cpp:95 src/model/Database.cpp:102 #: src/model/Database.cpp:120 src/model/Database.cpp:155 msgid "Unable to open Database" msgstr "" -#: src/controller/KissCount.cpp:286 +#: src/controller/KissCount.cpp:313 msgid "Unexpected" msgstr "" @@ -466,8 +488,8 @@ msgstr "" msgid "User" msgstr "" -#: src/view/PreferencesPanel.cpp:618 src/view/UsersDialog.cpp:38 -#: src/view/UsersDialog.cpp:116 +#: src/view/UsersDialog.cpp:38 src/view/UsersDialog.cpp:118 +#: src/view/PreferencesPanel.cpp:618 msgid "User " msgstr "" diff --git a/src/ParseExp.cpp b/src/ParseExp.cpp new file mode 100644 index 0000000..cb22720 --- /dev/null +++ b/src/ParseExp.cpp @@ -0,0 +1,449 @@ +/* + Copyright 2010 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + +#include +#include +#include + +#include "ParseExp.h" + +/* + Algorithm + The idea of this parser is very simple : Create a binary tree with an operator, a left and a right operand. + Leafs are constants to be computed. This structure is more flexbile than a simple stack and very easy to parse + (for resultat computation). + A simple expression (3+4) will be represented by : + + + 3 4 + Another example (3+4+5) : + + + 3 + + 4 5 + + If an operator is less prioritary than his father we have to do a transformation. + Example with 3*4+5. + in first instance we may have this tree : + * + 3 + + 4 5 + So we must reverse the tree into something like : + + + * 5 + 3 4 + + At each step the parser must read one operand and one operator, + fill a node with the operator and left operand and recurse on right + operand. Finally we stop with a constant (a leaf). + Operations in parenthesis must be computed separatly and filled into + the tree like constants. + */ + +/* Less to most prioritary */ +enum {CST, ADD, SUB, MUL, DIV, MOD, EXP}; + +enum {DOUBLE_POINTED=1, INVALID_CHAR, INVALID_PARENTHESIS, INVALID_OPERATION}; + +#ifdef DEBUG +#define P(x) x +#else +#define P(x) +#endif + +double atof(char* s, int size) +{ + int neg = 0; + double res = 0; + + for (; size--; s++) + { + if (*s == '.') + { + neg = 10; + continue; + } + + if (neg > 0) + { + res += (*s - '0') / neg; + neg *= 10; + } + else + { + res *= 10; + res += *s - '0'; + } + } + + return res; +} + +void ParseExp(char** expr, struct parse_opt* root, bool needParenthesis) +{ + char* temp; + bool pointed = false; + struct parse_opt* l, *r, *op, *op_tmp; + char type = -1; + bool negative = false, number = false; + l = r = op = op_tmp = NULL; + + if (!**expr) return; + + for (temp=*expr; **expr; (*expr)++) + { + if (**expr == '(') + { + op_tmp = new struct parse_opt; + op_tmp->type = CST; + op_tmp->root = root; + op_tmp->l = op_tmp->r = NULL; + (*expr)++; + ParseExp(expr, op_tmp, true); + l = op_tmp; + root->l = l; + continue; + } + + if (**expr == ')') + { + if (!needParenthesis) + throw INVALID_PARENTHESIS; + + if ((*expr-temp) == 0) + throw INVALID_OPERATION; + break; + } + + if (**expr >= '0' && **expr <= '9') + continue; + + if (**expr == '.') + { + if (!pointed) + pointed = true; + else + throw DOUBLE_POINTED; + + continue; + } + + if (type != -1) + throw INVALID_OPERATION; + + switch(**expr) + { + case '+': + type = ADD; + break; + case '-': + if (temp == *expr) + { + if (negative) + throw INVALID_OPERATION; + temp++; + negative = true; + continue; + } + type = SUB; + break; + case '/': + type = DIV; + break; + case '*': + type = MUL; + break; + // case '%': + // type = MOD; + // break; + default: + throw INVALID_CHAR; + } + + number= true; + + if (!l) + { + if ((*expr-temp) == 0) + throw INVALID_OPERATION; + l = new struct parse_opt; + l->type = CST; + l->root = root; + l->l = NULL; l->r = NULL; + l->value = atof(temp, *expr-temp); + if (negative) + l->value *= -1.0; + root->l = l; + } + + // Here [temp..expr] must be left operand + operator + if (root->root && root->root->type >= type) + { + // Reverse tree + op = new parse_opt; + op->root = root->root; + op->type = root->root->type; + op->r = l; + op->l = root->root->l; + op->l->root = op; + root->root->l = op; + root->root->type = type; + + root->type = CST; + root->value = 0.0; + root->l = NULL ; root->r = NULL; + + (*expr)++; + ParseExp(expr, root, needParenthesis); + break; + temp=*expr; + } + else + { + // Recurse on right operand + root->type = type; + // atof + r = new struct parse_opt; + r->type = CST; + r->root = root; + r->l = NULL; r->r = NULL; + r->value = 0.0; + root->r = r; + + (*expr)++; + ParseExp(expr, r, needParenthesis); + break; + temp=*expr; + } + + } + + if (needParenthesis && **expr != ')') + throw INVALID_PARENTHESIS; + + if (!number) + { + if ((*expr-temp) == 0) + throw INVALID_OPERATION; + + if (op_tmp) + *root = *op_tmp; + else + { + root->type = CST; + root->l = NULL; root->r = NULL; + root->value = atof(temp, *expr-temp); + if (negative) + root->value *= -1.0; + } + } + + return ; +} + +double EvaluateExpr(struct parse_opt* root, bool del) +{ + double l, r; + char type; + + type = root->type; + + if (root->type != CST) + { + l = EvaluateExpr(root->l, del); + r = EvaluateExpr(root->r, del); + } + else + l = root->value; + + if (del) + { + if (root->l) delete root->l; + if (root->r) delete root->r; + } + + switch (type) + { + case ADD: + P(std::cout << l << " + " << r << std::endl); + return l+r; + case SUB: + P(std::cout << l << " - " << r << std::endl); + return l+r; + case MUL: + P(std::cout << l << " * " << r << std::endl); + return l*r; + case DIV: + P(std::cout << l << " / " << r << std::endl); + return l/r; + // case MOD: + // return EvaluateExpr(root->l) % EvaluateExpr(root->r); + case EXP: + P(std::cout << l << " ^ " << r << std::endl); + return l*r; + case CST: + return l; + default: + return 0.0; + } +} + +#ifdef DEBUG + +int main() +{ + char* e1 = new char[100] ; + char* e = e1; + struct parse_opt root, *r; + + try + { + memset(&root, 0, sizeof(root)); + r = &root; + strcpy(e1, "4*3"); + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "4*3+5"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "3+3+3"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "3+3+3+3"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "4+3*5"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "-4+3*5/2"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "5+-4"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "5--4"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "4*(3+2)"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "(3+2)*4"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "4*(3+2)+5"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "5+(3+2)*4"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "3+(3+(3+3))"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "3+(3+(3+(3+3)))*5"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "5+(3/(6+8--5)*9)*4"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + + e1 = e; + memset(e1, 0, 100); + strcpy(e1, "5+(3*(6+8--5)/9)*4"); + memset(&root, 0, sizeof(root)); + r = &root; + ParseExp(&e1, r, false); + std::cout << e << " = " << EvaluateExpr(&root, true) << "\n"; + } + catch (int e) + { + std::cout << "Error " << e << std::endl; + } + + return 0; +} + +#endif diff --git a/src/ParseExp.h b/src/ParseExp.h new file mode 100644 index 0000000..00c09c5 --- /dev/null +++ b/src/ParseExp.h @@ -0,0 +1,29 @@ +/* + Copyright 2010 Grégory Soutadé + + This file is part of KissCount. + + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . +*/ + +struct parse_opt { + struct parse_opt* root; + char type; + double value; + struct parse_opt* l; + struct parse_opt* r; +}; + +void ParseExp(char** expr, struct parse_opt* root, bool needParenthesis); +double EvaluateExpr(struct parse_opt* root, bool del); diff --git a/src/view/grid/wxGridCellFormulaEditor.cpp b/src/view/grid/wxGridCellFormulaEditor.cpp index 7e0ca2d..bfd09d4 100644 --- a/src/view/grid/wxGridCellFormulaEditor.cpp +++ b/src/view/grid/wxGridCellFormulaEditor.cpp @@ -47,19 +47,41 @@ bool wxGridCellFormulaEditor::EndEdit (int row, int col, wxGrid *grid/*, const w { wxString res = GetValue(); Operation op; + char* str, *str2; + struct parse_opt opt, *r; bool ret; res = res.Trim(); if (res.StartsWith(wxT("="))) + { + str = (char*) std::string(res.mb_str()).c_str(); + str2 = new char[strlen(str)]; + strcpy(str2, str+1); + r = &opt; + str = str2; + try { + ParseExp(&str2, r, false); + } + catch(...) + { + wxMessageBox(_("Invalid formula !"), _("Error"), wxICON_ERROR | wxOK); + delete str; + return false; + } + + delete str; _formula = res; + + ret = wxGridCellTextEditor::EndEdit(row, col, grid); + + grid->SetCellValue(row, col, wxString::Format(wxT("%.2lf"), EvaluateExpr(&opt, true))); + } else + { _formula = wxT(""); - - ret = wxGridCellTextEditor::EndEdit(row, col, grid); - - if (_formula.Length()) - grid->SetCellValue(row, col, wxT("0")); + ret = wxGridCellTextEditor::EndEdit(row, col, grid); + } return ret; } diff --git a/src/view/grid/wxGridCellFormulaEditor.h b/src/view/grid/wxGridCellFormulaEditor.h index 8817bf6..636a677 100644 --- a/src/view/grid/wxGridCellFormulaEditor.h +++ b/src/view/grid/wxGridCellFormulaEditor.h @@ -24,7 +24,7 @@ #include #include #include "GridAccount.h" - +#include "../../ParseExp.h" class wxGridCellFormulaEditor : public wxGridCellTextEditor { public: