Fix a bug : month & year changed when AccountPanel is re created (wxUI needs update)

This commit is contained in:
Grégory Soutadé 2012-04-01 11:19:27 +02:00
parent 62541cbe2e
commit 9991415e2c
2 changed files with 34 additions and 7 deletions

View File

@ -34,6 +34,16 @@ enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, BALANCE, STATS_ROW, CATS
enum {VIRTUAL_MODE=0, REAL_MODE, CHECK_MODE};
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _curMonth(-1), _curYear(-1), _inModification(false)
{
Init(kiss, parent, 0);
}
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent, int month=-1, int year=-1, int mode=VIRTUAL_MODE) : KissPanel(kiss, parent), _curMonth(month), _curYear(year), _inModification(false)
{
Init(kiss, parent, mode);
}
void AccountPanel::Init(KissCount* kiss, wxUI *parent, int curMode)
{
QHBoxLayout *hbox = new QHBoxLayout;
QHBoxLayout *hbox2 = new QHBoxLayout;
@ -149,7 +159,13 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
_real = new QRadioButton(_("Real"));
_check = new QRadioButton(_("Check"));
_virtual->setChecked(true);
switch(curMode)
{
case VIRTUAL_MODE: _virtual->setChecked(true); break;
case REAL_MODE: _real->setChecked(true); break;
case CHECK_MODE: _check->setChecked(true); break;
default: _virtual->setChecked(true); break;
}
{
QVBoxLayout *vbox = new QVBoxLayout;
@ -212,7 +228,13 @@ AccountPanel::~AccountPanel()
KissPanel* AccountPanel::CreatePanel()
{
return new AccountPanel(_kiss, _wxUI);
int mode;
if (_virtual->isChecked()) mode = VIRTUAL_MODE;
else if (_real->isChecked()) mode = REAL_MODE;
else if (_check->isChecked()) mode = CHECK_MODE;
return new AccountPanel(_kiss, _wxUI, _curMonth, _curYear, mode);
}
QPushButton* AccountPanel::GetButton()
@ -302,7 +324,7 @@ void AccountPanel::InitStatsGrid(User* user)
void AccountPanel::ChangeUser()
{
User* user = _kiss->GetUser();
int curYear = -1;
int curYear = -1, year;
QDate curDate = QDate::currentDate();
QTreeWidgetItem* curNode=NULL, *node;
std::map<int, std::vector<int> > ops;
@ -316,10 +338,11 @@ void AccountPanel::ChangeUser()
if (ops.size())
{
year = (_curYear == -1) ? curDate.year() : _curYear;
for(it = ops.begin(); it != ops.end(); it++)
{
node = new QTreeWidgetItem(QStringList(QString::number(it->first)));
if ((int)it->first <= curDate.year())
if ((int)it->first <= year)
{
curYear = it->first;
curNode = node;
@ -329,7 +352,7 @@ void AccountPanel::ChangeUser()
if (curYear != -1)
{
_tree->setCurrentItem(curNode);
LoadYear(curYear, true);
LoadYear(curYear, true);
}
}
else
@ -343,7 +366,7 @@ void AccountPanel::ChangeUser()
void AccountPanel::LoadYear(int year, bool showMonth)
{
User* user = _kiss->GetUser();
int curMonth = -1;
int curMonth = -1, month;
QTreeWidgetItem* parentNode, *curMonthNode = 0;
std::map<int, std::vector<int> > ops ;
std::vector<int>::iterator it;
@ -365,9 +388,11 @@ void AccountPanel::LoadYear(int year, bool showMonth)
if (!parentNode)
parentNode = _tree->topLevelItem(0);
month = (_curMonth == -1) ? curDate.month()-1 : _curMonth;
for (it = ops[year].begin(); it != ops[year].end(); it++)
{
if (!curMonthNode || (curDate.year() == _curYear && *it <= curDate.month()-1))
if (!curMonthNode || (year == _curYear && *it <= month))
{
curMonth = *it;
curMonthNode = new QTreeWidgetItem(QStringList(wxUI::months[*it]));

View File

@ -40,6 +40,8 @@ class AccountPanel: public KissPanel
public:
AccountPanel(KissCount* kiss, wxUI *parent);
AccountPanel(KissCount* kiss, wxUI *parent, int month, int year, int mode);
void Init(KissCount* kiss, wxUI *parent, int curMode);
~AccountPanel();
KissPanel* CreatePanel();