Bitcoin ABC  0.22.12
P2P Digital Currency
addresstablemodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 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_ADDRESSTABLEMODEL_H
6 #define BITCOIN_QT_ADDRESSTABLEMODEL_H
7 
8 #include <QAbstractTableModel>
9 #include <QStringList>
10 
11 enum class OutputType;
12 
13 class AddressTablePriv;
14 class WalletModel;
15 
16 namespace interfaces {
17 class Wallet;
18 }
19 
24 class AddressTableModel : public QAbstractTableModel {
25  Q_OBJECT
26 
27 public:
28  explicit AddressTableModel(WalletModel *parent = nullptr);
30 
31  enum ColumnIndex {
33  Label = 0,
35  Address = 1
36  };
37 
38  enum RoleIndex {
40  TypeRole = Qt::UserRole
41  };
42 
44  enum EditStatus {
46  OK,
56  KEY_GENERATION_FAILURE
57  };
58 
60  static const QString Send;
62  static const QString Receive;
63 
66  int rowCount(const QModelIndex &parent) const override;
67  int columnCount(const QModelIndex &parent) const override;
68  QVariant data(const QModelIndex &index, int role) const override;
69  bool setData(const QModelIndex &index, const QVariant &value,
70  int role) override;
71  QVariant headerData(int section, Qt::Orientation orientation,
72  int role) const override;
73  QModelIndex index(int row, int column,
74  const QModelIndex &parent) const override;
75  bool removeRows(int row, int count,
76  const QModelIndex &parent = QModelIndex()) override;
77  Qt::ItemFlags flags(const QModelIndex &index) const override;
80  /* Add an address to the model.
81  Returns the added address on success, and an empty string otherwise.
82  */
83  QString addRow(const QString &type, const QString &label,
84  const QString &address, const OutputType address_type);
85 
90  QString labelForAddress(const QString &address) const;
91 
96  QString purposeForAddress(const QString &address) const;
97 
98  /* Look up row index of an address in the model.
99  Return -1 if not found.
100  */
101  int lookupAddress(const QString &address) const;
102 
103  EditStatus getEditStatus() const { return editStatus; }
104 
105  OutputType GetDefaultAddressType() const;
106 
107 private:
109  AddressTablePriv *priv = nullptr;
110  QStringList columns;
111  EditStatus editStatus = OK;
112 
114  bool getAddressData(const QString &address, std::string *name,
115  std::string *purpose) const;
116 
118  void emitDataChanged(int index);
119 
120 public Q_SLOTS:
121  /* Update address list from core.
122  */
123  void updateEntry(const QString &address, const QString &label, bool isMine,
124  const QString &purpose, int status);
125 
126  friend class AddressTablePriv;
127 };
128 
129 #endif // BITCOIN_QT_ADDRESSTABLEMODEL_H
Address already in address book.
OutputType
Definition: outputtype.h:17
static const QString Send
Specifies send address.
Wallet could not be unlocked to create new receiving address.
const char * name
Definition: rest.cpp:43
EditStatus
Return status of edit/insert operation.
WalletModel *const walletModel
Qt model of the address book in the core.
int flags
Definition: bitcoin-tx.cpp:529
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
static const QString Receive
Specifies receive address.
static int count
Definition: tests.c:35
No changes were made during edit operation.
EditStatus getEditStatus() const