Fix bugs in group and ungroup

This commit is contained in:
Grégory Soutadé 2011-11-06 10:47:16 +01:00
parent c94bf51007
commit 76f7a70d1e

View File

@ -1043,7 +1043,7 @@ void GridAccount::OnOperationModified(int row, int col)
for(it = new_op.childs.begin(); it != new_op.childs.end(); it++) for(it = new_op.childs.begin(); it != new_op.childs.end(); it++)
{ {
op2 = GetOperation(*it); op2 = GetOperation(*it);
if (op2.day > last_day) break; if ((int)op2.day > last_day) break;
i++; i++;
} }
@ -1193,7 +1193,7 @@ void GridAccount::Group()
std::vector<Operation> ops; std::vector<Operation> ops;
std::vector<Operation>::iterator it2; std::vector<Operation>::iterator it2;
std::vector<int>::iterator it3; std::vector<int>::iterator it3;
int parent = 0; int parent = 0, deletedRows;
Operation op, op2; Operation op, op2;
int fix = -1, i, a, row; int fix = -1, i, a, row;
@ -1201,17 +1201,15 @@ void GridAccount::Group()
for (int i = 0; i < selected.size(); ++i) for (int i = 0; i < selected.size(); ++i)
{ {
op = _displayedOperations[selected[i].row()] ; row = selected[i].row();
op = _displayedOperations[row] ;
if (op.id) if (op.id)
{ {
if (!parent) if (!parent)
{ {
if (op.parent) if (op.parent)
{
parent = op.parent; parent = op.parent;
continue;
}
else if(op.meta) else if(op.meta)
parent = op.id; parent = op.id;
} }
@ -1224,6 +1222,12 @@ void GridAccount::Group()
} }
} }
if (op.parent)
{
row = GetDisplayedRow(op.parent);
op = _displayedOperations[row] ;
}
if (fix != -1 && ((!fix && op.fix_cost) || (fix && !op.fix_cost))) if (fix != -1 && ((!fix && op.fix_cost) || (fix && !op.fix_cost)))
{ {
QMessageBox::critical(0, _("Error"), _("Cannot group these operations")); QMessageBox::critical(0, _("Error"), _("Cannot group these operations"));
@ -1234,7 +1238,7 @@ void GridAccount::Group()
fix = op.fix_cost ? 1 : 0; fix = op.fix_cost ? 1 : 0;
ops.push_back(op); ops.push_back(op);
rows.push_back(selected[i].row()); rows.push_back(row);
} }
} }
@ -1271,22 +1275,20 @@ void GridAccount::Group()
//if (op.id) return; //if (op.id) return;
} }
std::sort(rows.begin(), rows.end());
for(i=0; i<(int)rows.size(); i++) for(i=0; i<(int)rows.size(); i++)
{ {
if (ops[i].meta) if (ops[i].meta)
RemoveMeta(ops[i], rows[i], true, false); deletedRows = RemoveMeta(ops[i], rows[i], true, false);
else else
{ {
if (ops[i].fix_cost) _fixCosts--; if (ops[i].fix_cost) _fixCosts--;
removeRow(rows[i]); removeRow(rows[i]);
_displayedOperations.erase(_displayedOperations.begin()+rows[i]); _displayedOperations.erase(_displayedOperations.begin()+rows[i]);
deletedRows = 1;
}
for(a=i+1; a<(int)rows.size(); a++) for(a=i+1; a<(int)rows.size(); a++)
if (rows[a] >= rows[i]) if (rows[a] >= rows[i])
rows[a]--; rows[a] -= deletedRows;
}
} }
for(it2=ops.begin(); it2!=ops.end(); it2++) for(it2=ops.begin(); it2!=ops.end(); it2++)
@ -1317,8 +1319,6 @@ void GridAccount::Group()
UpdateMeta(op); UpdateMeta(op);
InsertIntoGrid(op); InsertIntoGrid(op);
UpdateOperation(op);
} }
@ -1418,7 +1418,6 @@ removeLastGroup:
break; break;
} }
UpdateMeta(op2); UpdateMeta(op2);
UpdateOperation(op2);
} }
line = GetDisplayedRow(parent); line = GetDisplayedRow(parent);