Bitcoin Core  22.99.0
P2P Digital Currency
optionsmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_QT_OPTIONSMODEL_H
6 #define BITCOIN_QT_OPTIONSMODEL_H
7 
8 #include <cstdint>
9 #include <qt/guiconstants.h>
10 
11 #include <QAbstractListModel>
12 
13 #include <assert.h>
14 
15 namespace interfaces {
16 class Node;
17 }
18 
19 extern const char *DEFAULT_GUI_PROXY_HOST;
20 static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
21 
25 static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
26 
30 static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
31 
38 class OptionsModel : public QAbstractListModel
39 {
40  Q_OBJECT
41 
42 public:
43  explicit OptionsModel(QObject *parent = nullptr, bool resetSettings = false);
44 
45  enum OptionID {
46  StartAtStartup, // bool
47  ShowTrayIcon, // bool
48  MinimizeToTray, // bool
49  MapPortUPnP, // bool
50  MapPortNatpmp, // bool
51  MinimizeOnClose, // bool
52  ProxyUse, // bool
53  ProxyIP, // QString
54  ProxyPort, // int
55  ProxyUseTor, // bool
56  ProxyIPTor, // QString
57  ProxyPortTor, // int
58  DisplayUnit, // BitcoinUnits::Unit
59  ThirdPartyTxUrls, // QString
60  Language, // QString
65  Prune, // bool
66  PruneSize, // int
67  DatabaseCache, // int
68  ExternalSignerPath, // QString
70  Listen, // bool
71  Server, // bool
74  };
75 
76  void Init(bool resetSettings = false);
77  void Reset();
78 
79  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
80  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
81  bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
83  void setDisplayUnit(const QVariant &value);
84 
85  /* Explicit getters */
86  bool getShowTrayIcon() const { return m_show_tray_icon; }
87  bool getMinimizeToTray() const { return fMinimizeToTray; }
88  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
89  int getDisplayUnit() const { return nDisplayUnit; }
90  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
93  bool getSubFeeFromAmount() const { return m_sub_fee_from_amount; }
96 
97  /* Explicit setters */
98  void SetPruneEnabled(bool prune, bool force = false);
99  void SetPruneTargetGB(int prune_target_gb, bool force = false);
100 
101  /* Restart flag helper */
102  void setRestartRequired(bool fRequired);
103  bool isRestartRequired() const;
104 
105  interfaces::Node& node() const { assert(m_node); return *m_node; }
107 
108 private:
110  /* Qt-only settings */
114  QString language;
121  /* settings that were overridden by command-line */
123 
124  // Add option to list of GUI options overridden through command line/config file
125  void addOverriddenOption(const std::string &option);
126 
127  // Check settings version and upgrade default values if required
128  void checkAndMigrate();
129 Q_SIGNALS:
130  void displayUnitChanged(int unit);
131  void coinControlFeaturesChanged(bool);
132  void showTrayIconChanged(bool);
134 };
135 
136 #endif // BITCOIN_QT_OPTIONSMODEL_H
PruneMiBtoGB
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:25
interfaces
Definition: dummywallet.cpp:10
OptionsModel::getMinimizeOnClose
bool getMinimizeOnClose() const
Definition: optionsmodel.h:88
assert
assert(!tx.IsCoinBase())
OptionsModel::ShowTrayIcon
@ ShowTrayIcon
Definition: optionsmodel.h:47
OptionsModel::MinimizeOnClose
@ MinimizeOnClose
Definition: optionsmodel.h:51
OptionsModel::ThreadsScriptVerif
@ ThreadsScriptVerif
Definition: optionsmodel.h:64
OptionsModel::PruneSize
@ PruneSize
Definition: optionsmodel.h:66
OptionsModel::DisplayUnit
@ DisplayUnit
Definition: optionsmodel.h:58
OptionsModel::getOverriddenByCommandLine
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:95
OptionsModel::Listen
@ Listen
Definition: optionsmodel.h:70
OptionsModel::fMinimizeOnClose
bool fMinimizeOnClose
Definition: optionsmodel.h:113
DEFAULT_GUI_PROXY_PORT
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:20
OptionsModel::OptionID
OptionID
Definition: optionsmodel.h:45
OptionsModel::SetPruneEnabled
void SetPruneEnabled(bool prune, bool force=false)
Definition: optionsmodel.cpp:280
OptionsModel::displayUnitChanged
void displayUnitChanged(int unit)
OptionsModel::ProxyPort
@ ProxyPort
Definition: optionsmodel.h:54
OptionsModel::DatabaseCache
@ DatabaseCache
Definition: optionsmodel.h:67
OptionsModel::SpendZeroConfChange
@ SpendZeroConfChange
Definition: optionsmodel.h:69
OptionsModel::ExternalSignerPath
@ ExternalSignerPath
Definition: optionsmodel.h:68
OptionsModel::setDisplayUnit
void setDisplayUnit(const QVariant &value)
Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal.
Definition: optionsmodel.cpp:568
OptionsModel::nDisplayUnit
int nDisplayUnit
Definition: optionsmodel.h:115
OptionsModel::m_node
interfaces::Node * m_node
Definition: optionsmodel.h:109
OptionsModel::OptionIDRowCount
@ OptionIDRowCount
Definition: optionsmodel.h:73
OptionsModel::MinimizeToTray
@ MinimizeToTray
Definition: optionsmodel.h:48
OptionsModel::m_show_tray_icon
bool m_show_tray_icon
Definition: optionsmodel.h:111
OptionsModel::Reset
void Reset()
Definition: optionsmodel.cpp:218
OptionsModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: optionsmodel.cpp:390
OptionsModel::ProxyUse
@ ProxyUse
Definition: optionsmodel.h:52
OptionsModel::getSubFeeFromAmount
bool getSubFeeFromAmount() const
Definition: optionsmodel.h:93
OptionsModel::getEnablePSBTControls
bool getEnablePSBTControls() const
Definition: optionsmodel.h:94
OptionsModel::node
interfaces::Node & node() const
Definition: optionsmodel.h:105
OptionsModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: optionsmodel.cpp:243
OptionsModel::addOverriddenOption
void addOverriddenOption(const std::string &option)
Definition: optionsmodel.cpp:38
OptionsModel
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:38
OptionsModel::OptionsModel
OptionsModel(QObject *parent=nullptr, bool resetSettings=false)
Definition: optionsmodel.cpp:32
OptionsModel::isRestartRequired
bool isRestartRequired() const
Definition: optionsmodel.cpp:585
OptionsModel::m_use_embedded_monospaced_font
bool m_use_embedded_monospaced_font
Definition: optionsmodel.h:117
OptionsModel::SetPruneTargetGB
void SetPruneTargetGB(int prune_target_gb, bool force=false)
Definition: optionsmodel.cpp:295
OptionsModel::SubFeeFromAmount
@ SubFeeFromAmount
Definition: optionsmodel.h:63
OptionsModel::showTrayIconChanged
void showTrayIconChanged(bool)
OptionsModel::EnablePSBTControls
@ EnablePSBTControls
Definition: optionsmodel.h:72
OptionsModel::Server
@ Server
Definition: optionsmodel.h:71
OptionsModel::strThirdPartyTxUrls
QString strThirdPartyTxUrls
Definition: optionsmodel.h:116
OptionsModel::getCoinControlFeatures
bool getCoinControlFeatures() const
Definition: optionsmodel.h:92
OptionsModel::StartAtStartup
@ StartAtStartup
Definition: optionsmodel.h:46
OptionsModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: optionsmodel.cpp:306
OptionsModel::checkAndMigrate
void checkAndMigrate()
Definition: optionsmodel.cpp:591
OptionsModel::strOverriddenByCommandLine
QString strOverriddenByCommandLine
Definition: optionsmodel.h:122
OptionsModel::fMinimizeToTray
bool fMinimizeToTray
Definition: optionsmodel.h:112
OptionsModel::ProxyIPTor
@ ProxyIPTor
Definition: optionsmodel.h:56
OptionsModel::ProxyUseTor
@ ProxyUseTor
Definition: optionsmodel.h:55
OptionsModel::language
QString language
Definition: optionsmodel.h:114
OptionsModel::ProxyPortTor
@ ProxyPortTor
Definition: optionsmodel.h:57
OptionsModel::CoinControlFeatures
@ CoinControlFeatures
Definition: optionsmodel.h:62
OptionsModel::fCoinControlFeatures
bool fCoinControlFeatures
Definition: optionsmodel.h:118
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:68
GB_BYTES
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:59
OptionsModel::Init
void Init(bool resetSettings=false)
Definition: optionsmodel.cpp:44
OptionsModel::setNode
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:106
OptionsModel::ProxyIP
@ ProxyIP
Definition: optionsmodel.h:53
OptionsModel::Prune
@ Prune
Definition: optionsmodel.h:65
OptionsModel::ThirdPartyTxUrls
@ ThirdPartyTxUrls
Definition: optionsmodel.h:59
OptionsModel::MapPortUPnP
@ MapPortUPnP
Definition: optionsmodel.h:49
guiconstants.h
OptionsModel::m_enable_psbt_controls
bool m_enable_psbt_controls
Definition: optionsmodel.h:120
OptionsModel::getDisplayUnit
int getDisplayUnit() const
Definition: optionsmodel.h:89
OptionsModel::Language
@ Language
Definition: optionsmodel.h:60
DEFAULT_GUI_PROXY_HOST
const char * DEFAULT_GUI_PROXY_HOST
Definition: optionsmodel.cpp:28
OptionsModel::MapPortNatpmp
@ MapPortNatpmp
Definition: optionsmodel.h:50
PruneGBtoMiB
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:30
OptionsModel::useEmbeddedMonospacedFontChanged
void useEmbeddedMonospacedFontChanged(bool)
node
Definition: init.h:22
OptionsModel::getThirdPartyTxUrls
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:90
OptionsModel::m_sub_fee_from_amount
bool m_sub_fee_from_amount
Definition: optionsmodel.h:119
OptionsModel::getMinimizeToTray
bool getMinimizeToTray() const
Definition: optionsmodel.h:87
OptionsModel::UseEmbeddedMonospacedFont
@ UseEmbeddedMonospacedFont
Definition: optionsmodel.h:61
OptionsModel::getUseEmbeddedMonospacedFont
bool getUseEmbeddedMonospacedFont() const
Definition: optionsmodel.h:91
OptionsModel::coinControlFeaturesChanged
void coinControlFeaturesChanged(bool)
OptionsModel::setRestartRequired
void setRestartRequired(bool fRequired)
Definition: optionsmodel.cpp:579
OptionsModel::getShowTrayIcon
bool getShowTrayIcon() const
Definition: optionsmodel.h:86