Do not reload current panel when a modification is done (but reload other ones) Add a method to KissPanel for reload other panels avoiding directly using _wxUI member

This commit is contained in:
Grégory Soutadé 2017-10-29 18:21:54 +01:00 committed by Grégory Soutadé
parent 0b096d88bd
commit 258a3eb48d
9 changed files with 69 additions and 47 deletions

View File

@ -138,8 +138,6 @@ void KissCount::UpdateOperation(Operation& op, bool checkTransfert)
accountAmount = _db->CalcAccountAmount(op.account, op.month, op.year, 0);
_db->SetAccountAmount(op.account, op.month, op.year, accountAmount);
}
_wxUI->NeedReload();
}
int KissCount::AddOperation(Operation& op, bool checkTransfert)
@ -156,8 +154,6 @@ int KissCount::AddOperation(Operation& op, bool checkTransfert)
_db->SetAccountAmount(op.account, op.month, op.year, accountAmount);
}
_wxUI->NeedReload();
return ret;
}
@ -178,8 +174,6 @@ void KissCount::DeleteOperation(Operation& op)
accountAmount = _db->CalcAccountAmount(op.account, op.month, op.year, 0);
_db->SetAccountAmount(op.account, op.month, op.year, accountAmount);
}
_wxUI->NeedReload();
}
void KissCount::DeleteOperations(int month, int year)
@ -193,7 +187,6 @@ void KissCount::DeleteOperations(int month, int year)
delete _user->_operations[year];
_user->_operations.erase(year);
}
_wxUI->NeedReload();
}
int KissCount::MetaAmount(int id)

View File

@ -794,7 +794,7 @@ void AccountPanel::OnAccountModified(int row, int column)
_accountsInitValues[id] = amount;
UpdateStats();
_wxUI->NeedReload();
NeedReload();
}
void AccountPanel::OnTreeRightClick(const QPoint & pos)
@ -929,7 +929,7 @@ void AccountPanel::OnMenuGenerate()
g.setModal(true);
g.exec();
_wxUI->setEnabled(true);
_wxUI->NeedReload();
NeedReload();
}
void AccountPanel::OnMenuDelete()
@ -996,8 +996,8 @@ void AccountPanel::OnMenuDelete()
if (month == -1)
month = ops[year][0];
ShowMonth(month, year);
_wxUI->NeedReload();
}
NeedReload();
}
void AccountPanel::GenerateMonth(int month, int year)
@ -1041,7 +1041,7 @@ void AccountPanel::GenerateMonth(int month, int year)
_tree->setCurrentItem(itemMonth);
ShowMonth(month, year);
_wxUI->NeedReload();
NeedReload();
}
void AccountPanel::OnShow()
@ -1146,7 +1146,7 @@ void AccountPanel::OnUpdateNextMonths()
else
QMessageBox::information(0, "KissCount", _("Any account updated !"));
_wxUI->NeedReload();
NeedReload();
delete[] cur_amounts;
}

View File

@ -419,7 +419,7 @@ void ImportPanel::OnLoadOperations()
_tagsGrid->setRowCount(0);
_wxUI->NeedReload();
NeedReload();
}
_operations = _importEngine->GetOperations(accounts, categories, tags);
@ -515,7 +515,7 @@ void ImportPanel::OnIntegrate()
QMessageBox::information(0, "KissCount", _("Operations successfully imported"));
_wxUI->NeedReload();
NeedReload();
}
void ImportPanel::OnOperationModified(int row, int col)

View File

