Merge pull request #11796 from sepalani/gecko-sort

Gecko/ARCode: Add sort by enabled state
This commit is contained in:
Mai 2023-05-02 14:59:08 -04:00 committed by GitHub
commit 0b9b09ad32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include "DolphinQt/Config/ARCodeWidget.h" #include "DolphinQt/Config/ARCodeWidget.h"
#include <algorithm>
#include <utility> #include <utility>
#include <QCursor> #include <QCursor>
@ -113,6 +114,8 @@ void ARCodeWidget::OnContextMenuRequested()
QMenu menu; QMenu menu;
menu.addAction(tr("Sort Alphabetically"), this, &ARCodeWidget::SortAlphabetically); 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()); menu.exec(QCursor::pos());
} }
@ -123,6 +126,26 @@ void ARCodeWidget::SortAlphabetically()
OnListReordered(); 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() void ARCodeWidget::OnListReordered()
{ {
// Reorder codes based on the indices of table item // Reorder codes based on the indices of table item

View File

@ -43,6 +43,8 @@ private:
void UpdateList(); void UpdateList();
void SaveCodes(); void SaveCodes();
void SortAlphabetically(); void SortAlphabetically();
void SortEnabledCodesFirst();
void SortDisabledCodesFirst();
void OnCodeAddClicked(); void OnCodeAddClicked();
void OnCodeEditClicked(); void OnCodeEditClicked();

View File

@ -3,6 +3,7 @@
#include "DolphinQt/Config/GeckoCodeWidget.h" #include "DolphinQt/Config/GeckoCodeWidget.h"
#include <algorithm>
#include <utility> #include <utility>
#include <QCursor> #include <QCursor>
@ -257,6 +258,8 @@ void GeckoCodeWidget::OnContextMenuRequested()
QMenu menu; QMenu menu;
menu.addAction(tr("Sort Alphabetically"), this, &GeckoCodeWidget::SortAlphabetically); 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()); menu.exec(QCursor::pos());
} }
@ -267,6 +270,26 @@ void GeckoCodeWidget::SortAlphabetically()
OnListReordered(); 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() void GeckoCodeWidget::OnListReordered()
{ {
// Reorder codes based on the indices of table item // Reorder codes based on the indices of table item

View File

@ -48,6 +48,8 @@ private:
void DownloadCodes(); void DownloadCodes();
void SaveCodes(); void SaveCodes();
void SortAlphabetically(); void SortAlphabetically();
void SortEnabledCodesFirst();
void SortDisabledCodesFirst();
std::string m_game_id; std::string m_game_id;
std::string m_gametdb_id; std::string m_gametdb_id;