From 76f7a70d1e6dbf5843ac1dd57a1697aec9332f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 6 Nov 2011 10:47:16 +0100 Subject: [PATCH] Fix bugs in group and ungroup --- src/view/grid/GridAccount.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 67d2b45..75775b3 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -1043,7 +1043,7 @@ void GridAccount::OnOperationModified(int row, int col) for(it = new_op.childs.begin(); it != new_op.childs.end(); it++) { op2 = GetOperation(*it); - if (op2.day > last_day) break; + if ((int)op2.day > last_day) break; i++; } @@ -1193,7 +1193,7 @@ void GridAccount::Group() std::vector ops; std::vector::iterator it2; std::vector::iterator it3; - int parent = 0; + int parent = 0, deletedRows; Operation op, op2; int fix = -1, i, a, row; @@ -1201,17 +1201,15 @@ void GridAccount::Group() for (int i = 0; i < selected.size(); ++i) { - op = _displayedOperations[selected[i].row()] ; + row = selected[i].row(); + op = _displayedOperations[row] ; if (op.id) { if (!parent) { if (op.parent) - { parent = op.parent; - continue; - } else if(op.meta) 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))) { QMessageBox::critical(0, _("Error"), _("Cannot group these operations")); @@ -1234,7 +1238,7 @@ void GridAccount::Group() fix = op.fix_cost ? 1 : 0; 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; } - std::sort(rows.begin(), rows.end()); - for(i=0; i<(int)rows.size(); i++) { if (ops[i].meta) - RemoveMeta(ops[i], rows[i], true, false); + deletedRows = RemoveMeta(ops[i], rows[i], true, false); else { if (ops[i].fix_cost) _fixCosts--; removeRow(rows[i]); _displayedOperations.erase(_displayedOperations.begin()+rows[i]); - - for(a=i+1; a<(int)rows.size(); a++) - if (rows[a] >= rows[i]) - rows[a]--; + deletedRows = 1; } + for(a=i+1; a<(int)rows.size(); a++) + if (rows[a] >= rows[i]) + rows[a] -= deletedRows; } for(it2=ops.begin(); it2!=ops.end(); it2++) @@ -1317,8 +1319,6 @@ void GridAccount::Group() UpdateMeta(op); InsertIntoGrid(op); - - UpdateOperation(op); } @@ -1418,7 +1418,6 @@ removeLastGroup: break; } UpdateMeta(op2); - UpdateOperation(op2); } line = GetDisplayedRow(parent);