Use std C++ algorithmes in model
This commit is contained in:
parent
6596097f72
commit
8d7a019ca7
|
@ -45,6 +45,11 @@ struct Account {
|
|||
|
||||
return (ac1.name.Cmp(ac2.name) < 0);
|
||||
}
|
||||
|
||||
bool operator == (const wxString& accountId)
|
||||
{
|
||||
return id == accountId;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#ifndef CATEGORY_H
|
||||
#define CATEGORY_H
|
||||
|
||||
#include <wx/wx.h>
|
||||
|
||||
struct Category
|
||||
{
|
||||
wxString id;
|
||||
|
@ -29,6 +31,11 @@ struct Category
|
|||
wxColour forecolor;
|
||||
wxString font;
|
||||
bool fix_cost;
|
||||
|
||||
bool operator == (const wxString& catId)
|
||||
{
|
||||
return id == catId;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "Operation.h"
|
||||
|
||||
bool sortOperations(Operation op1, Operation op2)
|
||||
bool sortOperations(const Operation& op1, const Operation& op2)
|
||||
{
|
||||
if (!op1.fix_cost && op2.fix_cost) return false;
|
||||
if (op1.fix_cost && !op2.fix_cost) return true;
|
||||
|
@ -42,7 +42,7 @@ bool sortOperations(Operation op1, Operation op2)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool reverseSortOperations(Operation op1, Operation op2)
|
||||
bool reverseSortOperations(const Operation& op1, const Operation& op2)
|
||||
{
|
||||
return !sortOperations(op1, op2);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ struct Operation {
|
|||
std::vector<wxString> childs;
|
||||
} ;
|
||||
|
||||
bool sortOperations(Operation op1, Operation op2);
|
||||
bool reverseSortOperations(Operation op1, Operation op2);
|
||||
bool sortOperations(const Operation& op1, const Operation& op2);
|
||||
bool reverseSortOperations(const Operation& op1, const Operation& op2);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,11 +45,9 @@ void User::InvalidateOperations()
|
|||
Category User::GetCategory(const wxString& catId)
|
||||
{
|
||||
Category cat;
|
||||
std::vector<Category>::iterator it;
|
||||
std::vector<Category>::iterator it = std::find(_categories.begin(), _categories.end(), catId);
|
||||
|
||||
for (it=_categories.begin(); it !=_categories.end(); it++)
|
||||
if (it->id == catId)
|
||||
return *it;
|
||||
if (it !=_categories.end()) return *it;
|
||||
|
||||
if (_db->LoadCategory(catId, wxT(""), cat))
|
||||
return cat;
|
||||
|
@ -67,11 +65,9 @@ Category User::GetCategory(const wxString& catId)
|
|||
wxString User::GetCategoryName(const wxString& catId)
|
||||
{
|
||||
Category cat;
|
||||
std::vector<Category>::iterator it;
|
||||
std::vector<Category>::iterator it = std::find(_categories.begin(), _categories.end(), catId);
|
||||
|
||||
for (it=_categories.begin(); it !=_categories.end(); it++)
|
||||
if (it->id == catId)
|
||||
return it->name;
|
||||
if (it !=_categories.end()) return it->name;
|
||||
|
||||
if (_db->LoadCategory(catId, wxT(""), cat))
|
||||
return cat.name;
|
||||
|
@ -109,20 +105,21 @@ const wxFont User::GetCategoryFont(const wxString& catId)
|
|||
return f;
|
||||
}
|
||||
|
||||
Account User::GetAccount(const wxString& accountId)
|
||||
Account User::GetAccount(const wxString& accountId) throw (AccountNotFound)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
if (it->id == accountId)
|
||||
return *it;
|
||||
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), accountId);
|
||||
|
||||
if (it != _accounts.end())
|
||||
return *it;
|
||||
|
||||
throw AccountNotFound();
|
||||
}
|
||||
|
||||
wxString User::GetAccountName(const wxString& accountId)
|
||||
{
|
||||
std::vector<Account>::iterator it;
|
||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||
if (it->id == accountId)
|
||||
return it->name;
|
||||
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), accountId);
|
||||
|
||||
if (it != _accounts.end()) return it->name;
|
||||
|
||||
return _("Unknown") ;
|
||||
}
|
||||
|
@ -218,9 +215,7 @@ bool User::Group(std::vector<Operation>* ops, const Operation& op)
|
|||
{
|
||||
if (it->id == op.parent)
|
||||
{
|
||||
for (it2 = it->childs.begin(); it2 != it->childs.end(); it2++)
|
||||
if (*it2 == op.id)
|
||||
break;
|
||||
it2 = std::find(it->childs.begin(), it->childs.end(), op.id);
|
||||
// Already into childs
|
||||
if (it2 != it->childs.end()) return true;
|
||||
it->childs.push_back(op.id);
|
||||
|
|
|
@ -51,12 +51,14 @@ public:
|
|||
std::map<wxString, wxString> _preferences;
|
||||
std::map<wxString, ImportPattern> _importPatterns;
|
||||
|
||||
class AccountNotFound {};
|
||||
|
||||
Category GetCategory(const wxString& catId);
|
||||
wxString GetCategoryName(const wxString& catId);
|
||||
wxString GetCategoryId(const wxString& catName);
|
||||
const wxFont GetCategoryFont(const wxString& catId);
|
||||
|
||||
Account GetAccount(const wxString& accountId);
|
||||
Account GetAccount(const wxString& accountId) throw (AccountNotFound);
|
||||
wxString GetAccountName(const wxString& accountId);
|
||||
wxString GetAccountId(const wxString& accountName);
|
||||
|
||||
|
|
|
@ -54,13 +54,13 @@ void XMLImportEngine::LoadAccount(XMLImportEngine* _this, const char** attrs)
|
|||
|
||||
if (account_number.Length())
|
||||
{
|
||||
for (i=0; i<(int)_this->_user->_accounts.size(); i++)
|
||||
try {
|
||||
Account ac = _this->_user->GetAccount(account_number);
|
||||
_this->_accounts[id] = ac.id;
|
||||
return;
|
||||
}
|
||||
catch (User::AccountNotFound)
|
||||
{
|
||||
if (_this->_user->_accounts[i].number == account_number)
|
||||
{
|
||||
_this->_accounts[id] = _this->_user->_accounts[i].id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,13 +135,12 @@ void XMLImportEngine::LoadCategory(XMLImportEngine* _this, const char** attrs)
|
|||
|
||||
UNESCAPE_CHARS(cat.name);
|
||||
|
||||
for (i=0; i<(int)_this->_user->_categories.size(); i++)
|
||||
wxString catId = _this->_user->GetCategoryId(name);
|
||||
|
||||
if (catId != wxT("0"))
|
||||
{
|
||||
if (_this->_user->_categories[i].name == name)
|
||||
{
|
||||
_this->_categories[id] = _this->_user->_categories[i].id;
|
||||
return;
|
||||
}
|
||||
_this->_categories[id] = catId;
|
||||
return;
|
||||
}
|
||||
|
||||
_this->_categories[id] = wxT("unknown-") + name;
|
||||
|
|
Loading…
Reference in New Issue
Block a user