diff libgui/src/workspace-view.cc @ 29542:3d34b70b5a49

connect many Qt signals and slots without SIGNAL and SLOT macros This changes switches most code in the libgui/src and libgui/graphics directories to use the new Qt style of connecting signals and slots that uses pointers to member functions or function objects instead of strings to refer to the signal and slot functions. For an introduction, see https://wiki.qt.io/New_Signal_Slot_Syntax. There are many connections left to adapt. In some cases, there are overloaded functions (or default parameters) that need to be handled. Use of QOverload<> or an anonymous function should fix these. In others, we are connecting to parent objects where we only have a pointer to QWidget instead of a specific type of object. To fix those, we need to either move the code that makes th connection to a place where the actual types of both objects are known or pass more specific types as the parent object. In a few cases, there appear to real mismatches in the types of objects and the signal/slot functions. Files affected: ButtonControl.cc, ButtonGroup.cc, ContextMenu.cc, EditControl.cc, Figure.cc, ListBoxControl.cc, Menu.cc, Object.cc, ObjectProxy.cc, Panel.cc, PopupMenuControl.cc, PushTool.cc, SliderControl.cc, Table.cc, ToggleTool.cc, ToolBar.cc, annotation-dialog.cc, qt-graphics-toolkit.cc, color-picker.cc, command-widget.cc, dialog.cc, documentation-bookmarks.cc, documentation.cc, files-dock-widget.cc, find-files-dialog.cc, history-dock-widget.cc, interpreter-qobject.cc, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, find-dialog.cc, octave-qscintilla.cc, main-window.cc, octave-dock-widget.cc, octave-qobject.cc, qt-interpreter-events.cc, set-path-dialog.cc, set-path-model.cc, settings-dialog.cc, shortcut-manager.cc, tab-bar.cc, variable-editor-model.cc, variable-editor.cc, welcome-wizard.cc, welcome-wizard.h, workspace-view.cc, and workspace-view.h.
author John W. Eaton <jwe@octave.org>
date Fri, 16 Apr 2021 23:06:32 -0400
parents 7854d5752dd2
children 5b7e721844df
line wrap: on
line diff
--- a/libgui/src/workspace-view.cc	Thu Apr 15 11:08:57 2021 -0400
+++ b/libgui/src/workspace-view.cc	Fri Apr 16 23:06:32 2021 -0400
@@ -132,8 +132,8 @@
 
         m_view->horizontalHeader ()->setContextMenuPolicy (Qt::CustomContextMenu);
         connect (m_view->horizontalHeader (),
-                 SIGNAL (customContextMenuRequested (const QPoint &)),
-                 this, SLOT (header_contextmenu_requested (const QPoint &)));
+                 &QTableView::customContextMenuRequested,
+                 this, &workspace_view::header_contextmenu_requested);
 
         // Init state of the filter
         m_filter->addItems (settings->value (ws_mru_list.key).toStringList ());
@@ -146,18 +146,18 @@
 
     // Connect signals and slots.
 
-    connect (m_filter, SIGNAL (editTextChanged (const QString&)),
-             this, SLOT (filter_update (const QString&)));
-    connect (m_filter_checkbox, SIGNAL (toggled (bool)),
-             this, SLOT (filter_activate (bool)));
-    connect (m_filter->lineEdit (), SIGNAL (editingFinished ()),
-             this, SLOT (update_filter_history ()));
+    connect (m_filter, &QComboBox::editTextChanged,
+             this, &workspace_view::filter_update);
+    connect (m_filter_checkbox, &QCheckBox::toggled,
+             this, &workspace_view::filter_activate);
+    connect (m_filter->lineEdit (), &QLineEdit::editingFinished,
+             this, &workspace_view::update_filter_history);
 
-    connect (m_view, SIGNAL (customContextMenuRequested (const QPoint&)),
-             this, SLOT (contextmenu_requested (const QPoint&)));
+    connect (m_view, &QTableView::customContextMenuRequested,
+             this, &workspace_view::contextmenu_requested);
 
-    connect (m_view, SIGNAL (activated (QModelIndex)),
-             this, SLOT (handle_contextmenu_edit (void)));
+    connect (m_view, &QTableView::activated,
+             this, &workspace_view::handle_contextmenu_edit);
 
     connect (this, SIGNAL (command_requested (const QString&)),
              p, SLOT (execute_command_in_terminal (const QString&)));
@@ -313,6 +313,20 @@
         action->setChecked (settings->value (ws_columns_shown_keys.at (i),true).toBool ());
       }
 
+    // FIXME: We could use
+    //
+    //   connect (&m_sig_mapper, QOverload<int>::of (&QSignalMapper::mapped),
+    //            this, &workspace_view::toggle_header);
+    //
+    // but referring to QSignalMapper::mapped will generate deprecated
+    // function warnings from GCC.  We could also use
+    //
+    //   connect (&m_sig_mapper, &QSignalMapper::mappedInt,
+    //            this, &workspace_view::toggle_header);
+    //
+    // but the function mappedInt was not introduced until Qt 5.15 so
+    // we'll need a feature test.
+
     connect (&sig_mapper, SIGNAL (mapped (int)),
              this, SLOT (toggle_header (int)));
 
@@ -349,16 +363,17 @@
         QString var_name = get_var_name (index);
 
         menu.addAction (tr ("Open in Variable Editor"), this,
-                        SLOT (handle_contextmenu_edit ()));
+                        &workspace_view::handle_contextmenu_edit);
 
         menu.addAction (tr ("Copy name"), this,
-                        SLOT (handle_contextmenu_copy ()));
+                        &workspace_view::handle_contextmenu_copy);
 
         menu.addAction (tr ("Copy value"), this,
-                        SLOT (handle_contextmenu_copy_value ()));
+                        &workspace_view::handle_contextmenu_copy_value);
 
-        QAction *rename = menu.addAction (tr ("Rename"), this,
-                                          SLOT (handle_contextmenu_rename ()));
+        QAction *rename
+          = menu.addAction (tr ("Rename"), this,
+                            &workspace_view::handle_contextmenu_rename);
 
         // Use m_model here instead of using "m_view->model ()" because
         // that points to the proxy model.
@@ -369,18 +384,18 @@
           }
 
         menu.addAction ("Clear " + var_name, this,
-                        SLOT (handle_contextmenu_clear ()));
+                        &workspace_view::handle_contextmenu_clear);
 
         menu.addSeparator ();
 
         menu.addAction ("disp (" + var_name + ')', this,
-                        SLOT (handle_contextmenu_disp ()));
+                        &workspace_view::handle_contextmenu_disp);
 
         menu.addAction ("plot (" + var_name + ')', this,
-                        SLOT (handle_contextmenu_plot ()));
+                        &workspace_view::handle_contextmenu_plot);
 
         menu.addAction ("stem (" + var_name + ')', this,
-                        SLOT (handle_contextmenu_stem ()));
+                        &workspace_view::handle_contextmenu_stem);
 
         menu.addSeparator ();
 
@@ -388,10 +403,10 @@
 
     if (m_filter_shown)
       menu.addAction (tr ("Hide filter"), this,
-                      SLOT (handle_contextmenu_filter ()));
+                      &workspace_view::handle_contextmenu_filter);
     else
       menu.addAction (tr ("Show filter"), this,
-                      SLOT (handle_contextmenu_filter ()));
+                      &workspace_view::handle_contextmenu_filter);
 
     menu.exec (m_view->mapToGlobal (qpos));
   }