Add "start_date" and "end_date" into accounts properties
This commit is contained in:
parent
74ca6a2285
commit
3684c324c0
2
Makefile
2
Makefile
|
@ -16,7 +16,7 @@ CXXFLAGS+=-Wall
|
||||||
ifdef WIN32
|
ifdef WIN32
|
||||||
CXXFLAGS+=-DRESOURCES_ROOT="\"./resources/\"" -static
|
CXXFLAGS+=-DRESOURCES_ROOT="\"./resources/\"" -static
|
||||||
else
|
else
|
||||||
CXXFLAGS+=-DRESOURCES_ROOT="\"$(SHARE_DIR)\"" -ggdb -fPIC
|
CXXFLAGS+=-DRESOURCES_ROOT="\"$(SHARE_DIR)\"" -ggdb -fPIC -O0
|
||||||
# For developpers
|
# For developpers
|
||||||
#CXXFLAGS+=-DRESOURCES_ROOT="\"./resources/\""
|
#CXXFLAGS+=-DRESOURCES_ROOT="\"./resources/\""
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
CREATE TABLE kisscount(db_version VARCHAR(20));
|
CREATE TABLE kisscount(db_version VARCHAR(20));
|
||||||
CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255));
|
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), hidden 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), start DATE, end DATE);
|
||||||
CREATE TABLE shared_account(account REFERENCES account(id), user REFERENCES user(id));
|
CREATE TABLE shared_account(account REFERENCES account(id), user REFERENCES user(id));
|
||||||
CREATE TABLE account_amount(account REFERENCES account(id), year INTEGER, month INTEGER, amount INTEGER, PRIMARY KEY(account, year, month));
|
CREATE TABLE account_amount(account REFERENCES account(id), year INTEGER, month INTEGER, amount INTEGER, PRIMARY KEY(account, year, month));
|
||||||
CREATE TABLE operation(id INTEGER PRIMARY KEY, parent REFERENCES operation(id), user REFERENCES user(id), account REFERENCES account(id) ON DELETE SET NULL, year INTEGER, month INTEGER, day INTEGER, amount INTEGER, description VARCHAR(255), category REFERENCES category(id) ON DELETE SET NULL, fix_cost CHAR(1), checked CHAR(1), formula VARCHAR(255), transfert REFERENCES operation(id), meta CHAR(1), virtual CHAR(1), tag REFERENCES tag(id));
|
CREATE TABLE operation(id INTEGER PRIMARY KEY, parent REFERENCES operation(id), user REFERENCES user(id), account REFERENCES account(id) ON DELETE SET NULL, year INTEGER, month INTEGER, day INTEGER, amount INTEGER, description VARCHAR(255), category REFERENCES category(id) ON DELETE SET NULL, fix_cost CHAR(1), checked CHAR(1), formula VARCHAR(255), transfert REFERENCES operation(id), meta CHAR(1), virtual CHAR(1), tag REFERENCES tag(id));
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#ifndef ACCOUNT_H
|
#ifndef ACCOUNT_H
|
||||||
#define ACCOUNT_H
|
#define ACCOUNT_H
|
||||||
|
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
struct Account {
|
struct Account {
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -30,6 +32,8 @@ struct Account {
|
||||||
bool is_owner;
|
bool is_owner;
|
||||||
bool _virtual;
|
bool _virtual;
|
||||||
bool hidden;
|
bool hidden;
|
||||||
|
QDate start_date;
|
||||||
|
QDate end_date;
|
||||||
|
|
||||||
bool operator() (const Account& ac1, const Account& ac2) const
|
bool operator() (const Account& ac1, const Account& ac2) const
|
||||||
{
|
{
|
||||||
|
@ -52,6 +56,36 @@ struct Account {
|
||||||
{
|
{
|
||||||
return id == accountId;
|
return id == accountId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool validAt(int day, int month, int year)
|
||||||
|
{
|
||||||
|
QDate targetDate = QDate(year, month+1, day+1);
|
||||||
|
|
||||||
|
return (targetDate >= start_date &&
|
||||||
|
targetDate <= end_date);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validAt(int month, int year)
|
||||||
|
{
|
||||||
|
QDate targetDateS = QDate(year, month+1, 01);
|
||||||
|
QDate targetDateE = targetDateS.addMonths(1).addDays(-1);
|
||||||
|
|
||||||
|
return !(end_date < targetDateS ||
|
||||||
|
start_date > targetDateE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validAt(int month_start, int year_start,
|
||||||
|
int month_end, int year_end)
|
||||||
|
{
|
||||||
|
QDate targetDateS = QDate(year_start, month_start+1, 01);
|
||||||
|
QDate targetDateE = QDate(year_end, month_end+1, 01);
|
||||||
|
targetDateE = targetDateE.addMonths(1).addDays(-1);
|
||||||
|
|
||||||
|
return !(end_date < targetDateS ||
|
||||||
|
start_date > targetDateE);
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -210,6 +210,8 @@ static inline void fillAccount(Account* account, const QSqlRecord& set)
|
||||||
account->_virtual = set.value("virtual").toBool();
|
account->_virtual = set.value("virtual").toBool();
|
||||||
account->is_owner = true;
|
account->is_owner = true;
|
||||||
account->hidden = set.value("hidden").toBool();
|
account->hidden = set.value("hidden").toBool();
|
||||||
|
account->start_date = set.value("start").toDate();
|
||||||
|
account->end_date = set.value("end").toDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void fillCategory(Category* category, const QSqlRecord& set)
|
static inline void fillCategory(Category* category, const QSqlRecord& set)
|
||||||
|
@ -812,6 +814,12 @@ void Database::UpdateAccount(Account& ac)
|
||||||
|
|
||||||
EXECUTE_SQL_UPDATE(req, );
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
|
req = "UPDATE account SET start='%1', end='%2' WHERE id='%3'" ;
|
||||||
|
req = req.arg(ac.start_date.toString("yyyy-MM-dd"), ac.end_date.toString("yyyy-MM-dd"),
|
||||||
|
QString::number(ac.id));
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
if (!ac.shared && ac.is_owner)
|
if (!ac.shared && ac.is_owner)
|
||||||
{
|
{
|
||||||
req = QString("DELETE FROM shared_account WHERE account='%1'").arg(ac.id);
|
req = QString("DELETE FROM shared_account WHERE account='%1'").arg(ac.id);
|
||||||
|
|
|
@ -126,7 +126,7 @@ public:
|
||||||
static const int NOT_CHECKED_OP = (1 << 3);
|
static const int NOT_CHECKED_OP = (1 << 3);
|
||||||
static const int ALL_OP = (~0);
|
static const int ALL_OP = (~0);
|
||||||
|
|
||||||
static const int VERSION = 4;
|
static const int VERSION = 5;
|
||||||
|
|
||||||
Database(const char* filename, KissCount* kiss);
|
Database(const char* filename, KissCount* kiss);
|
||||||
|
|
||||||
|
|
|
@ -100,22 +100,38 @@ static void Version_3_to_4(QSqlDatabase& _db)
|
||||||
|
|
||||||
req = "CREATE TABLE tag(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255));";
|
req = "CREATE TABLE tag(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255));";
|
||||||
|
|
||||||
UPDATE_TABLE("2", "3", "1");
|
UPDATE_TABLE("3", "3", "1");
|
||||||
|
|
||||||
/* Account */
|
/* Account */
|
||||||
req = "ALTER TABLE operation ADD tag REFERENCES tag(id)";
|
req = "ALTER TABLE operation ADD tag REFERENCES tag(id)";
|
||||||
|
|
||||||
UPDATE_TABLE("2", "3", "2");
|
UPDATE_TABLE("3", "3", "2");
|
||||||
|
|
||||||
req = "UPDATE operation SET tag='0'";
|
req = "UPDATE operation SET tag='0'";
|
||||||
|
|
||||||
UPDATE_TABLE("2", "3", "3");
|
UPDATE_TABLE("3", "3", "3");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Version_4_to_5(QSqlDatabase& _db)
|
||||||
|
{
|
||||||
|
QString req ;
|
||||||
|
|
||||||
|
/* Account */
|
||||||
|
req = "ALTER TABLE account ADD COLUMN start DATE;";
|
||||||
|
UPDATE_TABLE("4", "5", "5");
|
||||||
|
|
||||||
|
req = "ALTER TABLE account ADD COLUMN end DATE;";
|
||||||
|
UPDATE_TABLE("4", "5", "6");
|
||||||
|
|
||||||
|
req = "UPDATE account SET start='1900-01-01', end='2050-12-31';";
|
||||||
|
UPDATE_TABLE("4", "5", "11");
|
||||||
}
|
}
|
||||||
|
|
||||||
static update_func updates[] = {
|
static update_func updates[] = {
|
||||||
Version_1_to_2,
|
Version_1_to_2,
|
||||||
Version_2_to_3,
|
Version_2_to_3,
|
||||||
Version_3_to_4
|
Version_3_to_4,
|
||||||
|
Version_4_to_5
|
||||||
};
|
};
|
||||||
|
|
||||||
void Database::CheckDatabaseVersion()
|
void Database::CheckDatabaseVersion()
|
||||||
|
|
|
@ -485,14 +485,15 @@ void AccountPanel::InitAccountsGrid(User* user, int month, int year)
|
||||||
nbAccounts = 0;
|
nbAccounts = 0;
|
||||||
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++)
|
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++)
|
||||||
{
|
{
|
||||||
if (!it->hidden) nbAccounts++;
|
if (!it->hidden && it->validAt(month, year))
|
||||||
|
nbAccounts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
_accountsGrid->setRowCount(nbAccounts);
|
_accountsGrid->setRowCount(nbAccounts);
|
||||||
|
|
||||||
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++)
|
for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++)
|
||||||
{
|
{
|
||||||
if (it->hidden)
|
if (it->hidden || !it->validAt(month, year))
|
||||||
{
|
{
|
||||||
value = _kiss->GetAccountAmount(it->id, month, year);
|
value = _kiss->GetAccountAmount(it->id, month, year);
|
||||||
_accountsInitValues[it->id] = value;
|
_accountsInitValues[it->id] = value;
|
||||||
|
@ -670,7 +671,9 @@ void AccountPanel::UpdateStats()
|
||||||
|
|
||||||
for (intIt=curAccountAmounts[i].begin(); intIt!=curAccountAmounts[i].end(); intIt++)
|
for (intIt=curAccountAmounts[i].begin(); intIt!=curAccountAmounts[i].end(); intIt++)
|
||||||
{
|
{
|
||||||
if (user->GetAccount(intIt->first).hidden || user->GetAccount(intIt->first)._virtual)
|
account = user->GetAccount(intIt->first);
|
||||||
|
if (account.hidden || account._virtual ||
|
||||||
|
!account.validAt(i, _curMonth, _curYear))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (curAccountAmounts[i][intIt->first] < minimalValue)
|
if (curAccountAmounts[i][intIt->first] < minimalValue)
|
||||||
|
@ -716,7 +719,7 @@ void AccountPanel::UpdateStats()
|
||||||
|
|
||||||
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
|
for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++)
|
||||||
{
|
{
|
||||||
if (accountIt->hidden)
|
if (accountIt->hidden || !accountIt->validAt(_curMonth, _curYear))
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -30,8 +30,9 @@
|
||||||
|
|
||||||
#include "PreferencesPanel.hpp"
|
#include "PreferencesPanel.hpp"
|
||||||
#include "grid/StarDelegate.hpp"
|
#include "grid/StarDelegate.hpp"
|
||||||
|
#include "grid/CalendarDelegate.hpp"
|
||||||
|
|
||||||
enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_VIRTUAL, ACCOUNT_BLOCKED, ACCOUNT_DELETE, ACCOUNT_HIDDEN, NUMBER_COLS_ACCOUNT};
|
enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_DEFAULT, ACCOUNT_VIRTUAL, ACCOUNT_BLOCKED, ACCOUNT_START, ACCOUNT_END, ACCOUNT_DELETE, ACCOUNT_HIDDEN, NUMBER_COLS_ACCOUNT};
|
||||||
enum {CATEGORY_NAME, CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY};
|
enum {CATEGORY_NAME, CATEGORY_BACKGROUND_COLOR, CATEGORY_FOREGROUND_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY};
|
||||||
enum {TAG_NAME, TAG_DELETE, NUMBER_COLS_TAG};
|
enum {TAG_NAME, TAG_DELETE, NUMBER_COLS_TAG};
|
||||||
|
|
||||||
|
@ -102,14 +103,18 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu
|
||||||
|
|
||||||
_accountsGrid = new QTableWidget();
|
_accountsGrid = new QTableWidget();
|
||||||
|
|
||||||
StarDelegate* starDelegate = new StarDelegate(this, &user->_accounts);
|
CalendarDelegate* calendarDelegate = new CalendarDelegate(this, &user->_accounts, true, _kiss->GetDateFormat());
|
||||||
_accountsGrid->setItemDelegateForColumn(ACCOUNT_NUMBER, starDelegate);
|
_accountsGrid->setItemDelegateForColumn(ACCOUNT_START, calendarDelegate);
|
||||||
|
|
||||||
|
calendarDelegate = new CalendarDelegate(this, &user->_accounts, false, _kiss->GetDateFormat());
|
||||||
|
_accountsGrid->setItemDelegateForColumn(ACCOUNT_END, calendarDelegate);
|
||||||
|
|
||||||
InitAccounts(user);
|
InitAccounts(user);
|
||||||
|
|
||||||
connect(_accountsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnAccountModified(int, int)));
|
connect(_accountsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnAccountModified(int, int)));
|
||||||
connect(_accountsGrid, SIGNAL(currentCellChanged(int, int, int, int)), this, SLOT(OnAccountCellChanged(int, int, int, int)));
|
connect(_accountsGrid, SIGNAL(currentCellChanged(int, int, int, int)), this, SLOT(OnAccountCellChanged(int, int, int, int)));
|
||||||
|
|
||||||
|
|
||||||
staticBoxSizer->addWidget(_accountsGrid);
|
staticBoxSizer->addWidget(_accountsGrid);
|
||||||
|
|
||||||
hbox1->addWidget(staticAccount);
|
hbox1->addWidget(staticAccount);
|
||||||
|
@ -240,6 +245,8 @@ void PreferencesPanel::InitAccounts(User* user)
|
||||||
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_DEFAULT, new QTableWidgetItem(_("Default")));
|
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_DEFAULT, new QTableWidgetItem(_("Default")));
|
||||||
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_VIRTUAL, new QTableWidgetItem(_("Virtual")));
|
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_VIRTUAL, new QTableWidgetItem(_("Virtual")));
|
||||||
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_BLOCKED, new QTableWidgetItem(_("Blocked")));
|
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_BLOCKED, new QTableWidgetItem(_("Blocked")));
|
||||||
|
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_START, new QTableWidgetItem(_("Start")));
|
||||||
|
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_END, new QTableWidgetItem(_("End")));
|
||||||
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_DELETE, new QTableWidgetItem(_("Delete")));
|
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_DELETE, new QTableWidgetItem(_("Delete")));
|
||||||
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_HIDDEN, new QTableWidgetItem(_("Hidden")));
|
_accountsGrid->setHorizontalHeaderItem(ACCOUNT_HIDDEN, new QTableWidgetItem(_("Hidden")));
|
||||||
|
|
||||||
|
@ -304,6 +311,9 @@ void PreferencesPanel::AddAccount(int line, Account ac)
|
||||||
_hiddenAccountSignalMapper.setMapping(checkBox, ac.id);
|
_hiddenAccountSignalMapper.setMapping(checkBox, ac.id);
|
||||||
connect(checkBox, SIGNAL(stateChanged(int)), &_hiddenAccountSignalMapper, SLOT(map()));
|
connect(checkBox, SIGNAL(stateChanged(int)), &_hiddenAccountSignalMapper, SLOT(map()));
|
||||||
|
|
||||||
|
_accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(ac.start_date.toString(_kiss->GetDateFormat())));
|
||||||
|
_accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(ac.end_date.toString(_kiss->GetDateFormat())));
|
||||||
|
|
||||||
for(int i=0; i<NUMBER_COLS_ACCOUNT; i++)
|
for(int i=0; i<NUMBER_COLS_ACCOUNT; i++)
|
||||||
if (!_accountsGrid->item(line, i))
|
if (!_accountsGrid->item(line, i))
|
||||||
_accountsGrid->setItem(line, i, new QTableWidgetItem(""));
|
_accountsGrid->setItem(line, i, new QTableWidgetItem(""));
|
||||||
|
@ -318,6 +328,8 @@ void PreferencesPanel::AddAccount(int line, Account ac)
|
||||||
SET_READ_ONLY(line, ACCOUNT_NUMBER);
|
SET_READ_ONLY(line, ACCOUNT_NUMBER);
|
||||||
SET_READ_ONLY(line, ACCOUNT_DEFAULT);
|
SET_READ_ONLY(line, ACCOUNT_DEFAULT);
|
||||||
SET_READ_ONLY(line, ACCOUNT_VIRTUAL);
|
SET_READ_ONLY(line, ACCOUNT_VIRTUAL);
|
||||||
|
SET_READ_ONLY(line, ACCOUNT_START);
|
||||||
|
SET_READ_ONLY(line, ACCOUNT_END);
|
||||||
SET_READ_ONLY(line, ACCOUNT_BLOCKED);
|
SET_READ_ONLY(line, ACCOUNT_BLOCKED);
|
||||||
SET_READ_ONLY(line, ACCOUNT_HIDDEN);
|
SET_READ_ONLY(line, ACCOUNT_HIDDEN);
|
||||||
}
|
}
|
||||||
|
@ -331,6 +343,11 @@ void PreferencesPanel::AddAccount(int line, Account ac)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
QDate date = QDate::currentDate();
|
||||||
|
_accountsGrid->setItem(line, ACCOUNT_START, new QTableWidgetItem(date.toString(_kiss->GetDateFormat())));
|
||||||
|
date = date.addYears(30);
|
||||||
|
_accountsGrid->setItem(line, ACCOUNT_END, new QTableWidgetItem(date.toString(_kiss->GetDateFormat())));
|
||||||
|
|
||||||
for(int i=0; i<NUMBER_COLS_ACCOUNT; i++)
|
for(int i=0; i<NUMBER_COLS_ACCOUNT; i++)
|
||||||
if (!_accountsGrid->item(line, i))
|
if (!_accountsGrid->item(line, i))
|
||||||
_accountsGrid->setItem(line, i, new QTableWidgetItem(""));
|
_accountsGrid->setItem(line, i, new QTableWidgetItem(""));
|
||||||
|
@ -964,7 +981,7 @@ void PreferencesPanel::OnFontClicked(int id)
|
||||||
|
|
||||||
void PreferencesPanel::OnAccountModified(int row, int col)
|
void PreferencesPanel::OnAccountModified(int row, int col)
|
||||||
{
|
{
|
||||||
int op_complete = 1, new_id;
|
int op_complete = 3, new_id;
|
||||||
QString value ;
|
QString value ;
|
||||||
Account new_account, account;
|
Account new_account, account;
|
||||||
User* user = _kiss->GetUser();
|
User* user = _kiss->GetUser();
|
||||||
|
@ -987,6 +1004,27 @@ void PreferencesPanel::OnAccountModified(int row, int col)
|
||||||
//op_complete--;
|
//op_complete--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value = _accountsGrid->item(row, ACCOUNT_START)->text();
|
||||||
|
if (value.size())
|
||||||
|
{
|
||||||
|
new_account.start_date = QDate::fromString(value, "dd/MM/yyyy");
|
||||||
|
op_complete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = _accountsGrid->item(row, ACCOUNT_END)->text();
|
||||||
|
if (value.size())
|
||||||
|
{
|
||||||
|
new_account.end_date = QDate::fromString(value, "dd/MM/yyyy");
|
||||||
|
op_complete--;
|
||||||
|
|
||||||
|
if (new_account.end_date < new_account.start_date)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(0, _("Error"), _("End date before start date"));
|
||||||
|
_inModification = false;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Account modification
|
// Account modification
|
||||||
if (user->GetAccountsNumber() && row < user->GetAccountsNumber())
|
if (user->GetAccountsNumber() && row < user->GetAccountsNumber())
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,6 +75,7 @@ private:
|
||||||
std::map<QString, QString> _sharedOwners;
|
std::map<QString, QString> _sharedOwners;
|
||||||
QSignalMapper _defaultSignalMapper, _virtualSignalMapper, _blockedSignalMapper, _deleteAccountSignalMapper, _hiddenAccountSignalMapper, _deleteCategorySignalMapper, _deleteTagSignalMapper, _backgroundColorSignalMapper, _foregroundColorSignalMapper, _fontSignalMapper;
|
QSignalMapper _defaultSignalMapper, _virtualSignalMapper, _blockedSignalMapper, _deleteAccountSignalMapper, _hiddenAccountSignalMapper, _deleteCategorySignalMapper, _deleteTagSignalMapper, _backgroundColorSignalMapper, _foregroundColorSignalMapper, _fontSignalMapper;
|
||||||
bool _inModification;
|
bool _inModification;
|
||||||
|
|
||||||
void InitAccounts(User* user);
|
void InitAccounts(User* user);
|
||||||
void InitCategories(User* user);
|
void InitCategories(User* user);
|
||||||
void InitTags(User* user);
|
void InitTags(User* user);
|
||||||
|
|
|
@ -41,7 +41,6 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
|
||||||
std::vector<Category>::iterator categoryIt;
|
std::vector<Category>::iterator categoryIt;
|
||||||
std::map<int, std::vector<int> > operations;
|
std::map<int, std::vector<int> > operations;
|
||||||
std::map<int, std::vector<int> >::iterator it;
|
std::map<int, std::vector<int> >::iterator it;
|
||||||
QListWidgetItem* item;
|
|
||||||
|
|
||||||
_icons[KissPanel::LOW_RES_ICON] = STATS_LOW_ICON;
|
_icons[KissPanel::LOW_RES_ICON] = STATS_LOW_ICON;
|
||||||
_icons[KissPanel::HIGH_RES_ICON] = STATS_ICON;
|
_icons[KissPanel::HIGH_RES_ICON] = STATS_ICON;
|
||||||
|
@ -97,11 +96,7 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
|
||||||
_account = new QListWidget(this);
|
_account = new QListWidget(this);
|
||||||
for(i=0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++, i++)
|
for(i=0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++, i++)
|
||||||
{
|
{
|
||||||
item = new QListWidgetItem(accountIt->name, _account);
|
_account->addItem(accountIt->name);
|
||||||
if (accountIt->hidden)
|
|
||||||
item->setCheckState (Qt::Unchecked);
|
|
||||||
else
|
|
||||||
item->setCheckState (Qt::Checked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_account->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
_account->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||||
|
@ -330,6 +325,10 @@ void StatsPanel::OnShow()
|
||||||
void StatsPanel::OnRangeChange(int index)
|
void StatsPanel::OnRangeChange(int index)
|
||||||
{
|
{
|
||||||
int monthFrom, monthTo, yearFrom, yearTo;
|
int monthFrom, monthTo, yearFrom, yearTo;
|
||||||
|
QListWidgetItem* item;
|
||||||
|
std::vector<Account>::iterator accountIt;
|
||||||
|
int i;
|
||||||
|
User* user = _kiss->GetUser();
|
||||||
|
|
||||||
monthFrom = _monthFrom->currentIndex();
|
monthFrom = _monthFrom->currentIndex();
|
||||||
yearFrom = _yearFrom->currentText().toInt();
|
yearFrom = _yearFrom->currentText().toInt();
|
||||||
|
@ -343,6 +342,15 @@ void StatsPanel::OnRangeChange(int index)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i=0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++, i++)
|
||||||
|
{
|
||||||
|
item = _account->item(i);
|
||||||
|
if (accountIt->hidden || !accountIt->validAt(monthFrom, yearFrom, monthTo, yearTo))
|
||||||
|
item->setCheckState (Qt::Unchecked);
|
||||||
|
else
|
||||||
|
item->setCheckState (Qt::Checked);
|
||||||
|
}
|
||||||
|
|
||||||
_costRepartitionBanner->Reset();
|
_costRepartitionBanner->Reset();
|
||||||
UpdateStats(monthFrom, yearFrom, monthTo, yearTo);
|
UpdateStats(monthFrom, yearFrom, monthTo, yearTo);
|
||||||
}
|
}
|
||||||
|
|
77
src/view/grid/CalendarDelegate.cpp
Normal file
77
src/view/grid/CalendarDelegate.cpp
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
Copyright 2017 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 <QtWidgets>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "CalendarDelegate.hpp"
|
||||||
|
|
||||||
|
void CalendarDelegate::OnCalendarClicked(const QDate &date)
|
||||||
|
{
|
||||||
|
_date = date;
|
||||||
|
commitData(qobject_cast<QWidget*>(sender()));
|
||||||
|
closeEditor(qobject_cast<QWidget*>(sender()), QAbstractItemDelegate::SubmitModelCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget * CalendarDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||||
|
{
|
||||||
|
QCalendarWidget* calendar = new QCalendarWidget(parent);
|
||||||
|
|
||||||
|
calendar->setGridVisible(false);
|
||||||
|
calendar->setFirstDayOfWeek(Qt::Monday);
|
||||||
|
calendar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
|
calendar->setMinimumWidth(300);
|
||||||
|
calendar->setMinimumHeight(200);
|
||||||
|
|
||||||
|
connect(calendar, SIGNAL(clicked (const QDate&)), this, SLOT(OnCalendarClicked(const QDate&)));
|
||||||
|
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CalendarDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||||
|
const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (index.row() < (int)_accounts->size())
|
||||||
|
{
|
||||||
|
Account ac = (*_accounts)[index.row()];
|
||||||
|
if (_start)
|
||||||
|
ac.start_date = _date;
|
||||||
|
else
|
||||||
|
ac.end_date = _date;
|
||||||
|
}
|
||||||
|
model->setData(index, qVariantFromValue(_date.toString(_dateFormat)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CalendarDelegate::setEditorData(QWidget *editor,
|
||||||
|
const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QCalendarWidget *calendar = qobject_cast<QCalendarWidget *>(editor);
|
||||||
|
|
||||||
|
if (index.row() >= (int)_accounts->size())
|
||||||
|
calendar->setSelectedDate(_date);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Account ac = (*_accounts)[index.row()];
|
||||||
|
if (_start)
|
||||||
|
calendar->setSelectedDate(ac.start_date);
|
||||||
|
else
|
||||||
|
calendar->setSelectedDate(ac.end_date);
|
||||||
|
}
|
||||||
|
}
|
51
src/view/grid/CalendarDelegate.hpp
Normal file
51
src/view/grid/CalendarDelegate.hpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
Copyright 2017 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 CALENDARDELEGATE_H
|
||||||
|
#define CALENDARDELEGATE_H
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
#include <model/Account.hpp>
|
||||||
|
#include <QCalendarWidget>
|
||||||
|
|
||||||
|
class CalendarDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CalendarDelegate(QWidget *parent = 0, std::vector<Account>* accounts=0, bool start=true, QString dateFormat="dd/MM/yyyy") :
|
||||||
|
QStyledItemDelegate(parent), _accounts(accounts), _start(start), _dateFormat(dateFormat) {}
|
||||||
|
|
||||||
|
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 slots:
|
||||||
|
void OnCalendarClicked(const QDate &date);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Account>* _accounts;
|
||||||
|
bool _start;
|
||||||
|
QDate _date;
|
||||||
|
QString _dateFormat;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user