* Correct two bugs with meta operations (one operation left after deleting, and transfert displays)
* Add primary support for formulas
This commit is contained in:
parent
477d155c3f
commit
0c3a148472
|
@ -255,7 +255,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
|
||||||
{
|
{
|
||||||
std::vector<Operation>::iterator it;
|
std::vector<Operation>::iterator it;
|
||||||
std::vector<wxString>::iterator it2;
|
std::vector<wxString>::iterator it2;
|
||||||
int r, g, b, amount;
|
int r, g, b;
|
||||||
|
double amount;
|
||||||
wxColour color;
|
wxColour color;
|
||||||
wxDateTime curDate;
|
wxDateTime curDate;
|
||||||
wxString description;
|
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));
|
SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op.amount));
|
||||||
else
|
else
|
||||||
SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op.amount));
|
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)
|
if (!op.meta)
|
||||||
SetCellValue(line, ACCOUNT, user->GetAccountName(op.account));
|
SetCellValue(line, ACCOUNT, user->GetAccountName(op.account));
|
||||||
if (!fix && !op.meta)
|
if (!fix && !op.meta)
|
||||||
|
@ -633,6 +638,9 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
|
||||||
value.ToDouble(&new_op.amount);
|
value.ToDouble(&new_op.amount);
|
||||||
new_op.amount *= -1.0;
|
new_op.amount *= -1.0;
|
||||||
op_complete--;
|
op_complete--;
|
||||||
|
wxGridCellFormulaEditor* pEditor = (wxGridCellFormulaEditor*) GetCellEditor(row, col);
|
||||||
|
new_op.formula = pEditor->GetFormula();
|
||||||
|
pEditor->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
value = GetCellValue(row, CREDIT);
|
value = GetCellValue(row, CREDIT);
|
||||||
|
@ -640,6 +648,9 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
|
||||||
{
|
{
|
||||||
value.ToDouble(&new_op.amount);
|
value.ToDouble(&new_op.amount);
|
||||||
op_complete--;
|
op_complete--;
|
||||||
|
wxGridCellFormulaEditor* pEditor = (wxGridCellFormulaEditor*) GetCellEditor(row, col);
|
||||||
|
new_op.formula = pEditor->GetFormula();
|
||||||
|
pEditor->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
value = GetCellValue(row, CATEGORY);
|
value = GetCellValue(row, CATEGORY);
|
||||||
|
@ -750,10 +761,30 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
|
||||||
RemoveMeta(_displayedOperations[row], row, true, true);
|
RemoveMeta(_displayedOperations[row], row, true, true);
|
||||||
else
|
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);
|
DeleteRows(row, 1);
|
||||||
DeleteOperation(cur_op);
|
DeleteOperation(cur_op);
|
||||||
_kiss->DeleteOperation(cur_op);
|
_kiss->DeleteOperation(cur_op);
|
||||||
_displayedOperations.erase(_displayedOperations.begin()+row);
|
_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--;
|
_fixCosts = _fixCosts--;
|
||||||
inModification = false ;
|
inModification = false ;
|
||||||
|
@ -829,10 +860,30 @@ void GridAccount::OnOperationModified(wxGridEvent& event)
|
||||||
RemoveMeta(_displayedOperations[row], row, true, true);
|
RemoveMeta(_displayedOperations[row], row, true, true);
|
||||||
else
|
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);
|
DeleteRows(row, 1);
|
||||||
DeleteOperation(cur_op);
|
DeleteOperation(cur_op);
|
||||||
_displayedOperations.erase(_displayedOperations.begin()+row);
|
_displayedOperations.erase(_displayedOperations.begin()+row);
|
||||||
_kiss->DeleteOperation(cur_op);
|
_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 ;
|
inModification = false ;
|
||||||
event.Skip();
|
event.Skip();
|
||||||
|
@ -1214,7 +1265,7 @@ removeLastGroup:
|
||||||
line = GetDisplayedRow(op.id);
|
line = GetDisplayedRow(op.id);
|
||||||
DeleteRows(line, 1);
|
DeleteRows(line, 1);
|
||||||
_displayedOperations.erase(_displayedOperations.begin()+line);
|
_displayedOperations.erase(_displayedOperations.begin()+line);
|
||||||
InsertIntoGrid(GetOperation(op.id)); // Don't use temp variable
|
InsertIntoGrid(GetOperation(op.id));
|
||||||
if (op.fix_cost) _fixCosts--;
|
if (op.fix_cost) _fixCosts--;
|
||||||
for (a=0; a<(int)op2.childs.size(); a++)
|
for (a=0; a<(int)op2.childs.size(); a++)
|
||||||
if (op2.childs[a] == op.id)
|
if (op2.childs[a] == op.id)
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "wxGridCellFastBoolEditor.h"
|
#include "wxGridCellFastBoolEditor.h"
|
||||||
#include "wxGridCellTreeButtonRenderer.h"
|
#include "wxGridCellTreeButtonRenderer.h"
|
||||||
#include "wxGridCellTreeButtonEditor.h"
|
#include "wxGridCellTreeButtonEditor.h"
|
||||||
|
#include "wxGridCellFormulaEditor.h"
|
||||||
|
|
||||||
class KissCount;
|
class KissCount;
|
||||||
|
|
||||||
|
@ -56,13 +57,14 @@ public:
|
||||||
|
|
||||||
int _fixCosts;
|
int _fixCosts;
|
||||||
int _week1, _week2, _week3, _week4;
|
int _week1, _week2, _week3, _week4;
|
||||||
|
std::vector<Operation> _displayedOperations;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KissCount* _kiss;
|
KissCount* _kiss;
|
||||||
wxString* _categories, *_accounts;
|
wxString* _categories, *_accounts;
|
||||||
std::vector<Operation>* _operations;
|
std::vector<Operation>* _operations;
|
||||||
bool _canAddOperation;
|
bool _canAddOperation;
|
||||||
int _curMonth, _curYear;
|
int _curMonth, _curYear;
|
||||||
std::vector<Operation> _displayedOperations;
|
|
||||||
|
|
||||||
void SetWeek(int week, int line);
|
void SetWeek(int week, int line);
|
||||||
void ResetWeeks();
|
void ResetWeeks();
|
||||||
|
|
70
src/view/grid/wxGridCellFormulaEditor.cpp
Normal file
70
src/view/grid/wxGridCellFormulaEditor.cpp
Normal 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;
|
||||||
|
}
|
56
src/view/grid/wxGridCellFormulaEditor.h
Normal file
56
src/view/grid/wxGridCellFormulaEditor.h
Normal 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
|
Loading…
Reference in New Issue
Block a user