Skip to content

Commit 4231032

Browse files
laanwjjonasschnelli
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).
1 parent 76af4eb commit 4231032

File tree

2 files changed

+11
-49
lines changed

2 files changed

+11
-49
lines changed

src/qt/coincontroldialog.cpp

Lines changed: 10 additions & 24 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

@@ -137,11 +135,9 @@ CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, QWidge
137135
ui->treeWidget->setColumnWidth(COLUMN_CONFIRMATIONS, 110);
138136
ui->treeWidget->setColumnHidden(COLUMN_TXHASH, true); // store transaction hash in this column, but don't show it
139137
ui->treeWidget->setColumnHidden(COLUMN_VOUT_INDEX, true); // store vout index in this column, but don't show it
140-
ui->treeWidget->setColumnHidden(COLUMN_AMOUNT_INT64, true); // store amount int64 in this column, but don't show it
141-
ui->treeWidget->setColumnHidden(COLUMN_DATE_INT64, true); // store date int64 in this column, but don't show it
142138

143139
// default view is sorted by amount desc
144-
sortView(COLUMN_AMOUNT_INT64, Qt::DescendingOrder);
140+
sortView(COLUMN_AMOUNT, Qt::DescendingOrder);
145141

146142
// restore list mode and sortorder as a convenience feature
147143
QSettings settings;
@@ -173,15 +169,6 @@ void CoinControlDialog::setModel(WalletModel *_model)
173169
}
174170
}
175171

176-
// helper function str_pad
177-
QString CoinControlDialog::strPad(QString s, int nPadLength, QString sPadding)
178-
{
179-
while (s.length() < nPadLength)
180-
s = sPadding + s;
181-
182-
return s;
183-
}
184-
185172
// ok button
186173
void CoinControlDialog::buttonBoxClicked(QAbstractButton* button)
187174
{
@@ -347,20 +334,18 @@ void CoinControlDialog::sortView(int column, Qt::SortOrder order)
347334
sortColumn = column;
348335
sortOrder = order;
349336
ui->treeWidget->sortItems(column, order);
350-
ui->treeWidget->header()->setSortIndicator(getMappedColumn(sortColumn), sortOrder);
337+
ui->treeWidget->header()->setSortIndicator(sortColumn, sortOrder);
351338
}
352339

353340
// treeview: clicked on header
354341
void CoinControlDialog::headerSectionClicked(int logicalIndex)
355342
{
356343
if (logicalIndex == COLUMN_CHECKBOX) // click on most left column -> do nothing
357344
{
358-
ui->treeWidget->header()->setSortIndicator(getMappedColumn(sortColumn), sortOrder);
345+
ui->treeWidget->header()->setSortIndicator(sortColumn, sortOrder);
359346
}
360347
else
361348
{
362-
logicalIndex = getMappedColumn(logicalIndex, false);
363-
364349
if (sortColumn == logicalIndex)
365350
sortOrder = ((sortOrder == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder);
366351
else
@@ -730,14 +715,15 @@ void CoinControlDialog::updateView()
730715

731716
// amount
732717
itemOutput->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, out.tx->vout[out.i].nValue));
733-
itemOutput->setData(COLUMN_AMOUNT_INT64, Qt::DisplayRole, QVariant((qlonglong)out.tx->vout[out.i].nValue)); // padding so that sorting works correctly
718+
itemOutput->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)out.tx->vout[out.i].nValue)); // padding so that sorting works correctly
734719

735720
// date
736721
itemOutput->setText(COLUMN_DATE, GUIUtil::dateTimeStr(out.tx->GetTxTime()));
737-
itemOutput->setData(COLUMN_DATE_INT64, Qt::DisplayRole, QVariant((qlonglong)out.tx->GetTxTime()));
722+
itemOutput->setData(COLUMN_DATE, Qt::UserRole, QVariant((qlonglong)out.tx->GetTxTime()));
738723

739724
// confirmations
740-
itemOutput->setText(COLUMN_CONFIRMATIONS, strPad(QString::number(out.nDepth), 8, " "));
725+
itemOutput->setText(COLUMN_CONFIRMATIONS, QString::number(out.nDepth));
726+
itemOutput->setData(COLUMN_CONFIRMATIONS, Qt::UserRole, QVariant((qlonglong)out.nDepth));
741727

742728
// transaction hash
743729
uint256 txhash = out.tx->GetHash();
@@ -765,7 +751,7 @@ void CoinControlDialog::updateView()
765751
{
766752
itemWalletAddress->setText(COLUMN_CHECKBOX, "(" + QString::number(nChildren) + ")");
767753
itemWalletAddress->setText(COLUMN_AMOUNT, BitcoinUnits::format(nDisplayUnit, nSum));
768-
itemWalletAddress->setText(COLUMN_AMOUNT_INT64, strPad(QString::number(nSum), 15, " "));
754+
itemWalletAddress->setData(COLUMN_AMOUNT, Qt::UserRole, QVariant((qlonglong)nSum));
769755
}
770756
}
771757

src/qt/coincontroldialog.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,46 +70,22 @@ class CoinControlDialog : public QDialog
7070

7171
const PlatformStyle *platformStyle;
7272

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

7776
enum
7877
{
79-
COLUMN_CHECKBOX,
78+
COLUMN_CHECKBOX = 0,
8079
COLUMN_AMOUNT,
8180
COLUMN_LABEL,
8281
COLUMN_ADDRESS,
8382
COLUMN_DATE,
8483
COLUMN_CONFIRMATIONS,
8584
COLUMN_TXHASH,
8685
COLUMN_VOUT_INDEX,
87-
COLUMN_AMOUNT_INT64,
88-
COLUMN_DATE_INT64
8986
};
9087
friend class CCoinControlWidgetItem;
9188

92-
// some columns have a hidden column containing the value used for sorting
93-
int getMappedColumn(int column, bool fVisibleColumn = true)
94-
{
95-
if (fVisibleColumn)
96-
{
97-
if (column == COLUMN_AMOUNT_INT64)
98-
return COLUMN_AMOUNT;
99-
else if (column == COLUMN_DATE_INT64)
100-
return COLUMN_DATE;
101-
}
102-
else
103-
{
104-
if (column == COLUMN_AMOUNT)
105-
return COLUMN_AMOUNT_INT64;
106-
else if (column == COLUMN_DATE)
107-
return COLUMN_DATE_INT64;
108-
}
109-
110-
return column;
111-
}
112-
11389
private Q_SLOTS:
11490
void showMenu(const QPoint &);
11591
void copyAmount();

0 commit comments

Comments
 (0)