1 #ifndef DELEGATIONITEMMODEL_H
2 #define DELEGATIONITEMMODEL_H
3 
4 #include <QAbstractItemModel>
5 #include <QStringList>
6 #include <QThread>
7 #include <QtGlobal>
8 
9 #include <memory>
10 
11 namespace interfaces {
12 class Handler;
13 }
14 
15 class WalletModel;
16 class DelegationItemPriv;
17 class DelegationWorker;
18 class DelegationItemEntry;
19 
20 class DelegationItemModel : public QAbstractItemModel
21 {
22     Q_OBJECT
23 public:
24     enum ColumnIndex {
25         Address = 0,
26         StakerName = 1,
27         StakerAddress = 2,
28         Fee = 3,
29         Height = 4,
30         Time = 5
31     };
32 
33     enum DataRole{
34         HashRole = Qt::UserRole + 1,
35         AddressRole = Qt::UserRole + 2,
36         StakerNameRole = Qt::UserRole + 3,
37         StakerAddressRole = Qt::UserRole + 4,
38         FeeRole = Qt::UserRole + 5,
39         BlockHeightRole = Qt::UserRole + 6,
40         CreateTxHashRole = Qt::UserRole + 7,
41         RemoveTxHashRole = Qt::UserRole + 8,
42         FormattedFeeRole = Qt::UserRole + 9,
43         BalanceRole = Qt::UserRole + 10,
44         StakeRole = Qt::UserRole + 11,
45         WeightRole = Qt::UserRole + 12,
46         FormattedWeightRole = Qt::UserRole + 13,
47         TxStatusRole = Qt::UserRole + 14,
48     };
49 
50     enum TxStatus
51     {
52         NoTx = 0,
53         CreateTxConfirmed = 1,
54         CreateTxNotConfirmed = 2,
55         CreateTxError = 3,
56         RemoveTxNotConfirmed = 4,
57         RemoveTxError = 5,
58     };
59 
60     DelegationItemModel(WalletModel *parent = 0);
61     ~DelegationItemModel();
62 
63     /** @name Methods overridden from QAbstractItemModel
64         @{*/
65     QModelIndex index(int row, int column,
66                               const QModelIndex &parent = QModelIndex()) const;
67     QModelIndex parent(const QModelIndex &child) const;
68     int rowCount(const QModelIndex &parent = QModelIndex()) const;
69     int columnCount(const QModelIndex &parent = QModelIndex()) const;
70     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
71     /*@}*/
72 
73     void updateDelegationData(const DelegationItemEntry& entry);
74 
75 public Q_SLOTS:
76     void checkDelegationChanged();
77     void itemChanged(QString hash, qint64 balance, qint64 stake, qint64 weight, qint32 status);
78 
79 private Q_SLOTS:
80     void updateDelegationData(const QString &hash, int status, bool showDelegation);
81 
82 private:
83     /** Notify listeners that data changed. */
84     void emitDataChanged(int index);
85     void subscribeToCoreSignals();
86     void unsubscribeFromCoreSignals();
87     QString formatFee(const DelegationItemEntry *rec) const;
88 
89     QStringList columns;
90     WalletModel *walletModel;
91     DelegationItemPriv* priv;
92     DelegationWorker* worker;
93     QThread t;
94     std::unique_ptr<interfaces::Handler> m_handler_delegation_changed;
95 
96     friend class DelegationItemPriv;
97 };
98 
99 #endif // DELEGATIONITEMMODEL_H
100