changeset 27247:9e5a825bb966

replace more explicit callback functions with lambda expressions * Canvas.h, Canvas.cc (Canvas::annotation_callback): Delete. Replace uses of callback functions with equivalent lambda expressions in calls to octave_link::post_event. * file-editor-tab.h, file-editor-tab.cc (file_editor_tab::add_breakpoint_event): New function. (file_editor_tab::add_breakpoint_callback, file_editor_tab::remove_breakpoint_callback, file_editor_tab::remove_all_breakpoints_callback): Delete. Replace uses of callback functions with equivalent lambda expressions in calls to octave_link::post_event. Use add_breakpoint_event to consolidate the calls to post_event for this action to a single function. * variable-editor-model.h, variable-editor-model.cc (variable_editor_model::eval_expr_event): New function. (variable_editor_model::init_from_oct): Eliminate unnecessary function parameter. (variable_editor_model::set_data_oct, variable_editor_model::eval_oct): Delete. Replace uses of callback functions with equivalent lambda expressions in calls to octave_link::post_event. Use eval_expr_event to consolidate the calls to post_event for this action to a single function.
author John W. Eaton <jwe@octave.org>
date Fri, 12 Jul 2019 19:26:55 -0400
parents 7c778a102de8
children a23f25cc2aae
files libgui/graphics/Canvas.cc libgui/graphics/Canvas.h libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/variable-editor-model.cc libgui/src/variable-editor-model.h
diffstat 6 files changed, 134 insertions(+), 145 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/Canvas.cc	Fri Jul 12 15:34:28 2019 -0700
+++ b/libgui/graphics/Canvas.cc	Fri Jul 12 19:26:55 2019 -0400
@@ -266,17 +266,6 @@
       }
   }
 
-  void
-  Canvas::annotation_callback (const octave_value_list& args)
-  {
-    octave::interpreter& interp
-      = octave::__get_interpreter__ ("Canvas::annotation_callback");
-
-    interp.feval ("annotation", args);
-
-    redraw ();
-  }
-
   static void
   autoscale_axes (axes::properties& ap)
   {
@@ -886,8 +875,16 @@
                     props = anno_dlg.get_properties ();
                     props.prepend (figObj.get_handle ().as_octave_value ());
 
-                    octave_link::post_event (this, &Canvas::annotation_callback,
-                                             props);
+                    octave_link::post_event
+                      ([this, props] (void)
+                       {
+                         octave::interpreter& interp
+                           = octave::__get_interpreter__ ("Canvas::canvasMouseReleaseEvent");
+
+                         interp.feval ("annotation", props);
+
+                         redraw ();
+                       });
                   }
               }
           }
--- a/libgui/graphics/Canvas.h	Fri Jul 12 15:34:28 2019 -0700
+++ b/libgui/graphics/Canvas.h	Fri Jul 12 19:26:55 2019 -0400
@@ -110,7 +110,6 @@
     void updateCurrentPoint (const graphics_object& fig,
                              const graphics_object& obj);
 
-    void annotation_callback (const octave_value_list& args);
     void select_object (graphics_object obj, QMouseEvent *event,
                         graphics_object& currentObj, graphics_object& axesObj,
                         bool axes_only = false,
--- a/libgui/src/m-editor/file-editor-tab.cc	Fri Jul 12 15:34:28 2019 -0700
+++ b/libgui/src/m-editor/file-editor-tab.cc	Fri Jul 12 19:26:55 2019 -0400
@@ -434,8 +434,7 @@
       {
         info.condition = cond.toStdString ();
 
-        octave_link::post_event
-          (this, &file_editor_tab::add_breakpoint_callback, info);
+        add_breakpoint_event (info);
       }
   }
 
@@ -1065,51 +1064,6 @@
     _edit_area->markerDeleteAll (marker::bookmark);
   }
 
