* Correct two bugs with meta operations (one operation left after deleting, and transfert displays)

* Add primary support for formulas
This commit is contained in:
Grégory Soutadé 2010-10-08 20:47:56 +02:00
parent 477d155c3f
commit 0c3a148472
4 changed files with 183 additions and 4 deletions

View File

@ -255,7 +255,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
{
std::vector<Operation>::iterator it;
std::vector<wxString>::iterator it2;
int r, g, b, amount;
int r, g, b;
double amount;
wxColour color;
wxDateTime curDate;
wxString description;
@ -314,6 +315,10 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op.amount));
else
SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op.amount));
SetCellEditor(line, DEBIT, new wxGridCellFormulaEditor(op.formula));
SetCellEditor(line, CREDIT, new wxGridCellFormulaEditor(op.formula));
if (!op.meta)
SetCellValue(line, ACCOUNT, user->GetAccountName(op.account));
if (!fix && !op.meta)
@ -633,6 +638,9 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
value.ToDouble(&new_op.amount);
new_op.amount *= -1.0;
op_complete--;
wxGridCellFormulaEditor* pEditor = (wxGridCellFormulaEditor*) GetCellEditor(row, col);
new_op.formula = pEditor->GetFormula();
pEditor->DecRef();
}
value = GetCellValue(row, CREDIT);
@ -640,6 +648,9 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
{
value.ToDouble(&new_op.amount);
op_complete--;
wxGridCellFormulaEditor* pEditor = (wxGridCellFormulaEditor*) GetCellEditor(row, col);
new_op.formula = pEditor->GetFormula();
pEditor->DecRef();
}
value = GetCellValue(row, CATEGORY);
@ -750,10 +761,30 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
RemoveMeta(_displayedOperations[row], row, true, true);
else
{
if (cur_op.parent.Length())
{
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);
_kiss->DeleteOperation(cur_op);
_displayedOperations.erase(_displayedOperations.begin()+row);
if (cur_op.parent.Length() && op_tmp.childs.size() <= 1)
{
row = GetDisplayedRow(cur_op.parent);
DeleteRows(row, 1);
DeleteOperation(op_tmp);
_kiss->DeleteOperation(op_tmp);
_displayedOperations.erase(_displayedOperations.begin()+row);
}
}
_fixCosts = _fixCosts--;
inModification = false ;
@ -767,7 +798,7 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
new_op.meta = cur_op.meta;
new_op.parent = cur_op.parent;
new_op.childs = cur_op.childs;
if (cur_op.day != new_op.day)
{
need_insertion = true;
@ -829,10 +860,30 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
RemoveMeta(_displayedOperations[row], row, true, true);
else
{
if (cur_op.parent.Length())
{
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);
_kiss->DeleteOperation(cur_op);
if (cur_op.parent.Length() && op_tmp.childs.size() <= 1)
{
row = GetDisplayedRow(cur_op.parent);
DeleteRows(row, 1);
DeleteOperation(op_tmp);
_kiss->DeleteOperation(op_tmp);
_displayedOperations.erase(_displayedOperations.begin()+row);
}
}
inModification = false ;
event.Skip();
@ -1214,7 +1265,7 @@ removeLastGroup:
line = GetDisplayedRow(op.id);
DeleteRows(line, 1);
_displayedOperations.erase(_displayedOperations.begin()+line);
InsertIntoGrid(GetOperation(op.id)); // Don't use temp variable
InsertIntoGrid(GetOperation(op.id));
if (op.fix_cost) _fixCosts--;
for (a=0; a<(int)op2.childs.size(); a++)
if (op2.childs[a] == op.id)

View File

@ -30,6 +30,7 @@
#include "wxGridCellFastBoolEditor.h"
#include "wxGridCellTreeButtonRenderer.h"
#include "wxGridCellTreeButtonEditor.h"
#include "wxGridCellFormulaEditor.h"
class KissCount;
@ -56,13 +57,14 @@ public:
int _fixCosts;
int _week1, _week2, _week3, _week4;
std::vector<Operation> _displayedOperations;
private:
KissCount* _kiss;
wxString* _categories, *_accounts;
std::vector<Operation>* _operations;
bool _canAddOperation;
int _curMonth, _curYear;
std::vector<Operation> _displayedOperations;
void SetWeek(int week, int line);
void ResetWeeks();

View File

@ -0,0 +1,70 @@
/*
Copyright 2010 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 "wxGridCellFormulaEditor.h"
wxGridCellFormulaEditor::wxGridCellFormulaEditor(const wxString& formula) : _formula(formula)
{}
void wxGridCellFormulaEditor::BeginEdit (int row, int col, wxGrid *grid) {
static bool inModification = false;
Operation op;
if (inModification) return ;
inModification = true;
op = ((GridAccount*) grid)->_displayedOperations[row];
if (op.formula.Length())
{
grid->SetCellValue(row, col, op.formula);
_formula = op.formula;
}
wxGridCellTextEditor::BeginEdit(row, col, grid);
inModification = false;
}
bool wxGridCellFormulaEditor::EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
wxString res = GetValue();
Operation op;
bool ret;
res = res.Trim();
if (res.StartsWith(wxT("=")))
_formula = res;
else
_formula = wxT("");
ret = wxGridCellTextEditor::EndEdit(row, col, grid);
if (_formula.Length())
grid->SetCellValue(row, col, wxT("0"));
return ret;
}
wxString wxGridCellFormulaEditor::GetFormula()
{
return _formula;
}

View File

@ -0,0 +1,56 @@
/*
Copyright 2010 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 WXGRIDCELLFORMULAEDITOR_H
#define WXGRIDCELLFORMULAEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
#include "GridAccount.h"
class wxGridCellFormulaEditor : public wxGridCellTextEditor
{
public:
wxGridCellFormulaEditor(const wxString& formula);
/* ~wxGridCellFormulEeditor(); */
/* wxGridCellEditor* Clone () const; */
void BeginEdit (int row, int col, wxGrid *grid);
/* void Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler); */
bool EndEdit (int row, int col, wxGrid *grid/*, const wxString &oldval, wxString *newval*/);
/* void ApplyEdit (int row, int col, wxGrid *grid); */
/* void Reset () ; */
/* wxString GetValue() const ; */
/* void SetSize (const wxRect &rect); */
/* void Show (bool show, wxGridCellAttr *attr); */
wxString GetFormula();
private:
wxString _formula;
wxButton* _button;
int _row, _col;
wxGrid* _grid;
/* DECLARE_EVENT_TABLE(); */
};
#endif