forked from David4860/navcoin-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaosupport.cpp
More file actions
158 lines (126 loc) · 4.99 KB
/
Copy pathdaosupport.cpp
File metadata and controls
158 lines (126 loc) · 4.99 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright (c) 2019 The NavCoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "daosupport.h"
DaoSupport::DaoSupport(QWidget *parent, CConsultation consultation) :
layout(new QVBoxLayout),
consultation(consultation),
answerBox(new QGroupBox)
{
this->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
this->setLayout(layout);
auto *bottomBox = new QFrame;
auto *bottomBoxLayout = new QHBoxLayout;
bottomBoxLayout->setContentsMargins(QMargins());
bottomBox->setLayout(bottomBoxLayout);
QPushButton* closeBtn = new QPushButton(tr("Close"));
connect(closeBtn, SIGNAL(clicked()), this, SLOT(onClose()));
warningLbl = new QLabel("");
warningLbl->setObjectName("warning");
warningLbl->setVisible(false);
answerBox = new QGroupBox("");
QVBoxLayout *vbox = new QVBoxLayout;
QVector<QCheckBox*> answers;
CConsultationAnswerMap consultationAnswerMap;
if (pcoinsTip && pcoinsTip->GetAllConsultationAnswers(consultationAnswerMap))
{
CStateViewCache coins(pcoinsTip);
for (auto& it: consultationAnswerMap)
{
CConsultationAnswer c = it.second;
if (c.parent != consultation.hash)
continue;
QString s = QString::fromStdString(consultation.IsAboutConsensusParameter() ? FormatConsensusParameter((Consensus::ConsensusParamsPos)consultation.nMin, c.sAnswer) : c.sAnswer);
QCheckBox* answer = new QCheckBox(s);
answers << answer;
answer->setProperty("id", QString::fromStdString(c.hash.GetHex()));
connect(answer, SIGNAL(toggled(bool)), this, SLOT(onSupport(bool)));
auto v = mapSupported.find(c.hash);
if (v != mapSupported.end())
{
answer->setChecked(true);
}
vbox->addWidget(answer);
}
}
if (answers.size() == 0)
vbox->addWidget(new QLabel(tr("There are no proposed answers")));
QPushButton* proposeBtn = new QPushButton(answers.size() == 0 ? tr("Propose an answer") : tr("Propose a different answer"));
connect(proposeBtn, SIGNAL(clicked()), this, SLOT(onPropose()));
bottomBoxLayout->addStretch(1);
if (consultation.CanHaveNewAnswers())
bottomBoxLayout->addWidget(proposeBtn);
bottomBoxLayout->addWidget(closeBtn);
vbox->addStretch(1);
answerBox->setLayout(vbox);
layout->addSpacing(15);
QLabel* titleLabel = new QLabel(tr("Consultation:<br><br>%1").arg(QString::fromStdString(consultation.strDZeel)));
titleLabel->setWordWrap(true) ;
layout->addWidget(titleLabel);
layout->addSpacing(15);
layout->addWidget(new QLabel(tr("Possible answers:")));
layout->addWidget(answerBox);
if (answers.size() > 0)
{
layout->addWidget(new QLabel(tr("Check the box from the answers you consider valid for the aforementioned question in order to support them.")));
layout->addWidget(new QLabel(tr("Consultations need to gather a minimal support from the network before being allowed to start with the voting.")));
layout->addWidget(new QLabel(tr("Supporting an answer does not mean voting for it, but just agreeing with the answer being part of the final set of possible answers.")));
}
layout->addSpacing(15);
layout->addWidget(warningLbl);
layout->addWidget(bottomBox);
layout->addSpacing(15);
}
void DaoSupport::setModel(WalletModel *model)
{
this->model = model;
}
void DaoSupport::showWarning(QString text)
{
warningLbl->setText(text);
warningLbl->setVisible(text == "" ? false : true);
adjustSize();
}
void DaoSupport::onSupport(bool fChecked)
{
LOCK(cs_main);
QVariant idV = sender()->property("id");
QCheckBox *clickedBox = qobject_cast<QCheckBox*>(sender());
if (idV.isValid())
{
CStateViewCache coins(pcoinsTip);
warningLbl->setVisible(false);
adjustSize();
uint256 hash = uint256S(idV.toString().toStdString());
CConsultationAnswer answer;
if (coins.HaveConsultationAnswer(hash) && coins.GetConsultationAnswer(hash, answer) &&
answer.CanBeSupported(coins))
{
bool duplicate;
if (fChecked)
Support(hash, duplicate);
else
RemoveSupport(hash.ToString());
}
}
}
void DaoSupport::onClose()
{
close();
}
void DaoSupport::onPropose()
{
DaoProposeAnswer dlg(this, consultation, [this](QString s)->bool{
try
{
return consultation.IsAboutConsensusParameter() ? IsValidConsensusParameterProposal((Consensus::ConsensusParamsPos)consultation.nMin, RemoveFormatConsensusParameter((Consensus::ConsensusParamsPos)consultation.nMin, s.toStdString()), chainActive.Tip(), *pcoinsTip) : !s.isEmpty();
}
catch (...)
{
return false;
}
});
dlg.setModel(model);
dlg.exec();
close();
}