From 31884eab4b4a24024c868a905458a21b9cf97e9e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 20 Jun 2022 19:45:36 +0300 Subject: [PATCH 21/21] Qt: Fix citydlg happiness layout memory leak See osdn #44885 Signed-off-by: Marko Lindqvist --- client/gui-qt/citydlg.cpp | 16 +++++++++++----- client/gui-qt/citydlg.h | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/client/gui-qt/citydlg.cpp b/client/gui-qt/citydlg.cpp index 2a349c76d2..47339160fc 100644 --- a/client/gui-qt/citydlg.cpp +++ b/client/gui-qt/citydlg.cpp @@ -1480,7 +1480,7 @@ city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent) small_font = fc_font::instance()->get_font(fonts::city_label); zoom = 1.0; - happines_shown = false; + happiness_shown = false; central_splitter = new QSplitter; central_splitter->setOpaqueResize(false); central_left_splitter = new QSplitter; @@ -2041,7 +2041,7 @@ void city_dialog::change_production(bool next) ****************************************************************************/ void city_dialog::update_happiness_button() { - if (happines_shown) { + if (happiness_shown) { happiness_button->setToolTip(_("Show city production")); } else { happiness_button->setToolTip(_("Show happiness information")); @@ -2055,7 +2055,7 @@ void city_dialog::show_happiness() { setUpdatesEnabled(false); - if (!happines_shown) { + if (!happiness_shown) { leftbot_layout->replaceWidget(prod_unit_splitter, happiness_widget, Qt::FindDirectChildrenOnly); @@ -2073,11 +2073,10 @@ void city_dialog::show_happiness() setUpdatesEnabled(true); update(); - happines_shown = !happines_shown; + happiness_shown = !happiness_shown; update_happiness_button(); } - /**************************************************************************** Updates buttons/widgets which should be enabled/disabled ****************************************************************************/ @@ -2160,6 +2159,13 @@ city_dialog::~city_dialog() supported_units->clear_layout(); removeEventFilter(this); ::city_dlg_created = false; + + // Delete the one widget that currently does NOT have a parent + if (happiness_shown) { + delete prod_unit_splitter; + } else { + delete happiness_widget; + } } /**************************************************************************** diff --git a/client/gui-qt/citydlg.h b/client/gui-qt/citydlg.h index 6807085140..70095de441 100644 --- a/client/gui-qt/citydlg.h +++ b/client/gui-qt/citydlg.h @@ -425,10 +425,9 @@ protected: ****************************************************************************/ class city_dialog: public qfc_dialog { - Q_OBJECT - bool happines_shown; + bool happiness_shown; QHBoxLayout *single_page_layout; QHBoxLayout *happiness_layout; QSplitter *prod_unit_splitter; -- 2.35.1