Tag management : first version
This commit is contained in:
@@ -101,6 +101,7 @@ void GrisbiImportEngine::LoadOperation(const QXmlAttributes& attrs)
|
||||
op.parent = 0;
|
||||
op.account = 0;
|
||||
op.category = 0;
|
||||
op.tag = 0;
|
||||
op.fix_cost = false;
|
||||
op.checked = false;
|
||||
op.transfert = 0;
|
||||
|
||||
@@ -196,6 +196,7 @@ void ImportEngine::ApplyPattern(ImportPattern& pattern, Operation& op)
|
||||
|
||||
op.account = pattern.account;
|
||||
op.category = pattern.category;
|
||||
op.tag = pattern.tag;
|
||||
|
||||
if (pattern.pattern == NULL_IMPORT_PATTERN) return;
|
||||
|
||||
@@ -250,6 +251,7 @@ int ImportEngine::UpdatePattern(int pos)
|
||||
pattern.pattern = FindPattern(_descriptions[op.id], op.description);
|
||||
pattern.account = op.account;
|
||||
pattern.category = op.category;
|
||||
pattern.tag = op.tag;
|
||||
|
||||
_user->_importPatterns[key1] = pattern;
|
||||
|
||||
@@ -281,6 +283,7 @@ void ImportEngine::MatchPattern(QString& originalKey, Operation& op)
|
||||
pattern.pattern = FindPattern(originalKey, op.description);
|
||||
pattern.account = op.account;
|
||||
pattern.category = op.category;
|
||||
pattern.tag = op.tag;
|
||||
|
||||
_user->_importPatterns[key1] = pattern;
|
||||
|
||||
@@ -293,13 +296,14 @@ void ImportEngine::MatchPattern(QString& originalKey, Operation& op)
|
||||
}
|
||||
}
|
||||
|
||||
void ImportEngine::ParseFile(std::vector<Account>& accounts, std::vector<Category>& categories)
|
||||
void ImportEngine::ParseFile(std::vector<Account>& accounts, std::vector<Category>& categories, std::vector<Tag>& tags)
|
||||
{
|
||||
accounts = _unresolvedAccounts;
|
||||
categories = _unresolvedCategories;
|
||||
tags = _unresolvedTags;
|
||||
}
|
||||
|
||||
std::vector<Operation>* ImportEngine::GetOperations(std::map<int, int>& accounts, std::map<int, int>& categories)
|
||||
std::vector<Operation>* ImportEngine::GetOperations(std::map<int, int>& accounts, std::map<int, int>& categories, std::map<int, int>& tags)
|
||||
{
|
||||
int i;
|
||||
std::map<AccountAmount, int, AccountAmount>::iterator it;
|
||||
@@ -320,6 +324,11 @@ std::vector<Operation>* ImportEngine::GetOperations(std::map<int, int>& accounts
|
||||
else
|
||||
_operations[i].category = _categories[_operations[i].category];
|
||||
|
||||
if (_tags[_operations[i].tag] < 0)
|
||||
_operations[i].tag = tags[_operations[i].tag];
|
||||
else
|
||||
_operations[i].tag = _tags[_operations[i].tag];
|
||||
|
||||
}
|
||||
|
||||
for(it=_accountAmounts.begin(); it!=_accountAmounts.end(); it++)
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
QString pattern;
|
||||
int account;
|
||||
int category;
|
||||
int tag;
|
||||
} ;
|
||||
|
||||
class ImportEngine {
|
||||
@@ -50,10 +51,10 @@ public:
|
||||
virtual bool HandleFile(const QString& path, User* user, Database* db, KissCount* kiss)=0;
|
||||
|
||||
// Parse the file and return accounts that doesn't match
|
||||
virtual void ParseFile(std::vector<Account>& accounts, std::vector<Category>& categories);
|
||||
virtual void ParseFile(std::vector<Account>& accounts, std::vector<Category>& categories, std::vector<Tag>& tags);
|
||||
|
||||
// Final Step
|
||||
virtual std::vector<Operation>* GetOperations(std::map<int, int>& accounts, std::map<int, int>& categories);
|
||||
virtual std::vector<Operation>* GetOperations(std::map<int, int>& accounts, std::map<int, int>& categories, std::map<int, int>& tags);
|
||||
|
||||
const std::map<AccountAmount, int, AccountAmount>& GetAccountAmounts();
|
||||
|
||||
@@ -73,8 +74,10 @@ protected:
|
||||
|
||||
std::map<int, int> _accounts;
|
||||
std::map<int, int> _categories;
|
||||
std::map<int, int> _tags;
|
||||
std::vector<Account> _unresolvedAccounts;
|
||||
std::vector<Category> _unresolvedCategories;
|
||||
std::vector<Tag> _unresolvedTags;
|
||||
std::vector<Operation> _operations;
|
||||
std::map<int, QString> _descriptions;
|
||||
std::map<AccountAmount, int, AccountAmount> _accountAmounts;
|
||||
|
||||
@@ -81,6 +81,7 @@ int OFXImportEngine::transaction_cb(const struct OfxTransactionData data, void *
|
||||
op.id = ++id;
|
||||
op.parent = 0;
|
||||
op.category = 0;
|
||||
op.tag = 0;
|
||||
op.fix_cost = false;
|
||||
op.account = _this->_curAccount;
|
||||
op.checked = false;
|
||||
|
||||
@@ -84,6 +84,9 @@ bool XMLImportEngine::startElement (const QString& namespaceURI, const QString&
|
||||
else if (qName == "category")
|
||||
LoadCategory(attrs);
|
||||
|
||||
else if (qName == "tag")
|
||||
LoadTag(attrs);
|
||||
|
||||
else if (qName == "operation")
|
||||
LoadOperation(attrs);
|
||||
else
|
||||
@@ -201,6 +204,32 @@ void XMLImportEngine::LoadCategory(const QXmlAttributes& attrs)
|
||||
_unresolvedCategories.push_back(cat);
|
||||
}
|
||||
|
||||
void XMLImportEngine::LoadTag(const QXmlAttributes& attrs)
|
||||
{
|
||||
QString name;
|
||||
int id;
|
||||
Tag tag;
|
||||
static int unknownTag = 0;
|
||||
|
||||
tag.name = name = attrs.value("name");
|
||||
tag.id = id = attrs.value("id").toInt();
|
||||
|
||||
UNESCAPE_CHARS(tag.name);
|
||||
|
||||
try
|
||||
{
|
||||
int tagId = _user->GetTagId(name);
|
||||
|
||||
_tags[id] = tagId;
|
||||
return;
|
||||
}
|
||||
catch(User::TagNotFound e)
|
||||
{}
|
||||
|
||||
_tags[id] = --unknownTag;
|
||||
_unresolvedTags.push_back(tag);
|
||||
}
|
||||
|
||||
void XMLImportEngine::LoadOperation(const QXmlAttributes& attrs)
|
||||
{
|
||||
Operation op;
|
||||
@@ -213,6 +242,7 @@ void XMLImportEngine::LoadOperation(const QXmlAttributes& attrs)
|
||||
op.amount = attrs.value("amount").toInt();
|
||||
op.description = attrs.value("description");
|
||||
op.category = attrs.value("category").toInt();
|
||||
op.tag = attrs.value("tag").toInt();
|
||||
op.fix_cost = (attrs.value("fix_cost") == "1");
|
||||
op.account = attrs.value("account").toInt();
|
||||
op.checked = (attrs.value("checked") == "1");
|
||||
|
||||
@@ -40,6 +40,7 @@ private:
|
||||
void LoadAccount(const QXmlAttributes& atts);
|
||||
void LoadAccountAmount(const QXmlAttributes& atts);
|
||||
void LoadCategory(const QXmlAttributes& atts);
|
||||
void LoadTag(const QXmlAttributes& atts);
|
||||
void LoadOperation(const QXmlAttributes& atts);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user