First version of SearchPanel (+ code migration for GridAccount)
This commit is contained in:
190
src/view/SearchPanel.cpp
Normal file
190
src/view/SearchPanel.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
Copyright 2010 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 "AccountPanel.h"
|
||||
|
||||
enum {SEARCH_ID, GRID_ID};
|
||||
|
||||
BEGIN_EVENT_TABLE(SearchPanel, wxPanel)
|
||||
EVT_BUTTON(SEARCH_ID, SearchPanel::OnButtonSearch)
|
||||
EVT_SHOW(SearchPanel::OnShow)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
||||
{ \
|
||||
_grid->SetCellBackgroundColour(row, i, color); \
|
||||
}
|
||||
|
||||
SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*parent)), _kiss(kiss), _wxUI(parent), _operations(NULL)
|
||||
{
|
||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
DEFAULT_FONT(font);
|
||||
User* user = _kiss->GetUser();
|
||||
std::vector<Account>::iterator accountIt;
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
|
||||
SetSizer(vbox);
|
||||
|
||||
_checkDescription = new wxCheckBox(this, wxID_ANY, _("Description"));
|
||||
_checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from"));
|
||||
_checkDateTo = new wxCheckBox(this, wxID_ANY, _("Date to"));
|
||||
_checkAmountFrom = new wxCheckBox(this, wxID_ANY, _("Amount from"));
|
||||
_checkAmountTo = new wxCheckBox(this, wxID_ANY, _("Amount to"));
|
||||
_checkCategory = new wxCheckBox(this, wxID_ANY, _("Category"));
|
||||
_checkAccount = new wxCheckBox(this, wxID_ANY, _("Account"));
|
||||
|
||||
wxGridBagSizer *gridBagSizer = new wxGridBagSizer(3, 9);
|
||||
|
||||
_calendarFrom = new wxCalendarCtrl(this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize,
|
||||
wxCAL_MONDAY_FIRST);
|
||||
_calendarTo = new wxCalendarCtrl(this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize,
|
||||
wxCAL_MONDAY_FIRST);
|
||||
|
||||
|
||||
_description = new wxTextCtrl(this, wxID_ANY);
|
||||
wxSize size = _description->GetSize();
|
||||
size.SetWidth(size.GetWidth()*2);
|
||||
_description->SetMinSize(size);
|
||||
_amountFrom = new wxTextCtrl(this, wxID_ANY);
|
||||
_amountTo = new wxTextCtrl(this, wxID_ANY);
|
||||
|
||||
_category = new wxCheckListBox(this, wxID_ANY);
|
||||
for(categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++)
|
||||
_category->Append(categoryIt->name);
|
||||
_account = new wxCheckListBox(this, wxID_ANY);
|
||||
for(accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++)
|
||||
_account->Append(accountIt->name);
|
||||
|
||||
_searchButton = new wxButton(this, SEARCH_ID, _("Search"));
|
||||
|
||||
gridBagSizer->Add(_checkDescription, wxGBPosition(0, 0));
|
||||
gridBagSizer->Add(_description, wxGBPosition(1, 0));
|
||||
gridBagSizer->Add(_checkDateFrom, wxGBPosition(0, 1));
|
||||
gridBagSizer->Add(_calendarFrom, wxGBPosition(1, 1));
|
||||
gridBagSizer->Add(_checkDateTo, wxGBPosition(0, 2));
|
||||
gridBagSizer->Add(_calendarTo, wxGBPosition(1, 2));
|
||||
gridBagSizer->Add(_checkAmountFrom, wxGBPosition(0, 3));
|
||||
gridBagSizer->Add(_amountFrom, wxGBPosition(1, 3));
|
||||
gridBagSizer->Add(_checkAmountTo, wxGBPosition(0, 4));
|
||||
gridBagSizer->Add(_amountTo, wxGBPosition(1, 4));
|
||||
gridBagSizer->Add(_checkCategory, wxGBPosition(0, 5));
|
||||
gridBagSizer->Add(_category, wxGBPosition(1, 5));
|
||||
gridBagSizer->Add(_checkAccount, wxGBPosition(0, 6));
|
||||
gridBagSizer->Add(_account, wxGBPosition(1, 6));
|
||||
gridBagSizer->Add(_searchButton, wxGBPosition(2, 0));
|
||||
|
||||
vbox->Add(gridBagSizer);
|
||||
vbox->Add(-1, 20);
|
||||
|
||||
_grid = new GridAccount(_kiss, this, GRID_ID);
|
||||
|
||||
vbox->Add(_grid);
|
||||
|
||||
Fit();
|
||||
|
||||
SetMinSize(wxSize(1024, 640));
|
||||
SetScrollbars(10, 10, 100/10, 100/10);
|
||||
|
||||
Hide();
|
||||
}
|
||||
|
||||
SearchPanel::~SearchPanel()
|
||||
{
|
||||
if (_operations) delete _operations;
|
||||
}
|
||||
|
||||
void SearchPanel::OnButtonSearch(wxCommandEvent& event)
|
||||
{
|
||||
wxString *description=NULL, *amountFrom=NULL, *amountTo=NULL;
|
||||
std::vector<wxString> categories, accounts;
|
||||
wxDateTime *dateFrom=NULL, *dateTo=NULL, *dateTmp;
|
||||
User* user= _kiss->GetUser();
|
||||
int i;
|
||||
std::vector<Operation>::iterator it;
|
||||
|
||||
_grid->DeleteRows(1, _grid->GetNumberRows()-1);
|
||||
|
||||
if (_checkDescription->IsChecked())
|
||||
{
|
||||
description = new wxString;
|
||||
*description = _description->GetLineText(0);
|
||||
}
|
||||
|
||||
if (_checkDateFrom->IsChecked())
|
||||
{
|
||||
dateFrom = new wxDateTime;
|
||||
*dateFrom = _calendarFrom->GetDate();
|
||||
}
|
||||
|
||||
if (_checkDateTo->IsChecked())
|
||||
{
|
||||
dateTo = new wxDateTime;
|
||||
*dateTo = _calendarTo->GetDate();
|
||||
}
|
||||
|
||||
if (dateFrom && dateTo && *dateFrom > *dateTo)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (_checkAmountFrom->IsChecked())
|
||||
{
|
||||
amountFrom = new wxString;
|
||||
*amountFrom = _amountFrom->GetLineText(0);
|
||||
}
|
||||
|
||||
if (_checkAmountTo->IsChecked())
|
||||
{
|
||||
amountTo = new wxString;
|
||||
*amountTo = _amountTo->GetLineText(0);
|
||||
}
|
||||
|
||||
if (_checkCategory->IsChecked())
|
||||
{
|
||||
for(i=0; i<user->GetCategoriesNumber(); i++)
|
||||
if (_category->IsChecked(i))
|
||||
categories.push_back(user->_categories[i].id);
|
||||
}
|
||||
|
||||
if (_checkAccount->IsChecked())
|
||||
{
|
||||
for(i=0; i<user->GetAccountsNumber(); i++)
|
||||
if (_account->IsChecked(i))
|
||||
accounts.push_back(user->_accounts[i].id);
|
||||
}
|
||||
|
||||
if (_operations)
|
||||
delete _operations;
|
||||
|
||||
_operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts);
|
||||
|
||||
for(i=1, it = _operations->begin(); it != _operations->end(); it++, i++)
|
||||
{
|
||||
_grid->InsertOperation(user, &(*it), i, false, 0, 0);
|
||||
}
|
||||
|
||||
_wxUI->Layout();
|
||||
}
|
||||
|
||||
void SearchPanel::OnShow(wxShowEvent& event)
|
||||
{
|
||||
_wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + _("Search"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user