KissCount

KissCount Commit Details

Date:2013-02-26 12:17:35 (7 years 4 months ago)
Author:Grégory Soutadé
Branch:dev, master, qt5
Commit:2ec5e124da3a7fe8c0b37a3ac46106ea95fafe56
Parents: 0d80d91a479b9169f5df8967f9c95b346506a659
Message:Extract cost repartition banner

Changes:
Csrc/model/export/CSVExportEngine.hpp → src/view/CostRepartitionBanner.hpp
Asrc/view/CostRepartitionBanner.cpp (full)
MChangeLog (1 diff)
Msrc/view/AccountPanel.cpp (15 diffs)
Msrc/view/AccountPanel.hpp (2 diffs)

File differences

ChangeLog
11
22
3
3
44
55
66
77
88
9
9
1010
1111
1212
v0.4 (17/02/2013)
** User **
Add icons for low resolution
Add icons for low resolution screens
Sort categories using translated names
Set DateFrom to first of month for SearchBanner
Add CSV export
** Dev **
Primitive handle of low resolutions
Primitive handle of low resolution screens
Rework GridAccount
Simplify UpdateNextMonths function
Add "create_if_not_exsits" to Database::GetAccountAmount
src/view/AccountPanel.cpp
2020
2121
2222
23
24
2523
2624
2725
......
2927
3028
3129
32
30
3331
3432
3533
......
5149
5250
5351
54
55
52
5653
5754
5855
59
6056
6157
6258
......
7066
7167
7268
73
74
7569
7670
7771
......
9690
9791
9892
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
93
14194
14295
14396
......
155108
156109
157110
158
111
159112
113
114
160115
161116
162117
......
212167
213168
214169
215
170
216171
217172
218173
219174
220175
221
222
223
224176
225177
226178
......
248200
249201
250202
251
252
253203
254204
255205
......
261211
262212
263213
264
214
265215
266216
267217
268218
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285219
286220
287221
......
289223
290224
291225
292
293226
294227
295228
296229
297230
298231
299
300232
301233
302234
......
308240
309241
310242
311
312243
313244
245
246
314247
315248
316249
......
572505
573506
574507
508
575509
576510
577511
......
666600
667601
668602
603
669604
670605
671606
......
677612
678613
679614
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709615
710616
711617
......
740646
741647
742648
649
650
743651
744652
745653
#include <QHeaderView>
#include <QGroupBox>
#include <QMessageBox>
#include <KDChartLegend>
#include <KDChartPieDiagram>
#include "AccountPanel.hpp"
#include "grid/FloatDelegate.hpp"
#include "SnapshotsDialog.hpp"
enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS};
enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, BALANCE, STATS_ROW, CATS_STATS, NON_FIX};
enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, BALANCE, CATS_STATS};
enum {VIRTUAL_MODE=0, REAL_MODE, CHECK_MODE};
QVBoxLayout *vbox = new QVBoxLayout;
QVBoxLayout *vbox2 = new QVBoxLayout;
QVBoxLayout *vbox3 = new QVBoxLayout;
// wxChartPanel* chart ;
int i ;
int i;
User* user = _kiss->GetUser();
std::vector<Account>::iterator accountIt;
std::vector<Category>::iterator categoryIt;
int nbCategories;
_icons[KissPanel::LOW_RES_ICON] = USER_LOW_ICON;
_icons[KissPanel::HIGH_RES_ICON] = USER_ICON;
_tree->setContextMenuPolicy(Qt::CustomContextMenu);
connect(_tree, SIGNAL(customContextMenuRequested ( const QPoint & )), this, SLOT(OnTreeRightClick(const QPoint &)));
// ColorScheme* colorScheme = new ColorScheme(wxUI::categoryColors, WXSIZEOF(wxUI::categoryColors));
_calendar = new QCalendarWidget(this);
_calendar->setGridVisible(false);
_calendar->setFirstDayOfWeek(Qt::Monday);
_categoriesIndexes[categoryIt->name] = i;
}
nbCategories = user->GetCategoriesNumber();
// nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
_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->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
legend->setOrientation( Qt::Vertical );
legend->setTitleText( _("Cost repartition") );
QVector< double > vec;
vec << 0.0;
_dataset = new QStandardItemModel(nbCategories, 2, this);
_categoriesValues = new int[nbCategories];
for(i=0; i<nbCategories; i++)
{
_categoriesValues[i] = 0.0;
_pie->setDataset( i, vec, _categories[i] );
_pie->pieDiagram()->setBrush(i, QBrush(wxUI::categoryColors[i]));
legend->setText( i, _categories[i] );
_dataset->setData(_dataset->index(i, 0, QModelIndex()), _categories[i]);
_dataset->setData(_dataset->index(i, 1, QModelIndex()), 0.0);
if (i < wxUI::MAX_CATEGORY)
_dataset->setData(_dataset->index(i, 0, QModelIndex()), wxUI::categoryColors[i], Qt::DecorationRole);
}
_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 = new int[user->GetCategoriesNumber()];
_grid = new GridAccount(_kiss, this, true, true, true);
_grid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_statsGrid = new QTableWidget(this);
_statsGrid->verticalHeader()->setHidden(true);
_statsGrid->horizontalHeader()->setHidden(true);
_statsGrid->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
_statsGrid->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
_costRepartitionBanner = new CostRepartitionBanner(_kiss, this, _categories);
QGroupBox *groupBox = new QGroupBox(_("Mode"));
_virtual = new QRadioButton(_("Virtual"));
vbox2->addWidget(_grid, 1);
hbox->addLayout(vbox2);
vbox->addWidget(_statsGrid);
vbox->addWidget(_pie);
vbox->addWidget(_costRepartitionBanner);
hbox->addLayout(vbox);
ChangeUser();
layout();
QSize s = legend->sizeHint();
legend->setMaximumSize(s.width(), s.height()/3);
}
AccountPanel::~AccountPanel()
void AccountPanel::InitStatsGrid(User* user)
{
int i;
int nb_categories = user->GetCategoriesNumber();
DEFAULT_FONT(font);
if (!_statsGrid->rowCount())
{
_statsGrid->clear();
}
_statsGrid->setRowCount(nb_categories+CATS_STATS+1); // Headers + blank + categories + non fix
_statsGrid->setRowCount(CATS_STATS); // Headers
_statsGrid->setItem(TOTAL_CREDIT, 0, new QTableWidgetItem(_("Total Credit")));
_statsGrid->setItem(TOTAL_DEBIT, 0, new QTableWidgetItem(_("Total Debit")));
for(i=0; i<nb_categories; i++)
{
if (i)
{
_statsGrid->setItem(CATS_STATS+i+1, 0, new QTableWidgetItem(_categories[i]));
_statsGrid->setItem(CATS_STATS+i+1, 1, new QTableWidgetItem(""));
_statsGrid->item(CATS_STATS+i+1, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
}
else
{
_statsGrid->setItem(CATS_STATS+i, 0, new QTableWidgetItem(_categories[i]));
_statsGrid->setItem(CATS_STATS+i, 1, new QTableWidgetItem(""));
_statsGrid->item(CATS_STATS+i, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
}
}
font.setBold(true);
_statsGrid->setItem(CUR_CREDIT, 0, new QTableWidgetItem(_("Cur Credit")));
_statsGrid->setItem(TOTAL_CREDIT, 0, new QTableWidgetItem(_("Total Credit")));
_statsGrid->setItem(TOTAL_DEBIT, 0, new QTableWidgetItem(_("Total Debit")));
_statsGrid->setItem(BALANCE, 0, new QTableWidgetItem(_("Balance")));
_statsGrid->setItem(NON_FIX, 0, new QTableWidgetItem(_("Non fix")));
_statsGrid->setItem(CUR_CREDIT, 1, new QTableWidgetItem(""));
_statsGrid->setItem(CUR_DEBIT, 1, new QTableWidgetItem(""));
_statsGrid->setItem(TOTAL_CREDIT, 1, new QTableWidgetItem(""));
_statsGrid->setItem(TOTAL_DEBIT, 1, new QTableWidgetItem(""));
_statsGrid->setItem(BALANCE, 1, new QTableWidgetItem(""));
_statsGrid->setItem(NON_FIX, 1, new QTableWidgetItem(""));
_statsGrid->item(CUR_DEBIT, 0)->setFont(font);
_statsGrid->item(CUR_CREDIT, 0)->setFont(font);
_statsGrid->item(TOTAL_CREDIT, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
_statsGrid->item(TOTAL_DEBIT, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
_statsGrid->item(BALANCE, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
_statsGrid->item(NON_FIX, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
_statsGrid->resizeColumnToContents(0);
_costRepartitionBanner->Reset();
}
void AccountPanel::ChangeUser()
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;
_statsGrid->item(BALANCE, 1)->setText(v.sprintf("%.2lf", (double)balance/100));
_statsGrid->item(BALANCE, 1)->setForeground((balance >= 0) ? QBrush(Qt::green) : QBrush(Qt::red));
// KDChart::Legend* legend = _pie->legend();
for(i=0; i<user->GetCategoriesNumber(); i++)
{
if (totalDebit != 0)
percents = (_categoriesValues[i]*100)/totalDebit;
else
percents = 0.0;
if (i)
_statsGrid->item(CATS_STATS+i+1, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)_categoriesValues[i]/100, (int)percents));
else
_statsGrid->item(CATS_STATS+i, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)_categoriesValues[i]/100, (int)percents));
QVector< double > vec;
vec << (double) _categoriesValues[i] / 100;
_pie->setDataset( i, vec, _categories[i] );
// if (_categoriesValues[i] == 0.0)
// legend->setDatasetHidden(i, true);
// else
// legend->setDatasetHidden(i, false);
// _dataset->setData(_dataset->index(i, 1, QModelIndex()), _categoriesValues[i]);
}
value = totalDebit - _categoriesValues[0];
if (totalDebit != 0)
percents = (value*100)/totalDebit;
else
percents = 0.0;
_statsGrid->item(NON_FIX, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)value/100, (int)percents));
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
{
if (accountIt->hidden)
}
}
_costRepartitionBanner->UpdateCosts(operations, _categoriesValues, totalDebit);
_accountsGrid->resizeColumnToContents(ACCOUNT_INIT);
_accountsGrid->resizeColumnToContents(ACCOUNT_CUR);
_accountsGrid->resizeColumnToContents(ACCOUNT_FINAL);
src/view/AccountPanel.hpp
2525
2626
2727
28
2928
3029
3130
3231
3332
33
3434
3535
3636
......
7676
7777
7878
79
79
8080
8181
8282
8383
8484
8585
86
8786
8887
8988
#include <QTableWidget>
#include <QRadioButton>
#include <QStandardItemModel>
#include <KDChartWidget>
#include "view.hpp"
#include <model/model.hpp>
#include "grid/GridAccount.hpp"
#include "CostRepartitionBanner.hpp"
class GridAccount;
QCalendarWidget* _calendar;
GridAccount* _grid;
QTableWidget* _accountsGrid, *_statsGrid;
KDChart::Widget* _pie;
CostRepartitionBanner* _costRepartitionBanner;
int *_categoriesValues;
// wxRadioBox *_radioMode;
std::map<QString, int> _categoriesIndexes;
std::vector<Operation>* _curOperations;
QString* _categories, *_accounts;
std::map<int, int> _accountsInitValues;
QStandardItemModel* _dataset;
int _fixCosts;
QRadioButton *_virtual, *_real, *_check;
bool _inModification;
src/view/CostRepartitionBanner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
Copyright 2010-2013 Grégory Soutadé
This file is part of KissCount.
KissCount is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KissCount is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include <KDChartLegend>
#include <KDChartPieDiagram>
#include "CostRepartitionBanner.hpp"
CostRepartitionBanner::CostRepartitionBanner(KissCount* kiss, QFrame* parent, QString* categories) : QFrame(parent), _kiss(kiss), _categories(categories)
{
User* user = _kiss->GetUser();
int nbCategories, i;
QVBoxLayout *vbox = new QVBoxLayout;
setLayout(vbox);
nbCategories = user->GetCategoriesNumber();
_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->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
legend->setOrientation( Qt::Vertical );
legend->setTitleText( _("Cost repartition") );
QVector< double > vec;
vec << 0.0;
_dataset = new QStandardItemModel(nbCategories, 2, this);
for(i=0; i<nbCategories; i++)
{
_pie->setDataset( i, vec, _categories[i] );
_pie->pieDiagram()->setBrush(i, QBrush(wxUI::categoryColors[i]));
legend->setText( i, _categories[i] );
_dataset->setData(_dataset->index(i, 0, QModelIndex()), _categories[i]);
_dataset->setData(_dataset->index(i, 1, QModelIndex()), 0.0);
if (i < wxUI::MAX_CATEGORY)
_dataset->setData(_dataset->index(i, 0, QModelIndex()), wxUI::categoryColors[i], Qt::DecorationRole);
}
_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);
_statsGrid = new QTableWidget(this);
_statsGrid->verticalHeader()->setHidden(true);
_statsGrid->horizontalHeader()->setHidden(true);
_statsGrid->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
QSize s = legend->sizeHint();
legend->setMaximumSize(s.width(), s.height()/3);
vbox->addWidget(_statsGrid);
vbox->addWidget(_pie);
setMaximumWidth(300);
}
void CostRepartitionBanner::Reset()
{
int i;
User* user = _kiss->GetUser();
int nb_categories = user->GetCategoriesNumber();
if (!_statsGrid->rowCount())
{
_statsGrid->setColumnCount(2);
//_statsGrid->EnableEditing(false);
}
else
{
_statsGrid->clear();
}
_statsGrid->setRowCount(nb_categories+1); // categories + non fix
_statsGrid->setItem(1, 0, new QTableWidgetItem(_("Non fix")));
_statsGrid->setItem(1, 1, new QTableWidgetItem(""));
for(i=0; i<nb_categories; i++)
{
if (!i)
{
_statsGrid->setItem(i, 0, new QTableWidgetItem(_categories[i]));
_statsGrid->setItem(i, 1, new QTableWidgetItem(""));
_statsGrid->item(i, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
}
else
{
_statsGrid->setItem(i+1, 0, new QTableWidgetItem(_categories[i]));
_statsGrid->setItem(i+1, 1, new QTableWidgetItem(""));
_statsGrid->item(i+1, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
}
}
_statsGrid->resizeColumnToContents(0);
}
void CostRepartitionBanner::UpdateCosts(std::vector<Operation>& operations, int *categoriesValues, int totalDebit)
{
int i;
User* user = _kiss->GetUser();
int value, percents;
QString v;
for(i=0; i<user->GetCategoriesNumber(); i++)
{
if (totalDebit != 0)
percents = (categoriesValues[i]*100)/totalDebit;
else
percents = 0.0;
if (!i)
_statsGrid->item(i, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)categoriesValues[i]/100, (int)percents));
else
_statsGrid->item(i+1, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)categoriesValues[i]/100, (int)percents));
// KDChart::Legend* legend = _pie->legend();
QVector< double > vec;
vec << (double) categoriesValues[i] / 100;
_pie->setDataset( i, vec, _categories[i] );
// if (categoriesValues[i] == 0.0)
// legend->setDatasetHidden(i, true);
// else
// legend->setDatasetHidden(i, false);
// _dataset->setData(_dataset->index(i, 1, QModelIndex()), categoriesValues[i]);
}
value = totalDebit - categoriesValues[0];
if (totalDebit != 0)
percents = (value*100)/totalDebit;
else
percents = 0.0;
_statsGrid->item(1, 1)->setText(v.sprintf("%.2lf (%02d %%)", (double)value/100, (int)percents));
_statsGrid->resizeColumnToContents(1);
}
src/view/CostRepartitionBanner.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Copyright 2010-2013 Grégory Soutadé
This file is part of KissCount.
KissCount is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KissCount is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COSTREPARTITIONBANNER_H
#define COSTREPARTITIONBANNER_H
#include <QtGui>
#include <KDChartWidget>
#include "view.hpp"
#include <model/model.hpp>
class CostRepartitionBanner: public QFrame
{
Q_OBJECT;
public:
CostRepartitionBanner(KissCount* kiss, QFrame* parent, QString* categories);
void Reset();
void UpdateCosts(std::vector<Operation>& operations, int *categoriesValues, int totalDebit);
private:
KissCount* _kiss;
QString* _categories;
QTableWidget* _statsGrid;
KDChart::Widget* _pie;
QStandardItemModel* _dataset;
};
#endif

Archive Download the corresponding diff file