KissCount

KissCount Commit Details

Date:2013-02-26 15:34:52 (7 years 4 months ago)
Author:Grégory Soutadé
Branch:dev, master, qt5
Commit:eaba622a3fd7199f73e21c22daaafb2d6877b4b1
Parents: fb2541358c7fc3fa60ef7bb6f49d4ebef449eb70
Message:Extract cost repartition from StatsPannel

Changes:
Msrc/view/AccountPanel.cpp (3 diffs)
Msrc/view/CostRepartitionBanner.cpp (1 diff)
Msrc/view/CostRepartitionBanner.hpp (1 diff)
Msrc/view/StatsPanel.cpp (6 diffs)
Msrc/view/StatsPanel.hpp (2 diffs)

File differences

src/view/AccountPanel.cpp
505505
506506
507507
508
509508
510509
511510
......
600599
601600
602601
603
604602
605603
606604
......
646644
647645
648646
649
647
650648
651649
652650
Operation op;
bool blocked_account ;
QString v;
std::vector<Operation> operations;
_inModification = true;
curAccountAmount[op.account] += op.amount;
finalAccountAmount[op.account] += op.amount;
}
operations.push_back(op);
}
balance = totalCredit - totalDebit;
}
}
_costRepartitionBanner->UpdateCosts(operations, _categoriesValues, totalDebit);
_costRepartitionBanner->UpdateCosts(_categoriesValues, totalDebit);
_accountsGrid->resizeColumnToContents(ACCOUNT_INIT);
_accountsGrid->resizeColumnToContents(ACCOUNT_CUR);
src/view/CostRepartitionBanner.cpp
125125
126126
127127
128
128
129129
130130
131131
_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();
src/view/CostRepartitionBanner.hpp
3434
3535
3636
37
37
3838
3939
4040
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;
src/view/StatsPanel.cpp
1919
2020
2121
22
2322
2423
2524
......
3332
3433
3534
36
35
3736
3837
3938
4039
4140
42
4341
4442
4543
......
112110
113111
114112
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
113
141114
142115
143
144116
145117
146
147118
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165119
166120
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
121
122
123
187124
188125
189126
190127
191128
192129
193
194130
195131
196132
......
215151
216152
217153
218
219
154
155
220156
221157
222158
......
363299
364300
365301
366
367
368
369302
370303
371304
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
305
390306
391307
392
393
394
395
396
397
398
399
400
401
308
402309
403310
404311
......
424331
425332
426333
334
427335
428336
429337
#include <QMessageBox>
#include <KDChartLegend>
#include <KDChartPieDiagram>
#include <KDChartLineDiagram>
#include <KDChartCartesianAxis>
_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;
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);
_categoriesValues[i] = 0.0;
_vbox3->addWidget(_costRepartitionBanner);
_vbox2->addLayout(hbox);
_hbox2->addLayout(_vbox2);
vbox->addLayout(_hbox2);
_hbox2->addLayout(_vbox3);
_hbox2->addWidget(_pie);
OnRangeChange(0);
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;
_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();
}
return;
}
_costRepartitionBanner->Reset();
UpdateStats(monthFrom, yearFrom, monthTo, yearTo);
}
src/view/StatsPanel.hpp
2222
2323
2424
25
2526
2627
2728
......
4445
4546
4647
47
48
48
4949
5050
5151
#include <QtGui>
#include <KDChartWidget>
#include "CostRepartitionBanner.hpp"
#include "view.hpp"
#include <model/model.hpp>
private:
QCalendarWidget* _calendarFrom, *_calendarTo;
QComboBox* _monthFrom, *_yearFrom, *_monthTo, *_yearTo;
QTableWidget *_statsGrid;
KDChart::Widget* _pie;
CostRepartitionBanner* _costRepartitionBanner;
int *_categoriesValues;
//CategorySimpleDataset* _dataset;
KDChart::Widget *_plot ;

Archive Download the corresponding diff file