From 80120f47a86e9028366ee6b5c47eeda0e4e57639 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Thu, 30 May 2024 17:14:20 +0300
Subject: [PATCH 68/68] Qt6x: Avoid using deprecated QCheckBox::stateChanged()

See RM #687

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-qt/chatline.cpp | 27 ++++++++++++++++++++++---
 client/gui-qt/chatline.h   |  3 ++-
 client/gui-qt/citydlg.cpp  | 40 ++++++++++++++++++++++++++++++++++----
 client/gui-qt/citydlg.h    |  3 ++-
 client/gui-qt/fc_client.h  |  3 ++-
 client/gui-qt/gotodlg.cpp  | 23 ++++++++++++++++++++--
 client/gui-qt/gotodlg.h    |  3 ++-
 client/gui-qt/pages.cpp    | 35 ++++++++++++++++++++++++++++++---
 8 files changed, 121 insertions(+), 16 deletions(-)

diff --git a/client/gui-qt/chatline.cpp b/client/gui-qt/chatline.cpp
index 55f1c3bdeb..67062ea765 100644
--- a/client/gui-qt/chatline.cpp
+++ b/client/gui-qt/chatline.cpp
@@ -300,16 +300,37 @@ chatwdg::chatwdg(QWidget *parent)
   connect(chat_output, &text_browser_dblclck::dbl_clicked,
           this, &chatwdg::toggle_size);
   connect(remove_links, &QAbstractButton::clicked, this, &chatwdg::rm_links);
-  connect(cb, &QCheckBox::stateChanged, this, &chatwdg::state_changed);
+#ifdef FC_QT6X_MODE
+#if QT_VERSION >= 0x060700
+  connect(cb, &QCheckBox::checkStateChanged, this, &chatwdg::state_changed);
+#else  // QT >= 6.7
+  connect(cb, &QCheckBox::stateChanged, this, &chatwdg::state_changed_depr);
+#endif // QT >= 6.7
+#else  // FC_QT6X_MODE
+  connect(cb, &QCheckBox::stateChanged, this, &chatwdg::state_changed_depr);
+#endif // FC_QT6X_MODE
   setMouseTracking(true);
 
   chat_listener::listen();
 }
 
 /***********************************************************************//**
-  Manages "To allies" chat button state
+  Manages "To allies" chat button state.
+***************************************************************************/
+void chatwdg::state_changed(Qt::CheckState state)
+{
+  if (state != Qt::Unchecked) {
+    gui_options.gui_qt_allied_chat_only = true;
+  } else {
+    gui_options.gui_qt_allied_chat_only = false;
+  }
+}
+
+/***********************************************************************//**
+  Manages "To allies" chat button state.
+  This deprecated slot is used in Qt < 6.7
 ***************************************************************************/
