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