Some Grid code moved to GridAccount
This commit is contained in:
parent
67d3275b28
commit
9c52ca5362
|
@ -291,9 +291,7 @@ void AccountPanel::LoadYear(int year, bool showMonth)
|
|||
void AccountPanel::ShowMonth(int month, int year)
|
||||
{
|
||||
std::vector<Operation> operations;
|
||||
std::vector<Operation>::iterator it;
|
||||
_fixCosts = 0;
|
||||
int curLine = 0;
|
||||
User* user = _kiss->GetUser();
|
||||
DEFAULT_FONT(font);
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
|
@ -337,24 +335,7 @@ void AccountPanel::ShowMonth(int month, int year)
|
|||
// Operations are ordered
|
||||
_curOperations = &((*user->_operations[year])[month]);
|
||||
|
||||
it = _curOperations->begin();
|
||||
|
||||
for (;it != _curOperations->end() && it->fix_cost; it++)
|
||||
InsertOperation(user, &(*it), ++curLine, true);
|
||||
|
||||
InsertOperation(user, NULL, ++curLine, true);
|
||||
_grid->_fixCosts = _fixCosts--;
|
||||
|
||||
for (; it != _curOperations->end(); it++)
|
||||
InsertOperation(user, &(*it), ++curLine, false);
|
||||
|
||||
InsertOperation(user, NULL, ++curLine, false);
|
||||
|
||||
_grid->AutoSizeColumn(CATEGORY, false);
|
||||
_grid->AutoSizeColumn(DATE, false);
|
||||
_grid->AutoSizeColumn(ACCOUNT, false);
|
||||
_grid->AutoSizeColumn(DELETE, false);
|
||||
_grid->AutoSizeColumn(CHECKED, false);
|
||||
_grid->LoadOperations(_curOperations, true, true, _curMonth, _curYear);
|
||||
|
||||
InitAccountsGrid(user, month, year);
|
||||
|
||||
|
@ -377,40 +358,6 @@ void AccountPanel::ShowMonth(int month, int year)
|
|||
// SetMinSize(GetSize());
|
||||
}
|
||||
|
||||
void AccountPanel::InsertOperation(User* user, Operation* op, int line, bool fix)
|
||||
{
|
||||
std::vector<Operation>::iterator it;
|
||||
int curLine, curWeek, week, i;
|
||||
|
||||
_grid->InsertOperation(user, op, line, fix, _curMonth, _curYear);
|
||||
|
||||
if (fix)
|
||||
_fixCosts++;
|
||||
|
||||
if (op && !fix)
|
||||
{
|
||||
for (it = _curOperations->begin(), curLine=1;
|
||||
it->fix_cost && it != _curOperations->end();
|
||||
it++, curLine++) ;
|
||||
|
||||
if (it == _curOperations->end()) return;
|
||||
|
||||
curLine++;
|
||||
curWeek = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
|
||||
for (i=1, it++; it != _curOperations->end(); it++, curLine++)
|
||||
{
|
||||
week = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
|
||||
if (week != curWeek)
|
||||
{
|
||||
_grid->SetWeek(i++, curLine);
|
||||
curWeek = week;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_wxUI->Layout();
|
||||
}
|
||||
|
||||
void AccountPanel::InitAccountsGrid(User* user, int month, int year)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
|
@ -828,7 +775,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
|
|||
|
||||
i++; // For header
|
||||
if (!fix_op) i++;
|
||||
InsertOperation(user, &new_op, i, fix_op);
|
||||
_grid->InsertOperationWithWeek(user, &new_op, i, fix_op, _curMonth, _curYear);
|
||||
if (fix_op)
|
||||
_grid->_fixCosts = _fixCosts+1;
|
||||
}
|
||||
|
|
|
@ -225,16 +225,7 @@ void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
for(i=1, it = _operations->begin(); it != _operations->end(); it++, i++)
|
||||
{
|
||||
_grid->InsertOperation(user, &(*it), i, false, 0, 0);
|
||||
}
|
||||
|
||||
_grid->AutoSizeColumn(CATEGORY, false);
|
||||
_grid->AutoSizeColumn(DATE, false);
|
||||
_grid->AutoSizeColumn(ACCOUNT, false);
|
||||
_grid->AutoSizeColumn(DELETE, false);
|
||||
_grid->AutoSizeColumn(CHECKED, false);
|
||||
_grid->LoadOperations(_operations, false, false, 0, 0);
|
||||
|
||||
_wxUI->Layout();
|
||||
}
|
||||
|
|
|
@ -116,7 +116,77 @@ void GridAccount::SetWeek(int week, int line) {
|
|||
}
|
||||
}
|
||||
|
||||
void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear)
|
||||
void GridAccount::LoadOperations(std::vector<Operation>* operations, bool canAddOperation, bool setWeek, int month, int year)
|
||||
{
|
||||
std::vector<Operation>::iterator it;
|
||||
User* user = _kiss->GetUser();
|
||||
int curLine = 0;
|
||||
|
||||
_operations = operations;
|
||||
_canAddOperation = canAddOperation;
|
||||
|
||||
_fixCosts = 1;
|
||||
|
||||
it = _operations->begin();
|
||||
|
||||
for (;it != _operations->end() && it->fix_cost; it++)
|
||||
if (setWeek)
|
||||
InsertOperationWithWeek(user, &(*it), ++curLine, true, it->month, it->year);
|
||||
else
|
||||
InsertOperation(user, &(*it), ++curLine, true, it->month, it->year);
|
||||
|
||||
if (canAddOperation)
|
||||
InsertOperation(user, NULL, ++curLine, true, month, year);
|
||||
|
||||
for (; it != _operations->end(); it++)
|
||||
if (setWeek)
|
||||
InsertOperationWithWeek(user, &(*it), ++curLine, false, it->month, it->year);
|
||||
else
|
||||
InsertOperation(user, &(*it), ++curLine, false, it->month, it->year);
|
||||
|
||||
if (canAddOperation)
|
||||
InsertOperation(user, NULL, ++curLine, false, month, year);
|
||||
|
||||
AutoSizeColumn(CATEGORY, false);
|
||||
AutoSizeColumn(DATE, false);
|
||||
AutoSizeColumn(ACCOUNT, false);
|
||||
AutoSizeColumn(DELETE, false);
|
||||
AutoSizeColumn(CHECKED, false);
|
||||
}
|
||||
|
||||
void GridAccount::InsertOperationWithWeek(User* user, Operation* op, int line, bool fix, int month, int year)
|
||||
{
|
||||
std::vector<Operation>::iterator it;
|
||||
int curLine, curWeek, week, i;
|
||||
|
||||
InsertOperation(user, op, line, fix, month, year);
|
||||
|
||||
if (fix)
|
||||
_fixCosts++;
|
||||
|
||||
if (op && !fix)
|
||||
{
|
||||
for (it = _operations->begin(), curLine=1;
|
||||
it->fix_cost && it != _operations->end();
|
||||
it++, curLine++) ;
|
||||
|
||||
if (it == _operations->end()) return;
|
||||
|
||||
curLine++;
|
||||
curWeek = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
|
||||
for (i=1, it++; it != _operations->end(); it++, curLine++)
|
||||
{
|
||||
week = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
|
||||
if (week != curWeek)
|
||||
{
|
||||
SetWeek(i++, curLine);
|
||||
curWeek = week;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, int month, int year)
|
||||
{
|
||||
std::vector<Operation>::iterator it;
|
||||
int r, g, b;
|
||||
|
@ -149,18 +219,18 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
|||
{
|
||||
cat = user->GetCategory(op->category);
|
||||
|
||||
SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year));
|
||||
SetCellEditor(line, DATE, new CalendarEditor(op->day, month, year));
|
||||
description = op->description;
|
||||
UNESCAPE_CHARS(description);
|
||||
SetCellValue(line, DESCRIPTION, description);
|
||||
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
|
||||
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, month+1, year));
|
||||
if (op->amount < 0)
|
||||
SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount));
|
||||
else
|
||||
SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount));
|
||||
SetCellValue(line, ACCOUNT, user->GetAccountName(op->account));
|
||||
if (!fix)
|
||||
SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
|
||||
SetCellValue(line, CATEGORY, cat.name);
|
||||
SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ());
|
||||
SetCellEditor(line, DELETE, new wxGridCellBoolEditor ());
|
||||
SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
|
||||
|
@ -186,16 +256,16 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
|
|||
}
|
||||
else
|
||||
{
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, month, year));
|
||||
if (!fix &&
|
||||
curDate.GetMonth() == curMonth &&
|
||||
curDate.GetYear() == curYear)
|
||||
curDate.GetMonth() == month &&
|
||||
curDate.GetYear() == year)
|
||||
{
|
||||
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), curMonth+1, curYear));
|
||||
SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, curMonth, curYear));
|
||||
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), month+1, year));
|
||||
SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, month, year));
|
||||
}
|
||||
else
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, month, year));
|
||||
|
||||
if (fix)
|
||||
{
|
||||
|
|
|
@ -41,7 +41,10 @@ public:
|
|||
wxPen GetColGridLinePen (int col);
|
||||
wxPen GetRowGridLinePen (int row);
|
||||
void SetWeek(int week, int line);
|
||||
void InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear);
|
||||
|
||||
void LoadOperations(std::vector<Operation>* operations, bool canAddOperation, bool setWeek, int month, int year);
|
||||
void InsertOperationWithWeek(User* user, Operation* op, int line, bool fix, int month, int year) ;
|
||||
void InsertOperation(User* user, Operation* op, int line, bool fix, int month, int year) ;
|
||||
|
||||
void OnCellLeftClick(wxGridEvent& evt);
|
||||
|
||||
|
@ -50,6 +53,8 @@ public:
|
|||
private:
|
||||
KissCount* _kiss;
|
||||
wxString* _categories, *_accounts;
|
||||
std::vector<Operation>* _operations;
|
||||
bool _canAddOperation;
|
||||
|
||||
DECLARE_EVENT_TABLE();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user