diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index da47befd530..07492ad12b1 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -28,15 +28,31 @@ class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel { const QString m_type; + const bool m_nestedFilterEnabled; public: - AddressBookSortFilterProxyModel(const QString& type, QObject* parent) + AddressBookSortFilterProxyModel(const QString& type, QObject* parent, bool enableNestedFilter) : QSortFilterProxyModel(parent) , m_type(type) + , m_nestedFilterEnabled(enableNestedFilter) { setDynamicSortFilter(true); setFilterCaseSensitivity(Qt::CaseInsensitive); setSortCaseSensitivity(Qt::CaseInsensitive); + + if (m_nestedFilterEnabled) { + nextedFilterProxyModel.reset(new AddressBookSortFilterProxyModel(type, this, false)); + nextedFilterProxyModel->setSourceModel(this); + } + } + + AddressBookSortFilterProxyModel* nestedProxyModel() const noexcept{ + if (!m_nestedFilterEnabled) return const_cast(this); + return nextedFilterProxyModel.get(); + } + + bool isNestedFilterEnabled() const { + return m_nestedFilterEnabled; } protected: @@ -66,6 +82,9 @@ class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel return filterBy; } + +private: + std::unique_ptr nextedFilterProxyModel{nullptr}; }; AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode _mode, Tabs _tab, QWidget *parent) : @@ -154,12 +173,12 @@ void AddressBookPage::setModel(AddressTableModel *_model) return; auto type = tab == ReceivingTab ? AddressTableModel::Receive : AddressTableModel::Send; - proxyModel = new AddressBookSortFilterProxyModel(type, this); + proxyModel.reset(new AddressBookSortFilterProxyModel(type, this, false)); proxyModel->setSourceModel(_model); - connect(ui->searchLineEdit, &QLineEdit::textChanged, proxyModel, &QSortFilterProxyModel::setFilterWildcard); + connect(ui->searchLineEdit, &QLineEdit::textChanged, proxyModel.get(), &QSortFilterProxyModel::setFilterWildcard); - ui->tableView->setModel(proxyModel); + ui->tableView->setModel(proxyModel->nestedProxyModel()); ui->tableView->sortByColumn(0, Qt::AscendingOrder); // Set column widths @@ -308,7 +327,7 @@ void AddressBookPage::on_exportButton_clicked() CSVModelWriter writer(filename); // name, column, role - writer.setModel(proxyModel); + writer.setModel(proxyModel.get()); writer.addColumn("Label", AddressTableModel::Label, Qt::EditRole); writer.addColumn("Address Type", AddressTableModel::Type, Qt::EditRole); writer.addColumn("Address", AddressTableModel::Address, Qt::EditRole); diff --git a/src/qt/addressbookpage.h b/src/qt/addressbookpage.h index 283209d00c7..fe7095118bd 100644 --- a/src/qt/addressbookpage.h +++ b/src/qt/addressbookpage.h @@ -53,7 +53,7 @@ public Q_SLOTS: Mode mode; Tabs tab; QString returnValue; - AddressBookSortFilterProxyModel *proxyModel; + std::unique_ptr proxyModel{nullptr}; QMenu *contextMenu; QString newAddressToSelect;