* Create a grid directory for grid's components

* Fix a bug inside ShowPanels
* Add fast comboboxes editing inside grids
This commit is contained in:
Grégory Soutadé 2010-09-04 11:54:49 +02:00
parent 32d03d70cd
commit b820a3632a
15 changed files with 168 additions and 22 deletions

View File

@ -10,10 +10,12 @@ CXX=g++
SOURCES=$(wildcard src/model/*.cpp)
SOURCES+=$(wildcard src/view/*.cpp)
SOURCES+=$(wildcard src/view/grid/*.cpp)
SOURCES+=$(wildcard src/controller/*.cpp)
SOURCES+=src/main.cpp src/sha1.cpp
HEADERS=$(wildcard src/model/*.h)
HEADERS+=$(wildcard src/view/*.h)
HEADERS+=$(wildcard src/view/grid/*.h)
HEADERS+=$(wildcard src/controller/*.h)
HEADERS+=src/main.h src/sha1.h
OBJS=$(SOURCES:.cpp=.o)
@ -21,9 +23,9 @@ OBJS=$(SOURCES:.cpp=.o)
all: kc
clean:
rm -f *~ src/*~ src/*.o src/model/*.o src/model/*~ src/view/*.o src/view/*~ src/controller/*.o src/controller/*~ kc
rm -f *~ src/*~ src/*.o src/model/*.o src/model/*~ src/view/*.o src/view/grid/*.o src/view/grid/*~ src/view/*~ src/controller/*.o src/controller/*~ kc
%.o : src/model/%.cpp src/view/%.cpp src/controller/%.cpp src/%.cpp
%.o : src/model/%.cpp src/view/%.cpp src/view/grid/%.cpp src/controller/%.cpp src/%.cpp
$(CXX) $(CXXFLAGS) $< -c
kc: $(OBJS)

2
TODO
View File

@ -18,6 +18,7 @@ Documentation (en)
Cool for 0.1:
Database auto saving at startup
Use caches for created panels (avoid destroying/creating panels for nothing)
Add search function to web view
===============================================================
Next version
@ -27,6 +28,7 @@ Formulas
Import/Export module
Undo/redo
Printing (maybe in html)
Refactor web view code
===============================================================
Will not be implemented

View File

@ -27,14 +27,14 @@
#include <wx/chartpanel.h>
#include <wx/scrolwin.h>
#include "CalendarEditor.h"
#include "wxGridCellBitmapRenderer.h"
#include "grid/wxGridCellBitmapRenderer.h"
#include "view.h"
#include <controller/KissCount.h>
#include "wxUI.h"
#include <model/model.h>
#include "GridAccount.h"
#include "grid/GridAccount.h"
#include <wx/category/categorysimpledataset.h>
class wxUI;

View File

@ -23,9 +23,10 @@
#include <wx/wx.h>
#include <wx/grid.h>
#include <list>
#include "AccountPanel.h"
#include <view/AccountPanel.h>
#include <model/model.h>
#include <controller/KissCount.h>
#include "wxGridCellFastBoolEditor.h"
class KissCount;
@ -42,11 +43,14 @@ public:
void SetWeek(int week, int line);
void InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear);
void OnCellLeftClick(wxGridEvent& evt);
int _fixCosts;
int _week1, _week2, _week3, _week4;
private:
KissCount* _kiss;
wxString* _categories, *_accounts;
DECLARE_EVENT_TABLE();
};
#endif

View File

@ -83,7 +83,11 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p
// Account
staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL);
_accountsGrid = new wxGrid(this, ACCOUNTS_GRID_ID);
{
int clicks[] = {ACCOUNT_SHARED, ACCOUNT_DEFAULT, ACCOUNT_DELETE};
_accountsGrid = new wxMyGrid(this, ACCOUNTS_GRID_ID, clicks, 3);
}
InitAccounts(user);
@ -95,7 +99,11 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p
// Categories
staticBoxSizer = new wxStaticBoxSizer (staticCategories, wxVERTICAL);
_categoriesGrid = new wxGrid(this, CATEGORIES_GRID_ID);
{
int clicks[] = {CATEGORY_COLOR, CATEGORY_FONT, CATEGORY_DELETE};
_categoriesGrid = new wxMyGrid(this, CATEGORIES_GRID_ID, clicks, 3);
}
staticBoxSizer->Add(_categoriesGrid);
@ -167,11 +175,11 @@ void PreferencesPanel::InitAccounts(User* user)
_accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number);
_accountsGrid->SetCellRenderer(curLine, ACCOUNT_SHARED, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(curLine, ACCOUNT_SHARED, new wxGridCellBoolEditor ());
_accountsGrid->SetCellEditor(curLine, ACCOUNT_SHARED, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ());
_accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(curLine, ACCOUNT_DELETE, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellBoolEditor ());
_accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellValue(curLine, ACCOUNT_SHARED, (it->shared)?wxT("1"):wxT("0"));
_accountsGrid->SetCellValue(curLine, ACCOUNT_DEFAULT, (it->_default)?wxT("1"):wxT("0"));
@ -217,7 +225,7 @@ void PreferencesPanel::InitCategories(User* user)
if (curLine)
{
_categoriesGrid->SetCellRenderer(curLine, CATEGORY_DELETE, new wxGridCellBoolRenderer ());
_categoriesGrid->SetCellEditor(curLine, CATEGORY_DELETE, new wxGridCellBoolEditor ());
_categoriesGrid->SetCellEditor(curLine, CATEGORY_DELETE, new wxGridCellFastBoolEditor ());
}
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE);
@ -381,11 +389,11 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
}
_accountsGrid->SetCellRenderer(row, ACCOUNT_SHARED, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(row, ACCOUNT_SHARED, new wxGridCellBoolEditor ());
_accountsGrid->SetCellEditor(row, ACCOUNT_SHARED, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(row, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(row, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ());
_accountsGrid->SetCellEditor(row, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellRenderer(row, ACCOUNT_DELETE, new wxGridCellBoolRenderer ());
_accountsGrid->SetCellEditor(row, ACCOUNT_DELETE, new wxGridCellBoolEditor ());
_accountsGrid->SetCellEditor(row, ACCOUNT_DELETE, new wxGridCellFastBoolEditor ());
_accountsGrid->SetCellAlignment(row, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(row, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE);
_accountsGrid->SetCellAlignment(row, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
@ -494,7 +502,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
_categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false);
_categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false);
_categoriesGrid->SetCellRenderer(row, CATEGORY_DELETE, new wxGridCellBoolRenderer ());
_categoriesGrid->SetCellEditor(row, CATEGORY_DELETE, new wxGridCellBoolEditor ());
_categoriesGrid->SetCellEditor(row, CATEGORY_DELETE, new wxGridCellFastBoolEditor ());
_categoriesGrid->SetCellAlignment(row, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE);
_categoriesGrid->SetCellAlignment(row, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE);

View File

@ -25,9 +25,9 @@
#include <wx/treectrl.h>
#include <wx/scrolwin.h>
#include "CalendarEditor.h"
#include "wxGridCellBitmapRenderer.h"
#include "grid/wxGridCellBitmapRenderer.h"
#include "AccountPanel.h"
#include "GridAccount.h"
#include "grid/GridAccount.h"
#include "view.h"
#include <controller/KissCount.h>

View File

@ -24,6 +24,10 @@
SetCellBackgroundColour(row, i, color); \
}
BEGIN_EVENT_TABLE(GridAccount, wxGrid)
EVT_GRID_CELL_LEFT_CLICK(GridAccount::OnCellLeftClick )
END_EVENT_TABLE()
GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxGrid(parent, id),
_fixCosts(0), _week1(0), _week2(0), _week3(0), _week4(0), _kiss(kiss)
{
@ -140,9 +144,9 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
if (!fix)
SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ());
SetCellEditor(line, DELETE, new wxGridCellBoolEditor ());
SetCellEditor(line, DELETE, new wxGridCellFastBoolEditor ());
SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
SetCellEditor(line, CHECKED, new wxGridCellBoolEditor ());
SetCellEditor(line, CHECKED, new wxGridCellFastBoolEditor ());
color = user->GetCategory(op->category).color;
@ -187,3 +191,33 @@ void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix,
Layout();
SetMinSize(GetMinSize());
}
// From http://nomadsync.cvs.sourceforge.net/nomadsync/nomadsync/src/
void GridAccount::OnCellLeftClick(wxGridEvent& evt)
{
if (evt.GetCol() != DELETE && evt.GetCol() != CHECKED) { evt.Skip() ; return;}
// This forces the cell to go into edit mode directly
//m_waitForSlowClick = TRUE;
SetGridCursor(evt.GetRow(), evt.GetCol());
// Store the click co-ordinates in the editor if possible
// if an editor has created a ClientData area, we presume it's
// a wxPoint and we store the click co-ordinates
wxGridCellEditor* pEditor = GetCellEditor(evt.GetRow(), evt.GetCol());
wxPoint* pClickPoint = (wxPoint*)pEditor->GetClientData();
if (pClickPoint)
{
*pClickPoint = ClientToScreen(evt.GetPosition());
#ifndef __WINDOWS__
EnableCellEditControl(true);
#endif
}
// hack to prevent selection from being lost when click combobox
if (evt.GetCol() == 0 && IsInSelection(evt.GetRow(), evt.GetCol()))
{
//m_selTemp = m_selection;
m_selection = NULL;
}
pEditor->DecRef();
evt.Skip();
}

View File

@ -0,0 +1,24 @@
#ifndef WXGRIDCELLFASTBOOLEDITOR_H
#define WXGRIDCELLFASTBOOLEDITOR_H
#include <wx/wx.h>
#include <wx/grid.h>
// From http://wiki.wxwidgets.org/WxGrid
class wxGridCellFastBoolEditor : public wxGridCellBoolEditor
{
public:
void BeginEdit (int row, int col, wxGrid* grid)
{
wxGridCellBoolEditor::BeginEdit(row, col, grid);
wxFocusEvent event (wxEVT_KILL_FOCUS);
if (m_control)
{
m_control->GetEventHandler()->AddPendingEvent(event);
}
}
};
#endif

View File

@ -0,0 +1,48 @@
#include "wxMyGrid.h"
BEGIN_EVENT_TABLE(wxMyGrid, wxGrid)
EVT_GRID_CELL_LEFT_CLICK(wxMyGrid::OnCellLeftClick )
END_EVENT_TABLE()
wxMyGrid::wxMyGrid(wxWindow* parent, int id, int* clicks, int size) : wxGrid(parent, id)
{
for(int i=0; i<size; i++)
_clicks.push_back(clicks[i]);
}
// From http://nomadsync.cvs.sourceforge.net/nomadsync/nomadsync/src/
void wxMyGrid::OnCellLeftClick(wxGridEvent& evt)
{
std::vector<int>::iterator it;
for(it = _clicks.begin(); it != _clicks.end(); it++)
{
if (*it == evt.GetCol())
{
// This forces the cell to go into edit mode directly
//m_waitForSlowClick = TRUE;
SetGridCursor(evt.GetRow(), evt.GetCol());
// Store the click co-ordinates in the editor if possible
// if an editor has created a ClientData area, we presume it's
// a wxPoint and we store the click co-ordinates
wxGridCellEditor* pEditor = GetCellEditor(evt.GetRow(), evt.GetCol());
wxPoint* pClickPoint = (wxPoint*)pEditor->GetClientData();
if (pClickPoint)
{
*pClickPoint = ClientToScreen(evt.GetPosition());
#ifndef __WINDOWS__
EnableCellEditControl(true);
#endif
}
// hack to prevent selection from being lost when click combobox
if (evt.GetCol() == 0 && IsInSelection(evt.GetRow(), evt.GetCol()))
{
//m_selTemp = m_selection;
m_selection = NULL;
}
pEditor->DecRef();
break;
}
}
evt.Skip();
}

22
src/view/grid/wxMyGrid.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef WXMYGRID_H
#define WXMYGRID_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <vector>
// From http://wiki.wxwidgets.org/WxGrid
class wxMyGrid : public wxGrid
{
public:
wxMyGrid(wxWindow* parent, int id, int* clicks, int size);
void OnCellLeftClick(wxGridEvent& ev);
private:
std::vector<int> _clicks;
DECLARE_EVENT_TABLE();
};
#endif

View File

@ -185,10 +185,10 @@ void wxUI::LoadUser()
void wxUI::ShowPanel(wxPanel* panel)
{
int month, year, account=0, preferences=0, search=0, stats=0;
int month, year=-1, account=0, preferences=0, search=0, stats=0;
wxShowEvent event;
if (!panel) return;
if (!panel || panel == _curPanel) return;
if (_curPanel)
{

View File

@ -29,6 +29,8 @@
#include "SearchPanel.h"
#include "StatsPanel.h"
#include <controller/KissCount.h>
#include "grid/wxMyGrid.h"
#include "grid/wxGridCellFastBoolEditor.h"
class KissCount;
class ButtonPanel;

View File

@ -12,7 +12,7 @@ fi
make || (echo "Compilation failed" ; exit 1)
mkdir -p $DIR/lib
cp -r lib/freechart/lib/* lib/wxsqlite3-1.9.9/lib/* $DIR/lib
cp -r kc init.sql ressources tools/launch_kc.sh TODO CONTRIBUTORS COPYING README README.fr $DIR
cp -r kc init.sql ressources tools/launch_kc.sh TODO CONTRIBUTORS COPYING README README.fr www $DIR
find $DIR -type f -executable -exec strip \{\} \;
tar -jcf $FILE $DIR
rm -rf $DIR