From a9bcdcc733b78c42661a5da42d68b03ffb27d59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Tue, 1 Nov 2011 16:17:20 +0100 Subject: [PATCH] Enable operation modification in GridAccount Fix a bug : Fix category in choices of normal operation Fix a bug : bad request in Database.cpp Fix a bug : bad month in calendar Add a 5th week for black line --- src/model/Database.cpp | 2 +- src/view/AccountPanel.cpp | 4 +- src/view/grid/GridAccount.cpp | 957 ++++++++++++++-------------- src/view/grid/GridAccount.hpp | 19 +- src/view/grid/TableViewDelegate.hpp | 3 +- 5 files changed, 492 insertions(+), 493 deletions(-) diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 821a91b..b585023 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -494,7 +494,7 @@ void Database::LinkOrUnlinkOperation(User* user, Operation& op) // No one or not linked if (!GetOperation(op.transfert, &linked) || op.description != linked.description || op.amount != -linked.amount || op.account == linked.account) { - req = QString("UPDATE operation SET transfert='' virtual='0' WHERE id='%1'").arg(op.id); + req = QString("UPDATE operation SET transfert='', virtual='0' WHERE id='%1'").arg(op.id); EXECUTE_SQL_UPDATE(req, ); op.transfert = 0; op._virtual = false; diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index c656d8a..e00d38e 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -422,8 +422,8 @@ void AccountPanel::ShowMonth(int month, int year) connect(_accountsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnAccountModified(int, int))); - dateStart.setDate(dateStart.year(), dateStart.month(), 1); - dateEnd.setDate(dateEnd.year(), dateEnd.month(), dateStart.daysInMonth()); + dateStart.setDate(_curYear, _curMonth+1, 1); + dateEnd.setDate(_curYear, _curMonth+1, dateStart.daysInMonth()); _calendar->setDateRange(dateStart, dateEnd); if ((curDate.month()-1) == month && curDate.year() == year) _calendar->showToday(); diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 9dd4258..6f02371 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -48,10 +48,11 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent, bool canAddOperation, bool setWeek, bool synchronizeWithDatabase) : QTableWidget(parent), _fixCosts(0), _week1(0), - _week2(0), _week3(0), _week4(0), _canAddOperation(canAddOperation), + _week2(0), _week3(0), _week4(0), _week5(0), _canAddOperation(canAddOperation), _parent(parent), _kiss(kiss), _setWeek(setWeek), _databaseSynchronization(synchronizeWithDatabase), _loadOperations(false), - _curMonth(0), _curYear(0), _signalMapper(this) + _curMonth(0), _curYear(0), _buttonSignalMapper(this), _checkSignalMapper(this), + _inModification(false) { //DEFAULT_FONT(font); QFont font; @@ -101,15 +102,14 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent, accountIt++, i++) _accounts[i] = accountIt->name; - _categories = new QString[user->GetCategoriesNumber()] ; - for(i=0, categoryIt = user->_categories.begin(); + _categories = new QString[user->GetCategoriesNumber()-1] ; + for(i=0, categoryIt = user->_categories.begin()+1; categoryIt != user->_categories.end(); categoryIt++, i++) { _categories[i] = categoryIt->name ; } - // Connect(id, wxEVT_GRID_CELL_CHANGE, wxGridEventHandler(GridAccount::OnOperationModified), 0, this); resizeColumnToContents(TREE); resizeColumnToContents(CATEGORY); resizeColumnToContents(OP_DATE); @@ -117,9 +117,10 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent, resizeColumnToContents(OP_DELETE); resizeColumnToContents(CHECKED); - connect(&_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnMetaClicked(int))); - + connect(&_buttonSignalMapper, SIGNAL(mapped(int)), this, SLOT(OnMetaClicked(int))); + connect(&_checkSignalMapper, SIGNAL(mapped(int)), this, SLOT(OnCheckClicked(int))); setItemDelegate(new TableViewDelegate(this)); + connect(this, SIGNAL(cellChanged(int, int)), this, SLOT(OnOperationModified(int, int))); } GridAccount::~GridAccount() @@ -130,7 +131,7 @@ GridAccount::~GridAccount() void GridAccount::ResetWeeks() { - _week1 = _week2 = _week3 = _week4 = 0; + _week1 = _week2 = _week3 = _week4 = _week5 = 0; } void GridAccount::SetWeek(int week, int line) { @@ -139,6 +140,7 @@ void GridAccount::SetWeek(int week, int line) { case 2: _week2 = line; break; case 3: _week3 = line; break; case 4: _week4 = line; break; + case 5: _week5 = line; break; } } @@ -203,7 +205,7 @@ void GridAccount::LoadOperations(std::vector* operations, int month, TabDelegate* descriptionEditor = new TabDelegate(this, &_displayedOperations); setItemDelegateForColumn(DESCRIPTION, descriptionEditor); - ChoiceDelegate* categoryEditor = new ChoiceDelegate(this, _categories, user->GetCategoriesNumber()); + ChoiceDelegate* categoryEditor = new ChoiceDelegate(this, _categories, user->GetCategoriesNumber()-1); setItemDelegateForColumn(CATEGORY, categoryEditor); ChoiceDelegate* accountEditor = new ChoiceDelegate(this, _accounts, user->GetAccountsNumber()); setItemDelegateForColumn(ACCOUNT, accountEditor); @@ -300,7 +302,6 @@ void GridAccount::InsertOperationWithWeek(User* user, Operation& op, int line, b if (op.id && !fix) ComputeWeeks(); } -#include void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, int month, int year) { @@ -323,6 +324,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, if (!user->_accounts.size()) return; + _inModification = true; + insertRow(line); if (fix) @@ -355,13 +358,13 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, if (!op.meta) setItem(line, ACCOUNT, new QTableWidgetItem(user->GetAccountName(op.account))); if (!fix && !op.meta) - setItem(line, CATEGORY, new QTableWidgetItem(cat.name)); + setItem(line, CATEGORY, new QTableWidgetItem(_(cat.name.toStdString().c_str()))); checkBox = new QCheckBox(); checkBox->setTristate(false); setCellWidget(line, CHECKED, checkBox); - // SetCellRenderer(line, OP_DELETE, new wxGridCellBoolRenderer ()); - // SetCellEditor(line, OP_DELETE, new wxGridCellBoolEditor ()); + _checkSignalMapper.setMapping(checkBox, op.id); + connect(checkBox, SIGNAL(stateChanged(int)), &_checkSignalMapper, SLOT(map())); if (op.meta && !op.amount) { @@ -386,11 +389,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, } SET_ROW_COLOR(line, color, cat.forecolor); - if (op.category && cat.font.length()) - { - font = user->GetCategoryFont(cat.id); - SET_ROW_FONT(line, font); - } + SET_ROW_FONT(line, user->GetCategoryFont(cat.id)); if (!_loadOperations) { @@ -420,6 +419,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, SET_READ_ONLY(this->item(line, CHECKED)); SET_READ_ONLY(this->item(line, OP_DELETE)); + SET_ROW_FONT(line, user->GetCategoryFont(0)); } this->item(line, OP_DATE)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter); @@ -432,8 +432,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, { int height = rowHeight(TREE); QPushButton* button = new QPushButton("+"); - _signalMapper.setMapping(button, op.id); - connect(button, SIGNAL(clicked()), &_signalMapper, SLOT(map())); + _buttonSignalMapper.setMapping(button, op.id); + connect(button, SIGNAL(clicked()), &_buttonSignalMapper, SLOT(map())); button->setMaximumSize(QSize(height, height)); setCellWidget(line, TREE, button); @@ -450,6 +450,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, resizeRowToContents(line); layout(); + + _inModification = false; } void GridAccount::DeleteOperation(const Operation& op) @@ -535,6 +537,7 @@ int GridAccount::RemoveMeta(Operation op, int line, bool removeRoot, bool delete int i, deletedOperations = 0; Operation op2; QPushButton* button = qobject_cast (cellWidget(line, TREE)); + QCheckBox* checkBox = qobject_cast (cellWidget(line, CHECKED)); for(i=0; i<(int)op.childs.size(); i++) { @@ -565,7 +568,8 @@ int GridAccount::RemoveMeta(Operation op, int line, bool removeRoot, bool delete if (removeRoot) { removeRow(line); - button->disconnect(&_signalMapper, SLOT(map())); + button->disconnect(&_buttonSignalMapper, SLOT(map())); + checkBox->disconnect(&_checkSignalMapper, SLOT(map())); removeCellWidget(line, TREE); _displayedOperations.erase(_displayedOperations.begin()+line); if (op.fix_cost) _fixCosts--; @@ -583,48 +587,46 @@ int GridAccount::RemoveMeta(Operation op, int line, bool removeRoot, bool delete void GridAccount::CheckMeta(Operation& op, int line, bool check) { - // std::vector::iterator it, it2; - // wxGridCellTreeButtonRenderer* treeRenderer; - // int i; - // Operation op2; - // wxColour color ; - // unsigned char r, g, b; - // User* user = _kiss->GetUser(); + int i, new_line; + Operation op2; + QColor color ; + unsigned char r, g, b; + User* user = _kiss->GetUser(); - // treeRenderer = (wxGridCellTreeButtonRenderer*) GetCellRenderer(line, TREE); + QPushButton* button = qobject_cast(cellWidget(line, TREE)); - // for(i=0; i<(int)op.childs.size(); i++) - // { - // op2 = GetOperation(op.childs[i]); - // op2.checked = check; - // UpdateOperation(op2); + for(i=0; i<(int)op.childs.size(); i++) + { + op2 = GetOperation(op.childs[i]); + op2.checked = check; + UpdateOperation(op2); - // if (op2.meta) - // CheckMeta(op2, line+1, check); + if (op2.meta) + CheckMeta(op2, line+1, check); - // if (treeRenderer->IsCollapsed()) - // { - // SetCellValue(line+i+1, CHECKED, check ? wxT("1") : wxT("0")); - // color = user->GetCategory(op2.category).backcolor; + if (button->text() == "-") + { + QCheckBox* checkBox = qobject_cast(cellWidget(line+i+1, CHECKED)); + checkBox->setCheckState(check ? Qt::Checked : Qt::Unchecked); + color = user->GetCategory(op2.category).backcolor; - // if (check) - // { - // r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ; - // g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ; - // b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ; - // color.Set(r, g, b, color.Alpha()); - // } - - // SET_ROW_COLOR(line+i+1, color, user->GetCategory(op2.category).forecolor); - // } - // } - - // treeRenderer->DecRef(); + if (check) + { + r = ((color.red()*1.5) >= 0xFF) ? 0xFF : color.red()*1.5 ; + g = ((color.green()*1.5) >= 0xFF) ? 0xFF : color.green()*1.5 ; + b = ((color.blue()*1.5) >= 0xFF) ? 0xFF : color.blue()*1.5 ; + color.setRgb(r, g, b); + } + + new_line = line+i+1; + SET_ROW_COLOR(new_line, color, user->GetCategory(op2.category).forecolor); + } + } } void GridAccount::OnMetaClicked(int id) { - QPushButton* button = qobject_cast (_signalMapper.mapping(id)); + QPushButton* button = qobject_cast (_buttonSignalMapper.mapping(id)); std::vector::iterator it; std::vector::iterator it2; int i, row; @@ -655,487 +657,492 @@ void GridAccount::OnMetaClicked(int id) } } -void GridAccount::OnOperationModified() +void GridAccount::OnCheckClicked(int id) { - // User* user = _kiss->GetUser(); - // int row = event.GetRow(); - // int col = event.GetCol(); - // Operation new_op, cur_op, op_tmp, op_tmp2; - // int op_complete = 6, i, last_day; - // wxString value ; - // wxDateTime date; - // bool need_insertion = false; - // static bool inModification = false ; - // wxColour color ; - // unsigned char r, g, b; - // wxGridCellTreeButtonRenderer* treeRenderer; - // std::vector::iterator it; - // Operation op, op2; - // double amount; - // wxFont font; - // Category cat ; + std::vector::iterator it; + int row; - // // Avoid recursives calls - // if (inModification || _loadOperations) return; + if (_inModification || _loadOperations) return; - // inModification = true ; + QCheckBox* checkBox = qobject_cast (_checkSignalMapper.mapping(id)); + + it = std::find(_displayedOperations.begin(), _displayedOperations.end(), id); + + if (it == _displayedOperations.end()) return ; + + row = it-_displayedOperations.begin(); + _displayedOperations[row].checked = (checkBox->checkState() == Qt::Checked); + OnOperationModified(row, CHECKED); +} + +void GridAccount::OnOperationModified(int row, int col) +{ + User* user = _kiss->GetUser(); + Operation new_op, cur_op, op_tmp, op_tmp2; + int op_complete = 6, i, last_day; + QString value, v ; + QDate date; + bool need_insertion = false; + QColor color ; + unsigned char r, g, b; + std::vector::iterator it; + Operation op, op2; + double amount; + QFont font; + Category cat ; + + // Avoid recursives calls + if (_inModification || _loadOperations) return; + + _inModification = true ; - // if (col == DEBIT) - // SetCellValue(row, CREDIT, ""); - // else if (col == CREDIT) - // SetCellValue(row, DEBIT, ""); + cur_op = (_displayedOperations)[row] ; - // value = GetCellValue(row, DESCRIPTION); - // if (value) - // { - // new_op.description = value; - // op_complete--; - // } + if (col == DEBIT) + setItem(row, CREDIT, new QTableWidgetItem("")); + else if (col == CREDIT) + setItem(row, DEBIT, new QTableWidgetItem("")); - // value = GetCellValue(row, OP_DATE); - // if (value) - // { - // date.ParseFormat(value, wxT("%d/%m/%Y")); - // new_op.day = date.GetDay()-1; - // new_op.month = date.GetMonth(); - // new_op.year = date.GetYear(); - // op_complete--; - // } + value = item(row, DESCRIPTION)->text(); + if (value.length()) + { + new_op.description = value; + op_complete--; + } + + value = item(row, OP_DATE)->text(); + if (value.length()) + { + date = QDate::fromString(value, "dd/MM/yyyy"); + new_op.day = date.day()-1; + new_op.month = date.month()-1; + new_op.year = date.year(); + op_complete--; + } - // if (col == DESCRIPTION && - // (!GetCellValue(row, CATEGORY) || - // !GetCellValue(row, ACCOUNT))) - // { - // new_op.fix_cost = (row <= _fixCosts); - // if (_kiss->SearchPreviousOperation(&op_tmp, new_op, _curMonth, _curYear, _canAddOperation)) - // { - // if (!GetCellValue(row, CATEGORY)) - // { - // new_op.category = op_tmp.category; - // SetCellValue(row, CATEGORY, wxGetTranslation(user->GetCategoryName(new_op.category))); - // op_complete--; - // } + if (!cur_op.meta && col == DESCRIPTION && + (!item(row, CATEGORY)->text().length() || + !item(row, ACCOUNT)->text().length())) + { + new_op.fix_cost = (row <= _fixCosts); + if (_kiss->SearchPreviousOperation(&op_tmp, new_op, _curMonth, _curYear, _canAddOperation)) + { + if (!item(row, CATEGORY)->text().length()) + setItem(row, CATEGORY, new QTableWidgetItem(_(user->GetCategoryName(op_tmp.category).toStdString().c_str()))); - // if (!GetCellValue(row, ACCOUNT)) - // { - // new_op.account = op_tmp.account; - // SetCellValue(row, ACCOUNT, user->GetAccountName(new_op.account)); - // op_complete--; - // } + if (!item(row, ACCOUNT)->text().length()) + setItem(row, ACCOUNT, new QTableWidgetItem(user->GetAccountName(op_tmp.account))); - // col = CATEGORY; - // new_op.fix_cost = (new_op.category == user->GetCategoryId(wxT("Fix"))); - // } - // } + col = CATEGORY; + new_op.fix_cost = (new_op.category == user->GetCategoryId("Fix")); + } + } - // value = GetCellValue(row, DEBIT); - // if (value) - // { - // value.ToDouble(&new_op.amount); - // if (new_op.amount < 0) - // { - // new_op.amount *= -1.0; - // SetCellValue(row, DEBIT, wxString::Format(wxT("%.2lf"), new_op.amount)); - // } - // if (new_op.amount != 0.0) new_op.amount *= -1.0; - // op_complete--; - // wxGridCellFormulaEditor* pEditor = (wxGridCellFormulaEditor*) GetCellEditor(row, DEBIT); - // new_op.formula = pEditor->GetFormula(); - // pEditor->DecRef(); - // } + value = item(row, DEBIT)->text(); + if (value.length()) + { + new_op.amount = value.toDouble(); + if (new_op.amount < 0) + { + new_op.amount *= -1.0; + setItem(row, DEBIT, new QTableWidgetItem(value.sprintf("%.2lf", new_op.amount))); + } + if (new_op.amount != 0.0) new_op.amount *= -1.0; + op_complete--; + new_op.formula = _displayedOperations[row].formula; + } - // value = GetCellValue(row, CREDIT); - // if (value) - // { - // value.ToDouble(&new_op.amount); - // if (new_op.amount < 0) - // { - // new_op.amount *= -1.0; - // SetCellValue(row, CREDIT, wxString::Format(wxT("%.2lf"), new_op.amount)); - // } - // op_complete--; - // wxGridCellFormulaEditor* pEditor = (wxGridCellFormulaEditor*) GetCellEditor(row, CREDIT); - // new_op.formula = pEditor->GetFormula(); - // pEditor->DecRef(); - // } + value = item(row, CREDIT)->text(); + if (value.length()) + { + new_op.amount = value.toDouble(); + if (new_op.amount < 0) + { + new_op.amount *= -1.0; + setItem(row, DEBIT, new QTableWidgetItem(value.sprintf("%.2lf", new_op.amount))); + } + if (new_op.amount != 0.0) new_op.amount *= -1.0; + op_complete--; + new_op.formula = _displayedOperations[row].formula; + } - // value = GetCellValue(row, CATEGORY); - // if (value) - // { - // new_op.category = user->GetCategoryId(value); - // op_complete--; - // } + value = item(row, CATEGORY)->text(); + if (value.length()) + { + new_op.category = user->GetCategoryId(value); + op_complete--; + } - // value = GetCellValue(row, ACCOUNT); - // if (value) - // { - // new_op.account = user->GetAccountId(value); - // op_complete--; - // } + value = item(row, ACCOUNT)->text(); + if (value.length()) + { + new_op.account = user->GetAccountId(value); + op_complete--; + } - // value = GetCellValue(row, CHECKED); - // if (value && value != wxT("0")) - // new_op.checked = true; - // else - // new_op.checked = false; - // op_complete--; + if (cellWidget(row, CHECKED)) + new_op.checked = _displayedOperations[row].checked; + else + new_op.checked = false; + op_complete--; - // cur_op = (_displayedOperations)[row] ; + if (col == CHECKED || col == CATEGORY) + { + color = user->GetCategory(new_op.category).backcolor; - // if (col == CHECKED || col == CATEGORY) - // { - // color = user->GetCategory(new_op.category).backcolor; + if (new_op.checked) + { + r = ((color.red()*1.5) >= 0xFF) ? 0xFF : color.red()*1.5 ; + g = ((color.green()*1.5) >= 0xFF) ? 0xFF : color.green()*1.5 ; + b = ((color.blue()*1.5) >= 0xFF) ? 0xFF : color.blue()*1.5 ; + color.setRgb(r, g, b); + } - // if (new_op.checked) - // { - // r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ; - // g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ; - // b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ; - // color.Set(r, g, b, color.Alpha()); - // } + SET_ROW_COLOR(row, color, user->GetCategory(new_op.category).forecolor); + SET_ROW_FONT(row, user->GetCategoryFont(new_op.category)); - // SET_ROW_COLOR(row, color, user->GetCategory(new_op.category).forecolor); - // SET_ROW_FONT(row, user->GetCategoryFont(new_op.category)); - - // if (col == CHECKED) - // { - // cur_op.checked = new_op.checked; - // UpdateOperation(cur_op); - // inModification = false; - // if (cur_op.meta) - // CheckMeta(cur_op, row, cur_op.checked); - // else - // { - // if (cur_op.parent) - // { - // op2 = GetOperation(cur_op.parent); - // UpdateMeta(op2); - // int row2 = GetDisplayedRow(op2.id); - // SetCellValue(row2, CHECKED, op2.checked ? wxT("1") : wxT("0")); + if (col == CHECKED) + { + cur_op.checked = new_op.checked; + UpdateOperation(cur_op); + if (cur_op.meta) + CheckMeta(cur_op, row, cur_op.checked); + else + { + if (cur_op.parent) + { + op2 = GetOperation(cur_op.parent); + UpdateMeta(op2); + int row2 = GetDisplayedRow(op2.id); + QCheckBox* checkBox = qobject_cast(cellWidget(row2, CHECKED)); + checkBox->setCheckState(op2.checked ? Qt::Checked : Qt::Unchecked); - // color = user->GetCategory(op2.category).backcolor; + color = user->GetCategory(op2.category).backcolor; - // if (op2.checked) - // { - // r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ; - // g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ; - // b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ; - // color.Set(r, g, b, color.Alpha()); - // } + if (op2.checked) + { + r = ((color.red()*1.5) >= 0xFF) ? 0xFF : color.red()*1.5 ; + g = ((color.green()*1.5) >= 0xFF) ? 0xFF : color.green()*1.5 ; + b = ((color.blue()*1.5) >= 0xFF) ? 0xFF : color.blue()*1.5 ; + color.setRgb(r, g, b); + } - // SET_ROW_COLOR(row2, color, user->GetCategory(op2.category).forecolor); - // } - // } - // event.Skip(); - // return; - // } - // } + SET_ROW_COLOR(row2, color, user->GetCategory(op2.category).forecolor); + } + } + _inModification = false; + return; + } + } + else + { + SET_ROW_COLOR(row, user->GetCategory(new_op.category).backcolor, user->GetCategory(new_op.category).forecolor); + SET_ROW_FONT(row, user->GetCategoryFont(new_op.category)); + } - // if (col == OP_DELETE) - // { - // wxMessageDialog dialog(this, _("Are you sure want to delete : \n")+new_op.description, wxT("KissCount"), wxYES_NO); - // if (dialog.ShowModal() == wxID_NO) - // { - // SetCellValue(row, col, wxT("0")); - // inModification = false; - // return; - // } - // } + if (col == OP_DELETE) + { + if (QMessageBox::question(0, "KissCount", _("Are you sure want to delete : \n")+new_op.description, QMessageBox::Yes|QMessageBox::No) == QMessageBox::No) + { + //SetCellValue(row, col, wxT("0")); + _inModification = false; + return; + } + } - // // Modify a fix operation - // if (row < _fixCosts || !_canAddOperation) - // { - // if (col == OP_DELETE) - // { - // if (cur_op.parent) - // user->UnGroup(_displayedOperations[row]); + // Modify a fix operation + if (row < _fixCosts || !_canAddOperation) + { + if (col == OP_DELETE) + { + if (cur_op.parent) + user->UnGroup(_displayedOperations[row]); - // if (cur_op.meta) - // RemoveMeta(_displayedOperations[row], row, true, true); - // else - // { - // if (cur_op.parent) - // { - // op_tmp = GetOperation(cur_op.parent); - // for (int a=0; a<(int)op_tmp.childs.size(); a++) - // if (op_tmp.childs[a] == op.id) - // { - // op2.childs.erase(op_tmp.childs.begin()+a); - // break; - // } - // } + if (cur_op.meta) + RemoveMeta(_displayedOperations[row], row, true, true); + else + { + if (cur_op.parent) + { + op_tmp = GetOperation(cur_op.parent); + for (int a=0; a<(int)op_tmp.childs.size(); a++) + if (op_tmp.childs[a] == op.id) + { + op2.childs.erase(op_tmp.childs.begin()+a); + break; + } + } - // DeleteRows(row, 1); - // DeleteOperation(cur_op); - // if (_databaseSynchronization) - // _kiss->DeleteOperation(cur_op); - // _displayedOperations.erase(_displayedOperations.begin()+row); + removeRow(row); + DeleteOperation(cur_op); + if (_databaseSynchronization) + _kiss->DeleteOperation(cur_op); + _displayedOperations.erase(_displayedOperations.begin()+row); - // if (cur_op.parent && op_tmp.childs.size() < 2) - // { - // if (op_tmp.childs.size() == 1) - // { - // op_tmp2 = GetOperation(op_tmp.childs[0]); - // op_tmp2.parent = ""; - // UpdateOperation(op_tmp2); - // row = GetDisplayedRow(op_tmp2.id); - // _displayedOperations[row] = op_tmp2; - // } - // row = GetDisplayedRow(cur_op.parent); - // DeleteRows(row, 1); - // DeleteOperation(op_tmp); - // if (_databaseSynchronization) - // _kiss->DeleteOperation(op_tmp); - // _displayedOperations.erase(_displayedOperations.begin()+row); - // _fixCosts--; - // } - // _fixCosts--; - // ComputeWeeks(); - // } - // inModification = false ; - // event.Skip(); - // return ; - // } + if (cur_op.parent && op_tmp.childs.size() < 2) + { + if (op_tmp.childs.size() == 1) + { + op_tmp2 = GetOperation(op_tmp.childs[0]); + op_tmp2.parent = 0; + UpdateOperation(op_tmp2); + row = GetDisplayedRow(op_tmp2.id); + _displayedOperations[row] = op_tmp2; + } + row = GetDisplayedRow(cur_op.parent); + removeRow(row); + DeleteOperation(op_tmp); + if (_databaseSynchronization) + _kiss->DeleteOperation(op_tmp); + _displayedOperations.erase(_displayedOperations.begin()+row); + _fixCosts--; + } + _fixCosts--; + ComputeWeeks(); + } + _inModification = false ; + return ; + } - // new_op.id = cur_op.id; - // new_op.fix_cost = true; - // new_op.transfert = cur_op.transfert; - // new_op.meta = cur_op.meta; - // new_op.parent = cur_op.parent; - // new_op.childs = cur_op.childs; - // new_op._virtual = cur_op._virtual; + new_op.id = cur_op.id; + new_op.fix_cost = true; + new_op.transfert = cur_op.transfert; + new_op.meta = cur_op.meta; + new_op.parent = cur_op.parent; + new_op.childs = cur_op.childs; + new_op._virtual = cur_op._virtual; - // if (cur_op.day != new_op.day) - // { - // need_insertion = true; - // DeleteRows(row, 1); - // DeleteOperation(cur_op); - // _displayedOperations.erase(_displayedOperations.begin()+row); - // _fixCosts--; - // } - // else - // { - // UpdateOperation(new_op); - // (_displayedOperations)[row] = new_op; - // } - // } - // // Add a fixCost - // else if (row == _fixCosts) - // { - // if (op_complete) { - // inModification = false ; - // return ; - // } - // need_insertion = true; - // new_op.fix_cost = true; - // new_op.meta = false; - // new_op._virtual = false; + if (cur_op.day != new_op.day) + { + need_insertion = true; + removeRow(row); + DeleteOperation(cur_op); + _displayedOperations.erase(_displayedOperations.begin()+row); + _fixCosts--; + } + else + { + UpdateOperation(new_op); + (_displayedOperations)[row] = new_op; + } + } + // Add a fixCost + else if (row == _fixCosts) + { + if (op_complete) { + _inModification = false ; + return ; + } + need_insertion = true; + new_op.fix_cost = true; + new_op.meta = false; + new_op._virtual = false; - // for(i=0; iAddOperation(new_op); - // } - // // Modify an operation - // else if (row < (int)(_displayedOperations.size()-1)) - // { - // new_op.id = cur_op.id; - // new_op.fix_cost = false; - // new_op.transfert = cur_op.transfert; - // new_op.meta = cur_op.meta; - // new_op.parent = cur_op.parent; - // new_op.childs = cur_op.childs; - // new_op._virtual = cur_op._virtual; + new_op.id = _kiss->AddOperation(new_op); + } + // Modify an operation + else if (row < (int)(_displayedOperations.size()-1)) + { + new_op.id = cur_op.id; + new_op.fix_cost = false; + new_op.transfert = cur_op.transfert; + new_op.meta = cur_op.meta; + new_op.parent = cur_op.parent; + new_op.childs = cur_op.childs; + new_op._virtual = cur_op._virtual; - // if (col == OP_DELETE) - // { - // if (cur_op.parent) - // user->UnGroup(_displayedOperations[row]); + if (col == OP_DELETE) + { + if (cur_op.parent) + user->UnGroup(_displayedOperations[row]); - // if (cur_op.meta) - // RemoveMeta(_displayedOperations[row], row, true, true); - // else - // { - // if (cur_op.parent) - // { - // op_tmp = GetOperation(cur_op.parent); - // for (int a=0; a<(int)op_tmp.childs.size(); a++) - // if (op_tmp.childs[a] == op.id) - // { - // op2.childs.erase(op_tmp.childs.begin()+a); - // break; - // } - // } + if (cur_op.meta) + RemoveMeta(_displayedOperations[row], row, true, true); + else + { + if (cur_op.parent) + { + op_tmp = GetOperation(cur_op.parent); + for (int a=0; a<(int)op_tmp.childs.size(); a++) + if (op_tmp.childs[a] == op.id) + { + op2.childs.erase(op_tmp.childs.begin()+a); + break; + } + } - // DeleteRows(row, 1); - // DeleteOperation(cur_op); - // _displayedOperations.erase(_displayedOperations.begin()+row); - // if (_databaseSynchronization) - // _kiss->DeleteOperation(cur_op); + removeRow(row); + DeleteOperation(cur_op); + _displayedOperations.erase(_displayedOperations.begin()+row); + if (_databaseSynchronization) + _kiss->DeleteOperation(cur_op); - // if (cur_op.parent && op_tmp.childs.size() <= 1) - // { - // if (op_tmp.childs.size() == 1) - // { - // op_tmp2 = GetOperation(op_tmp.childs[0]); - // op_tmp2.parent = ""; - // UpdateOperation(op_tmp2); - // row = GetDisplayedRow(op_tmp2.id); - // _displayedOperations[row] = op_tmp2; - // } - // row = GetDisplayedRow(cur_op.parent); - // DeleteRows(row, 1); - // DeleteOperation(op_tmp); - // if (_databaseSynchronization) - // _kiss->DeleteOperation(op_tmp); - // _displayedOperations.erase(_displayedOperations.begin()+row); - // } + if (cur_op.parent && op_tmp.childs.size() <= 1) + { + if (op_tmp.childs.size() == 1) + { + op_tmp2 = GetOperation(op_tmp.childs[0]); + op_tmp2.parent = 0; + UpdateOperation(op_tmp2); + row = GetDisplayedRow(op_tmp2.id); + _displayedOperations[row] = op_tmp2; + } + row = GetDisplayedRow(cur_op.parent); + removeRow(row); + DeleteOperation(op_tmp); + if (_databaseSynchronization) + _kiss->DeleteOperation(op_tmp); + _displayedOperations.erase(_displayedOperations.begin()+row); + } - // ComputeWeeks(); - // } - // inModification = false ; - // event.Skip(); - // return ; - // } + ComputeWeeks(); + } + _inModification = false ; + return ; + } - // if (cur_op.day != new_op.day) - // { - // need_insertion = true; - // DeleteRows(row, 1); - // DeleteOperation(cur_op); - // _displayedOperations.erase(_displayedOperations.begin()+row); - // } - // else - // { - // UpdateOperation(new_op); - // (_displayedOperations)[row] = new_op; - // } - // } - // // Add an operation - // else - // { - // if (op_complete) { - // inModification = false ; - // return ; - // } - // need_insertion = true; - // new_op.fix_cost = false; - // new_op.meta = false; - // new_op._virtual = false; + if (cur_op.day != new_op.day) + { + need_insertion = true; + removeRow(row); + DeleteOperation(cur_op); + _displayedOperations.erase(_displayedOperations.begin()+row); + } + else + { + UpdateOperation(new_op); + (_displayedOperations)[row] = new_op; + } + } + // Add an operation + else + { + if (op_complete) { + _inModification = false ; + return ; + } + need_insertion = true; + new_op.fix_cost = false; + new_op.meta = false; + new_op._virtual = false; - // for(i=0; iAddOperation(new_op); - // } + new_op.id = _kiss->AddOperation(new_op); + } - // if (user->GetAccount(new_op.account).blocked && new_op.amount < 0) - // wxMessageBox(_("You made a debit on a blocked account"), _("Warning"), wxICON_WARNING | wxOK); + if (user->GetAccount(new_op.account).blocked && new_op.amount < 0) + QMessageBox::warning(0, _("Warning"), _("You made a debit on a blocked account")); - // if (need_insertion) - // { - // InsertIntoGrid(new_op); - // UpdateOperation(new_op); - // } + if (need_insertion) + { + InsertIntoGrid(new_op); + UpdateOperation(new_op); + } - // if (new_op.parent) - // { - // row = GetDisplayedRow(new_op.parent); + if (new_op.parent) + { + row = GetDisplayedRow(new_op.parent); - // new_op = _displayedOperations[row]; + new_op = _displayedOperations[row]; - // last_day = new_op.day; + last_day = new_op.day; - // UpdateMeta(new_op); + UpdateMeta(new_op); - // _displayedOperations[row] = new_op; + _displayedOperations[row] = new_op; - // cat = user->GetCategory(new_op.category); + cat = user->GetCategory(new_op.category); - // if (new_op.category) - // color = cat.backcolor; - // else - // color = view::OWN_GREEN; + if (new_op.category) + color = cat.backcolor; + else + color = view::OWN_GREEN; - // if (new_op.checked) - // { - // r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ; - // g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ; - // b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ; - // color.Set(r, g, b, color.Alpha()); - // SetCellValue(row, CHECKED, wxT("1")); - // } - // else - // SetCellValue(row, CHECKED, wxT("0")); + QCheckBox* checkBox = qobject_cast (_checkSignalMapper.mapping(op.parent)); + if (new_op.checked) + { + r = ((color.red()*1.5) >= 0xFF) ? 0xFF : color.red()*1.5 ; + g = ((color.green()*1.5) >= 0xFF) ? 0xFF : color.green()*1.5 ; + b = ((color.blue()*1.5) >= 0xFF) ? 0xFF : color.blue()*1.5 ; + color.setRgb(r, g, b); + checkBox->setCheckState(Qt::Checked); + } + else + checkBox->setCheckState(Qt::Unchecked); - // SET_ROW_COLOR(row, color, cat.forecolor); + SET_ROW_COLOR(row, color, cat.forecolor); - // if (new_op.category && cat.font) - // { - // font = user->GetCategoryFont(cat.id); - // SET_ROW_FONT(row, font); - // } + if (new_op.category && cat.font.length()) + { + font = user->GetCategoryFont(cat.id); + SET_ROW_FONT(row, font); + } - // SetCellValue(row, OP_DATE, wxString::Format(wxT("%02d/%02d/%d"), new_op.day+1, _curMonth+1, _curYear)); + setItem(row, OP_DATE, new QTableWidgetItem(v.sprintf("%02d/%02d/%d", new_op.day+1, _curMonth+1, _curYear))); - // if (!_displayedOperations[row].amount) - // { - // amount = _kiss->MetaPositiveAmount(new_op.id); + if (!_displayedOperations[row].amount) + { + amount = _kiss->MetaPositiveAmount(new_op.id); - // SetCellValue(row, DEBIT, wxString::Format(wxT("%.2lf"), amount)); - // SetCellValue(row, CREDIT, wxString::Format(wxT("%.2lf"), amount)); - // } - // else - // { - // if (_displayedOperations[row].amount < 0) - // { - // SetCellValue(row, DEBIT, wxString::Format(wxT("%.2lf"), -new_op.amount)); - // SetCellValue(row, CREDIT, ""); - // } - // else - // { - // SetCellValue(row, DEBIT, ""); - // SetCellValue(row, CREDIT, wxString::Format(wxT("%.2lf"), new_op.amount)); - // } - // } + setItem(row, DEBIT, new QTableWidgetItem(v.sprintf("%.2lf", amount))); + setItem(row, CREDIT, new QTableWidgetItem(v.sprintf("%.2lf", amount))); + } + else + { + if (_displayedOperations[row].amount < 0) + { + setItem(row, DEBIT, new QTableWidgetItem(v.sprintf("%.2lf", -new_op.amount))); + setItem(row, CREDIT, new QTableWidgetItem("")); + } + else + { + setItem(row, DEBIT, new QTableWidgetItem("")); + setItem(row, CREDIT, new QTableWidgetItem(v.sprintf("%.2lf", new_op.amount))); + } + } - // // Move updated meta - // if ((int)new_op.day != last_day) - // { - // int i; - // RemoveMeta(new_op, row, true, false); - // InsertIntoGrid(new_op); - // row = GetDisplayedRow(new_op.id); - // for (i=1, it=new_op.childs.begin(); it!=new_op.childs.end(); it++, i++) - // { - // op2 = GetOperation(*it); - // InsertOperationWithWeek(user, op2, row+i, op2.fix_cost, _curMonth, _curYear); - // } - // treeRenderer = (wxGridCellTreeButtonRenderer*) GetCellRenderer(row, 0); - // treeRenderer->Invert(); - // treeRenderer->DecRef(); - // } - // } + // Move updated meta + if ((int)new_op.day != last_day) + { + int i; + RemoveMeta(new_op, row, true, false); + InsertIntoGrid(new_op); + row = GetDisplayedRow(new_op.id); + for (i=1, it=new_op.childs.begin(); it!=new_op.childs.end(); it++, i++) + { + op2 = GetOperation(*it); + InsertOperationWithWeek(user, op2, row+i, op2.fix_cost, _curMonth, _curYear); + } + QPushButton* button = qobject_cast (cellWidget(row, TREE)); + if (button->text() == "+") + button->setText("-"); + else + button->setText("+"); + } + } - // inModification = false ; - - // event.Skip(); + _inModification = false ; } void GridAccount::UpdateMeta(Operation& meta) diff --git a/src/view/grid/GridAccount.hpp b/src/view/grid/GridAccount.hpp index f9cb306..0224002 100644 --- a/src/view/grid/GridAccount.hpp +++ b/src/view/grid/GridAccount.hpp @@ -20,20 +20,12 @@ #ifndef GRIDACCOUNT_H #define GRIDACCOUNT_H -// #include -// #include #include #include #include #include #include #include -// #include "wxGridCellFastBoolEditor.hpp" -// #include "wxGridCellTreeButtonRenderer.hpp" -// #include "wxGridCellTreeButtonEditor.hpp" -// #include "wxGridCellBitmapRenderer.hpp" -// #include "wxGridCellFormulaEditor.hpp" -// #include "wxGridCellTabStringRenderer.hpp" #include #include @@ -55,9 +47,6 @@ public: bool canAddOperation, bool setWeek, bool synchronizeWithDatabase); ~GridAccount(); - // wxPen GetColGridLinePen (int col); - // wxPen GetRowGridLinePen (int row); - virtual void ClearGrid(); void LoadOperations(std::vector* operations, int month, int year); void InsertOperationWithWeek(User* user, Operation& op, int line, bool fix, int month, int year) ; @@ -69,13 +58,14 @@ public: void UnGroup(); int _fixCosts; - int _week1, _week2, _week3, _week4; + int _week1, _week2, _week3, _week4, _week5; bool _canAddOperation; std::vector _displayedOperations; private slots: - void OnOperationModified(); + void OnOperationModified(int row, int col); void OnMetaClicked(int id); + void OnCheckClicked(int id); private: QWidget* _parent; @@ -87,7 +77,8 @@ private: std::vector* _operations; bool _loadOperations; int _curMonth, _curYear; - QSignalMapper _signalMapper; + QSignalMapper _buttonSignalMapper, _checkSignalMapper; + bool _inModification; void SetWeek(int week, int line); void ResetWeeks(); diff --git a/src/view/grid/TableViewDelegate.hpp b/src/view/grid/TableViewDelegate.hpp index cd08136..02c83d5 100644 --- a/src/view/grid/TableViewDelegate.hpp +++ b/src/view/grid/TableViewDelegate.hpp @@ -64,7 +64,8 @@ public: row == _grid->_week1 || row == _grid->_week2 || row == _grid->_week3 || - row == _grid->_week4) + row == _grid->_week4 || + row == _grid->_week5) painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); } }