changeset 27391:a329a41cf341

use interpreter_event signals in set_path_dialog object * set-path-model.h, set-path-model.cc (set_path_modeld::interpreter_event): New signals. (set_path_model::set_path_model): Don't call path_to_model. Initialization must happen after all signals are connected. (set_path_model::model_to_path, set_path_model::path_to_model, set_path_model::save): Use interpreter_event signals instead of accessing event manager and interpreter object directly from the set_path_model object in the GUI thread. * set-path-dialog.h, set-path-dialog.cc (set_path_dialog::interpreter_event): New signals. (set_path_dialog::set_path_dialog): Connect interpreter_event signals from the model to interpreter_event signals in the dialog. * main-window.cc (main_window::handle_set_path_dialog_request): Connect interpreter_event signals from the dialog to interpreter_event signals in the main window. Call update_model for the set_path_dialog object.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Sep 2019 13:38:40 -0400
parents baeed03c3766
children 820a87b87c01
files libgui/src/main-window.cc libgui/src/set-path-dialog.cc libgui/src/set-path-dialog.h libgui/src/set-path-model.cc libgui/src/set-path-model.h
diffstat 5 files changed, 53 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Thu Sep 12 09:57:34 2019 -0700
+++ b/libgui/src/main-window.cc	Wed Sep 11 13:38:40 2019 -0400
@@ -1670,14 +1670,30 @@
     m_set_path_dlg->setAttribute (Qt::WA_DeleteOnClose);
     m_set_path_dlg->show ();
 
+    // Any interpreter_event signal from a set_path_dialog object is
+    // handled the same as for the main_window object.
+
+    connect (m_set_path_dlg, SIGNAL (interpreter_event (const fcn_callback&)),
+             this, SIGNAL (interpreter_event (const fcn_callback&)));
+
+    connect (m_set_path_dlg, SIGNAL (interpreter_event (const meth_callback&)),
+             this, SIGNAL (interpreter_event (const meth_callback&)));
+
     connect (m_set_path_dlg,
              SIGNAL (modify_path_signal (const octave_value_list&, bool, bool)),
              this, SLOT (modify_path (const octave_value_list&, bool, bool)));
 
     interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj ();
+
     qt_interpreter_events *qt_link = interp_qobj->qt_link ();
+
     connect (qt_link, SIGNAL (update_path_dialog_signal (void)),
              m_set_path_dlg, SLOT (update_model (void)));
+
+    // Now that all the signal connections are in place for the dialog
+    // we can set the initial value of the path in the model.
+
+    m_set_path_dlg->update_model ();
   }
 
   void main_window::find_files (const QString& start_dir)
--- a/libgui/src/set-path-dialog.cc	Thu Sep 12 09:57:34 2019 -0700
+++ b/libgui/src/set-path-dialog.cc	Wed Sep 11 13:38:40 2019 -0400
@@ -51,6 +51,8 @@
 #include "resource-manager.h"
 #include "gui-preferences.h"
 
