From 7dfe4bdb18a03aee7ce8aa12c118fa85b5239ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Fri, 1 Oct 2010 20:09:15 +0200 Subject: [PATCH] * Fix some Group operations bugs. Still a buggy version with Group management ! --- src/controller/KissCount.cpp | 28 +++++++++++++++------- src/view/AccountPanel.cpp | 2 ++ src/view/grid/GridAccount.cpp | 44 ++++++++++++++++++++++++----------- src/view/grid/GridAccount.h | 2 +- 4 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 4a4f1ca..2989c48 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -219,7 +219,7 @@ std::map > KissCount::GetAllOperations() void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo) { - std::vector::iterator it; + std::vector::iterator it, it2; std::map meta; Operation op; @@ -233,28 +233,40 @@ void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int year LoadYear(yearFrom, false); for(it = (*_user->_operations[yearFrom])[monthFrom].begin(); - it != (*_user->_operations[yearFrom])[monthFrom].end() - && it->fix_cost; - it++) + it != (*_user->_operations[yearFrom])[monthFrom].end(); + it++) { + if (!it->fix_cost) continue; op = *it; op.month = monthTo; op.year = yearTo; op.checked = false; op.id = AddOperation(op); + op.childs.clear(); if (op.meta) meta[it->id] = op.id; (*_user->_operations[yearTo])[monthTo].push_back(op); } // Re Generate parents - for(it = (*_user->_operations[yearFrom])[monthFrom].begin(); - it != (*_user->_operations[yearFrom])[monthFrom].end() - && it->fix_cost; - it++) + for(it = (*_user->_operations[yearFrom])[monthTo].begin(); + it != (*_user->_operations[yearFrom])[monthTo].end(); + it++) { if (it->parent.Length()) + { it->parent = meta[it->parent]; + UpdateOperation(*it); + + for(it2 = (*_user->_operations[yearFrom])[monthTo].begin(); + it2 != (*_user->_operations[yearFrom])[monthTo].end(); + it2++) + if (it2->id == it->parent) + { + it2->childs.push_back(&(*it)); + break; + } + } } } _wxUI->GenerateMonth(monthTo, yearTo); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index 0c4d94f..5f25fc8 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -430,6 +430,8 @@ void AccountPanel::UpdateStats() for (it=_curOperations->begin(); it!=_curOperations->end(); it++) { + if (it->meta) continue; + if (it->amount > 0) { if (day >= it->day) diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 0c6e98b..9fd5fc0 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -421,10 +421,11 @@ void GridAccount::InsertIntoGrid(Operation* op) } } - if (!(_displayedOperations)[i]->fix_cost && op->fix_cost) + if (i == (int)_displayedOperations.size() || + i == _fixCosts) + i--; + else if (!(_displayedOperations)[i]->fix_cost && op->fix_cost) i --; - else if (i == (int)_displayedOperations.size() || - i == _fixCosts) i--; _operations->push_back(*op); @@ -768,7 +769,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event) event.Skip(); } -void GridAccount::UpdateMeta(Operation* op, std::vector ops) +void GridAccount::UpdateMeta(Operation* op, std::vector& ops) { std::vector::iterator it; Operation* op_ ; @@ -802,6 +803,7 @@ void GridAccount::UpdateMeta(Operation* op, std::vector ops) if (op_->category.Length() && op_->category != category) updateCat = false; } + op_->parent = op->id; } if (updateCat) @@ -815,7 +817,7 @@ void GridAccount::Group() std::vector ops; std::vector::iterator it2, it3; wxString parent = wxT(""); - Operation* op; + Operation* op=NULL; int fix = -1, i; // Singly selected cells. @@ -837,31 +839,40 @@ void GridAccount::Group() if (!parent.Length()) { if (op->parent.Length()) + { parent = op->parent; + continue; + } else if(op->meta) parent = op->id; } else { - if ((parent.Length() && op->parent != parent) || (fix != -1 && ((!fix && op->fix_cost) || (fix && !op->fix_cost)))) + if ((parent.Length() && op->parent.Length() && op->parent != parent)) { wxMessageBox(_("Cannot group these operations"), _("Error"), wxICON_ERROR | wxOK); return ; } } + if (fix != -1 && ((!fix && op->fix_cost) || (fix && !op->fix_cost))) + { + wxMessageBox(_("Cannot group these operations"), _("Error"), wxICON_ERROR | wxOK); + return ; + } + if (fix == -1) fix = op->fix_cost ? 1 : 0; - - rows.push_back(c.GetRow()); + ops.push_back(op); + rows.push_back(c.GetRow()); } } - if (rows.size() < 2) return; - if (!parent.Length()) { + if (rows.size() < 2) return; + op = new Operation; op->parent = wxT(""); op->day = ops[0]->day; @@ -881,10 +892,17 @@ void GridAccount::Group() } else { - for(i=0, it2=ops.begin(); it2!=ops.end(); it2++, i++) - if ((*it2)->id == parent) + if (rows.size() < 1) return; + + for(i=0, it2=_displayedOperations.begin(); it2!=_displayedOperations.end(); it2++, i++) + if (*it2 && (*it2)->id == parent) + { + RemoveMeta(*it2, i, true, false); + op = *it2; break; - op = *it2; + } + + if (!op) return; } std::sort(rows.begin(), rows.end()); diff --git a/src/view/grid/GridAccount.h b/src/view/grid/GridAccount.h index 5f9cd68..8793251 100644 --- a/src/view/grid/GridAccount.h +++ b/src/view/grid/GridAccount.h @@ -68,7 +68,7 @@ private: void ResetWeeks(); void InsertIntoGrid(Operation* op); void DeleteOperation(const Operation& op); - void UpdateMeta(Operation* op, std::vector ops); + void UpdateMeta(Operation* op, std::vector& ops); void RemoveMeta(Operation* op, int line, bool removeRoot, bool deleteOp); DECLARE_EVENT_TABLE();