From 81ec90be9c2ef4342b50cf896f90c481721ddaee Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 26 Apr 2023 12:48:59 +0400 Subject: [PATCH 1/2] GeckoCode: Add sort by enabled state --- .../Core/DolphinQt/Config/GeckoCodeWidget.cpp | 23 +++++++++++++++++++ .../Core/DolphinQt/Config/GeckoCodeWidget.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp b/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp index b94a544424..124bb20185 100644 --- a/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp +++ b/Source/Core/DolphinQt/Config/GeckoCodeWidget.cpp @@ -3,6 +3,7 @@ #include "DolphinQt/Config/GeckoCodeWidget.h" +#include #include #include @@ -257,6 +258,8 @@ void GeckoCodeWidget::OnContextMenuRequested() QMenu menu; menu.addAction(tr("Sort Alphabetically"), this, &GeckoCodeWidget::SortAlphabetically); + menu.addAction(tr("Show Enabled Codes First"), this, &GeckoCodeWidget::SortEnabledCodesFirst); + menu.addAction(tr("Show Disabled Codes First"), this, &GeckoCodeWidget::SortDisabledCodesFirst); menu.exec(QCursor::pos()); } @@ -267,6 +270,26 @@ void GeckoCodeWidget::SortAlphabetically() OnListReordered(); } +void GeckoCodeWidget::SortEnabledCodesFirst() +{ + std::stable_sort(m_gecko_codes.begin(), m_gecko_codes.end(), [](const auto& a, const auto& b) { + return a.enabled && a.enabled != b.enabled; + }); + + UpdateList(); + SaveCodes(); +} + +void GeckoCodeWidget::SortDisabledCodesFirst() +{ + std::stable_sort(m_gecko_codes.begin(), m_gecko_codes.end(), [](const auto& a, const auto& b) { + return !a.enabled && a.enabled != b.enabled; + }); + + UpdateList(); + SaveCodes(); +} + void GeckoCodeWidget::OnListReordered() { // Reorder codes based on the indices of table item diff --git a/Source/Core/DolphinQt/Config/GeckoCodeWidget.h b/Source/Core/DolphinQt/Config/GeckoCodeWidget.h index 7a5fe17667..a4312f7ec7 100644 --- a/Source/Core/DolphinQt/Config/GeckoCodeWidget.h +++ b/Source/Core/DolphinQt/Config/GeckoCodeWidget.h @@ -48,6 +48,8 @@ private: void DownloadCodes(); void SaveCodes(); void SortAlphabetically(); + void SortEnabledCodesFirst(); + void SortDisabledCodesFirst(); std::string m_game_id; std::string m_gametdb_id; From 26355957374931e31bfd31a40fbe69a0ed66f262 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 26 Apr 2023 12:53:29 +0400 Subject: [PATCH 2/2] ARCode: Add sort by enabled state --- Source/Core/DolphinQt/Config/ARCodeWidget.cpp | 23 +++++++++++++++++++ Source/Core/DolphinQt/Config/ARCodeWidget.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp index 6a18a16937..667f9373c1 100644 --- a/Source/Core/DolphinQt/Config/ARCodeWidget.cpp +++ b/Source/Core/DolphinQt/Config/ARCodeWidget.cpp @@ -3,6 +3,7 @@ #include "DolphinQt/Config/ARCodeWidget.h" +#include #include #include @@ -113,6 +114,8 @@ void ARCodeWidget::OnContextMenuRequested() QMenu menu; menu.addAction(tr("Sort Alphabetically"), this, &ARCodeWidget::SortAlphabetically); + menu.addAction(tr("Show Enabled Codes First"), this, &ARCodeWidget::SortEnabledCodesFirst); + menu.addAction(tr("Show Disabled Codes First"), this, &ARCodeWidget::SortDisabledCodesFirst); menu.exec(QCursor::pos()); } @@ -123,6 +126,26 @@ void ARCodeWidget::SortAlphabetically() OnListReordered(); } +void ARCodeWidget::SortEnabledCodesFirst() +{ + std::stable_sort(m_ar_codes.begin(), m_ar_codes.end(), [](const auto& a, const auto& b) { + return a.enabled && a.enabled != b.enabled; + }); + + UpdateList(); + SaveCodes(); +} + +void ARCodeWidget::SortDisabledCodesFirst() +{ + std::stable_sort(m_ar_codes.begin(), m_ar_codes.end(), [](const auto& a, const auto& b) { + return !a.enabled && a.enabled != b.enabled; + }); + + UpdateList(); + SaveCodes(); +} + void ARCodeWidget::OnListReordered() { // Reorder codes based on the indices of table item diff --git a/Source/Core/DolphinQt/Config/ARCodeWidget.h b/Source/Core/DolphinQt/Config/ARCodeWidget.h index 862eaac1ab..d24c3fcaf8 100644 --- a/Source/Core/DolphinQt/Config/ARCodeWidget.h +++ b/Source/Core/DolphinQt/Config/ARCodeWidget.h @@ -43,6 +43,8 @@ private: void UpdateList(); void SaveCodes(); void SortAlphabetically(); + void SortEnabledCodesFirst(); + void SortDisabledCodesFirst(); void OnCodeAddClicked(); void OnCodeEditClicked();