Extract cost repartition from StatsPannel
This commit is contained in:
parent
fb2541358c
commit
eaba622a3f
|
@ -505,7 +505,6 @@ void AccountPanel::UpdateStats()
|
|||
Operation op;
|
||||
bool blocked_account ;
|
||||
QString v;
|
||||
std::vector<Operation> 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);
|
||||
|
|
|
@ -125,7 +125,7 @@ void CostRepartitionBanner::Reset()
|
|||
_statsGrid->resizeColumnToContents(0);
|
||||
}
|
||||
|
||||
void CostRepartitionBanner::UpdateCosts(std::vector<Operation>& operations, int *categoriesValues, int totalDebit)
|
||||
void CostRepartitionBanner::UpdateCosts(int *categoriesValues, int totalDebit)
|
||||
{
|
||||
int i;
|
||||
User* user = _kiss->GetUser();
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
CostRepartitionBanner(KissCount* kiss, QFrame* parent, QString* categories);
|
||||
|
||||
void Reset();
|
||||
void UpdateCosts(std::vector<Operation>& operations, int *categoriesValues, int totalDebit);
|
||||
void UpdateCosts(int *categoriesValues, int totalDebit);
|
||||
|
||||
private:
|
||||
KissCount* _kiss;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include <QMessageBox>
|
||||
#include <KDChartLegend>
|
||||
#include <KDChartPieDiagram>
|
||||
#include <KDChartLineDiagram>
|
||||
#include <KDChartCartesianAxis>
|
||||
|
||||
|
@ -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<Account>::iterator accountIt;
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
std::map<int, std::vector<int> > operations;
|
||||
std::map<int, std::vector<int> >::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; i<user->GetCategoriesNumber(); 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; i<user->GetCategoriesNumber(); 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; i<nbCategories; i++)
|
||||
{
|
||||
_categoriesValues[i] = 0.0;
|
||||
_pie->setDataset(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);
|
||||
_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<Account>::iterator accountIt;
|
||||
std::map<int, int>::iterator categoriesIt;
|
||||
std::map<int, std::map<int, int> >::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);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <QtGui>
|
||||
#include <KDChartWidget>
|
||||
#include "CostRepartitionBanner.hpp"
|
||||
|
||||
#include "view.hpp"
|
||||
#include <model/model.hpp>
|
||||
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue
Block a user