-  void file_editor_tab::add_breakpoint_callback (const bp_info& info)
-  {
-    bp_table::intmap line_info;
-    line_info[0] = info.line;
-
-    if (octave_qt_link::file_in_path (info.file, info.dir))
-      {
-        bp_table& bptab = __get_bp_table__ ("octave_qt_link::file_in_path");
-
-        bp_table::intmap bpmap
-          = bptab.add_breakpoint (info.function_name, "", line_info, info.condition);
-
-        // Store some info breakpoint
-        if (m_breakpoint_info.remove_next && (bpmap.size() > 0))
-          {
-            bp_table::intmap::iterator bp_it = bpmap.begin();
-            m_breakpoint_info.remove_line = bp_it->second;
-            m_breakpoint_info.remove_next = false;
-          }
-      }
-  }
-
-  void file_editor_tab::remove_breakpoint_callback (const bp_info& info)
-  {
-    bp_table::intmap line_info;
-    line_info[0] = info.line;
-
-    if (octave_qt_link::file_in_path (info.file, info.dir))
-      {
-        bp_table& bptab = __get_bp_table__ ("remove_breakpoint_callback");
-
-        bptab.remove_breakpoint (info.function_name, line_info);
-      }
-  }
-
-  void file_editor_tab::remove_all_breakpoints_callback (const bp_info& info)
-  {
-    if (octave_qt_link::file_in_path (info.file, info.dir))
-      {
-        bp_table& bptab = __get_bp_table__ ("remove_all_breakpoints_callback");
-
-        bptab.remove_all_breakpoints_in_file (info.function_name, true);
-      }
-  }
-
   file_editor_tab::bp_info::bp_info (const QString& fname, int l,
                                      const QString& cond)
     : line (l), file (fname.toStdString ()), condition (cond.toStdString ())
@@ -1146,8 +1100,7 @@
   {
     bp_info info (_file_name, line, condition);
 
-    octave_link::post_event
-      (this, &file_editor_tab::add_breakpoint_callback, info);
+    add_breakpoint_event (info);
   }
 
   void file_editor_tab::handle_request_remove_breakpoint (int line)
@@ -1155,7 +1108,18 @@
     bp_info info (_file_name, line);
 
     octave_link::post_event
-      (this, &file_editor_tab::remove_breakpoint_callback, info);
+      ([info] (void)
+       {
+         bp_table::intmap line_info;
+         line_info[0] = info.line;
+
+         if (octave_qt_link::file_in_path (info.file, info.dir))
+           {
+             bp_table& bptab = __get_bp_table__ ("file_editor_tab::handle_request_remove_breakpoint");
+
+             bptab.remove_breakpoint (info.function_name, line_info);
+           }
+       });
   }
 
   void file_editor_tab::toggle_breakpoint (const QWidget *ID)
@@ -1227,7 +1191,15 @@
     bp_info info (_file_name);
 
     octave_link::post_event
-      (this, &file_editor_tab::remove_all_breakpoints_callback, info);
+      ([info] (void)
+       {
+         if (octave_qt_link::file_in_path (info.file, info.dir))
+           {
+             bp_table& bptab = __get_bp_table__ ("file_editor_tab::remove_all_breakpoints");
+
+             bptab.remove_all_breakpoints_in_file (info.function_name, true);
+           }
+       });
   }
 
   void file_editor_tab::scintilla_command (const QWidget *ID, unsigned int sci_msg)
@@ -1345,6 +1317,32 @@
     _find_dialog->save_data (&m_find_dlg_data);
   }
 
+  void file_editor_tab::add_breakpoint_event (const bp_info& info)
+  {
+    octave_link::post_event
+      ([this, info] (void)
+       {
+         bp_table::intmap line_info;
+         line_info[0] = info.line;
+
+         if (octave_qt_link::file_in_path (info.file, info.dir))
+           {
+             bp_table& bptab = __get_bp_table__ ("file_editor_tab::add_breakpoint_event");
+
+             bp_table::intmap bpmap
+               = bptab.add_breakpoint (info.function_name, "", line_info, info.condition);
+
+             // Store some info breakpoint
+             if (m_breakpoint_info.remove_next && (bpmap.size() > 0))
+               {
+                 bp_table::intmap::iterator bp_it = bpmap.begin();
+                 m_breakpoint_info.remove_line = bp_it->second;
+                 m_breakpoint_info.remove_next = false;
+               }
+           }
+       });
+  }
+
   // This methos creates the find dialog in way that is at first suitable
   // for re-creating it after the toplevel of the editor has changed.
   // The find dialog is initially creatied, activated and shown with find ()
