mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-03-11 08:54:48 +00:00
Move more methods into base class
This commit is contained in:
parent
be137a2cac
commit
c9aff28f7e
8 changed files with 50 additions and 122 deletions
|
|
@ -53,6 +53,24 @@ ReportsWidgetBase::ReportsWidgetBase(QWidget* parent, SortProxyModelKind proxyMo
|
|||
ReportsWidgetBase::~ReportsWidgetBase()
|
||||
{}
|
||||
|
||||
void ReportsWidgetBase::loadSettings(QSharedPointer<Database> db)
|
||||
{
|
||||
m_db = std::move(db);
|
||||
m_widgetDataCalculated = false;
|
||||
m_referencesModel->clear();
|
||||
m_rowToEntry.clear();
|
||||
|
||||
auto row = QList<QStandardItem*>();
|
||||
row << new QStandardItem(tr("Please wait, report is being calculated…"));
|
||||
m_referencesModel->appendRow(row);
|
||||
}
|
||||
|
||||
void ReportsWidgetBase::saveSettings()
|
||||
{
|
||||
// Most report tabs are passive, so override them in derived classes if they need to
|
||||
// save settings
|
||||
}
|
||||
|
||||
QMenu *ReportsWidgetBase::customMenuRequestedBase()
|
||||
{
|
||||
auto selected = getTableView()->selectionModel()->selectedRows();
|
||||
|
|
@ -230,3 +248,19 @@ void ReportsWidgetBase::deleteSelectedEntries()
|
|||
|
||||
updateWidget();
|
||||
}
|
||||
|
||||
void ReportsWidgetBase::emitEntryActivated(const QModelIndex& index)
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
emit entryActivated(const_cast<Entry*>(entry));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@ public:
|
|||
explicit ReportsWidgetBase(QWidget* parent, SortProxyModelKind);
|
||||
virtual ~ReportsWidgetBase();
|
||||
|
||||
virtual void loadSettings(QSharedPointer<Database> db);
|
||||
virtual void saveSettings();
|
||||
|
||||
protected:
|
||||
virtual QTableView *getTableView() const = 0;
|
||||
virtual void updateWidget() = 0;
|
||||
|
|
@ -54,12 +57,13 @@ public slots:
|
|||
QList<Entry*> getSelectedEntries();
|
||||
void expireSelectedEntries();
|
||||
void deleteSelectedEntries();
|
||||
void emitEntryActivated(const QModelIndex& index);
|
||||
|
||||
signals:
|
||||
void entryActivated(Entry*);
|
||||
|
||||
protected:
|
||||
bool m_calculated = false;
|
||||
bool m_widgetDataCalculated = false;
|
||||
QScopedPointer<QStandardItemModel> m_referencesModel;
|
||||
QScopedPointer<QSortFilterProxyModel> m_modelProxy;
|
||||
QSharedPointer<Database> m_db;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include "core/Metadata.h"
|
||||
#include "gui/GuiTools.h"
|
||||
#include "gui/Icons.h"
|
||||
#include "gui/MessageBox.h"
|
||||
#include "gui/styles/StateColorPalette.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
|
|
@ -174,25 +173,13 @@ void ReportsWidgetBrowserStatistics::addStatisticsRow(bool hasUrls,
|
|||
m_rowToEntry.append({group, entry});
|
||||
}
|
||||
|
||||
void ReportsWidgetBrowserStatistics::loadSettings(QSharedPointer<Database> db)
|
||||
{
|
||||
m_db = std::move(db);
|
||||
m_statisticsCalculated = false;
|
||||
m_referencesModel->clear();
|
||||
m_rowToEntry.clear();
|
||||
|
||||
auto row = QList<QStandardItem*>();
|
||||
row << new QStandardItem(tr("Please wait, browser statistics is being calculated…"));
|
||||
m_referencesModel->appendRow(row);
|
||||
}
|
||||
|
||||
void ReportsWidgetBrowserStatistics::showEvent(QShowEvent* event)
|
||||
{
|
||||
QWidget::showEvent(event);
|
||||
|
||||
if (!m_statisticsCalculated) {
|
||||
if (!m_widgetDataCalculated) {
|
||||
// Perform stats calculation on next event loop to allow widget to appear
|
||||
m_statisticsCalculated = true;
|
||||
m_widgetDataCalculated = true;
|
||||
QTimer::singleShot(0, this, SLOT(calculateBrowserStatistics()));
|
||||
}
|
||||
}
|
||||
|
|
@ -245,22 +232,6 @@ void ReportsWidgetBrowserStatistics::calculateBrowserStatistics()
|
|||
m_ui->browserStatisticsTableView->resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void ReportsWidgetBrowserStatistics::emitEntryActivated(const QModelIndex& index)
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
emit entryActivated(const_cast<Entry*>(entry));
|
||||
}
|
||||
}
|
||||
|
||||
void ReportsWidgetBrowserStatistics::customMenuRequested(QPoint pos)
|
||||
{
|
||||
auto menu = customMenuRequestedBase();
|
||||
|
|
@ -284,11 +255,6 @@ void ReportsWidgetBrowserStatistics::customMenuRequested(QPoint pos)
|
|||
menu->popup(m_ui->browserStatisticsTableView->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void ReportsWidgetBrowserStatistics::saveSettings()
|
||||
{
|
||||
// Nothing to do - the tab is passive
|
||||
}
|
||||
|
||||
void ReportsWidgetBrowserStatistics::deletePluginDataFromSelectedEntries()
|
||||
{
|
||||
const auto& selectedEntries = getSelectedEntries();
|
||||
|
|
|
|||
|
|
@ -41,9 +41,6 @@ public:
|
|||
explicit ReportsWidgetBrowserStatistics(QWidget* parent = nullptr);
|
||||
~ReportsWidgetBrowserStatistics() override;
|
||||
|
||||
void loadSettings(QSharedPointer<Database> db);
|
||||
void saveSettings();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
void updateWidget() override;
|
||||
|
|
@ -54,7 +51,6 @@ signals:
|
|||
|
||||
public slots:
|
||||
void calculateBrowserStatistics();
|
||||
void emitEntryActivated(const QModelIndex& index);
|
||||
void customMenuRequested(QPoint);
|
||||
void deletePluginDataFromSelectedEntries();
|
||||
|
||||
|
|
@ -63,8 +59,6 @@ private:
|
|||
QMap<QString, QStringList> getBrowserConfigFromEntry(Entry* entry) const;
|
||||
|
||||
QScopedPointer<Ui::ReportsWidgetBrowserStatistics> m_ui;
|
||||
|
||||
bool m_statisticsCalculated = false;
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_REPORTSWIDGETBROWSERSTATISTICS_H
|
||||
|
|
|
|||
|
|
@ -24,13 +24,11 @@
|
|||
#include "core/PasswordHealth.h"
|
||||
#include "gui/GuiTools.h"
|
||||
#include "gui/Icons.h"
|
||||
#include "gui/MessageBox.h"
|
||||
#include "gui/styles/StateColorPalette.h"
|
||||
#include "gui/reports/ProxyModels.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QShortcut>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
namespace
|
||||
|
|
@ -77,27 +75,6 @@ namespace
|
|||
QList<QSharedPointer<Item>> m_items;
|
||||
bool m_anyExcludedEntries = false;
|
||||
};
|
||||
|
||||
class ReportSortProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
ReportSortProxyModel(QObject* parent)
|
||||
: QSortFilterProxyModel(parent){};
|
||||
~ReportSortProxyModel() override = default;
|
||||
|
||||
protected:
|
||||
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override
|
||||
{
|
||||
// Check if the display data is a number, convert and compare if so
|
||||
bool ok = false;
|
||||
int leftInt = sourceModel()->data(left).toString().toInt(&ok);
|
||||
if (ok) {
|
||||
return leftInt < sourceModel()->data(right).toString().toInt();
|
||||
}
|
||||
// Otherwise use default sorting
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Health::Health(QSharedPointer<Database> db)
|
||||
|
|
@ -238,15 +215,7 @@ void ReportsWidgetHealthcheck::addHealthRow(QSharedPointer<PasswordHealth> healt
|
|||
|
||||
void ReportsWidgetHealthcheck::loadSettings(QSharedPointer<Database> db)
|
||||
{
|
||||
m_db = std::move(db);
|
||||
m_healthCalculated = false;
|
||||
m_referencesModel->clear();
|
||||
m_rowToEntry.clear();
|
||||
|
||||
auto row = QList<QStandardItem*>();
|
||||
row << new QStandardItem(tr("Please wait, health data is being calculated…"));
|
||||
m_referencesModel->appendRow(row);
|
||||
// Default sort by first column (health score)
|
||||
ReportsWidgetBase::loadSettings(db);
|
||||
m_ui->healthcheckTableView->sortByColumn(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
|
|
@ -254,9 +223,9 @@ void ReportsWidgetHealthcheck::showEvent(QShowEvent* event)
|
|||
{
|
||||
QWidget::showEvent(event);
|
||||
|
||||
if (!m_healthCalculated) {
|
||||
if (!m_widgetDataCalculated) {
|
||||
// Perform stats calculation on next event loop to allow widget to appear
|
||||
m_healthCalculated = true;
|
||||
m_widgetDataCalculated = true;
|
||||
QTimer::singleShot(0, this, SLOT(calculateHealth()));
|
||||
}
|
||||
}
|
||||
|
|
@ -306,21 +275,6 @@ void ReportsWidgetHealthcheck::calculateHealth()
|
|||
emit tablePopulated();
|
||||
}
|
||||
|
||||
void ReportsWidgetHealthcheck::emitEntryActivated(const QModelIndex& index)
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
emit entryActivated(const_cast<Entry*>(entry));
|
||||
}
|
||||
}
|
||||
|
||||
void ReportsWidgetHealthcheck::customMenuRequested(QPoint pos)
|
||||
{
|
||||
auto menu = customMenuRequestedBase();
|
||||
|
|
@ -333,11 +287,6 @@ void ReportsWidgetHealthcheck::customMenuRequested(QPoint pos)
|
|||
menu->popup(m_ui->healthcheckTableView->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void ReportsWidgetHealthcheck::saveSettings()
|
||||
{
|
||||
// nothing to do - the tab is passive
|
||||
}
|
||||
|
||||
void ReportsWidgetHealthcheck::updateWidget()
|
||||
{
|
||||
calculateHealth();
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ public:
|
|||
explicit ReportsWidgetHealthcheck(QWidget* parent = nullptr);
|
||||
~ReportsWidgetHealthcheck() override;
|
||||
|
||||
void loadSettings(QSharedPointer<Database> db);
|
||||
void saveSettings();
|
||||
void loadSettings(QSharedPointer<Database> db) override;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
|
@ -51,20 +50,16 @@ protected:
|
|||
QTableView *getTableView() const override;
|
||||
|
||||
signals:
|
||||
void entryActivated(Entry*);
|
||||
void tablePopulated();
|
||||
|
||||
public slots:
|
||||
void calculateHealth();
|
||||
void emitEntryActivated(const QModelIndex& index);
|
||||
void customMenuRequested(QPoint);
|
||||
|
||||
private:
|
||||
void addHealthRow(QSharedPointer<PasswordHealth>, Group*, Entry*, bool excluded);
|
||||
|
||||
QScopedPointer<Ui::ReportsWidgetHealthcheck> m_ui;
|
||||
|
||||
bool m_healthCalculated = false;
|
||||
};
|
||||
|
||||
#endif // KEEPASSXC_REPORTSWIDGETHEALTHCHECK_H
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include "core/Metadata.h"
|
||||
#include "gui/GuiTools.h"
|
||||
#include "gui/Icons.h"
|
||||
#include "gui/MessageBox.h"
|
||||
#include "gui/reports/ProxyModels.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
|
@ -61,21 +60,17 @@ ReportsWidgetHibp::~ReportsWidgetHibp() = default;
|
|||
|
||||
void ReportsWidgetHibp::loadSettings(QSharedPointer<Database> db)
|
||||
{
|
||||
// Re-initialize
|
||||
m_db = std::move(db);
|
||||
m_referencesModel->clear();
|
||||
m_pwndPasswords.clear();
|
||||
m_error.clear();
|
||||
m_rowToEntry.clear();
|
||||
m_editedEntry = nullptr;
|
||||
#ifdef WITH_XC_NETWORKING
|
||||
m_ui->stackedWidget->setCurrentIndex(0);
|
||||
m_ui->validationButton->setEnabled(true);
|
||||
m_ui->progressBar->hide();
|
||||
#else
|
||||
// Compiled without networking, can't do anything
|
||||
// Compiled without networking, can't do anything
|
||||
m_ui->stackedWidget->setCurrentIndex(2);
|
||||
#endif
|
||||
|
||||
ReportsWidgetBase::loadSettings(db);
|
||||
m_referencesModel->clear();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -348,11 +343,6 @@ void ReportsWidgetHibp::customMenuRequested(QPoint pos)
|
|||
menu->popup(m_ui->hibpTableView->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void ReportsWidgetHibp::saveSettings()
|
||||
{
|
||||
// nothing to do - the tab is passive
|
||||
}
|
||||
|
||||
void ReportsWidgetHibp::updateWidget()
|
||||
{
|
||||
makeHibpTable();
|
||||
|
|
|
|||
|
|
@ -47,17 +47,13 @@ public:
|
|||
explicit ReportsWidgetHibp(QWidget* parent = nullptr);
|
||||
~ReportsWidgetHibp() override;
|
||||
|
||||
void loadSettings(QSharedPointer<Database> db);
|
||||
void saveSettings();
|
||||
void loadSettings(QSharedPointer<Database> db) override;
|
||||
void refreshAfterEdit();
|
||||
|
||||
protected:
|
||||
void updateWidget() override;
|
||||
QTableView *getTableView() const override;
|
||||
|
||||
signals:
|
||||
void entryActivated(Entry*);
|
||||
|
||||
public slots:
|
||||
void emitEntryActivated(const QModelIndex&);
|
||||
void addHibpResult(const QString&, int);
|
||||
|
|
|
|||
Loading…
Reference in a new issue