From 4b2dad074aace0f54e608110d3defcdc173bb470 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 15 Oct 2023 18:35:12 +0200 Subject: [PATCH] DolphinQt: Move GraphicsModListWidget::ClearLayoutRecursively() to QtUtils. --- Source/Core/DolphinQt/CMakeLists.txt | 2 ++ .../Config/GraphicsModListWidget.cpp | 26 +-------------- .../DolphinQt/Config/GraphicsModListWidget.h | 2 -- Source/Core/DolphinQt/DolphinQt.vcxproj | 2 ++ .../QtUtils/ClearLayoutRecursively.cpp | 33 +++++++++++++++++++ .../QtUtils/ClearLayoutRecursively.h | 8 +++++ 6 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 Source/Core/DolphinQt/QtUtils/ClearLayoutRecursively.cpp create mode 100644 Source/Core/DolphinQt/QtUtils/ClearLayoutRecursively.h diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index 4079d3db94..87fc14c766 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -279,6 +279,8 @@ add_executable(dolphin-emu QtUtils/AspectRatioWidget.h QtUtils/BlockUserInputFilter.cpp QtUtils/BlockUserInputFilter.h + QtUtils/ClearLayoutRecursively.cpp + QtUtils/ClearLayoutRecursively.h QtUtils/DolphinFileDialog.cpp QtUtils/DolphinFileDialog.h QtUtils/DoubleClickEventFilter.cpp diff --git a/Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp b/Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp index 8af40e8c04..c497ff82ed 100644 --- a/Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp +++ b/Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp @@ -19,6 +19,7 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" #include "DolphinQt/Config/GraphicsModWarningWidget.h" +#include "DolphinQt/QtUtils/ClearLayoutRecursively.h" #include "DolphinQt/Settings.h" #include "UICommon/GameFile.h" #include "VideoCommon/GraphicsModSystem/Config/GraphicsMod.h" @@ -240,31 +241,6 @@ void GraphicsModListWidget::SaveModList() m_needs_save = true; } -void GraphicsModListWidget::ClearLayoutRecursively(QLayout* layout) -{ - while (QLayoutItem* child = layout->takeAt(0)) - { - if (child == nullptr) - continue; - - if (child->widget()) - { - layout->removeWidget(child->widget()); - delete child->widget(); - } - else if (child->layout()) - { - ClearLayoutRecursively(child->layout()); - layout->removeItem(child); - } - else - { - layout->removeItem(child); - } - delete child; - } -} - void GraphicsModListWidget::SaveToDisk() { m_needs_save = false; diff --git a/Source/Core/DolphinQt/Config/GraphicsModListWidget.h b/Source/Core/DolphinQt/Config/GraphicsModListWidget.h index 970a160980..7b32792cff 100644 --- a/Source/Core/DolphinQt/Config/GraphicsModListWidget.h +++ b/Source/Core/DolphinQt/Config/GraphicsModListWidget.h @@ -56,8 +56,6 @@ private: void SaveModList(); - void ClearLayoutRecursively(QLayout* layout); - void OpenGraphicsModDir(); void CalculateGameRunning(Core::State state); diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index 4ac411b410..f73ea5c1cc 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -181,6 +181,7 @@ + @@ -240,6 +241,7 @@ + diff --git a/Source/Core/DolphinQt/QtUtils/ClearLayoutRecursively.cpp b/Source/Core/DolphinQt/QtUtils/ClearLayoutRecursively.cpp new file mode 100644 index 0000000000..b7e588d01b --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/ClearLayoutRecursively.cpp @@ -0,0 +1,33 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "DolphinQt/QtUtils/ClearLayoutRecursively.h" + +#include +#include +#include + +void ClearLayoutRecursively(QLayout* layout) +{ + while (QLayoutItem* child = layout->takeAt(0)) + { + if (child == nullptr) + continue; + + if (child->widget()) + { + layout->removeWidget(child->widget()); + delete child->widget(); + } + else if (child->layout()) + { + ClearLayoutRecursively(child->layout()); + layout->removeItem(child); + } + else + { + layout->removeItem(child); + } + delete child; + } +} diff --git a/Source/Core/DolphinQt/QtUtils/ClearLayoutRecursively.h b/Source/Core/DolphinQt/QtUtils/ClearLayoutRecursively.h new file mode 100644 index 0000000000..71fa07e712 --- /dev/null +++ b/Source/Core/DolphinQt/QtUtils/ClearLayoutRecursively.h @@ -0,0 +1,8 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +class QLayout; + +void ClearLayoutRecursively(QLayout* layout);