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