qt: Skip displayUnitChanged signal if unit is not actually changed

Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
This commit is contained in:
Hennadii Stepanov 2021-04-20 22:15:39 +03:00 committed by William Casarin
parent ffbc2fe459
commit 0554251d66
2 changed files with 8 additions and 10 deletions

View file

@ -572,15 +572,13 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
return successful;
}
/** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
void OptionsModel::setDisplayUnit(const QVariant &value)
void OptionsModel::setDisplayUnit(const QVariant& new_unit)
{
if (!value.isNull()) {
QSettings settings;
m_display_bitcoin_unit = value.value<BitcoinUnit>();
settings.setValue("DisplayBitcoinUnit", QVariant::fromValue(m_display_bitcoin_unit));
Q_EMIT displayUnitChanged(m_display_bitcoin_unit);
}
if (new_unit.isNull() || new_unit.value<BitcoinUnit>() == m_display_bitcoin_unit) return;
m_display_bitcoin_unit = new_unit.value<BitcoinUnit>();
QSettings settings;
settings.setValue("DisplayBitcoinUnit", QVariant::fromValue(m_display_bitcoin_unit));
Q_EMIT displayUnitChanged(m_display_bitcoin_unit);
}
void OptionsModel::setRestartRequired(bool fRequired)

View file

@ -80,8 +80,8 @@ public:
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
/** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
void setDisplayUnit(const QVariant &value);
/** Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal */
void setDisplayUnit(const QVariant& new_unit);
/* Explicit getters */
bool getShowTrayIcon() const { return m_show_tray_icon; }