From 3039211c205e8d065695f7bc681cc3a44933de2f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 May 2019 12:31:47 -0400 Subject: yuzu/configuration/configure_mouse_advanced: Clean up array accesses Deduplicates array accesses and uses a named variable where appropriate. --- .../configuration/configure_mouse_advanced.cpp | 41 ++++++++++++---------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/yuzu/configuration/configure_mouse_advanced.cpp b/src/yuzu/configuration/configure_mouse_advanced.cpp index ba5992f9f..a14bb1475 100644 --- a/src/yuzu/configuration/configure_mouse_advanced.cpp +++ b/src/yuzu/configuration/configure_mouse_advanced.cpp @@ -77,30 +77,31 @@ ConfigureMouseAdvanced::ConfigureMouseAdvanced(QWidget* parent) }; for (int button_id = 0; button_id < Settings::NativeMouseButton::NumMouseButtons; button_id++) { - if (!button_map[button_id]) + auto* const button = button_map[button_id]; + if (button == nullptr) { continue; - button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); - connect(button_map[button_id], &QPushButton::released, [=]() { + } + + button->setContextMenuPolicy(Qt::CustomContextMenu); + connect(button, &QPushButton::released, [=] { handleClick( button_map[button_id], [=](const Common::ParamPackage& params) { buttons_param[button_id] = params; }, InputCommon::Polling::DeviceType::Button); }); - connect(button_map[button_id], &QPushButton::customContextMenuRequested, - [=](const QPoint& menu_location) { - QMenu context_menu; - context_menu.addAction(tr("Clear"), [&] { - buttons_param[button_id].Clear(); - button_map[button_id]->setText(tr("[not set]")); - }); - context_menu.addAction(tr("Restore Default"), [&] { - buttons_param[button_id] = - Common::ParamPackage{InputCommon::GenerateKeyboardParam( - Config::default_mouse_buttons[button_id])}; - button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); - }); - context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); - }); + connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { + QMenu context_menu; + context_menu.addAction(tr("Clear"), [&] { + buttons_param[button_id].Clear(); + button_map[button_id]->setText(tr("[not set]")); + }); + context_menu.addAction(tr("Restore Default"), [&] { + buttons_param[button_id] = Common::ParamPackage{ + InputCommon::GenerateKeyboardParam(Config::default_mouse_buttons[button_id])}; + button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); + }); + context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); + }); } connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); }); @@ -150,8 +151,10 @@ void ConfigureMouseAdvanced::restoreDefaults() { void ConfigureMouseAdvanced::ClearAll() { for (int i = 0; i < Settings::NativeMouseButton::NumMouseButtons; ++i) { - if (button_map[i] && button_map[i]->isEnabled()) + const auto* const button = button_map[i]; + if (button != nullptr && button->isEnabled()) { buttons_param[i].Clear(); + } } updateButtonLabels(); -- cgit v1.2.3