Skip to content

Commit

Permalink
Clean: SettingsWalletOptionsWidget -> SettingsWidget friend class con…
Browse files Browse the repository at this point in the history
…nection
  • Loading branch information
furszy committed Apr 11, 2021
1 parent a6b14f6 commit 71bec54
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
29 changes: 26 additions & 3 deletions src/qt/pivx/settings/settingswalletoptionswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void SettingsWalletOptionsWidget::onResetClicked()
inform(tr("Options reset succeed"));
}

void SettingsWalletOptionsWidget::setMapper(QDataWidgetMapper *mapper){
void SettingsWalletOptionsWidget::setMapper(QDataWidgetMapper *mapper)
{
mapper->addMapping(ui->radioButtonSpend, OptionsModel::SpendZeroConfChange);

// Network
Expand All @@ -76,10 +77,10 @@ void SettingsWalletOptionsWidget::setMapper(QDataWidgetMapper *mapper){
mapper->addMapping(ui->lineEditPort, OptionsModel::ProxyPort);
}

void SettingsWalletOptionsWidget::setWalletModel(WalletModel* model)
void SettingsWalletOptionsWidget::loadWalletModel()
{
PWidget::setWalletModel(model);
reloadWalletOptions();
connect(walletModel, &WalletModel::notifySSTChanged, this, &SettingsWalletOptionsWidget::setSpinBoxStakeSplitThreshold);
}

void SettingsWalletOptionsWidget::reloadWalletOptions()
Expand All @@ -97,6 +98,28 @@ double SettingsWalletOptionsWidget::getSpinBoxStakeSplitThreshold() const
return ui->spinBoxStakeSplitThreshold->value();
}

bool SettingsWalletOptionsWidget::saveWalletOnlyOptions()
{
// stake split threshold
const CAmount sstOld = walletModel->getWalletStakeSplitThreshold();
const CAmount sstNew = static_cast<CAmount>(getSpinBoxStakeSplitThreshold() * COIN);
if (sstNew != sstOld) {
const double stakeSplitMinimum = walletModel->getSSTMinimum();
if (sstNew != 0 && sstNew < static_cast<CAmount>(stakeSplitMinimum * COIN)) {
setSpinBoxStakeSplitThreshold(stakeSplitMinimum);
inform(tr("Stake Split too low, it shall be either >= %1 or equal to 0 (to disable stake splitting)").arg(stakeSplitMinimum));
return false;
}
walletModel->setWalletStakeSplitThreshold(sstNew);
}
return true;
}

void SettingsWalletOptionsWidget::discardWalletOnlyOptions()
{
reloadWalletOptions();
}

SettingsWalletOptionsWidget::~SettingsWalletOptionsWidget(){
delete ui;
}
12 changes: 6 additions & 6 deletions src/qt/pivx/settings/settingswalletoptionswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace Ui {
class SettingsWalletOptionsWidget;
}

class SettingsWidget;

class SettingsWalletOptionsWidget : public PWidget
{
Q_OBJECT
Expand All @@ -22,6 +20,11 @@ class SettingsWalletOptionsWidget : public PWidget
explicit SettingsWalletOptionsWidget(PIVXGUI* _window, QWidget *parent = nullptr);
~SettingsWalletOptionsWidget();

void setMapper(QDataWidgetMapper *mapper);

void discardWalletOnlyOptions();
bool saveWalletOnlyOptions();

Q_SIGNALS:
void saveSettings();
void discardSettings();
Expand All @@ -30,12 +33,9 @@ public Q_SLOTS:
void onResetClicked();

private:
friend class SettingsWidget;

Ui::SettingsWalletOptionsWidget *ui;

void setMapper(QDataWidgetMapper *mapper);
void setWalletModel(WalletModel* model);
void loadWalletModel() override;
void reloadWalletOptions();

void setSpinBoxStakeSplitThreshold(double val);
Expand Down
19 changes: 3 additions & 16 deletions src/qt/pivx/settings/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ void SettingsWidget::loadWalletModel()
this->settingsBitToolWidget->setWalletModel(this->walletModel);
this->settingsDisplayOptionsWidget->setWalletModel(this->walletModel);
this->settingsWalletOptionsWidget->setWalletModel(this->walletModel);

// connect to walletModel signals
connect(walletModel, &WalletModel::notifySSTChanged, this->settingsWalletOptionsWidget, &SettingsWalletOptionsWidget::setSpinBoxStakeSplitThreshold);
}

void SettingsWidget::onResetAction()
Expand All @@ -222,18 +219,8 @@ void SettingsWidget::onResetAction()

void SettingsWidget::onSaveOptionsClicked()
{
// stake split threshold
const CAmount sstOld = walletModel->getWalletStakeSplitThreshold();
const CAmount sstNew = static_cast<CAmount>(settingsWalletOptionsWidget->getSpinBoxStakeSplitThreshold() * COIN);
if (sstNew != sstOld) {
const double stakeSplitMinimum = walletModel->getSSTMinimum();
if (sstNew != 0 && sstNew < static_cast<CAmount>(stakeSplitMinimum * COIN)) {
settingsWalletOptionsWidget->setSpinBoxStakeSplitThreshold(stakeSplitMinimum);
inform(tr("Stake Split too low, it shall be either >= %1 or equal to 0 (to disable stake splitting)").arg(stakeSplitMinimum));
return;
}
walletModel->setWalletStakeSplitThreshold(sstNew);
}
// Save settings that are stored inside the wallet only
settingsWalletOptionsWidget->saveWalletOnlyOptions();

This comment has been minimized.

Copy link
@random-zebra

random-zebra Apr 11, 2021

Collaborator

we should check the return value, and exit early if false


if (mapper->submit()) {
OptionsModel* optionsModel = this->clientModel->getOptionsModel();
Expand Down Expand Up @@ -414,7 +401,7 @@ void SettingsWidget::onDiscardChanges()
return;
clientModel->getOptionsModel()->refreshDataView();
}
settingsWalletOptionsWidget->reloadWalletOptions();
settingsWalletOptionsWidget->discardWalletOnlyOptions();
}

void SettingsWidget::setMapper()
Expand Down

0 comments on commit 71bec54

Please sign in to comment.