PIVX Core  5.6.99
P2P Digital Currency
addresstablemodel.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_ADDRESSTABLEMODEL_H
7 #define PIVX_QT_ADDRESSTABLEMODEL_H
8 
9 #include <QAbstractTableModel>
10 #include <QStringList>
11 
12 class AddressTablePriv;
13 class WalletModel;
14 
15 class CWallet;
16 
20 class AddressTableModel : public QAbstractTableModel
21 {
22  Q_OBJECT
23 
24 public:
25  explicit AddressTableModel(CWallet* wallet, WalletModel* parent = 0);
27 
28  enum ColumnIndex {
29  Label = 0,
30  Address = 1,
31  Date = 2,
32  Type = 3
33  };
34 
35  enum RoleIndex {
36  TypeRole = Qt::UserRole
37  };
38 
40  enum EditStatus {
41  OK,
47  };
48 
49  static const QString Send;
50  static const QString Receive;
51  static const QString Zerocoin;
52  static const QString Delegator;
53  static const QString Delegable;
54  static const QString ColdStaking;
55  static const QString ColdStakingSend;
56  static const QString ShieldedReceive;
57  static const QString ShieldedSend;
61  int rowCount(const QModelIndex& parent) const;
62  int columnCount(const QModelIndex& parent) const;
63  int sizeSend() const;
64  int sizeRecv() const;
65  int sizeDell() const;
66  int sizeColdSend() const;
67  int sizeShieldedSend() const;
68  int sizeSendAll() const;
69  void notifyChange(const QModelIndex &index);
70  QVariant data(const QModelIndex& index, int role) const;
71  bool setData(const QModelIndex& index, const QVariant& value, int role);
72  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
73  QModelIndex index(int row, int column, const QModelIndex& parent) const;
74  bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
75  Qt::ItemFlags flags(const QModelIndex& index) const;
78  /* Add an address to the model.
79  Returns the added address on success, and an empty string otherwise.
80  */
81  QString addRow(const QString& type, const QString& label, const QString& address);
82 
83  /* Look up label for address in address book, if not found return empty string.
84  */
85  QString labelForAddress(const QString& address) const;
86 
87  /* Look up row index of an address in the model.
88  Return -1 if not found.
89  */
90  int lookupAddress(const QString& address) const;
91 
92  /*
93  * Look up purpose for address in address book, if not found return empty string
94  */
95  std::string purposeForAddress(const std::string& address) const;
96 
100  bool isWhitelisted(const std::string& address) const;
101 
105  QString getAddressToShow(bool shielded = false) const;
106 
107  EditStatus getEditStatus() const { return editStatus; }
108 
109 private:
111  CWallet* wallet{nullptr};
113  QStringList columns{};
115 
117  void emitDataChanged(int index);
118 
119 public Q_SLOTS:
120  /* Update address list from core.
121  */
122  void updateEntry(const QString& address, const QString& label, bool isMine, const QString& purpose, int status);
123  void updateEntry(const QString &pubCoin, const QString &isUsed, int status);
124  friend class AddressTablePriv;
125 };
126 
127 #endif // PIVX_QT_ADDRESSTABLEMODEL_H
Qt model of the address book in the core.
@ TypeRole
Type of address (Send, Receive, ColdStaking, ColdStakingSend, Delegator, Delegable)
int lookupAddress(const QString &address) const
AddressTablePriv * priv
int columnCount(const QModelIndex &parent) const
static const QString Delegator
Specifies cold staking addresses which delegated tokens to this wallet and ARE being staked.
AddressTableModel(CWallet *wallet, WalletModel *parent=0)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
static const QString ColdStakingSend
Specifies send cold staking addresses (simil 'contacts')
static const QString ShieldedSend
Specifies shielded receive address.
EditStatus getEditStatus() const
WalletModel * walletModel
EditStatus
Return status of edit/insert operation.
@ WALLET_UNLOCK_FAILURE
Wallet could not be unlocked to create new receiving address.
@ NO_CHANGES
No changes were made during edit operation.
@ INVALID_ADDRESS
Unparsable address.
@ KEY_GENERATION_FAILURE
Generating a new public key for a receiving address failed.
@ OK
Everything ok.
@ DUPLICATE_ADDRESS
Address already in address book.
void emitDataChanged(int index)
Notify listeners that data changed.
@ Address
Bitcoin address.
@ Label
User specified label.
@ Date
Address creation date.
@ Type
Address Type.
std::string purposeForAddress(const std::string &address) const
static const QString ShieldedReceive
Specifies shielded send address.
Qt::ItemFlags flags(const QModelIndex &index) const
bool setData(const QModelIndex &index, const QVariant &value, int role)
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
QModelIndex index(int row, int column, const QModelIndex &parent) const
int sizeShieldedSend() const
QVariant data(const QModelIndex &index, int role) const
static const QString Send
Specifies send address.
bool isWhitelisted(const std::string &address) const
Checks if the address is whitelisted.
static const QString Zerocoin
Specifies stealth address.
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
QString getAddressToShow(bool shielded=false) const
Return last unused address.
QString addRow(const QString &type, const QString &label, const QString &address)
static const QString Delegable
Specifies cold staking addresses which delegated tokens to this wallet.
void notifyChange(const QModelIndex &index)
static const QString Receive
Specifies receive address.
int rowCount(const QModelIndex &parent) const
static const QString ColdStaking
Specifies cold staking own addresses.
QString labelForAddress(const QString &address) const
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:577
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109