296fa5805453cb7588c68af4c9b5514203a7f292
[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 class WalletModel;
10
11 class AddressTableModel : public QAbstractTableModel
12 {
13     Q_OBJECT
14 public:
15     explicit AddressTableModel(CWallet *wallet, WalletModel *parent = 0);
16     ~AddressTableModel();
17
18     enum ColumnIndex {
19         Label = 0,   /* User specified label */
20         Address = 1  /* Bitcoin address */
21     };
22
23     enum RoleIndex {
24         TypeRole = Qt::UserRole
25     };
26
27     // Return status of last edit/insert operation
28     enum EditStatus {
29         OK = 0,
30         INVALID_ADDRESS = 1,
31         DUPLICATE_ADDRESS = 2
32     };
33
34     static const QString Send; /* Send addres */
35     static const QString Receive; /* Receive address */
36
37     /* Overridden methods from QAbstractTableModel */
38     int rowCount(const QModelIndex &parent) const;
39     int columnCount(const QModelIndex &parent) const;
40     QVariant data(const QModelIndex &index, int role) const;
41     bool setData(const QModelIndex & index, const QVariant & value, int role);
42     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
43     QModelIndex index(int row, int column, const QModelIndex & parent) const;
44     bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
45     Qt::ItemFlags flags(const QModelIndex & index) const;
46
47     /* Add an address to the model.
48        Returns the added address on success, and an empty string otherwise.
49      */
50     QString addRow(const QString &type, const QString &label, const QString &address);
51
52     /* Update address list from core. Invalidates any indices.
53      */
54     void updateList();
55
56     /* Look up label for address in address book, if not found return empty string.
57      */
58     QString labelForAddress(const QString &address) const;
59
60     /* Look up row index of an address in the model.
61        Return -1 if not found.
62      */
63     int lookupAddress(const QString &address) const;
64
65     EditStatus getEditStatus() const { return editStatus; }
66
67 private:
68     WalletModel *walletModel;
69     CWallet *wallet;
70     AddressTablePriv *priv;
71     QStringList columns;
72     EditStatus editStatus;
73
74 signals:
75     void defaultAddressChanged(const QString &address);
76
77 public slots:
78     void update();
79 };
80
81 #endif // ADDRESSTABLEMODEL_H