Bitcoin Core  21.99.0
P2P Digital Currency
addresstablemodel.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_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 
23 class AddressTableModel : public QAbstractTableModel
24 {
25  Q_OBJECT
26 
27 public:
28  explicit AddressTableModel(WalletModel *parent = nullptr, bool pk_hash_only = false);
30 
31  enum ColumnIndex {
32  Label = 0,
33  Address = 1
34  };
35 
36  enum RoleIndex {
37  TypeRole = Qt::UserRole
38  };
39 
41  enum EditStatus {
42  OK,
48  };
49 
50  static const QString Send;
51  static const QString Receive;
55  int rowCount(const QModelIndex &parent) const override;
56  int columnCount(const QModelIndex &parent) const override;
57  QVariant data(const QModelIndex &index, int role) const override;
58  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
59  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
60  QModelIndex index(int row, int column, const QModelIndex &parent) const override;
61  bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
62  Qt::ItemFlags flags(const QModelIndex &index) const override;
65  /* Add an address to the model.
66  Returns the added address on success, and an empty string otherwise.
67  */
68  QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type);
69 
71  QString labelForAddress(const QString &address) const;
72 
74  QString purposeForAddress(const QString &address) const;
75 
76  /* Look up row index of an address in the model.
77  Return -1 if not found.
78  */
79  int lookupAddress(const QString &address) const;
80 
81  EditStatus getEditStatus() const { return editStatus; }
82 
84 
85 private:
87  AddressTablePriv *priv = nullptr;
88  QStringList columns;
90 
92  bool getAddressData(const QString &address, std::string* name, std::string* purpose) const;
93 
95  void emitDataChanged(int index);
96 
97 public Q_SLOTS:
98  /* Update address list from core.
99  */
100  void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status);
101 
102  friend class AddressTablePriv;
103 };
104 
105 #endif // BITCOIN_QT_ADDRESSTABLEMODEL_H
interfaces
Definition: dummywallet.cpp:10
OutputType
OutputType
Definition: outputtype.h:17
count
static int count
Definition: tests.c:35
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
AddressTableModel::walletModel
WalletModel *const walletModel
Definition: addresstablemodel.h:86
AddressTableModel::AddressTableModel
AddressTableModel(WalletModel *parent=nullptr, bool pk_hash_only=false)
Definition: addresstablemodel.cpp:165
AddressTableModel
Qt model of the address book in the core.
Definition: addresstablemodel.h:23
AddressTableModel::~AddressTableModel
~AddressTableModel()
Definition: addresstablemodel.cpp:173
AddressTableModel::labelForAddress
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
Definition: addresstablemodel.cpp:412
AddressTableModel::KEY_GENERATION_FAILURE
@ KEY_GENERATION_FAILURE
Generating a new public key for a receiving address failed.
Definition: addresstablemodel.h:47
AddressTableModel::Receive
static const QString Receive
Specifies receive address.
Definition: addresstablemodel.h:51
AddressTableModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: addresstablemodel.cpp:194
AddressTableModel::columns
QStringList columns
Definition: addresstablemodel.h:88
AddressTableModel::emitDataChanged
void emitDataChanged(int index)
Notify listeners that data changed.
Definition: addresstablemodel.cpp:453
AddressTableModel::ColumnIndex
ColumnIndex
Definition: addresstablemodel.h:31
AddressTableModel::priv
AddressTablePriv * priv
Definition: addresstablemodel.h:87
AddressTableModel::addRow
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
Definition: addresstablemodel.cpp:343
AddressTableModel::EditStatus
EditStatus
Return status of edit/insert operation.
Definition: addresstablemodel.h:41
AddressTableModel::index
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition: addresstablemodel.cpp:322
AddressTableModel::rowCount
int rowCount(const QModelIndex &parent) const override
Definition: addresstablemodel.cpp:178
AddressTableModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: addresstablemodel.cpp:305
AddressTableModel::Label
@ Label
User specified label.
Definition: addresstablemodel.h:32
AddressTablePriv
Definition: addresstablemodel.cpp:69
AddressTableModel::columnCount
int columnCount(const QModelIndex &parent) const override
Definition: addresstablemodel.cpp:186
AddressTableModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Definition: addresstablemodel.cpp:237
AddressTableModel::RoleIndex
RoleIndex
Definition: addresstablemodel.h:36
AddressTableModel::lookupAddress
int lookupAddress(const QString &address) const
Definition: addresstablemodel.cpp:437
name
const char * name
Definition: rest.cpp:43
AddressTableModel::getEditStatus
EditStatus getEditStatus() const
Definition: addresstablemodel.h:81
AddressTableModel::WALLET_UNLOCK_FAILURE
@ WALLET_UNLOCK_FAILURE
Wallet could not be unlocked to create new receiving address.
Definition: addresstablemodel.h:46
AddressTableModel::TypeRole
@ TypeRole
Type of address (Send or Receive)
Definition: addresstablemodel.h:37
AddressTableModel::INVALID_ADDRESS
@ INVALID_ADDRESS
Unparseable address.
Definition: addresstablemodel.h:44
AddressTableModel::OK
@ OK
Everything ok.
Definition: addresstablemodel.h:42
AddressTableModel::NO_CHANGES
@ NO_CHANGES
No changes were made during edit operation.
Definition: addresstablemodel.h:43
AddressTableModel::Send
static const QString Send
Specifies send address.
Definition: addresstablemodel.h:50
AddressTableModel::updateEntry
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
Definition: addresstablemodel.cpp:336
AddressTableModel::editStatus
EditStatus editStatus
Definition: addresstablemodel.h:89
AddressTableModel::GetDefaultAddressType
OutputType GetDefaultAddressType() const
Definition: addresstablemodel.cpp:451
AddressTableModel::getAddressData
bool getAddressData(const QString &address, std::string *name, std::string *purpose) const
Look up address book data given an address string.
Definition: addresstablemodel.cpp:430
AddressTableModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Definition: addresstablemodel.cpp:398
AddressTableModel::purposeForAddress
QString purposeForAddress(const QString &address) const
Look up purpose for address in address book, if not found return empty string.
Definition: addresstablemodel.cpp:421
AddressTableModel::DUPLICATE_ADDRESS
@ DUPLICATE_ADDRESS
Address already in address book.
Definition: addresstablemodel.h:45
AddressTableModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: addresstablemodel.cpp:293
AddressTableModel::Address
@ Address
Bitcoin address.
Definition: addresstablemodel.h:33