diff --git a/src/gui/reports/ReportsWidgetHealthcheck.cpp b/src/gui/reports/ReportsWidgetHealthcheck.cpp index 9e1cf1812..5f502b16b 100644 --- a/src/gui/reports/ReportsWidgetHealthcheck.cpp +++ b/src/gui/reports/ReportsWidgetHealthcheck.cpp @@ -28,6 +28,7 @@ #include #include +#include #include namespace @@ -119,11 +120,13 @@ ReportsWidgetHealthcheck::ReportsWidgetHealthcheck(QWidget* parent) : QWidget(parent) , m_ui(new Ui::ReportsWidgetHealthcheck()) , m_errorIcon(Resources::instance()->icon("dialog-error")) + , m_referencesModel(new QStandardItemModel(this)) + , m_modelProxy(new QSortFilterProxyModel(this)) { m_ui->setupUi(this); - m_referencesModel.reset(new QStandardItemModel()); - m_ui->healthcheckTableView->setModel(m_referencesModel.data()); + m_modelProxy->setSourceModel(m_referencesModel.data()); + m_ui->healthcheckTableView->setModel(m_modelProxy.data()); m_ui->healthcheckTableView->setSelectionMode(QAbstractItemView::NoSelection); m_ui->healthcheckTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); m_ui->healthcheckTableView->setSortingEnabled(true); @@ -272,7 +275,8 @@ void ReportsWidgetHealthcheck::emitEntryActivated(const QModelIndex& index) return; } - const auto row = m_rowToEntry[index.row()]; + auto mappedIndex = m_modelProxy->mapToSource(index); + const auto row = m_rowToEntry[mappedIndex.row()]; const auto group = row.first; const auto entry = row.second; if (group && entry) { @@ -288,7 +292,8 @@ void ReportsWidgetHealthcheck::customMenuRequested(QPoint pos) if (!index.isValid()) { return; } - m_contextmenuEntry = const_cast(m_rowToEntry[index.row()].second); + auto mappedIndex = m_modelProxy->mapToSource(index); + m_contextmenuEntry = const_cast(m_rowToEntry[mappedIndex.row()].second); if (!m_contextmenuEntry) { return; } diff --git a/src/gui/reports/ReportsWidgetHealthcheck.h b/src/gui/reports/ReportsWidgetHealthcheck.h index ca848e686..58ac0a03b 100644 --- a/src/gui/reports/ReportsWidgetHealthcheck.h +++ b/src/gui/reports/ReportsWidgetHealthcheck.h @@ -28,6 +28,7 @@ class Database; class Entry; class Group; class PasswordHealth; +class QSortFilterProxyModel; class QStandardItemModel; namespace Ui @@ -66,6 +67,7 @@ private: bool m_healthCalculated = false; QIcon m_errorIcon; QScopedPointer m_referencesModel; + QScopedPointer m_modelProxy; QSharedPointer m_db; QList> m_rowToEntry; Entry* m_contextmenuEntry = nullptr; diff --git a/src/gui/reports/ReportsWidgetHibp.cpp b/src/gui/reports/ReportsWidgetHibp.cpp index 48e3946a4..48e36518d 100644 --- a/src/gui/reports/ReportsWidgetHibp.cpp +++ b/src/gui/reports/ReportsWidgetHibp.cpp @@ -27,6 +27,7 @@ #include "gui/MessageBox.h" #include +#include #include namespace @@ -49,11 +50,13 @@ namespace ReportsWidgetHibp::ReportsWidgetHibp(QWidget* parent) : QWidget(parent) , m_ui(new Ui::ReportsWidgetHibp()) + , m_referencesModel(new QStandardItemModel(this)) + , m_modelProxy(new QSortFilterProxyModel(this)) { m_ui->setupUi(this); - m_referencesModel.reset(new QStandardItemModel()); - m_ui->hibpTableView->setModel(m_referencesModel.data()); + m_modelProxy->setSourceModel(m_referencesModel.data()); + m_ui->hibpTableView->setModel(m_modelProxy.data()); m_ui->hibpTableView->setSelectionMode(QAbstractItemView::NoSelection); m_ui->hibpTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); m_ui->hibpTableView->setSortingEnabled(true); @@ -299,7 +302,8 @@ void ReportsWidgetHibp::emitEntryActivated(const QModelIndex& index) } // Find which database entry was double-clicked - const auto entry = m_rowToEntry[index.row()]; + auto mappedIndex = m_modelProxy->mapToSource(index); + const auto entry = m_rowToEntry[mappedIndex.row()]; if (entry) { // Found it, invoke entry editor m_editedEntry = entry; @@ -350,7 +354,8 @@ void ReportsWidgetHibp::customMenuRequested(QPoint pos) if (!index.isValid()) { return; } - m_contextmenuEntry = const_cast(m_rowToEntry[index.row()]); + auto mappedIndex = m_modelProxy->mapToSource(index); + m_contextmenuEntry = const_cast(m_rowToEntry[mappedIndex.row()]); if (!m_contextmenuEntry) { return; } diff --git a/src/gui/reports/ReportsWidgetHibp.h b/src/gui/reports/ReportsWidgetHibp.h index f7d1a754b..0d76c07fe 100644 --- a/src/gui/reports/ReportsWidgetHibp.h +++ b/src/gui/reports/ReportsWidgetHibp.h @@ -33,6 +33,7 @@ class Database; class Entry; class Group; +class QSortFilterProxyModel; class QStandardItemModel; namespace Ui @@ -69,6 +70,7 @@ private: QScopedPointer m_ui; QScopedPointer m_referencesModel; + QScopedPointer m_modelProxy; QSharedPointer m_db; QMap m_pwndPasswords; // Passwords we found to have been pwned (value is pwn count)