Bitcoin Core 28.99.0
P2P Digital Currency
optionsmodel.h
Go to the documentation of this file.
1// Copyright (c) 2011-2022 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/bitcoinunits.h>
10#include <qt/guiconstants.h>
11
12#include <QAbstractListModel>
13#include <QFont>
14
15#include <assert.h>
16#include <variant>
17
18struct bilingual_str;
19namespace interfaces {
20class Node;
21}
22
23extern const char *DEFAULT_GUI_PROXY_HOST;
24static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
25
29static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
30
34static inline int64_t PruneGBtoMiB(int gb) { return gb * GB_BYTES / 1024 / 1024; }
35
42class OptionsModel : public QAbstractListModel
43{
44 Q_OBJECT
45
46public:
47 explicit OptionsModel(interfaces::Node& node, QObject *parent = nullptr);
48
49 enum OptionID {
51 ShowTrayIcon, // bool
55 ProxyUse, // bool
56 ProxyIP, // QString
57 ProxyPort, // int
58 ProxyUseTor, // bool
59 ProxyIPTor, // QString
61 DisplayUnit, // BitcoinUnit
62 ThirdPartyTxUrls, // QString
63 Language, // QString
64 FontForMoney, // FontChoice
68 Prune, // bool
69 PruneSize, // int
73 Listen, // bool
74 Server, // bool
76 MaskValues, // bool
78 };
79
80 enum class FontChoiceAbstract {
81 EmbeddedFont,
82 BestSystemFont,
83 };
84 typedef std::variant<FontChoiceAbstract, QFont> FontChoice;
86 static QFont getFontForChoice(const FontChoice& fc);
87
88 bool Init(bilingual_str& error);
89 void Reset();
90
91 int rowCount(const QModelIndex & parent = QModelIndex()) const override;
92 QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
93 bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
94 QVariant getOption(OptionID option, const std::string& suffix="") const;
95 bool setOption(OptionID option, const QVariant& value, const std::string& suffix="");
97 void setDisplayUnit(const QVariant& new_unit);
98
99 /* Explicit getters */
100 bool getShowTrayIcon() const { return m_show_tray_icon; }
101 bool getMinimizeToTray() const { return fMinimizeToTray; }
102 bool getMinimizeOnClose() const { return fMinimizeOnClose; }
104 QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
105 QFont getFontForMoney() const;
110
112 bool hasSigner();
113
114 /* Explicit setters */
115 void SetPruneTargetGB(int prune_target_gb);
116
117 /* Restart flag helper */
118 void setRestartRequired(bool fRequired);
119 bool isRestartRequired() const;
120
121 interfaces::Node& node() const { return m_node; }
122
123private:
125 /* Qt-only settings */
129 QString language;
137
138 /* settings that were overridden by command-line */
140
141 static QString FontChoiceToString(const OptionsModel::FontChoice&);
142 static FontChoice FontChoiceFromString(const QString&);
143
144 // Add option to list of GUI options overridden through command line/config file
145 void addOverriddenOption(const std::string &option);
146
147 // Check settings version and upgrade default values if required
148 void checkAndMigrate();
149
150Q_SIGNALS:
154 void fontForMoneyChanged(const QFont&);
155};
156
157Q_DECLARE_METATYPE(OptionsModel::FontChoice)
158
159#endif // BITCOIN_QT_OPTIONSMODEL_H
Unit
Bitcoin units.
Definition: bitcoinunits.h:42
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:43
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
BitcoinUnit m_display_bitcoin_unit
Definition: optionsmodel.h:130
QString strOverriddenByCommandLine
Definition: optionsmodel.h:139
std::variant< FontChoiceAbstract, QFont > FontChoice
Definition: optionsmodel.h:84
bool isRestartRequired() const
QFont getFontForMoney() const
bool getCoinControlFeatures() const
Definition: optionsmodel.h:106
bool fCoinControlFeatures
Definition: optionsmodel.h:133
bool getEnablePSBTControls() const
Definition: optionsmodel.h:108
interfaces::Node & node() const
Definition: optionsmodel.h:121
void coinControlFeaturesChanged(bool)
QString strThirdPartyTxUrls
Definition: optionsmodel.h:131
bool getSubFeeFromAmount() const
Definition: optionsmodel.h:107
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool m_sub_fee_from_amount
Definition: optionsmodel.h:134
bool setOption(OptionID option, const QVariant &value, const std::string &suffix="")
interfaces::Node & m_node
Definition: optionsmodel.h:124
void displayUnitChanged(BitcoinUnit unit)
void SetPruneTargetGB(int prune_target_gb)
bool Init(bilingual_str &error)
void showTrayIconChanged(bool)
OptionsModel(interfaces::Node &node, QObject *parent=nullptr)
bool getMinimizeToTray() const
Definition: optionsmodel.h:101
bool fMinimizeToTray
Definition: optionsmodel.h:127
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:103
bool getShowTrayIcon() const
Definition: optionsmodel.h:100
bool hasSigner()
Whether -signer was set or not.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
bool m_mask_values
Definition: optionsmodel.h:136
const QString & getOverriddenByCommandLine()
Definition: optionsmodel.h:109
bool m_enable_psbt_controls
Definition: optionsmodel.h:135
QVariant getOption(OptionID option, const std::string &suffix="") const
bool getMinimizeOnClose() const
Definition: optionsmodel.h:102
void setDisplayUnit(const QVariant &new_unit)
Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal.
FontChoice m_font_money
Definition: optionsmodel.h:132
static FontChoice FontChoiceFromString(const QString &)
static QFont getFontForChoice(const FontChoice &fc)
QString getThirdPartyTxUrls() const
Definition: optionsmodel.h:104
void checkAndMigrate()
void fontForMoneyChanged(const QFont &)
QString language
Definition: optionsmodel.h:129
static QString FontChoiceToString(const OptionsModel::FontChoice &)
void addOverriddenOption(const std::string &option)
static const FontChoice UseBestSystemFont
Definition: optionsmodel.h:85
bool fMinimizeOnClose
Definition: optionsmodel.h:128
void setRestartRequired(bool fRequired)
bool m_show_tray_icon
Definition: optionsmodel.h:126
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:71
static constexpr uint64_t GB_BYTES
Definition: guiconstants.h:58
Definition: messages.h:20
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
Definition: optionsmodel.h:29
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
Definition: optionsmodel.h:34
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
Definition: optionsmodel.h:24
const char * DEFAULT_GUI_PROXY_HOST
Bilingual messages:
Definition: translation.h:21