Fix default month selection (sometimes not current month)

This commit is contained in:
Grégory Soutadé 2017-10-29 18:21:54 +01:00 committed by Grégory Soutadé
parent b1ce5fc2a2
commit 05b070a502
1 changed files with 29 additions and 22 deletions

View File

@ -331,8 +331,8 @@ void AccountPanel::ChangeUser()
void AccountPanel::LoadYear(int year, bool showMonth)
{
User* user = _kiss->GetUser();
int curMonth = -1, month;
QTreeWidgetItem* parentNode, *curMonthNode = 0;
int lastMonth = -1, month;
QTreeWidgetItem* parentNode, *curMonthNode = 0, *lastMonthNode = 0;
std::map<int, std::vector<int> > ops ;
std::vector<int>::iterator it;
QDate curDate = QDate::currentDate();
@ -344,6 +344,7 @@ void AccountPanel::LoadYear(int year, bool showMonth)
return;
}
_inModification = true;
_curYear = year ;
_kiss->LoadYear(year);
ops = _kiss->GetAllOperations();
@ -353,35 +354,38 @@ void AccountPanel::LoadYear(int year, bool showMonth)
if (!parentNode)
parentNode = _tree->topLevelItem(0);
if (_curMonth == -1)
{
if (_curYear == curDate.year())
month = curDate.month()-1;
else
month = 0;
}
if (_curYear == curDate.year())
month = curDate.month()-1;
else
month = 0;
for (it = ops[year].begin(); it != ops[year].end(); it++)
{
if (!curMonthNode || (year == _curYear && *it <= month))
{
curMonth = *it;
curMonthNode = new QTreeWidgetItem(QStringList(wxUI::months[*it]));
parentNode->addChild(curMonthNode);
}
else
parentNode->addChild(new QTreeWidgetItem(QStringList(wxUI::months[*it])));
lastMonthNode = new QTreeWidgetItem(QStringList(wxUI::months[*it]));
if (year == _curYear && *it == month)
curMonthNode = lastMonthNode;
lastMonth = *it;
parentNode->addChild(lastMonthNode);
}
_tree->expandItem(parentNode);
layout();
if (showMonth)
{
_tree->setCurrentItem(curMonthNode);
ShowMonth(curMonth, year);
if (curMonthNode)
{
_tree->setCurrentItem(curMonthNode);
ShowMonth(month, year);
}
else
{
_tree->setCurrentItem(lastMonthNode);
ShowMonth(lastMonth, year);
}
}
_wxUI->layout();
_inModification = false;
}
void AccountPanel::ShowMonth(int month, int year)
@ -551,7 +555,7 @@ void AccountPanel::UpdateStats()
QTextCharFormat textFormat;
QBrush brush;
int minStartAccount = 0;
_inModification = true;
if (_virtual->isChecked()) mode = VIRTUAL_MODE;
@ -775,8 +779,6 @@ void AccountPanel::UpdateStats()
void AccountPanel::OnOperationModified()
{
UpdateStats();
layout();
}
void AccountPanel::OnAccountModified(int row, int column)
@ -792,6 +794,7 @@ void AccountPanel::OnAccountModified(int row, int column)
_accountsInitValues[id] = amount;
UpdateStats();
_wxUI->NeedReload();
}
void AccountPanel::OnTreeRightClick(const QPoint & pos)
@ -812,6 +815,8 @@ void AccountPanel::OnTreeChange (QTreeWidgetItem * item, int column)
int i;
QString monthString;
if (_inModification) return;
item = _tree->currentItem ();
if (!item) return;
@ -924,6 +929,7 @@ void AccountPanel::OnMenuGenerate()
g.setModal(true);
g.exec();
_wxUI->setEnabled(true);
_wxUI->NeedReload();
}
void AccountPanel::OnMenuDelete()
@ -1140,6 +1146,7 @@ void AccountPanel::OnUpdateNextMonths()
else
QMessageBox::information(0, "KissCount", _("Any account updated !"));
_wxUI->NeedReload();
delete[] cur_amounts;
}