A lot of good job done

This commit is contained in:
2010-06-21 13:02:02 +02:00
parent 083054b376
commit c322a01adb
10 changed files with 125 additions and 62 deletions

View File

@@ -21,7 +21,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
int i ;
DEFAULT_FONT(font);
User* user = _kiss->GetUser();
std::map<wxString, Account>::iterator accountIt;
std::vector<Account>::iterator accountIt;
std::map<wxString, wxString>::iterator it;
wxColour categoryColors[] = {wxColour(0x00, 0x45, 0x86),
wxColour(0xFF, 0x3E, 0x0E),
@@ -41,12 +41,12 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
_pie = new PiePlot();
_accounts = new wxString[user->_accounts.size()];
_accounts = new wxString[user->GetAccountsNumber()];
for (i=0,
accountIt = user->_accounts.begin();
accountIt != user->_accounts.end();
accountIt++, i++)
_accounts[i] = user->_accounts[accountIt->first].name;
_accounts[i] = accountIt->name;
_categories = new wxString[user->GetCategoriesNumber()] ;
for(i=0, it = user->_preferences._categories.begin(); it != user->_preferences._categories.end(); it++, i++)
@@ -319,7 +319,7 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
_grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2));
_grid->SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(-1, 2));
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->_accounts.size(), _accounts, false);
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false);
_grid->SetCellEditor(line, ACCOUNT, accountEditor);
// Remove Fix category
wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false);
@@ -404,9 +404,8 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
void AccountPanel::InitAccountsGrid(User* user, int month, int year)
{
std::map<wxString, Account>::iterator it;
std::vector<Account>::iterator it;
int curLine = 0;
Account account ;
double value;
int i, a;
DEFAULT_FONT(font);
@@ -416,19 +415,17 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
for (i=0, it = user->_accounts.begin(); it != user->_accounts.end(); i++, it++, curLine++)
{
_accountsGrid->AppendRows();
account = user->_accounts[it->first];
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, account.number);
_accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, account.name);
value = _kiss->GetAccountAmount(it->first, month, year);
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number);
_accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name);
value = _kiss->GetAccountAmount(it->id, month, year);
_accountsGrid->SetCellValue(curLine, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value));
_accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2));
for (a=0; a<NUMBER_COLS_ACCOUNTS; a++)
_accountsGrid->SetReadOnly(curLine, a, a != ACCOUNT_INIT);
_accountsGrid->SetCellFont(curLine, ACCOUNT_CUR, font);
_accountsIndexes[it->first] = i;
_accountsInitValues[it->first] = value;
_accountsInitValues[it->id] = value;
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_INIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_CUR, wxALIGN_RIGHT, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_FINAL, wxALIGN_RIGHT, wxALIGN_CENTRE);
@@ -447,6 +444,7 @@ void AccountPanel::UpdateStats()
std::map<wxString, double> curAccountAmount, finalAccountAmount;
std::map<wxString, double>::iterator doubleIt;
std::map<wxString, int>::iterator intIt;
std::vector<Account>::iterator accountIt;
curDate.SetToCurrent();
@@ -498,13 +496,12 @@ void AccountPanel::UpdateStats()
for(i=0; i<user->GetCategoriesNumber()+1; i++)
_statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf"), _categoriesValues[i]));
for (intIt=_accountsIndexes.begin(); intIt!=_accountsIndexes.end(); intIt++)
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
{
i = _accountsIndexes[intIt->first];
value = curAccountAmount[intIt->first];
value = curAccountAmount[accountIt->id];
_accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf"), value));
_accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00));
value = finalAccountAmount[intIt->first];
value = finalAccountAmount[accountIt->id];
_accountsGrid->SetCellValue(i, ACCOUNT_FINAL, wxString::Format(wxT("%.2lf"), value));
}
@@ -653,13 +650,14 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
}
need_insertion = true;
fix_op = true;
new_op.fix_cost = true;
for(i=0; i<NUMBER_COLS_OPS; i++)
{
if (i == CATEGORY) continue;
_grid->SetCellValue(event.GetRow(), i, _(""));
}
_kiss->AddOperation(new_op);
new_op.id = _kiss->AddOperation(new_op);
}
// Modify an operation
else if (row <= user->GetOperationsNumber(_curMonth, _curYear))
@@ -697,12 +695,14 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
return ;
}
need_insertion = true;
fix_op = false;
new_op.fix_cost = false;
for(i=0; i<NUMBER_COLS_OPS; i++)
{
_grid->SetCellValue(event.GetRow(), i, _(""));
}
_kiss->AddOperation(new_op);
new_op.id = _kiss->AddOperation(new_op);
}
if (need_insertion)

