Work on AccountPanel : add treeview
This commit is contained in:
parent
633bd15fdd
commit
fc9b06c507
|
@ -1011,7 +1011,7 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
|||
{
|
||||
QString req, req2, reqUnion;
|
||||
QSqlRecord set;
|
||||
QSqlQuery query(_db);
|
||||
QSqlQuery query(_db),query2(_db);
|
||||
std::vector<Account>::iterator it;
|
||||
std::map<int, std::vector<int> > res;
|
||||
int year;
|
||||
|
@ -1041,9 +1041,10 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
|||
reqUnion = req + " UNION " + req2;
|
||||
EXECUTE_SQL_QUERY(reqUnion, res);
|
||||
|
||||
while (query.next())
|
||||
query2 = query;
|
||||
while (query2.next())
|
||||
{
|
||||
set = query.record();
|
||||
set = query2.record();
|
||||
|
||||
year = set.value("year").toInt();
|
||||
|
||||
|
@ -1081,7 +1082,7 @@ std::map<int, std::vector<int> > Database::GetAllOperations(User* user)
|
|||
}
|
||||
query.clear();
|
||||
}
|
||||
query.clear();
|
||||
query2.clear();
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
@ -27,29 +27,26 @@ enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, BALANCE, STATS_ROW, CATS
|
|||
|
||||
enum {VIRTUAL_MODE=0, REAL_MODE, CHECK_MODE};
|
||||
|
||||
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _curMonth(-1), _curYear(-1) //, _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT)
|
||||
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _curMonth(-1), _curYear(-1)
|
||||
{
|
||||
// wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
// wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL);
|
||||
// wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||
// wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
|
||||
// wxBoxSizer *vbox3 = new wxBoxSizer(wxVERTICAL);
|
||||
QHBoxLayout *hbox = new QHBoxLayout;
|
||||
QHBoxLayout *hbox2 = new QHBoxLayout;
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
QVBoxLayout *vbox2 = new QVBoxLayout;
|
||||
QVBoxLayout *vbox3 = new QVBoxLayout;
|
||||
// wxChartPanel* chart ;
|
||||
// int i ;
|
||||
// User* user = _kiss->GetUser();
|
||||
// std::vector<Account>::iterator accountIt;
|
||||
// std::vector<Category>::iterator categoryIt;
|
||||
// DEFAULT_FONT(font);
|
||||
// wxRect rect = wxDisplay().GetGeometry();
|
||||
// int nbCategories;
|
||||
int i ;
|
||||
User* user = _kiss->GetUser();
|
||||
std::vector<Account>::iterator accountIt;
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
DEFAULT_FONT(font);
|
||||
int nbCategories;
|
||||
|
||||
// SetSizer(hbox);
|
||||
setLayout(hbox);
|
||||
|
||||
_categoriesValues=0;
|
||||
_categories=0;
|
||||
_accounts=0;
|
||||
|
||||
// ColorScheme* colorScheme = new ColorScheme(wxUI::categoryColors, WXSIZEOF(wxUI::categoryColors));
|
||||
_tree = new QTreeWidget(this);
|
||||
_tree->headerItem()->setHidden(true);
|
||||
// ColorScheme* colorScheme = new ColorScheme(wxUI::categoryColors, WXSIZEOF(wxUI::categoryColors));
|
||||
|
||||
// _pie = new PiePlot();
|
||||
// _calendar = new wxCalendarCtrl(this, CALENDAR_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize,
|
||||
|
@ -59,27 +56,27 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
|
|||
// _calendar->EnableHolidayDisplay(false);
|
||||
// _calendar->Enable(false);
|
||||
|
||||
// _accounts = new wxString[user->GetAccountsNumber()];
|
||||
// for (i=0,
|
||||
// accountIt = user->_accounts.begin();
|
||||
// accountIt != user->_accounts.end();
|
||||
// accountIt++, i++)
|
||||
// _accounts[i] = accountIt->name;
|
||||
_accounts = new QString[user->GetAccountsNumber()];
|
||||
for (i=0,
|
||||
accountIt = user->_accounts.begin();
|
||||
accountIt != user->_accounts.end();
|
||||
accountIt++, i++)
|
||||
_accounts[i] = accountIt->name;
|
||||
|
||||
// _categories = new wxString[user->GetCategoriesNumber()] ;
|
||||
// for(i=0, categoryIt = user->_categories.begin();
|
||||
// categoryIt != user->_categories.end();
|
||||
// categoryIt++, i++)
|
||||
// {
|
||||
// _categories[i] = wxGetTranslation(categoryIt->name) ;
|
||||
// _categoriesIndexes[categoryIt->name] = i;
|
||||
// }
|
||||
_categories = new QString[user->GetCategoriesNumber()] ;
|
||||
for(i=0, categoryIt = user->_categories.begin();
|
||||
categoryIt != user->_categories.end();
|
||||
categoryIt++, i++)
|
||||
{
|
||||
_categories[i] = _(categoryIt->name.toStdString().c_str()) ;
|
||||
_categoriesIndexes[categoryIt->name] = i;
|
||||
}
|
||||
|
||||
// nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
|
||||
nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
|
||||
|
||||
// _categoriesValues = new double[user->GetCategoriesNumber()];
|
||||
// for(i=0; i<user->GetCategoriesNumber(); i++)
|
||||
// _categoriesValues[i] = 0.0;
|
||||
_categoriesValues = new double[user->GetCategoriesNumber()];
|
||||
for(i=0; i<user->GetCategoriesNumber(); i++)
|
||||
_categoriesValues[i] = 0.0;
|
||||
|
||||
// _dataset = new CategorySimpleDataset(_categories, nbCategories);
|
||||
// _dataset->AddSerie(_("Serie 1"), _categoriesValues, nbCategories);
|
||||
|
@ -125,13 +122,13 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
|
|||
// wxButton* buttonUnGroup = new wxButton(this, UNGROUP_ID, _("UnGroup"));
|
||||
// wxButton* buttonUpdateNextMonths = new wxButton(this, UPDATE_NEXT_MONTHS_ID, _("Update next months"));
|
||||
|
||||
// vbox3->Add(&_tree, 0, wxGROW|wxALL, 2);
|
||||
vbox3->addWidget(_tree);
|
||||
// vbox3->Add(buttonUpdateNextMonths, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);
|
||||
// vbox3->Add(buttonGroup, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);
|
||||
// vbox3->Add(buttonUnGroup, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);
|
||||
// vbox3->Add(_radioMode, 0, wxALIGN_CENTER_HORIZONTAL|wxUP, 50);
|
||||
|
||||
// hbox->Add(vbox3, 0, wxALL, 2);
|
||||
hbox->addLayout(vbox3);
|
||||
// // hbox->Add(vbox3, 0, wxGROW|wxALL, 2);
|
||||
// hbox2->Add(_accountsGrid, 0, wxGROW|wxALL, 2);
|
||||
// hbox2->Add(_calendar, 0, wxALL, 2);
|
||||
|
@ -142,9 +139,9 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
|
|||
// vbox->Add(chart, 0, wxALIGN_CENTER_HORIZONTAL|wxUP, 10);
|
||||
// hbox->Add(vbox, 0, wxGROW|wxALL, 2);
|
||||
|
||||
// ChangeUser();
|
||||
ChangeUser();
|
||||
|
||||
// Fit();
|
||||
layout();
|
||||
|
||||
// SetMinSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
|
||||
// SetMaxSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25));
|
||||
|
@ -237,94 +234,89 @@ void AccountPanel::InitStatsGrid(User* user)
|
|||
// _statsGrid->SetCellAlignment(BALANCE, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
||||
// _statsGrid->SetCellAlignment(NON_FIX, 1, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
void AccountPanel::ChangeUser()
|
||||
{
|
||||
// User* user = _kiss->GetUser();
|
||||
// int curYear = -1;
|
||||
// wxDateTime curDate;
|
||||
// wxTreeItemId rootNode, curNode;
|
||||
// std::map<int, std::vector<int> > ops;
|
||||
// std::map<int, std::vector<int> >::iterator it;
|
||||
User* user = _kiss->GetUser();
|
||||
int curYear = -1;
|
||||
QDate curDate = QDate::currentDate();
|
||||
QTreeWidgetItem* curNode;
|
||||
std::map<int, std::vector<int> > ops;
|
||||
std::map<int, std::vector<int> >::iterator it;
|
||||
|
||||
// ops = _kiss->GetAllOperations();
|
||||
ops = _kiss->GetAllOperations();
|
||||
|
||||
// InitStatsGrid(user);
|
||||
InitStatsGrid(user);
|
||||
|
||||
// _tree.DeleteAllItems();
|
||||
// rootNode = _tree.AddRoot(wxT(""));
|
||||
_tree->clear();
|
||||
|
||||
// curDate.SetToCurrent();
|
||||
// if (ops.size())
|
||||
// {
|
||||
// for(it = ops.begin(); it != ops.end(); it++)
|
||||
// {
|
||||
// if ((int)it->first <= curDate.GetYear())
|
||||
// {
|
||||
// curYear = it->first;
|
||||
// curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
||||
// }
|
||||
// else
|
||||
// _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first));
|
||||
// }
|
||||
// Fit();
|
||||
// if (curYear != -1)
|
||||
// {
|
||||
// _tree.SelectItem(curNode, true);
|
||||
// LoadYear(curYear);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), curDate.GetYear()));
|
||||
// _tree.AppendItem(curNode, wxUI::months[(int)curDate.GetYear()]);
|
||||
// Fit();
|
||||
// }
|
||||
if (ops.size())
|
||||
{
|
||||
for(it = ops.begin(); it != ops.end(); it++)
|
||||
{
|
||||
if ((int)it->first <= curDate.year())
|
||||
curYear = it->first;
|
||||
curNode = new QTreeWidgetItem(QStringList(QString::number(it->first)));
|
||||
_tree->addTopLevelItem(curNode);
|
||||
}
|
||||
layout();
|
||||
if (curYear != -1)
|
||||
{
|
||||
_tree->setCurrentItem(curNode);
|
||||
LoadYear(curYear);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
curNode = new QTreeWidgetItem(QStringList(QString::number(curDate.year())));
|
||||
_tree->addTopLevelItem(curNode);
|
||||
layout();
|
||||
}
|
||||
}
|
||||
|
||||
void AccountPanel::LoadYear(int year, bool showMonth)
|
||||
{
|
||||
// User* user = _kiss->GetUser();
|
||||
// int curMonth = -1;
|
||||
// wxDateTime curDate;
|
||||
// wxTreeItemId parentNode, curMonthNode;
|
||||
// std::map<int, std::vector<int> > ops ;
|
||||
// std::vector<int>::iterator it;
|
||||
User* user = _kiss->GetUser();
|
||||
int curMonth = -1;
|
||||
QDate curDate = QDate::currentDate();
|
||||
QTreeWidgetItem* parentNode, *curMonthNode;
|
||||
std::map<int, std::vector<int> > ops ;
|
||||
std::vector<int>::iterator it;
|
||||
|
||||
// if (user->_operations[year] && _tree.GetChildrenCount(_tree.GetSelection(), true))
|
||||
// {
|
||||
// if (showMonth)
|
||||
// ShowMonth(-1, year);
|
||||
// return;
|
||||
// }
|
||||
if (user->_operations[year] && _tree->currentItem()->childCount())
|
||||
{
|
||||
if (showMonth)
|
||||
ShowMonth(-1, year);
|
||||
return;
|
||||
}
|
||||
|
||||
// _curYear = year ;
|
||||
// _kiss->LoadYear(year);
|
||||
// ops = _kiss->GetAllOperations();
|
||||
_curYear = year ;
|
||||
_kiss->LoadYear(year);
|
||||
ops = _kiss->GetAllOperations();
|
||||
|
||||
// curDate.SetToCurrent();
|
||||
// parentNode = _tree.GetSelection();
|
||||
parentNode = _tree->currentItem();
|
||||
|
||||
// for (it = ops[year].begin(); it != ops[year].end(); it++)
|
||||
// {
|
||||
// if (curMonth == -1 || (year == curDate.GetYear() && *it <= curDate.GetMonth()))
|
||||
// {
|
||||
// curMonth = *it;
|
||||
// curMonthNode = _tree.AppendItem(parentNode, wxUI::months[*it]);
|
||||
// }
|
||||
// else
|
||||
// _tree.AppendItem(parentNode, wxUI::months[*it]);
|
||||
// }
|
||||
for (it = ops[year].begin(); it != ops[year].end(); it++)
|
||||
{
|
||||
if (curMonth == -1 || (year == curDate.year() && *it <= curDate.month()))
|
||||
{
|
||||
curMonth = *it;
|
||||
curMonthNode = new QTreeWidgetItem(QStringList(wxUI::months[*it]));
|
||||
parentNode->addChild(curMonthNode);
|
||||
}
|
||||
else
|
||||
_tree->topLevelItem(0)->addChild(new QTreeWidgetItem(QStringList(wxUI::months[*it])));
|
||||
}
|
||||
|
||||
// _tree.Expand(parentNode);
|
||||
// Fit();
|
||||
// if (showMonth)
|
||||
// {
|
||||
// _tree.SelectItem(curMonthNode, true);
|
||||
// ShowMonth(curMonth, year);
|
||||
// }
|
||||
_tree->expandItem(parentNode);
|
||||
layout();
|
||||
if (showMonth)
|
||||
{
|
||||
_tree->setCurrentItem(curMonthNode);
|
||||
ShowMonth(curMonth, year);
|
||||
}
|
||||
|
||||
// _wxUI->Layout();
|
||||
_wxUI->layout();
|
||||
}
|
||||
|
||||
void AccountPanel::ShowMonth(int month, int year)
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
// #include <wx/chartpanel.h>
|
||||
// #include <wx/radiobox.h>
|
||||
|
||||
#include <QTreeWidget>
|
||||
|
||||
#include "view.hpp"
|
||||
|
||||
#include <model/model.hpp>
|
||||
|
@ -69,7 +71,7 @@ public:
|
|||
int _curMonth, _curYear;
|
||||
|
||||
private:
|
||||
// wxTreeCtrl _tree;
|
||||
QTreeWidget *_tree;
|
||||
// wxCalendarCtrl* _calendar;
|
||||
// GridAccount* _grid;
|
||||
// wxGrid *_statsGrid, *_accountsGrid;
|
||||
|
|
|
@ -136,7 +136,7 @@ bool wxUI::SetLanguage(QString language)
|
|||
|
||||
months[0] = _("january");
|
||||
months[1] = _("february");
|
||||
months[2] = _("marchpp");
|
||||
months[2] = _("march");
|
||||
months[3] = _("april");
|
||||
months[4] = _("may");
|
||||
months[5] = _("june");
|
||||
|
|
Loading…
Reference in New Issue
Block a user