mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
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: ACKa63b60f02b
furszy: Code review ACKa63b60f0
promag: Code review ACKa63b60f02b
. Tree-SHA512: 1d99a1ce435b4055c1a38d2490702cf5b89bacc7d168c9968a60550bfd9f6dace649d5e98699de68d6305f02d5d1e3eb7e177ab578b98b996dd873b1df0ed236
This commit is contained in:
commit
b0e16eb3ac
2 changed files with 254 additions and 240 deletions
|
@ -335,9 +335,29 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
||||||
{
|
{
|
||||||
if(role == Qt::EditRole)
|
if(role == Qt::EditRole)
|
||||||
{
|
{
|
||||||
QSettings settings;
|
return getOption(OptionID(index.row()));
|
||||||
switch(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:
|
case StartAtStartup:
|
||||||
return GUIUtil::GetStartOnSystemStartup();
|
return GUIUtil::GetStartOnSystemStartup();
|
||||||
case ShowTrayIcon:
|
case ShowTrayIcon:
|
||||||
|
@ -410,19 +430,14 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// write QSettings values
|
bool OptionsModel::setOption(OptionID option, const QVariant& value)
|
||||||
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
|
|
||||||
{
|
{
|
||||||
bool successful = true; /* set to false on parse error */
|
bool successful = true; /* set to false on parse error */
|
||||||
if(role == Qt::EditRole)
|
|
||||||
{
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
switch(index.row())
|
|
||||||
{
|
switch (option) {
|
||||||
case StartAtStartup:
|
case StartAtStartup:
|
||||||
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
|
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
|
||||||
break;
|
break;
|
||||||
|
@ -585,9 +600,6 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT dataChanged(index, index);
|
|
||||||
|
|
||||||
return successful;
|
return successful;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,8 @@ public:
|
||||||
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) 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;
|
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 */
|
/** Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal */
|
||||||
void setDisplayUnit(const QVariant& new_unit);
|
void setDisplayUnit(const QVariant& new_unit);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue