Skip to content

Commit 8eb1a34

Browse files
hebastopromag
andcommitted
qt: Skip displayUnitChanged signal if unit is not actually changed
Co-authored-by: João Barbosa <[email protected]>
1 parent 16e7d3f commit 8eb1a34

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/qt/optionsmodel.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,15 +519,13 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
519519
return successful;
520520
}
521521

522-
/** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
523-
void OptionsModel::setDisplayUnit(const QVariant &value)
522+
void OptionsModel::setDisplayUnit(const QVariant& new_unit)
524523
{
525-
if (!value.isNull()) {
526-
QSettings settings;
527-
m_display_bitcoin_unit = value.value<BitcoinUnit>();
528-
settings.setValue("DisplayBitcoinUnit", QVariant::fromValue(m_display_bitcoin_unit));
529-
Q_EMIT displayUnitChanged(m_display_bitcoin_unit);
530-
}
524+
if (new_unit.isNull() || new_unit.value<BitcoinUnit>() == m_display_bitcoin_unit) return;
525+
m_display_bitcoin_unit = new_unit.value<BitcoinUnit>();
526+
QSettings settings;
527+
settings.setValue("DisplayBitcoinUnit", QVariant::fromValue(m_display_bitcoin_unit));
528+
Q_EMIT displayUnitChanged(m_display_bitcoin_unit);
531529
}
532530

533531
void OptionsModel::setRestartRequired(bool fRequired)

src/qt/optionsmodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class OptionsModel : public QAbstractListModel
7777
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
7878
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
7979
bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
80-
/** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
81-
void setDisplayUnit(const QVariant &value);
80+
/** Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal */
81+
void setDisplayUnit(const QVariant& new_unit);
8282

8383
/* Explicit getters */
8484
bool getShowTrayIcon() const { return m_show_tray_icon; }

0 commit comments

Comments
 (0)