PIVX Core  5.6.99
P2P Digital Currency
coincontroldialog.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Copyright (c) 2017-2021 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_QT_COINCONTROLDIALOG_H
7 #define PIVX_QT_COINCONTROLDIALOG_H
8 
9 #include "amount.h"
10 #include "optional.h"
11 #include "snackbar.h"
12 #include "uint256.h"
13 
14 #include <QAbstractButton>
15 #include <QAction>
16 #include <QDialog>
17 #include <QList>
18 #include <QMenu>
19 #include <QPoint>
20 #include <QString>
21 #include <QTreeWidgetItem>
22 
23 class WalletModel;
24 class CCoinControl;
25 class CTxMemPool;
26 
27 struct TotalAmounts {
28  CAmount nPayAmount{0}; // sum of recipients send amount
29  CAmount nAmount{0}; // sum of value of selected inputs
30  CAmount nPayFee{0}; // expected tx fee
31  CAmount nAfterFee{0}; // nAmount - nPayFee
32  CAmount nChange{0}; // nAfterFee - nPayAmount
33  unsigned int nQuantity{0}; // number of selected inputs
34  unsigned int nBytes{0}; // expected tx size
35  bool fDust{false}; // true if any output is below the dust threshold
36 };
37 
38 namespace Ui
39 {
40 class CoinControlDialog;
41 }
42 
43 class CCoinControlWidgetItem : public QTreeWidgetItem
44 {
45 public:
46  explicit CCoinControlWidgetItem(QTreeWidget *parent, int type = Type) : QTreeWidgetItem(parent, type) {}
47  explicit CCoinControlWidgetItem(int type = Type) : QTreeWidgetItem(type) {}
48  explicit CCoinControlWidgetItem(QTreeWidgetItem *parent, int type = Type) : QTreeWidgetItem(parent, type) {}
49 
50  bool operator<(const QTreeWidgetItem &other) const override;
51 };
52 
53 class CoinControlDialog : public QDialog
54 {
55  Q_OBJECT
56 
57 public:
58  explicit CoinControlDialog(QWidget* parent = nullptr, bool _forDelegation = false);
59  ~CoinControlDialog() override;
60 
61  void setModel(WalletModel* model);
62  void updateLabels();
63  void updateView();
64  void refreshDialog();
65  void clearPayAmounts();
66  void addPayAmount(const CAmount& amount, bool isShieldedRecipient);
67  void setSelectionType(bool isTransparent) { fSelectTransparent = isTransparent; }
68  bool hasModel() { return model; }
69 
71 
72 private:
73  Ui::CoinControlDialog* ui{nullptr};
74  SnackBar *snackBar{nullptr};
75  WalletModel* model{nullptr};
77  Qt::SortOrder sortOrder;
80  // pair (recipient amount, ishielded recipient)
81  std::vector<std::pair<CAmount, bool>> payAmounts{};
82  unsigned int nSelectableInputs{0};
83 
84  // whether should show available utxo or notes.
85  bool fSelectTransparent{true};
86 
87  QMenu* contextMenu{nullptr};
88  QTreeWidgetItem* contextMenuItem{nullptr};
89  QAction* copyTransactionHashAction{nullptr};
90  QAction* lockAction{nullptr};
91  QAction* unlockAction{nullptr};
92 
93  void updatePushButtonSelectAll(bool checked);
94  void sortView(int, Qt::SortOrder);
95  void inform(const QString& text);
96  void toggleItemLock(QTreeWidgetItem* item);
97  void toggleCoinLock();
98 
99  // Load a row with coin's data
100  void loadAvailableCoin(bool treeMode,
101  CCoinControlWidgetItem* itemWalletAddress,
102  QFlags<Qt::ItemFlag> flgCheckbox,
103  QFlags<Qt::ItemFlag> flgTristate,
104  int nDisplayUnit,
105  const QString& sWalletAddress,
106  const Optional<QString>& stakerAddress,
107  const QString& sWalletLabel,
108  const uint256& txhash,
109  const uint32_t outIndex,
110  const CAmount nValue,
111  const int64_t nTime,
112  const int nDepth,
113  const bool isChange);
114 
115  // calculate sums for selected amount, number of inputs, change, fee, after fee value, and transaction size
116  TotalAmounts getTotals() const;
117 
118 
119  enum {
128  };
130 
131 private Q_SLOTS:
132  void showMenu(const QPoint&);
133  void copyAmount();
134  void copyLabel();
135  void copyAddress();
136  void copyTransactionHash();
137  void lockCoin();
138  void unlockCoin();
139  void clipboardQuantity();
140  void clipboardAmount();
141  void clipboardFee();
142  void clipboardAfterFee();
143  void clipboardBytes();
144  void clipboardLowOutput();
145  void clipboardChange();
146  void radioTreeMode(bool);
147  void radioListMode(bool);
148  void viewItemChanged(QTreeWidgetItem*, int);
149  void headerSectionClicked(int);
150  void buttonSelectAllClicked();
152  void updateLabelLocked();
153 };
154 
155 #endif // PIVX_QT_COINCONTROLDIALOG_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
Coin Control Features.
Definition: coincontrol.h:34
CCoinControlWidgetItem(QTreeWidgetItem *parent, int type=Type)
bool operator<(const QTreeWidgetItem &other) const override
CCoinControlWidgetItem(QTreeWidget *parent, int type=Type)
CCoinControlWidgetItem(int type=Type)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:384
void updatePushButtonSelectAll(bool checked)
QTreeWidgetItem * contextMenuItem
CoinControlDialog(QWidget *parent=nullptr, bool _forDelegation=false)
WalletModel * model
void toggleItemLock(QTreeWidgetItem *item)
void setSelectionType(bool isTransparent)
TotalAmounts getTotals() const
void loadAvailableCoin(bool treeMode, CCoinControlWidgetItem *itemWalletAddress, QFlags< Qt::ItemFlag > flgCheckbox, QFlags< Qt::ItemFlag > flgTristate, int nDisplayUnit, const QString &sWalletAddress, const Optional< QString > &stakerAddress, const QString &sWalletLabel, const uint256 &txhash, const uint32_t outIndex, const CAmount nValue, const int64_t nTime, const int nDepth, const bool isChange)
unsigned int nSelectableInputs
void setModel(WalletModel *model)
CCoinControl * coinControl
QAction * copyTransactionHashAction
void inform(const QString &text)
Ui::CoinControlDialog * ui
void sortView(int, Qt::SortOrder)
void showMenu(const QPoint &)
void addPayAmount(const CAmount &amount, bool isShieldedRecipient)
void viewItemChanged(QTreeWidgetItem *, int)
Qt::SortOrder sortOrder
std::vector< std::pair< CAmount, bool > > payAmounts
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109
256-bit opaque blob.
Definition: uint256.h:138
boost::optional< T > Optional
Substitute for C++17 std::optional.
Definition: optional.h:12
unsigned int nQuantity
unsigned int nBytes