From 1e79c5114efde835d8f9a7d3860999a40d89beac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 5 Jun 2010 14:33:19 +0200 Subject: [PATCH] wip --- model/Account.cpp | 7 ++++ model/Account.h | 21 +++++++++++ model/Preferences.cpp | 1 + view/AccountPanel.cpp | 36 ++++++++++++++++++ view/CalendarEditor.cpp | 81 +++++++++++++++++++++++++++++++++++++++++ view/CalendarEditor.h | 36 ++++++++++++++++++ 6 files changed, 182 insertions(+) create mode 100755 model/Account.cpp create mode 100755 model/Account.h create mode 100644 model/Preferences.cpp create mode 100644 view/CalendarEditor.cpp create mode 100644 view/CalendarEditor.h diff --git a/model/Account.cpp b/model/Account.cpp new file mode 100755 index 0000000..b235d8d --- /dev/null +++ b/model/Account.cpp @@ -0,0 +1,7 @@ +#include "Account.h" + + +Account::~Account() +{ + +} diff --git a/model/Account.h b/model/Account.h new file mode 100755 index 0000000..149fada --- /dev/null +++ b/model/Account.h @@ -0,0 +1,21 @@ +#ifndef ACCOUNT_H +#define ACCOUNT_H + +#include +#include +#include + +class Account +{ +public: + ~Account(); + + wxString _id; + wxString _name; + wxString _number; + int _amount; + bool _shared; + bool _default; +}; + +#endif diff --git a/model/Preferences.cpp b/model/Preferences.cpp new file mode 100644 index 0000000..6ef05cf --- /dev/null +++ b/model/Preferences.cpp @@ -0,0 +1 @@ +#include "Preferences.h" diff --git a/view/AccountPanel.cpp b/view/AccountPanel.cpp index 216c199..713c85a 100644 --- a/view/AccountPanel.cpp +++ b/view/AccountPanel.cpp @@ -350,6 +350,41 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, VIEW, NUMBER_COLS_OPS SetMinSize(GetSize()); } +void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix) +{ + + _grid->InsertRows(line, 1); + + _grid->SetCellEditor(curLine, DATE, new CalendarEditor(it->day, it->month, it->year)); + _grid->SetCellEditor(curLine, DEBIT, new wxGridCellFloatEditor(-1, 2)); + _grid->SetCellEditor(curLine, CREDIT, new wxGridCellFloatEditor(-1, 2)); + accountEditor = new wxGridCellChoiceEditor(user->_accounts.size()+1, _accounts, false); + + if (fix) + { + _fixCosts++; + SET_ROW_COLOR(curLine, OWN_YELLOW); + _grid->SetCellValue(curLine, CATEGORY, _("Fixe")); + _grid->SetReadOnly(curLine, CATEGORY); + } + else + { + SET_ROW_COLOR(curLine, OWN_GREEN); + } + + if (op) + { + _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("%.2lf"), -it->amount)); + else + _grid->SetCellValue(curLine, CREDIT, wxString::Format(wxT("%.2lf"), it->amount)); + _grid->SetCellEditor(curLine, ACCOUNT, accountEditor); + _grid->SetCellValue(curLine, ACCOUNT, user->GetAccountName(it->account)); + } +} + void AccountPanel::InitAccountsGrid(User* user, int month, int year) { std::map::iterator it; @@ -516,6 +551,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) op_complete--; } + // Penser au fix // Modify a fix operation if (row < _fixCosts) { diff --git a/view/CalendarEditor.cpp b/view/CalendarEditor.cpp new file mode 100644 index 0000000..7b93162 --- /dev/null +++ b/view/CalendarEditor.cpp @@ -0,0 +1,81 @@ +#include "CalendarEditor.h" + +CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(NULL), _calendar(NULL) +{ +} + +CalendarEditor::~CalendarEditor() +{ + if (_calendar) delete _calendar; +} + +void CalendarEditor::BeginEdit(int row, int col, wxGrid *grid) +{ + // wxDateTime date, dateDef; + + // if (!grid->GetCellValue(row, col).Len()) return; + + // if (date.ParseFormat(grid->GetCellValue(row, col), _("%d/%m/%Y"), dateDef)) + // _calendar->SetDate(date); +} + +wxGridCellEditor* CalendarEditor::Clone() const +{ + return new CalendarEditor(_day, _month, _year); +} + +void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler) +{ + _parent = parent; + _calendar = new wxCalendarCtrl(parent, id); + _calendar->EnableHolidayDisplay(false); + _calendar->EnableMonthChange(false); + _calendar->EnableYearChange(false); + _calendar->SetDate(wxDateTime(_day, _month, _year)); + // (void (wxObject::*)(wxEvent&)) + Connect((int)id, (int)wxEVT_CALENDAR_SEL_CHANGED, wxCommandEventHandler(CalendarEditor::OnCalendarChange)); + //evtHandler->Connect((int)id, (int)wxEVT_CALENDAR_DOUBLECLICKED, (void (wxObject::*)(wxEvent&))&CalendarEditor::OnCalendarChange); + //evtHandler->Connect(wxEVT_CALENDAR_DOUBLECLICKED, (void (wxObject::*)(wxEvent&))&CalendarEditor::OnCalendarChange); + //wxGridCellEditor::Create(parent, id, evtHandler); +} + +bool CalendarEditor::EndEdit (int row, int col, wxGrid *grid) +{ + grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year)) ; + + return true; +} + +void CalendarEditor::ApplyEdit (int row, int col, wxGrid *grid) +{ + grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year)) ; +} + +wxString CalendarEditor::GetValue() const +{ + return wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year); +} + +void CalendarEditor::Reset() +{ + _calendar->SetDate(wxDateTime(_day, _month, _year)); +} + +void CalendarEditor::Show (bool show, wxGridCellAttr *attr) +{ + _calendar->Show(show); +} + +void CalendarEditor::SetSize (const wxRect &rect) +{ + wxSize size = _calendar->GetMinSize(); + _calendar->SetSize(wxRect(rect.x, rect.y, size.GetWidth(), size.GetHeight())); +} + +void CalendarEditor::OnCalendarChange(wxCommandEvent& event) +{ + std::cout << "ON CHANGE\n" ; + //wxDateTime date = _calendar->GetDate(); + _day = _calendar->GetDate().GetDay(); + _calendar->Show(false); +} diff --git a/view/CalendarEditor.h b/view/CalendarEditor.h new file mode 100644 index 0000000..6086ebb --- /dev/null +++ b/view/CalendarEditor.h @@ -0,0 +1,36 @@ +#ifndef CALENDAREDITOR_H +#define CALENDAREDITOR_H + +#include +#include +#include +#include +#include + +class CalendarEditor : public wxGridCellEditor, public wxEvtHandler +{ +public: + + CalendarEditor(int day, int month, int year); + ~CalendarEditor(); + + void BeginEdit(int row, int col, wxGrid *grid); + wxGridCellEditor* Clone () const; + void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler); + bool EndEdit(int row, int col, wxGrid *grid); + void ApplyEdit(int row, int col, wxGrid *grid); + wxString GetValue() const; + void Reset(); + void Show(bool show, wxGridCellAttr *attr=NULL); + void SetSize (const wxRect &rect); + void OnCalendarChange(wxCommandEvent& event); + +private: + int _day; + int _month; + int _year; + wxWindow *_parent; + wxCalendarCtrl *_calendar; +}; + +#endif