Bitcoin Core  21.99.0
P2P Digital Currency
optionsmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 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 <amount.h>
9 #include <cstdint>
10 #include <qt/guiconstants.h>
11 
12 #include <QAbstractListModel>
13 
14 #include <assert.h>
15 
16 namespace interfaces {
17 class Node;
18 }
19 
20 extern const char *DEFAULT_GUI_PROXY_HOST;
21 static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
22 
26 static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
27 
31 static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
32 
39 class OptionsModel : public QAbstractListModel
40 {
41  Q_OBJECT
42 
43 public:
44  explicit OptionsModel(QObject *parent = nullptr, bool resetSettings = false);
45 
46  enum OptionID {
47  StartAtStartup, // bool
48  ShowTrayIcon, // bool
49  MinimizeToTray, // bool
50  MapPortUPnP, // bool
51  MapPortNatpmp, // bool
52  MinimizeOnClose, // bool
53  ProxyUse, // bool
54  ProxyIP, // QString
55  ProxyPort, // int
56  ProxyUseTor, // bool
57  ProxyIPTor, // QString
58  ProxyPortTor, // int
59  DisplayUnit, // BitcoinUnits::Unit
60  ThirdPartyTxUrls, // QString
61  Language, // QString
65  Prune, // bool
66  PruneSize, // int
67  DatabaseCache, // int
68  ExternalSignerPath, // QString
70  Listen, // bool
72  };
73 
74  void Init(bool resetSettings = false);
75  void Reset();
76 
77  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
78  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
79  bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
81  void setDisplayUnit(const QVariant &value);
82 
83  /* Explicit getters */
84  bool getShowTrayIcon() const { return m_show_tray_icon; }
85  bool getMinimizeToTray() const { return fMinimizeToTray; }
86  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
87  int getDisplayUnit() const { return nDisplayUnit; }
88  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
92 
93  /* Explicit setters */
94  void SetPruneEnabled(bool prune, bool force = false);
95  void SetPruneTargetGB(int prune_target_gb, bool force = false);
96 
97  /* Restart flag helper */
98  void setRestartRequired(bool fRequired);
99  bool isRestartRequired() const;
100 
101  interfaces::Node& node() const { assert(m_node); return *m_node; }
103 
104 private:
106  /* Qt-only settings */
110  QString language;
115  /* settings that were overridden by command-line */
117 
118  // Add option to list of GUI options overridden through command line/config file
119  void addOverriddenOption(const std::string &option);
120 
121  // Check settings version and upgrade default values if required
122  void checkAndMigrate();
123 Q_SIGNALS:
124  void displayUnitChanged(int unit);
125  void coinControlFeaturesChanged(bool);
126  void showTrayIconChanged(bool);
128 };
129 
130 #endif // BITCOIN_QT_OPTIONSMODEL_H
PruneMiBtoGB
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:26
interfaces
Definition: dummywallet.cpp:10
OptionsModel::getMinimizeOnClose
bool getMinimizeOnClose() const
Definition: optionsmodel.h:86
assert
assert(!tx.IsCoinBase())
OptionsModel::ShowTrayIcon
@ ShowTrayIcon
Definition: optionsmodel.h:48
OptionsModel::MinimizeOnClose
@ MinimizeOnClose
Definition: optionsmodel.h:52
OptionsModel::ThreadsScriptVerif
@ ThreadsScriptVerif
Definition: optionsmodel.h:64
OptionsModel::PruneSize
@ PruneSize
Definition: optionsmodel.h:66
OptionsModel::DisplayUnit
@ DisplayUnit
Definition: optionsmodel.h:59
OptionsModel::getOverriddenByCommandLine
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:91
OptionsModel::Listen
@ Listen
Definition: optionsmodel.h:70
OptionsModel::fMinimizeOnClose
bool fMinimizeOnClose
Definition: optionsmodel.h:109
DEFAULT_GUI_PROXY_PORT
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:21
OptionsModel::OptionID
OptionID
Definition: optionsmodel.h:46
OptionsModel::SetPruneEnabled
void SetPruneEnabled(bool prune, bool force=false)
Definition: optionsmodel.cpp:263
OptionsModel::displayUnitChanged
void displayUnitChanged(int unit)
OptionsModel::ProxyPort
@ ProxyPort
Definition: optionsmodel.h:55
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:531
OptionsModel::nDisplayUnit
int nDisplayUnit
Definition: optionsmodel.h:111
OptionsModel::m_node
interfaces::Node * m_node
Definition: optionsmodel.h:105
OptionsModel::OptionIDRowCount
@ OptionIDRowCount
Definition: optionsmodel.h:71
OptionsModel::MinimizeToTray
@ MinimizeToTray
Definition: optionsmodel.h:49
OptionsModel::m_show_tray_icon
bool m_show_tray_icon
Definition: optionsmodel.h:107
OptionsModel::Reset
void Reset()
Definition: optionsmodel.cpp:201
OptionsModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: optionsmodel.cpp:367
OptionsModel::ProxyUse
@ ProxyUse
Definition: optionsmodel.h:53
OptionsModel::node
interfaces::Node & node() const
Definition: optionsmodel.h:101
OptionsModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: optionsmodel.cpp:226
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:39
OptionsModel::OptionsModel
OptionsModel(QObject *parent=nullptr, bool resetSettings=false)
Definition: optionsmodel.cpp:32
OptionsModel::isRestartRequired
bool isRestartRequired() const
Definition: optionsmodel.cpp:548
OptionsModel::m_use_embedded_monospaced_font
bool m_use_embedded_monospaced_font
Definition: optionsmodel.h:113
OptionsModel::SetPruneTargetGB
void SetPruneTargetGB(int prune_target_gb, bool force=false)
Definition: optionsmodel.cpp:278
OptionsModel::showTrayIconChanged
void showTrayIconChanged(bool)
OptionsModel::strThirdPartyTxUrls
QString strThirdPartyTxUrls
Definition: optionsmodel.h:112
OptionsModel::getCoinControlFeatures
bool getCoinControlFeatures() const
Definition: optionsmodel.h:90
OptionsModel::StartAtStartup
@ StartAtStartup
Definition: optionsmodel.h:47
OptionsModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: optionsmodel.cpp:289
OptionsModel::checkAndMigrate
void checkAndMigrate()
Definition: optionsmodel.cpp:554
OptionsModel::strOverriddenByCommandLine
QString strOverriddenByCommandLine
Definition: optionsmodel.h:116
OptionsModel::fMinimizeToTray
bool fMinimizeToTray
Definition: optionsmodel.h:108
OptionsModel::ProxyIPTor
@ ProxyIPTor
Definition: optionsmodel.h:57
OptionsModel::ProxyUseTor
@ ProxyUseTor
Definition: optionsmodel.h:56
OptionsModel::language
QString language
Definition: optionsmodel.h:110
OptionsModel::ProxyPortTor
@ ProxyPortTor
Definition: optionsmodel.h:58
OptionsModel::CoinControlFeatures
@ CoinControlFeatures
Definition: optionsmodel.h:63
OptionsModel::fCoinControlFeatures
bool fCoinControlFeatures
Definition: optionsmodel.h:114
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
GB_BYTES
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:53
OptionsModel::Init
void Init(bool resetSettings=false)
Definition: optionsmodel.cpp:44
OptionsModel::setNode
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:102
OptionsModel::ProxyIP
@ ProxyIP
Definition: optionsmodel.h:54
OptionsModel::Prune
@ Prune
Definition: optionsmodel.h:65
OptionsModel::ThirdPartyTxUrls
@ ThirdPartyTxUrls
Definition: optionsmodel.h:60
OptionsModel::MapPortUPnP
@ MapPortUPnP
Definition: optionsmodel.h:50
guiconstants.h
OptionsModel::getDisplayUnit
int getDisplayUnit() const
Definition: optionsmodel.h:87
OptionsModel::Language
@ Language
Definition: optionsmodel.h:61
DEFAULT_GUI_PROXY_HOST
const char * DEFAULT_GUI_PROXY_HOST
Definition: optionsmodel.cpp:28
OptionsModel::MapPortNatpmp
@ MapPortNatpmp
Definition: optionsmodel.h:51
PruneGBtoMiB
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:31
OptionsModel::useEmbeddedMonospacedFontChanged
void useEmbeddedMonospacedFontChanged(bool)
node
Definition: interfaces.cpp:66
OptionsModel::getThirdPartyTxUrls
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:88
OptionsModel::getMinimizeToTray
bool getMinimizeToTray() const
Definition: optionsmodel.h:85
amount.h
OptionsModel::UseEmbeddedMonospacedFont
@ UseEmbeddedMonospacedFont
Definition: optionsmodel.h:62
OptionsModel::getUseEmbeddedMonospacedFont
bool getUseEmbeddedMonospacedFont() const
Definition: optionsmodel.h:89
OptionsModel::coinControlFeaturesChanged
void coinControlFeaturesChanged(bool)
OptionsModel::setRestartRequired
void setRestartRequired(bool fRequired)
Definition: optionsmodel.cpp:542
OptionsModel::getShowTrayIcon
bool getShowTrayIcon() const
Definition: optionsmodel.h:84