+#include "ovl.h"
+
 namespace octave
 {
   set_path_dialog::set_path_dialog (QWidget *parent)
@@ -112,6 +114,15 @@
     connect (m_save_button, SIGNAL (clicked (void)),
              model, SLOT (save (void)));
 
+    // Any interpreter_event signal from a set_path_model object is
+    // handled the same as for the parent set_path_dialog object.
+
+    connect (model, SIGNAL (interpreter_event (const fcn_callback&)),
+             this, SIGNAL (interpreter_event (const fcn_callback&)));
+
+    connect (model, SIGNAL (interpreter_event (const meth_callback&)),
+             this, SIGNAL (interpreter_event (const meth_callback&)));
+
     m_path_list = new QListView (this);
     m_path_list->setWordWrap (false);
     m_path_list->setModel (model);
--- a/libgui/src/set-path-dialog.h	Thu Sep 12 09:57:34 2019 -0700
+++ b/libgui/src/set-path-dialog.h	Wed Sep 11 13:38:40 2019 -0400
@@ -26,7 +26,9 @@
 #include <QModelIndex>
 #include <QFileInfo>
 
-#include "ovl.h"
+#include "qt-interpreter-events.h"
+
+class octave_value_list;
 
 class QLabel;
 class QPushButton;
@@ -42,6 +44,10 @@
 
   public:
 
+    // You must call update_model to fully initialize the path displayed
+    // in the dialog.  That may only be done after the intepreter_event
+    // signal connections are made to the Octave interpreter.
+
     set_path_dialog (QWidget *parent = nullptr);
 
     virtual ~set_path_dialog (void);
@@ -55,6 +61,9 @@
     void modify_path_signal (const octave_value_list& dir_list,
                              bool rm, bool subdirs);
 
+    void interpreter_event (const fcn_callback& fcn);
+    void interpreter_event (const meth_callback& meth);
+
   public slots:
 
     void update_model (void);
--- a/libgui/src/set-path-model.cc	Thu Sep 12 09:57:34 2019 -0700
+++ b/libgui/src/set-path-model.cc	Wed Sep 11 13:38:40 2019 -0400
@@ -33,15 +33,15 @@
 #include <QtAlgorithms>
 #include <QMessageBox>
 
+#include "qt-interpreter-events.h"
+#include "set-path-model.h"
+
 #include "pathsearch.h"
 
-#include "event-manager.h"
 #include "interpreter-private.h"
 #include "interpreter.h"
 #include "load-path.h"
 
-#include "set-path-model.h"
-
 namespace octave
 {
   set_path_model::set_path_model (QObject *p)
@@ -51,7 +51,6 @@
              this, SLOT (update_data (const QStringList&)));
 
     m_revertible = false;
-    path_to_model ();
   }
 
   std::string set_path_model::to_string (void)
@@ -75,20 +74,16 @@
 
   void set_path_model::model_to_path (void)
   {
-    event_manager& evmgr
-      = __get_event_manager__ ("set_path_model::model_to_path");
-
     std::string path_str = to_string ();
 
-    evmgr.post_event
-      ([path_str] (void)
+    emit interpreter_event
+      ([path_str] (interpreter& interp)
        {
          // INTERPRETER THREAD
 
-         load_path& lp = __get_load_path__ ("set_path_model::model_to_path");
+         load_path& lp = interp.get_load_path ();
 
          lp.set (path_str);
-
        });
   }
 
@@ -105,15 +100,11 @@
   {
     model_to_path ();
 
-    event_manager& evmgr = __get_event_manager__ ("set_path_model::save");
-
-    evmgr.post_event
-      ([] (void)
+    emit interpreter_event
+      ([] (interpreter& interp)
        {
          // INTERPRETER THREAD
 
-         interpreter& interp = __get_interpreter__ ("set_path_model::save");
-
          interp.feval ("savepath");
        });
   }
@@ -291,12 +282,10 @@
 
   void set_path_model::path_to_model (void)
   {
-    event_manager& evmgr = __get_event_manager__ ("set_path_model::path_to_model");
-
-    evmgr.post_event
-      ([this] (void)
+    emit interpreter_event
+      ([this] (interpreter& interp)
        {
-         load_path& lp = __get_load_path__ ("set_path_model::path_to_model");
+         load_path& lp = interp.get_load_path ();
 
          std::list<std::string> dir_list = lp.dir_list ();
 
--- a/libgui/src/set-path-model.h	Thu Sep 12 09:57:34 2019 -0700
+++ b/libgui/src/set-path-model.h	Wed Sep 11 13:38:40 2019 -0400
@@ -29,6 +29,8 @@
 #include <QFileInfo>
 #include <QIcon>
 
+#include "qt-interpreter-events.h"
+
 namespace octave
 {
   class set_path_model : public QAbstractListModel
@@ -79,6 +81,9 @@
 
     void update_data_signal (const QStringList& dirs);
 
+    void interpreter_event (const fcn_callback& fcn);
+    void interpreter_event (const meth_callback& meth);
+
   private slots:
 
     void update_data (const QStringList& dirs);