Skip to content

Commit

Permalink
feat(qt): Governance Tab should respect selected units and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Nov 18, 2024
1 parent 018d80a commit f074cae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/qt/governancelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <netbase.h>
#include <qt/clientmodel.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>

#include <univalue.h>

Expand Down Expand Up @@ -135,8 +136,9 @@ QVariant ProposalModel::data(const QModelIndex& index, int role) const
return proposal->startDate().date();
case Column::END_DATE:
return proposal->endDate().date();
case Column::PAYMENT_AMOUNT:
return proposal->paymentAmount();
case Column::PAYMENT_AMOUNT: {
return BitcoinUnits::floorWithUnit(m_display_unit, proposal->paymentAmount() * COIN, false, BitcoinUnits::SeparatorStyle::ALWAYS);
}
case Column::IS_ACTIVE:
return proposal->isActive() ? tr("Yes") : tr("No");
case Column::VOTING_STATUS:
Expand Down Expand Up @@ -283,6 +285,11 @@ const Proposal* ProposalModel::getProposalAt(const QModelIndex& index) const
return m_data[index.row()];
}

void ProposalModel::setDisplayUnit(int display_unit)
{
this->m_display_unit = display_unit;
}

//
// Governance Tab main widget.
//
Expand Down Expand Up @@ -340,6 +347,17 @@ void GovernanceList::setClientModel(ClientModel* model)
{
this->clientModel = model;
updateProposalList();
if (model != nullptr) {
connect(model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &GovernanceList::updateDisplayUnit);
}
}

void GovernanceList::updateDisplayUnit()
{
if (this->clientModel) {
proposalModel->setDisplayUnit(this->clientModel->getOptionsModel()->getDisplayUnit());
ui->govTableView->update();
}
}

void GovernanceList::updateProposalList()
Expand Down
5 changes: 5 additions & 0 deletions src/qt/governancelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <governance/object.h>
#include <primitives/transaction.h>
#include <qt/bitcoinunits.h>
#include <sync.h>
#include <util/system.h>

Expand Down Expand Up @@ -48,6 +49,7 @@ class GovernanceList : public QWidget
QTimer* timer;

private Q_SLOTS:
void updateDisplayUnit();
void updateProposalList();
void updateProposalCount() const;
void showProposalContextMenu(const QPoint& pos);
Expand Down Expand Up @@ -92,6 +94,7 @@ class ProposalModel : public QAbstractTableModel
private:
QList<const Proposal*> m_data;
int nAbsVoteReq = 0;
int m_display_unit{BitcoinUnits::DASH};

public:
explicit ProposalModel(QObject* parent = nullptr) :
Expand Down Expand Up @@ -119,6 +122,8 @@ class ProposalModel : public QAbstractTableModel
void setVotingParams(int nAbsVoteReq);

const Proposal* getProposalAt(const QModelIndex& index) const;

void setDisplayUnit(int display_unit);
};

#endif // BITCOIN_QT_GOVERNANCELIST_H

0 comments on commit f074cae

Please sign in to comment.