From f074caeb840798005f329537207f5e5ad25a7f3f Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 19 Nov 2024 00:55:33 +0300 Subject: [PATCH] feat(qt): Governance Tab should respect selected units and settings --- src/qt/governancelist.cpp | 22 ++++++++++++++++++++-- src/qt/governancelist.h | 5 +++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/qt/governancelist.cpp b/src/qt/governancelist.cpp index 2439486b186013..53e7c15bf3c6fb 100644 --- a/src/qt/governancelist.cpp +++ b/src/qt/governancelist.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -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: @@ -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. // @@ -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() diff --git a/src/qt/governancelist.h b/src/qt/governancelist.h index 04c65acdb6539b..6c9621683273cb 100644 --- a/src/qt/governancelist.h +++ b/src/qt/governancelist.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -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); @@ -92,6 +94,7 @@ class ProposalModel : public QAbstractTableModel private: QList m_data; int nAbsVoteReq = 0; + int m_display_unit{BitcoinUnits::DASH}; public: explicit ProposalModel(QObject* parent = nullptr) : @@ -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