PreferencesPanel started

This commit is contained in:
Grégory Soutadé 2010-05-17 18:03:21 +02:00
parent 47bd0da612
commit 22cef5fe16
10 changed files with 191 additions and 15 deletions

View File

@ -21,7 +21,7 @@ OBJS=$(SOURCES:.cpp=.o)
all: kc
clean:
rm -f *.o
rm -f *.o model/*.o view/*.o controller/*.o kc
%.o : model/%.cpp view/%.cpp controller/%.cpp %.cpp
$(CXX) $(CXXFLAGS) $< -c

3
TODO Normal file
View File

@ -0,0 +1,3 @@
Fusion operation
Séparer
Détail

View File

@ -46,7 +46,7 @@ void KissCount::LoadUser(wxString user)
_wxUI->LoadUser();
}
void KissCount::LoadYear(int year, bool force=false)
void KissCount::LoadYear(int year, bool force)
{
if (!force && _user->_operations[year] != NULL) return;

View File

@ -1,5 +1,5 @@
CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255));
CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), amount INTEGER, shared CHAR(1), default_account CHAR(1));
CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared CHAR(1), default_account CHAR(1));
CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount INTEGER);
CREATE TABLE operation(id INTEGER PRIMARY KEY, user REFERENCES user(id), account REFERENCES account(id), year INTEGER, month INTEGER, day INTEGER, amount INTEGER, description VARCHAR(255), category REFERENCES preference(id), fix_cost CHAR(1));
CREATE TABLE preference(id INTEGER PRIMARY KEY, user REFERENCES user(id), type VARCHAR(255), name VARCHAR(255), value VARCHAR(255));
@ -11,7 +11,7 @@ INSERT INTO default_preference ("type", "value") VALUES ("category", "Frais de f
INSERT INTO default_preference ("type", "value") VALUES ("category", "Exceptionnel");
-- No password
INSERT INTO user ("id", "name", "password") VALUES ("0", "Greg", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
INSERT INTO account ("id", "user", "name", "number", "amount", "shared", "default_account") VALUES ("0", "0", "Compte courant", "000", "1234", "0", "1");
INSERT INTO account ("id", "user", "name", "number", "shared", "default_account") VALUES ("0", "0", "Compte courant", "000" , "0", "1");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("0", "0", "0", "2010", "0", "0", "1234", "Opé 1", "0", "1");
INSERT INTO operation ("id", "user", "account", "year", "month", "day", "amount", "description", "category", "fix_cost") VALUES ("1", "0", "0", "2010", "0", "1", "5678", "Opé 2", "1", "0");
INSERT INTO preference ("type", "value") VALUES ("category", "Fixe");

View File

@ -3,7 +3,9 @@
enum {ID_BUTTON_ACCOUNT=1, ID_BUTTON_STATS, ID_BUTTON_PREFS, ID_BUTTON_CHANGE_USER};
BEGIN_EVENT_TABLE(ButtonPanel, wxPanel)
EVT_BUTTON(ID_BUTTON_CHANGE_USER, ButtonPanel::OnChangeUser)
EVT_BUTTON(ID_BUTTON_ACCOUNT, ButtonPanel::OnButtonAccount)
EVT_BUTTON(ID_BUTTON_PREFS, ButtonPanel::OnButtonPreferences)
EVT_BUTTON(ID_BUTTON_CHANGE_USER, ButtonPanel::OnButtonChangeUser)
END_EVENT_TABLE()
ButtonPanel::ButtonPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent)
@ -33,7 +35,17 @@ ButtonPanel::~ButtonPanel()
delete _changeUser;
}
void ButtonPanel::OnChangeUser(wxCommandEvent& event)
void ButtonPanel::OnButtonAccount(wxCommandEvent& event)
{
_wxUI->ShowAccount();
}
void ButtonPanel::OnButtonPreferences(wxCommandEvent& event)
{
_wxUI->ShowPreferences();
}
void ButtonPanel::OnButtonChangeUser(wxCommandEvent& event)
{
_wxUI->ChangeUser();
}

View File

@ -22,7 +22,9 @@ public:
ButtonPanel(KissCount* kiss, wxUI *parent);
~ButtonPanel();
void OnChangeUser(wxCommandEvent& event);
void OnButtonAccount(wxCommandEvent& event);
void OnButtonPreferences(wxCommandEvent& event);
void OnButtonChangeUser(wxCommandEvent& event);
private:
KissCount* _kiss;

79
view/PreferencesPanel.cpp Normal file
View File

@ -0,0 +1,79 @@
#include "PreferencesPanel.h"
PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent)
{
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
//wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxStaticBox* staticUser, *staticAccount, *staticCategories;
User* user = _kiss->GetUser();
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
wxButton* buttonChangeName, *buttonChangePassword;
wxStaticBoxSizer * staticBoxSizer;
wxTextCtrl* name;
SetSizer(vbox);
staticUser = new wxStaticBox(this, -1, _("User"));
staticAccount = new wxStaticBox(this, -1, _("Accounts"));
staticCategories = new wxStaticBox(this, -1, _("Categories"));
// User
staticBoxSizer = new wxStaticBoxSizer (staticUser, wxVERTICAL);
gridBagSizer = new wxGridBagSizer(10, 10);
staticBoxSizer->Add(gridBagSizer);
label = new wxStaticText(this, -1, _("Name"));
gridBagSizer->Add(label, wxGBPosition(0, 0));
name = new wxTextCtrl(this, -1, user->_name);
gridBagSizer->Add(name, wxGBPosition(0, 1));
buttonChangeName = new wxButton(this, -1, _("Change Name"));
buttonChangePassword = new wxButton(this, -1, _("Change Password"));
gridBagSizer->Add(buttonChangeName, wxGBPosition(1, 0));
gridBagSizer->Add(buttonChangePassword, wxGBPosition(1, 1));
vbox->Add(staticBoxSizer);
vbox->Add(-1, 20);
// Account
staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL);
_accountGrid = new wxGrid(this, -1);
LoadAccounts(user);
staticBoxSizer->Add(_accountGrid);
vbox->Add(staticBoxSizer);
vbox->Add(-1, 20);
// Categories
staticBoxSizer = new wxStaticBoxSizer (staticCategories, wxVERTICAL);
_categoriesGrid = new wxGrid(this, -1);
staticBoxSizer->Add(_categoriesGrid);
vbox->Add(staticBoxSizer);
Fit();
SetMinSize(GetSize());
Hide();
}
void PreferencesPanel::LoadAccounts(User* user)
{
_accountGrid->CreateGrid(0, 5);
_accountGrid->SetRowLabelSize(0);
_accountGrid->SetColLabelValue(0, _("Name"));
_accountGrid->SetColLabelValue(1, _("Number"));
_accountGrid->SetColLabelValue(2, _("Shared"));
_accountGrid->SetColLabelValue(3, _("Default"));
_accountGrid->SetColLabelValue(4, _(""));
}

34
view/PreferencesPanel.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef PREFERENCESPANEL_H
#define PREFERENCESPANEL_H
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/treectrl.h>
#include <wx/statbox.h>
#include <wx/gbsizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <controller/KissCount.h>
#include "wxUI.h"
#include <model/model.h>
class wxUI;
class KissCount;
class PreferencesPanel: public wxPanel
{
public:
PreferencesPanel(KissCount* kiss, wxUI *parent);
void ChangeUser();
private:
KissCount* _kiss;
wxUI* _wxUI;
wxGrid* _accountGrid;
wxGrid* _categoriesGrid;
void LoadAccounts(User* user);
};
#endif

View File

@ -8,7 +8,7 @@ END_EVENT_TABLE()
wxString months[12] = {_("january"), _("february"), _("march"), _("april"), _("may"), _("june"), _("july"), _("august"), _("september"), _("october"), _("november"), _("december")} ;
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss)
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL)
{
_hbox = new wxBoxSizer(wxVERTICAL);
ButtonPanel* buttons = new ButtonPanel(_kiss, this);
@ -34,6 +34,7 @@ wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxS
wxUI::~wxUI()
{
if (_accountPanel) delete _accountPanel;
if (_preferencesPanel) delete _preferencesPanel;
}
void wxUI::OnQuit(wxCommandEvent& WXUNUSED(event))
@ -48,6 +49,17 @@ void wxUI::OnAbout(wxCommandEvent& WXUNUSED(event))
wxOK | wxICON_INFORMATION, this );
}
void wxUI::ShowAccount()
{
ShowPanel(_accountPanel);
}
void wxUI::ShowPreferences()
{
ShowPanel(_preferencesPanel);
}
void wxUI::ChangeUser()
{
UsersDialog u(_kiss, this);
@ -56,12 +68,36 @@ void wxUI::ChangeUser()
void wxUI::LoadUser()
{
if (_accountPanel)
if (_curPanel)
{
_hbox->Detach(_accountPanel);
delete _accountPanel;
_hbox->Detach(_curPanel);
_curPanel = NULL;
}
if (_accountPanel)
delete _accountPanel;
if (_preferencesPanel)
delete _preferencesPanel;
_accountPanel = new AccountPanel(_kiss, this);
_hbox->Add(_accountPanel);
_preferencesPanel = new PreferencesPanel(_kiss, this);
ShowPanel(_accountPanel);
}
void wxUI::ShowPanel(wxPanel* panel)
{
if (!panel) return;
if (_curPanel)
{
_hbox->Detach(_curPanel);
_curPanel->Hide();
}
_curPanel = panel;
_hbox->Add(panel);
_curPanel->Show();
Layout();
}

View File

@ -4,11 +4,13 @@
#include <wx/wx.h>
#include "AccountPanel.h"
#include "ButtonPanel.h"
#include "PreferencesPanel.h"
#include "UsersDialog.h"
#include <controller/KissCount.h>
class KissCount;
class AccountPanel;
class PreferencesPanel;
extern wxString months[12];
@ -25,12 +27,20 @@ public:
void ChangeUser();
void LoadUser();
DECLARE_EVENT_TABLE();
void ShowAccount();
void ShowPreferences();
private:
KissCount *_kiss;
wxBoxSizer *_hbox;
AccountPanel *_accountPanel;
KissCount *_kiss;
PreferencesPanel *_preferencesPanel;
wxPanel *_curPanel;
void ShowPanel(wxPanel* panel);
DECLARE_EVENT_TABLE();
};
enum