Work on PreferencesPanel and fix a bug in Database (bad request for AddOperation)

This commit is contained in:
Grégory Soutadé 2012-01-07 09:21:22 +01:00
parent fda8f32fd7
commit a71638ace6
4 changed files with 212 additions and 166 deletions

View File

@ -591,12 +591,12 @@ int Database::AddOperation(User* user, Operation& op, bool checkTransfert)
ESCAPE_CHARS(op.description); ESCAPE_CHARS(op.description);
req = "INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert', 'meta', 'virtual') VALUES ('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8'" ; req = "INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert', 'meta', 'virtual', 'checked') VALUES ('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8'" ;
req = req.arg(QString::number(user->_id), (op.parent) ? QString::number(op.parent): "", QString::number(op.account), QString::number(op.year), req = req.arg(QString::number(user->_id), (op.parent) ? QString::number(op.parent): "", QString::number(op.account), QString::number(op.year),
QString::number(op.month), QString::number(op.day), DoubleToString(op.amount), op.description); QString::number(op.month), QString::number(op.day), DoubleToString(op.amount), op.description);
req += ", '%1', '%2', '%3', '%4', '%5', '%6')"; req += ", '%1', '%2', '%3', '%4', '%5', '%6', '%7')";
req = req.arg(QString::number(op.category), QString::number(op.fix_cost), op.formula, (op.transfert) ? QString::number(op.transfert): "", req = req.arg(QString::number(op.category), QString::number(op.fix_cost), op.formula, (op.transfert) ? QString::number(op.transfert): "",
QString::number(op.meta), QString::number(op._virtual)); QString::number(op.meta), QString::number(op._virtual), QString::number(op.checked));
if (!query.exec(req)) if (!query.exec(req))
{ {

View File

@ -18,7 +18,7 @@
*/ */
// #include "PasswordDialog.hpp" #include "PasswordDialog.hpp"
#include "PreferencesPanel.hpp" #include "PreferencesPanel.hpp"
#include "grid/StarDelegate.hpp" #include "grid/StarDelegate.hpp"
@ -133,6 +133,8 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : KissPanel(ki
InitCategories(user); InitCategories(user);
connect(_categoriesGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnCategoryModified(int, int)));
vbox->addWidget(staticCategories); vbox->addWidget(staticCategories);
// Operation Order // Operation Order
@ -361,7 +363,9 @@ void PreferencesPanel::InitCategories(User* user)
if (!_categoriesGrid->item(curLine, i)) if (!_categoriesGrid->item(curLine, i))
_categoriesGrid->setItem(curLine, i, new QTableWidgetItem("")); _categoriesGrid->setItem(curLine, i, new QTableWidgetItem(""));
SET_READ_ONLY(curLine, CATEGORY_NAME); SET_READ_ONLY(curLine, CATEGORY_BACKGROUND_COLOR);
SET_READ_ONLY(curLine, CATEGORY_FOREGROUND_COLOR);
SET_READ_ONLY(curLine, CATEGORY_FONT);
SET_READ_ONLY(curLine, CATEGORY_DELETE); SET_READ_ONLY(curLine, CATEGORY_DELETE);
cat.id = 0; cat.id = 0;
@ -434,11 +438,13 @@ void PreferencesPanel::AddCategory(int line, Category cat)
void PreferencesPanel::InitLanguage(User* user) void PreferencesPanel::InitLanguage(User* user)
{ {
int i, select=0; int i, select=0;
QListWidgetItem* item;
for (i=0; i<SupportedLanguages::NB_SUPPORTED_LANGUAGES; i++) for (i=0; i<SupportedLanguages::NB_SUPPORTED_LANGUAGES; i++)
{ {
_language->addItem(SupportedLanguages::languages[i].name); item = new QListWidgetItem(SupportedLanguages::languages[i].name);
//_language->setItemWidget(new QListWidgetItem(SupportedLanguages::languages[i].name), QIcon(SupportedLanguages::languages[i].icon)); item->setIcon(QIcon(SupportedLanguages::languages[i].icon)),
_language->addItem(item);
if (SupportedLanguages::languages[i].language == _wxUI->_language) if (SupportedLanguages::languages[i].language == _wxUI->_language)
select = i; select = i;
@ -607,16 +613,139 @@ void PreferencesPanel::OnAccountDeleteClicked(int id)
} }
void PreferencesPanel::OnCategoryDeleteClicked(int id) void PreferencesPanel::OnCategoryDeleteClicked(int id)
{} {
QStringList categories;
int i, row;
QString res;
User* user = _kiss->GetUser();
bool ok;
QCheckBox* checkBox = qobject_cast<QCheckBox*> (_deleteCategorySignalMapper.mapping(id));
Category category;
std::vector<Category>::iterator it;
if (_inModification) return;
it = std::find(user->_categories.begin(), user->_categories.end(), id);
if (it == user->_categories.end()) return ;
_inModification = true;
row = it-user->_categories.begin();
category = user->_categories[row];
categories << _("None");
for(i=0; i < user->GetCategoriesNumber(); i++)
if (user->_categories[i].id != id)
categories << _(user->_categories[i].name.toStdString().c_str());
res = QInputDialog::getItem(this, "KissCount", _("Wich category will replace this one ?"), categories, 0, false, &ok);
if (!ok)
{
checkBox->setCheckState(Qt::Unchecked);
_inModification = false;
return;
}
else
{
i = categories.indexOf(res);
_kiss->DeleteCategory(category, (!i) ? 0 : user->GetCategoryId(categories[i]));
_categoriesGrid->removeRow(row);
_wxUI->NeedReload();
}
_inModification = false;
}
void PreferencesPanel::OnBackgroundColorClicked(int id) void PreferencesPanel::OnBackgroundColorClicked(int id)
{} {
User* user = _kiss->GetUser();
QColor color;
std::vector<Category>::iterator it;
int row;
it = std::find(user->_categories.begin(), user->_categories.end(), id);
if (it == user->_categories.end()) return ;
row = it-user->_categories.begin();
_inModification = true ;
color = QColorDialog::getColor(user->_categories[row].backcolor);
if (color.isValid())
{
user->_categories[row].backcolor = color;
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor);
_wxUI->NeedReload();
}
_inModification = false ;
}
void PreferencesPanel::OnForegroundClicked(int id) void PreferencesPanel::OnForegroundClicked(int id)
{} {
User* user = _kiss->GetUser();
QColor color;
std::vector<Category>::iterator it;
int row;
it = std::find(user->_categories.begin(), user->_categories.end(), id);
if (it == user->_categories.end()) return ;
row = it-user->_categories.begin();
_inModification = true ;
color = QColorDialog::getColor(user->_categories[row].forecolor);
if (color.isValid())
{
user->_categories[row].forecolor = color;
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor);
_wxUI->NeedReload();
}
_inModification = false ;
}
void PreferencesPanel::OnFontClicked(int id) void PreferencesPanel::OnFontClicked(int id)
{} {
User* user = _kiss->GetUser();
bool ok;
QFont font;
std::vector<Category>::iterator it;
int row;
it = std::find(user->_categories.begin(), user->_categories.end(), id);
if (it == user->_categories.end()) return ;
row = it-user->_categories.begin();
_inModification = true ;
font = QFontDialog::getFont(&ok, user->_categories[row].font);
if (ok)
{
user->_categories[row].font = KissCount::CompactFont(font);
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_FONT(row, font);
_wxUI->NeedReload();
}
_inModification = false ;
}
void PreferencesPanel::OnAccountModified(int row, int col) void PreferencesPanel::OnAccountModified(int row, int col)
{ {
@ -766,170 +895,88 @@ void PreferencesPanel::OnSharedChange(QListWidgetItem *item)
_wxUI->NeedReload(); _wxUI->NeedReload();
} }
void PreferencesPanel::OnCategoryModified() void PreferencesPanel::OnCategoryModified(int row, int col)
{ {
// int op_complete = 1; int op_complete = 1;
// wxString value; QString value;
// User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
// int row = event.GetRow(); static bool _inModification = false ;
// int col = event.GetCol(); Category new_cat, old_cat;
// static bool _inModification = false ; int new_id;
// Category new_cat, cat_tmp; QTableWidgetItem* item = _categoriesGrid->item(row, col);
// int i, a;
// if (_inModification) return; if (_inModification) return;
// _inModification = true; _inModification = true;
// if (event.GetCol() == CATEGORY_BACKGROUND_COLOR) value = item->text();
// { if (value.size())
// wxColourData color; {
// color.SetColour(wxColor(user->_categories[row].backcolor)); new_cat.name = value;
// wxColourDialog dial(this, &color); op_complete--;
}
// if (dial.ShowModal() == wxID_OK) new_cat.backcolor = item->background().color();
// { new_cat.forecolor = item->foreground().color();
// user->_categories[row].backcolor = dial.GetColourData().GetColour(); new_cat.font = "";
// _kiss->UpdateCategory(user->_categories[row]); new_cat.parent = 0;
// SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor);
// _wxUI->NeedReload();
// }
// _inModification = false ; // Categories modification
// return ; if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber())
// } {
old_cat = user->_categories[row];
new_cat.id = user->_categories[row].id;
new_cat.fix_cost = user->_categories[row].fix_cost;
new_cat.backcolor = old_cat.backcolor;
new_cat.forecolor = old_cat.forecolor;
new_cat.font = old_cat.font;
new_cat.parent = old_cat.parent;
// if (event.GetCol() == CATEGORY_FOREGROUND_COLOR) new_id = user->GetCategoryId(new_cat.name);
// { if (new_id != 0 && new_id != new_cat.id)
// wxColourData color; {
// color.SetColour(wxColor(user->_categories[row].forecolor)); QMessageBox::critical(0, _("Error"), _("Category ")+new_cat.name+_(" already exists"));
// wxColourDialog dial(this, &color); _categoriesGrid->setItem(row, CATEGORY_NAME, new QTableWidgetItem(_(user->_categories[row].name.toStdString().c_str())));
_inModification = false;
return ;
}
// if (dial.ShowModal() == wxID_OK) _kiss->UpdateCategory(new_cat);
// { }
// user->_categories[row].forecolor = dial.GetColourData().GetColour(); // New category
// _kiss->UpdateCategory(user->_categories[row]); else
{
// SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor); if (op_complete)
// _wxUI->NeedReload(); {
// } _inModification = false;
return ;
// _inModification = false ; }
// return ;
// }
// if (event.GetCol() == CATEGORY_FONT)
// {
// wxFontData font;
// font.SetInitialFont(_kiss->ExtractFont(user->_categories[row].font));
// wxFontDialog dial(this, font);
// if (dial.ShowModal() == wxID_OK)
// {
// font = dial.GetFontData();
// user->_categories[row].font = _kiss->CompactFont(font.GetChosenFont());
// _kiss->UpdateCategory(user->_categories[row]);
// SET_ROW_FONT(row, font.GetChosenFont());
// _wxUI->NeedReload();
// }
// _inModification = false ;
// return ;
// }
// value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME);
// if (value.Length())
// {
// new_cat.name = value;
// op_complete--;
// }
// new_cat.backcolor = _categoriesGrid->GetCellBackgroundColour(row, col);
// new_cat.forecolor = _categoriesGrid->GetCellTextColour(row, col);
// new_cat.font = wxT("");
// new_cat.parent = wxT("0");
// // Categories modification
// if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber())
// {
// new_cat.id = user->_categories[row].id;
// new_cat.fix_cost = user->_categories[row].fix_cost;
// if (col == CATEGORY_DELETE)
// {
// wxString *categories = new wxString[user->GetCategoriesNumber()];
// categories[0] = _("None");
// a = 0;
// for(i=0; i < user->GetCategoriesNumber(); i++)
// if (user->_categories[i].id != new_cat.id)
// categories[++a] = wxGetTranslation(user->_categories[i].name);
// wxSingleChoiceDialog dialog(_wxUI, _("Wich category will replace this one ?"), wxT("KissCount"), user->GetCategoriesNumber(), categories);
// if (dialog.ShowModal() == wxID_CANCEL)
// {
// _categoriesGrid->setItem(row, col, wxT("0"));
// }
// else
// {
// _categoriesGrid->DeleteRows(row, 1);
// i = dialog.GetSelection();
// _kiss->DeleteCategory(user->_categories[row], (!i) ? wxT("0") : user->GetCategoryId(categories[i]));
// Fit();
// _wxUI->NeedReload();
// }
// _inModification = false;
// return;
// }
// value = user->GetCategoryId(new_cat.name);
// if (value != wxT("0") && value != new_cat.id)
// {
// wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK );
// _categoriesGrid->setItem(row, CATEGORY_NAME, user->_categories[row].name);
// _inModification = false;
// return ;
// }
// _kiss->UpdateCategory(new_cat);
// }
// // New category
// else
// {
// if (op_complete)
// {
// _inModification = false;
// return ;
// }
// if (user->GetCategoryId(new_cat.name) != wxT("0")) if (user->GetCategoryId(new_cat.name) != 0)
// { {
// wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); QMessageBox::critical(0, _("Error"), _("Category ")+new_cat.name+_(" already exists"));
// _inModification = false; _inModification = false;
// return ; return ;
// } }
// new_cat.fix_cost = false; new_cat.fix_cost = false;
// _kiss->AddCategory(new_cat); _kiss->AddCategory(new_cat);
// AddCategory(row, new_cat); AddCategory(row, new_cat);
// _categoriesGrid->SetReadOnly(row, CATEGORY_BACKGROUND_COLOR, false); SET_READ_ONLY(row, CATEGORY_BACKGROUND_COLOR);
// _categoriesGrid->SetReadOnly(row, CATEGORY_FOREGROUND_COLOR, false); SET_READ_ONLY(row, CATEGORY_FOREGROUND_COLOR);
// _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false); SET_READ_ONLY(row, CATEGORY_FONT);
// _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false); SET_READ_ONLY(row, CATEGORY_DELETE);
// new_cat.id = wxT("0"); new_cat.id = 0;
// _categoriesGrid->AppendRows(); _categoriesGrid->setRowCount(row+2);
// AddCategory(++row, new_cat); AddCategory(++row, new_cat);
// } }
// Fit(); _wxUI->NeedReload();
// _wxUI->NeedReload();
// _inModification = false; _inModification = false;
// return;
} }
void PreferencesPanel::OnChangeName() void PreferencesPanel::OnChangeName()
@ -961,8 +1008,9 @@ void PreferencesPanel::OnChangeName()
void PreferencesPanel::OnChangePassword() void PreferencesPanel::OnChangePassword()
{ {
// PasswordDialog p(_kiss, _wxUI); PasswordDialog g(_kiss, _wxUI);
// p.ShowModal(); g.setModal(true);
g.exec();
} }
void PreferencesPanel::OnOperationOrderChange(int index) void PreferencesPanel::OnOperationOrderChange(int index)

View File

@ -52,7 +52,7 @@ private slots:
void OnAccountModified(int row, int col); void OnAccountModified(int row, int col);
void OnAccountCellChanged(int row, int col, int, int); void OnAccountCellChanged(int row, int col, int, int);
void OnSharedChange(QListWidgetItem *item); void OnSharedChange(QListWidgetItem *item);
void OnCategoryModified(); void OnCategoryModified(int row, int col);
void OnChangeName(); void OnChangeName();
void OnChangePassword(); void OnChangePassword();
void OnOperationOrderChange(int index); void OnOperationOrderChange(int index);

View File

@ -23,7 +23,7 @@
namespace SupportedLanguages { namespace SupportedLanguages {
#define ICONS_PATH RESSOURCES_ROOT "icons/" #define ICONS_PATH RESSOURCES_ROOT "icons/"
enum wxLanguage {wxLANGUAGE_ENGLISH, wxLANGUAGE_FRENCH} ; enum wxLanguage {wxLANGUAGE_ENGLISH, wxLANGUAGE_FRENCH, NB_SUPPORTED_LANGUAGES} ;
typedef struct { typedef struct {
QString name; QString name;
@ -31,8 +31,6 @@ namespace SupportedLanguages {
wxLanguage language; wxLanguage language;
} language ; } language ;
const int NB_SUPPORTED_LANGUAGES = 2;
static const language languages[NB_SUPPORTED_LANGUAGES] = { static const language languages[NB_SUPPORTED_LANGUAGES] = {
{ "English", ICONS_PATH "/United Kingdom.png", wxLANGUAGE_ENGLISH}, { "English", ICONS_PATH "/United Kingdom.png", wxLANGUAGE_ENGLISH},
{ "Français",ICONS_PATH "/France.png", wxLANGUAGE_FRENCH} { "Français",ICONS_PATH "/France.png", wxLANGUAGE_FRENCH}