Add a constructor for Operation (to clear all fields)

Setup default date when insert an operation in GridAccount
This commit is contained in:
Grégory Soutadé 2020-04-19 16:47:35 +02:00
parent 196a0cc5ab
commit c57405a407
2 changed files with 69 additions and 58 deletions

View File

@ -42,6 +42,26 @@ struct Operation {
std::vector<int> childs;
int tag;
Operation()
{
id = 0;
parent = 0;
day = 0;
month = 0;
year = 0;
amount = 0.0;
description = "";
category = 0;
fix_cost = false;
account = 0;
checked = 0;
transfert = 0;
formula = "";
meta = false;
_virtual = false;
tag = 0;
}
bool operator == (int opId)
{
return id == opId;

View File

@ -53,7 +53,7 @@ GridAccount::GridAccount(KissCount* kiss, KissPanel *parent,
_loadOperations(false),
_curMonth(0), _curYear(0), _treeSignalMapper(this), _checkSignalMapper(this),
_deleteSignalMapper(this), _inModification(false), _completer(0),
_transfertCompletionIndex(0), _ctrlT(0), _ctrlR(0), _suppr(0)
_transfertCompletionIndex(0), _lastCtrlH(0), _ctrlT(0), _ctrlR(0), _suppr(0)
{
DEFAULT_FONT(font);
int i;
@ -203,23 +203,9 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
User* user = _kiss->GetUser();
std::vector<Account>::iterator accountIt;
int curLine = 0, i;
Operation NULLop;
Operation NULLop = Operation();
QStringList list;
NULLop.id = 0;
NULLop.parent = 0;
NULLop.amount = 0.0;
NULLop.description = "";
NULLop.category = 0;
NULLop.tag = 0;
NULLop.fix_cost = false;
NULLop.account = 0;
NULLop.checked = 0;
NULLop.transfert = 0;
NULLop.formula = "";
NULLop.meta = false;
NULLop._virtual = false;
_loadOperations = true;
_operations = operations;
_curMonth = month;
@ -514,6 +500,11 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
// NULL Op
item = new QTableWidgetItem("");
setItem(line, DESCRIPTION, item);
op.month = _curMonth;
op.year = _curYear;
op.day = 0;
if (fix)
{
SET_ROW_COLOR(line, view::OWN_YELLOW, Qt::black);
@ -536,6 +527,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
else
day = 1;
op.day = day-1;
setItem(line, OP_DATE, new QTableWidgetItem(_kiss->FormatDate(day, month+1, year)));
SET_ROW_COLOR(line, view::OWN_GREEN, Qt::black);
}
@ -980,7 +972,7 @@ void GridAccount::OnOperationModified(int row, int col)
Category cat ;
Tag tag;
bool fix_cost;
Operation NULLop;
Operation NULLop = Operation();
Account account;
// Avoid recursives calls
@ -1192,7 +1184,6 @@ void GridAccount::OnOperationModified(int row, int col)
}
RemoveRow(new_op, row, false);
NULLop.id = 0;
InsertOperation(user, NULLop, row, new_op.fix_cost, _curMonth, _curYear);
new_op.id = new_op_id;