Skip to content

Commit 1fcff19

Browse files
gui: Add Address Type Column to AddressBookPage
Add new address type column to the addresstablemodel, use the getOutputType function from the wallet interface to display the correct address type in the new column content. Update the address book page to set the new column resize mode and to display the new column only when the receiving tab is enabled so it must be hidden on the sending tab. Update AddressBookFilterProxyModel::filterAcceptsRow so the filter works also on the new addressType column content. Also the searLineEdit greyed text reflects that the new field/ column addressType will be included in the search/ filter by but only when the receiving tab is enabled. Add the new column to the export feature.
1 parent e0e22a1 commit 1fcff19

4 files changed

+38
-16
lines changed

src/qt/addressbookpage.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,21 @@ class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel
5050
}
5151

5252
auto address = model->index(row, AddressTableModel::Address, parent);
53+
auto addressType = model->index(row, AddressTableModel::Type, parent);
5354

5455
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
5556
const auto pattern = filterRegularExpression();
5657
#else
5758
const auto pattern = filterRegExp();
5859
#endif
59-
return (model->data(address).toString().contains(pattern) ||
60-
model->data(label).toString().contains(pattern));
60+
auto filterBy = model->data(address).toString().contains(pattern) ||
61+
model->data(label).toString().contains(pattern);
62+
63+
if (m_type == AddressTableModel::Receive) {
64+
filterBy = filterBy || model->data(addressType).toString().contains(pattern);
65+
}
66+
67+
return filterBy;
6168
}
6269
};
6370

@@ -109,11 +116,13 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
109116
ui->labelExplanation->setText(tr("These are your Bitcoin addresses for sending payments. Always check the amount and the receiving address before sending coins."));
110117
ui->deleteAddress->setVisible(true);
111118
ui->newAddress->setVisible(true);
119+
ui->searchLineEdit->setPlaceholderText("Enter address or label to search");
112120
break;
113121
case ReceivingTab:
114122
ui->labelExplanation->setText(tr("These are your Bitcoin addresses for receiving payments. Use the 'Create new receiving address' button in the receive tab to create new addresses.\nSigning is only possible with addresses of the type 'legacy'."));
115123
ui->deleteAddress->setVisible(false);
116124
ui->newAddress->setVisible(false);
125+
ui->searchLineEdit->setPlaceholderText("Enter address, address type or label to search");
117126
break;
118127
}
119128

@@ -156,6 +165,9 @@ void AddressBookPage::setModel(AddressTableModel *_model)
156165
// Set column widths
157166
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Label, QHeaderView::Stretch);
158167
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents);
168+
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Type, QHeaderView::ResizeToContents);
169+
// Show the "Address type" column only on the Receiving tab
170+
ui->tableView->setColumnHidden(AddressTableModel::ColumnIndex::Type, (tab == SendingTab));
159171

160172
connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
161173
this, &AddressBookPage::selectionChanged);
@@ -298,6 +310,7 @@ void AddressBookPage::on_exportButton_clicked()
298310
// name, column, role
299311
writer.setModel(proxyModel);
300312
writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole);
313+
writer.addColumn("Address Type", AddressTableModel::Type, Qt::EditRole);
301314
writer.addColumn("Address", AddressTableModel::Address, Qt::EditRole);
302315

303316
if(!writer.write()) {

src/qt/addresstablemodel.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ struct AddressTableEntry
3030
Type type;
3131
QString label;
3232
QString address;
33+
QString addressType;
3334

3435
AddressTableEntry() = default;
35-
AddressTableEntry(Type _type, const QString &_label, const QString &_address):
36-
type(_type), label(_label), address(_address) {}
36+
AddressTableEntry(Type _type, const QString &_label, const QString &_address, const OutputType &_addresstype):
37+
type(_type), label(_label), address(_address) {
38+
addressType = GUIUtil::outputTypeDescriptionsMap().at(_addresstype).description;
39+
}
3740
};
3841

