From 0999db4004721f112ee8066a98a602782ff92afd Mon Sep 17 00:00:00 2001 From: Dino Date: Sat, 21 Jun 2025 20:30:01 -0400 Subject: [PATCH] #1530 Qt client, Shortcuts options dialog, fix bug with Reset button --- client/gui-qt/shortcuts.cpp | 59 ++++++++++++++++++++++--------------- client/gui-qt/shortcuts.h | 1 + 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/client/gui-qt/shortcuts.cpp b/client/gui-qt/shortcuts.cpp index 2fdafe6c96..0ad9ce0d9e 100644 --- a/client/gui-qt/shortcuts.cpp +++ b/client/gui-qt/shortcuts.cpp @@ -596,24 +596,18 @@ fc_shortcuts_dialog::~fc_shortcuts_dialog() **************************************************************************/ void fc_shortcuts_dialog::init() { - fc_shortcut *sc; QPushButton *but; QScrollArea *scroll; QSize size; - QString desc; QWidget *widget; - shortcut_id id; widget = new QWidget(this); scroll = new QScrollArea(this); scroll->setWidgetResizable(true); scroll_layout = new QVBoxLayout; + populate_scroll_layout(); + main_layout = new QVBoxLayout; - foreach (sc, fc_shortcuts::sc()->hash) { - id = fc_shortcuts::sc()->get_id(sc); - desc = fc_shortcuts::sc()->get_desc(id); - add_option(sc); - } widget->setProperty("doomed", true); widget->setLayout(scroll_layout); scroll->setWidget(widget); @@ -665,7 +659,23 @@ void fc_shortcuts_dialog::init() } /**********************************************************************//** - Adds shortcut option for dialog + Adds all the shortcut options to the dialog's scroll_layout +**************************************************************************/ +void fc_shortcuts_dialog::populate_scroll_layout() +{ + fc_shortcut *sc; + shortcut_id id; + QString desc; + + foreach (sc, fc_shortcuts::sc()->hash) { + id = fc_shortcuts::sc()->get_id(sc); + desc = fc_shortcuts::sc()->get_desc(id); + add_option(sc); + } +} + +/**********************************************************************//** + Adds a shortcut option to the dialog's scroll_layout **************************************************************************/ void fc_shortcuts_dialog::add_option(fc_shortcut *sc) { @@ -701,23 +711,26 @@ void fc_shortcuts_dialog::edit_shortcut() **************************************************************************/ void fc_shortcuts_dialog::refresh() { - QLayout *layout; - QLayoutItem *item; + QLayoutItem *box_layout_item; + QLayoutItem *row_layout_item; QWidget *widget; - - layout = main_layout; - while ((item = layout->takeAt(0))) { - if (item->layout() != nullptr) { - // Nothing - } else if ((widget = item->widget()) != nullptr) { - widget->hide(); - delete widget; - } else { - delete item; + QLayout *box_layout; // corresponds to one of the hb's in add_option() + + // clear out the scroll_layout + while ((row_layout_item = scroll_layout->takeAt(0)) != nullptr) { + box_layout = row_layout_item->layout(); + while ((box_layout_item = box_layout->takeAt(0)) != nullptr) { + widget = box_layout_item->widget(); + if (widget != nullptr) { // this test may not be needed + delete widget; + } + delete box_layout_item; } + delete row_layout_item; } - delete main_layout; - init(); + + // re-populate the scroll_layout + populate_scroll_layout(); } /**********************************************************************//** diff --git a/client/gui-qt/shortcuts.h b/client/gui-qt/shortcuts.h index 9d02d1c3f6..4661733504 100644 --- a/client/gui-qt/shortcuts.h +++ b/client/gui-qt/shortcuts.h @@ -196,6 +196,7 @@ class fc_shortcuts_dialog : public QDialog QMap *hashcopy; void add_option(fc_shortcut *sc); void init(); + void populate_scroll_layout(); void refresh(); public: fc_shortcuts_dialog(QWidget *parent = 0); -- 2.31.0