From 05b070a5029bedd90d05ac02c178c296bcdf5362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 29 Oct 2017 18:21:54 +0100 Subject: [PATCH] Fix default month selection (sometimes not current month) --- src/view/AccountPanel.cpp | 51 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index f6f82b0..4ddae44 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -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 > ops ; std::vector::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; }