Add context menu on transaction list: copy label, copy address, edit label, show...
[novacoin.git] / src / qt / addresstablemodel.h
1 #ifndef ADDRESSTABLEMODEL_H
2 #define ADDRESSTABLEMODEL_H
3
4 #include <QAbstractTableModel>
5 #include <QStringList>
6
7 class AddressTablePriv;
8 class CWallet;
9
10 class AddressTableModel : public QAbstractTableModel
11 {
12     Q_OBJECT
13 public:
14     explicit AddressTableModel(CWallet *wallet, QObject *parent = 0);
15     ~AddressTableModel();
16
17     enum ColumnIndex {
18         Label = 0,   /* User specified label */
19         Address = 1  /* Bitcoin address */
20     };
21
22     enum {
23         TypeRole = Qt::UserRole
24     } RoleIndex;
25
26     static const QString Send; /* Send addres */
27     static const QString Receive; /* Receive address */
28
29     /* Overridden methods from QAbstractTableModel */
30     int rowCount(const QModelIndex &parent) const;
31     int columnCount(const QModelIndex &parent) const;
32     QVariant data(const QModelIndex &index, int role) const;
33     bool setData(const QModelIndex & index, const QVariant & value, int role);
34     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
35     QModelIndex index(int row, int column, const QModelIndex & parent) const;
36     bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
37     Qt::ItemFlags flags(const QModelIndex & index) const;
38
39     /* Add an address to the model.
40        Returns the added address on success, and an empty string otherwise.
41      */
42     QString addRow(const QString &type, const QString &label, const QString &address);
43
44     /* Update address list from core. Invalidates any indices.
45      */
46     void updateList();
47
48     /* Check address for validity
49      */
50     bool validateAddress(const QString &address);
51
52     /* Look up label for address in address book, if not found return empty string.
53      */
54     QString labelForAddress(const QString &address) const;
55
56     /* Look up row index of an address in the model.
57        Return -1 if not found.
58      */
59     int lookupAddress(const QString &address) const;
60
61 private:
62     CWallet *wallet;
63     AddressTablePriv *priv;
64     QStringList columns;
65
66 signals:
67     void defaultAddressChanged(const QString &address);
68
69 public slots:
70     void update();
71 };
72
73 #endif // ADDRESSTABLEMODEL_H