yuzu/configure_input: Make CallConfigureDialog a non-member template function

This doesn't depend on any part of the private interface, so it can be
made a non-member internal function.
This commit is contained in:
Lioncash 2018-11-27 05:14:59 -05:00
parent 11cf13a6e1
commit 0782d3971b
3 changed files with 20 additions and 21 deletions

View file

@ -20,6 +20,19 @@
#include "yuzu/configuration/configure_input_player.h" #include "yuzu/configuration/configure_input_player.h"
#include "yuzu/configuration/configure_mouse_advanced.h" #include "yuzu/configuration/configure_mouse_advanced.h"
namespace {
template <typename Dialog, typename... Args>
void CallConfigureDialog(ConfigureInput& parent, Args&&... args) {
parent.applyConfiguration();
Dialog dialog(&parent, std::forward<Args>(args)...);
const auto res = dialog.exec();
if (res == QDialog::Accepted) {
dialog.applyConfiguration();
}
}
} // Anonymous namespace
ConfigureInput::ConfigureInput(QWidget* parent) ConfigureInput::ConfigureInput(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) { : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) {
ui->setupUi(this); ui->setupUi(this);
@ -59,31 +72,20 @@ ConfigureInput::ConfigureInput(QWidget* parent)
for (std::size_t i = 0; i < players_configure.size(); ++i) { for (std::size_t i = 0; i < players_configure.size(); ++i) {
connect(players_configure[i], &QPushButton::pressed, this, connect(players_configure[i], &QPushButton::pressed, this,
[this, i]() { CallConfigureDialog<ConfigureInputPlayer>(i, false); }); [this, i] { CallConfigureDialog<ConfigureInputPlayer>(*this, i, false); });
} }
connect(ui->handheld_configure, &QPushButton::pressed, this, connect(ui->handheld_configure, &QPushButton::pressed, this,
[this]() { CallConfigureDialog<ConfigureInputPlayer>(8, false); }); [this] { CallConfigureDialog<ConfigureInputPlayer>(*this, 8, false); });
connect(ui->debug_configure, &QPushButton::pressed, this, connect(ui->debug_configure, &QPushButton::pressed, this,
[this]() { CallConfigureDialog<ConfigureInputPlayer>(9, true); }); [this] { CallConfigureDialog<ConfigureInputPlayer>(*this, 9, true); });
connect(ui->mouse_advanced, &QPushButton::pressed, this, connect(ui->mouse_advanced, &QPushButton::pressed, this,
[this]() { CallConfigureDialog<ConfigureMouseAdvanced>(); }); [this] { CallConfigureDialog<ConfigureMouseAdvanced>(*this); });
connect(ui->touchscreen_advanced, &QPushButton::pressed, this, connect(ui->touchscreen_advanced, &QPushButton::pressed, this,
[this]() { CallConfigureDialog<ConfigureTouchscreenAdvanced>(); }); [this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); });
}
template <typename Dialog, typename... Args>
void ConfigureInput::CallConfigureDialog(Args&&... args) {
this->applyConfiguration();
Dialog dialog(this, std::forward<Args>(args)...);
const auto res = dialog.exec();
if (res == QDialog::Accepted) {
dialog.applyConfiguration();
}
} }
void ConfigureInput::OnDockedModeChanged(bool last_state, bool new_state) { void ConfigureInput::OnDockedModeChanged(bool last_state, bool new_state) {

View file

@ -32,9 +32,6 @@ public:
private: private:
void updateUIEnabled(); void updateUIEnabled();
template <typename Dialog, typename... Args>
void CallConfigureDialog(Args&&... args);
void OnDockedModeChanged(bool last_state, bool new_state); void OnDockedModeChanged(bool last_state, bool new_state);
/// Load configuration settings. /// Load configuration settings.

View file

@ -4,11 +4,11 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <utility>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QMessageBox>
#include <QTimer> #include <QTimer>
#include "common/assert.h" #include "common/assert.h"
#include "common/param_package.h" #include "common/param_package.h"
#include "input_common/main.h" #include "input_common/main.h"