Add grid editor/renderer for multiple operations

This commit is contained in:
Grégory Soutadé 2010-09-14 21:11:41 +02:00
parent 4a90f93130
commit e7a2b0c988
8 changed files with 259 additions and 20 deletions

View File

@ -277,17 +277,6 @@ void AccountPanel::LoadYear(int year, bool showMonth)
_wxUI->Layout();
}
#define SET_ROW_COLOR(row, backcolor, forecolor) for(int i=0; i<NUMBER_COLS_OPS; i++) \
{ \
_grid->SetCellBackgroundColour(row, i, backcolor); \
_grid->SetCellTextColour(row, i, forecolor); \
}
#define SET_ROW_FONT(row, font) for(int i=0; i<NUMBER_COLS_OPS; i++) \
{ \
_grid->SetCellFont(row, i, font); \
}
void AccountPanel::ShowMonth(int month, int year)
{
std::vector<Operation> operations;

View File

@ -29,11 +29,6 @@ EVT_GRID_CMD_CELL_CHANGE(GRID_ID, SearchPanel::OnOperationModified)
EVT_SHOW(SearchPanel::OnShow)
END_EVENT_TABLE()
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
{ \
_grid->SetCellBackgroundColour(row, i, color); \
}
#define UNESCAPE_CHARS(s) { \
s.Replace(wxT("\\\""), wxT("\""), true); \
s.Replace(wxT("\\\'"), wxT("\'"), true); \

View File

@ -56,11 +56,11 @@ GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxG
SetColLabelSize(0);
SetRowLabelSize(0);
SetColSize (0, GetColSize(0)*3);
SetColSize (DESCRIPTION, GetColSize(DESCRIPTION)*3);
SetDefaultCellFont(font);
font.SetWeight(wxFONTWEIGHT_BOLD);
wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), wxT(""), wxT("")};
wxString colsName[] = {wxT(""), _("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), wxT(""), wxT("")};
for(i=0; i<NUMBER_COLS_OPS; i++)
{
SetCellValue(0, i, colsName[i]);
@ -158,6 +158,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, bool canAdd
if (canAddOperation)
InsertOperation(user, NULL, ++curLine, false, month, year);
AutoSizeColumn(TREE, false);
AutoSizeColumn(CATEGORY, false);
AutoSizeColumn(DATE, false);
AutoSizeColumn(ACCOUNT, false);
@ -223,6 +224,8 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
InsertRows(line, 1);
SetCellRenderer(line, TREE, new wxGridCellTreeButtonRenderer());
SetCellEditor(line, TREE, new wxGridCellTreeButtonEditor());
SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(wxID_ANY, 2));
SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(wxID_ANY, 2));
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false);
@ -315,7 +318,7 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
// From http://nomadsync.cvs.sourceforge.net/nomadsync/nomadsync/src/
void GridAccount::OnCellLeftClick(wxGridEvent& evt)
{
if (evt.GetCol() != DELETE && evt.GetCol() != CHECKED) { evt.Skip() ; return;}
if (evt.GetCol() != TREE && evt.GetCol() != DELETE && evt.GetCol() != CHECKED) { evt.Skip() ; return;}
// This forces the cell to go into edit mode directly
//m_waitForSlowClick = TRUE;

View File

@ -27,10 +27,12 @@
#include <model/model.h>
#include <controller/KissCount.h>
#include "wxGridCellFastBoolEditor.h"
#include "wxGridCellTreeButtonRenderer.h"
#include "wxGridCellTreeButtonEditor.h"
class KissCount;
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, CHECKED, NUMBER_COLS_OPS};
enum {TREE, DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, CHECKED, NUMBER_COLS_OPS};
class GridAccount : public wxGrid
{

View File

@ -0,0 +1,74 @@
/*
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 "wxGridCellTreeButtonEditor.h"
wxGridCellEditor* wxGridCellTreeButtonEditor::Clone () const
{
return new wxGridCellTreeButtonEditor();
}
void wxGridCellTreeButtonEditor::BeginEdit (int row, int col, wxGrid *grid)
{
wxGridEvent evt(0, 0, NULL, row, col);
_row = row;
_col = col;
_grid = grid;
wxGridCellRenderer* pRenderer = _grid->GetCellRenderer(_row, _col);
((wxGridCellTreeButtonRenderer*) pRenderer)->Invert();
pRenderer->DecRef();
((GridAccount*)_grid)->OnCellLeftClick(evt);
}
void wxGridCellTreeButtonEditor::Create (wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
{
}
bool wxGridCellTreeButtonEditor::EndEdit (int row, int col, /*const*/ wxGrid *grid/*, const wxString &oldval, wxString *newval*/)
{
return true;
}
void wxGridCellTreeButtonEditor::ApplyEdit (int row, int col, wxGrid *grid)
{}
void wxGridCellTreeButtonEditor::Reset ()
{}
wxString wxGridCellTreeButtonEditor::GetValue() const
{
wxGridCellRenderer* pRenderer = _grid->GetCellRenderer(_row, _col);
wxString res = ((wxGridCellTreeButtonRenderer*) pRenderer)->IsCollapsed() ? wxT("1") : wxT("0");
pRenderer->DecRef();
return res;
}
void wxGridCellTreeButtonEditor::SetSize (const wxRect &rect)
{
}
void wxGridCellTreeButtonEditor::Show (bool show, wxGridCellAttr *attr=NULL)
{
}

