From 20509721cffe34310edf2c2e5f51cfa5ac955dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Thu, 10 Jun 2010 19:15:25 +0200 Subject: [PATCH] wip --- view/AccountPanel.cpp | 177 +++++++++++++++++++++--------------------- view/AccountPanel.h | 1 + 2 files changed, 90 insertions(+), 88 deletions(-) diff --git a/view/AccountPanel.cpp b/view/AccountPanel.cpp index 713c85a..a8b5da4 100644 --- a/view/AccountPanel.cpp +++ b/view/AccountPanel.cpp @@ -224,7 +224,7 @@ void AccountPanel::ShowMonth(int year, int month) User* user = _kiss->GetUser(); DEFAULT_FONT(font); std::map::iterator categoryIt; - wxGridCellChoiceEditor* categoryEditor, *accountEditor; + //wxGridCellChoiceEditor* categoryEditor, *accountEditor; int i; _curMonth = month; @@ -272,72 +272,15 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS } ; */ for (;it->fix_cost && it != _curOperations->end(); it++) - { - curLine++; - _fixCosts++; - _grid->AppendRows(); - SET_ROW_COLOR(curLine, OWN_YELLOW); - _grid->SetCellValue(curLine, DESCRIPTION, it->description); - _grid->SetCellValue(curLine, DATE, wxString::Format(wxT("%02d/%02d/%d"), it->day+1, it->month+1, it->year)); - _grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year)); - if (it->amount < 0) - _grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -it->amount)); - else - _grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%.2lf"), it->amount)); - _grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2)); - _grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2)); - _grid->SetCellValue(curLine, CATEGORY, _("Fixe")); - _grid->SetReadOnly(curLine, CATEGORY); - accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); - _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); - _grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account)); - } + InsertOperation(user, &(*it), ++curLine, true); - _grid->AppendRows(); - curLine++; - SET_ROW_COLOR(curLine, OWN_YELLOW); - _grid->SetCellValue(curLine, CATEGORY, _("Fixe")); - _grid->SetReadOnly(curLine, CATEGORY); - _grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year)); - _grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2)); - _grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2)); - accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); - _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); - - _grid->_fixCosts = _fixCosts+1; + InsertOperation(user, NULL, ++curLine, true); + _grid->_fixCosts = _fixCosts--; for (; it != _curOperations->end(); it++) - { - curLine++; - _grid->AppendRows(); - SET_ROW_COLOR(curLine, OWN_GREEN); - _grid->SetCellValue(curLine, DESCRIPTION, it->description); - _grid->SetCellValue(curLine, DATE, wxString::Format(wxT("%02d/%02d/%d"), it->day+1, it->month+1, it->year)); - _grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year)); - if (it->amount < 0) - _grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -it->amount)); - else - _grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%.2lf"), it->amount)); - _grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2)); - _grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2)); - categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()+1, _categories, false); - _grid->SetCellEditor(curLine, CATEGORY, categoryEditor); - _grid->SetCellValue(curLine, CATEGORY, user->GetCategoryName(it->category)); - accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); - _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); - _grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account)); - } + InsertOperation(user, &(*it), ++curLine, false); - _grid->AppendRows(); - curLine++; - SET_ROW_COLOR(curLine, OWN_GREEN); - categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, _categories, false); - _grid->SetCellEditor(curLine, CATEGORY, categoryEditor); - _grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year)); - _grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2)); - _grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2)); - accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); - _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); + InsertOperation(user, NULL, ++curLine, false); _grid->AutoSizeColumn(CATEGORY, false); _grid->AutoSizeColumn(ACCOUNT, false); @@ -352,37 +295,43 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix) { - _grid->InsertRows(line, 1); - _grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year)); - _grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2)); - _grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2)); - accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); + _grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2)); + _grid->SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(-1, 2)); + wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); + _grid->SetCellEditor(line, ACCOUNT, accountEditor); + wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()+1, _categories, false); + _grid->SetCellEditor(line, CATEGORY, categoryEditor); if (fix) { - _fixCosts++; - SET_ROW_COLOR(curLine, OWN_YELLOW); - _grid->SetCellValue(curLine, CATEGORY, _("Fixe")); - _grid->SetReadOnly(curLine, CATEGORY); + _fixCosts++; + SET_ROW_COLOR(line, OWN_YELLOW); + _grid->SetCellValue(line, CATEGORY, _("Fixe")); + _grid->SetReadOnly(line, CATEGORY); } else { - SET_ROW_COLOR(curLine, OWN_GREEN); + SET_ROW_COLOR(line, OWN_GREEN); } if (op) { - _grid->SetCellValue(curLine, DESCRIPTION, it->description); - _grid->SetCellValue(curLine, DATE, wxString::Format(wxT("%02d/%02d/%d"), it->day+1, it->month+1, it->year)); - if (it->amount < 0) - _grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%.2lf"), -it->amount)); - else - _grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%.2lf"), it->amount)); - _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); - _grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account)); + _grid->SetCellEditor(line, DATE, new CalendarEditor(op->day+1, op->month, op->year)); + _grid->SetCellValue(line, DESCRIPTION, op->description); + _grid->SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year)); + if (op->amount < 0) + _grid->SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount)); + else + _grid->SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount)); + _grid->SetCellValue(line, ACCOUNT, user->GetAccountName(op->account)); + _grid->SetCellValue(line, CATEGORY, user->GetCategoryName(op->category)); } + else + { + _grid->SetCellEditor(line, DATE, new CalendarEditor(0, _curMonth, _curYear)); + } } void AccountPanel::InitAccountsGrid(User* user, int month, int year) @@ -495,11 +444,17 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) User* user = _kiss->GetUser(); int row = event.GetRow()-1; struct operation new_op, cur_op; - int op_complete = 5; + int op_complete = 5, i; wxString value ; wxDateTime date; - bool need_insertion = false; + bool need_insertion = false, fix_op=false; + static bool inModification = false ; + // Avoid recursives calls + if (inModification) return; + + inModification = true ; + if (event.GetCol() == DEBIT) _grid->SetCellValue(event.GetRow(), CREDIT, _("")); else if (event.GetCol() == CREDIT) @@ -551,7 +506,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) op_complete--; } - // Penser au fix + // Penser au fix implosif // Modify a fix operation if (row < _fixCosts) { @@ -560,18 +515,29 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) if (cur_op.day != new_op.day) { need_insertion = true; - _grid->DeleteRows(row, 1); + _grid->DeleteRows(event.GetRow(), 1); _curOperations->erase(_curOperations->begin()+row); } else (*_curOperations)[row] = new_op; _kiss->UpdateOperation(new_op); + fix_op = true; } // Add a fixCost else if (row == _fixCosts) { - if (op_complete) return ; + if (op_complete) { + inModification = false ; + return ; + } need_insertion = true; + fix_op = true; + + for(i=0; iSetCellValue(event.GetRow(), i, _("")); + } } // Modify an operation else if (row <= user->GetOperationsNumber(_curMonth, _curYear)) @@ -582,7 +548,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) if (cur_op.day != new_op.day) { need_insertion = true; - _grid->DeleteRows(row+1, 1); + _grid->DeleteRows(event.GetRow(), 1); _curOperations->erase(_curOperations->begin()+row); } else @@ -593,10 +559,45 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) else { row--; - if (op_complete) return ; + if (op_complete) { + inModification = false ; + return ; + } need_insertion = true; + for(i=0; iSetCellValue(event.GetRow(), i, _("")); + } + } + + if (need_insertion) + { + for(i=0; i<(int)_curOperations->size(); i++) + { + if ((*_curOperations)[i].fix_cost && !fix_op) continue; + if (!(*_curOperations)[i].fix_cost && fix_op) break; + if ((*_curOperations)[i].day > new_op.day) + { + if (i) + { + // First Operation + if ((*_curOperations)[i-1].fix_cost && !fix_op) break; + i--; + } + break; + } + } + + _curOperations->insert(_curOperations->begin()+i ,new_op); + i++; // For header + if (!fix_op) i++; + InsertOperation(user, &new_op, i, fix_op); + if (fix_op) + _grid->_fixCosts = _fixCosts+1; } UpdateStats(); + + inModification = false ; } diff --git a/view/AccountPanel.h b/view/AccountPanel.h index 05490b2..932eb5d 100644 --- a/view/AccountPanel.h +++ b/view/AccountPanel.h @@ -60,6 +60,7 @@ private: void InitStatsGrid(User* user); void InitAccountsGrid(User* user, int month, int year); void UpdateStats(); + void InsertOperation(User* user, operation* op, int line, bool fix); DECLARE_EVENT_TABLE(); };