Use C++ std algorithms in controller
Use methods from User instead of directly modify attributes
This commit is contained in:
@@ -105,6 +105,35 @@ const wxFont User::GetCategoryFont(const wxString& catId)
|
||||
return f;
|
||||
}
|
||||
|
||||
void User::AddCategory(const Category& cat)
|
||||
{
|
||||
_categories.push_back(cat);
|
||||
_categoriesFonts.push_back(KissCount::ExtractFont(wxT("")));
|
||||
}
|
||||
|
||||
void User::UpdateCategory(const Category& cat)
|
||||
{
|
||||
std::vector<Category>::iterator it = std::find(_categories.begin(), _categories.end(), cat.id);
|
||||
|
||||
if (it !=_categories.end())
|
||||
{
|
||||
*it = cat;
|
||||
_categoriesFonts[it-_categories.begin()] = KissCount::ExtractFont(cat.font);
|
||||
}
|
||||
}
|
||||
|
||||
void User::DeleteCategory(const Category& cat)
|
||||
{
|
||||
std::vector<Category>::iterator it = std::find(_categories.begin(), _categories.end(), cat.id);
|
||||
|
||||
if (it !=_categories.end())
|
||||
{
|
||||
int pos = it - _categories.begin();
|
||||
_categories.erase(_categories.begin()+pos);
|
||||
_categoriesFonts.erase(_categoriesFonts.begin()+pos);
|
||||
}
|
||||
}
|
||||
|
||||
Account User::GetAccount(const wxString& accountId) throw (AccountNotFound)
|
||||
{
|
||||
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), accountId);
|
||||
@@ -134,6 +163,27 @@ wxString User::GetAccountId(const wxString& accountName)
|
||||
return wxT("0") ;
|
||||
}
|
||||
|
||||
void User::AddAccount(Account& ac)
|
||||
{
|
||||
_accounts.push_back(ac);
|
||||
}
|
||||
|
||||
void User::UpdateAccount(Account& ac)
|
||||
{
|
||||
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), ac.id);
|
||||
|
||||
if (it != _accounts.end())
|
||||
*it = ac;
|
||||
}
|
||||
|
||||
void User::DeleteAccount(Account& ac)
|
||||
{
|
||||
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), ac.id);
|
||||
|
||||
if (it != _accounts.end())
|
||||
_accounts.erase(it);
|
||||
}
|
||||
|
||||
int User::GetCategoriesNumber()
|
||||
{
|
||||
return _categories.size();
|
||||
|
||||
Reference in New Issue
Block a user