From ec3ac0a8b46724249c89a61891d974730c319370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 7 Oct 2018 11:55:41 +0200 Subject: [PATCH] Add quick transfert dialog (ctrl+t shortcut) --- ChangeLog | 6 +- src/view/grid/GridAccount.cpp | 53 +++++++++++++++++- src/view/grid/GridAccount.hpp | 3 + src/view/grid/TransfertDialog.cpp | 92 +++++++++++++++++++++++++++++++ src/view/grid/TransfertDialog.hpp | 51 +++++++++++++++++ 5 files changed, 202 insertions(+), 3 deletions(-) create mode 100644 src/view/grid/TransfertDialog.cpp create mode 100644 src/view/grid/TransfertDialog.hpp diff --git a/ChangeLog b/ChangeLog index bfdf23b..57df147 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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) diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 26f1821..cefa133 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -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& 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::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(); + } + } +} diff --git a/src/view/grid/GridAccount.hpp b/src/view/grid/GridAccount.hpp index 901f6f2..9bfc9ca 100644 --- a/src/view/grid/GridAccount.hpp +++ b/src/view/grid/GridAccount.hpp @@ -30,6 +30,7 @@ #include #include #include +#include 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(); diff --git a/src/view/grid/TransfertDialog.cpp b/src/view/grid/TransfertDialog.cpp new file mode 100644 index 0000000..e06a06a --- /dev/null +++ b/src/view/grid/TransfertDialog.cpp @@ -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 . +*/ +#include "TransfertDialog.hpp" +#include + +TransfertDialog::TransfertDialog(KissCount* kiss, User* user, Operation& curOperation, + int* selectedAccount, bool* groupOperations) : + QDialog(0, Qt::Dialog), _kiss(kiss), _outSelectedAccount(selectedAccount), + _outGroupOperations(groupOperations) +{ + std::vector::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); +} diff --git a/src/view/grid/TransfertDialog.hpp b/src/view/grid/TransfertDialog.hpp new file mode 100644 index 0000000..2441e7d --- /dev/null +++ b/src/view/grid/TransfertDialog.hpp @@ -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 . +*/ + +#ifndef TRANSFERTDIALOG_H +#define TRANSFERTDIALOG_H + +#include +#include +#include + +#include + +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 _accounts; + QCheckBox* _groupOperations; + QPushButton* _ok; + int* _outSelectedAccount; + bool* _outGroupOperations; +}; +#endif