Skip to content

Commit c72c424

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 c65eb23 commit c72c424

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
@@ -46,14 +46,21 @@ class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel
4646
}
4747

4848
auto address = model->index(row, AddressTableModel::Address, parent);
49+
auto addressType = model->index(row, AddressTableModel::Type, parent);
4950

5051
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
5152
const auto pattern = filterRegularExpression();
5253
#else
5354
const auto pattern = filterRegExp();
5455
#endif
55-
return (model->data(address).toString().contains(pattern) ||
56-
model->data(label).toString().contains(pattern));
56+
auto filterBy = model->data(address).toString().contains(pattern) ||
57+
model->data(label).toString().contains(pattern);
58+
59+
if (m_type == AddressTableModel::Receive) {
60+
filterBy = filterBy || model->data(addressType).toString().contains(pattern);
61+
}
62+
63+
return filterBy;
5764
}
5865
};
5966

@@ -95,11 +102,13 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode,
95102
ui->labelExplanation->setText(tr("These are your Bitcoin addresses for sending payments. Always check the amount and the receiving address before sending coins."));
96103
ui->deleteAddress->setVisible(true);
97104
ui->newAddress->setVisible(true);
105+
ui->searchLineEdit->setPlaceholderText("Enter address or label to search");
98106
break;
99107
case ReceivingTab:
100108
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'."));
101109
ui->deleteAddress->setVisible(false);
102110
ui->newAddress->setVisible(false);
111+
ui->searchLineEdit->setPlaceholderText("Enter address, address type or label to search");
103112
break;
104113
}
105114

@@ -140,8 +149,11 @@ void AddressBookPage::setModel(AddressTableModel *_model)
140149
ui->tableView->sortByColumn(0, Qt::AscendingOrder);
141150

142151
// Set column widths
143-
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Label, QHeaderView::Stretch);
152+
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Label, QHeaderView::ResizeToContents);
144153
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents);
154+
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Type, QHeaderView::ResizeToContents);
155+
// Show the "Address type" column only on the Receiving tab
156+
ui->tableView->setColumnHidden(AddressTableModel::ColumnIndex::Type, (tab == SendingTab));
145157

146158
connect(ui->tableView->selectionModel(), &QItemSelectionModel::selectionChanged,
147159
this, &AddressBookPage::selectionChanged);
@@ -285,6 +297,7 @@ void AddressBookPage::on_exportButton_clicked()
285297
// name, column, role
286298
writer.setModel(proxyModel);
287299
writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole);
300+
writer.addColumn("Address Type", AddressTableModel::Type, Qt::EditRole);
288301
writer.addColumn("Address", AddressTableModel::Address, Qt::EditRole);
289302

290303
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
@@ -137,8 +137,10 @@ void WalletModel::updateTransaction()
137137
void WalletModel::updateAddressBook(const QString &address, const QString &label,
138138
bool isMine, wallet::AddressPurpose purpose, int status)
139139
{
140-
if(addressTableModel)
141-
addressTableModel->updateEntry(address, label, isMine, purpose, status);
140+
if (addressTableModel) {
141+
CTxDestination destination = DecodeDestination(address.toStdString());
142+
addressTableModel->updateEntry(address, label, isMine, purpose, status, m_wallet->getOutputType(destination));
143+
}
142144
}
143145

144146
void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)

0 commit comments

Comments
 (0)