Extract cost repartition banner
This commit is contained in:
parent
0d80d91a47
commit
2ec5e124da
|
@ -1,12 +1,12 @@
|
||||||
v0.4 (17/02/2013)
|
v0.4 (17/02/2013)
|
||||||
** User **
|
** User **
|
||||||
Add icons for low resolution
|
Add icons for low resolution screens
|
||||||
Sort categories using translated names
|
Sort categories using translated names
|
||||||
Set DateFrom to first of month for SearchBanner
|
Set DateFrom to first of month for SearchBanner
|
||||||
Add CSV export
|
Add CSV export
|
||||||
|
|
||||||
** Dev **
|
** Dev **
|
||||||
Primitive handle of low resolutions
|
Primitive handle of low resolution screens
|
||||||
Rework GridAccount
|
Rework GridAccount
|
||||||
Simplify UpdateNextMonths function
|
Simplify UpdateNextMonths function
|
||||||
Add "create_if_not_exsits" to Database::GetAccountAmount
|
Add "create_if_not_exsits" to Database::GetAccountAmount
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <KDChartLegend>
|
|
||||||
#include <KDChartPieDiagram>
|
|
||||||
|
|
||||||
#include "AccountPanel.hpp"
|
#include "AccountPanel.hpp"
|
||||||
#include "grid/FloatDelegate.hpp"
|
#include "grid/FloatDelegate.hpp"
|
||||||
|
@ -29,7 +27,7 @@
|
||||||
#include "SnapshotsDialog.hpp"
|
#include "SnapshotsDialog.hpp"
|
||||||
|
|
||||||
enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS};
|
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};
|
enum {VIRTUAL_MODE=0, REAL_MODE, CHECK_MODE};
|
||||||
|
|
||||||
|
@ -51,12 +49,10 @@ void AccountPanel::Init(KissCount* kiss, wxUI *parent, int curMode)
|
||||||
QVBoxLayout *vbox = new QVBoxLayout;
|
QVBoxLayout *vbox = new QVBoxLayout;
|
||||||
QVBoxLayout *vbox2 = new QVBoxLayout;
|
QVBoxLayout *vbox2 = new QVBoxLayout;
|
||||||
QVBoxLayout *vbox3 = new QVBoxLayout;
|
QVBoxLayout *vbox3 = new QVBoxLayout;
|
||||||
// wxChartPanel* chart ;
|
int i;
|
||||||
int i ;
|
|
||||||
User* user = _kiss->GetUser();
|
User* user = _kiss->GetUser();
|
||||||
std::vector<Account>::iterator accountIt;
|
std::vector<Account>::iterator accountIt;
|
||||||
std::vector<Category>::iterator categoryIt;
|
std::vector<Category>::iterator categoryIt;
|
||||||
int nbCategories;
|
|
||||||
|
|
||||||
_icons[KissPanel::LOW_RES_ICON] = USER_LOW_ICON;
|
_icons[KissPanel::LOW_RES_ICON] = USER_LOW_ICON;
|
||||||
_icons[KissPanel::HIGH_RES_ICON] = USER_ICON;
|
_icons[KissPanel::HIGH_RES_ICON] = USER_ICON;
|
||||||
|
@ -70,8 +66,6 @@ void AccountPanel::Init(KissCount* kiss, wxUI *parent, int curMode)
|
||||||
_tree->setContextMenuPolicy(Qt::CustomContextMenu);
|
_tree->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(_tree, SIGNAL(customContextMenuRequested ( const QPoint & )), this, SLOT(OnTreeRightClick(const QPoint &)));
|
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 = new QCalendarWidget(this);
|
||||||
_calendar->setGridVisible(false);
|
_calendar->setGridVisible(false);
|
||||||
_calendar->setFirstDayOfWeek(Qt::Monday);
|
_calendar->setFirstDayOfWeek(Qt::Monday);
|
||||||
|
@ -96,48 +90,7 @@ void AccountPanel::Init(KissCount* kiss, wxUI *parent, int curMode)
|
||||||
_categoriesIndexes[categoryIt->name] = i;
|
_categoriesIndexes[categoryIt->name] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbCategories = user->GetCategoriesNumber();
|
_categoriesValues = new int[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);
|
|
||||||
|
|
||||||
_grid = new GridAccount(_kiss, this, true, true, true);
|
_grid = new GridAccount(_kiss, this, true, true, true);
|
||||||
_grid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
_grid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
@ -155,8 +108,10 @@ void AccountPanel::Init(KissCount* kiss, wxUI *parent, int curMode)
|
||||||
_statsGrid = new QTableWidget(this);
|
_statsGrid = new QTableWidget(this);
|
||||||
_statsGrid->verticalHeader()->setHidden(true);
|
_statsGrid->verticalHeader()->setHidden(true);
|
||||||
_statsGrid->horizontalHeader()->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"));
|
QGroupBox *groupBox = new QGroupBox(_("Mode"));
|
||||||
|
|
||||||
_virtual = new QRadioButton(_("Virtual"));
|
_virtual = new QRadioButton(_("Virtual"));
|
||||||
|
@ -212,15 +167,12 @@ void AccountPanel::Init(KissCount* kiss, wxUI *parent, int curMode)
|
||||||
vbox2->addWidget(_grid, 1);
|
vbox2->addWidget(_grid, 1);
|
||||||
hbox->addLayout(vbox2);
|
hbox->addLayout(vbox2);
|
||||||
vbox->addWidget(_statsGrid);
|
vbox->addWidget(_statsGrid);
|
||||||
vbox->addWidget(_pie);
|
vbox->addWidget(_costRepartitionBanner);
|
||||||
hbox->addLayout(vbox);
|
hbox->addLayout(vbox);
|
||||||
|
|
||||||
ChangeUser();
|
ChangeUser();
|
||||||
|
|
||||||
layout();
|
layout();
|
||||||
|
|
||||||
QSize s = legend->sizeHint();
|
|
||||||
legend->setMaximumSize(s.width(), s.height()/3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountPanel::~AccountPanel()
|
AccountPanel::~AccountPanel()
|
||||||
|
@ -248,8 +200,6 @@ QString AccountPanel::GetToolTip()
|
||||||
|
|
||||||
void AccountPanel::InitStatsGrid(User* user)
|
void AccountPanel::InitStatsGrid(User* user)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int nb_categories = user->GetCategoriesNumber();
|
|
||||||
DEFAULT_FONT(font);
|
DEFAULT_FONT(font);
|
||||||
|
|
||||||
if (!_statsGrid->rowCount())
|
if (!_statsGrid->rowCount())
|
||||||
|
@ -261,27 +211,11 @@ void AccountPanel::InitStatsGrid(User* user)
|
||||||
{
|
{
|
||||||
_statsGrid->clear();
|
_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_CREDIT, 0, new QTableWidgetItem(_("Total Credit")));
|
||||||
_statsGrid->setItem(TOTAL_DEBIT, 0, new QTableWidgetItem(_("Total Debit")));
|
_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);
|
font.setBold(true);
|
||||||
|
|
||||||
_statsGrid->setItem(CUR_CREDIT, 0, new QTableWidgetItem(_("Cur Credit")));
|
_statsGrid->setItem(CUR_CREDIT, 0, new QTableWidgetItem(_("Cur Credit")));
|
||||||
|
@ -289,14 +223,12 @@ void AccountPanel::InitStatsGrid(User* user)
|
||||||
_statsGrid->setItem(TOTAL_CREDIT, 0, new QTableWidgetItem(_("Total Credit")));
|
_statsGrid->setItem(TOTAL_CREDIT, 0, new QTableWidgetItem(_("Total Credit")));
|
||||||
_statsGrid->setItem(TOTAL_DEBIT, 0, new QTableWidgetItem(_("Total Debit")));
|
_statsGrid->setItem(TOTAL_DEBIT, 0, new QTableWidgetItem(_("Total Debit")));
|
||||||
_statsGrid->setItem(BALANCE, 0, new QTableWidgetItem(_("Balance")));
|
_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_CREDIT, 1, new QTableWidgetItem(""));
|
||||||
_statsGrid->setItem(CUR_DEBIT, 1, new QTableWidgetItem(""));
|
_statsGrid->setItem(CUR_DEBIT, 1, new QTableWidgetItem(""));
|
||||||
_statsGrid->setItem(TOTAL_CREDIT, 1, new QTableWidgetItem(""));
|
_statsGrid->setItem(TOTAL_CREDIT, 1, new QTableWidgetItem(""));
|
||||||
_statsGrid->setItem(TOTAL_DEBIT, 1, new QTableWidgetItem(""));
|
_statsGrid->setItem(TOTAL_DEBIT, 1, new QTableWidgetItem(""));
|
||||||
_statsGrid->setItem(BALANCE, 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_DEBIT, 0)->setFont(font);
|
||||||
_statsGrid->item(CUR_CREDIT, 0)->setFont(font);
|
_statsGrid->item(CUR_CREDIT, 0)->setFont(font);
|
||||||
|
@ -308,9 +240,10 @@ void AccountPanel::InitStatsGrid(User* user)
|
||||||
_statsGrid->item(TOTAL_CREDIT, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
_statsGrid->item(TOTAL_CREDIT, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
||||||
_statsGrid->item(TOTAL_DEBIT, 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(BALANCE, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
||||||
_statsGrid->item(NON_FIX, 1)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
|
||||||
|
|
||||||
_statsGrid->resizeColumnToContents(0);
|
_statsGrid->resizeColumnToContents(0);
|
||||||
|
|
||||||
|
_costRepartitionBanner->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::ChangeUser()
|
void AccountPanel::ChangeUser()
|
||||||
|
@ -572,6 +505,7 @@ void AccountPanel::UpdateStats()
|
||||||
Operation op;
|
Operation op;
|
||||||
bool blocked_account ;
|
bool blocked_account ;
|
||||||
QString v;
|
QString v;
|
||||||
|
std::vector<Operation> operations;
|
||||||
|
|
||||||
_inModification = true;
|
_inModification = true;
|
||||||
|
|
||||||
|
@ -666,6 +600,7 @@ void AccountPanel::UpdateStats()
|
||||||
curAccountAmount[op.account] += op.amount;
|
curAccountAmount[op.account] += op.amount;
|
||||||
finalAccountAmount[op.account] += op.amount;
|
finalAccountAmount[op.account] += op.amount;
|
||||||
}
|
}
|
||||||
|
operations.push_back(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
balance = totalCredit - totalDebit;
|
balance = totalCredit - totalDebit;
|
||||||
|
@ -677,35 +612,6 @@ void AccountPanel::UpdateStats()
|
||||||
_statsGrid->item(BALANCE, 1)->setText(v.sprintf("%.2lf", (double)balance/100));
|
_statsGrid->item(BALANCE, 1)->setText(v.sprintf("%.2lf", (double)balance/100));
|
||||||
_statsGrid->item(BALANCE, 1)->setForeground((balance >= 0) ? QBrush(Qt::green) : QBrush(Qt::red));
|
_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++)
|
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
|
||||||
{
|
{
|
||||||
if (accountIt->hidden)
|
if (accountIt->hidden)
|
||||||
|
@ -740,6 +646,8 @@ void AccountPanel::UpdateStats()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_costRepartitionBanner->UpdateCosts(operations, _categoriesValues, totalDebit);
|
||||||
|
|
||||||
_accountsGrid->resizeColumnToContents(ACCOUNT_INIT);
|
_accountsGrid->resizeColumnToContents(ACCOUNT_INIT);
|
||||||
_accountsGrid->resizeColumnToContents(ACCOUNT_CUR);
|
_accountsGrid->resizeColumnToContents(ACCOUNT_CUR);
|
||||||
_accountsGrid->resizeColumnToContents(ACCOUNT_FINAL);
|
_accountsGrid->resizeColumnToContents(ACCOUNT_FINAL);
|
||||||
|
|
|
@ -25,12 +25,12 @@
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <KDChartWidget>
|
|
||||||
|
|
||||||
#include "view.hpp"
|
#include "view.hpp"
|
||||||
|
|
||||||
#include <model/model.hpp>
|
#include <model/model.hpp>
|
||||||
#include "grid/GridAccount.hpp"
|
#include "grid/GridAccount.hpp"
|
||||||
|
#include "CostRepartitionBanner.hpp"
|
||||||
|
|
||||||
class GridAccount;
|
class GridAccount;
|
||||||
|
|
||||||
|
@ -76,14 +76,13 @@ private:
|
||||||
QCalendarWidget* _calendar;
|
QCalendarWidget* _calendar;
|
||||||
GridAccount* _grid;
|
GridAccount* _grid;
|
||||||
QTableWidget* _accountsGrid, *_statsGrid;
|
QTableWidget* _accountsGrid, *_statsGrid;
|
||||||
KDChart::Widget* _pie;
|
CostRepartitionBanner* _costRepartitionBanner;
|
||||||
int *_categoriesValues;
|
int *_categoriesValues;
|
||||||
// wxRadioBox *_radioMode;
|
// wxRadioBox *_radioMode;
|
||||||
std::map<QString, int> _categoriesIndexes;
|
std::map<QString, int> _categoriesIndexes;
|
||||||
std::vector<Operation>* _curOperations;
|
std::vector<Operation>* _curOperations;
|
||||||
QString* _categories, *_accounts;
|
QString* _categories, *_accounts;
|
||||||
std::map<int, int> _accountsInitValues;
|
std::map<int, int> _accountsInitValues;
|
||||||
QStandardItemModel* _dataset;
|
|
||||||
int _fixCosts;
|
int _fixCosts;
|
||||||
QRadioButton *_virtual, *_real, *_check;
|
QRadioButton *_virtual, *_real, *_check;
|
||||||
bool _inModification;
|
bool _inModification;
|
||||||
|
|
|
@ -0,0 +1,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);
|
||||||
|
}
|
|
@ -0,0 +1,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
|
Loading…
Reference in New Issue