From f2dcfcb356c73f8041f59e8efb4b10a85f1e64f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Thu, 14 Oct 2010 22:16:22 +0200 Subject: [PATCH] * Corrects a lot of bugs * Add Tabulation when it's a meta operation child --- src/ParseExp.cpp | 3 +- src/view/grid/GridAccount.cpp | 26 +++++++----- src/view/grid/GridAccount.h | 1 + src/view/grid/wxGridCellFormulaEditor.cpp | 1 + src/view/grid/wxGridCellTabStringRenderer.cpp | 40 +++++++++++++++++++ src/view/grid/wxGridCellTabStringRenderer.h | 35 ++++++++++++++++ 6 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 src/view/grid/wxGridCellTabStringRenderer.cpp create mode 100644 src/view/grid/wxGridCellTabStringRenderer.h diff --git a/src/ParseExp.cpp b/src/ParseExp.cpp index cb22720..81f7e37 100644 --- a/src/ParseExp.cpp +++ b/src/ParseExp.cpp @@ -59,6 +59,7 @@ 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 @@ -80,7 +81,7 @@ double atof(char* s, int size) if (neg > 0) { - res += (*s - '0') / neg; + res += (double) (*s - '0') / (double)neg; neg *= 10; } else diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index d7756ba..be1b53e 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -313,6 +313,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, description = op.description; UNESCAPE_CHARS(description); SetCellValue(line, DESCRIPTION, description); + SetCellRenderer(line, DESCRIPTION, new wxGridCellTabStringRenderer ()); SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op.day+1, month+1, year)); if (op.amount < 0) SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op.amount)); @@ -328,7 +329,10 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ()); SetCellEditor(line, CHECKED, new wxGridCellFastBoolEditor ()); - color = cat.backcolor; + if (op.category.Length()) + color = cat.backcolor; + else + color = OWN_GREEN; if (op.checked) { @@ -494,7 +498,7 @@ void GridAccount::RemoveMeta(Operation& op, int line, bool removeRoot, bool dele if (treeRenderer->IsCollapsed()) { DeleteRows(line+1, 1); - if (_displayedOperations[line+1].fix_cost) _fixCosts--; + if (op2.fix_cost) _fixCosts--; _displayedOperations.erase(_displayedOperations.begin()+line+1); } @@ -517,6 +521,7 @@ void GridAccount::RemoveMeta(Operation& op, int line, bool removeRoot, bool dele DeleteOperation(op); _kiss->DeleteOperation(op); } + if (op.fix_cost) _fixCosts--; } treeRenderer->DecRef(); @@ -1040,7 +1045,7 @@ void GridAccount::Group() std::vector::iterator it3; wxString parent = wxT(""); Operation op, op2; - int fix = -1, i; + int fix = -1, i, row; GetSelectedOperations(&selected); @@ -1110,15 +1115,10 @@ void GridAccount::Group() { if (rows.size() < 1) return; - for(i=0, it2=_displayedOperations.begin(); it2!=_displayedOperations.end(); it2++, i++) - if (it2->id.Length() && it2->id == parent) - { - RemoveMeta(*it2, i, true, false); - op = *it2; - break; - } + row = GetDisplayedRow(parent); + op = _displayedOperations[row]; - if (op.id.Length()) return; + //if (op.id.Length()) return; } std::sort(rows.begin(), rows.end()); @@ -1131,6 +1131,7 @@ void GridAccount::Group() RemoveMeta(ops[i], rows[i]-i, true, false); else { + if (ops[i].fix_cost) _fixCosts--; DeleteRows(rows[i]-i, 1); _displayedOperations.erase(_displayedOperations.begin()+rows[i]-i); } @@ -1141,6 +1142,7 @@ void GridAccount::Group() RemoveMeta(ops[i], rows[i], true, false); else { + if (ops[i].fix_cost) _fixCosts--; DeleteRows(rows[i], 1); _displayedOperations.erase(_displayedOperations.begin()+rows[i]); } @@ -1149,6 +1151,8 @@ void GridAccount::Group() for(it2=ops.begin(); it2!=ops.end(); it2++) { + if (it2->id == parent) continue; + for (i=0, it3=op.childs.begin(); it3!=op.childs.end(); it3++, i++) { op2 = GetOperation(*it3); diff --git a/src/view/grid/GridAccount.h b/src/view/grid/GridAccount.h index c7eb5dc..139d876 100644 --- a/src/view/grid/GridAccount.h +++ b/src/view/grid/GridAccount.h @@ -31,6 +31,7 @@ #include "wxGridCellTreeButtonRenderer.h" #include "wxGridCellTreeButtonEditor.h" #include "wxGridCellFormulaEditor.h" +#include "wxGridCellTabStringRenderer.h" class KissCount; diff --git a/src/view/grid/wxGridCellFormulaEditor.cpp b/src/view/grid/wxGridCellFormulaEditor.cpp index bfd09d4..a5d08ae 100644 --- a/src/view/grid/wxGridCellFormulaEditor.cpp +++ b/src/view/grid/wxGridCellFormulaEditor.cpp @@ -52,6 +52,7 @@ bool wxGridCellFormulaEditor::EndEdit (int row, int col, wxGrid *grid/*, const w bool ret; res = res.Trim(); + res.Replace(wxT(","), wxT("."), true); if (res.StartsWith(wxT("="))) { diff --git a/src/view/grid/wxGridCellTabStringRenderer.cpp b/src/view/grid/wxGridCellTabStringRenderer.cpp new file mode 100644 index 0000000..ee9eedd --- /dev/null +++ b/src/view/grid/wxGridCellTabStringRenderer.cpp @@ -0,0 +1,40 @@ +/* + 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 "wxGridCellTabStringRenderer.h" + +void wxGridCellTabStringRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected) +{ + wxString d; + wxGridTableBase * table ; + + if (!((GridAccount*) &grid)->_displayedOperations[row].parent.Length()) + { + wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); + return; + } + + table = grid.GetTable(); + + d = table->GetValue(row, col).Trim(); + + table->SetValue(row, col, wxT(" ") + d); + wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); + table->SetValue(row, col, d); +} diff --git a/src/view/grid/wxGridCellTabStringRenderer.h b/src/view/grid/wxGridCellTabStringRenderer.h new file mode 100644 index 0000000..d57ecab --- /dev/null +++ b/src/view/grid/wxGridCellTabStringRenderer.h @@ -0,0 +1,35 @@ +/* + 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 . +*/ + +#ifndef WXGRIDCELLTABSTRINGRENDERER_H +#define WXGRIDCELLTABSTRINGRENDERER_H + +#include +#include +#include + +#include "GridAccount.h" + +class wxGridCellTabStringRenderer : public wxGridCellStringRenderer +{ +public: + virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected); +}; + +#endif