1 #ifndef SUPERSTAKERITEMMODEL_H
2 #define SUPERSTAKERITEMMODEL_H
3 
4 #include <QAbstractItemModel>
5 #include <QStringList>
6 #include <QThread>
7 
8 #include <memory>
9 
10 namespace interfaces {
11 class Handler;
12 }
13 
14 class WalletModel;
15 class SuperStakerItemPriv;
16 class SuperStakerWorker;
17 class SuperStakerItemEntry;
18 
19 class SuperStakerItemModel : public QAbstractItemModel
20 {
21     Q_OBJECT
22 public:
23     enum ColumnIndex {
24         StakerName = 0,
25         StakerAddress = 1,
26         MinFee = 2,
27         Staking = 3,
28         Time = 4
29     };
30 
31     enum DataRole{
32         HashRole = Qt::UserRole + 1,
33         StakerNameRole = Qt::UserRole + 2,
34         StakerAddressRole = Qt::UserRole + 3,
35         MinFeeRole = Qt::UserRole + 4,
36         StakingRole = Qt::UserRole + 5,
37         FormattedMinFeeRole = Qt::UserRole + 6,
38         BalanceRole = Qt::UserRole + 7,
39         StakeRole = Qt::UserRole + 8,
40         WeightRole = Qt::UserRole + 9,
41         FormattedWeightRole = Qt::UserRole + 10,
42         DelegationsWeightRole = Qt::UserRole + 11,
43         FormattedDelegationsWeightRole = Qt::UserRole + 12,
44     };
45 
46     SuperStakerItemModel(WalletModel *parent = 0);
47     ~SuperStakerItemModel();
48 
49     /** @name Methods overridden from QAbstractItemModel
50         @{*/
51     QModelIndex index(int row, int column,
52                               const QModelIndex &parent = QModelIndex()) const;
53     QModelIndex parent(const QModelIndex &child) const;
54     int rowCount(const QModelIndex &parent = QModelIndex()) const;
55     int columnCount(const QModelIndex &parent = QModelIndex()) const;
56     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
57     /*@}*/
58 
59     void updateSuperStakerData(const SuperStakerItemEntry& entry);
60 
61 public Q_SLOTS:
62     void checkSuperStakerChanged();
63     void itemChanged(QString hash, qint64 balance, qint64 stake, qint64 weight, qint64 delegationsWeight, bool staking);
64 
65 private Q_SLOTS:
66     void updateSuperStakerData(const QString &hash, int status, bool showSuperStaker);
67 
68 private:
69     /** Notify listeners that data changed. */
70     void emitDataChanged(int index);
71     void subscribeToCoreSignals();
72     void unsubscribeFromCoreSignals();
73     QString formatMinFee(const SuperStakerItemEntry *rec) const;
74 
75     QStringList columns;
76     WalletModel *walletModel;
77     SuperStakerItemPriv* priv;
78     SuperStakerWorker* worker;
79     QThread t;
80     std::unique_ptr<interfaces::Handler> m_handler_superstaker_changed;
81 
82     friend class SuperStakerItemPriv;
83 };
84 
85 #endif // SUPERSTAKERITEMMODEL_H
86