@ -696,7 +696,7 @@ void PreferencesPanel::OnAccountDefaultClicked(int id)
account = user->_accounts[row];
_inModification = false;
_wxUI->NeedReload();
NeedReload();
}
void PreferencesPanel::OnAccountVirtualClicked(int id)
@ -722,7 +722,7 @@ void PreferencesPanel::OnAccountVirtualClicked(int id)
_kiss->UpdateAccount(account);
_inModification = false;
_wxUI->NeedReload();
NeedReload();
}
void PreferencesPanel::OnAccountBlockedClicked(int id)
@ -748,7 +748,7 @@ void PreferencesPanel::OnAccountBlockedClicked(int id)
_kiss->UpdateAccount(account);
_inModification = false;
_wxUI->NeedReload();
NeedReload();
}
void PreferencesPanel::OnAccountDeleteClicked(int id)
@ -813,7 +813,7 @@ void PreferencesPanel::OnAccountDeleteClicked(int id)
}
_inModification = false;
_wxUI->NeedReload();
NeedReload();
}
void PreferencesPanel::OnAccountHiddenClicked(int id)
@ -847,7 +847,7 @@ void PreferencesPanel::OnAccountHiddenClicked(int id)
_kiss->UpdateAccount(account);
_inModification = false;
_wxUI->NeedReload();
NeedReload();
}
void PreferencesPanel::OnCategoryDeleteClicked(int id)
@ -892,7 +892,7 @@ void PreferencesPanel::OnCategoryDeleteClicked(int id)
_kiss->DeleteCategory(category, (!i) ? 0 : user->GetCategoryId(categories[i]));
_categoriesGrid->removeRow(row);
_wxUI->NeedReload();
NeedReload();
}
_inModification = false;
}
@ -939,7 +939,7 @@ void PreferencesPanel::OnTagDeleteClicked(int id)
_kiss->DeleteTag(tag, (!i) ? 0 : user->GetTagId(tags[i]));
_tagsGrid->removeRow(row);
_wxUI->NeedReload();
NeedReload();
}
_inModification = false;
}
@ -969,7 +969,7 @@ void PreferencesPanel::OnBackgroundColorClicked(int id)
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor);
_wxUI->NeedReload();
NeedReload();
}
_inModification = false ;
@ -1000,7 +1000,7 @@ void PreferencesPanel::OnForegroundClicked(int id)
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_COLOR(row, user->_categories[row].backcolor, user->_categories[row].forecolor);
_wxUI->NeedReload();
NeedReload();
}
_inModification = false ;
@ -1032,7 +1032,7 @@ void PreferencesPanel::OnFontClicked(int id)
_kiss->UpdateCategory(user->_categories[row]);
SET_ROW_FONT(row, font);
_wxUI->NeedReload();
NeedReload();
}
_inModification = false ;
@ -1157,7 +1157,7 @@ void PreferencesPanel::OnAccountModified(int row, int col)
_accountsGrid->resizeColumnsToContents();
_wxUI->NeedReload();
NeedReload();
_inModification = false;
}
@ -1223,7 +1223,7 @@ void PreferencesPanel::OnSharedChanged(QListWidgetItem *item)
_inModification = false;
_wxUI->NeedReload();
NeedReload();
}
void PreferencesPanel::OnCategoryModified(int row, int col)
@ -1318,7 +1318,7 @@ void PreferencesPanel::OnCategoryModified(int row, int col)
AddCategory(++row, new_cat);
}
_wxUI->NeedReload();
NeedReload();
_inModification = false;
}
@ -1400,7 +1400,7 @@ void PreferencesPanel::OnTagModified(int row, int col)
AddTag(++row, new_tag);
}
_wxUI->NeedReload();
NeedReload();
_inModification = false;
}
@ -1428,7 +1428,7 @@ void PreferencesPanel::OnChangeName()
_kiss->ChangeName(name);
QMessageBox::information(0, "KissCount", _("Name changed"));
_wxUI->NeedReload();
NeedReload();
OnShow();
}
@ -1446,7 +1446,7 @@ void PreferencesPanel::OnOperationOrderChanged(int index)
else
_kiss->SetOperationOrder("DESC");
_wxUI->NeedReload();
NeedReload();
}
void PreferencesPanel::OnLanguageChanged(int index)
@ -1458,7 +1458,7 @@ void PreferencesPanel::OnLanguageChanged(int index)
if (_wxUI->SetLanguage(name_lang) || language == SupportedLanguages::English)
{
_wxUI->NeedReload();
NeedReload();
_kiss->SetLanguage(name_lang);
QMessageBox::information(0, "KissCount", _("Language successfully changed, please go to another panel"));
}
@ -1488,7 +1488,7 @@ void PreferencesPanel::OnKillMe()
void PreferencesPanel::OnAccountLimitChanged(int val)
{
_kiss->SetAccountLimitValue(val);
_wxUI->NeedReload();
NeedReload();
}
void PreferencesPanel::OnAccountLimitColorClicked(void)
@ -1509,7 +1509,7 @@ void PreferencesPanel::OnAccountLimitColorClicked(void)
palette.setColor(QPalette::Base, user->GetAccountLimitColor());
_accountLimit->setPalette(palette);
_wxUI->NeedReload();
NeedReload();
}
_inModification = false ;

View File

@ -210,7 +210,7 @@ void SearchPanel::OnButtonChangeAccount()
UpdateCostRepartition();
_wxUI->NeedReload();
NeedReload();
}
static void ChangeCategory(Operation* op, void** params)
@ -260,7 +260,7 @@ void SearchPanel::OnButtonChangeCategory()
UpdateCostRepartition();
_wxUI->NeedReload();
NeedReload();
}
static void ChangeTag(Operation* op, void** params)
@ -305,7 +305,7 @@ void SearchPanel::OnButtonChangeTag()
UpdateCostRepartition();
_wxUI->NeedReload();
NeedReload();
}
static void ChangeName(Operation* op, void** params)
@ -333,7 +333,7 @@ void SearchPanel::OnButtonRename()
UpdateCostRepartition();
_wxUI->NeedReload();
NeedReload();
}
void SearchPanel::OnShow()
@ -343,5 +343,5 @@ void SearchPanel::OnShow()
void SearchPanel::OnOperationModified()
{
_wxUI->NeedReload();
NeedReload();
}

