changeset 29057:450920c987b8

update profiler status in gui from interpreter * main-window.cc (handle_gui_status_update): new slot for updating status indicators in the gui triggered by the interpreter; (profiler_session, profiler_session_resume, profiler_stop): do not trigger status update here (construct_octave_qt_link): connect gui status update signal with new related slot; (construct_profile_menu): remove obsolete connection of former status update signal with related slot * main-window.h: remove obsolete update signal of the main window; new slote for updateing status indicators in the gui * qt-interpreter-events.cc (gui_status_update): slot for the event managers status update signal emitting signal for the main window * interpreter-events.h: new slot gui_status_update, new signal gui_status_update_signal * event-manager.cc (__event_manager_gui_status_update__): new function, for now just a stub, which should only be activated if some interpreter action only implemented in m-files requires to update a status indicator in the gui * event-manager.h: new virtual slot for gui status update, new slot calling qt-links gui_status_update * profiler.cc: include event-manager.h; (__profiler_enable__): call event managers gui_status_update depending on enabling/disabling the profiler
author Torsten Lilge <ttl-octave@mailbox.org>
date Thu, 12 Nov 2020 21:11:50 +0100
parents dbf8a7f16c4e
children b211e6e866f6
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/qt-interpreter-events.cc libgui/src/qt-interpreter-events.h libinterp/corefcn/event-manager.cc libinterp/corefcn/event-manager.h libinterp/parse-tree/profiler.cc
diffstat 7 files changed, 93 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Thu Nov 12 18:28:49 2020 +0100
+++ b/libgui/src/main-window.cc	Thu Nov 12 21:11:50 2020 +0100
@@ -1646,6 +1646,21 @@
     emit unregister_doc_signal (file);
   }
 
+  void main_window::handle_gui_status_update (const QString& feature,
+                                              const QString& status)
+  {
+    // Put actions that are required for updating a gui features here
+
+    // Profiler on/off
+    if (! feature.compare ("profiler"))
+      {
+        if (! status.compare ("on", Qt::CaseInsensitive))
+          handle_profiler_status_update (true);
+        else if (! status.compare ("off", Qt::CaseInsensitive))
+          handle_profiler_status_update (false);
+      }
+  }
+
   void main_window::handle_octave_ready (void)
   {
     // actions after the startup files are executed
@@ -1932,8 +1947,6 @@
           // INTERPRETER THREAD
 
           Ffeval (interp, ovl ("profile","on"));
-
-          emit profiler_status_update (true);
         });
   }
 
@@ -1945,8 +1958,6 @@
           // INTERPRETER THREAD
 
           Ffeval (interp, ovl ("profile","resume"));
-
-          emit profiler_status_update (true);
         });
   }
 
@@ -1957,9 +1968,7 @@
         {
           // INTERPRETER THREAD
 
-          Ffeval (interp, ovl ("profile","resume"));
-
-          emit profiler_status_update (false);
+          Ffeval (interp, ovl ("profile","off"));
         });
   }
 
@@ -2317,6 +2326,11 @@
              SIGNAL (unregister_doc_signal (const QString &)),
              this, SLOT (handle_unregister_doc (const QString &)));
 
+    connect (qt_link, SIGNAL (gui_status_update_signal (const QString &,
+                                                        const QString &)),
+             this, SLOT (handle_gui_status_update (const QString &,
+                                                   const QString &)));
+
     connect (qt_link, SIGNAL (update_gui_lexer_signal (bool)),
              this, SIGNAL (update_gui_lexer_signal (bool)));
   }
@@ -2620,9 +2634,6 @@
 
     m_profiler_show = add_action (profiler_menu, QIcon (),
           tr ("&Show Profile Data"), SLOT (profiler_show ()));
-
-    connect (this, SIGNAL (profiler_status_update (bool)),
-             this, SLOT (handle_profiler_status_update (bool)));
   }
 
   void main_window::editor_tabs_changed (bool have_tabs)
--- a/libgui/src/main-window.h	Thu Nov 12 18:28:49 2020 +0100
+++ b/libgui/src/main-window.h	Thu Nov 12 21:11:50 2020 +0100
@@ -125,8 +125,6 @@
     void interpreter_event (const fcn_callback& fcn);
     void interpreter_event (const meth_callback& meth);
 
-    void profiler_status_update (bool);
-
   public slots:
 
     void focus_changed (QWidget *w_old, QWidget *w_new);
@@ -208,6 +206,8 @@
     void pasteClipboard (void);
     void selectAll (void);
 
+    void handle_gui_status_update (const QString& feature, const QString& status);
+
     void focus_console_after_command (void);
     void handle_show_doc (const QString& file);
     void handle_register_doc (const QString& file);
--- a/libgui/src/qt-interpreter-events.cc	Thu Nov 12 18:28:49 2020 +0100
+++ b/libgui/src/qt-interpreter-events.cc	Thu Nov 12 21:11:50 2020 +0100
@@ -447,6 +447,13 @@
     emit unregister_doc_signal (QString::fromStdString (file));
   }
 