-void chatwdg::state_changed(int state)
+void chatwdg::state_changed_depr(int state)
 {
   if (state > 0) {
     gui_options.gui_qt_allied_chat_only = true;
diff --git a/client/gui-qt/chatline.h b/client/gui-qt/chatline.h
index 2d7de76359..ff5b7df58e 100644
--- a/client/gui-qt/chatline.h
+++ b/client/gui-qt/chatline.h
@@ -125,7 +125,8 @@ public:
   void scroll_to_bottom();
   void update_font();
 private slots:
-  void state_changed(int state);
+  void state_changed(Qt::CheckState state);
+  void state_changed_depr(int state);
   void rm_links();
   void anchor_clicked(const QUrl &link);
   void toggle_size();
diff --git a/client/gui-qt/citydlg.cpp b/client/gui-qt/citydlg.cpp
index 0e134f6c14..ba7e01590a 100644
--- a/client/gui-qt/citydlg.cpp
+++ b/client/gui-qt/citydlg.cpp
@@ -1936,15 +1936,35 @@ city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent)
     } else if (i == list_size - 2) {
       cma_celeb_checkbox = new QCheckBox;
       slider_grid->addWidget(cma_celeb_checkbox, i + 1, 2 , 1 , 1);
+#ifdef FC_QT6X_MODE
+#if QT_VERSION >= 0x060700
       connect(cma_celeb_checkbox,
-              &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed);
+              &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
+#else  // QT >= 6.7
+      connect(cma_celeb_checkbox,
+              &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
+#endif // QT >= 6.7
+#else  // FC_QT6X_MODE
+      connect(cma_celeb_checkbox,
+              &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
+#endif // FC_QT6X_MODE
     } else {
       fc_assert(i == list_size - 1);
 
       cma_max_growth = new QCheckBox;
       slider_grid->addWidget(cma_max_growth, i + 1, 2 , 1 , 1);
+#ifdef FC_QT6X_MODE
+#if QT_VERSION >= 0x060700
+      connect(cma_max_growth,
+              &QCheckBox::checkStateChanged, this, &city_dialog::cma_toggle_changed);
+#else  // QT >= 6.7
+      connect(cma_max_growth,
+              &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
+#endif // QT >= 6.7
+#else  // FC_QT6X_MODE
       connect(cma_max_growth,
-              &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed);
+              &QCheckBox::stateChanged, this, &city_dialog::cma_toggle_changed_depr);
+#endif // FC_QT6X_MODE
     }
 
     if (i <= list_size - 2) {
@@ -2608,9 +2628,21 @@ void city_dialog::cma_remove()
 }
 
 /************************************************************************//**
-  CMA option 'celebrate' or 'max_growth' QCheckBox state has been changed
+  CMA option 'celebrate' or 'max_growth' QCheckBox state has been changed.
+****************************************************************************/
+void city_dialog::cma_toggle_changed(Qt::CheckState state)
+{
+  if (cma_is_city_under_agent(dlgcity, nullptr)) {
+    cma_changed();
+    update_cma_tab();
+  }
+}
+
+/************************************************************************//**
+  CMA option 'celebrate' or 'max_growth' QCheckBox state has been changed.
+  This deprecated slot is used on Qt < 6.7.
 ****************************************************************************/
-void city_dialog::cma_toggle_changed(int val)
+void city_dialog::cma_toggle_changed_depr(int state)
 {
   if (cma_is_city_under_agent(dlgcity, nullptr)) {
     cma_changed();
diff --git a/client/gui-qt/citydlg.h b/client/gui-qt/citydlg.h
index 158e996392..31a3dda83f 100644
--- a/client/gui-qt/citydlg.h
+++ b/client/gui-qt/citydlg.h
@@ -537,7 +537,8 @@ private slots:
   void display_worklist_menu(const QPoint &p);
   void disband_state_changed(bool allow_disband);
   void cma_slider(int val);
-  void cma_toggle_changed(int val);
+  void cma_toggle_changed(Qt::CheckState state);
+  void cma_toggle_changed_depr(int state);
   void cma_remove();
   void cma_enable();
   void cma_changed();
diff --git a/client/gui-qt/fc_client.h b/client/gui-qt/fc_client.h
index 9e3cb6c322..ba93130a09 100644
--- a/client/gui-qt/fc_client.h
+++ b/client/gui-qt/fc_client.h
@@ -310,7 +310,8 @@ private slots:
   void browse_saves();
   void browse_scenarios();
   void clear_status_bar();
-  void state_preview(int);
+  void state_preview(Qt::CheckState state);
+  void state_preview_depr(int state);
 
 public slots:
   void switch_page(int i);
diff --git a/client/gui-qt/gotodlg.cpp b/client/gui-qt/gotodlg.cpp
index aa3d57e330..ffeeae7b40 100644
--- a/client/gui-qt/gotodlg.cpp
+++ b/client/gui-qt/gotodlg.cpp
@@ -121,8 +121,18 @@ goto_dialog::goto_dialog(QWidget *parent): qfc_dialog(parent)
   connect(close_but, &QAbstractButton::clicked, this, &goto_dialog::close_dlg);
   connect(goto_city, &QAbstractButton::clicked, this, &goto_dialog::go_to_city);
   connect(airlift_city, &QAbstractButton::clicked, this, &goto_dialog::airlift_to);
-  connect(show_all, &QCheckBox::stateChanged,
+#ifdef FC_QT6X_MODE
+#if QT_VERSION >= 0x060700
+  connect(show_all, &QCheckBox::checkStateChanged,
           this, &goto_dialog::checkbox_changed);
+#else  // QT >= 6.7
+  connect(show_all, &QCheckBox::stateChanged,
+          this, &goto_dialog::checkbox_changed_depr);
+#endif // QT >= 6.7
+#else  // FC_QT6X_MODE
+  connect(show_all, &QCheckBox::stateChanged,
+          this, &goto_dialog::checkbox_changed_depr);
+#endif // FC_QT6X_MODE
   connect(goto_tab->selectionModel(),
           SIGNAL(selectionChanged(const QItemSelection &,
                                   const QItemSelection &)),
@@ -155,7 +165,16 @@ goto_dialog::~goto_dialog()
 /***********************************************************************//**
   Slot for checkbox 'all nations'
 ***************************************************************************/
-void goto_dialog::checkbox_changed(int state)
+void goto_dialog::checkbox_changed(Qt::CheckState state)
+{
+  update_dlg();
+}
+
+/***********************************************************************//**
+  Slot for checkbox 'all nations'
+  This deprecated slot is used in Qt < 6.7
+***************************************************************************/
+void goto_dialog::checkbox_changed_depr(int state)
 {
   update_dlg();
 }
diff --git a/client/gui-qt/gotodlg.h b/client/gui-qt/gotodlg.h
index 87564a1eab..2dad9cadca 100644
--- a/client/gui-qt/gotodlg.h
+++ b/client/gui-qt/gotodlg.h
@@ -65,7 +65,8 @@ private slots:
   void go_to_city();
   void airlift_to();
   void item_selected(const QItemSelection &sl, const QItemSelection &ds);
-  void checkbox_changed(int state);
+  void checkbox_changed(Qt::CheckState state);
+  void checkbox_changed_depr(int state);
 protected:
   void paint(QPainter *painter, QPaintEvent *event);
   void paintEvent(QPaintEvent *event);
diff --git a/client/gui-qt/pages.cpp b/client/gui-qt/pages.cpp
index e66d408c73..d7005a8f69 100644
--- a/client/gui-qt/pages.cpp
+++ b/client/gui-qt/pages.cpp
@@ -536,8 +536,18 @@ void fc_client::create_load_page()
   connect(saves_load->selectionModel(),
           &QItemSelectionModel::selectionChanged, this,
           &fc_client::slot_selection_changed);
-  connect(show_preview, &QCheckBox::stateChanged, this,
+#ifdef FC_QT6X_MODE
+#if QT_VERSION >= 0x060700
+  connect(show_preview, &QCheckBox::checkStateChanged, this,
           &fc_client::state_preview);
+#else  // QT >= 6.7
+  connect(show_preview, &QCheckBox::stateChanged, this,
+          &fc_client::state_preview_depr);
+#endif // QT >= 6.7
+#else  // FC_QT6X_MODE
+  connect(show_preview, &QCheckBox::stateChanged, this,
+          &fc_client::state_preview_depr);
+#endif // FC_QT6X_MODE
   pages_layout[PAGE_LOAD]->addWidget(wdg, 1, 0);
   pages_layout[PAGE_LOAD]->addWidget(load_save_text, 2, 0, 1, 2);
   pages_layout[PAGE_LOAD]->addWidget(load_pix, 2, 2, 1, 2);
@@ -841,9 +851,28 @@ void fc_client::browse_saves(void)
 }
 
 /**********************************************************************//**
-  State of preview has been changed
+  State of preview has been changed.
+**************************************************************************/
+void fc_client::state_preview(Qt::CheckState state)
+{
+  QItemSelection slctn;
+
+  if (show_preview->checkState() == Qt::Unchecked) {
+    gui_options.gui_qt_show_preview = false;
+  } else {
+    gui_options.gui_qt_show_preview = true;
+  }
+  slctn = saves_load->selectionModel()->selection();
+  saves_load->selectionModel()->clearSelection();
+  saves_load->selectionModel()->select(slctn, QItemSelectionModel::Rows
+                                       | QItemSelectionModel::SelectCurrent);
+}
+
+/**********************************************************************//**
+  State of preview has been changed.
+  This deprecated slot is used in Qt < 6.7
 **************************************************************************/
-void fc_client::state_preview(int new_state)
+void fc_client::state_preview_depr(int new_state)
 {
   QItemSelection slctn;
 
-- 
2.43.0

