Enable account initial value modification

Fix a bug : accounts table header reset in InitAccounts
This commit is contained in:
Grégory Soutadé 2011-10-30 09:27:03 +01:00
parent 42b1b3b85d
commit 4441ea1810
2 changed files with 36 additions and 30 deletions

View File

@ -61,7 +61,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
_calendar->setGridVisible(false);
_calendar->setFirstDayOfWeek(Qt::Monday);
_calendar->setNavigationBarVisible(false);
_calendar->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
_calendar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
_accounts = new QString[user->GetAccountsNumber()];
@ -103,21 +104,10 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
_accountsGrid->setRowCount(0);
_accountsGrid->verticalHeader()->setHidden(true);
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_NUMBER, new QTableWidgetItem(_("Account number")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_NAME, new QTableWidgetItem(_("Account name")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_INIT, new QTableWidgetItem(_("Initial value")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_CUR, new QTableWidgetItem(_("Current value")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_FINAL, new QTableWidgetItem(_("Final value")));
_accountsGrid->resizeColumnsToContents();
_accountsGrid->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
for(i=0; i<NUMBER_COLS_ACCOUNTS; i++)
{
QFont font = _accountsGrid->horizontalHeaderItem(i)->font();
font.setBold(true);
_accountsGrid->horizontalHeaderItem(i)->setFont(font);
}
connect(_accountsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnAccountModified(int, int)));
_statsGrid = new QTableWidget(this);
_statsGrid->verticalHeader()->setHidden(true);
@ -420,8 +410,12 @@ void AccountPanel::ShowMonth(int month, int year)
_grid->LoadOperations(_curOperations, _curMonth, _curYear);
disconnect(_accountsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnAccountModified(int, int)));
InitAccountsGrid(user, month, year);
connect(_accountsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnAccountModified(int, int)));
dateStart.setDate(dateStart.year(), dateStart.month(), 1);
dateEnd.setDate(dateEnd.year(), dateEnd.month(), dateStart.daysInMonth());
_calendar->setDateRange(dateStart, dateEnd);
@ -450,6 +444,19 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
if (_accountsGrid->rowCount())
_accountsGrid->clear();
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_NUMBER, new QTableWidgetItem(_("Account number")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_NAME, new QTableWidgetItem(_("Account name")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_INIT, new QTableWidgetItem(_("Initial value")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_CUR, new QTableWidgetItem(_("Current value")));
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_FINAL, new QTableWidgetItem(_("Final value")));
for(i=0; i<NUMBER_COLS_ACCOUNTS; i++)
{
QFont font = _accountsGrid->horizontalHeaderItem(i)->font();
font.setBold(true);
_accountsGrid->horizontalHeaderItem(i)->setFont(font);
}
FloatDelegate* floatEditor = new FloatDelegate(_accountsGrid);
_accountsGrid->setItemDelegateForColumn(ACCOUNT_INIT, floatEditor);
@ -750,27 +757,26 @@ void AccountPanel::OnOperationModified()
layout();
}
void AccountPanel::OnAccountModified()
void AccountPanel::OnAccountModified(int row, int column)
{
// User* user = _kiss->GetUser();
// int row = event.GetRow();
// double amount;
// wxString id = user->GetAccountId(_accounts[row]);
User* user = _kiss->GetUser();
double amount;
int id = user->GetAccountId(_accounts[row]);
static bool inModification = false;
// static bool inModification = false;
if (inModification || column != ACCOUNT_INIT) return;
inModification = true;
// if (inModification) return ;
amount = _accountsGrid->item(row, column)->text().toDouble();
_kiss->SetAccountAmount(id, _curMonth, _curYear, amount);
_accountsInitValues[id] = amount;
// inModification = true;
UpdateStats();
// _accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount);
// _kiss->SetAccountAmount(id, _curMonth, _curYear, amount);
// _accountsInitValues[id] = amount;
// UpdateStats();
// inModification = false;
inModification = false;
}
void AccountPanel::OnTreeRightClick()

View File

@ -65,7 +65,7 @@ public:
private slots:
void OnOperationModified();
void OnAccountModified();
void OnAccountModified(int row, int column);
void OnTreeRightClick();
void OnTreeChange (QTreeWidgetItem * item, int column);
void OnMenuGenerate();