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
69  Listen, // bool
71  };
72 
73  void Init(bool resetSettings = false);
74  void Reset();
75 
76  int rowCount(const QModelIndex & parent = QModelIndex()) const override;
77  QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
78  bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
80  void setDisplayUnit(const QVariant &value);
81 
82  /* Explicit getters */
83  bool getShowTrayIcon() const { return m_show_tray_icon; }
84  bool getMinimizeToTray() const { return fMinimizeToTray; }
85  bool getMinimizeOnClose() const { return fMinimizeOnClose; }
86  int getDisplayUnit() const { return nDisplayUnit; }
87  QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
91 
92  /* Explicit setters */
93  void SetPruneEnabled(bool prune, bool force = false);
94  void SetPruneTargetGB(int prune_target_gb, bool force = false);
95 
96  /* Restart flag helper */
97  void setRestartRequired(bool fRequired);
98  bool isRestartRequired() const;
99 
100  interfaces::Node& node() const { assert(m_node); return *m_node; }
102 
103 private:
105  /* Qt-only settings */
109  QString language;
114  /* settings that were overridden by command-line */
116 
117  // Add option to list of GUI options overridden through command line/config file
118  void addOverriddenOption(const std::string &option);
119 
120  // Check settings version and upgrade default values if required
121  void checkAndMigrate();
122 Q_SIGNALS:
123  void displayUnitChanged(int unit);
124  void coinControlFeaturesChanged(bool);
125  void showTrayIconChanged(bool);
127 };
128 
129 #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:85
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:90
OptionsModel::Listen
@ Listen
Definition: optionsmodel.h:69
OptionsModel::fMinimizeOnClose
bool fMinimizeOnClose
Definition: optionsmodel.h:108
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:255
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:68
OptionsModel::setDisplayUnit
void setDisplayUnit(const QVariant &value)
Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal.
Definition: optionsmodel.cpp:515
OptionsModel::nDisplayUnit
int nDisplayUnit
Definition: optionsmodel.h:110
OptionsModel::m_node
interfaces::Node * m_node
Definition: optionsmodel.h:104
OptionsModel::OptionIDRowCount
@ OptionIDRowCount
Definition: optionsmodel.h:70
OptionsModel::MinimizeToTray
@ MinimizeToTray
Definition: optionsmodel.h:49
OptionsModel::m_show_tray_icon
bool m_show_tray_icon
Definition: optionsmodel.h:106
OptionsModel::Reset
void Reset()
Definition: optionsmodel.cpp:193
OptionsModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: optionsmodel.cpp:357
OptionsModel::ProxyUse
@ ProxyUse
Definition: optionsmodel.h:53
OptionsModel::node
interfaces::Node & node() const
Definition: optionsmodel.h:100
OptionsModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: optionsmodel.cpp:218
OptionsModel::addOverriddenOption
void addOverriddenOption(const std::string &option)
Definition: optionsmodel.cpp:37
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:31
OptionsModel::isRestartRequired
bool isRestartRequired() const
Definition: optionsmodel.cpp:532
OptionsModel::m_use_embedded_monospaced_font
bool m_use_embedded_monospaced_font
Definition: optionsmodel.h:112
OptionsModel::SetPruneTargetGB
void SetPruneTargetGB(int prune_target_gb, bool force=false)
Definition: optionsmodel.cpp:270
OptionsModel::showTrayIconChanged
void showTrayIconChanged(bool)
OptionsModel::strThirdPartyTxUrls
QString strThirdPartyTxUrls
Definition: optionsmodel.h:111
OptionsModel::getCoinControlFeatures
bool getCoinControlFeatures() const
Definition: optionsmodel.h:89
OptionsModel::StartAtStartup
@ StartAtStartup
Definition: optionsmodel.h:47
OptionsModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: optionsmodel.cpp:281
OptionsModel::checkAndMigrate
void checkAndMigrate()
Definition: optionsmodel.cpp:538
OptionsModel::strOverriddenByCommandLine
QString strOverriddenByCommandLine
Definition: optionsmodel.h:115
OptionsModel::fMinimizeToTray
bool fMinimizeToTray
Definition: optionsmodel.h:107
OptionsModel::ProxyIPTor
@ ProxyIPTor
Definition: optionsmodel.h:57
OptionsModel::ProxyUseTor
@ ProxyUseTor
Definition: optionsmodel.h:56
OptionsModel::language
QString language
Definition: optionsmodel.h:109
OptionsModel::ProxyPortTor
@ ProxyPortTor
Definition: optionsmodel.h:58
OptionsModel::CoinControlFeatures
@ CoinControlFeatures
Definition: optionsmodel.h:63
OptionsModel::fCoinControlFeatures
bool fCoinControlFeatures
Definition: optionsmodel.h:113
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:53
GB_BYTES
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:53
OptionsModel::Init
void Init(bool resetSettings=false)
Definition: optionsmodel.cpp:43
OptionsModel::setNode
void setNode(interfaces::Node &node)
Definition: optionsmodel.h:101
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:86
OptionsModel::Language
@ Language
Definition: optionsmodel.h:61
DEFAULT_GUI_PROXY_HOST
const char * DEFAULT_GUI_PROXY_HOST
Definition: optionsmodel.cpp:27
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:64
OptionsModel::getThirdPartyTxUrls
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:87
OptionsModel::getMinimizeToTray
bool getMinimizeToTray() const
Definition: optionsmodel.h:84
amount.h
assert
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
OptionsModel::UseEmbeddedMonospacedFont
@ UseEmbeddedMonospacedFont
Definition: optionsmodel.h:62
OptionsModel::getUseEmbeddedMonospacedFont
bool getUseEmbeddedMonospacedFont() const
Definition: optionsmodel.h:88
OptionsModel::coinControlFeaturesChanged
void coinControlFeaturesChanged(bool)
OptionsModel::setRestartRequired
void setRestartRequired(bool fRequired)
Definition: optionsmodel.cpp:526
OptionsModel::getShowTrayIcon
bool getShowTrayIcon() const
Definition: optionsmodel.h:83