From 386c7fd50d4e50c83a4401443e5bbd6436a51424 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Wed, 20 Jul 2022 18:38:45 +0200 Subject: [PATCH 1/4] Clarify code in is_server_running() --- client/connectdlg_common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/connectdlg_common.cpp b/client/connectdlg_common.cpp index 71e7512d1c..f2974206db 100644 --- a/client/connectdlg_common.cpp +++ b/client/connectdlg_common.cpp @@ -130,7 +130,7 @@ bool is_server_running() if (server_quitting) { return false; } - return serverProcess::i()->state(); + return serverProcess::i()->state() > QProcess::NotRunning; } /** From f59a2b80eb51111b1630e06c20d850cf2eccf8a1 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Wed, 20 Jul 2022 18:39:38 +0200 Subject: [PATCH 2/4] Remove unused parameter in page_load::state_preview --- client/page_load.cpp | 10 ++++------ client/page_load.h | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/client/page_load.cpp b/client/page_load.cpp index ea236ab0f7..57853edfc4 100644 --- a/client/page_load.cpp +++ b/client/page_load.cpp @@ -174,17 +174,15 @@ void page_load::browse_saves() /** State of preview has been changed */ -void page_load::state_preview(int new_state) +void page_load::state_preview() { - Q_UNUSED(new_state) - QItemSelection slctn; - gui_options.gui_qt_show_preview = ui.show_preview->checkState() != Qt::Unchecked; - slctn = ui.saves_load->selectionModel()->selection(); + auto selection = ui.saves_load->selectionModel()->selection(); ui.saves_load->selectionModel()->clearSelection(); ui.saves_load->selectionModel()->select( - slctn, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent); + selection, + QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent); } void page_load::slot_selection_changed(const QItemSelection &selected, diff --git a/client/page_load.h b/client/page_load.h index 844d5f80ef..5797065d54 100644 --- a/client/page_load.h +++ b/client/page_load.h @@ -25,7 +25,7 @@ class page_load : public QWidget { private slots: void slot_selection_changed(const QItemSelection &, const QItemSelection &); - void state_preview(int); + void state_preview(); void browse_saves(); private: From 824e67db9326870a4dd267c16ec7338e16f63346 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Thu, 21 Jul 2022 18:11:13 +0200 Subject: [PATCH 3/4] Merge all functions that pop down the city overlay There were three functions that all did the same thing. Simplify the API by merging them. --- client/citydlg.cpp | 26 +++++--------------------- client/client_main.cpp | 6 +++--- client/climisc.cpp | 5 ++++- client/mapview.cpp | 2 +- client/packhand.cpp | 2 +- client/qtg_cxxside.h | 3 +-- client/top_bar.cpp | 2 +- 7 files changed, 16 insertions(+), 30 deletions(-) diff --git a/client/citydlg.cpp b/client/citydlg.cpp index 0502b21dca..523b87f46d 100644 --- a/client/citydlg.cpp +++ b/client/citydlg.cpp @@ -806,7 +806,7 @@ void unit_list_item::activate_and_close_dialog() if (can_issue_orders()) { unit_focus_set(m_unit); queen()->city_overlay->dont_focus = true; - popdown_all_city_dialogs(); + popdown_city_dialog(); } } @@ -2074,7 +2074,7 @@ void city_dialog::refresh() update_cma_tab(); update_disabled(); } else { - destroy_city_dialog(); + popdown_city_dialog(); } update_map_canvas_visible(); @@ -2799,31 +2799,15 @@ void real_city_dialog_popup(struct city *pcity) } /** - Closes city dialog + * Closes the city overlay. */ -void destroy_city_dialog() +void popdown_city_dialog() { - // Only tyrans destroy cities instead building - if (king()->current_page() >= PAGE_GAME) { + if (queen()) { queen()->city_overlay->hide(); } } -/** - Close the dialog for the given city. - */ -void popdown_city_dialog(struct city *pcity) -{ - Q_UNUSED(pcity) - - popdown_all_city_dialogs(); // We only ever have one city dialog -} - -/** - Close the dialogs for all cities. - */ -void popdown_all_city_dialogs() { queen()->city_overlay->hide(); } - /** Refresh (update) all data for the given city's dialog. */ diff --git a/client/client_main.cpp b/client/client_main.cpp index 1bd1525986..93e998e4ed 100644 --- a/client/client_main.cpp +++ b/client/client_main.cpp @@ -798,7 +798,7 @@ void set_client_state(enum client_states newstate) break; case C_S_DISCONNECTED: - popdown_all_city_dialogs(); + popdown_city_dialog(); close_all_diplomacy_dialogs(); popdown_all_game_dialogs(); meswin_clear_older(MESWIN_CLEAR_ALL, 0); @@ -818,7 +818,7 @@ void set_client_state(enum client_states newstate) break; case C_S_PREPARING: - popdown_all_city_dialogs(); + popdown_city_dialog(); close_all_diplomacy_dialogs(); popdown_all_game_dialogs(); meswin_clear_older(MESWIN_CLEAR_ALL, 0); @@ -892,7 +892,7 @@ void set_client_state(enum client_states newstate) } city_list_iterate_end; } - popdown_all_city_dialogs(); + popdown_city_dialog(); close_all_diplomacy_dialogs(); popdown_all_game_dialogs(); unit_focus_set(nullptr); diff --git a/client/climisc.cpp b/client/climisc.cpp index b273156745..878d08f81b 100644 --- a/client/climisc.cpp +++ b/client/climisc.cpp @@ -154,7 +154,10 @@ void client_remove_city(struct city *pcity) // nothing yet } - popdown_city_dialog(pcity); + if (auto dialog = is_any_city_dialog_open(); + dialog && pcity->id == dialog->id) { + popdown_city_dialog(); + } game_remove_city(&wld, pcity); city_report_dialog_update(); refresh_city_mapcanvas(&old_city, ptile, true, false); diff --git a/client/mapview.cpp b/client/mapview.cpp index acff3ca816..6cc576acf1 100644 --- a/client/mapview.cpp +++ b/client/mapview.cpp @@ -617,7 +617,7 @@ void tileset_changed(void) } update_unit_info_label(get_units_in_focus()); - destroy_city_dialog(); + popdown_city_dialog(); // Update science report if open if (queen()->isRepoDlgOpen(QStringLiteral("SCI"))) { i = queen()->gimmeIndexOf(QStringLiteral("SCI")); diff --git a/client/packhand.cpp b/client/packhand.cpp index 7154491ac0..5860371b00 100644 --- a/client/packhand.cpp +++ b/client/packhand.cpp @@ -2097,7 +2097,7 @@ void handle_game_info(const struct packet_game_info *pinfo) } if (game.info.is_edit_mode != pinfo->is_edit_mode) { - popdown_all_city_dialogs(); + popdown_city_dialog(); // Clears the current goto command. clear_hover_state(); diff --git a/client/qtg_cxxside.h b/client/qtg_cxxside.h index 13f45bcd4b..1f9b43a749 100644 --- a/client/qtg_cxxside.h +++ b/client/qtg_cxxside.h @@ -48,8 +48,7 @@ void editgui_popdown_all(); void start_turn(); void real_city_dialog_popup(struct city *pcity); void real_city_dialog_refresh(struct city *pcity); -void popdown_city_dialog(struct city *pcity); -void popdown_all_city_dialogs(); +void popdown_city_dialog(); bool handmade_scenario_warning(); void refresh_unit_city_dialogs(struct unit *punit); bool city_dialog_is_open(struct city *pcity); diff --git a/client/top_bar.cpp b/client/top_bar.cpp index c56ca2d9cb..7c11636147 100644 --- a/client/top_bar.cpp +++ b/client/top_bar.cpp @@ -453,7 +453,7 @@ void top_bar::addWidget(QWidget *fsw) */ void top_bar_show_map() { - popdown_all_city_dialogs(); + popdown_city_dialog(); queen()->game_tab_widget->setCurrentIndex(0); } From 6e00a03b44e33071bdae0811662c950a6c3e8dc5 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Fri, 22 Jul 2022 15:27:32 +0200 Subject: [PATCH 4/4] Remove useless queen() calls We were using queen()->mapview even from *inside* the map_view class. Nonsense... --- client/mapctrl.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/client/mapctrl.cpp b/client/mapctrl.cpp index b54cb89f01..c39afbe418 100644 --- a/client/mapctrl.cpp +++ b/client/mapctrl.cpp @@ -98,8 +98,6 @@ void map_view::keyPressEvent(QKeyEvent *event) Qt::KeyboardModifiers key_mod = QApplication::keyboardModifiers(); bool is_shift = key_mod.testFlag(Qt::ShiftModifier); - auto scale = queen()->mapview_wdg->scale(); - if (C_S_RUNNING == client_state()) { if (is_shift) { switch (event->key()) { @@ -116,8 +114,7 @@ void map_view::keyPressEvent(QKeyEvent *event) case Qt::Key_Up: case Qt::Key_8: if (is_shift) { - recenter_button_pressed(queen()->mapview_wdg->width() / 2 / scale, - 0); + recenter_button_pressed(width() / 2 / scale(), 0); } else { key_unit_move(DIR8_NORTH); } @@ -125,8 +122,7 @@ void map_view::keyPressEvent(QKeyEvent *event) case Qt::Key_Left: case Qt::Key_4: if (is_shift) { - recenter_button_pressed(0, - queen()->mapview_wdg->height() / 2 / scale); + recenter_button_pressed(0, height() / 2 / scale()); } else { key_unit_move(DIR8_WEST); } @@ -134,8 +130,7 @@ void map_view::keyPressEvent(QKeyEvent *event) case Qt::Key_Right: case Qt::Key_6: if (is_shift) { - recenter_button_pressed(queen()->mapview_wdg->width() / scale, - queen()->mapview_wdg->height() / 2 / scale); + recenter_button_pressed(width() / scale(), height() / 2 / scale()); } else { key_unit_move(DIR8_EAST); } @@ -143,8 +138,7 @@ void map_view::keyPressEvent(QKeyEvent *event) case Qt::Key_Down: case Qt::Key_2: if (is_shift) { - recenter_button_pressed(queen()->mapview_wdg->width() / 2 / scale, - queen()->mapview_wdg->height() / scale); + recenter_button_pressed(width() / 2 / scale(), height() / scale()); } else { key_unit_move(DIR8_SOUTH); }