Add quick transfert dialog (ctrl+t shortcut)

This commit is contained in:
Grégory Soutadé 2018-10-07 11:55:41 +02:00
parent 74528b4a00
commit ec3ac0a8b4
5 changed files with 202 additions and 3 deletions

View File

@ -1,12 +1,14 @@
v0.8 (03/10/2018)
v0.8 (07/10/2018)
** User **
Add multi month operation support : Normal operation with description "... (XX/YY)" will be forwarded to next month
Auto fill operation amount if it was the same for the last 3 operations
Add quick transfert dialog (ctrl+t shortcut)
** Dev **
** Bugs **
Current account value is badly computed if operations are not in date order
NULLop was set with random values which can cause misunderstanding when entering a new operation
Resize date column for new operations (can be bold while other are not)
KissCount crash or do something wrong when selecting multiple columns for group/ungroup operations
v0.7.1 (07/05/2018)

View File

@ -27,6 +27,7 @@
#include "FloatDelegate.hpp"
#include "FormulaDelegate.hpp"
#include "TabDelegate.hpp"
#include "TransfertDialog.hpp"
#define SET_ROW_COLOR(row, backcolor, forecolor) for(int i=0; i<NUMBER_COLS_OPS; i++) \
{ \
@ -52,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)
_transfertCompletionIndex(0), _ctrlT(0)
{
DEFAULT_FONT(font);
int i;
@ -122,6 +123,9 @@ GridAccount::GridAccount(KissCount* kiss, KissPanel *parent,
connect(&_deleteSignalMapper, SIGNAL(mapped(int)), this, SLOT(OnDeleteClicked(int)));
setItemDelegate(new TableViewDelegate(this));
connect(this, SIGNAL(cellChanged(int, int)), this, SLOT(OnOperationModified(int, int)));
if (canAddOperation)
_ctrlT = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_T), this, SLOT(OnCtrlT()));
}
GridAccount::~GridAccount()
@ -132,6 +136,8 @@ GridAccount::~GridAccount()
delete[] _accounts;
if (_completer)
delete _completer;
if (_ctrlT)
delete _ctrlT;
}
void GridAccount::ResetWeeks()
@ -1660,3 +1666,48 @@ void GridAccount::MassUpdate(std::vector<int>& rows, bool do_childs, updateOpera
_parent->setEnabled(true);
_kiss->setOverrideCursor(QCursor(Qt::ArrowCursor));
}
void GridAccount::OnCtrlT(void)
{
Operation op, op2;
QModelIndexList selected = selectedIndexes();
int account, idx;
bool groupOperations;
User* user = _kiss->GetUser();
std::vector<Operation>::iterator it;
if (selected.size() > 1 || !selected.size())
return;
op = _displayedOperations[selected[0].row()] ;
if (op.parent || op.meta || op.transfert)
return;
TransfertDialog g(_kiss, user, op, &account, &groupOperations);
g.setModal(true);
if (g.exec())
{
op2 = op;
op2.account = account;
op2.amount *= -1;
op2.id = _kiss->AddOperation(op2);
InsertOperationWithWeek(user, op2, selected[0].row()+1, op.fix_cost, op.month, op.year);
for (idx = 0, it = _operations->begin(); it != _operations->end(); it++, idx++)
{
if (it->id == op.id)
{
_operations->insert(_operations->begin()+idx+1, op2);
break;
}
}
if (groupOperations)
{
setRangeSelected(QTableWidgetSelectionRange(selected[0].row(), 0, selected[0].row()+1, 0), true);
Group();
}
}
}

View File

@ -30,6 +30,7 @@
#include <QTableWidget>
#include <QSignalMapper>
#include <QCompleter>
#include <QShortcut>
class KissCount;
@ -70,6 +71,7 @@ private slots:
void OnMetaClicked(int id);
void OnCheckClicked(int id);
void OnDeleteClicked(int id);
void OnCtrlT(void);
private:
KissPanel* _parent;
@ -86,6 +88,7 @@ private:
bool _inModification;
QCompleter* _completer;
int _transfertCompletionIndex;
QShortcut* _ctrlT;
void SetWeek(int week, int line);
void ResetWeeks();

View File

@ -0,0 +1,92 @@
/*
Copyright 2010-2018 Grégory Soutadé
This file is part of KissCount.
KissCount is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KissCount is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TransfertDialog.hpp"
#include <QLabel>
TransfertDialog::TransfertDialog(KissCount* kiss, User* user, Operation& curOperation,
int* selectedAccount, bool* groupOperations) :
QDialog(0, Qt::Dialog), _kiss(kiss), _outSelectedAccount(selectedAccount),
_outGroupOperations(groupOperations)
{
std::vector<Account>::iterator accountIt;
QGridLayout* gridLayout;
Operation op_tmp;
bool hasPrevious;
int selectedIndex = -1, curIndex = 0;
gridLayout = new QGridLayout(this);
setWindowTitle(_("Create Transfert"));
setModal(true);
gridLayout->addWidget(new QLabel(_("Transfert to "), this), 0, 0);
_account = new QComboBox(this);
gridLayout->addWidget(_account, 0, 1);
_ok = new QPushButton(_("OK"), this);
QPushButton* cancel = new QPushButton(_("Cancel"), this);
gridLayout->addWidget(_ok, 0, 2);
gridLayout->addWidget(cancel, 1, 2);
if(_kiss->SearchPreviousOperation(&op_tmp, curOperation, curOperation.month,
curOperation.year, true, 1))
{
hasPrevious = (op_tmp.transfert)?true:false;
}
for (accountIt = user->_accounts.begin();
accountIt != user->_accounts.end();
accountIt++, curIndex++)
{
if (accountIt->id != curOperation.account &&
accountIt->validAt(curOperation.month, curOperation.year))
{
_account->addItem(accountIt->name);
_accounts.push_back(accountIt->id);
if (hasPrevious && accountIt->id == op_tmp.account)
selectedIndex = curIndex;
}
}
if (selectedIndex != -1)
_account->setCurrentIndex(selectedIndex);
_groupOperations = new QCheckBox(_("Group operations"));
_groupOperations->setChecked(true);
gridLayout->addWidget(_groupOperations, 1, 1);
connect(_ok, SIGNAL(clicked()), this, SLOT(OnOK()));
connect(cancel, SIGNAL(clicked()), this, SLOT(OnCancel()));
_ok->setFocus();
}
void TransfertDialog::OnOK()
{
*_outSelectedAccount = _accounts[_account->currentIndex()];
*_outGroupOperations = (_groupOperations->checkState() == Qt::Checked);
done(1);
}
void TransfertDialog::OnCancel()
{
*_outSelectedAccount = -1;
done(0);
}

View File

@ -0,0 +1,51 @@
/*
Copyright 2010-2018 Grégory Soutadé
This file is part of KissCount.
KissCount is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KissCount is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSFERTDIALOG_H
#define TRANSFERTDIALOG_H
#include <QDialog>
#include <QComboBox>
#include <QCheckBox>
#include <view/wxUI.hpp>
class TransfertDialog : public QDialog
{
Q_OBJECT;
public:
TransfertDialog(KissCount* kiss, User* user, Operation& curOperation,
int* selectedAccount, bool* groupOperations);
private slots:
void OnOK();
void OnCancel();
private:
KissCount* _kiss;
wxUI* _wxUI;
QComboBox* _account;
std::vector<int> _accounts;
QCheckBox* _groupOperations;
QPushButton* _ok;
int* _outSelectedAccount;
bool* _outGroupOperations;
};
#endif