From 04bc0726278a927edd5a5678f15516739f96fd7e Mon Sep 17 00:00:00 2001 From: tygyh Date: Fri, 15 Nov 2024 09:15:06 +0100 Subject: [PATCH] Move variables to inner scope --- .../DolphinQt/Config/Graphics/EnhancementsWidget.cpp | 4 ++-- Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp | 2 +- Source/Core/DolphinQt/Debugger/CodeWidget.cpp | 2 +- Source/Core/DolphinQt/GameList/GameList.cpp | 12 +++++------- Source/Core/DolphinQt/GameList/GameListModel.cpp | 3 +-- Source/Core/DolphinQt/HotkeyScheduler.cpp | 5 ++--- Source/Core/DolphinQt/RenderWidget.cpp | 3 +-- 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp index 7cf67ab39a..ef2c365fa5 100644 --- a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp @@ -332,9 +332,9 @@ void EnhancementsWidget::LoadPPShaders(StereoMode stereo_mode) tr("%1 doesn't support this feature.") .arg(tr(g_video_backend->GetDisplayName().c_str()))); - VideoCommon::PostProcessingConfiguration pp_shader; if (selected_shader != "" && supports_postprocessing) { + VideoCommon::PostProcessingConfiguration pp_shader; pp_shader.LoadShader(selected_shader); m_configure_pp_effect->setEnabled(pp_shader.HasOptions()); } @@ -513,9 +513,9 @@ void EnhancementsWidget::SaveSettings() "" : m_pp_effect->currentText().toStdString()); - VideoCommon::PostProcessingConfiguration pp_shader; if (Config::Get(Config::GFX_ENHANCE_POST_SHADER) != "") { + VideoCommon::PostProcessingConfiguration pp_shader; pp_shader.LoadShader(Config::Get(Config::GFX_ENHANCE_POST_SHADER)); m_configure_pp_effect->setEnabled(pp_shader.HasOptions()); } diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index 792d78d9b0..be88f99913 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -71,10 +71,10 @@ private: painter->setClipRect(option.rect); painter->setPen(m_parent->palette().text().color()); - constexpr u32 x_offset_in_branch_for_vertical_line = 10; const u32 addr = m_parent->AddressForRow(index.row()); for (const CodeViewBranch& branch : m_parent->m_branches) { + constexpr u32 x_offset_in_branch_for_vertical_line = 10; const int y_center = option.rect.top() + option.rect.height() / 2; const int x_left = option.rect.left() + WIDTH_PER_BRANCH_ARROW * branch.indentation; const int x_right = x_left + x_offset_in_branch_for_vertical_line; diff --git a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp index c36f8c31d7..76a7bc1478 100644 --- a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp @@ -519,8 +519,8 @@ void CodeWidget::StepOut() clock::time_point timeout = clock::now() + std::chrono::seconds(5); auto& power_pc = m_system.GetPowerPC(); - auto& ppc_state = power_pc.GetPPCState(); { + auto& ppc_state = power_pc.GetPPCState(); Core::CPUThreadGuard guard(m_system); PowerPC::CoreMode old_mode = power_pc.GetMode(); diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index 64e9ae6774..51960863b2 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -186,12 +186,11 @@ void GameList::MakeListView() if (!Settings::GetQSettings().contains(QStringLiteral("tableheader/state"))) m_list->sortByColumn(static_cast(GameListModel::Column::Title), Qt::AscendingOrder); - - const auto SetResizeMode = [&hor_header](const GameListModel::Column column, - const QHeaderView::ResizeMode mode) { - hor_header->setSectionResizeMode(static_cast(column), mode); - }; { + const auto SetResizeMode = [&hor_header](const GameListModel::Column column, + const QHeaderView::ResizeMode mode) { + hor_header->setSectionResizeMode(static_cast(column), mode); + }; using Column = GameListModel::Column; using Mode = QHeaderView::ResizeMode; SetResizeMode(Column::Platform, Mode::Fixed); @@ -1021,8 +1020,6 @@ void GameList::OnSectionResized(int index, int, int) { auto* hor_header = m_list->horizontalHeader(); - std::vector sections; - const int vis_index = hor_header->visualIndex(index); const int col_count = hor_header->count() - hor_header->hiddenSectionCount(); @@ -1040,6 +1037,7 @@ void GameList::OnSectionResized(int index, int, int) if (!last) { + std::vector sections; for (int i = 0; i < vis_index; i++) { const int logical_index = hor_header->logicalIndex(i); diff --git a/Source/Core/DolphinQt/GameList/GameListModel.cpp b/Source/Core/DolphinQt/GameList/GameListModel.cpp index c70a870c23..c64de13b03 100644 --- a/Source/Core/DolphinQt/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt/GameList/GameListModel.cpp @@ -106,13 +106,12 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const // For natural sorting, pad all numbers to the same length. if (SORT_ROLE == role) { - constexpr int MAX_NUMBER_LENGTH = 10; - const QRegularExpression rx(QStringLiteral("\\d+")); QRegularExpressionMatch match; int pos = 0; while ((match = rx.match(name, pos)).hasMatch()) { + constexpr int MAX_NUMBER_LENGTH = 10; pos = match.capturedStart(); name.replace(pos, match.capturedLength(), match.captured().rightJustified(MAX_NUMBER_LENGTH)); diff --git a/Source/Core/DolphinQt/HotkeyScheduler.cpp b/Source/Core/DolphinQt/HotkeyScheduler.cpp index a35d96f388..19d4e5d0f6 100644 --- a/Source/Core/DolphinQt/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt/HotkeyScheduler.cpp @@ -80,9 +80,6 @@ static bool IsHotkey(int id, bool held = false) static void HandleFrameStepHotkeys() { - constexpr int MAX_FRAME_STEP_DELAY = 60; - constexpr int FRAME_STEP_DELAY = 30; - static int frame_step_count = 0; static int frame_step_delay = 1; static int frame_step_delay_count = 0; @@ -96,6 +93,7 @@ static void HandleFrameStepHotkeys() if (IsHotkey(HK_FRAME_ADVANCE_DECREASE_SPEED)) { + constexpr int MAX_FRAME_STEP_DELAY = 60; frame_step_delay = std::min(frame_step_delay + 1, MAX_FRAME_STEP_DELAY); return; } @@ -108,6 +106,7 @@ static void HandleFrameStepHotkeys() if (IsHotkey(HK_FRAME_ADVANCE, true)) { + constexpr int FRAME_STEP_DELAY = 30; if (frame_step_delay_count < frame_step_delay && frame_step_hold) frame_step_delay_count++; diff --git a/Source/Core/DolphinQt/RenderWidget.cpp b/Source/Core/DolphinQt/RenderWidget.cpp index d88a17e3d3..4f0c399ed2 100644 --- a/Source/Core/DolphinQt/RenderWidget.cpp +++ b/Source/Core/DolphinQt/RenderWidget.cpp @@ -530,11 +530,10 @@ void RenderWidget::PassEventToPresenter(const QEvent* event) const u32 key = static_cast(key_event->key() & 0x1FF); const char* chars = nullptr; - QByteArray utf8; if (is_down) { - utf8 = key_event->text().toUtf8(); + QByteArray utf8 = key_event->text().toUtf8(); if (utf8.size()) chars = utf8.constData();