From 2a02e029d2169e1e29333b21c7db1e17fdea37ce Mon Sep 17 00:00:00 2001 From: Agoston Szepessy Date: Sun, 28 Dec 2025 22:30:32 -0800 Subject: [PATCH] Copilot PR feedback --- src/core/Group.cpp | 4 +- .../ReportsWidgetBrowserStatistics.cpp | 37 ++++++------ src/gui/reports/ReportsWidgetHealthcheck.cpp | 34 ++++++----- src/gui/reports/ReportsWidgetHibp.cpp | 43 +++++++------- tests/gui/TestGui.cpp | 56 +++++++++---------- tests/gui/TestGui.h | 4 +- 6 files changed, 96 insertions(+), 82 deletions(-) diff --git a/src/core/Group.cpp b/src/core/Group.cpp index 7b93dee21..29c765a6a 100644 --- a/src/core/Group.cpp +++ b/src/core/Group.cpp @@ -1289,7 +1289,7 @@ void Group::setExcludeFromReports(bool excluded) // group because it'll make it easier to individually set it for an // entry later on if (excluded) { - for (auto &entry : m_entries) { + for (auto& entry : m_entries) { entry->setExcludeFromReports(false); } } @@ -1297,7 +1297,7 @@ void Group::setExcludeFromReports(bool excluded) void Group::markAllEntriesExcludedFromReports() { - for (auto &entry : m_entries) { + for (auto& entry : m_entries) { entry->setExcludeFromReports(true); } } diff --git a/src/gui/reports/ReportsWidgetBrowserStatistics.cpp b/src/gui/reports/ReportsWidgetBrowserStatistics.cpp index b8a857541..25f57aced 100644 --- a/src/gui/reports/ReportsWidgetBrowserStatistics.cpp +++ b/src/gui/reports/ReportsWidgetBrowserStatistics.cpp @@ -24,8 +24,8 @@ #include "core/Metadata.h" #include "gui/GuiTools.h" #include "gui/Icons.h" -#include "gui/styles/StateColorPalette.h" #include "gui/MessageBox.h" +#include "gui/styles/StateColorPalette.h" #include #include @@ -142,8 +142,8 @@ void ReportsWidgetBrowserStatistics::addStatisticsRow(bool hasUrls, auto title = entry->title(); if (excluded) { - if(group->excludeFromReports()) { - title.append(tr(" (Group Excluded")); + if (group->excludeFromReports()) { + title.append(tr(" (Group Excluded)")); } else { title.append(tr(" (Excluded)")); } @@ -306,7 +306,8 @@ void ReportsWidgetBrowserStatistics::customMenuRequested(QPoint pos) // Create the "exclude from reports" menu item const auto excludeAction = new QAction(icons()->icon("reports-exclude"), tr("Exclude Entry(s) from reports"), this); - const auto excludeGroupsAction = new QAction(icons()->icon("reports-exclude"), tr("Exclude Group(s) from reports"), this); + const auto excludeGroupsAction = + new QAction(icons()->icon("reports-exclude"), tr("Exclude Group(s) from reports"), this); bool isExcluded = false; bool isGroupExcluded = false; @@ -336,28 +337,32 @@ void ReportsWidgetBrowserStatistics::customMenuRequested(QPoint pos) connect(excludeAction, &QAction::toggled, excludeAction, [this, selected](bool checked) { QSet groups; - // If we are including entries (checked is false) but a group is excluded, ask the user if they - // would like to include the rest of the group as well (or keep it excluded). - // If they exclude it, we need to include the whole group, and then exclude - // the entries that aren't selected here. + // If we are including entries (checked is false) but a group is excluded, ask the user if they + // would like to include the rest of the group as well (or keep it excluded). + // If they exclude it, we need to include the whole group, and then exclude + // the entries that aren't selected here. if (!checked) { - for(const auto index : selected) { + for (const auto index : selected) { auto row = m_modelProxy->mapToSource(index).row(); auto entry = m_rowToEntry[row].second; if (entry) { - auto *group = entry->group(); + auto* group = entry->group(); if (group->excludeFromReports() && !groups.contains(group)) { - QString msg = tr("The Group for \"%1\" is excluded. Would you like to include all Entries from there as well?").arg(entry->title()); - auto response = MessageBox::question(this, tr("Include Group?"), msg, MessageBox::Yes | MessageBox::No | MessageBox::Cancel, MessageBox::No); + QString msg = tr("The Group for \"%1\" is excluded. Would you like to include all Entries from " + "there as well?") + .arg(entry->title()); + auto response = MessageBox::question(this, + tr("Include Group?"), + msg, + MessageBox::Yes | MessageBox::No | MessageBox::Cancel, + MessageBox::No); if (response == MessageBox::Cancel) { return; - } - else if (response == MessageBox::Yes) { + } else if (response == MessageBox::Yes) { group->setExcludeFromReports(false); - } - else if (response == MessageBox::No) { + } else if (response == MessageBox::No) { // We'll exclude all entries from the group here and then // include the selected ones below group->setExcludeFromReports(false); diff --git a/src/gui/reports/ReportsWidgetHealthcheck.cpp b/src/gui/reports/ReportsWidgetHealthcheck.cpp index 8b5912fe7..ee77eadf4 100644 --- a/src/gui/reports/ReportsWidgetHealthcheck.cpp +++ b/src/gui/reports/ReportsWidgetHealthcheck.cpp @@ -24,8 +24,8 @@ #include "core/PasswordHealth.h" #include "gui/GuiTools.h" #include "gui/Icons.h" -#include "gui/styles/StateColorPalette.h" #include "gui/MessageBox.h" +#include "gui/styles/StateColorPalette.h" #include #include @@ -198,8 +198,8 @@ void ReportsWidgetHealthcheck::addHealthRow(QSharedPointer healt auto title = entry->title(); if (excluded) { - if(group->excludeFromReports()) { - title.append(tr(" (Group Excluded")); + if (group->excludeFromReports()) { + title.append(tr(" (Group Excluded)")); } else { title.append(tr(" (Excluded)")); } @@ -226,8 +226,7 @@ void ReportsWidgetHealthcheck::addHealthRow(QSharedPointer healt if (excluded) { if (group->excludeFromReports()) { row[1]->setToolTip(tr("The group for this entry is being excluded from reports")); - } - else { + } else { row[1]->setToolTip(tr("This entry is being excluded from reports")); } } @@ -360,8 +359,9 @@ void ReportsWidgetHealthcheck::customMenuRequested(QPoint pos) // Create the "exclude from reports" menu item const auto excludeAction = new QAction(icons()->icon("reports-exclude"), tr("Exclude Entry(s) from reports"), this); excludeAction->setObjectName("contextMenuExcludeAction"); - const auto excludeGroupsAction = new QAction(icons()->icon("reports-exclude"), tr("Exclude Group(s) from reports"), this); - excludeGroupsAction->setObjectName("contextMenuxcludeGroupAction"); + const auto excludeGroupsAction = + new QAction(icons()->icon("reports-exclude"), tr("Exclude Group(s) from reports"), this); + excludeGroupsAction->setObjectName("contextMenuExcludeGroupAction"); bool isExcluded = false; bool isGroupExcluded = false; @@ -396,23 +396,27 @@ void ReportsWidgetHealthcheck::customMenuRequested(QPoint pos) // If they exclude it, we need to include the whole group, and then exclude // the entries that aren't selected here. if (!checked) { - for(const auto index : selected) { + for (const auto index : selected) { auto row = m_modelProxy->mapToSource(index).row(); auto entry = m_rowToEntry[row].second; if (entry) { - auto *group = entry->group(); + auto* group = entry->group(); if (group->excludeFromReports() && !groups.contains(group)) { - QString msg = tr("The Group for \"%1\" is excluded. Would you like to include all Entries from there as well?").arg(entry->title()); - auto response = MessageBox::question(this, tr("Include Group?"), msg, MessageBox::Yes | MessageBox::No | MessageBox::Cancel, MessageBox::No); + QString msg = tr("The Group for \"%1\" is excluded. Would you like to include all Entries from " + "there as well?") + .arg(entry->title()); + auto response = MessageBox::question(this, + tr("Include Group?"), + msg, + MessageBox::Yes | MessageBox::No | MessageBox::Cancel, + MessageBox::No); if (response == MessageBox::Cancel) { return; - } - else if (response == MessageBox::Yes) { + } else if (response == MessageBox::Yes) { group->setExcludeFromReports(false); - } - else if (response == MessageBox::No) { + } else if (response == MessageBox::No) { // We'll exclude all entries from the group here and then // include the selected ones below group->setExcludeFromReports(false); diff --git a/src/gui/reports/ReportsWidgetHibp.cpp b/src/gui/reports/ReportsWidgetHibp.cpp index 234041d53..21e8ac7fd 100644 --- a/src/gui/reports/ReportsWidgetHibp.cpp +++ b/src/gui/reports/ReportsWidgetHibp.cpp @@ -160,8 +160,8 @@ void ReportsWidgetHibp::makeHibpTable() continue; } - if(group->excludeFromReports()) { - title.append(tr(" (Group Excluded")); + if (group->excludeFromReports()) { + title.append(tr(" (Group Excluded)")); } else { title.append(tr(" (Excluded)")); } @@ -174,7 +174,7 @@ void ReportsWidgetHibp::makeHibpTable() if (entry->excludeFromReports()) { row[1]->setToolTip(tr("This entry is being excluded from reports")); - } else if(entry->group()->excludeFromReports()) { + } else if (entry->group()->excludeFromReports()) { row[1]->setToolTip(tr("The group for this entry is being excluded from reports")); } @@ -393,7 +393,8 @@ void ReportsWidgetHibp::customMenuRequested(QPoint pos) // Create the "exclude from reports" menu item const auto excludeAction = new QAction(icons()->icon("reports-exclude"), tr("Exclude Entry(s) from reports"), this); - const auto excludeGroupsAction = new QAction(icons()->icon("reports-exclude"), tr("Exclude Group(s) from reports"), this); + const auto excludeGroupsAction = + new QAction(icons()->icon("reports-exclude"), tr("Exclude Group(s) from reports"), this); bool isExcluded = false; bool isGroupExcluded = false; @@ -424,28 +425,32 @@ void ReportsWidgetHibp::customMenuRequested(QPoint pos) connect(excludeAction, &QAction::toggled, excludeAction, [this, selected](bool checked) { QSet groups; - // If we are including entries (checked is false) but a group is excluded, ask the user if they - // would like to include the rest of the group as well (or keep it excluded). - // If they exclude it, we need to include the whole group, and then exclude - // the entries that aren't selected here. + // If we are including entries (checked is false) but a group is excluded, ask the user if they + // would like to include the rest of the group as well (or keep it excluded). + // If they exclude it, we need to include the whole group, and then exclude + // the entries that aren't selected here. if (!checked) { - for(const auto index : selected) { + for (const auto index : selected) { auto row = m_modelProxy->mapToSource(index).row(); auto entry = m_rowToEntry[row]; if (entry) { - auto *group = entry->group(); + auto* group = entry->group(); if (group->excludeFromReports() && !groups.contains(group)) { - QString msg = tr("The Group for \"%1\" is excluded. Would you like to include all Entries from there as well?").arg(entry->title()); - auto response = MessageBox::question(this, tr("Include Group?"), msg, MessageBox::Yes | MessageBox::No | MessageBox::Cancel, MessageBox::No); + QString msg = tr("The Group for \"%1\" is excluded. Would you like to include all Entries from " + "there as well?") + .arg(entry->title()); + auto response = MessageBox::question(this, + tr("Include Group?"), + msg, + MessageBox::Yes | MessageBox::No | MessageBox::Cancel, + MessageBox::No); if (response == MessageBox::Cancel) { return; - } - else if (response == MessageBox::Yes) { + } else if (response == MessageBox::Yes) { group->setExcludeFromReports(false); - } - else if (response == MessageBox::No) { + } else if (response == MessageBox::No) { // We'll exclude all entries from the group here and then // include the selected ones below group->setExcludeFromReports(false); @@ -462,9 +467,9 @@ void ReportsWidgetHibp::customMenuRequested(QPoint pos) auto row = m_modelProxy->mapToSource(index).row(); auto entry = m_rowToEntry[row]; - // If the containing group is excluded but the user wants to include - // this entry, ask if they want to keep the remaining items in the group - // excluded or included + // If the containing group is excluded but the user wants to include + // this entry, ask if they want to keep the remaining items in the group + // excluded or included if (entry) { entry->setExcludeFromReports(checked); } diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index ed75b98a7..0ebb48681 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -62,8 +62,8 @@ #include "gui/group/GroupModel.h" #include "gui/group/GroupView.h" #include "gui/remote/RemoteHandler.h" -#include "gui/reports/ReportsWidgetHealthcheck.h" #include "gui/reports/ReportsDialog.h" +#include "gui/reports/ReportsWidgetHealthcheck.h" #include "gui/tag/TagsEdit.h" #include "gui/wizard/NewDatabaseWizard.h" #include "keys/FileKey.h" @@ -2485,7 +2485,7 @@ void TestGui::testDatabaseReports() Group* financeGroup = m_dbWidget->currentGroup()->findChildByName("Finance"); QCOMPARE(financeGroup->entries().size(), 3); - auto *actionReports = m_mainWindow->findChild("actionReports"); + auto* actionReports = m_mainWindow->findChild("actionReports"); QVERIFY(actionReports->isEnabled()); auto* toolBar = m_mainWindow->findChild("toolBar"); @@ -2498,13 +2498,13 @@ void TestGui::testDatabaseReports() QTest::mouseClick(actionReportsWidget, Qt::LeftButton); - auto *reportsDialog = m_dbWidget->findChild("reportsDialog"); + auto* reportsDialog = m_dbWidget->findChild("reportsDialog"); QVERIFY(reportsDialog); - CategoryListWidget *categoryList = reportsDialog->findChild("categoryList"); + CategoryListWidget* categoryList = reportsDialog->findChild("categoryList"); categoryList->setCurrentCategory(1); - QStackedWidget *stackedWidget = reportsDialog->findChild("stackedWidget"); + QStackedWidget* stackedWidget = reportsDialog->findChild("stackedWidget"); QVERIFY(stackedWidget); stackedWidget->setCurrentIndex(1); @@ -2512,18 +2512,18 @@ void TestGui::testDatabaseReports() QVERIFY(healthCheckWidget); QTest::mouseClick(healthCheckWidget, Qt::LeftButton); - QTableView *healthTable = healthCheckWidget->findChild("healthcheckTableView"); + QTableView* healthTable = healthCheckWidget->findChild("healthcheckTableView"); QVERIFY(healthTable); QSignalSpy healthCheckWidgetSpy(healthCheckWidget, &ReportsWidgetHealthcheck::tablePopulated); - QAbstractItemModel *healthModel = healthTable->model(); + QAbstractItemModel* healthModel = healthTable->model(); QVERIFY(healthModel); QTRY_COMPARE(healthCheckWidgetSpy.count(), 1); QCOMPARE(healthModel->rowCount(), 8); // account for 2 existing passwords at the start of each test case - auto *reportsDialogButtonBox = reportsDialog->findChild("buttonBox"); + auto* reportsDialogButtonBox = reportsDialog->findChild("buttonBox"); QTest::mouseClick(reportsDialogButtonBox->button(QDialogButtonBox::Close), Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode); } @@ -2548,21 +2548,21 @@ void TestGui::testExcludedGroupEntryInReports() auto* toolBar = m_mainWindow->findChild("toolBar"); QVERIFY(toolBar); - auto *editGroupAction = m_mainWindow->findChild("actionGroupEdit"); + auto* editGroupAction = m_mainWindow->findChild("actionGroupEdit"); QVERIFY(editGroupAction->isEnabled()); triggerAction("actionGroupEdit"); auto* editGroupWidget = m_dbWidget->findChild("editGroupWidget"); QVERIFY(editGroupWidget); - // Bring up group edit page + // Bring up group edit page QTest::mouseClick(editGroupWidget, Qt::LeftButton); QLineEdit* nameEdit = editGroupWidget->findChild("editName"); QCOMPARE(nameEdit->text(), QString("Entertainment")); // Find database report exclusion checkbox and check it - QCheckBox *excludeGroupFromReportsCheckbox = editGroupWidget->findChild("excludeReportsCheckBox"); + QCheckBox* excludeGroupFromReportsCheckbox = editGroupWidget->findChild("excludeReportsCheckBox"); QVERIFY(excludeGroupFromReportsCheckbox); excludeGroupFromReportsCheckbox->setChecked(true); @@ -2578,7 +2578,7 @@ void TestGui::testExcludedGroupEntryInReports() QVERIFY(entertainmentGroup->excludeFromReports()); // Verify they don't show up in the report - auto *actionReports = m_mainWindow->findChild("actionReports"); + auto* actionReports = m_mainWindow->findChild("actionReports"); QVERIFY(actionReports->isEnabled()); QWidget* actionReportsWidget = toolBar->widgetForAction(actionReports); @@ -2588,13 +2588,13 @@ void TestGui::testExcludedGroupEntryInReports() QTest::mouseClick(actionReportsWidget, Qt::LeftButton); - auto *reportsDialog = m_dbWidget->findChild("reportsDialog"); + auto* reportsDialog = m_dbWidget->findChild("reportsDialog"); QVERIFY(reportsDialog); - CategoryListWidget *categoryList = reportsDialog->findChild("categoryList"); + CategoryListWidget* categoryList = reportsDialog->findChild("categoryList"); categoryList->setCurrentCategory(1); - QStackedWidget *stackedWidget = reportsDialog->findChild("stackedWidget"); + QStackedWidget* stackedWidget = reportsDialog->findChild("stackedWidget"); QVERIFY(stackedWidget); stackedWidget->setCurrentIndex(1); @@ -2602,19 +2602,19 @@ void TestGui::testExcludedGroupEntryInReports() QVERIFY(healthCheckWidget); QTest::mouseClick(healthCheckWidget, Qt::LeftButton); - QTableView *healthTable = healthCheckWidget->findChild("healthcheckTableView"); + QTableView* healthTable = healthCheckWidget->findChild("healthcheckTableView"); QVERIFY(healthTable); QSignalSpy healthCheckWidgetSpy(healthCheckWidget, &ReportsWidgetHealthcheck::tablePopulated); - QAbstractItemModel *healthModel = healthTable->model(); + QAbstractItemModel* healthModel = healthTable->model(); QVERIFY(healthModel); // There should be 3 showing QTRY_COMPARE(healthCheckWidgetSpy.count(), 1); QCOMPARE(healthModel->rowCount(), 5); // account for 2 existing passwords at the start of each test case - QCheckBox *showExcludedCheckBox = healthCheckWidget->findChild("showExcluded"); + QCheckBox* showExcludedCheckBox = healthCheckWidget->findChild("showExcluded"); QVERIFY(showExcludedCheckBox); QCOMPARE(showExcludedCheckBox->isChecked(), false); @@ -2625,11 +2625,11 @@ void TestGui::testExcludedGroupEntryInReports() healthModel = healthTable->model(); QCOMPARE(healthModel->rowCount(), 8); // account for 2 existing passwords at the start of each test case - for(int i = 0; i < healthModel->rowCount(); ++i) { + for (int i = 0; i < healthModel->rowCount(); ++i) { QModelIndex index = healthModel->index(i, 1); QVariant data = healthModel->data(index); - if(data.toString().contains("Netflix")) { + if (data.toString().contains("Netflix")) { auto rect = healthTable->visualRect(index); auto centerPoint = rect.center(); QTest::mouseClick(healthTable->viewport(), Qt::LeftButton, Qt::NoModifier, centerPoint); @@ -2637,9 +2637,9 @@ void TestGui::testExcludedGroupEntryInReports() // QTest::mouseClick(healthCheckWidget, Qt::RightButton); healthCheckWidget->customMenuRequested(centerPoint); - QMenu *menu = healthCheckWidget->findChild("customMenu"); + QMenu* menu = healthCheckWidget->findChild("customMenu"); QVERIFY(menu); - QAction *excludeEntryAction = healthCheckWidget->findChild("contextMenuExcludeAction"); + QAction* excludeEntryAction = healthCheckWidget->findChild("contextMenuExcludeAction"); QVERIFY(excludeEntryAction); MessageBox::setNextAnswer(MessageBox::No); @@ -2651,11 +2651,11 @@ void TestGui::testExcludedGroupEntryInReports() QTRY_COMPARE(healthCheckWidgetSpy.count(), 3); - for(int i = 0; i < healthModel->rowCount(); ++i) { + for (int i = 0; i < healthModel->rowCount(); ++i) { QModelIndex index = healthModel->index(i, 1); QVariant data = healthModel->data(index); - if(data.toString().contains("Netflix")) { + if (data.toString().contains("Netflix")) { QVERIFY(!data.toString().contains("(Group Excluded)")); break; } @@ -2667,7 +2667,7 @@ void TestGui::testExcludedGroupEntryInReports() QCOMPARE(healthModel->rowCount(), 6); // 2 existing passwords from start, 3 from Finance, 1 from Entertainment - auto *reportsDialogButtonBox = reportsDialog->findChild("buttonBox"); + auto* reportsDialogButtonBox = reportsDialog->findChild("buttonBox"); QTest::mouseClick(reportsDialogButtonBox->button(QDialogButtonBox::Close), Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode); } @@ -2702,7 +2702,7 @@ void TestGui::addCannedEntries() QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); } -void TestGui::addGroup(const QString &name) +void TestGui::addGroup(const QString& name) { // Find buttons for group creation auto* editGroupWidget = m_dbWidget->findChild("editGroupWidget"); @@ -2710,7 +2710,7 @@ void TestGui::addGroup(const QString &name) auto* editGroupWidgetButtonBox = editGroupWidget->findChild("buttonBox"); // Add group with specified name - Group *rootGroup = m_db->rootGroup(); + Group* rootGroup = m_db->rootGroup(); m_dbWidget->groupView()->setCurrentGroup(rootGroup); // Add group on root level m_dbWidget->createGroup(); QTest::keyClicks(nameEdit, name); @@ -2718,7 +2718,7 @@ void TestGui::addGroup(const QString &name) m_dbWidget->groupView()->setCurrentGroup(rootGroup); // Reset to root level } -void TestGui::addEntry(const QString &groupName, const QString &title, const QString &username, const QString &password) +void TestGui::addEntry(const QString& groupName, const QString& title, const QString& username, const QString& password) { // Find buttons auto* toolBar = m_mainWindow->findChild("toolBar"); diff --git a/tests/gui/TestGui.h b/tests/gui/TestGui.h index c9181effe..fee7ab690 100644 --- a/tests/gui/TestGui.h +++ b/tests/gui/TestGui.h @@ -76,8 +76,8 @@ private slots: private: void addCannedEntries(); - void addGroup(const QString &name); - void addEntry(const QString &groupName, const QString &title, const QString &username, const QString &password); + void addGroup(const QString& name); + void addEntry(const QString& groupName, const QString& title, const QString& username, const QString& password); void checkDatabase(const QString& filePath, const QString& expectedDbName); void checkDatabase(const QString& filePath = {}); void triggerAction(const QString& name);