Skip to content

Commit 7be6b79

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 90284c7 commit 7be6b79

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

src/qt/addressbookpage.cpp

Lines changed: 16 additions & 3 deletions
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

@@ -99,11 +106,13 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
99106
ui->labelExplanation->setText(tr("These are your Bitcoin addresses for sending payments. Always check the amount and the receiving address before sending coins."));
100107
ui->deleteAddress->setVisible(true);
101108
ui->newAddress->setVisible(true);
109+
ui->searchLineEdit->setPlaceholderText("Enter address or label to search");
102110
break;
103111
case ReceivingTab:
104112
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'."));
105113
ui->deleteAddress->setVisible(false);
106114
ui->newAddress->setVisible(false);
115+
ui->searchLineEdit->setPlaceholderText("Enter address, address type or label to search");
107116
break;
108117
}
109118

@@ -144,8 +153,11 @@ void AddressBookPage::setModel(AddressTableModel *_model)
144153
ui->tableView->sortByColumn(0, Qt::AscendingOrder);
145154

146155
// Set column widths
147-
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Label, QHeaderView::Stretch);
156+
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Label, QHeaderView::ResizeToContents);
148157
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents);
158+
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Type, QHeaderView::ResizeToContents);
159+
// Show the "Address type" column only on the Receiving tab
160+
ui->tableView->setColumnHidden(AddressTableModel::ColumnIndex::Type, (tab == SendingTab));
149161

150162
connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
151163
this, &AddressBookPage::selectionChanged);
@@ -289,6 +301,7 @@ void AddressBookPage::on_exportButton_clicked()
289301
// name, column, role
290302
writer.setModel(proxyModel);
291303
writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole);
304+
writer.addColumn("Address Type", AddressTableModel::Type, Qt::EditRole);
292305
writer.addColumn("Address", AddressTableModel::Address, Qt::EditRole);
293306

294307
if(!writer.write()) {

src/qt/addresstablemodel.cpp

Lines changed: 16 additions & 9 deletions
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

Lines changed: 3 additions & 3 deletions
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 {
@@ -104,8 +105,7 @@ class AddressTableModel : public QAbstractTableModel
104105
public Q_SLOTS:
105106
/* Update address list from core.
106107
*/
107-
void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status);
108-
108+
void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status, const OutputType &address_type);
109109
friend class AddressTablePriv;
110110
};
111111

src/qt/walletmodel.cpp

Lines changed: 4 additions & 2 deletions
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)