View File

@ -43,7 +43,7 @@
#define SET_READ_ONLY(item) item->setFlags(item->flags() & ~Qt::ItemIsEditable);
GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
GridAccount::GridAccount(KissCount* kiss, KissPanel *parent,
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase)
: QTableWidget(parent), _fixCosts(0), _week1(0),
_week2(0), _week3(0), _week4(0), _week5(0), _canAddOperation(canAddOperation),
@ -165,7 +165,10 @@ void GridAccount::UpdateOperation(Operation& op)
if (it != _operations->end())
{
if (_databaseSynchronization)
{
_kiss->UpdateOperation(op);
_parent->NeedReload();
}
*it = op;
}
}
@ -572,7 +575,10 @@ void GridAccount::DeleteOperation(const Operation& op) throw (OperationNotFound)
if (it != _operations->end())
{
if (_databaseSynchronization)
{
_kiss->DeleteOperation(*it);
_parent->NeedReload();
}
if (it->parent)
{
parent = GetOperation(it->parent);
@ -1151,6 +1157,7 @@ void GridAccount::OnOperationModified(int row, int col)
new_op.parent = 0;
new_op_id = _kiss->AddOperation(new_op);
_parent->NeedReload();
if (!new_op_id)
{
@ -1353,6 +1360,7 @@ void GridAccount::Group()
op.childs.clear();
op.id = _kiss->AddOperation(op);
_parent->NeedReload();
}
else
{
@ -1596,7 +1604,10 @@ void GridAccount::MassUpdate(std::vector<int>& rows, bool do_childs, updateOpera
{
func (&(*it), params);
if (_databaseSynchronization)
{
_kiss->UpdateOperation(*it);
_parent->NeedReload();
}
if (it->meta && do_childs)
{

View File

@ -44,7 +44,7 @@ public:
enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, TAG, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS};
GridAccount(KissCount* kiss, QWidget *parent,
GridAccount(KissCount* kiss, KissPanel *parent,
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
~GridAccount();
@ -72,7 +72,7 @@ private slots:
void OnDeleteClicked(int id);
private:
QWidget* _parent;
KissPanel* _parent;
KissCount* _kiss;
bool _displayLines;
bool _setWeek;

View File

@ -50,7 +50,7 @@ QColor wxUI::categoryColors[MAX_CATEGORY] = {QColor(0x00, 0x45, 0x86),
wxUI::wxUI(KissCount* kiss, const QString& title)
: QFrame(0), _language(SupportedLanguages::languages[SupportedLanguages::English].name),
_kiss(kiss), _signalMapper(this), _curPanel(0), _locale(0),
_needReload(false)
_needReload(0)
{
QPushButton* button;
QDesktopWidget desk;
@ -223,6 +223,7 @@ void wxUI::LoadPanels()
{
for (i=0; i<(int)_panels.size(); i++)
{
if (i == _needReload) continue;
temp = _panels[i]->CreatePanel();
_buttons[i]->disconnect(&_signalMapper, SLOT(map()));
delete _panels[i];
@ -277,7 +278,7 @@ void wxUI::ShowPanel(KissPanel* panel)
for(i=0; i<(int)_panels.size(); i++)
if (_panels[i] == panel) break;
LoadPanels();
_needReload = false;
_needReload = 0;
_curPanel = _panels[i];
}
else
@ -357,9 +358,24 @@ void wxUI::KillMe()
_panels.clear();
}
void wxUI::NeedReload()
void wxUI::NeedReload(KissPanel* panel)
{
_needReload = true;
unsigned i;
// Reload all panels
_needReload = -1;
if (panel)
{
for(i=0; i<_panels.size(); i++)
{
if (panel == _panels[i])
{
_needReload = i;
break;
}
}
}
}
QString wxUI::GetDateFormat()

View File

@ -72,7 +72,7 @@ public:
void KillMe();
void ShowPanel(KissPanel* panel);
void NeedReload();
void NeedReload(KissPanel* panel);
QLocale* GetLocale() {return _locale;}
QString GetDateFormat();
@ -96,7 +96,7 @@ private:
std::vector<QPushButton*> _buttons;
QLocale *_locale;
QTranslator _translator;
bool _needReload;
int _needReload;
void InitPanels();
void LoadPanels();
@ -122,6 +122,8 @@ public:
virtual QPushButton* GetButton() {return createButton();}
virtual QString GetToolTip() {return "";}
void NeedReload(void) {_wxUI->NeedReload(this);}
protected:
KissCount* _kiss;
wxUI* _wxUI;