changeset 29762:84d7e1ace446

improve variable editor functionality when used without GUI main window This change connects signals and slots for the variable editor plotting and update features using the base_qobject instead of the main_window object so that they may function as expected when the variable editor is opened from the command line. * main-window.h, main-window.cc (main_window::main_window): Don't connect the variable_editor::command_signal to the main_window::execute_command_in_terminal_signal. (main_window::refresh_variable_editor, main_window::handle_variable_editor_update): Delete. * octave-qobject.h, octave-qobject.cc (base_qobject::refresh_variable_editor, base_qobject::execute_command): New slots, copied from main_window object. (base_qobject::variable_editor_widget): Connect the variable_editor::updated, variable_editor::command_signal, and qt_interpreter_events::refresh_variable_editor_signal signals to base_qobject slots instead of main_window slots.
author John W. Eaton <jwe@octave.org>
date Tue, 15 Jun 2021 22:35:33 -0400
parents 3b5ffc4c70e9
children 83ca5801187b
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-qobject.cc libgui/src/octave-qobject.h
diffstat 4 files changed, 41 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Tue Jun 15 20:35:59 2021 -0400
+++ b/libgui/src/main-window.cc	Tue Jun 15 22:35:33 2021 -0400
@@ -249,9 +249,6 @@
 
     make_dock_widget_connections (m_variable_editor_window);
 
-    connect (m_variable_editor_window, &variable_editor::command_signal,
-             this, &main_window::execute_command_in_terminal);
-
     m_previous_dock = m_command_window;
 
     // Set active editor depending on editor window.  If the latter is
@@ -1961,31 +1958,6 @@
       }
   }
 
-  void main_window::refresh_variable_editor (void)
-  {
-    m_variable_editor_window->refresh ();
-  }
-
-  void main_window::handle_variable_editor_update (void)
-  {
-    // Called when the variable editor emits the updated signal.  The size
-    // of a variable may have changed, so we refresh the workspace in the
-    // interpreter.  That will eventually cause the workspace view in the
-    // GUI to be updated.
-
-    emit interpreter_event
-      ([] (interpreter& interp)
-       {
-         // INTERPRETER THREAD
-
-         tree_evaluator& tw = interp.get_evaluator ();
-
-         event_manager& xevmgr = interp.get_event_manager ();
-
-         xevmgr.set_workspace (true, tw.get_symbol_info (), false);
-       });
-  }
-
   void main_window::profiler_session (void)
   {
     emit interpreter_event
@@ -2096,15 +2068,9 @@
 
     qt_interpreter_events *qt_link = interp_qobj->qt_link ();
 
-    connect (qt_link, &qt_interpreter_events::refresh_variable_editor_signal,
-             this, &main_window::refresh_variable_editor);
-
     connect (m_workspace_window, &workspace_view::rename_variable_signal,
              this, &main_window::handle_rename_variable_request);
 
-    connect (m_variable_editor_window, &variable_editor::updated,
-             this, &main_window::handle_variable_editor_update);
-
     construct_menu_bar ();
 
     construct_tool_bar ();
--- a/libgui/src/main-window.h	Tue Jun 15 20:35:59 2021 -0400
+++ b/libgui/src/main-window.h	Tue Jun 15 22:35:33 2021 -0400
@@ -257,10 +257,6 @@
 
     void edit_variable (const QString &name, const octave_value&);
 
-    void refresh_variable_editor (void);
-
-    void handle_variable_editor_update (void);
-
   protected:
 
     void closeEvent (QCloseEvent *closeEvent);
--- a/libgui/src/octave-qobject.cc	Tue Jun 15 20:35:59 2021 -0400
+++ b/libgui/src/octave-qobject.cc	Tue Jun 15 22:35:33 2021 -0400
@@ -537,8 +537,20 @@
         m_variable_editor_widget->set_adopted (true);
       }
     else if (! m_variable_editor_widget)
-      m_variable_editor_widget
-        = QPointer<variable_editor> (new variable_editor (mw, *this));
+      {
+        m_variable_editor_widget
+          = QPointer<variable_editor> (new variable_editor (mw, *this));
+
+        connect (m_variable_editor_widget, &variable_editor::updated,
+                 this, &base_qobject::handle_variable_editor_update);
+
+        connect (m_variable_editor_widget, &variable_editor::command_signal,
+                 this, &base_qobject::execute_command);
+
+        connect (qt_link (),
+                 &qt_interpreter_events::refresh_variable_editor_signal,
+                 this, &base_qobject::refresh_variable_editor);
+      }
 
     return m_variable_editor_widget;
   }
@@ -678,6 +690,29 @@
        });
   }
 
+  void base_qobject::refresh_variable_editor (void)
+  {
+    m_variable_editor_widget->refresh ();
+  }
+
+  void base_qobject::execute_command (const QString& command)
+  {
+    emit interpreter_event
+      ([=] (interpreter& interp)
+      {
+        // INTERPRETER THREAD
+
+        // FIXME: Do we need to do anything special about errors here?
+        // Currently the eval function will just call error() in the
+        // interpreter event loop and throw an execution error.  It will
+        // be caught, so shouldn't crash the interpreter, but the
+        // message may not go anywhere useful depending on how the GUI
+        // is being used or if Octave running server mode.
+
+        interp.eval (command.toStdString (), 0);
+      });
+  }
+
   void base_qobject::close_gui (void)
   {
     if (m_app_context.experimental_terminal_widget ())
--- a/libgui/src/octave-qobject.h	Tue Jun 15 20:35:59 2021 -0400
+++ b/libgui/src/octave-qobject.h	Tue Jun 15 22:35:33 2021 -0400
@@ -183,6 +183,8 @@
 
   public slots:
 
+    void execute_command (const QString& command);
+
     // Note: START_GUI and CLOSE_GUI don't currently perform any work
     // with the old terminal widget.
     void start_gui (bool gui_app);
@@ -201,6 +203,8 @@
 
     void handle_variable_editor_update (void);
 
+    void refresh_variable_editor (void);
+
     void interpreter_ready (void);
 
     void interpreter_event (const fcn_callback& fcn);