@@ -163,7 +163,7 @@ void AddressBookPage::setModel(AddressTableModel *_model)
163
163
return ;
164
164
165
165
auto type = tab == ReceivingTab ? AddressTableModel::Receive : AddressTableModel::Send;
166
- proxyModel.reset (new AddressBookSortFilterProxyModel (type, this , false ));
166
+ proxyModel.reset (new AddressBookSortFilterProxyModel (type, this , true ));
167
167
proxyModel->setSourceModel (_model);
168
168
169
169
connect (ui->searchLineEdit , &QLineEdit::textChanged, proxyModel.get (), &QSortFilterProxyModel::setFilterWildcard);
@@ -186,6 +186,8 @@ void AddressBookPage::setModel(AddressTableModel *_model)
186
186
187
187
selectionChanged ();
188
188
this ->updateWindowsTitleWithWalletName ();
189
+
190
+ this ->setupAddressTypeCombo ();
189
191
}
190
192
191
193
void AddressBookPage::on_copyAddress_clicked ()
@@ -214,7 +216,7 @@ void AddressBookPage::onEditAction()
214
216
EditAddressDialog::EditSendingAddress :
215
217
EditAddressDialog::EditReceivingAddress, this );
216
218
dlg->setModel (model);
217
- QModelIndex origIndex = proxyModel->mapToSource (indexes.at (0 ));
219
+ QModelIndex origIndex = proxyModel->nestedProxyModel ()-> mapToSource (indexes.at (0 ));
218
220
dlg->loadRow (origIndex.row ());
219
221
GUIUtil::ShowModalDialogAsynchronously (dlg);
220
222
}
@@ -318,7 +320,7 @@ void AddressBookPage::on_exportButton_clicked()
318
320
CSVModelWriter writer (filename);
319
321
320
322
// name, column, role
321
- writer.setModel (proxyModel. get ());
323
+ writer.setModel (proxyModel-> nestedProxyModel ());
322
324
writer.addColumn (" Label" , AddressTableModel::Label, Qt::EditRole);
323
325
writer.addColumn (" Address Type" , AddressTableModel::Type, Qt::EditRole);
324
326
writer.addColumn (" Address" , AddressTableModel::Address, Qt::EditRole);
@@ -342,7 +344,7 @@ void AddressBookPage::contextualMenu(const QPoint &point)
342
344
343
345
void AddressBookPage::selectNewAddress (const QModelIndex &parent, int begin, int /* end*/ )
344
346
{
345
- QModelIndex idx = proxyModel->mapFromSource (model->index (begin, AddressTableModel::Address, parent));
347
+ QModelIndex idx = proxyModel. get () ->mapFromSource (model->index (begin, AddressTableModel::Address, parent));
346
348
if (idx.isValid () && (idx.data (Qt::EditRole).toString () == newAddressToSelect))
347
349
{
348
350
// Select row of newly created address, once
@@ -364,3 +366,97 @@ void AddressBookPage::updateWindowsTitleWithWalletName()
364
366
}
365
367
}
366
368
}
369
+
370
+ std::map<OutputType, QString> AddressBookPage::addressTypeTooltipMap () {
371
+ return {{OutputType::LEGACY, QObject::tr (" Not recommended due to higher fees and less protection against typos." )},
372
+ {OutputType::P2SH_SEGWIT, QObject::tr (" An address compatible with older wallets." )},
373
+ {OutputType::BECH32, QObject::tr (" Native segwit address (BIP-173). Some old wallets don't support it." )},
374
+ {OutputType::BECH32M, QObject::tr (" Bech32m (BIP-350) is an upgrade to Bech32, wallet support is still limited." )}};
375
+ }
376
+
377
+ QString AddressBookPage::showAllTypes () const {
378
+ return QObject::tr (" All" );
379
+ }
380
+
381
+ QString AddressBookPage::showAllTypesToolTip () const {
382
+ return QObject::tr (" Select an address type to filter by." );
383
+ }
384
+
385
+ void AddressBookPage::handleAddressTypeChanged (int index)
386
+ {
387
+ QString selectedValue = ui->addressType ->currentText ();
388
+ // If show all types is selected then clear the selected value
389
+ // that will be sent to the filter so it shows everything
390
+ if (selectedValue == showAllTypes ()) selectedValue.clear ();
391
+ // Emit a signal with the selected value
392
+ Q_EMIT addressTypeChanged (selectedValue);
393
+ // Forcing the resize as if it was selected an item with
394
+ // shorter content and right after a longer one, the
395
+ // columns are not resizing properly, this fixes it
396
+ ui->tableView ->resizeColumnsToContents ();
397
+ }
398
+
399
+ void AddressBookPage::initializeAddressTypeCombo ()
400
+ {
401
+ const auto index = ui->addressType ->count ();
402
+ ui->addressType ->addItem (showAllTypes (), index);
403
+ ui->addressType ->setItemData (index, showAllTypesToolTip (), Qt::ToolTipRole);
404
+ ui->addressType ->setCurrentIndex (index);
405
+ }
406
+
407
+ void AddressBookPage::setupAddressTypeCombo ()
408
+ {
409
+ this ->initializeAddressTypeCombo ();
410
+ ui->labelAddressType ->setVisible (tab == ReceivingTab);
411
+ ui->addressType ->setVisible (tab == ReceivingTab);
412
+ GUIUtil::AddItemsToAddressTypeCombo (ui->addressType , true , this ->addressTypeTooltipMap ());
413
+ connect (ui->addressType , qOverload<int >(&QComboBox::currentIndexChanged), this , &AddressBookPage::handleAddressTypeChanged);
414
+ connect (this , &AddressBookPage::addressTypeChanged, proxyModel->nestedProxyModel (), &QSortFilterProxyModel::setFilterFixedString);
415
+ }
416
+
417
+ std::map<OutputType, QString> AddressBookPage::addressTypeTooltipMap () {
418
+ return {{OutputType::LEGACY, QObject::tr (" Not recommended due to higher fees and less protection against typos." )},
419
+ {OutputType::P2SH_SEGWIT, QObject::tr (" An address compatible with older wallets." )},
420
+ {OutputType::BECH32, QObject::tr (" Native segwit address (BIP-173). Some old wallets don't support it." )},
421
+ {OutputType::BECH32M, QObject::tr (" Bech32m (BIP-350) is an upgrade to Bech32, wallet support is still limited." )}};
422
+ }
423
+
424
+ QString AddressBookPage::showAllTypes () const {
425
+ return QObject::tr (" All" );
426
+ }
427
+
428
+ QString AddressBookPage::showAllTypesToolTip () const {
429
+ return QObject::tr (" Select an address type to filter by." );
430
+ }
431
+
432
+ void AddressBookPage::handleAddressTypeChanged (int index)
433
+ {
434
+ QString selectedValue = ui->addressType ->currentText ();
435
+ // If show all types is selected then clear the selected value
436
+ // that will be sent to the filter so it shows everything
437
+ if (selectedValue == showAllTypes ()) selectedValue.clear ();
438
+ // Emit a signal with the selected value
439
+ Q_EMIT addressTypeChanged (selectedValue);
440
+ // Forcing the resize as if it was selected an item with
441
+ // shorter content and right after a longer one, the
442
+ // columns are not resizing properly, this fixes it
443
+ ui->tableView ->resizeColumnsToContents ();
444
+ }
445
+
446
+ void AddressBookPage::initializeAddressTypeCombo ()
447
+ {
448
+ const auto index = ui->addressType ->count ();
449
+ ui->addressType ->addItem (showAllTypes (), index);
450
+ ui->addressType ->setItemData (index, showAllTypesToolTip (), Qt::ToolTipRole);
451
+ ui->addressType ->setCurrentIndex (index);
452
+ }
453
+
454
+ void AddressBookPage::setupAddressTypeCombo ()
455
+ {
456
+ this ->initializeAddressTypeCombo ();
457
+ ui->labelAddressType ->setVisible (tab == ReceivingTab);
458
+ ui->addressType ->setVisible (tab == ReceivingTab);
459
+ GUIUtil::AddItemsToAddressTypeCombo (ui->addressType , true , this ->addressTypeTooltipMap ());
460
+ connect (ui->addressType , qOverload<int >(&QComboBox::currentIndexChanged), this , &AddressBookPage::handleAddressTypeChanged);
461
+ connect (this , &AddressBookPage::addressTypeChanged, proxyModel->nestedProxyModel (), &QSortFilterProxyModel::setFilterFixedString);
462
+ }
0 commit comments