Add ctrl+h shortcut to setup current operation date to yesterday. If called twice, set date to last operation date (if any)

This commit is contained in:
Grégory Soutadé 2020-04-19 16:50:07 +02:00
parent c57405a407
commit 2e89948c1f
3 changed files with 76 additions and 4 deletions

View File

@ -1,6 +1,8 @@
v0.9 (27/07/2019)
v0.9 (19/04/2020)
** User **
Add ctrl+h shortcut to setup current operation date to yesterday. If called twice, set date to last operation date (if any)
** Dev **
Add a constructor for Operation (to clear all fields)
** Bugs **
Check index in ctrl+t, ctrl+r and suppr callback to avoid doing something on non existant operation

View File

@ -122,6 +122,7 @@ GridAccount::GridAccount(KissCount* kiss, KissPanel *parent,
{
_ctrlT = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_T), this, SLOT(OnCtrlT()));
_ctrlR = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_R), this, SLOT(OnCtrlR()));
_ctrlH = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_H), this, SLOT(OnCtrlH()));
_suppr = new QShortcut(QKeySequence(Qt::Key_Delete), this, SLOT(OnSuppr()));
}
}
@ -1734,6 +1735,74 @@ void GridAccount::OnCtrlR(void)
}
}
void GridAccount::OnCtrlH(void)
{
QModelIndexList selected = selectedIndexes();
Operation op, prev_op;
QString value;
QDate date;
int row, day;
if (selected.size() != 1)
return;
row = selected[0].row();
op = _displayedOperations[row];
if (op.meta)
return;
if (!op.id)
{
op.month = _curMonth;
op.year = _curYear;
value = item(row, OP_DATE)->text();
if (value.length())
{
date = QDate::fromString(value, _kiss->GetDateLocalFormat());
op.day = date.day()-1;
}
else
op.day = 0;
// Set previous operation day
if (row <= _fixCosts)
_lastCtrlH = row;
}
// Ctrl+H multiple times
// Set day to previous operation day
if (_lastCtrlH == row)
{
if (row < 2)
return;
prev_op = _displayedOperations[row-1];
// No previous operation or day already equal
if (!prev_op.id || op.day == prev_op.day)
return;
day = prev_op.day;
}
// Set day to yesterday
else
{
day = QDate::currentDate().day()-1;
day--;
}
_inModification = true ;
op.day = day;
if (op.id)
UpdateOperation(op);
item(row, OP_DATE)->setText(_kiss->FormatDate(op.day+1, op.month+1, op.year));
_lastCtrlH = row;
_inModification = false ;
}
void GridAccount::OnSuppr(void)
{
QModelIndexList selected = selectedIndexes();

View File

@ -73,6 +73,7 @@ private slots:
void OnDeleteClicked(int id);
void OnCtrlT(void);
void OnCtrlR(void);
void OnCtrlH(void);
void OnSuppr(void);
private:
@ -89,8 +90,8 @@ private:
QSignalMapper _treeSignalMapper, _checkSignalMapper, _deleteSignalMapper;
bool _inModification;
QCompleter* _completer;
int _transfertCompletionIndex;
QShortcut* _ctrlT, *_ctrlR, *_suppr;
int _transfertCompletionIndex, _lastCtrlH;
QShortcut* _ctrlT, *_ctrlR, *_ctrlH, *_suppr;
void SetWeek(int week, int line);
void ResetWeeks();