Enable panels mechanism

This commit is contained in:
Grégory Soutadé 2011-09-04 19:25:53 +02:00
parent f6e0f92ad7
commit 633bd15fdd
4 changed files with 1296 additions and 82 deletions

1112
src/view/AccountPanel.cpp Normal file

File diff suppressed because it is too large Load Diff

93
src/view/AccountPanel.hpp Normal file
View File

@ -0,0 +1,93 @@
/*
Copyright 2010-2011 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 ACCOUNTPANEL_H
#define ACCOUNTPANEL_H
// #include <wx/wx.h>
// #include <wx/grid.h>
// #include <wx/treectrl.h>
// #include <wx/pie/pieplot.h>
// #include <wx/chartpanel.h>
// #include <wx/radiobox.h>
#include "view.hpp"
#include <model/model.hpp>
// #include "grid/GridAccount.hpp"
// #include "grid/CalendarEditor.hpp"
// #include <wx/category/categorysimpledataset.h>
class GridAccount;
class AccountPanel: public KissPanel
{
Q_OBJECT;
public:
AccountPanel(KissCount* kiss, wxUI *parent);
~AccountPanel();
KissPanel* CreatePanel();
QPushButton* GetButton();
QString GetToolTip();
void OnShow();
void ChangeUser();
void LoadYear(int year, bool showMonth=true);
void ShowMonth(int month, int year);
void GenerateMonth(int month, int year);
void OnOperationModified();
void OnAccountModified();
void OnTreeRightClick();
void OnTreeChange();
void OnMenuGenerate();
void OnMenuDelete();
void OnCalendarChange();
void OnModeChange();
void OnGroup();
void OnUnGroup();
void OnUpdateNextMonths();
int _curMonth, _curYear;
private:
// wxTreeCtrl _tree;
// wxCalendarCtrl* _calendar;
// GridAccount* _grid;
// wxGrid *_statsGrid, *_accountsGrid;
// PiePlot* _pie;
double *_categoriesValues;
// wxRadioBox *_radioMode;
std::map<QString, int> _categoriesIndexes;
std::vector<Operation>* _curOperations;
QString* _categories, *_accounts;
std::map<QString, double> _accountsInitValues;
// CategorySimpleDataset* _dataset;
int _fixCosts;
void InitStatsGrid(User* user);
void InitAccountsGrid(User* user, int month, int year);
void UpdateStats();
void InsertOperation(User* user, Operation* op, int line, bool fix);
void GetTreeSelection(int* month, int* year);
};
#endif

View File

@ -19,8 +19,8 @@
#include <QMessageBox> #include <QMessageBox>
/*#include "AccountPanel.hpp" #include "AccountPanel.hpp"
#include "PreferencesPanel.hpp" /*#include "PreferencesPanel.hpp"
#include "UsersDialog.hpp" #include "UsersDialog.hpp"
#include "GenerateDialog.hpp" #include "GenerateDialog.hpp"
#include "SearchPanel.hpp" #include "SearchPanel.hpp"
@ -53,13 +53,15 @@ QColor wxUI::categoryColors[MAX_CATEGORY] = {QColor(0x00, 0x45, 0x86),
QColor(0x00, 0x84, 0xD1)}; QColor(0x00, 0x84, 0xD1)};
wxUI::wxUI(KissCount* kiss, const QString& title) wxUI::wxUI(KissCount* kiss, const QString& title)
: QFrame(0), _kiss(kiss), : QFrame(0), _kiss(kiss), _signalMapper(this),
_curPanel(0), _locale(0), _needReload(false) _curPanel(0), _locale(0), _needReload(false)
{ {
QPushButton* button; QPushButton* button;
setWindowTitle(title); setWindowTitle(title);
connect(&_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnButtonClicked(int)));
_vbox = new QVBoxLayout; _vbox = new QVBoxLayout;
_buttonsBox = new QHBoxLayout; _buttonsBox = new QHBoxLayout;
@ -87,10 +89,10 @@ wxUI::wxUI(KissCount* kiss, const QString& title)
wxUI::~wxUI() wxUI::~wxUI()
{ {
//int i; int i;
// for (i=0; i<(int)_panels.size(); i++) for (i=0; i<(int)_panels.size(); i++)
// Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this); _buttons[i]->disconnect(&_signalMapper, SLOT(map()));
if (_locale) delete _locale; if (_locale) delete _locale;
} }
@ -148,22 +150,25 @@ bool wxUI::SetLanguage(QString language)
return res; return res;
} }
#define ADD_PANEL(panelName, id) \ #define ADD_PANEL(panelName) \
panel = new panelName(_kiss, this); \ panel = new panelName(_kiss, this); \
button = panel->GetButton(id); \ button = panel->GetButton(); \
button->SetToolTip(panel->GetToolTip()); \ button->setToolTip(panel->GetToolTip()); \
_buttonsBox->Insert(id, button); \ _buttonsBox->insertWidget(id, button); \
_buttons.insert(_buttons.begin()+id, button); \ _buttons.insert(_buttons.begin()+id, button); \
_panels.push_back(panel); \ _panels.push_back(panel); \
Connect(id, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), panel, this); _signalMapper.setMapping(button, id); \
connect(button, SIGNAL(clicked()), &_signalMapper, SLOT(map())); \
id++;
void wxUI::InitPanels() void wxUI::InitPanels()
{ {
// KissPanel* panel; KissPanel* panel;
// wxBitmapButton* button; QPushButton* button;
// _panels.clear(); _panels.clear();
int id=0;
// ADD_PANEL(AccountPanel, 0); ADD_PANEL(AccountPanel);
// ADD_PANEL(StatsPanel, 1); // ADD_PANEL(StatsPanel, 1);
// ADD_PANEL(SearchPanel, 2); // ADD_PANEL(SearchPanel, 2);
// ADD_PANEL(PreferencesPanel, 3); // ADD_PANEL(PreferencesPanel, 3);
@ -173,29 +178,29 @@ void wxUI::InitPanels()
void wxUI::LoadPanels() void wxUI::LoadPanels()
{ {
// std::vector<KissPanel*>::iterator it; std::vector<KissPanel*>::iterator it;
// KissPanel* temp; KissPanel* temp;
// int i; int i;
// if (_curPanel) if (_curPanel)
// { {
// _vbox->Detach(_curPanel); _vbox->removeWidget(_curPanel);
// _curPanel = 0; _curPanel = 0;
// } }
// if (_panels.size()) if (_panels.size())
// { {
// for (i=0; i<(int)_panels.size(); i++) for (i=0; i<(int)_panels.size(); i++)
// { {
// temp = _panels[i]->CreatePanel(); temp = _panels[i]->CreatePanel();
// Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this); _buttons[i]->disconnect(&_signalMapper, SLOT(map()));
// _panels[i] = temp; _panels[i] = temp;
// Connect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), temp, this); connect(_buttons[i], SIGNAL(clicked()), &_signalMapper, SLOT(map()));
// _buttons[i]->SetToolTip(temp->GetToolTip()); _buttons[i]->setToolTip(temp->GetToolTip());
// } }
// } }
// else else
// InitPanels(); InitPanels();
} }
void wxUI::LoadUser() void wxUI::LoadUser()
@ -213,39 +218,38 @@ void wxUI::LoadUser()
void wxUI::ShowPanel(KissPanel* panel) void wxUI::ShowPanel(KissPanel* panel)
{ {
// wxShowEvent event; int i;
// int i; User* user = _kiss->GetUser();
// User* user = _kiss->GetUser();
// if (!panel) return; if (!panel) return;
// if (_curPanel) if (_curPanel)
// { {
// _vbox->Detach(_curPanel); _vbox->removeWidget(_curPanel);
// _curPanel->Hide(); _curPanel->hide();
// } }
// if (_needReload) if (_needReload)
// { {
// user->InvalidateOperations(); user->InvalidateOperations();
// for(i=0; i<(int)_panels.size(); i++) for(i=0; i<(int)_panels.size(); i++)
// if (_panels[i] == panel) break; if (_panels[i] == panel) break;
// LoadPanels(); LoadPanels();
// _needReload = false; _needReload = false;
// _curPanel = _panels[i]; _curPanel = _panels[i];
// } }
// else else
// _curPanel = panel; _curPanel = panel;
// _curPanel->OnShow(event); _curPanel->OnShow();
// _vbox->Add(_curPanel); _vbox->addWidget(_curPanel);
// _curPanel->Show(); _curPanel->show();
// Layout(); layout();
} }
void wxUI::OnButtonClicked() void wxUI::OnButtonClicked(int id)
{ {
// ShowPanel(_panels[event.GetId()]); ShowPanel(_panels[id]);
} }
void wxUI::OnButtonChangeUser() void wxUI::OnButtonChangeUser()
@ -272,27 +276,30 @@ void wxUI::OnButtonQuit()
void wxUI::GenerateMonth(int month, int year) void wxUI::GenerateMonth(int month, int year)
{ {
// ((AccountPanel*)_panels[0])->GenerateMonth(month, year); (dynamic_cast<AccountPanel*>(_panels[0]))->GenerateMonth(month, year);
} }
void wxUI::KillMe() void wxUI::KillMe()
{ {
// std::vector<KissPanel*>::iterator it; std::vector<KissPanel*>::iterator it;
// if (_curPanel) if (_curPanel)
// { {
// _vbox->Detach(_curPanel); _vbox->removeWidget(_curPanel);
// _curPanel = 0; _curPanel = 0;
// } }
// for (it=_panels.begin(); it!= _panels.end(); it++) for (it=_panels.begin(); it!= _panels.end(); it++)
// { {
// if (*it) delete *it; if (*it)
// _buttonsBox->Remove(0); {
// _buttons.erase(_buttons.begin()); _buttonsBox->removeWidget(*it);
// } delete *it;
}
_buttons.erase(_buttons.begin());
}
// _panels.clear(); _panels.clear();
} }
void wxUI::NeedReload() void wxUI::NeedReload()

View File

@ -28,6 +28,7 @@ class ImportEngine;
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QScrollArea> #include <QScrollArea>
#include <QPushButton> #include <QPushButton>
#include <QSignalMapper>
#include <controller/KissCount.hpp> #include <controller/KissCount.hpp>
@ -71,13 +72,14 @@ public:
int _language; int _language;
private slots: private slots:
void OnButtonClicked(); void OnButtonClicked(int id);
void OnButtonChangeUser(); void OnButtonChangeUser();
void OnButtonAbout(); void OnButtonAbout();
void OnButtonQuit(); void OnButtonQuit();
private: private:
KissCount *_kiss; KissCount *_kiss;
QSignalMapper _signalMapper;
QVBoxLayout *_vbox; QVBoxLayout *_vbox;
QHBoxLayout *_buttonsBox; QHBoxLayout *_buttonsBox;
KissPanel *_curPanel; KissPanel *_curPanel;
@ -100,9 +102,9 @@ public:
_KissButton(0) _KissButton(0)
{hide();} {hide();}
virtual void OnShow(QShowEvent * event)=0; virtual void OnShow()=0;
virtual KissPanel* CreatePanel()=0; virtual KissPanel* CreatePanel()=0;
virtual QPushButton* GetButton(int id) {return 0;} virtual QPushButton* GetButton() {return 0;}
virtual QString GetToolTip() {return "";} virtual QString GetToolTip() {return "";}
protected: protected: