Use C++ std algorithms in controller
Use methods from User instead of directly modify attributes
This commit is contained in:
parent
8d7a019ca7
commit
5b9487b490
|
@ -41,7 +41,7 @@ KissCount::KissCount(const char* bdd_filename) : _user(0)
|
|||
catch (std::string s)
|
||||
{
|
||||
_wxUI->Close(true);
|
||||
throw s;
|
||||
throw ;
|
||||
}
|
||||
|
||||
_wxUI->ChangeUser();
|
||||
|
@ -173,8 +173,7 @@ wxString KissCount::AddAccount(Account& ac)
|
|||
wxDateTime curDate;
|
||||
|
||||
ac.id = _db->AddAccount(_user, ac);
|
||||
_user->_accounts.push_back(ac);
|
||||
|
||||
_user->AddAccount(ac);
|
||||
curDate.SetToCurrent();
|
||||
|
||||
SetAccountAmount(ac.id, (int)curDate.GetMonth(), curDate.GetYear(), 0.0);
|
||||
|
@ -184,13 +183,8 @@ wxString KissCount::AddAccount(Account& ac)
|
|||
|
||||
void KissCount::UpdateAccount(Account& ac)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
int i;
|
||||
|
||||
_db->UpdateAccount(ac);
|
||||
for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++)
|
||||
if (it->id == ac.id)
|
||||
_user->_accounts[i] = ac;
|
||||
_user->UpdateAccount(ac);
|
||||
|
||||
if (ac._default)
|
||||
std::sort(_user->_accounts.begin(), _user->_accounts.end(), Account());
|
||||
|
@ -198,17 +192,10 @@ void KissCount::UpdateAccount(Account& ac)
|
|||
|
||||
void KissCount::DeleteAccount(Account& ac, const wxString& replacement)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
int i;
|
||||
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it2;
|
||||
|
||||
_db->DeleteAccount(_user, ac, replacement);
|
||||
for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++)
|
||||
if (it->id == ac.id)
|
||||
{
|
||||
_user->_accounts.erase(_user->_accounts.begin()+i);
|
||||
break;
|
||||
}
|
||||
_user->DeleteAccount(ac);
|
||||
|
||||
for (it2= _user->_operations.begin();
|
||||
it2 != _user->_operations.end();
|
||||
|
@ -238,27 +225,16 @@ wxString KissCount::getSharedAccountOwner(const wxString& account)
|
|||
|
||||
wxString KissCount::AddCategory(Category& category)
|
||||
{
|
||||
wxString id;
|
||||
id = _db->AddCategory(_user, category);
|
||||
category.id = id;
|
||||
category.id = _db->AddCategory(_user, category);
|
||||
_user->AddCategory(category);
|
||||
|
||||
_user->_categories.push_back(category);
|
||||
_user->_categoriesFonts.push_back(ExtractFont(wxT("")));
|
||||
|
||||
return id;
|
||||
return category.id;
|
||||
}
|
||||
|
||||
void KissCount::UpdateCategory(Category& category)
|
||||
{
|
||||
_db->UpdateCategory(category);
|
||||
|
||||
for (int i=0; i<_user->GetCategoriesNumber();i++)
|
||||
if (_user->_categories[i].id == category.id)
|
||||
{
|
||||
_user->_categories[i] = category;
|
||||
_user->_categoriesFonts[i] = ExtractFont(category.font);
|
||||
break;
|
||||
}
|
||||
_user->UpdateCategory(category);
|
||||
}
|
||||
|
||||
void KissCount::DeleteCategory(Category& category, const wxString& replacement)
|
||||
|
@ -266,14 +242,7 @@ void KissCount::DeleteCategory(Category& category, const wxString& replacement)
|
|||
std::map<unsigned int, std::map<unsigned int, std::vector<Operation> >* >::iterator it;
|
||||
|
||||
_db->DeleteCategory(_user, category, replacement);
|
||||
|
||||
for (int i=0; i<_user->GetCategoriesNumber();i++)
|
||||
if (_user->_categories[i].id == category.id)
|
||||
{
|
||||
_user->_categories.erase(_user->_categories.begin()+i);
|
||||
_user->_categoriesFonts.erase(_user->_categoriesFonts.begin()+i);
|
||||
break;
|
||||
}
|
||||
_user->DeleteCategory(category);
|
||||
|
||||
for (it= _user->_operations.begin();
|
||||
it != _user->_operations.end();
|
||||
|
@ -575,15 +544,11 @@ wxString KissCount::CompactFont(const wxFont& font)
|
|||
|
||||
void KissCount::UnRegisterImportEngine(ImportEngine* engine)
|
||||
{
|
||||
std::vector<ImportEngine*>::iterator it;
|
||||
std::vector<ImportEngine*>* importEngines = KissCount::GetImportEngines();
|
||||
|
||||
for(it=importEngines->begin(); it!=importEngines->end(); it++)
|
||||
if (*it == engine)
|
||||
{
|
||||
importEngines->erase(it);
|
||||
break;
|
||||
}
|
||||
std::vector<ImportEngine*>::iterator it = std::find(importEngines->begin(), importEngines->end(), engine);
|
||||
|
||||
if (it!=importEngines->end()) importEngines->erase(it);
|
||||
}
|
||||
|
||||
void KissCount::RegisterImportEngine(ImportEngine* engine)
|
||||
|
@ -628,15 +593,11 @@ void KissCount::UpdateImportPattern()
|
|||
|
||||
void KissCount::UnRegisterExportEngine(ExportEngine* engine)
|
||||
{
|
||||
std::vector<ExportEngine*>::iterator it;
|
||||
std::vector<ExportEngine*>* exportEngines = KissCount::GetExportEngines();
|
||||
|
||||
for(it=exportEngines->begin(); it!=exportEngines->end(); it++)
|
||||
if (*it == engine)
|
||||
{
|
||||
exportEngines->erase(it);
|
||||
break;
|
||||
}
|
||||
std::vector<ExportEngine*>::iterator it = std::find(exportEngines->begin(), exportEngines->end(), engine);
|
||||
|
||||
if (it!=exportEngines->end()) exportEngines->erase(it);
|
||||
}
|
||||
|
||||
void KissCount::RegisterExportEngine(ExportEngine* engine)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -57,10 +57,18 @@ public:
|
|||
wxString GetCategoryName(const wxString& catId);
|
||||
wxString GetCategoryId(const wxString& catName);
|
||||
const wxFont GetCategoryFont(const wxString& catId);
|
||||
void AddCategory(const Category& cat);
|
||||
void UpdateCategory(const Category& cat);
|
||||
void DeleteCategory(const Category& cat);
|
||||
|
||||
|
||||
Account GetAccount(const wxString& accountId) throw (AccountNotFound);
|
||||
wxString GetAccountName(const wxString& accountId);
|
||||
wxString GetAccountId(const wxString& accountName);
|
||||
void AddAccount(Account& ac);
|
||||
void UpdateAccount(Account& ac);
|
||||
void DeleteAccount(Account& ac);
|
||||
|
||||
|
||||
int GetCategoriesNumber();
|
||||
int GetAccountsNumber();
|
||||
|
|
Loading…
Reference in New Issue
Block a user