From ea8ad359477e73e14c1f4d89c2e96d0064b28512 Mon Sep 17 00:00:00 2001 From: DanielSvoboda Date: Tue, 10 Dec 2024 13:57:30 -0300 Subject: [PATCH] Fix delete cheats button (#1731) --- src/qt_gui/cheats_patches.cpp | 26 +++++++++++++++++++++++--- src/qt_gui/cheats_patches.h | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/qt_gui/cheats_patches.cpp b/src/qt_gui/cheats_patches.cpp index 446b5a0e..2fea0b6e 100644 --- a/src/qt_gui/cheats_patches.cpp +++ b/src/qt_gui/cheats_patches.cpp @@ -955,15 +955,33 @@ void CheatsPatches::createFilesJson(const QString& repository) { jsonFile.close(); } -void CheatsPatches::addCheatsToLayout(const QJsonArray& modsArray, const QJsonArray& creditsArray) { +void CheatsPatches::clearListCheats() { QLayoutItem* item; while ((item = rightLayout->takeAt(0)) != nullptr) { - delete item->widget(); - delete item; + QWidget* widget = item->widget(); + if (widget) { + delete widget; + } else { + QLayout* layout = item->layout(); + if (layout) { + QLayoutItem* innerItem; + while ((innerItem = layout->takeAt(0)) != nullptr) { + QWidget* innerWidget = innerItem->widget(); + if (innerWidget) { + delete innerWidget; + } + delete innerItem; + } + delete layout; + } + } } m_cheats.clear(); m_cheatCheckBoxes.clear(); +} +void CheatsPatches::addCheatsToLayout(const QJsonArray& modsArray, const QJsonArray& creditsArray) { + clearListCheats(); int maxWidthButton = 0; for (const QJsonValue& modValue : modsArray) { @@ -1056,6 +1074,8 @@ void CheatsPatches::addCheatsToLayout(const QJsonArray& modsArray, const QJsonAr } void CheatsPatches::populateFileListCheats() { + clearListCheats(); + QString cheatsDir; Common::FS::PathToQString(cheatsDir, Common::FS::GetUserPath(Common::FS::PathType::CheatsDir)); diff --git a/src/qt_gui/cheats_patches.h b/src/qt_gui/cheats_patches.h index b07e828c..4217436f 100644 --- a/src/qt_gui/cheats_patches.h +++ b/src/qt_gui/cheats_patches.h @@ -36,6 +36,7 @@ public: const QString& m_gameVersion, bool showMessageBox); void downloadPatches(const QString repository, const bool showMessageBox); void createFilesJson(const QString& repository); + void clearListCheats(); void compatibleVersionNotice(const QString repository); signals: