Implement GenerateMonth function
This commit is contained in:
parent
c2b6aea35a
commit
739ac0cbc2
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "AccountPanel.hpp"
|
#include "AccountPanel.hpp"
|
||||||
#include "grid/FloatDelegate.hpp"
|
#include "grid/FloatDelegate.hpp"
|
||||||
|
#include "GenerateDialog.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, STATS_ROW, CATS_STATS, NON_FIX};
|
||||||
|
@ -53,6 +54,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
|
||||||
_tree->headerItem()->setHidden(true);
|
_tree->headerItem()->setHidden(true);
|
||||||
_tree->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
_tree->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
connect(_tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(OnTreeChange(QTreeWidgetItem*, int)));
|
connect(_tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(OnTreeChange(QTreeWidgetItem*, int)));
|
||||||
|
_tree->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
connect(_tree, SIGNAL(customContextMenuRequested ( const QPoint & )), this, SLOT(OnTreeRightClick(const QPoint &)));
|
||||||
|
|
||||||
// ColorScheme* colorScheme = new ColorScheme(wxUI::categoryColors, WXSIZEOF(wxUI::categoryColors));
|
// ColorScheme* colorScheme = new ColorScheme(wxUI::categoryColors, WXSIZEOF(wxUI::categoryColors));
|
||||||
|
|
||||||
|
@ -283,7 +286,7 @@ void AccountPanel::ChangeUser()
|
||||||
User* user = _kiss->GetUser();
|
User* user = _kiss->GetUser();
|
||||||
int curYear = -1;
|
int curYear = -1;
|
||||||
QDate curDate = QDate::currentDate();
|
QDate curDate = QDate::currentDate();
|
||||||
QTreeWidgetItem* curNode;
|
QTreeWidgetItem* curNode=NULL, *node;
|
||||||
std::map<int, std::vector<int> > ops;
|
std::map<int, std::vector<int> > ops;
|
||||||
std::map<int, std::vector<int> >::iterator it;
|
std::map<int, std::vector<int> >::iterator it;
|
||||||
|
|
||||||
|
@ -297,10 +300,13 @@ void AccountPanel::ChangeUser()
|
||||||
{
|
{
|
||||||
for(it = ops.begin(); it != ops.end(); it++)
|
for(it = ops.begin(); it != ops.end(); it++)
|
||||||
{
|
{
|
||||||
|
node = new QTreeWidgetItem(QStringList(QString::number(it->first)));
|
||||||
if ((int)it->first <= curDate.year())
|
if ((int)it->first <= curDate.year())
|
||||||
|
{
|
||||||
curYear = it->first;
|
curYear = it->first;
|
||||||
curNode = new QTreeWidgetItem(QStringList(QString::number(it->first)));
|
curNode = node;
|
||||||
_tree->addTopLevelItem(curNode);
|
}
|
||||||
|
_tree->addTopLevelItem(node);
|
||||||
}
|
}
|
||||||
if (curYear != -1)
|
if (curYear != -1)
|
||||||
{
|
{
|
||||||
|
@ -779,16 +785,16 @@ void AccountPanel::OnAccountModified(int row, int column)
|
||||||
inModification = false;
|
inModification = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::OnTreeRightClick()
|
void AccountPanel::OnTreeRightClick(const QPoint & pos)
|
||||||
{
|
{
|
||||||
// wxMenu menu(0);
|
QMenu menu(this);
|
||||||
|
|
||||||
// menu.Append(MENU_GENERATE_ID, _("Generate month"));
|
menu.addAction(_("Generate month"), this, SLOT(OnMenuGenerate()));
|
||||||
// menu.AppendSeparator();
|
menu.addSeparator();
|
||||||
// if (_tree.GetCount() > 1)
|
if (_tree->columnCount() >= 1)
|
||||||
// menu.Append(MENU_DELETE_ID, _("Delete"));
|
menu.addAction(_("Delete"), this, SLOT(OnMenuDelete()));
|
||||||
|
|
||||||
// PopupMenu(&menu, event.GetPoint());
|
menu.exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::OnTreeChange (QTreeWidgetItem * item, int column)
|
void AccountPanel::OnTreeChange (QTreeWidgetItem * item, int column)
|
||||||
|
@ -852,61 +858,60 @@ void AccountPanel::OnTreeChange (QTreeWidgetItem * item, int column)
|
||||||
|
|
||||||
void AccountPanel::GetTreeSelection(int* month, int* year)
|
void AccountPanel::GetTreeSelection(int* month, int* year)
|
||||||
{
|
{
|
||||||
// wxString monthString;
|
QString monthString;
|
||||||
// int i;
|
int i;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
// *month = -1; *year = -1;
|
*month = -1; *year = -1;
|
||||||
|
|
||||||
// monthString = _tree.GetItemText(_tree.GetSelection());
|
monthString = _tree->currentItem()->text(0);
|
||||||
// for (i=0; i<12; i++)
|
for (i=0; i<12; i++)
|
||||||
// if (monthString == wxUI::months[i])
|
if (monthString == wxUI::months[i])
|
||||||
// {
|
{
|
||||||
// *month = i;
|
*month = i;
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (*month == -1)
|
if (*month == -1)
|
||||||
// {
|
{
|
||||||
// *year = wxAtoi(monthString);
|
*year = monthString.toInt(&ok);
|
||||||
|
|
||||||
// // Error
|
// Error
|
||||||
// if (year == 0)
|
if (!ok)
|
||||||
// {
|
{
|
||||||
// *month = -1;
|
*month = -1;
|
||||||
// *year = -1;
|
*year = -1;
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// *year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(_tree.GetSelection())));
|
*year = _tree->currentItem()->parent()->text(0).toInt(&ok);
|
||||||
|
|
||||||
// // Error
|
// Error
|
||||||
// if (year == 0)
|
if (!ok)
|
||||||
// {
|
{
|
||||||
// *month = -1;
|
*month = -1;
|
||||||
// *year = -1;
|
*year = -1;
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::OnMenuGenerate()
|
void AccountPanel::OnMenuGenerate()
|
||||||
{
|
{
|
||||||
// int month, year;
|
int month, year;
|
||||||
// wxDateTime curDate;
|
QDate curDate = QDate::currentDate();
|
||||||
|
|
||||||
// curDate.SetToCurrent();
|
GetTreeSelection(&month, &year);
|
||||||
|
|
||||||
// GetTreeSelection(&month, &year);
|
if (month == -1 && year == curDate.year())
|
||||||
|
{
|
||||||
|
month = _curMonth;
|
||||||
|
}
|
||||||
|
|
||||||
// if (month == -1 && year == curDate.GetYear())
|
GenerateDialog g(_kiss, _wxUI, month, year);
|
||||||
// {
|
g.exec();
|
||||||
// month = _curMonth;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// GenerateDialog g(_kiss, _wxUI, month, year);
|
|
||||||
// g.ShowModal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::OnMenuDelete()
|
void AccountPanel::OnMenuDelete()
|
||||||
|
@ -963,78 +968,48 @@ void AccountPanel::OnMenuDelete()
|
||||||
// }
|
// }
|
||||||
// _wxUI->NeedReload();
|
// _wxUI->NeedReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::GenerateMonth(int month, int year)
|
void AccountPanel::GenerateMonth(int month, int year)
|
||||||
{
|
{
|
||||||
// wxTreeItemId root, years, node ;
|
QString s;
|
||||||
// wxTreeItemIdValue cookie;
|
const QString syear = s.sprintf("%d", year);
|
||||||
// wxString monthString, yearString;
|
QList<QTreeWidgetItem *> items = _tree->findItems(syear, Qt::MatchExactly|Qt::MatchRecursive);
|
||||||
// std::map<int, std::vector<int> > ops ;
|
QTreeWidgetItem *root, *itemYear = NULL, *itemMonth;
|
||||||
// std::vector<int>::iterator it ;
|
std::map<int, std::vector<int> > ops ;
|
||||||
// int i;
|
std::vector<int>::iterator it ;
|
||||||
|
|
||||||
// root = _tree.GetRootItem();
|
int i;
|
||||||
// yearString = wxString::Format(wxT("%d"), year);
|
|
||||||
// monthString = wxUI::months[month];
|
|
||||||
|
|
||||||
// ops = _kiss->GetAllOperations();
|
ops = _kiss->GetAllOperations();
|
||||||
|
|
||||||
// if (_tree.GetChildrenCount(root, true) < 1)
|
// Year not found
|
||||||
// {
|
if (items.size() == 0)
|
||||||
// node = _tree.AppendItem(root, yearString);
|
{
|
||||||
// node = _tree.AppendItem(node, monthString);
|
for(i=0; i<_tree->topLevelItemCount(); i++)
|
||||||
|
{
|
||||||
|
root = _tree->topLevelItem(i);
|
||||||
|
if (root->text(0).toInt() > year)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
itemYear = new QTreeWidgetItem(QStringList(syear));
|
||||||
|
_tree->insertTopLevelItem(i, itemYear);
|
||||||
|
_tree->setCurrentItem(itemYear);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
itemYear = items[0];
|
||||||
|
|
||||||
// _tree.SelectItem(node, true);
|
for(i=0, it = ops[year].begin(); it != ops[year].end(); it++, i++)
|
||||||
// ShowMonth(month, year);
|
{
|
||||||
// return ;
|
if (*it > month)
|
||||||
// }
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// years = _tree.GetFirstChild(root, cookie);
|
if (i) i--;
|
||||||
// while (years.IsOk())
|
itemMonth = new QTreeWidgetItem(QStringList(wxUI::months[month]));
|
||||||
// {
|
itemYear->insertChild(i, itemMonth);
|
||||||
// if (_tree.GetItemText(years) == yearString)
|
_tree->setCurrentItem(itemMonth);
|
||||||
// break;
|
|
||||||
// if (wxAtoi(_tree.GetItemText(years)) > year)
|
|
||||||
// {
|
|
||||||
// years = _tree.GetPrevSibling(years);
|
|
||||||
// if (!years.IsOk())
|
|
||||||
// years = _tree.PrependItem(root, yearString);
|
|
||||||
// else
|
|
||||||
// years = _tree.InsertItem(root, years, yearString);
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// years = _tree.GetNextSibling(years);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!years.IsOk())
|
ShowMonth(month, year);
|
||||||
// {
|
_wxUI->NeedReload();
|
||||||
// years = _tree.GetFirstChild(root, cookie);
|
|
||||||
// if (wxAtoi(_tree.GetItemText(years)) > year)
|
|
||||||
// years = _tree.PrependItem(root, yearString);
|
|
||||||
// else
|
|
||||||
// years = _tree.AppendItem(root, yearString);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!_tree.GetChildrenCount(years, true))
|
|
||||||
// node = _tree.AppendItem(years, monthString);
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// for(i=0, it = ops[year].begin();
|
|
||||||
// it != ops[year].end();
|
|
||||||
// it++, i++)
|
|
||||||
// {
|
|
||||||
// if (*it > month)
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// if (it == ops[year].end())
|
|
||||||
// years = _tree.AppendItem(years, monthString);
|
|
||||||
// else
|
|
||||||
// years = _tree.InsertItem(years, i-1, monthString);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _tree.SelectItem(node, true);
|
|
||||||
// ShowMonth(month, year);
|
|
||||||
// _wxUI->NeedReload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountPanel::OnShow()
|
void AccountPanel::OnShow()
|
||||||
|
|
|
@ -66,7 +66,7 @@ public:
|
||||||
private slots:
|
private slots:
|
||||||
void OnOperationModified();
|
void OnOperationModified();
|
||||||
void OnAccountModified(int row, int column);
|
void OnAccountModified(int row, int column);
|
||||||
void OnTreeRightClick();
|
void OnTreeRightClick(const QPoint & pos);
|
||||||
void OnTreeChange (QTreeWidgetItem * item, int column);
|
void OnTreeChange (QTreeWidgetItem * item, int column);
|
||||||
void OnMenuGenerate();
|
void OnMenuGenerate();
|
||||||
void OnMenuDelete();
|
void OnMenuDelete();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user