wip
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "AccountPanel.h"
|
||||
|
||||
static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _("")};
|
||||
|
||||
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, -1), _grid(this, -1)
|
||||
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, -1)
|
||||
{
|
||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxChartPanel* chart ;
|
||||
@@ -9,15 +10,15 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
||||
SetSizer(hbox);
|
||||
|
||||
_pie = new PiePlot();
|
||||
_grid.CreateGrid(10, 7);
|
||||
_grid.SetColLabelSize(0);
|
||||
_grid.SetRowLabelSize(0);
|
||||
//_grid.EnableGridLines(false);
|
||||
_grid = new GridAccount(this, -1);
|
||||
_grid->CreateGrid(1, NUMBER_COLS);
|
||||
_grid->SetColLabelSize(0);
|
||||
_grid->SetRowLabelSize(0);
|
||||
|
||||
chart = new wxChartPanel(this);
|
||||
chart->SetChart(new Chart(_pie, _("Cost repartition")));
|
||||
hbox->Add(&_tree, 0);
|
||||
hbox->Add(&_grid, 0);
|
||||
hbox->Add(_grid, 0);
|
||||
hbox->Add(chart, 0);
|
||||
|
||||
ChangeUser();
|
||||
@@ -85,19 +86,42 @@ void AccountPanel::LoadYear(int year)
|
||||
ShowMonth(year, curMonth);
|
||||
}
|
||||
|
||||
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS; i++) \
|
||||
{\
|
||||
_grid->SetCellBackgroundColour(row, i, color);\
|
||||
}
|
||||
|
||||
void AccountPanel::ShowMonth(int year, int month)
|
||||
{
|
||||
std::list<operation> operations;
|
||||
std::list<operation>::iterator it;
|
||||
int fixCosts = 0;
|
||||
int curLine = 0;
|
||||
User* user = _kiss->GetUser();
|
||||
wxFont font(DEFAULT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, DEFAULT_FONT);
|
||||
std::list<wxString>::iterator categoryIt;
|
||||
wxGridCellChoiceEditor* categoryEditor;
|
||||
wxString* categories;
|
||||
int i;
|
||||
|
||||
_wxUI->SetTitle(user->_name + _(" - ") + months[month]);
|
||||
|
||||
// Operations are ordered
|
||||
operations = (*user->_operations[year])[month];
|
||||
|
||||
_grid.CreateGrid(10, 7);
|
||||
_grid->CreateGrid(1, NUMBER_COLS);
|
||||
// Creating headers
|
||||
_grid.SetColSize (0, _grid.GetColSize(0)*4);
|
||||
_grid->SetColSize (0, _grid->GetColSize(0)*3);
|
||||
_grid->SetDefaultCellFont(font);
|
||||
|
||||
font.SetWeight(wxFONTWEIGHT_BOLD);
|
||||
for(i=0; i<NUMBER_COLS; i++)
|
||||
{
|
||||
_grid->SetCellValue(0, i, colsName[i]);
|
||||
_grid->SetCellBackgroundColour(0, i, OWN_CYAN);
|
||||
_grid->SetCellFont(0, i, font);
|
||||
_grid->SetReadOnly(0, i, true);
|
||||
}
|
||||
// SetCellBackgroundColour (int row, int col, const wxColour &colour);
|
||||
// SetCellFont (int row, int col, const wxFont &font);
|
||||
// SetCellValue (int row, int col, const wxString &s);
|
||||
@@ -106,6 +130,94 @@ void AccountPanel::ShowMonth(int year, int month)
|
||||
// AppendRows (int numRows=1, bool updateLabels=true);
|
||||
// InsertRows (int pos=0, int numRows=1, bool updateLabels=true);
|
||||
// SetReadOnly(row, col, bool)
|
||||
|
||||
categories = new wxString[user->_preferences._categories.size()+1];
|
||||
categories[0] = _("unknown");
|
||||
for (i=1,
|
||||
categoryIt = user->_preferences._categories.begin();
|
||||
categoryIt != user->_preferences._categories.end();
|
||||
categoryIt++,
|
||||
i++)
|
||||
categories[i] = *categoryIt;
|
||||
|
||||
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
||||
|
||||
it = operations.begin();
|
||||
|
||||
/*
|
||||
struct operation {
|
||||
wxString id;
|
||||
unsigned int day;
|
||||
unsigned int month;
|
||||
unsigned int year;
|
||||
int amount;
|
||||
wxString description;
|
||||
wxString category;
|
||||
bool fix_cost;
|
||||
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
||||
} ;
|
||||
*/
|
||||
while (it->fix_cost)
|
||||
{
|
||||
_grid->AppendRows();
|
||||
curLine++;
|
||||
fixCosts++;
|
||||
SET_ROW_COLOR(curLine, OWN_YELLOW);
|
||||
_grid->SetCellValue(curLine, DESCRIPTION, it->description);
|
||||
_grid->SetCellValue(curLine, DATE, wxString::Format(wxT("%02d/%02d/%d"), it->day+1, it->month+1, it->year));
|
||||
if (it->amount < 0)
|
||||
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%d"), -it->amount));
|
||||
else
|
||||
_grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%d"), it->amount));
|
||||
_grid->SetCellValue(curLine, CATEGORY, it->category);
|
||||
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
|
||||
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
|
||||
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
||||
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
|
||||
_grid->SetCellValue(curLine, ACCOUNT, it->account);
|
||||
it++;
|
||||
}
|
||||
|
||||
_grid->AppendRows();
|
||||
curLine++;
|
||||
SET_ROW_COLOR(curLine, OWN_YELLOW);
|
||||
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
||||
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
|
||||
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
|
||||
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
|
||||
|
||||
_grid->_fixCosts = ++fixCosts;
|
||||
|
||||
for (; it != operations.begin(); it++)
|
||||
{
|
||||
_grid->AppendRows();
|
||||
curLine++;
|
||||
SET_ROW_COLOR(curLine, OWN_GREEN);
|
||||
_grid->SetCellValue(curLine, DESCRIPTION, it->description);
|
||||
_grid->SetCellValue(curLine, DATE, wxString::Format(wxT("%02d/%02d/%d"), it->day+1, it->month+1, it->year));
|
||||
if (it->amount < 0)
|
||||
_grid->SetCellValue(curLine, DEBIT, wxString::Format(wxT("%d"), -it->amount));
|
||||
else
|
||||
_grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%d"), it->amount));
|
||||
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
|
||||
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
|
||||
_grid->SetCellValue(curLine, CATEGORY, it->category);
|
||||
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
||||
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
|
||||
_grid->SetCellValue(curLine, ACCOUNT, it->account);
|
||||
it++;
|
||||
}
|
||||
|
||||
_grid->AppendRows();
|
||||
curLine++;
|
||||
SET_ROW_COLOR(curLine, OWN_GREEN);
|
||||
categoryEditor = new wxGridCellChoiceEditor(user->_preferences._categories.size()+1, categories, false);
|
||||
_grid->SetCellEditor(curLine, CATEGORY, categoryEditor);
|
||||
_grid->SetCellEditor(curLine, DEBIT, new wxGridCellNumberEditor());
|
||||
_grid->SetCellEditor(curLine, CREDIT, new wxGridCellNumberEditor());
|
||||
|
||||
delete[] categories;
|
||||
|
||||
Fit();
|
||||
SetMinSize(GetSize());
|
||||
}
|
||||
|
@@ -7,6 +7,15 @@
|
||||
#include <wx/pie/pieplot.h>
|
||||
#include <wx/chartpanel.h>
|
||||
|
||||
#define OWN_CYAN wxColour(0x99, 0xCC, 0xFF)
|
||||
#define OWN_YELLOW wxColour(0xFF, 0xFF, 0x99)
|
||||
#define OWN_GREEN wxColour(0x3D, 0xEB, 0x3D)
|
||||
|
||||
#define DEFAULT_FONT _("Liberation Sans")
|
||||
#define DEFAULT_FONT_SIZE 12
|
||||
|
||||
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS};
|
||||
|
||||
#include <controller/KissCount.h>
|
||||
#include "wxUI.h"
|
||||
#include <model/model.h>
|
||||
@@ -27,7 +36,7 @@ private:
|
||||
KissCount* _kiss;
|
||||
wxUI* _wxUI;
|
||||
wxTreeCtrl _tree;
|
||||
GridAccount _grid;
|
||||
GridAccount* _grid;
|
||||
PiePlot* _pie;
|
||||
};
|
||||
|
||||
|
32
view/GridAccount.h
Normal file
32
view/GridAccount.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef GRIDACCOUNT_H
|
||||
#define GRIDACCOUNT_H
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <wx/grid.h>
|
||||
#include <list>
|
||||
#include "AccountPanel.h"
|
||||
|
||||
class GridAccount : public wxGrid
|
||||
{
|
||||
public:
|
||||
GridAccount(wxWindow *parent, wxWindowID id) : wxGrid(parent, id) {}
|
||||
wxPen GetColGridLinePen (int col) {return wxPen(*wxBLACK, 1, wxSOLID);}
|
||||
wxPen GetRowGridLinePen (int row) {
|
||||
if (row == 0 || row == _fixCosts ||
|
||||
row == (_fixCosts + _week1) ||
|
||||
row == (_fixCosts + _week2) ||
|
||||
row == (_fixCosts + _week3))
|
||||
return wxPen(*wxBLACK, 1, wxSOLID);
|
||||
|
||||
if (row <= _fixCosts)
|
||||
return wxPen(OWN_YELLOW, 1, wxSOLID);
|
||||
|
||||
return wxPen(OWN_GREEN, 1, wxSOLID);
|
||||
}
|
||||
|
||||
int _fixCosts;
|
||||
int _week1, _week2, _week3;
|
||||
private:
|
||||
std::list<int> _col;
|
||||
};
|
||||
#endif
|
Reference in New Issue
Block a user