Config/ARCodeWidget: Add option for alphabetical sorting

This commit is contained in:
spycrab 2019-06-21 09:28:32 +02:00
parent 1d43d9afc1
commit 396546f5c0
2 changed files with 24 additions and 0 deletions

View File

@ -5,8 +5,10 @@
#include "DolphinQt/Config/ARCodeWidget.h"
#include <QButtonGroup>
#include <QCursor>
#include <QHBoxLayout>
#include <QListWidget>
#include <QMenu>
#include <QPushButton>
#include <QVBoxLayout>
@ -49,6 +51,8 @@ void ARCodeWidget::CreateWidgets()
m_code_edit = new QPushButton(tr("&Edit Code..."));
m_code_remove = new QPushButton(tr("&Remove Code"));
m_code_list->setContextMenuPolicy(Qt::CustomContextMenu);
auto* button_layout = new QHBoxLayout;
button_layout->addWidget(m_code_add);
@ -68,10 +72,13 @@ void ARCodeWidget::ConnectWidgets()
{
connect(m_warning, &CheatWarningWidget::OpenCheatEnableSettings, this,
&ARCodeWidget::OpenGeneralSettings);
connect(m_code_list, &QListWidget::itemChanged, this, &ARCodeWidget::OnItemChanged);
connect(m_code_list, &QListWidget::itemSelectionChanged, this, &ARCodeWidget::OnSelectionChanged);
connect(m_code_list->model(), &QAbstractItemModel::rowsMoved, this,
&ARCodeWidget::OnListReordered);
connect(m_code_list, &QListWidget::customContextMenuRequested, this,
&ARCodeWidget::OnContextMenuRequested);
connect(m_code_add, &QPushButton::pressed, this, &ARCodeWidget::OnCodeAddPressed);
connect(m_code_edit, &QPushButton::pressed, this, &ARCodeWidget::OnCodeEditPressed);
@ -89,6 +96,21 @@ void ARCodeWidget::OnItemChanged(QListWidgetItem* item)
SaveCodes();
}
void ARCodeWidget::OnContextMenuRequested()
{
QMenu menu;
menu.addAction(tr("Sort Alphabetically"), this, &ARCodeWidget::SortAlphabetically);
menu.exec(QCursor::pos());
}
void ARCodeWidget::SortAlphabetically()
{
m_code_list->sortItems();
OnListReordered();
}
void ARCodeWidget::OnListReordered()
{
// Reorder codes based on the indices of table item

View File

@ -37,11 +37,13 @@ signals:
private:
void OnSelectionChanged();
void OnItemChanged(QListWidgetItem* item);
void OnContextMenuRequested();
void CreateWidgets();
void ConnectWidgets();
void UpdateList();
void SaveCodes();
void SortAlphabetically();
void OnCodeAddPressed();
void OnCodeEditPressed();