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

View File

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