--- a/libgui/src/m-editor/file-editor-tab.h	Fri Jul 12 15:34:28 2019 -0700
+++ b/libgui/src/m-editor/file-editor-tab.h	Fri Jul 12 19:26:55 2019 -0400
@@ -247,6 +247,8 @@
       std::string condition;
     };
 
+    void add_breakpoint_event (const bp_info& info);
+
     void find_create (void);
 
     bool valid_file_name (const QString& file = QString ());
@@ -269,9 +271,6 @@
     void do_indent_selected_text (bool indent);
     void do_smart_indent_line_or_selected_text (void);
 
-    void add_breakpoint_callback (const bp_info& info);
-    void remove_breakpoint_callback (const bp_info& info);
-    void remove_all_breakpoints_callback (const bp_info& info);
     void check_restore_breakpoints (void);
     void center_current_line (bool always=true);
 
--- a/libgui/src/variable-editor-model.cc	Fri Jul 12 15:34:28 2019 -0700
+++ b/libgui/src/variable-editor-model.cc	Fri Jul 12 19:26:55 2019 -0400
@@ -1013,7 +1013,34 @@
     std::string expr = os.str ();
 
     octave_link::post_event
-      (this, &variable_editor_model::set_data_oct, nm, expr, idx);
+      ([this, nm, expr, idx] (void)
+       {
+         // INTERPRETER THREAD
+
+         try
+           {
+             interpreter& interp
+               = __get_interpreter__ ("variable_editor_model::setData");
+
+             int parse_status = 0;
+             interp.eval_string (expr, true, parse_status);
+
+             octave_value val = retrieve_variable (nm);
+
+             emit update_data_signal (val);
+           }
+         catch (execution_exception&)
+           {
+             clear_update_pending ();
+
+             evaluation_error (expr);
+
+             // This will cause the data in the cell to be reset
+             // from the cached octave_value object.
+
+             emit dataChanged (idx, idx);
+           }
+       });
 
     return true;
   }
@@ -1049,13 +1076,11 @@
   {
     // FIXME: cells?
 
-    octave_link::post_event
-      (this, &variable_editor_model::eval_oct, name (),
-       QString ("%1 = [ %1(1:%2,:) ; zeros(%3, columns(%1)) ; %1(%2+%3:end,:) ]")
+    eval_expr_event
+      (QString ("%1 = [%1(1:%2,:); zeros(%3,columns(%1)); %1(%2+%3:end,:)]")
        .arg (QString::fromStdString (name ()))
        .arg (row)
-       .arg (count)
-       .toStdString ());
+       .arg (count));
 
     return true;
   }
@@ -1071,13 +1096,11 @@
         return false;
       }
 
-    octave_link::post_event
-      (this, &variable_editor_model::eval_oct, name (),
-       QString ("%1(%2:%3, :) = []")
+    eval_expr_event
+      (QString ("%1(%2:%3,:) = []")
        .arg (QString::fromStdString (name ()))
        .arg (row)
-       .arg (row + count)
-       .toStdString ());
+       .arg (row + count));
 
     return true;
   }
@@ -1085,13 +1108,11 @@
   bool
   variable_editor_model::insertColumns (int col, int count, const QModelIndex&)
   {
-    octave_link::post_event
-      (this, &variable_editor_model::eval_oct, name (),
-       QString ("%1 = [ %1(:,1:%2) ; zeros(rows(%1), %3) %1(:,%2+%3:end) ]")
+    eval_expr_event
+      (QString ("%1 = [%1(:,1:%2); zeros(rows(%1),%3) %1(:,%2+%3:end)]")
        .arg (QString::fromStdString (name ()))
        .arg (col)
-       .arg (count)
-       .toStdString ());
+       .arg (count));
 
     return true;
   }
