[Qt] fix coincontrol sort issue

This commit is contained in:
Jonas Schnelli 2016-11-18 10:26:38 +01:00
parent 9346f84299
commit 76af4eb876
No known key found for this signature in database
GPG Key ID: 29D4BCB6416F53EC
2 changed files with 27 additions and 6 deletions

View File

@ -35,6 +35,15 @@ QList<CAmount> CoinControlDialog::payAmounts;
CCoinControl* CoinControlDialog::coinControl = new CCoinControl(); CCoinControl* CoinControlDialog::coinControl = new CCoinControl();
bool CoinControlDialog::fSubtractFeeFromAmount = false; bool CoinControlDialog::fSubtractFeeFromAmount = false;
bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
int column = treeWidget()->sortColumn();
if (column == CoinControlDialog::COLUMN_AMOUNT_INT64 || column == CoinControlDialog::COLUMN_AMOUNT_INT64)
return data(CoinControlDialog::COLUMN_AMOUNT_INT64, Qt::DisplayRole).toULongLong() < other.data(CoinControlDialog::COLUMN_AMOUNT_INT64, Qt::DisplayRole).toULongLong();
if (column == CoinControlDialog::COLUMN_DATE || column == CoinControlDialog::COLUMN_DATE_INT64)
return data(CoinControlDialog::COLUMN_DATE_INT64, Qt::DisplayRole).toULongLong() < other.data(CoinControlDialog::COLUMN_DATE_INT64, Qt::DisplayRole).toULongLong();
return QTreeWidgetItem::operator<(other);
}
CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, QWidget *parent) : CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::CoinControlDialog), ui(new Ui::CoinControlDialog),
@ -658,7 +667,7 @@ void CoinControlDialog::updateView()
model->listCoins(mapCoins); model->listCoins(mapCoins);
BOOST_FOREACH(const PAIRTYPE(QString, std::vector<COutput>)& coins, mapCoins) { BOOST_FOREACH(const PAIRTYPE(QString, std::vector<COutput>)& coins, mapCoins) {
QTreeWidgetItem *itemWalletAddress = new QTreeWidgetItem(); CCoinControlWidgetItem *itemWalletAddress = new CCoinControlWidgetItem();
itemWalletAddress->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked); itemWalletAddress->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
QString sWalletAddress = coins.first; QString sWalletAddress = coins.first;
QString sWalletLabel = model->getAddressTableModel()->labelForAddress(sWalletAddress); QString sWalletLabel = model->getAddressTableModel()->labelForAddress(sWalletAddress);
@ -686,9 +695,9 @@ void CoinControlDialog::updateView()
nSum += out.tx->vout[out.i].nValue; nSum += out.tx->vout[out.i].nValue;
nChildren++; nChildren++;
QTreeWidgetItem *itemOutput; CCoinControlWidgetItem *itemOutput;
if (treeMode) itemOutput = new QTreeWidgetItem(itemWalletAddress); if (treeMode) itemOutput = new CCoinControlWidgetItem(itemWalletAddress);
else itemOutput = new QTreeWidgetItem(ui->treeWidget); else itemOutput = new CCoinControlWidgetItem(ui->treeWidget);
itemOutput->setFlags(flgCheckbox); itemOutput->setFlags(flgCheckbox);
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked); itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked);
@ -721,11 +730,11 @@ void CoinControlDialog::updateView()
// amount // amount
itemOutput->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, out.tx->vout[out.i].nValue)); itemOutput->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, out.tx->vout[out.i].nValue));
itemOutput->setText(COLUMN_AMOUNT_INT64, strPad(QString::number(out.tx->vout[out.i].nValue), 15, " ")); // padding so that sorting works correctly itemOutput->setData(COLUMN_AMOUNT_INT64, Qt::DisplayRole, QVariant((qlonglong)out.tx->vout[out.i].nValue)); // padding so that sorting works correctly
// date // date
itemOutput->setText(COLUMN_DATE, GUIUtil::dateTimeStr(out.tx->GetTxTime())); itemOutput->setText(COLUMN_DATE, GUIUtil::dateTimeStr(out.tx->GetTxTime()));
itemOutput->setText(COLUMN_DATE_INT64, strPad(QString::number(out.tx->GetTxTime()), 20, " ")); itemOutput->setData(COLUMN_DATE_INT64, Qt::DisplayRole, QVariant((qlonglong)out.tx->GetTxTime()));
// confirmations // confirmations
itemOutput->setText(COLUMN_CONFIRMATIONS, strPad(QString::number(out.nDepth), 8, " ")); itemOutput->setText(COLUMN_CONFIRMATIONS, strPad(QString::number(out.nDepth), 8, " "));

View File

@ -28,6 +28,17 @@ namespace Ui {
#define ASYMP_UTF8 "\xE2\x89\x88" #define ASYMP_UTF8 "\xE2\x89\x88"
class CCoinControlWidgetItem : public QTreeWidgetItem
{
public:
CCoinControlWidgetItem(QTreeWidget *parent, int type = Type) : QTreeWidgetItem(parent, type) {}
CCoinControlWidgetItem(int type = Type) : QTreeWidgetItem(type) {}
CCoinControlWidgetItem(QTreeWidgetItem *parent, int type = Type) : QTreeWidgetItem(parent, type) {}
bool operator<(const QTreeWidgetItem &other) const;
};
class CoinControlDialog : public QDialog class CoinControlDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -76,6 +87,7 @@ private:
COLUMN_AMOUNT_INT64, COLUMN_AMOUNT_INT64,
COLUMN_DATE_INT64 COLUMN_DATE_INT64
}; };
friend class CCoinControlWidgetItem;
// some columns have a hidden column containing the value used for sorting // some columns have a hidden column containing the value used for sorting
int getMappedColumn(int column, bool fVisibleColumn = true) int getMappedColumn(int column, bool fVisibleColumn = true)