mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-02 21:37:05 +01:00
[Qt] Clean up and fix coincontrol tree widget handling
- Do sorting for date, amount and confirmations column as longlong, not
unsigned longlong.
- Use `UserRole` to store our own data. This makes it treated as
ancillary data prevents it from being displayed.
- Get rid of `getMappedColumn` `strPad` - these are no longer necessary.
- Get rid of hidden `_INT64` columns.
- Start enumeration from 0 (otherwise values are undefined).
Github-Pull: #9185
Rebased-From: 4231032bfc
This commit is contained in:
committed by
Luke Dashjr
parent
6d70a73968
commit
ff423cc6b0
@@ -37,10 +37,8 @@ bool CoinControlDialog::fSubtractFeeFromAmount = false;
|
|||||||
|
|
||||||
bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
|
bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
|
||||||
int column = treeWidget()->sortColumn();
|
int column = treeWidget()->sortColumn();
|
||||||
if (column == CoinControlDialog::COLUMN_AMOUNT_INT64 || column == CoinControlDialog::COLUMN_AMOUNT_INT64)
|
if (column == CoinControlDialog::COLUMN_AMOUNT || column == CoinControlDialog::COLUMN_DATE || column == CoinControlDialog::COLUMN_CONFIRMATIONS)
|
||||||
return data(CoinControlDialog::COLUMN_AMOUNT_INT64, Qt::DisplayRole).toULongLong() < other.data(CoinControlDialog::COLUMN_AMOUNT_INT64, Qt::DisplayRole).toULongLong();
|
return data(column, Qt::UserRole).toLongLong() < other.data(column, Qt::UserRole).toLongLong();
|
||||||
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);
|
return QTreeWidgetItem::operator<(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,12 +139,9 @@ CoinControlDialog::CoinControlDialog(const PlatformStyle *platformStyle, QWidget
|
|||||||
ui->treeWidget->setColumnWidth(COLUMN_PRIORITY, 100);
|
ui->treeWidget->setColumnWidth(COLUMN_PRIORITY, 100);
|
||||||
ui->treeWidget->setColumnHidden(COLUMN_TXHASH, true); // store transaction hash in this column, but don't show it
|
ui->treeWidget->setColumnHidden(COLUMN_TXHASH, true); // store transaction hash in this column, but don't show it
|
||||||
ui->treeWidget->setColumnHidden(COLUMN_VOUT_INDEX, true); // store vout index in this column, but don't show it
|
ui->treeWidget->setColumnHidden(COLUMN_VOUT_INDEX, true); // store vout index in this column, but don't show it
|
||||||
ui->treeWidget->setColumnHidden(COLUMN_AMOUNT_INT64, true); // store amount int64 in this column, but don't show it
|
|
||||||
ui->treeWidget->setColumnHidden(COLUMN_PRIORITY_INT64, true); // store priority int64 in this column, but don't show it
|
|
||||||
ui->treeWidget->setColumnHidden(COLUMN_DATE_INT64, true); // store date int64 in this column, but don't show it
|
|
||||||
|
|
||||||
// default view is sorted by amount desc
|
// default view is sorted by amount desc
|
||||||
sortView(COLUMN_AMOUNT_INT64, Qt::DescendingOrder);
|
sortView(COLUMN_AMOUNT, Qt::DescendingOrder);
|
||||||
|
|
||||||
// restore list mode and sortorder as a convenience feature
|
// restore list mode and sortorder as a convenience feature
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
@@ -178,15 +173,6 @@ void CoinControlDialog::setModel(WalletModel *model)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function str_pad
|
|
||||||
QString CoinControlDialog::strPad(QString s, int nPadLength, QString sPadding)
|
|
||||||
{
|
|
||||||
while (s.length() < nPadLength)
|
|
||||||
s = sPadding + s;
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ok button
|
// ok button
|
||||||
void CoinControlDialog::buttonBoxClicked(QAbstractButton* button)
|
void CoinControlDialog::buttonBoxClicked(QAbstractButton* button)
|
||||||
{
|
{
|
||||||
@@ -358,7 +344,7 @@ void CoinControlDialog::sortView(int column, Qt::SortOrder order)
|
|||||||
sortColumn = column;
|
sortColumn = column;
|
||||||
sortOrder = order;
|
sortOrder = order;
|
||||||
ui->treeWidget->sortItems(column, order);
|
ui->treeWidget->sortItems(column, order);
|
||||||
ui->treeWidget->header()->setSortIndicator(getMappedColumn(sortColumn), sortOrder);
|
ui->treeWidget->header()->setSortIndicator(sortColumn, sortOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// treeview: clicked on header
|
// treeview: clicked on header
|
||||||
@@ -366,12 +352,10 @@ void CoinControlDialog::headerSectionClicked(int logicalIndex)
|
|||||||
{
|
{
|
||||||
if (logicalIndex == COLUMN_CHECKBOX) // click on most left column -> do nothing
|
if (logicalIndex == COLUMN_CHECKBOX) // click on most left column -> do nothing
|
||||||
{
|
{
|
||||||
ui->treeWidget->header()->setSortIndicator(getMappedColumn(sortColumn), sortOrder);
|
ui->treeWidget->header()->setSortIndicator(sortColumn, sortOrder);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logicalIndex = getMappedColumn(logicalIndex, false);
|
|
||||||
|
|
||||||
if (sortColumn == logicalIndex)
|
if (sortColumn == logicalIndex)
|
||||||
sortOrder = ((sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
|
sortOrder = ((sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
|
||||||
else
|
else
|
||||||
@@ -788,19 +772,20 @@ 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->setData(COLUMN_AMOUNT_INT64, Qt::DisplayRole, QVariant((qlonglong)out.tx->vout[out.i].nValue)); // padding so that sorting works correctly
|
itemOutput->setData(COLUMN_AMOUNT, Qt::UserRole, 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->setData(COLUMN_DATE_INT64, Qt::DisplayRole, QVariant((qlonglong)out.tx->GetTxTime()));
|
itemOutput->setData(COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)out.tx->GetTxTime()));
|
||||||
|
|
||||||
// confirmations
|
// confirmations
|
||||||
itemOutput->setText(COLUMN_CONFIRMATIONS, strPad(QString::number(out.nDepth), 8, " "));
|
itemOutput->setText(COLUMN_CONFIRMATIONS, QString::number(out.nDepth));
|
||||||
|
itemOutput->setData(COLUMN_CONFIRMATIONS, Qt::UserRole, QVariant((qlonglong)out.nDepth));
|
||||||
|
|
||||||
// priority
|
// priority
|
||||||
double dPriority = ((double)out.tx->vout[out.i].nValue / (nInputSize + 78)) * (out.nDepth+1); // 78 = 2 * 34 + 10
|
double dPriority = ((double)out.tx->vout[out.i].nValue / (nInputSize + 78)) * (out.nDepth+1); // 78 = 2 * 34 + 10
|
||||||
itemOutput->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPriority, mempoolEstimatePriority));
|
itemOutput->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPriority, mempoolEstimatePriority));
|
||||||
itemOutput->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64_t)dPriority), 20, " "));
|
itemOutput->setData(COLUMN_PRIORITY, Qt::UserRole, QVariant((qlonglong)dPriority));
|
||||||
dPrioritySum += (double)out.tx->vout[out.i].nValue * (out.nDepth+1);
|
dPrioritySum += (double)out.tx->vout[out.i].nValue * (out.nDepth+1);
|
||||||
nInputSum += nInputSize;
|
nInputSum += nInputSize;
|
||||||
|
|
||||||
@@ -831,9 +816,9 @@ void CoinControlDialog::updateView()
|
|||||||
dPrioritySum = dPrioritySum / (nInputSum + 78);
|
dPrioritySum = dPrioritySum / (nInputSum + 78);
|
||||||
itemWalletAddress->setText(COLUMN_CHECKBOX, "(" + QString::number(nChildren) + ")");
|
itemWalletAddress->setText(COLUMN_CHECKBOX, "(" + QString::number(nChildren) + ")");
|
||||||
itemWalletAddress->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, nSum));
|
itemWalletAddress->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, nSum));
|
||||||
itemWalletAddress->setText(COLUMN_AMOUNT_INT64, strPad(QString::number(nSum), 15, " "));
|
itemWalletAddress->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
|
||||||
itemWalletAddress->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPrioritySum, mempoolEstimatePriority));
|
itemWalletAddress->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPrioritySum, mempoolEstimatePriority));
|
||||||
itemWalletAddress->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64_t)dPrioritySum), 20, " "));
|
itemWalletAddress->setData(COLUMN_PRIORITY, Qt::UserRole, QVariant((qlonglong)dPrioritySum));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,13 +71,12 @@ private:
|
|||||||
|
|
||||||
const PlatformStyle *platformStyle;
|
const PlatformStyle *platformStyle;
|
||||||
|
|
||||||
QString strPad(QString, int, QString);
|
|
||||||
void sortView(int, Qt::SortOrder);
|
void sortView(int, Qt::SortOrder);
|
||||||
void updateView();
|
void updateView();
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
COLUMN_CHECKBOX,
|
COLUMN_CHECKBOX = 0,
|
||||||
COLUMN_AMOUNT,
|
COLUMN_AMOUNT,
|
||||||
COLUMN_LABEL,
|
COLUMN_LABEL,
|
||||||
COLUMN_ADDRESS,
|
COLUMN_ADDRESS,
|
||||||
@@ -86,37 +85,9 @@ private:
|
|||||||
COLUMN_PRIORITY,
|
COLUMN_PRIORITY,
|
||||||
COLUMN_TXHASH,
|
COLUMN_TXHASH,
|
||||||
COLUMN_VOUT_INDEX,
|
COLUMN_VOUT_INDEX,
|
||||||
COLUMN_AMOUNT_INT64,
|
|
||||||
COLUMN_PRIORITY_INT64,
|
|
||||||
COLUMN_DATE_INT64
|
|
||||||
};
|
};
|
||||||
friend class CCoinControlWidgetItem;
|
friend class CCoinControlWidgetItem;
|
||||||
|
|
||||||
// some columns have a hidden column containing the value used for sorting
|
|
||||||
int getMappedColumn(int column, bool fVisibleColumn = true)
|
|
||||||
{
|
|
||||||
if (fVisibleColumn)
|
|
||||||
{
|
|
||||||
if (column == COLUMN_AMOUNT_INT64)
|
|
||||||
return COLUMN_AMOUNT;
|
|
||||||
else if (column == COLUMN_PRIORITY_INT64)
|
|
||||||
return COLUMN_PRIORITY;
|
|
||||||
else if (column == COLUMN_DATE_INT64)
|
|
||||||
return COLUMN_DATE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (column == COLUMN_AMOUNT)
|
|
||||||
return COLUMN_AMOUNT_INT64;
|
|
||||||
else if (column == COLUMN_PRIORITY)
|
|
||||||
return COLUMN_PRIORITY_INT64;
|
|
||||||
else if (column == COLUMN_DATE)
|
|
||||||
return COLUMN_DATE_INT64;
|
|
||||||
}
|
|
||||||
|
|
||||||
return column;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void showMenu(const QPoint &);
|
void showMenu(const QPoint &);
|
||||||
void copyAmount();
|
void copyAmount();
|
||||||
|
|||||||
Reference in New Issue
Block a user