Merge bitcoin-core/gui#600: refactor: Add OptionsModel getOption/setOption methods

a63b60f02b refactor: Add OptionsModel getOption/setOption methods (Ryan Ofsky)

Pull request description:

  This is a trivial change which is needed as part of #602 to get bitcoind and bitcoin-qt to use the same settings instead of different settings. It is split off from #602 because it causes a lot of rebase conflicts (any time there is a GUI options change).

  This PR is very small and easy to review ignoring whitespace: https://github.com/bitcoin-core/gui/pull/600/files?w=1

ACKs for top commit:
  vasild:
    ACK a63b60f02b
  furszy:
    Code review ACK a63b60f0
  promag:
    Code review ACK a63b60f02b.

Tree-SHA512: 1d99a1ce435b4055c1a38d2490702cf5b89bacc7d168c9968a60550bfd9f6dace649d5e98699de68d6305f02d5d1e3eb7e177ab578b98b996dd873b1df0ed236
This commit is contained in:
Hennadii Stepanov 2022-05-22 20:06:03 +02:00
commit b0e16eb3ac
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
2 changed files with 254 additions and 240 deletions

View file

@ -335,9 +335,29 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
{
if(role == Qt::EditRole)
{
QSettings settings;
switch(index.row())
return getOption(OptionID(index.row()));
}
return QVariant();
}
// write QSettings values
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
bool successful = true; /* set to false on parse error */
if(role == Qt::EditRole)
{
successful = setOption(OptionID(index.row()), value);
}
Q_EMIT dataChanged(index, index);
return successful;
}
QVariant OptionsModel::getOption(OptionID option) const
{
QSettings settings;
switch (option) {
case StartAtStartup:
return GUIUtil::GetStartOnSystemStartup();
case ShowTrayIcon:
@ -411,18 +431,13 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return QVariant();
}
}
return QVariant();
}
// write QSettings values
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
bool OptionsModel::setOption(OptionID option, const QVariant& value)
{
bool successful = true; /* set to false on parse error */
if(role == Qt::EditRole)
{
QSettings settings;
switch(index.row())
{
switch (option) {
case StartAtStartup:
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
break;
@ -585,9 +600,6 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
default:
break;
}
}
Q_EMIT dataChanged(index, index);
return successful;
}

View file

@ -80,6 +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;
QVariant getOption(OptionID option) const;
bool setOption(OptionID option, const QVariant& value);
/** Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal */
void setDisplayUnit(const QVariant& new_unit);