Skip to content
Permalink
Browse files

Config/ARCodeWidget: Add option for alphabetical sorting

  • Loading branch information...
spycrab committed Jun 21, 2019
1 parent 1d43d9a commit 396546f5c056eda8fb01ba15ef300da17c9869f0
Showing with 24 additions and 0 deletions.
  1. +22 −0 Source/Core/DolphinQt/Config/ARCodeWidget.cpp
  2. +2 −0 Source/Core/DolphinQt/Config/ARCodeWidget.h
@@ -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
@@ -37,11 +37,13 @@ class ARCodeWidget : public QWidget
private:
void OnSelectionChanged();
void OnItemChanged(QListWidgetItem* item);
void OnContextMenuRequested();

void CreateWidgets();
void ConnectWidgets();
void UpdateList();
void SaveCodes();
void SortAlphabetically();

void OnCodeAddPressed();
void OnCodeEditPressed();

0 comments on commit 396546f

Please sign in to comment.
You can’t perform that action at this time.