Tag management : first version

This commit is contained in:
2014-11-10 11:54:28 +01:00
parent 899dc3db71
commit 57d4b90182
32 changed files with 868 additions and 60 deletions

View File

@@ -38,6 +38,7 @@ public:
private:
QString* _values;
int _nbValues;
bool _editable;
};
#endif

View File

@@ -57,6 +57,7 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
User* user = _kiss->GetUser();
std::vector<Account>::iterator accountIt;
std::vector<Category>::iterator categoryIt;
std::vector<Tag>::iterator tagIt;
QTableWidgetItem* item;
QLabel* label;
@@ -70,7 +71,7 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
setFont(font);
font.setBold(true);
QString colsName[] = {"", _("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), "", ""};
QString colsName[] = {"", _("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Tag"), _("Account"), "", ""};
for(i=0; i<NUMBER_COLS_OPS; i++)
{
item = new QTableWidgetItem(colsName[i]);
@@ -119,8 +120,17 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
_categories[i] = _(categoryIt->name.toStdString().c_str()) ;
}
_tags = new QString[user->GetTagsNumber()] ;
for(i=0, tagIt = user->_tags.begin();
tagIt != user->_tags.end();
tagIt++, i++)
{
_tags[i] = _(tagIt->name.toStdString().c_str()) ;
}
resizeColumnToContents(TREE);
resizeColumnToContents(CATEGORY);
resizeColumnToContents(TAG);
resizeColumnToContents(OP_DATE);
resizeColumnToContents(ACCOUNT);
resizeColumnToContents(OP_DELETE);
@@ -136,6 +146,7 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
GridAccount::~GridAccount()
{
delete[] _categories;
delete[] _tags;
delete[] _accounts;
if (_completer)
delete _completer;
@@ -234,6 +245,10 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
ChoiceDelegate* categoryEditor = new ChoiceDelegate(this, _categories, user->GetCategoriesNumber()-1);
setItemDelegateForColumn(CATEGORY, categoryEditor);
ChoiceDelegate* tagEditor = new ChoiceDelegate(this, _tags, user->GetTagsNumber());
setItemDelegateForColumn(TAG, tagEditor);
ChoiceDelegate* accountEditor = new ChoiceDelegate(this, _accounts, _nbAccounts);
setItemDelegateForColumn(ACCOUNT, accountEditor);
@@ -281,6 +296,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
}
resizeColumnToContents(TREE);
resizeColumnToContents(TAG);
resizeColumnToContents(CATEGORY);
resizeColumnToContents(OP_DATE);
resizeColumnToContents(ACCOUNT);
@@ -341,6 +357,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
QString description, v;
DEFAULT_FONT(font);
Category cat ;
Tag tag;
Operation op2;
QTableWidgetItem* item;
QCheckBox* checkBox;
@@ -366,6 +383,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
if (op.id)
{
cat = user->GetCategory(op.category);
tag = user->GetTag(op.tag);
description = op.description;
UNESCAPE_CHARS(description);
@@ -386,6 +404,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
setItem(line, ACCOUNT, new QTableWidgetItem(user->GetAccountName(op.account)));
if (!fix && !op.meta)
setItem(line, CATEGORY, new QTableWidgetItem(_(cat.name.toStdString().c_str())));
setItem(line, TAG, new QTableWidgetItem(_(tag.name.toStdString().c_str())));
checkBox = new QCheckBox();
checkBox->setCheckState(Qt::Unchecked);
@@ -487,6 +507,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
SET_READ_ONLY(this->item(line, CREDIT));
SET_READ_ONLY(this->item(line, DEBIT));
SET_READ_ONLY(this->item(line, CATEGORY));
SET_READ_ONLY(this->item(line, TAG));
SET_READ_ONLY(this->item(line, ACCOUNT));
}
else
@@ -896,6 +917,7 @@ void GridAccount::OnOperationModified(int row, int col)
Operation op, op2, parent;
QFont font;
Category cat ;
Tag tag;
bool fix_cost;
Operation NULLop;
@@ -914,6 +936,7 @@ void GridAccount::OnOperationModified(int row, int col)
new_op.amount = 0.0;
new_op.description = "";
new_op.category = 0;
new_op.tag = 0;
new_op.fix_cost = false;
new_op.account = 0;
new_op.checked = 0;
@@ -954,6 +977,9 @@ void GridAccount::OnOperationModified(int row, int col)
if (!item(row, CATEGORY)->text().length())
setItem(row, CATEGORY, new QTableWidgetItem(_(user->GetCategoryName(op_tmp.category).toStdString().c_str())));
if (!item(row, TAG)->text().length() && op_tmp.tag)
setItem(row, TAG, new QTableWidgetItem(_(user->GetTagName(op_tmp.tag).toStdString().c_str())));
if (!item(row, ACCOUNT)->text().length())
setItem(row, ACCOUNT, new QTableWidgetItem(user->GetAccountName(op_tmp.account)));
@@ -998,6 +1024,20 @@ void GridAccount::OnOperationModified(int row, int col)
op_complete--;
}
value = item(row, TAG)->text();
if (value.length())
{
try
{
new_op.tag = user->GetTagId(value);
}
catch (User::TagNotFound e)
{
op_complete++;
}
op_complete--;
}
value = item(row, ACCOUNT)->text();
if (value.length())
{
@@ -1052,7 +1092,7 @@ void GridAccount::OnOperationModified(int row, int col)
CheckOperation(new_op, row, new_op.checked, true);
SET_ROW_FONT(row, user->GetCategoryFont(cat.id));
if (op_complete) {
if (op_complete > 0) {
_inModification = false ;
return ;
}
@@ -1095,6 +1135,8 @@ void GridAccount::UpdateMeta(Operation& meta)
Operation op ;
int category = 0;
bool updateCat = false ;
int tag = 0;
bool updateTag = false ;
bool openMeta;
if (!meta.childs.size()) return ;
@@ -1133,12 +1175,28 @@ void GridAccount::UpdateMeta(Operation& meta)
if (op.category && op.category != category)
updateCat = false;
}
if (!tag)
{
if (op.tag)
{
tag = op.tag;
updateCat = true;
}
}
else
{
if (op.tag && op.tag != tag)
updateCat = false;
}
op.parent = meta.id;
}
if (updateCat)
meta.category = category;
if (updateTag)
meta.tag = tag;
meta.amount = _kiss->MetaAmount(meta.id);
UpdateOperation(meta);
@@ -1224,6 +1282,7 @@ void GridAccount::Group()
op.amount = 0;
op.description = "";
op.category = 0;
op.tag = 0;
op.fix_cost = fix;
op.account = 0;
op.checked = false;

View File

@@ -42,7 +42,7 @@ class GridAccount : public QTableWidget
public:
class OperationNotFound {};
enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS};
enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, TAG, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS};
GridAccount(KissCount* kiss, QWidget *parent,
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
@@ -77,7 +77,7 @@ private:
bool _displayLines;
bool _setWeek;
bool _databaseSynchronization;
QString* _categories, *_accounts;
QString* _categories, *_accounts, *_tags;
int _nbAccounts;
std::vector<Operation>* _operations;
bool _loadOperations;