From 37f03a1da018271db8cd6c3672d34dce249523c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 1 Feb 2012 12:43:43 +0100 Subject: [PATCH] See previous commit --- ressources/init.sql | 2 +- src/model/Account.hpp | 4 ++++ src/model/Database.cpp | 11 +++++----- src/model/Database.hpp | 2 +- src/model/DatabaseUpdate.cpp | 17 ++++++++++++++- src/view/AccountPanel.cpp | 36 ++++++++++++++++++++++++------- src/view/PreferencesPanel.cpp | 40 ++++++++++++++++++++++++++++++++++- src/view/PreferencesPanel.hpp | 3 ++- src/view/grid/GridAccount.cpp | 20 +++++++++++++++--- src/view/grid/GridAccount.hpp | 1 + www/index.php | 1 + 11 files changed, 116 insertions(+), 21 deletions(-) diff --git a/ressources/init.sql b/ressources/init.sql index ab44767..0a07ad6 100644 --- a/ressources/init.sql +++ b/ressources/init.sql @@ -1,6 +1,6 @@ CREATE TABLE kisscount(db_version VARCHAR(20)); CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255)); -CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared CHAR(1), blocked CHAR(1), default_account CHAR(1), virtual CHAR(1)); +CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared CHAR(1), blocked CHAR(1), default_account CHAR(1), virtual CHAR(1), hidden CHAR(1)); CREATE TABLE shared_account(account REFERENCES account(id), user REFERENCES user(id)); CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount FLOAT); CREATE TABLE operation(id INTEGER PRIMARY KEY, parent REFERENCES operation(id), user REFERENCES user(id), account REFERENCES account(id), year INTEGER, month INTEGER, day INTEGER, amount FLOAT, description VARCHAR(255), category REFERENCES category(id), fix_cost CHAR(1), checked CHAR(1), formula VARCHAR(255), transfert REFERENCES operation(id), meta CHAR(1), virtual CHAR(1)); diff --git a/src/model/Account.hpp b/src/model/Account.hpp index 8e79ce8..c384479 100644 --- a/src/model/Account.hpp +++ b/src/model/Account.hpp @@ -29,6 +29,7 @@ struct Account { bool _default; bool is_owner; bool _virtual; + bool hidden; bool operator() (const Account& ac1, const Account& ac2) const { @@ -41,6 +42,9 @@ struct Account { if (!ac1._virtual && ac2._virtual) return true; if (ac1._virtual && !ac2._virtual) return false; + if (!ac1.hidden && ac2.hidden) return true; + if (ac1.hidden && !ac2.hidden) return false; + return ac1.name < ac2.name; } diff --git a/src/model/Database.cpp b/src/model/Database.cpp index e9d2be6..ca058f1 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -233,6 +233,7 @@ static inline void fillAccount(Account* account, const QSqlRecord& set) account->_default = set.value("default_account").toBool(); account->_virtual = set.value("virtual").toBool(); account->is_owner = true; + account->hidden = set.value("hidden").toBool(); } static inline void fillCategory(Category* category, const QSqlRecord& set) @@ -775,10 +776,10 @@ int Database::AddAccount(User* user, Account& ac) QString req; QSqlQuery query(_db); - req = "INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account', 'virtual') VALUES " ; - req += "('%1', '%2', '%3', '%4', '%5', '%6', '%7')"; + req = "INSERT INTO account ('user', 'name', 'number', 'shared', 'blocked', 'default_account', 'virtual', 'hidden') VALUES " ; + req += "('%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8')"; req = req.arg(QString::number(user->_id), ac.name, ac.number, QString::number(ac.shared), QString::number(ac.blocked), - QString::number(ac._default), QString::number(ac._virtual)); + QString::number(ac._default), QString::number(ac._virtual), QString::number(ac.hidden)); if (!query.exec(req)) { @@ -796,9 +797,9 @@ void Database::UpdateAccount(Account& ac) { QString req; - req = "UPDATE account SET name='%1', number='%2', shared='%3', blocked='%4', default_account='%5', virtual='%6' WHERE id='%7'" ; + req = "UPDATE account SET name='%1', number='%2', shared='%3', blocked='%4', default_account='%5', virtual='%6', hidden='%7' WHERE id='%8'" ; req = req.arg(ac.name, ac.number, QString::number(ac.shared), QString::number(ac.blocked), QString::number(ac._default), - QString::number(ac._virtual), QString::number(ac.id)); + QString::number(ac._virtual), QString::number(ac.hidden), QString::number(ac.id)); EXECUTE_SQL_UPDATE(req, ); diff --git a/src/model/Database.hpp b/src/model/Database.hpp index 609759d..a685234 100644 --- a/src/model/Database.hpp +++ b/src/model/Database.hpp @@ -81,7 +81,7 @@ public: static const int NOT_CHECKED_OP = (1 << 3); static const int ALL_OP = (~0); - static const int VERSION = 2; + static const int VERSION = 3; Database(const char* filename, KissCount* kiss); diff --git a/src/model/DatabaseUpdate.cpp b/src/model/DatabaseUpdate.cpp index 2a1c375..b631db3 100644 --- a/src/model/DatabaseUpdate.cpp +++ b/src/model/DatabaseUpdate.cpp @@ -78,8 +78,23 @@ static void Version_1_to_2(QSqlDatabase& _db) UPDATE_TABLE("1", "2", "8"); } +static void Version_2_to_3(QSqlDatabase& _db) +{ + QString req ; + + /* Account */ + req = "ALTER TABLE account ADD hidden CHAR(1)"; + + UPDATE_TABLE("2", "3", "1"); + + req = "UPDATE account SET hidden='0'"; + + UPDATE_TABLE("2", "3", "2"); +} + static update_func updates[] = { - Version_1_to_2 + Version_1_to_2, + Version_2_to_3 }; void Database::CheckDatabaseVersion() diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index f66de3b..a58e8b6 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -454,7 +454,7 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year) std::vector::iterator it; int curLine = 0; double value; - int i, a; + int i, nbAccounts; QTableWidgetItem* item; QString v; DEFAULT_FONT(font); @@ -478,10 +478,24 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year) FloatDelegate* floatEditor = new FloatDelegate(_accountsGrid); _accountsGrid->setItemDelegateForColumn(ACCOUNT_INIT, floatEditor); - _accountsGrid->setRowCount(user->_accounts.size()); - - for (i=0, it = user->_accounts.begin(); it != user->_accounts.end(); i++, it++, curLine++) + nbAccounts = 0; + for (it = user->_accounts.begin(); it != user->_accounts.end(); it++) { + if (!it->hidden) nbAccounts++; + } + + _accountsGrid->setRowCount(nbAccounts); + + for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++) + { + if (it->hidden) + { + value = _kiss->GetAccountAmount(it->id, month, year); + _accountsInitValues[it->id] = value; + curLine--; + continue; + } + if (it->shared) _accountsGrid->setItem(curLine, ACCOUNT_NUMBER, new QTableWidgetItem(it->number + "*")); else @@ -493,12 +507,12 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year) _accountsGrid->setItem(curLine, ACCOUNT_INIT, new QTableWidgetItem(v.sprintf("%.2lf", value))); _accountsGrid->setItem(curLine, ACCOUNT_CUR, new QTableWidgetItem("")); _accountsGrid->setItem(curLine, ACCOUNT_FINAL, new QTableWidgetItem("")); - for (a=0; aitem(curLine, a); - if (a != ACCOUNT_INIT) + item = _accountsGrid->item(curLine, i); + if (i != ACCOUNT_INIT) item->setFlags(item->flags() & ~Qt::ItemIsEditable); - if (a == ACCOUNT_CUR) + if (i == ACCOUNT_CUR) item->setFont(font); } _accountsInitValues[it->id] = value; @@ -736,6 +750,12 @@ void AccountPanel::UpdateStats() for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++) { + if (accountIt->hidden) + { + i--; + continue; + } + if (mode != CHECK_MODE) { value = _accountsInitValues[accountIt->id]; diff --git a/src/view/PreferencesPanel.cpp b/src/view/PreferencesPanel.cpp index 65bb4af..e02b4cc 100644 --- a/src/view/PreferencesPanel.cpp +++ b/src/view/PreferencesPanel.cpp @@ -23,7 +23,7 @@ #include "PreferencesPanel.hpp" #include "grid/StarDelegate.hpp" -enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_VIRTUAL, ACCOUNT_BLOCKED, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT}; +enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_VIRTUAL, ACCOUNT_BLOCKED, ACCOUNT_DELETE, ACCOUNT_HIDDEN, NUMBER_COLS_ACCOUNT}; enum {CATEGORY_NAME, CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY}; PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _sharedWith(0), _curAccountRow(-1), _defaultSignalMapper(this), _virtualSignalMapper(this), _blockedSignalMapper(this), _deleteAccountSignalMapper(this), _deleteCategorySignalMapper(this), _backgroundColorSignalMapper(this), _foregroundColorSignalMapper(this), _fontSignalMapper(this), _inModification(false) @@ -171,6 +171,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : KissPanel(ki connect(&_virtualSignalMapper, SIGNAL(mapped(int)), this, SLOT(OnAccountVirtualClicked(int))); connect(&_blockedSignalMapper, SIGNAL(mapped(int)), this, SLOT(OnAccountBlockedClicked(int))); connect(&_deleteAccountSignalMapper, SIGNAL(mapped(int)), this, SLOT(OnAccountDeleteClicked(int))); + connect(&_hiddenAccountSignalMapper, SIGNAL(mapped(int)), this, SLOT(OnAccountHiddenClicked(int))); connect(&_deleteCategorySignalMapper, SIGNAL(mapped(int)), this, SLOT(OnCategoryDeleteClicked(int))); connect(&_backgroundColorSignalMapper, SIGNAL(mapped(int)), this, SLOT(OnBackgroundColorClicked(int))); @@ -219,6 +220,7 @@ void PreferencesPanel::InitAccounts(User* user) _accountsGrid->setHorizontalHeaderItem(ACCOUNT_VIRTUAL, new QTableWidgetItem(_("Virtual"))); _accountsGrid->setHorizontalHeaderItem(ACCOUNT_BLOCKED, new QTableWidgetItem(_("Blocked"))); _accountsGrid->setHorizontalHeaderItem(ACCOUNT_DELETE, new QTableWidgetItem(_("Delete"))); + _accountsGrid->setHorizontalHeaderItem(ACCOUNT_HIDDEN, new QTableWidgetItem(_("Hidden"))); font.setBold(true); for(int i=0; isetCellWidget(line, ACCOUNT_DELETE, checkBox); _deleteAccountSignalMapper.setMapping(checkBox, ac.id); connect(checkBox, SIGNAL(stateChanged(int)), &_deleteAccountSignalMapper, SLOT(map())); + + checkBox = new QCheckBox(); + checkBox->setCheckState((ac.hidden) ? Qt::Checked : Qt::Unchecked); + _accountsGrid->setCellWidget(line, ACCOUNT_HIDDEN, checkBox); + _hiddenAccountSignalMapper.setMapping(checkBox, ac.id); + connect(checkBox, SIGNAL(stateChanged(int)), &_hiddenAccountSignalMapper, SLOT(map())); for(int i=0; iitem(line, i)) @@ -290,6 +298,7 @@ void PreferencesPanel::AddAccount(int line, Account ac) SET_READ_ONLY(line, ACCOUNT_DEFAULT); SET_READ_ONLY(line, ACCOUNT_VIRTUAL); SET_READ_ONLY(line, ACCOUNT_BLOCKED); + SET_READ_ONLY(line, ACCOUNT_HIDDEN); } else { @@ -309,6 +318,7 @@ void PreferencesPanel::AddAccount(int line, Account ac) SET_READ_ONLY(line, ACCOUNT_VIRTUAL); SET_READ_ONLY(line, ACCOUNT_BLOCKED); SET_READ_ONLY(line, ACCOUNT_DELETE); + SET_READ_ONLY(line, ACCOUNT_HIDDEN); } _accountsGrid->resizeColumnsToContents(); } @@ -511,6 +521,8 @@ void PreferencesPanel::OnAccountDefaultClicked(int id) account = user->_accounts[row]; _inModification = false; + + _wxUI->NeedReload(); } void PreferencesPanel::OnAccountVirtualClicked(int id) @@ -530,6 +542,8 @@ void PreferencesPanel::OnAccountVirtualClicked(int id) account._virtual = (checkBox->checkState() == Qt::Checked); _kiss->UpdateAccount(account); + + _wxUI->NeedReload(); } void PreferencesPanel::OnAccountBlockedClicked(int id) @@ -549,6 +563,8 @@ void PreferencesPanel::OnAccountBlockedClicked(int id) account.blocked = (checkBox->checkState() == Qt::Checked); _kiss->UpdateAccount(account); + + _wxUI->NeedReload(); } void PreferencesPanel::OnAccountDeleteClicked(int id) @@ -612,6 +628,27 @@ void PreferencesPanel::OnAccountDeleteClicked(int id) _wxUI->NeedReload(); } +void PreferencesPanel::OnAccountHiddenClicked(int id) +{ + User* user = _kiss->GetUser(); + QCheckBox* checkBox = qobject_cast (_hiddenAccountSignalMapper.mapping(id)); + std::vector::iterator it; + Account account; + int row; + + it = std::find(user->_accounts.begin(), user->_accounts.end(), id); + + if (it == user->_accounts.end()) return ; + + row = it-user->_accounts.begin(); + account = user->_accounts[row]; + + account.hidden = (checkBox->checkState() == Qt::Checked); + _kiss->UpdateAccount(account); + + _wxUI->NeedReload(); +} + void PreferencesPanel::OnCategoryDeleteClicked(int id) { QStringList categories; @@ -814,6 +851,7 @@ void PreferencesPanel::OnAccountModified(int row, int col) new_account.blocked = false; new_account.is_owner = true; new_account._virtual = false; + new_account.hidden = false; AddAccount(row, new_account); _kiss->AddAccount(new_account); diff --git a/src/view/PreferencesPanel.hpp b/src/view/PreferencesPanel.hpp index a42c1ba..ca6a203 100644 --- a/src/view/PreferencesPanel.hpp +++ b/src/view/PreferencesPanel.hpp @@ -45,6 +45,7 @@ private slots: void OnAccountVirtualClicked(int id); void OnAccountBlockedClicked(int id); void OnAccountDeleteClicked(int id); + void OnAccountHiddenClicked(int id); void OnCategoryDeleteClicked(int id); void OnBackgroundColorClicked(int id); void OnForegroundClicked(int id); @@ -68,7 +69,7 @@ private: QListWidget* _sharedWith; int _curAccountRow; std::map _sharedOwners; - QSignalMapper _defaultSignalMapper, _virtualSignalMapper, _blockedSignalMapper, _deleteAccountSignalMapper, _deleteCategorySignalMapper, _backgroundColorSignalMapper, _foregroundColorSignalMapper, _fontSignalMapper; + QSignalMapper _defaultSignalMapper, _virtualSignalMapper, _blockedSignalMapper, _deleteAccountSignalMapper, _hiddenAccountSignalMapper, _deleteCategorySignalMapper, _backgroundColorSignalMapper, _foregroundColorSignalMapper, _fontSignalMapper; bool _inModification; void InitAccounts(User* user); void InitCategories(User* user); diff --git a/src/view/grid/GridAccount.cpp b/src/view/grid/GridAccount.cpp index 718bac7..8475fe4 100644 --- a/src/view/grid/GridAccount.cpp +++ b/src/view/grid/GridAccount.cpp @@ -92,12 +92,26 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent, label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); setCellWidget(0, CHECKED, label); - _accounts = new QString[user->GetAccountsNumber()]; + _nbAccounts = 0; + for (accountIt = user->_accounts.begin(); + accountIt != user->_accounts.end(); + accountIt++) + { + if (!accountIt->hidden) + _nbAccounts++; + } + + _accounts = new QString[_nbAccounts]; for (i=0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++, i++) - _accounts[i] = accountIt->name; + { + if (!accountIt->hidden) + _accounts[i] = accountIt->name; + else + i--; + } _categories = new QString[user->GetCategoriesNumber()-1] ; for(i=0, categoryIt = user->_categories.begin()+1; @@ -205,7 +219,7 @@ void GridAccount::LoadOperations(std::vector* operations, int month, ChoiceDelegate* categoryEditor = new ChoiceDelegate(this, _categories, user->GetCategoriesNumber()-1); setItemDelegateForColumn(CATEGORY, categoryEditor); - ChoiceDelegate* accountEditor = new ChoiceDelegate(this, _accounts, user->GetAccountsNumber()); + ChoiceDelegate* accountEditor = new ChoiceDelegate(this, _accounts, _nbAccounts); setItemDelegateForColumn(ACCOUNT, accountEditor); DateDelegate* dateEditor = new DateDelegate(this, month+1, year); diff --git a/src/view/grid/GridAccount.hpp b/src/view/grid/GridAccount.hpp index e1da734..f8d52b7 100644 --- a/src/view/grid/GridAccount.hpp +++ b/src/view/grid/GridAccount.hpp @@ -75,6 +75,7 @@ private: bool _setWeek; bool _databaseSynchronization; QString* _categories, *_accounts; + int _nbAccounts; std::vector* _operations; bool _loadOperations; int _curMonth, _curYear; diff --git a/www/index.php b/www/index.php index d0011a1..2d4afe0 100755 --- a/www/index.php +++ b/www/index.php @@ -206,6 +206,7 @@ function toggleOperations(parent, operations) accounts as $i => $account) { + if ($accounts["hidden"] == "1") continue; $val = GetAccountAmount($account["id"], $_SESSION["cur_month"], $_SESSION["cur_year"]); echo ""; if ($account["shared"] == "1")