+  void qt_interpreter_events::gui_status_update (const std::string& feature,
+                                                 const std::string& status)
+  {
+    emit gui_status_update_signal (QString::fromStdString (feature),
+                                   QString::fromStdString (status));
+  }
+
   void qt_interpreter_events::update_gui_lexer (void)
   {
     emit update_gui_lexer_signal (true);
--- a/libgui/src/qt-interpreter-events.h	Thu Nov 12 18:28:49 2020 +0100
+++ b/libgui/src/qt-interpreter-events.h	Thu Nov 12 21:11:50 2020 +0100
@@ -141,6 +141,8 @@
 
     void unregister_doc (const std::string& file);
 
+    void gui_status_update (const std::string& feature, const std::string& status);
+
     void update_gui_lexer (void);
 
     void directory_changed (const std::string& dir);
@@ -242,6 +244,8 @@
 
     void unregister_doc_signal (const QString& file);
 
+    void gui_status_update_signal (const QString& feature, const QString& status);
+
     void update_gui_lexer_signal (bool update_apis_only);
 
     void edit_variable_signal (const QString& name, const octave_value& val);
--- a/libinterp/corefcn/event-manager.cc	Thu Nov 12 18:28:49 2020 +0100
+++ b/libinterp/corefcn/event-manager.cc	Thu Nov 12 21:11:50 2020 +0100
@@ -577,6 +577,40 @@
   return ovl (evmgr.unregister_doc (file));
 }
 
+DEFMETHOD (__event_manager_gui_status_update__, interp, args, ,
+           doc: /* -*- texinfo -*-
+@deftypefn {} {} __event_manager_gui_status_update__ (@var{feature}, @var{status})
+Internal function for updating the status of some features in the GUI.
+@end deftypefn */)
+{
+  // This is currently a stub and should only be activated some
+  // interpreter action only implemented in m-files requires to update
+  // a status indicator in the gui. BUT: This internal function can
+  // be activated by the user leading to gui indicators not reflecting
+  // the real state of the related feature.
+  return ovl ();
+
+  std::string feature;
+  std::string status;
+
+  if (! (Fisguirunning ())(0).is_true ())
+    return ovl ();
+
+  if (args.length () < 2)
+    error ("__event_manager_gui_status_update__: two parameters required");
+  if (! (args(0).is_string ()))
+    error ("__event_manager_gui_status_update__: FEATURE must be a string");
+  if (! (args(1).is_string ()))
+    error ("__event_manager_gui_status_update__: STATUS must be a string");
+
+  feature = args(0).string_value ();
+  status = args(1).string_value ();
+
+  octave::event_manager& evmgr = interp.get_event_manager ();
+
+  return ovl (evmgr.gui_status_update (feature, status));
+}
+
 DEFMETHOD (__event_manager_update_gui_lexer__, interp, , ,
            doc: /* -*- texinfo -*-
 @deftypefn {} {} __event_manager_update_gui_lexer__ ()
--- a/libinterp/corefcn/event-manager.h	Thu Nov 12 18:28:49 2020 +0100
+++ b/libinterp/corefcn/event-manager.h	Thu Nov 12 21:11:50 2020 +0100
@@ -195,6 +195,9 @@
 
     virtual void unregister_doc (const std::string& /*file*/) { }
 
+    virtual void gui_status_update (const std::string& /*feature*/,
+                                    const std::string& /*status*/) { }
+
     virtual void update_gui_lexer (void) { }
 
     // Notifications of events in the interpreter that a GUI will
@@ -499,6 +502,17 @@
         return false;
     }
 
+    bool gui_status_update (const std::string& feature, const std::string& status)
+    {
+      if (enabled ())
+        {
+          instance->gui_status_update (feature, status);
+          return true;
+        }
+      else
+        return false;
+    }
+
     bool update_gui_lexer (void)
     {
       if (enabled ())
--- a/libinterp/parse-tree/profiler.cc	Thu Nov 12 18:28:49 2020 +0100
+++ b/libinterp/parse-tree/profiler.cc	Thu Nov 12 21:11:50 2020 +0100
@@ -28,6 +28,7 @@
 #endif
 
 #include "defun.h"
+#include "event-manager.h"
 #include "interpreter.h"
 #include "oct-time.h"
 #include "ov-struct.h"
@@ -397,7 +398,16 @@
   octave::profiler& profiler = interp.get_profiler ();
 
   if (nargin == 1)
-    profiler.set_active (args(0).bool_value ());
+    {
+      profiler.set_active (args(0).bool_value ());
+
+      std::string status = "off";
+      if (args(0).bool_value ())
+        status = "on";
+
+      octave::event_manager& evmgr = interp.get_event_manager ();
+      evmgr.gui_status_update ("profiler", status);  // tell GUI
+    }
 
   return ovl (profiler.enabled ());
 }