@@ -163,7 +163,7 @@ void AddressBookPage::setModel(AddressTableModel *_model)
163163 return ;
164164
165165 auto type = tab == ReceivingTab ? AddressTableModel::Receive : AddressTableModel::Send;
166- proxyModel.reset (new AddressBookSortFilterProxyModel (type, this , false ));
166+ proxyModel.reset (new AddressBookSortFilterProxyModel (type, this , true ));
167167 proxyModel->setSourceModel (_model);
168168
169169 connect (ui->searchLineEdit , &QLineEdit::textChanged, proxyModel.get (), &QSortFilterProxyModel::setFilterWildcard);
@@ -186,6 +186,8 @@ void AddressBookPage::setModel(AddressTableModel *_model)
186186
187187 selectionChanged ();
188188 this ->updateWindowsTitleWithWalletName ();
189+
190+ this ->setupAddressTypeCombo ();
189191}
190192
191193void AddressBookPage::on_copyAddress_clicked ()
@@ -214,7 +216,7 @@ void AddressBookPage::onEditAction()
214216 EditAddressDialog::EditSendingAddress :
215217 EditAddressDialog::EditReceivingAddress, this );
216218 dlg->setModel (model);
217- QModelIndex origIndex = proxyModel->mapToSource (indexes.at (0 ));
219+ QModelIndex origIndex = proxyModel->nestedProxyModel ()-> mapToSource (indexes.at (0 ));
218220 dlg->loadRow (origIndex.row ());
219221 GUIUtil::ShowModalDialogAsynchronously (dlg);
220222}
@@ -318,7 +320,7 @@ void AddressBookPage::on_exportButton_clicked()
318320 CSVModelWriter writer (filename);
319321
320322 // name, column, role
321- writer.setModel (proxyModel. get ());
323+ writer.setModel (proxyModel-> nestedProxyModel ());
322324 writer.addColumn (" Label" , AddressTableModel::Label, Qt::EditRole);
323325 writer.addColumn (" Address Type" , AddressTableModel::Type, Qt::EditRole);
324326 writer.addColumn (" Address" , AddressTableModel::Address, Qt::EditRole);
@@ -342,7 +344,7 @@ void AddressBookPage::contextualMenu(const QPoint &point)
342344
343345void AddressBookPage::selectNewAddress (const QModelIndex &parent, int begin, int /* end*/ )
344346{
345- QModelIndex idx = proxyModel->mapFromSource (model->index (begin, AddressTableModel::Address, parent));
347+ QModelIndex idx = proxyModel. get () ->mapFromSource (model->index (begin, AddressTableModel::Address, parent));
346348 if (idx.isValid () && (idx.data (Qt::EditRole).toString () == newAddressToSelect))
347349 {
348350 // Select row of newly created address, once
@@ -364,3 +366,97 @@ void AddressBookPage::updateWindowsTitleWithWalletName()
364366 }
365367 }
366368}
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