Move categories from map to vector
This commit is contained in:
@@ -22,7 +22,7 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
||||
DEFAULT_FONT(font);
|
||||
User* user = _kiss->GetUser();
|
||||
std::vector<Account>::iterator accountIt;
|
||||
std::map<wxString, wxString>::iterator it;
|
||||
std::vector<category>::iterator categoryIt;
|
||||
wxColour categoryColors[] = {wxColour(0x00, 0x45, 0x86),
|
||||
wxColour(0xFF, 0x3E, 0x0E),
|
||||
wxColour(0xFF, 0xD3, 0x20),
|
||||
@@ -49,10 +49,12 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
||||
_accounts[i] = accountIt->name;
|
||||
|
||||
_categories = new wxString[user->GetCategoriesNumber()] ;
|
||||
for(i=0, it = user->_preferences._categories.begin(); it != user->_preferences._categories.end(); it++, i++)
|
||||
for(i=0, categoryIt = user->_preferences._categories.begin();
|
||||
categoryIt != user->_preferences._categories.end();
|
||||
categoryIt++, i++)
|
||||
{
|
||||
_categories[i] = it->second ;
|
||||
_categoriesIndexes[it->second] = i;
|
||||
_categories[i] = categoryIt->name ;
|
||||
_categoriesIndexes[categoryIt->name] = i;
|
||||
}
|
||||
|
||||
_dataset = new CategorySimpleDataset(_categories, user->GetCategoriesNumber());
|
||||
@@ -232,7 +234,7 @@ void AccountPanel::ShowMonth(int year, int month)
|
||||
int curLine = 0;
|
||||
User* user = _kiss->GetUser();
|
||||
DEFAULT_FONT(font);
|
||||
std::map<wxString, wxString>::iterator categoryIt;
|
||||
std::vector<category>::iterator categoryIt;
|
||||
//wxGridCellChoiceEditor* categoryEditor, *accountEditor;
|
||||
int i;
|
||||
wxBitmap bitmap(_(DELETE_ICON));
|
||||
@@ -259,30 +261,9 @@ void AccountPanel::ShowMonth(int year, int month)
|
||||
_grid->SetCellAlignment(0, i, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
}
|
||||
_grid->SetCellRenderer(0, DELETE, new wxGridCellBitmapRenderer(bitmap));
|
||||
// SetCellBackgroundColour (int row, int col, const wxColour &colour);
|
||||
// SetCellFont (int row, int col, const wxFont &font);
|
||||
// SetCellValue (int row, int col, const wxString &s);
|
||||
// GetColSize (int col) const ;
|
||||
// SetColSize (int col, int width);
|
||||
// AppendRows (int numRows=1, bool updateLabels=true);
|
||||
// InsertRows (int pos=0, int numRows=1, bool updateLabels=true);
|
||||
// SetReadOnly(row, col, bool)
|
||||
|
||||
it = _curOperations->begin();
|
||||
|
||||
/*
|
||||
struct operation {
|
||||
wxString id;
|
||||
unsigned int day;
|
||||
unsigned int month;
|
||||
unsigned int year;
|
||||
int amount;
|
||||
wxString description;
|
||||
wxString category;
|
||||
bool fix_cost;
|
||||
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, NUMBER_COLS_OPS};
|
||||
} ;
|
||||
*/
|
||||
for (;it->fix_cost && it != _curOperations->end(); it++)
|
||||
InsertOperation(user, &(*it), ++curLine, true);
|
||||
|
||||
@@ -321,7 +302,6 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
|
||||
_grid->SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(-1, 2));
|
||||
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false);
|
||||
_grid->SetCellEditor(line, ACCOUNT, accountEditor);
|
||||
// Remove Fix category
|
||||
wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false);
|
||||
_grid->SetCellEditor(line, CATEGORY, categoryEditor);
|
||||
|
||||
@@ -349,7 +329,7 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
|
||||
_grid->SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
|
||||
_grid->SetCellEditor(line, CHECKED, new wxGridCellBoolEditor ());
|
||||
|
||||
color = user->_preferences._colors[user->GetCategoryName(op->category)];
|
||||
color = user->GetCategory(op->category).color;
|
||||
|
||||
if (op->checked)
|
||||
{
|
||||
@@ -587,7 +567,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
|
||||
|
||||
if (col == CHECKED || col == CATEGORY)
|
||||
{
|
||||
color = user->_preferences._colors[user->GetCategoryName(new_op.category)];
|
||||
color = user->GetCategory(new_op.category).color;
|
||||
|
||||
if (new_op.checked)
|
||||
{
|
||||
|
||||
@@ -130,7 +130,7 @@ void PreferencesPanel::InitAccounts(User* user)
|
||||
|
||||
void PreferencesPanel::InitCategories(User* user)
|
||||
{
|
||||
std::map<wxString, wxString>::iterator it;
|
||||
std::vector<category>::iterator it;
|
||||
int curLine = 0;
|
||||
DEFAULT_FONT(font);
|
||||
|
||||
@@ -147,8 +147,8 @@ void PreferencesPanel::InitCategories(User* user)
|
||||
{
|
||||
_categoriesGrid->AppendRows();
|
||||
|
||||
_categoriesGrid->SetCellValue(curLine, CATEGORY_NAME, it->second);
|
||||
SET_ROW_COLOR(curLine, user->_preferences._colors[it->second]);
|
||||
_categoriesGrid->SetCellValue(curLine, CATEGORY_NAME, it->name);
|
||||
SET_ROW_COLOR(curLine, it->color);
|
||||
if (curLine)
|
||||
{
|
||||
_categoriesGrid->SetCellRenderer(curLine, CATEGORY_DELETE, new wxGridCellBoolRenderer ());
|
||||
@@ -158,8 +158,6 @@ void PreferencesPanel::InitCategories(User* user)
|
||||
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
|
||||
_categoriesIndexes[curLine] = it->second;
|
||||
}
|
||||
|
||||
_categoriesGrid->SetReadOnly(0, CATEGORY_DELETE, true);
|
||||
@@ -172,16 +170,6 @@ void PreferencesPanel::InitCategories(User* user)
|
||||
SET_ROW_COLOR(curLine, OWN_GREEN);
|
||||
}
|
||||
|
||||
/*
|
||||
struct Account {
|
||||
wxString id;
|
||||
wxString name;
|
||||
wxString number;
|
||||
bool shared;
|
||||
bool _default;
|
||||
};
|
||||
|
||||
*/
|
||||
void PreferencesPanel::OnAccountModified(wxGridEvent& event)
|
||||
{
|
||||
int op_complete = 2;
|
||||
@@ -323,11 +311,12 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
|
||||
void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
||||
{
|
||||
int op_complete = 1;
|
||||
wxString value, categoryName ;
|
||||
wxString value;
|
||||
User* user = _kiss->GetUser();
|
||||
int row = event.GetRow();
|
||||
int col = event.GetCol();
|
||||
static bool inModification = false ;
|
||||
struct category new_cat;
|
||||
|
||||
if (inModification) return;
|
||||
|
||||
@@ -336,32 +325,34 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
||||
value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME);
|
||||
if (value != _(""))
|
||||
{
|
||||
categoryName = value;
|
||||
new_cat.name = value;
|
||||
op_complete--;
|
||||
}
|
||||
|
||||
new_cat.color = _categoriesGrid->GetCellBackgroundColour(row, col);
|
||||
|
||||
// Categories modification
|
||||
if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber())
|
||||
{
|
||||
new_cat.id = user->_preferences._categories[row].id;
|
||||
if (col == CATEGORY_DELETE)
|
||||
{
|
||||
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+categoryName, _("KissCount"), wxYES_NO);
|
||||
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_cat.name, _("KissCount"), wxYES_NO);
|
||||
if (dialog.ShowModal() == wxID_NO)
|
||||
{
|
||||
_categoriesGrid->SetCellValue(row, col, _("0"));
|
||||
}
|
||||
else
|
||||
{
|
||||
_categoriesIndexes.erase(row);
|
||||
_categoriesGrid->DeleteRows(row, 1);
|
||||
_kiss->DeleteCategory(categoryName);
|
||||
_kiss->DeleteCategory(user->_preferences._categories[row]);
|
||||
}
|
||||
|
||||
_wxUI->Layout();
|
||||
inModification = false;
|
||||
return;
|
||||
}
|
||||
_kiss->UpdateCategory(_categoriesIndexes[row], categoryName, _categoriesGrid->GetCellBackgroundColour(row, col));
|
||||
_kiss->UpdateCategory(user->_preferences._categories[row].name, new_cat);
|
||||
}
|
||||
// New category
|
||||
else
|
||||
@@ -372,8 +363,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
||||
return ;
|
||||
}
|
||||
|
||||
_categoriesIndexes[row] = categoryName;
|
||||
_kiss->AddCategory(categoryName, _categoriesGrid->GetCellBackgroundColour(row, col));
|
||||
_kiss->AddCategory(new_cat);
|
||||
_categoriesGrid->SetReadOnly(row, CATEGORY_COLOR, false);
|
||||
_categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false);
|
||||
_categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false);
|
||||
@@ -390,6 +380,8 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
||||
_categoriesGrid->SetReadOnly(row, CATEGORY_FONT, true);
|
||||
_categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, true);
|
||||
SET_ROW_COLOR(row, OWN_GREEN);
|
||||
|
||||
_wxUI->Layout();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -30,7 +30,6 @@ private:
|
||||
wxUI* _wxUI;
|
||||
wxGrid* _accountsGrid;
|
||||
wxGrid* _categoriesGrid;
|
||||
std::map<int, wxString> _categoriesIndexes;
|
||||
|
||||
void InitAccounts(User* user);
|
||||
void InitCategories(User* user);
|
||||
|
||||
Reference in New Issue
Block a user