forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgovernancelist.h
129 lines (103 loc) · 3.21 KB
/
governancelist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) 2021-2024 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_GOVERNANCELIST_H
#define BITCOIN_QT_GOVERNANCELIST_H
#include <governance/object.h>
#include <primitives/transaction.h>
#include <qt/bitcoinunits.h>
#include <sync.h>
#include <util/system.h>
#include <QAbstractTableModel>
#include <QDateTime>
#include <QMenu>
#include <QSortFilterProxyModel>
#include <QTimer>
#include <QWidget>
inline constexpr int GOVERNANCELIST_UPDATE_SECONDS = 10;
namespace Ui {
class GovernanceList;
}
class CDeterministicMNList;
class ClientModel;
class ProposalModel;
/** Governance Manager page widget */
class GovernanceList : public QWidget
{
Q_OBJECT
public:
explicit GovernanceList(QWidget* parent = nullptr);
~GovernanceList() override;
void setClientModel(ClientModel* clientModel);
private:
ClientModel* clientModel{nullptr};
std::unique_ptr<Ui::GovernanceList> ui;
ProposalModel* proposalModel;
QSortFilterProxyModel* proposalModelProxy;
QMenu* proposalContextMenu;
QTimer* timer;
private Q_SLOTS:
void updateDisplayUnit();
void updateProposalList();
void updateProposalCount() const;
void showProposalContextMenu(const QPoint& pos);
void showAdditionalInfo(const QModelIndex& index);
};
class Proposal : public QObject
{
private:
Q_OBJECT
ClientModel* clientModel;
const CGovernanceObject govObj;
QString m_title;
QDateTime m_startDate;
QDateTime m_endDate;
double m_paymentAmount;
QString m_url;
public:
explicit Proposal(ClientModel* _clientModel, const CGovernanceObject& _govObj, QObject* parent = nullptr);
QString title() const;
QString hash() const;
QDateTime startDate() const;
QDateTime endDate() const;
double paymentAmount() const;
QString url() const;
bool isActive() const;
QString votingStatus(int nAbsVoteReq) const;
int GetAbsoluteYesCount() const;
void openUrl() const;
QString toJson() const;
};
class ProposalModel : public QAbstractTableModel
{
Q_OBJECT
private:
QList<const Proposal*> m_data;
int nAbsVoteReq = 0;
int m_display_unit{BitcoinUnits::DASH};
public:
explicit ProposalModel(QObject* parent = nullptr) :
QAbstractTableModel(parent){};
enum Column : int {
HASH = 0,
TITLE,
START_DATE,
END_DATE,
PAYMENT_AMOUNT,
IS_ACTIVE,
VOTING_STATUS,
_COUNT // for internal use only
};
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
static int columnWidth(int section);
void append(const Proposal* proposal);
void remove(int row);
void reconcile(Span<const Proposal*> proposals);
void setVotingParams(int nAbsVoteReq);
const Proposal* getProposalAt(const QModelIndex& index) const;
void setDisplayUnit(int display_unit);
};
#endif // BITCOIN_QT_GOVERNANCELIST_H