diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index efb2dde..cf6690a 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -505,7 +505,6 @@ void AccountPanel::UpdateStats() Operation op; bool blocked_account ; QString v; - std::vector operations; _inModification = true; @@ -600,7 +599,6 @@ void AccountPanel::UpdateStats() curAccountAmount[op.account] += op.amount; finalAccountAmount[op.account] += op.amount; } - operations.push_back(op); } balance = totalCredit - totalDebit; @@ -646,7 +644,7 @@ void AccountPanel::UpdateStats() } } - _costRepartitionBanner->UpdateCosts(operations, _categoriesValues, totalDebit); + _costRepartitionBanner->UpdateCosts(_categoriesValues, totalDebit); _accountsGrid->resizeColumnToContents(ACCOUNT_INIT); _accountsGrid->resizeColumnToContents(ACCOUNT_CUR); diff --git a/src/view/CostRepartitionBanner.cpp b/src/view/CostRepartitionBanner.cpp index 04da323..1678570 100644 --- a/src/view/CostRepartitionBanner.cpp +++ b/src/view/CostRepartitionBanner.cpp @@ -125,7 +125,7 @@ void CostRepartitionBanner::Reset() _statsGrid->resizeColumnToContents(0); } -void CostRepartitionBanner::UpdateCosts(std::vector& operations, int *categoriesValues, int totalDebit) +void CostRepartitionBanner::UpdateCosts(int *categoriesValues, int totalDebit) { int i; User* user = _kiss->GetUser(); diff --git a/src/view/CostRepartitionBanner.hpp b/src/view/CostRepartitionBanner.hpp index b6ec7ca..dc8738b 100644 --- a/src/view/CostRepartitionBanner.hpp +++ b/src/view/CostRepartitionBanner.hpp @@ -34,7 +34,7 @@ public: CostRepartitionBanner(KissCount* kiss, QFrame* parent, QString* categories); void Reset(); - void UpdateCosts(std::vector& operations, int *categoriesValues, int totalDebit); + void UpdateCosts(int *categoriesValues, int totalDebit); private: KissCount* _kiss; diff --git a/src/view/StatsPanel.cpp b/src/view/StatsPanel.cpp index a9b3dae..874145d 100644 --- a/src/view/StatsPanel.cpp +++ b/src/view/StatsPanel.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -33,13 +32,12 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent, bool lowResolution) : _hbox2 = new QHBoxLayout(); _vbox2 = new QVBoxLayout(); _vbox3 = new QVBoxLayout(); - int i; + int i, nbCategories; User* user = _kiss->GetUser(); std::vector::iterator accountIt; std::vector::iterator categoryIt; std::map > operations; std::map >::iterator it; - int nbCategories; QListWidgetItem* item; _icons[KissPanel::LOW_RES_ICON] = STATS_LOW_ICON; @@ -112,85 +110,23 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent, bool lowResolution) : DEFAULT_FONT(font); - _statsGrid = new QTableWidget(this); - - _statsGrid->setRowCount(user->GetCategoriesNumber()+1); - _statsGrid->setColumnCount(2); - _statsGrid->verticalHeader()->setHidden(true); - _statsGrid->horizontalHeader()->setHidden(true); - - _statsGrid->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - - for(i=0; iGetCategoriesNumber(); i++) - { - if (i) - { - _statsGrid->setItem(i+1, 0, new QTableWidgetItem(_categories[i])); - _statsGrid->item(i+1, 0)->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); - } - else - { - _statsGrid->setItem(i, 0, new QTableWidgetItem(_categories[i])); - _statsGrid->item(i, 0)->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); - } - } - - _statsGrid->setItem(1, 0, new QTableWidgetItem(_("Non fix"))); - _statsGrid->setItem(1, 1, new QTableWidgetItem("")); - _statsGrid->item(1, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + _costRepartitionBanner = new CostRepartitionBanner(_kiss, this, _categories); _vbox3->addWidget(_account); - _vbox3->addWidget(_statsGrid); nbCategories = user->GetCategoriesNumber(); - // nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY; - _categoriesValues = new int[user->GetCategoriesNumber()]; - for(i=0; iGetCategoriesNumber(); i++) - _categoriesValues[i] = 0.0; - - _pie = new KDChart::Widget(); - _pie->setType( KDChart::Widget::Pie); - QPen pen; - pen.setWidth(2); - pen.setColor(Qt::black); - _pie->pieDiagram()->setPen(pen); - - _pie->addLegend(KDChart::Position::South); - KDChart::Legend* legend = _pie->legend(); - legend->setOrientation(Qt::Vertical); - legend->setTitleText(_("Cost repartition")); - QVector< double > vec; - vec << 0.0; _categoriesValues = new int[nbCategories]; for(i=0; isetDataset(i, vec, _categories[i]); - if (i < wxUI::MAX_CATEGORY) - _pie->pieDiagram()->setBrush(i, QBrush(wxUI::categoryColors[i])); - legend->setText(i, _categories[i]); - } - - _pie->setMinimumSize(200, 400); - _pie->setMaximumSize(200, 400); - - KDChart::TextAttributes legendTextAttr(legend->textAttributes()); - legendTextAttr.setFontSize(64); - legendTextAttr.setAutoShrink(true); - legend->setTextAttributes(legendTextAttr); - - legendTextAttr = KDChart::TextAttributes(legend->titleTextAttributes()); - legendTextAttr.setFontSize(64); - legendTextAttr.setAutoShrink(true); - legend->setTitleTextAttributes(legendTextAttr); + _categoriesValues[i] = 0.0; + + _vbox3->addWidget(_costRepartitionBanner); _vbox2->addLayout(hbox); _hbox2->addLayout(_vbox2); vbox->addLayout(_hbox2); _hbox2->addLayout(_vbox3); - _hbox2->addWidget(_pie); OnRangeChange(0); @@ -215,8 +151,8 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT std::vector::iterator accountIt; std::map::iterator categoriesIt; std::map >::iterator accountYearIt; - int total, non_fix; - int account, size, i, a, b, percents, nbDays; + int total; + int account, size, i, a, b, nbDays; QString value, v; User* user = _kiss->GetUser(); QDate date; @@ -363,42 +299,13 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT _vbox2->addWidget(_plot); total = 0.0; - for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++) - total += categoriesIt->second; - for(i=0, categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++, i++) { _categoriesValues[_categoriesIndexes[categoriesIt->first]] = categoriesIt->second; - if (total) - percents = (categoriesIt->second*100)/total; - else - percents = 0; - value = v.sprintf("%0.2lf (%02d%%)", (double) categoriesIt->second/100, percents); - if (i) - { - _statsGrid->setItem(_categoriesIndexes[categoriesIt->first]+1, 1, new QTableWidgetItem(value)); - _statsGrid->item(_categoriesIndexes[categoriesIt->first]+1, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); - } - else - { - _statsGrid->setItem(_categoriesIndexes[categoriesIt->first], 1, new QTableWidgetItem(value)); - _statsGrid->item(_categoriesIndexes[categoriesIt->first], 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); - } - QVector< double > vec; - vec << (double) _categoriesValues[_categoriesIndexes[categoriesIt->first]] / 100; - _pie->setDataset(_categoriesIndexes[categoriesIt->first], vec, _categories[_categoriesIndexes[categoriesIt->first]]); + total += categoriesIt->second; } - non_fix = total - _categoriesValues[0]; - - if (total) - percents = (non_fix*100)/total; - else - percents = 0; - value = v.sprintf("%0.2lf (%02d%%)", (double)non_fix/100, percents); - _statsGrid->setItem(1, 1, new QTableWidgetItem(value)); - - _statsGrid->resizeColumnsToContents(); + _costRepartitionBanner->UpdateCosts(_categoriesValues, total); layout(); } @@ -424,6 +331,7 @@ void StatsPanel::OnRangeChange(int index) return; } + _costRepartitionBanner->Reset(); UpdateStats(monthFrom, yearFrom, monthTo, yearTo); } diff --git a/src/view/StatsPanel.hpp b/src/view/StatsPanel.hpp index ffa418b..67164c4 100644 --- a/src/view/StatsPanel.hpp +++ b/src/view/StatsPanel.hpp @@ -22,6 +22,7 @@ #include #include +#include "CostRepartitionBanner.hpp" #include "view.hpp" #include @@ -44,8 +45,7 @@ private slots: private: QCalendarWidget* _calendarFrom, *_calendarTo; QComboBox* _monthFrom, *_yearFrom, *_monthTo, *_yearTo; - QTableWidget *_statsGrid; - KDChart::Widget* _pie; + CostRepartitionBanner* _costRepartitionBanner; int *_categoriesValues; //CategorySimpleDataset* _dataset; KDChart::Widget *_plot ;