From 340a53094d5b91ab1fa077e16ab69d8db173c2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 4 Oct 2010 20:15:03 +0200 Subject: [PATCH] Improve Group feature --- src/view/grid/GridAccount.cpp | 42 ++++++++++++++++++++++++++--------- src/view/grid/GridAccount.h | 3 ++- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 46ec903..bae280c 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -140,6 +140,15 @@ Operation& GridAccount::GetOperation(const wxString& id) return *it; } +int GridAccount::GetDisplayedRow(const wxString& id) +{ + for(int i=0; i<(int)_displayedOperations.size(); i++) + if (_displayedOperations[i].id == id) + return i; + + return -1; +} + void GridAccount::LoadOperations(std::vector* operations, bool canAddOperation, bool setWeek, int month, int year) { std::vector::iterator it; @@ -613,6 +622,8 @@ void GridAccount::OnOperationModified(wxGridEvent& event) } } + cur_op = (_displayedOperations)[row] ; + if (col == CHECKED || col == CATEGORY) { color = user->GetCategory(new_op.category).backcolor; @@ -643,8 +654,6 @@ void GridAccount::OnOperationModified(wxGridEvent& event) // Modify a fix operation if (row < _fixCosts) { - cur_op = (_displayedOperations)[row] ; - if (col == DELETE) { if (cur_op.parent.Length()) @@ -717,7 +726,6 @@ void GridAccount::OnOperationModified(wxGridEvent& event) // Modify an operation else if (row < (int)(_displayedOperations.size()-1)) { - cur_op = (_displayedOperations)[row] ; new_op.id = cur_op.id; new_op.fix_cost = false; new_op.transfert = cur_op.transfert; @@ -787,21 +795,33 @@ void GridAccount::OnOperationModified(wxGridEvent& event) InsertIntoGrid(new_op); inModification = false ; + + if (!need_insertion && (col == CHECKED || col == CATEGORY) && new_op.parent.Length()) + { + op2 = GetOperation(new_op.parent); + UpdateMeta(op2); + int row2 = GetDisplayedRow(op2.id); + wxGridEvent event2(-1, 0, NULL, row2, CATEGORY); + OnOperationModified(event2); + } + event.Skip(); } -void GridAccount::UpdateMeta(Operation& op, std::vector& ops) +void GridAccount::UpdateMeta(Operation& op) { - std::vector::iterator it; + std::vector::iterator it; Operation op_ ; wxString category = wxT(""); bool updateCat = false ; op.category = wxT(""); + op.checked = true; + op.amount = 0; - for(it=ops.begin(); it!=ops.end(); it++) + for(it=op.childs.begin(); it!=op.childs.end(); it++) { - op_ = *it; + op_ = GetOperation(*it); if (op_.year <= op.year && op_.month <= op.month && op_.day < op.day) { op.year = op_.year; @@ -809,6 +829,7 @@ void GridAccount::UpdateMeta(Operation& op, std::vector& ops) op.day = op_.day; } op.amount += op_.amount; + op.checked &= op_.checked; if (!op.description.Length() && op_.description.Length()) op.description = op_.description; if (!category.Length()) @@ -829,6 +850,8 @@ void GridAccount::UpdateMeta(Operation& op, std::vector& ops) if (updateCat) op.category = category; + + _kiss->UpdateOperation(op); } void GridAccount::Group() @@ -953,8 +976,6 @@ void GridAccount::Group() } } - UpdateMeta(op, ops); - for(it2=ops.begin(); it2!=ops.end(); it2++) { for (i=0, it3=op.childs.begin(); it3!=op.childs.end(); it3++, i++) @@ -978,7 +999,8 @@ void GridAccount::Group() _kiss->UpdateOperation(*it2); } - _kiss->UpdateOperation(op); + UpdateMeta(op); + InsertIntoGrid(op); } diff --git a/src/view/grid/GridAccount.h b/src/view/grid/GridAccount.h index 4942067..974287c 100644 --- a/src/view/grid/GridAccount.h +++ b/src/view/grid/GridAccount.h @@ -68,10 +68,11 @@ private: void ResetWeeks(); void InsertIntoGrid(Operation& op); void DeleteOperation(const Operation& op); - void UpdateMeta(Operation& op, std::vector& ops); + void UpdateMeta(Operation& op); void RemoveMeta(Operation& op, int line, bool removeRoot, bool deleteOp); Operation& GetOperation(const wxString& id); + int GetDisplayedRow(const wxString& id); DECLARE_EVENT_TABLE(); };