View File

@ -0,0 +1,50 @@
/*
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 WXGRIDCELLTREEBUTTONEDITOR_H
#define WXGRIDCELLTREEBUTTONEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/dc.h>
#include "GridAccount.h"
#include "wxGridCellTreeButtonRenderer.h"
class wxGridCellTreeButtonEditor : public wxGridCellEditor
{
public:
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);
private:
int _row, _col;
wxGrid* _grid;
};
#endif

View File

@ -0,0 +1,85 @@
/*
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 "wxGridCellTreeButtonRenderer.h"
wxGridCellTreeButtonRenderer::wxGridCellTreeButtonRenderer(bool collapsed) : _collapsed(collapsed)
{
}
wxGridCellRenderer* wxGridCellTreeButtonRenderer::Clone () const
{
return new wxGridCellTreeButtonRenderer(_collapsed);
}
bool wxGridCellTreeButtonRenderer::IsCollapsed()
{
return _collapsed;
}
void wxGridCellTreeButtonRenderer::Invert()
{
_collapsed = !_collapsed;
}
void wxGridCellTreeButtonRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &_rect, int row, int col, bool isSelected)
{
wxRect rect = _rect;
wxBrush originalBrush = dc.GetBrush();
wxPen originalPen = dc.GetPen();
dc.SetPen(wxPen(grid.GetCellBackgroundColour(row, col)));
dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col)));
dc.DrawRectangle(rect);
rect.x += 4 ;
rect.y += 4 ;
rect.width -= 8 ;
rect.height -= 8 ;
if (rect.width > rect.height)
rect.width = rect.height;
else if (rect.height > rect.width)
rect.height = rect.width;
dc.SetPen(wxPen(*wxBLACK));
dc.DrawLine(rect.x, rect.y, rect.x + rect.width, rect.y);
dc.DrawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
dc.DrawLine(rect.x, rect.y + rect.height, rect.x + rect.width + 1, rect.y + rect.height);
dc.DrawLine(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height);
rect.x += 2 ;
rect.y += 2 ;
rect.width -= 4 ;
rect.height -= 4 ;
dc.DrawLine(rect.x+1, rect.y + rect.height/2, rect.x + rect.width + 1, rect.y + rect.height/2);
if (!_collapsed)
dc.DrawLine(rect.x + rect.width/2 + 1, rect.y, rect.x + rect.width/2 + 1, rect.y + rect.height);
}
wxSize wxGridCellTreeButtonRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
return wxSize(8, 8);
}

View File

@ -0,0 +1,41 @@
/*
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 WXGRIDCELLTREEBUTTONRENDERER_H
#define WXGRIDCELLTREEBUTTONRENDERER_H
#include <wx/grid.h>
#include <wx/dc.h>
class wxGridCellTreeButtonRenderer : public wxGridCellRenderer
{
public:
wxGridCellTreeButtonRenderer(bool collapsed=false);
virtual wxGridCellRenderer* Clone () const;
virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected);
virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col);
bool IsCollapsed();
void Invert();
private:
bool _collapsed;
};
#endif