Commit 5665e8a6 authored by Artem B's avatar Artem B

Merge branch 'wallet-ui-sorting-by-numbers' into 'Current-dev'

Provide correct sorting to numeric columns in the wallet UI

See merge request crown/crown-core!134
parents 96c754b8 0c6c0cea
......@@ -910,4 +910,28 @@ QString formatPingTime(double dPingTime)
return dPingTime == 0 ? QObject::tr("N/A") : QString(QObject::tr("%1 ms")).arg(QString::number((int)(dPingTime * 1000), 10));
}
/**
* Class constructor.
* @param[int64_t] numValue The Number to convert to a QString for display
*/
QTableWidgetNumberItem::QTableWidgetNumberItem(const int64_t numValue) : QTableWidgetItem(), m_value(numValue)
{
this->setText(QString::number(numValue));
}
/**
* Comparator overload to ensure that the QStrings internally set as numbers are compared as numbers and not strings.
* @param[QTableWidgetItem] item Right hand side of the less than operator
*/
bool QTableWidgetNumberItem::operator<(QTableWidgetItem const& item) const
{
QTableWidgetNumberItem const* rhs = dynamic_cast<QTableWidgetNumberItem const*>(&item);
if (!rhs) {
return QTableWidgetItem::operator<(item);
}
return m_value < rhs->m_value;
}
} // namespace GUIUtil
......@@ -14,6 +14,7 @@
#include <QProgressBar>
#include <QString>
#include <QTableView>
#include <QTableWidget>
#include <boost/filesystem.hpp>
......@@ -172,6 +173,21 @@ namespace GUIUtil
void on_geometriesChanged();
};
/*
* An extension to the QTableWidgetItem that provides the ability to compare numeric values
* in a table widget, reverting back to the default parent comparison when the items are not
* both numeric.
*/
class QTableWidgetNumberItem : public QTableWidgetItem
{
public:
explicit QTableWidgetNumberItem(const int64_t numValue);
virtual bool operator<(QTableWidgetItem const& item) const;
private:
int64_t m_value;
};
bool GetStartOnSystemStartup();
bool SetStartOnSystemStartup(bool fAutoStart);
......
......@@ -568,16 +568,16 @@ void MasternodeList::updateVoteList(bool reset)
urlItem->setOpenExternalLinks(true);
urlItem->setStyleSheet("background-color: transparent;");
QTableWidgetItem *hashItem = new QTableWidgetItem(QString::fromStdString(pbudgetProposal->GetHash().ToString()));
QTableWidgetItem *blockStartItem = new QTableWidgetItem(QString::number((int64_t)pbudgetProposal->GetBlockStart()));
QTableWidgetItem *blockEndItem = new QTableWidgetItem(QString::number((int64_t)pbudgetProposal->GetBlockEnd()));
QTableWidgetItem *paymentsItem = new QTableWidgetItem(QString::number((int64_t)pbudgetProposal->GetTotalPaymentCount()));
QTableWidgetItem *remainingPaymentsItem = new QTableWidgetItem(QString::number((int64_t)pbudgetProposal->GetRemainingPaymentCount()));
QTableWidgetItem *yesVotesItem = new QTableWidgetItem(QString::number((int64_t)pbudgetProposal->GetYeas()));
QTableWidgetItem *noVotesItem = new QTableWidgetItem(QString::number((int64_t)pbudgetProposal->GetNays()));
QTableWidgetItem *abstainVotesItem = new QTableWidgetItem(QString::number((int64_t)pbudgetProposal->GetAbstains()));
GUIUtil::QTableWidgetNumberItem *blockStartItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetBlockStart());
GUIUtil::QTableWidgetNumberItem *blockEndItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetBlockEnd());
GUIUtil::QTableWidgetNumberItem *paymentsItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetTotalPaymentCount());
GUIUtil::QTableWidgetNumberItem *remainingPaymentsItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetRemainingPaymentCount());
GUIUtil::QTableWidgetNumberItem *yesVotesItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetYeas());
GUIUtil::QTableWidgetNumberItem *noVotesItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetNays());
GUIUtil::QTableWidgetNumberItem *abstainVotesItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetAbstains());
QTableWidgetItem *AddressItem = new QTableWidgetItem(QString::fromStdString(address2.ToString()));
QTableWidgetItem *totalPaymentItem = new QTableWidgetItem(QString::number((pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount())/100000000 ));
QTableWidgetItem *monthlyPaymentItem = new QTableWidgetItem(QString::number(pbudgetProposal->GetAmount()/100000000));
GUIUtil::QTableWidgetNumberItem *totalPaymentItem = new GUIUtil::QTableWidgetNumberItem((pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount())/100000000);
GUIUtil::QTableWidgetNumberItem *monthlyPaymentItem = new GUIUtil::QTableWidgetNumberItem(pbudgetProposal->GetAmount()/100000000);
ui->tableWidgetVoting->insertRow(0);
ui->tableWidgetVoting->setItem(0, 0, nameItem);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment