mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-18 14:10:44 +02:00
refactor: Add OptionsModel getOption/setOption methods
Easiest to review ignoring whitespace.
This commit is contained in:
parent
0de36941ec
commit
a63b60f02b
@ -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:
|
||||
@ -410,19 +430,14 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
||||
default:
|
||||
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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user