Add PreferencesPanel (incomplete)

This commit is contained in:
Grégory Soutadé 2011-12-18 13:51:04 +01:00
parent 9b0222323a
commit 649bdb32c7
12 changed files with 1217 additions and 19 deletions

View File

@ -190,8 +190,8 @@ void KissCount::UpdateAccount(Account& ac)
_db->UpdateAccount(ac);
_user->UpdateAccount(ac);
if (ac._default)
std::sort(_user->_accounts.begin(), _user->_accounts.end(), Account());
// if (ac._default)
// std::sort(_user->_accounts.begin(), _user->_accounts.end(), Account());
}
void KissCount::DeleteAccount(Account& ac, int replacement)

View File

@ -856,6 +856,8 @@ void Database::AddSharedAccount(Account& ac, const QString& granted)
req = QString("INSERT INTO shared_account ('account', 'user') VALUES ('%1', '%2')").arg(QString::number(ac.id), set.value("id").toString());
query.clear();
EXECUTE_SQL_UPDATE(req, );
if (!ac.shared)
@ -1638,7 +1640,7 @@ std::map<QString, QString> Database::getSharedAccountOwners(int account)
std::map<QString, QString> res;
QSqlRecord set, set2;
QSqlQuery query(_db);
QString req;
QString req, user;
req = QString("SELECT user FROM shared_account WHERE account='%1'").arg(account);
@ -1648,15 +1650,20 @@ std::map<QString, QString> Database::getSharedAccountOwners(int account)
{
set = query.record();
user = set.value("user").toString();
req = QString("SELECT name FROM user WHERE id='%1'").arg(set.value("user").toString());
query.clear();
EXECUTE_SQL_QUERY(req, res);
set2 = query.record();
if (query.next())
{
set2 = query.record();
res[set2.value("name").toString()] = set.value("user").toString();
res[set2.value("name").toString()] = user;
}
}
return res;
@ -1682,9 +1689,12 @@ QString Database::getSharedAccountOwner(int account)
EXECUTE_SQL_QUERY(req, "");
set = query.record();
return set.value("name").toString();
if (query.next())
{
set = query.record();
return set.value("name").toString();
}
}
return "";

View File

@ -281,9 +281,8 @@ bool User::Group(std::vector<Operation>* ops, const Operation& op)
if (it->id == op.parent)
{
it2 = std::find(it->childs.begin(), it->childs.end(), op.id);
// Already into childs
if (it2 != it->childs.end()) return true;
it->childs.push_back(op.id);
if (it2 == it->childs.end())
it->childs.push_back(op.id);
return true;
}
}
@ -293,10 +292,14 @@ bool User::Group(std::vector<Operation>* ops, const Operation& op)
void User::Group(const Operation& op)
{
std::vector<Operation>::iterator it;
if (!Group(&(*_operations[op.year])[op.month], op)
&& _db->LoadOperation(this, op.parent))
{
(*_operations[op.year])[op.month][(*_operations[op.year])[op.month].size()-1].childs.push_back(op.id);
it = std::find ((*_operations[op.year])[op.month].begin(), (*_operations[op.year])[op.month].end(), op.parent);
if (it != (*_operations[op.year])[op.month].end())
it->childs.push_back(op.id);
}
}

View File

@ -451,7 +451,6 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
for(i=0; i<NUMBER_COLS_ACCOUNTS; i++)
{
_accountsGrid->horizontalHeaderItem(i)->font();
_accountsGrid->horizontalHeaderItem(i)->setFont(font);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,82 @@
/*
Copyright 2010-2011 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/>.
*/
#ifndef PREFERENCESPANEL_H
#define PREFERENCESPANEL_H
#include <QtGui>
#include "SupportedLanguages.hpp"
#include "view.hpp"
#include <model/model.hpp>
class PreferencesPanel: public KissPanel
{
Q_OBJECT;
public:
PreferencesPanel(KissCount* kiss, wxUI *parent);
KissPanel* CreatePanel();
QPushButton* GetButton();
QString GetToolTip();
void OnShow();
void ChangeUser();
private slots:
void OnAccountDefaultClicked(int id);
void OnAccountVirtualClicked(int id);
void OnAccountBlockedClicked(int id);
void OnAccountDeleteClicked(int id);
void OnCategoryDeleteClicked(int id);
void OnBackgroundColorClicked(int id);
void OnForegroundClicked(int id);
void OnFontClicked(int id);
void OnAccountModified(int row, int col);
void OnAccountCellChanged(int row, int col, int, int);
void OnSharedChange(QListWidgetItem *item);
void OnCategoryModified();
void OnChangeName();
void OnChangePassword();
void OnOperationOrderChange(int index);
void OnLanguageChange();
void OnKillMe();
private:
QTableWidget* _accountsGrid;
QTableWidget* _categoriesGrid;
QLineEdit* _name;
QListWidget* _language;
QComboBox* _operationOrder;
QListWidget* _sharedWith;
int _curAccountRow;
std::map<QString, QString> _sharedOwners;
QSignalMapper _defaultSignalMapper, _virtualSignalMapper, _blockedSignalMapper, _deleteAccountSignalMapper, _deleteCategorySignalMapper, _backgroundColorSignalMapper, _foregroundColorSignalMapper, _fontSignalMapper;
bool _inModification;
void InitAccounts(User* user);
void InitCategories(User* user);
void InitLanguage(User* user);
void InitOperationOrder(User* user);
void AddAccount(int line, Account ac);
void AddCategory(int line, Category cat);
};
#endif

View File

@ -143,6 +143,7 @@ void SearchPanel::OnButtonChangeAccount()
res = QInputDialog::getItem(this, "KissCount", _("Choose a new account"), accounts, 0, false);
if (!res.size()) return ;
a = (res.length()) ? accounts.indexOf(res) : 0;
account = (a) ? user->_accounts[a-1].id : 0;

View File

@ -23,6 +23,8 @@
namespace SupportedLanguages {
#define ICONS_PATH RESSOURCES_ROOT "icons/"
enum wxLanguage {wxLANGUAGE_ENGLISH, wxLANGUAGE_FRENCH} ;
typedef struct {
QString name;
QString icon;

View File

@ -359,13 +359,13 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
setItem(line, CATEGORY, new QTableWidgetItem(_(cat.name.toStdString().c_str())));
checkBox = new QCheckBox();
checkBox->setTristate(false);
checkBox->setCheckState(Qt::Unchecked);
setCellWidget(line, OP_DELETE, checkBox);
_deleteSignalMapper.setMapping(checkBox, op.id);
connect(checkBox, SIGNAL(stateChanged(int)), &_deleteSignalMapper, SLOT(map()));
checkBox = new QCheckBox();
checkBox->setTristate(false);
checkBox->setCheckState((op.checked) ? Qt::Checked : Qt::Unchecked);
setCellWidget(line, CHECKED, checkBox);
_checkSignalMapper.setMapping(checkBox, op.id);
connect(checkBox, SIGNAL(stateChanged(int)), &_checkSignalMapper, SLOT(map()));
@ -389,7 +389,6 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
g = ((color.green()*1.5) >= 0xFF) ? 0xFF : color.green()*1.5 ;
b = ((color.blue()*1.5) >= 0xFF) ? 0xFF : color.blue()*1.5 ;
color.setRgb(r, g, b, color.alpha());
checkBox->setCheckState(Qt::Checked);
}
SET_ROW_COLOR(line, color, cat.forecolor);

View File

@ -0,0 +1,52 @@
/*
Copyright 2010-2011 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 <QtGui>
#include <QString>
#include "StarDelegate.hpp"
QWidget * StarDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
return new QLineEdit(parent);
}
void StarDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLineEdit *line = qobject_cast<QLineEdit *>(editor);
QString value = line->text().trimmed();
if ((*_accounts)[index.row()].shared)
model->setData(index, qVariantFromValue(value+ "*"));
else
model->setData(index, qVariantFromValue(value));
}
void StarDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QLineEdit* line = qobject_cast<QLineEdit *>(editor);
QString s = qVariantValue<QString>(index.data());
if (s.endsWith("*"))
line->setText(s.left(s.size()-1));
else
line->setText(s);
}

View File

@ -0,0 +1,42 @@
/*
Copyright 2010-2011 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/>.
*/
#ifndef STARDELEGATE_H
#define STARDELEGATE_H
#include "TableViewDelegate.hpp"
#include <QString>
class StarDelegate : public TableViewDelegate
{
Q_OBJECT;
public:
StarDelegate(QWidget *parent = 0, std::vector<Account>* accounts=0) : TableViewDelegate(parent), _accounts(accounts) {}
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
private:
std::vector<Account>* _accounts;
};
#endif

View File

@ -21,8 +21,8 @@
#include "AccountPanel.hpp"
#include "SearchPanel.hpp"
/*#include "PreferencesPanel.hpp"
#include "UsersDialog.hpp"
#include "PreferencesPanel.hpp"
/*#include "UsersDialog.hpp"
#include "StatsPanel.hpp"
#include "ImportPanel.hpp"
#include "ExportPanel.hpp"
@ -166,7 +166,7 @@ void wxUI::InitPanels()
ADD_PANEL(AccountPanel);
// ADD_PANEL(StatsPanel, 1);
ADD_PANEL(SearchPanel);
// ADD_PANEL(PreferencesPanel, 3);
ADD_PANEL(PreferencesPanel);
// ADD_PANEL(ImportPanel, 4);
// ADD_PANEL(ExportPanel, 5);
}