3942
struct AddressTableEntryLessThan
@@ -87,7 +90,8 @@ class AddressTablePriv
8790
address.purpose, address.is_mine);
8891
cachedAddressTable.append(AddressTableEntry(addressType,
8992
QString::fromStdString(address.name),
90-
QString::fromStdString(EncodeDestination(address.dest))));
93+
QString::fromStdString(EncodeDestination(address.dest)),
94+
wallet.getOutputType(address.dest)));
9195
}
9296
}
9397
// std::lower_bound() and std::upper_bound() require our cachedAddressTable list to be sorted in asc order
@@ -96,7 +100,7 @@ class AddressTablePriv
96100
std::sort(cachedAddressTable.begin(), cachedAddressTable.end(), AddressTableEntryLessThan());
97101
}
98102

99-
void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status)
103+
void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status, const OutputType &addresstype)
100104
{
101105
// Find address / label in model
102106
QList<AddressTableEntry>::iterator lower = std::lower_bound(
@@ -117,7 +121,7 @@ class AddressTablePriv
117121
break;
118122
}
119123
parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
120-
cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address));
124+
cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address, addresstype));
121125
parent->endInsertRows();
122126
break;
123127
case CT_UPDATED:
@@ -164,7 +168,7 @@ class AddressTablePriv
164168
AddressTableModel::AddressTableModel(WalletModel *parent, bool pk_hash_only) :
165169
QAbstractTableModel(parent), walletModel(parent)
166170
{
167-
columns << tr("Label") << tr("Address");
171+
columns << tr("Label") << tr("Address Type") << tr("Address");
168172
priv = new AddressTablePriv(this);
169173
priv->refreshAddressTable(parent->wallet(), pk_hash_only);
170174
}
@@ -208,6 +212,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
208212
}
209213
case Address:
210214
return rec->address;
215+
case Type:
216+
return rec->addressType;
211217
} // no default case, so the compiler can warn about missing cases
212218
assert(false);
213219
} else if (role == Qt::FontRole) {
@@ -216,6 +222,8 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
216222
return QFont();
217223
case Address:
218224
return GUIUtil::fixedPitchFont();
225+
case Type:
226+
return QFont();
219227
} // no default case, so the compiler can warn about missing cases
220228
assert(false);
221229
} else if (role == TypeRole) {
@@ -332,11 +340,10 @@ QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &par
332340
}
333341
}
334342

335-
void AddressTableModel::updateEntry(const QString &address,
336-
const QString &label, bool isMine, wallet::AddressPurpose purpose, int status)
343+
void AddressTableModel::updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status, const OutputType &addressType)
337344
{
338345
// Update address book model from Bitcoin core
339-
priv->updateEntry(address, label, isMine, purpose, status);
346+
priv->updateEntry(address, label, isMine, purpose, status, addressType);
340347
}
341348

342349
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)

src/qt/addresstablemodel.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class AddressTableModel : public QAbstractTableModel
3535

3636
enum ColumnIndex {
3737
Label = 0, /**< User specified label */
38-
Address = 1 /**< Bitcoin address */
38+
Type = 1, /**< Address type */
39+
Address = 2 /**< Bitcoin address */
3940
};
4041

4142
enum RoleIndex {
@@ -102,8 +103,7 @@ class AddressTableModel : public QAbstractTableModel
102103
public Q_SLOTS:
103104
/* Update address list from core.
104105
*/
105-
void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status);
106-
106+
void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status, const OutputType &address_type);
107107
friend class AddressTablePriv;
108108
};
109109

src/qt/walletmodel.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ void WalletModel::updateTransaction()
140140
void WalletModel::updateAddressBook(const QString &address, const QString &label,
141141
bool isMine, wallet::AddressPurpose purpose, int status)
142142
{
143-
if(addressTableModel)
144-
addressTableModel->updateEntry(address, label, isMine, purpose, status);
143+
if (addressTableModel) {
144+
CTxDestination destination = DecodeDestination(address.toStdString());
145+
addressTableModel->updateEntry(address, label, isMine, purpose, status, m_wallet->getOutputType(destination));
146+
}
145147
}
146148

147149
void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)

0 commit comments

Comments
 (0)