Add cost repartition to SearchPanel
This commit is contained in:
parent
eaba622a3f
commit
d6ef8aebdb
|
@ -105,6 +105,7 @@ void CostRepartitionBanner::Reset()
|
|||
|
||||
_statsGrid->setItem(1, 0, new QTableWidgetItem(_("Non fix")));
|
||||
_statsGrid->setItem(1, 1, new QTableWidgetItem(""));
|
||||
_statsGrid->item(1, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
||||
|
||||
for(i=0; i<nb_categories; i++)
|
||||
{
|
||||
|
|
|
@ -25,6 +25,8 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
|
|||
DEFAULT_FONT(font);
|
||||
std::vector<Account>::iterator accountIt;
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
int i;
|
||||
User* user = _kiss->GetUser();
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
QVBoxLayout *vbox2 = new QVBoxLayout;
|
||||
|
@ -56,12 +58,26 @@ SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
|
|||
connect(_changeCategoryButton, SIGNAL(clicked()), this, SLOT(OnButtonChangeCategory()));
|
||||
connect(_renameButton, SIGNAL(clicked()), this, SLOT(OnButtonRename()));
|
||||
|
||||
_categories = new QString[user->GetCategoriesNumber()] ;
|
||||
_categoriesValues = new int[user->GetCategoriesNumber()] ;
|
||||
for(i=0, categoryIt = user->_categories.begin();
|
||||
categoryIt != user->_categories.end();
|
||||
categoryIt++, i++)
|
||||
{
|
||||
_categoriesIndexes[categoryIt->id] = i;
|
||||
_categories[i] = _(categoryIt->name.toStdString().c_str()) ;
|
||||
}
|
||||
|
||||
_costRepartitionBanner = new CostRepartitionBanner(_kiss, this, _categories);
|
||||
|
||||
vbox2->addWidget(_changeAccountButton);
|
||||
vbox2->addWidget(_changeCategoryButton);
|
||||
vbox2->addWidget(_renameButton);
|
||||
|
||||
hbox->addLayout(vbox2);
|
||||
|
||||
hbox->addWidget(_costRepartitionBanner);
|
||||
|
||||
vbox->addLayout(hbox, 2);
|
||||
}
|
||||
|
||||
|
@ -79,6 +95,40 @@ QString SearchPanel::GetToolTip()
|
|||
return _("Search");
|
||||
}
|
||||
|
||||
void SearchPanel::UpdateCostRepartition()
|
||||
{
|
||||
int i;
|
||||
User* user = _kiss->GetUser();
|
||||
double total=0.0;
|
||||
std::vector<Operation>::iterator it;
|
||||
Account account;
|
||||
Operation op;
|
||||
|
||||
_costRepartitionBanner->Reset();
|
||||
|
||||
for (i=0; i<user->GetCategoriesNumber(); i++)
|
||||
_categoriesValues[i] = 0.0;
|
||||
|
||||
for(it=_operations->begin(); it!=_operations->end(); it++)
|
||||
{
|
||||
if (it->meta) continue;
|
||||
|
||||
op = *it;
|
||||
|
||||
account = user->GetAccount(op.account);
|
||||
|
||||
if (account.blocked && op.transfert && op.amount > 0)
|
||||
op.amount = -op.amount;
|
||||
|
||||
if (op.amount >= 0) continue;
|
||||
|
||||
_categoriesValues[_categoriesIndexes[op.category]] -= op.amount;
|
||||
total -= op.amount;
|
||||
}
|
||||
|
||||
_costRepartitionBanner->UpdateCosts(_categoriesValues, total);
|
||||
}
|
||||
|
||||
void SearchPanel::OnEnter(void* caller)
|
||||
{
|
||||
SearchPanel* _this = (SearchPanel*) caller;
|
||||
|
@ -111,6 +161,8 @@ void SearchPanel::OnButtonSearch()
|
|||
_wxUI->setEnabled(true);
|
||||
_kiss->setOverrideCursor(QCursor(Qt::ArrowCursor));
|
||||
|
||||
UpdateCostRepartition();
|
||||
|
||||
_wxUI->layout();
|
||||
}
|
||||
|
||||
|
@ -148,6 +200,8 @@ void SearchPanel::OnButtonChangeAccount()
|
|||
|
||||
_grid->MassUpdate(rows, true, ChangeAccount, params);
|
||||
|
||||
UpdateCostRepartition();
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
|
@ -196,6 +250,8 @@ void SearchPanel::OnButtonChangeCategory()
|
|||
|
||||
_grid->MassUpdate(rows, true, ChangeCategory, params);
|
||||
|
||||
UpdateCostRepartition();
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
|
@ -222,6 +278,8 @@ void SearchPanel::OnButtonRename()
|
|||
|
||||
_grid->MassUpdate(rows, false, ChangeName, params);
|
||||
|
||||
UpdateCostRepartition();
|
||||
|
||||
_wxUI->NeedReload();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "grid/GridAccount.hpp"
|
||||
#include "AccountPanel.hpp"
|
||||
#include "SearchBanner.hpp"
|
||||
#include "CostRepartitionBanner.hpp"
|
||||
|
||||
#include <model/model.hpp>
|
||||
|
||||
|
@ -53,9 +54,15 @@ private slots:
|
|||
void OnButtonRename();
|
||||
|
||||
private:
|
||||
void UpdateCostRepartition();
|
||||
|
||||
std::vector<Operation> *_operations;
|
||||
SearchBanner* _banner;
|
||||
GridAccount *_grid;
|
||||
CostRepartitionBanner *_costRepartitionBanner;
|
||||
QString* _categories;
|
||||
int *_categoriesValues;
|
||||
std::map<int, int> _categoriesIndexes;
|
||||
QPushButton* _searchButton, *_renameButton, *_changeAccountButton, *_changeCategoryButton;
|
||||
|
||||
static void OnEnter(void* caller);
|
||||
|
|
Loading…
Reference in New Issue
Block a user