update to 0.4 preview
[novacoin.git] / src / qt / transactiontablemodel.h
1 #ifndef TRANSACTIONTABLEMODEL_H
2 #define TRANSACTIONTABLEMODEL_H
3
4 #include <QAbstractTableModel>
5 #include <QStringList>
6
7 class CWallet;
8 class TransactionTablePriv;
9 class TransactionRecord;
10 class WalletModel;
11
12 /** UI model for the transaction table of a wallet.
13  */
14 class TransactionTableModel : public QAbstractTableModel
15 {
16     Q_OBJECT
17 public:
18     explicit TransactionTableModel(CWallet* wallet, WalletModel *parent = 0);
19     ~TransactionTableModel();
20
21     enum ColumnIndex {
22         Status = 0,
23         Date = 1,
24         Type = 2,
25         ToAddress = 3,
26         Amount = 4
27     };
28
29     /** Roles to get specific information from a transaction row.
30         These are independent of column.
31     */
32     enum RoleIndex {
33         /** Type of transaction */
34         TypeRole = Qt::UserRole,
35         /** Date and time this transaction was created */
36         DateRole,
37         /** Long description (HTML format) */
38         LongDescriptionRole,
39         /** Address of transaction */
40         AddressRole,
41         /** Label of address related to transaction */
42         LabelRole,
43         /** Net amount of transaction */
44         AmountRole,
45         /** Unique identifier */
46         TxIDRole,
47         /** Is transaction confirmed? */
48         ConfirmedRole,
49         /** Formatted amount, without brackets when unconfirmed */
50         FormattedAmountRole
51     };
52
53     int rowCount(const QModelIndex &parent) const;
54     int columnCount(const QModelIndex &parent) const;
55     QVariant data(const QModelIndex &index, int role) const;
56     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
57     QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
58 private:
59     CWallet* wallet;
60     WalletModel *walletModel;
61     QStringList columns;
62     TransactionTablePriv *priv;
63     int cachedNumBlocks;
64
65     QString lookupAddress(const std::string &address, bool tooltip) const;
66     QVariant addressColor(const TransactionRecord *wtx) const;
67     QString formatTxStatus(const TransactionRecord *wtx) const;
68     QString formatTxDate(const TransactionRecord *wtx) const;
69     QString formatTxType(const TransactionRecord *wtx) const;
70     QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const;
71     QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true) const;
72     QString formatTooltip(const TransactionRecord *rec) const;
73     QVariant txStatusDecoration(const TransactionRecord *wtx) const;
74     QVariant txAddressDecoration(const TransactionRecord *wtx) const;
75
76 public slots:
77     void updateTransaction(const QString &hash, int status);
78     void updateConfirmations();
79     void updateDisplayUnit();
80
81     friend class TransactionTablePriv;
82 };
83
84 #endif
85