@@ -1107,89 +1128,62 @@
         return false;
       }
 
-    octave_link::post_event
-      (this, &variable_editor_model::eval_oct, name (),
-       QString ("%1(:, %2:%3) = []")
+    eval_expr_event
+      (QString ("%1(:,%2:%3) = []")
        .arg (QString::fromStdString (name ()))
        .arg (col)
-       .arg (col + count)
-       .toStdString ());
+       .arg (col + count));
 
     return true;
   }
 
   void
-  variable_editor_model::set_data_oct (const std::string& name,
-                                       const std::string& expr,
-                                       const QModelIndex& idx)
+  variable_editor_model::init_from_oct (void)
   {
     // INTERPRETER THREAD
 
+    std::string nm = name ();
+
     try
       {
-        interpreter& interp
-          = __get_interpreter__ ("variable_editor_model::set_data_oct");
-
-        int parse_status = 0;
-        interp.eval_string (expr, true, parse_status);
-
-        octave_value val = retrieve_variable (name);
-
-        emit update_data_signal (val);
-      }
-    catch (execution_exception&)
-      {
-        clear_update_pending ();
-
-        evaluation_error (expr);
-
-        // This will cause the data in the cell to be reset
-        // from the cached octave_value object.
-
-        emit dataChanged (idx, idx);
-      }
-  }
-
-  void
-  variable_editor_model::init_from_oct (const std::string& name)
-  {
-    // INTERPRETER THREAD
-
-    try
-      {
-        octave_value val = retrieve_variable (name);
+        octave_value val = retrieve_variable (nm);
 
         emit update_data_signal (val);
       }
     catch (execution_exception&)
       {
         QString msg = (QString ("variable '%1' is invalid or undefined")
-                       .arg (QString::fromStdString (name)));
+                       .arg (QString::fromStdString (nm)));
 
         emit data_error_signal (msg);
       }
   }
 
   void
-  variable_editor_model::eval_oct (const std::string& name,
-                                   const std::string& expr)
+  variable_editor_model::eval_expr_event (const QString& expr_arg)
   {
-    // INTERPRETER THREAD
+    std::string expr = expr_arg.toStdString ();
 
-    try
-      {
-        interpreter& interp
-          = __get_interpreter__ ("variable_editor_model::eval_oct");
+    octave_link::post_event
+      ([this, expr] (void)
+       {
+         // INTERPRETER THREAD
 
-        int parse_status = 0;
-        interp.eval_string (expr, true, parse_status);
+         try
+           {
+             interpreter& interp
+               = __get_interpreter__ ("variable_editor_model::eval_expr_event");
+
+             int parse_status = 0;
+             interp.eval_string (expr, true, parse_status);
 
-        init_from_oct (name);
-      }
-    catch  (execution_exception&)
-      {
-        evaluation_error (expr);
-      }
+             init_from_oct ();
+           }
+         catch  (execution_exception&)
+           {
+             evaluation_error (expr);
+           }
+       });
   }
 
   // If the variable exists, load it into the data model.  If it doesn't
@@ -1242,7 +1236,12 @@
   variable_editor_model::update_data_cache (void)
   {
     octave_link::post_event
-      (this, &variable_editor_model::init_from_oct, name ());
+      ([this] (void)
+       {
+         // INTERPRETER_THREAD
+
+         init_from_oct ();
+       });
   }
 
   void
--- a/libgui/src/variable-editor-model.h	Fri Jul 12 15:34:28 2019 -0700
+++ b/libgui/src/variable-editor-model.h	Fri Jul 12 19:26:55 2019 -0400
@@ -299,12 +299,9 @@
 
     base_ve_model *rep;
 
-    void set_data_oct (const std::string& name, const std::string& expr,
-                       const QModelIndex&);
+    void init_from_oct (void);
 
-    void init_from_oct (const std::string& str);
-
-    void eval_oct (const std::string& name, const std::string& expr);
+    void eval_expr_event (const QString& expr);
 
     octave_value retrieve_variable (const std::string& name);