Add Generate Dialog & Contextual menu in AccountPanel

Fix a bug in year loading
This commit is contained in:
Grégory Soutadé 2011-10-31 09:14:40 +01:00
parent 4441ea1810
commit c2b6aea35a
2 changed files with 267 additions and 0 deletions

219
src/view/GenerateDialog.cpp Normal file
View File

@ -0,0 +1,219 @@
/*
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/>.
*/
#include "GenerateDialog.hpp"
#include <QLabel>
GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year) : QDialog(0, Qt::Dialog), _kiss(kiss), _wxUI(parent)
{
QGridLayout* gridLayout;
std::map<int, std::vector<int> >::iterator it;
int i, a, toSelect=-1;
QDate curDate = QDate::currentDate();
std::vector<int>::iterator monthIt;
QString s;
// wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
gridLayout = new QGridLayout(this);
setWindowTitle(_("Generate month"));
setModal(true);
gridLayout->addWidget(new QLabel(_("From "), this), 0, 0);
_yearFrom = new QComboBox(this);
gridLayout->addWidget(_yearFrom, 0, 1);
_monthFrom = new QComboBox(this);
gridLayout->addWidget(_monthFrom, 0, 2);
_yearTo = new QComboBox(this);
gridLayout->addWidget(_yearTo, 1, 1);
_monthTo = new QComboBox(this);
gridLayout->addWidget(_monthTo, 1, 2);
QPushButton* ok = new QPushButton(_("OK"), this);
QPushButton* cancel = new QPushButton(_("Cancel"), this);
gridLayout->addWidget(ok, 3, 1);
gridLayout->addWidget(cancel, 3, 2);
connect(ok, SIGNAL(clicked()), this, SLOT(OnOK()));
connect(cancel, SIGNAL(clicked()), this, SLOT(OnCancel()));
connect(_yearTo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnYearToChange(int)));
connect(_yearFrom, SIGNAL(currentIndexChanged(int)), this, SLOT(OnYearFromChange(int)));
_ops = _kiss->GetAllOperations();
_yearFrom->addItem("");
_monthFrom->addItem("");
for(i=1, it = _ops.begin(); it != _ops.end(); it++, i++)
{
_yearFrom->addItem(s.sprintf("%d", it->first));
if (year == it->first)
toSelect = i;
}
if (toSelect != -1)
{
_yearFrom->setCurrentIndex(toSelect);
toSelect=0;
if (month != -1)
{
for(i=0; i<(int)_monthFrom->count(); i++)
{
if (_monthFrom->itemText(i) == wxUI::months[month])
{
toSelect = i;
break;
}
}
}
_monthFrom->setCurrentIndex(toSelect);
}
else
{
_yearFrom->setCurrentIndex(0);
}
for(i=2000; i<=2050; i++)
_yearTo->addItem(s.sprintf("%d", i));
if (year == -1)
{
_yearTo->setCurrentIndex(curDate.year()-2000);
_monthTo->setCurrentIndex(curDate.month());
}
else
{
if (month == 11)
year++;
_yearTo->setCurrentIndex(year-2000);
if (month == -1)
_monthTo->setCurrentIndex(0);
else
{
for(a=0, i=0, monthIt=_ops[year].begin(); monthIt!=_ops[year].end() && i<12; i++)
{
if (i != *monthIt)
{
a++;
continue;
}
if (*monthIt > month)
break;
monthIt++;
}
_monthTo->setCurrentIndex(a);
}
}
}
void GenerateDialog::OnYearFromChange(int index)
{
QString years = _yearFrom->itemText(index);
int year;
std::vector<int>::iterator it;
_monthFrom->clear();
if (!years.length())
{
_monthFrom->addItem("");
return;
}
year = years.toInt();
for(it=_ops[year].begin(); it!=_ops[year].end(); it++)
_monthFrom->addItem(wxUI::months[*it]);
_monthFrom->setCurrentIndex(0);
layout();
}
void GenerateDialog::OnYearToChange(int index)
{
int year, i, ok;
std::vector<int>::iterator it;
_monthTo->clear();
year = _yearTo->currentText().toInt();
for (i=0; i<12; i++)
{
ok = 1;
for(it=_ops[year].begin(); it!=_ops[year].end(); it++)
{
if (*it == i)
{
ok=0; break;
}
}
if (ok)
_monthTo->addItem(wxUI::months[i]);
}
_monthTo->setCurrentIndex(0);
layout();
}
void GenerateDialog::OnOK()
{
int monthFrom, yearFrom, monthTo, yearTo, i;
if (!_yearFrom->itemText(_yearFrom->currentIndex()).length())
{
monthFrom = -1;
yearFrom = -1;
}
else
{
for (i=0; i<12; i++)
{
if (wxUI::months[i] == _monthFrom->itemText(_monthFrom->currentIndex()))
{
monthFrom = i;
break;
}
}
yearFrom = _yearFrom->itemText(_yearFrom->currentIndex()).toInt();
}
for (i=0; i<12; i++)
{
if (wxUI::months[i] == _monthTo->itemText(_monthTo->currentIndex()))
{
monthTo = i;
break;
}
}
yearTo = _yearTo->itemText(_yearTo->currentIndex()).toInt();
close();
_kiss->GenerateMonth(monthFrom, yearFrom, monthTo, yearTo);
}
void GenerateDialog::OnCancel()
{
close();
}

View File

@ -0,0 +1,48 @@
/*
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 GENERATEDIALOG_H
#define GENERATEDIALOG_H
#include <QDialog>
#include <QComboBox>
#include <QLineEdit>
#include "wxUI.hpp"
class GenerateDialog : public QDialog
{
Q_OBJECT;
public:
GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year);
private slots:
void OnYearFromChange(int index);
void OnYearToChange(int index);
void OnOK();
void OnCancel();
private:
KissCount* _kiss;
wxUI* _wxUI;
QComboBox* _yearFrom, *_monthFrom, *_yearTo, *_monthTo;
std::map<int, std::vector<int> > _ops;
};
#endif