View File

@@ -48,7 +48,7 @@ private:
wxGrid *_statsGrid, *_accountsGrid;
PiePlot* _pie;
double *_categoriesValues;
std::map<wxString, int> _categoriesIndexes, _accountsIndexes;
std::map<wxString, int> _categoriesIndexes;
std::vector<operation>* _curOperations;
int _curMonth, _curYear;
wxString* _categories, *_accounts;

View File

@@ -80,7 +80,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p
void PreferencesPanel::InitAccounts(User* user)
{
std::map<wxString, Account>::iterator it;
std::vector<Account>::iterator it;
int curLine = 0;
Account account ;
DEFAULT_FONT(font);
@@ -97,10 +97,9 @@ void PreferencesPanel::InitAccounts(User* user)
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++)
{
_accountsGrid->AppendRows();
account = user->_accounts[it->first];
_accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, account.name);
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, account.number);
_accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name);
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number);
_accountsGrid->SetCellRenderer(curLine, ACCOUNT_SHARED, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(curLine, ACCOUNT_SHARED, new wxGridCellBoolEditor ());
@@ -108,13 +107,12 @@ void PreferencesPanel::InitAccounts(User* user)
_accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ());
_accountsGrid->SetCellRenderer(curLine, ACCOUNT_DELETE, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellBoolEditor ());
_accountsGrid->SetCellValue(curLine, ACCOUNT_SHARED, (account.shared)?_("1"):_("0"));
_accountsGrid->SetCellValue(curLine, ACCOUNT_DEFAULT, (account._default)?_("1"):_("0"));
_accountsGrid->SetCellValue(curLine, ACCOUNT_SHARED, (it->shared)?_("1"):_("0"));
_accountsGrid->SetCellValue(curLine, ACCOUNT_DEFAULT, (it->_default)?_("1"):_("0"));
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(curLine, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsIndexes[curLine] = account.id;
}
_accountsGrid->AutoSizeColumns(true);
@@ -221,18 +219,17 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
if (col == ACCOUNT_DEFAULT)
{
new_account.id = _accountsIndexes[row];
new_account.id = user->_accounts[row].id;
for (i=0; i<user->GetAccountsNumber(); i++)
{
if (i != col)
if (i != row)
{
account = user->_accounts[_accountsIndexes[i]];
account = user->_accounts[i];
if (account._default)
{
account._default = false;
_kiss->UpdateAccount(account);
user->_accounts[_accountsIndexes[i]] = account;
_accountsGrid->SetCellValue(i, ACCOUNT_DEFAULT, _(""));
break;
}
@@ -245,7 +242,7 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
// Account modification
if (user->GetAccountsNumber() && row < user->GetAccountsNumber())
{
new_account.id = _accountsIndexes[row];
new_account.id = user->_accounts[row].id;
if (col == ACCOUNT_DELETE)
{
@@ -275,6 +272,14 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
return ;
}
if (user->GetAccountId(new_account.name) != _("0"))
{
wxMessageDialog dialog(_wxUI, _("Account ")+new_account.name+_(" already exists"), _("Error"), wxOK);
dialog.ShowModal();
inModification = false;
return ;
}
_accountsGrid->SetCellRenderer(row, ACCOUNT_SHARED, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(row, ACCOUNT_SHARED, new wxGridCellBoolEditor ());
_accountsGrid->SetCellRenderer(row, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ());
@@ -303,7 +308,7 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
_accountsGrid->SetReadOnly(row+1, ACCOUNT_DELETE, true);
_wxUI->Layout();
_kiss->InsertAccount(new_account);
_kiss->AddAccount(new_account);
}
inModification = false;

View File

@@ -30,7 +30,7 @@ private:
wxUI* _wxUI;
wxGrid* _accountsGrid;
wxGrid* _categoriesGrid;
std::map<int, wxString> _categoriesIndexes, _accountsIndexes;
std::map<int, wxString> _categoriesIndexes;
void InitAccounts(User* user);
void InitCategories(User* user);