* Fix some Group operations bugs. Still a buggy version with Group management !

This commit is contained in:
Grégory Soutadé 2010-10-01 20:09:15 +02:00
parent d9f75e5329
commit 7dfe4bdb18
4 changed files with 54 additions and 22 deletions

View File

@ -219,7 +219,7 @@ std::map<int, std::vector<int> > KissCount::GetAllOperations()
void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo)
{
std::vector<Operation>::iterator it;
std::vector<Operation>::iterator it, it2;
std::map<wxString, wxString> 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);

View File

@ -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)

View File

@ -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<Operation*> ops)
void GridAccount::UpdateMeta(Operation* op, std::vector<Operation*>& ops)
{
std::vector<Operation*>::iterator it;
Operation* op_ ;
@ -802,6 +803,7 @@ void GridAccount::UpdateMeta(Operation* op, std::vector<Operation*> 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<Operation*> ops;
std::vector<Operation*>::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());

View File

@ -68,7 +68,7 @@ private:
void ResetWeeks();
void InsertIntoGrid(Operation* op);
void DeleteOperation(const Operation& op);
void UpdateMeta(Operation* op, std::vector<Operation*> ops);
void UpdateMeta(Operation* op, std::vector<Operation*>& ops);
void RemoveMeta(Operation* op, int line, bool removeRoot, bool deleteOp);
DECLARE_EVENT_TABLE();