Skip to content

Commit ff423cc

Browse files
laanwjluke-jr
authored andcommitted
[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: bitcoin#9185 Rebased-From: 4231032
1 parent 6d70a73 commit ff423cc

File tree

2 files changed

+13
-57
lines changed

2 files changed

+13
-57
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ bool CoinControlDialog::fSubtractFeeFromAmount = false;
3737

3838
bool CCoinControlWidgetItem::operator<(const QTreeWidgetItem &other) const {
3939
int column = treeWidget()->sortColumn();
40-
if (column == CoinControlDialog::COLUMN_AMOUNT_INT64 || column == CoinControlDialog::COLUMN_AMOUNT_INT64)
41-
return data(CoinControlDialog::COLUMN_AMOUNT_INT64, Qt::DisplayRole).toULongLong() < other.data(CoinControlDialog::COLUMN_AMOUNT_INT64, Qt::DisplayRole).toULongLong();
42-
if (column == CoinControlDialog::COLUMN_DATE || column == CoinControlDialog::COLUMN_DATE_INT64)
43-
return data(CoinControlDialog::COLUMN_DATE_INT64, Qt::DisplayRole).toULongLong() < other.data(CoinControlDialog::COLUMN_DATE_INT64, Qt::DisplayRole).toULongLong();
40+
if (column == CoinControlDialog::COLUMN_AMOUNT || column == CoinControlDialog::COLUMN_DATE || column == CoinControlDialog::COLUMN_CONFIRMATIONS)
41+
return data(column, Qt::UserRole).toLongLong() < other.data(column, Qt::UserRole).toLongLong();
4442
return QTreeWidgetItem::operator<(other);
4543
}
4644

@@ -141,12 +139,9 @@ CoinControlDialog::CoinControlDialog(const PlatformStyle *platformStyle, QWidget
141139
ui->treeWidget->setColumnWidth(COLUMN_PRIORITY, 100);
142140
ui->treeWidget->setColumnHidden(COLUMN_TXHASH, true); // store transaction hash in this column, but don't show it
143141
ui->treeWidget->setColumnHidden(COLUMN_VOUT_INDEX, true); // store vout index in this column, but don't show it
144-
ui->treeWidget->setColumnHidden(COLUMN_AMOUNT_INT64, true); // store amount int64 in this column, but don't show it
145-
ui->treeWidget->setColumnHidden(COLUMN_PRIORITY_INT64, true); // store priority int64 in this column, but don't show it
146-
ui->treeWidget->setColumnHidden(COLUMN_DATE_INT64, true); // store date int64 in this column, but don't show it
147142

148143
// default view is sorted by amount desc
149-
sortView(COLUMN_AMOUNT_INT64, Qt::DescendingOrder);
144+
sortView(COLUMN_AMOUNT, Qt::DescendingOrder);
150145

151146
// restore list mode and sortorder as a convenience feature
152147
QSettings settings;
@@ -178,15 +173,6 @@ void CoinControlDialog::setModel(WalletModel *model)
178173
}
179174
}
180175

181-
// helper function str_pad
182-
QString CoinControlDialog::strPad(QString s, int nPadLength, QString sPadding)
183-
{
184-
while (s.length() < nPadLength)
185-
s = sPadding + s;
186-
187-
return s;
188-
}
189-
190176
// ok button
191177
void CoinControlDialog::buttonBoxClicked(QAbstractButton* button)
192178
{
@@ -358,20 +344,18 @@ void CoinControlDialog::sortView(int column, Qt::SortOrder order)
358344
sortColumn = column;
359345
sortOrder = order;
360346
ui->treeWidget->sortItems(column, order);
361-
ui->treeWidget->header()->setSortIndicator(getMappedColumn(sortColumn), sortOrder);
347+
ui->treeWidget->header()->setSortIndicator(sortColumn, sortOrder);
362348
}
363349

364350
// treeview: clicked on header
365351
void CoinControlDialog::headerSectionClicked(int logicalIndex)
366352
{
367353
if (logicalIndex == COLUMN_CHECKBOX) // click on most left column -> do nothing
368354
{
369-
ui->treeWidget->header()->setSortIndicator(getMappedColumn(sortColumn), sortOrder);
355+
ui->treeWidget->header()->setSortIndicator(sortColumn, sortOrder);
370356
}
371357
else
372358
{
373-
logicalIndex = getMappedColumn(logicalIndex, false);
374-
375359
if (sortColumn == logicalIndex)
376360
sortOrder = ((sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
377361
else
@@ -788,19 +772,20 @@ void CoinControlDialog::updateView()
788772

789773
// amount
790774
itemOutput->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, out.tx->vout[out.i].nValue));
791-
itemOutput->setData(COLUMN_AMOUNT_INT64, Qt::DisplayRole, QVariant((qlonglong)out.tx->vout[out.i].nValue)); // padding so that sorting works correctly
775+
itemOutput->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.tx->vout[out.i].nValue)); // padding so that sorting works correctly
792776

793777
// date
794778
itemOutput->setText(COLUMN_DATE, GUIUtil::dateTimeStr(out.tx->GetTxTime()));
795-
itemOutput->setData(COLUMN_DATE_INT64, Qt::DisplayRole, QVariant((qlonglong)out.tx->GetTxTime()));
779+
itemOutput->setData(COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)out.tx->GetTxTime()));
796780

797781
// confirmations
798-
itemOutput->setText(COLUMN_CONFIRMATIONS, strPad(QString::number(out.nDepth), 8, " "));
782+
itemOutput->setText(COLUMN_CONFIRMATIONS, QString::number(out.nDepth));
783+
itemOutput->setData(COLUMN_CONFIRMATIONS, Qt::UserRole, QVariant((qlonglong)out.nDepth));
799784

800785
// priority
801786
double dPriority = ((double)out.tx->vout[out.i].nValue / (nInputSize + 78)) * (out.nDepth+1); // 78 = 2 * 34 + 10
802787
itemOutput->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPriority, mempoolEstimatePriority));
803-
itemOutput->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64_t)dPriority), 20, " "));
788+
itemOutput->setData(COLUMN_PRIORITY, Qt::UserRole, QVariant((qlonglong)dPriority));
804789
dPrioritySum += (double)out.tx->vout[out.i].nValue * (out.nDepth+1);
805790
nInputSum += nInputSize;
806791

@@ -831,9 +816,9 @@ void CoinControlDialog::updateView()
831816
dPrioritySum = dPrioritySum / (nInputSum + 78);
832817
itemWalletAddress->setText(COLUMN_CHECKBOX, "(" + QString::number(nChildren) + ")");
833818
itemWalletAddress->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, nSum));
834-
itemWalletAddress->setText(COLUMN_AMOUNT_INT64, strPad(QString::number(nSum), 15, " "));
819+
itemWalletAddress->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
835820
itemWalletAddress->setText(COLUMN_PRIORITY, CoinControlDialog::getPriorityLabel(dPrioritySum, mempoolEstimatePriority));
836-
itemWalletAddress->setText(COLUMN_PRIORITY_INT64, strPad(QString::number((int64_t)dPrioritySum), 20, " "));
821+
itemWalletAddress->setData(COLUMN_PRIORITY, Qt::UserRole, QVariant((qlonglong)dPrioritySum));
837822
}
838823
}
839824

src/qt/coincontroldialog.h

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ class CoinControlDialog : public QDialog
7171

7272
const PlatformStyle *platformStyle;
7373

74-
QString strPad(QString, int, QString);
7574
void sortView(int, Qt::SortOrder);
7675
void updateView();
7776

7877
enum
7978
{
80-
COLUMN_CHECKBOX,
79+
COLUMN_CHECKBOX = 0,
8180
COLUMN_AMOUNT,
8281
COLUMN_LABEL,
8382
COLUMN_ADDRESS,
@@ -86,37 +85,9 @@ class CoinControlDialog : public QDialog
8685
COLUMN_PRIORITY,
8786
COLUMN_TXHASH,
8887
COLUMN_VOUT_INDEX,
89-
COLUMN_AMOUNT_INT64,
90-
COLUMN_PRIORITY_INT64,
91-
COLUMN_DATE_INT64
9288
};
9389
friend class CCoinControlWidgetItem;
9490

95-
// some columns have a hidden column containing the value used for sorting
96-
int getMappedColumn(int column, bool fVisibleColumn = true)
97-
{
98-
if (fVisibleColumn)
99-
{
100-
if (column == COLUMN_AMOUNT_INT64)
101-
return COLUMN_AMOUNT;
102-
else if (column == COLUMN_PRIORITY_INT64)
103-
return COLUMN_PRIORITY;
104-
else if (column == COLUMN_DATE_INT64)
105-
return COLUMN_DATE;
106-
}
107-
else
108-
{
109-
if (column == COLUMN_AMOUNT)
110-
return COLUMN_AMOUNT_INT64;
111-
else if (column == COLUMN_PRIORITY)
112-
return COLUMN_PRIORITY_INT64;
113-
else if (column == COLUMN_DATE)
114-
return COLUMN_DATE_INT64;
115-
}
116-
117-
return column;
118-
}
119-
12091
private Q_SLOTS:
12192
void showMenu(const QPoint &);
12293
void copyAmount();

0 commit comments

Comments
 (0)