changeset 24645:f61502510d08

restore ability to select variables for editing from workspace widget * octave-qt-link.h, octave-qt-link.cc: Declare octave::symbol_scope as a Qt metatype. (octave_qt_link::set_workspace_signal): Pass scope instead of individual lists of scope things. Change all uses. (octave_qt_link::do_set_workspace): Pass scope instead of list of workspace_element objects. * octave-link.h, octave-link.cc (octave_link::set_workspace, octave_link::do_set_workspace): Pass scope instead of list of workspace_element objects. Change all uses. * workspace-model.h, workspace-model.cc (workspace_model::m_scope): New data member. (workspace_model::set_workspace): Pass and store scope instead of individual lists of scope things. Change all uses. (workspace_model::clear_data): Also invalidate m_scope. (workspace_model::update_table): Unpack scope info here without using an intermediate list of workspace elements. (workspace_model::scope): New function. * workspace-view.h, workspace-view.cc (workspace_view::edit_variable_signal): Also pass value object. Change all uses. (workspace_view::setModel): Also extract value from scope. * workspace-element.h: Delete. * libinterp/corefcn/module.mk: Update. * symscope.h, symscope.cc (symbol_scope::workspace_info, symbol_scope::symbol_scope_rep::workspace_info): Delete.
author John W. Eaton <jwe@octave.org>
date Sat, 27 Jan 2018 09:06:50 -0500
parents e04a56630c8a
children d36e1f768bfa
files libgui/src/main-window.cc libgui/src/octave-qt-link.cc libgui/src/octave-qt-link.h libgui/src/workspace-model.cc libgui/src/workspace-model.h libgui/src/workspace-view.cc libgui/src/workspace-view.h libinterp/corefcn/module.mk libinterp/corefcn/octave-link.cc libinterp/corefcn/octave-link.h libinterp/corefcn/symscope.cc libinterp/corefcn/symscope.h libinterp/corefcn/symtab.h libinterp/corefcn/workspace-element.h
diffstat 14 files changed, 102 insertions(+), 237 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Fri Jan 26 19:50:04 2018 -0800
+++ b/libgui/src/main-window.cc	Sat Jan 27 09:06:50 2018 -0500
@@ -1977,15 +1977,10 @@
   if (m_start_gui)
     {
       connect (m_octave_qt_link,
-               SIGNAL (set_workspace_signal
-                       (bool, bool, const QString&, const QStringList&,
-                        const QStringList&, const QStringList&,
-                        const QStringList&, const QIntList&)),
+               SIGNAL (set_workspace_signal (bool, bool,
+                                             const octave::symbol_scope&)),
                m_workspace_model,
-               SLOT (set_workspace
-                     (bool, bool, const QString&, const QStringList&,
-                      const QStringList&, const QStringList&,
-                      const QStringList&, const QIntList&)));
+               SLOT (set_workspace (bool, bool, const octave::symbol_scope&)));
 
       connect (m_octave_qt_link, SIGNAL (clear_workspace_signal (void)),
                m_workspace_model, SLOT (clear_workspace (void)));
@@ -2550,7 +2545,7 @@
    = octave::__get_current_scope__ ("main_window::load_workspace_callback");
 
   if (scope)
-    octave_link::set_workspace (true, scope.workspace_info ());
+    octave_link::set_workspace (true, scope);
 }
 
 void
@@ -2565,7 +2560,7 @@
     {
       scope.rename (names.first, names.second);
 
-      octave_link::set_workspace (true, scope.workspace_info ());
+      octave_link::set_workspace (true, scope);
     }
 
   // FIXME: if this action fails, do we need a way to display that info
@@ -2634,7 +2629,7 @@
    = octave::__get_current_scope__ ("main_window::force_refresh_workspace");
 
   if (scope)
-    octave_link::set_workspace (true, scope.workspace_info (), false);
+    octave_link::set_workspace (true, scope, false);
 }
 
 bool
--- a/libgui/src/octave-qt-link.cc	Fri Jan 26 19:50:04 2018 -0800
+++ b/libgui/src/octave-qt-link.cc	Sat Jan 27 09:06:50 2018 -0500
@@ -41,18 +41,22 @@
 #include "interpreter-private.h"
 #include "load-path.h"
 #include "ov.h"
+#include "symscope.h"
 #include "utils.h"
 
 #include "octave-gui.h"
 #include "octave-qt-link.h"
 #include "resource-manager.h"
-#include "workspace-element.h"
+
+Q_DECLARE_METATYPE (octave_value)
+Q_DECLARE_METATYPE (octave::symbol_scope)
 
 octave_qt_link::octave_qt_link (QWidget *,
                                 octave::gui_application *app_context)
   : octave_link (), m_app_context (app_context)
 {
   qRegisterMetaType<octave_value> ("octave_value");
+  qRegisterMetaType<octave::symbol_scope> ("symbol_scope");
 }
 
 bool
@@ -422,32 +426,13 @@
 
 void
 octave_qt_link::do_set_workspace (bool top_level, bool debug,
-                                  const std::list<workspace_element>& ws,
+                                  const octave::symbol_scope& scope,
                                   bool update_variable_editor)
 {
   if (! top_level && ! debug)
     return;
 
-  QString scopes;
-  QStringList symbols;
-  QStringList class_names;
-  QStringList dimensions;
-  QStringList values;
-  QIntList complex_flags;
-
-  for (std::list<workspace_element>::const_iterator it = ws.begin ();
-       it != ws.end (); it++)
-    {
-      scopes.append (it->scope ());
-      symbols.append (QString::fromStdString (it->symbol ()));
-      class_names.append (QString::fromStdString (it->class_name ()));
-      dimensions.append (QString::fromStdString (it->dimension ()));
-      values.append (QString::fromStdString (it->value ()));
-      complex_flags.append (it->complex_flag ());
-    }
-
-  emit set_workspace_signal (top_level, debug, scopes, symbols, class_names,
-                             dimensions, values, complex_flags);
+  emit set_workspace_signal (top_level, debug, scope);
 
   if (update_variable_editor)
     emit refresh_variable_editor_signal ();
--- a/libgui/src/octave-qt-link.h	Fri Jan 26 19:50:04 2018 -0800
+++ b/libgui/src/octave-qt-link.h	Sat Jan 27 09:06:50 2018 -0500
@@ -42,6 +42,11 @@
 
 class octave_value;
 
+namespace octave
+{
+  class symbol_scope;
+}
+
 //! Provides threadsafe access to octave.
 //! @author Jacob Dawid
 //!
@@ -112,7 +117,7 @@
   void do_execute_command_in_terminal (const std::string& command);
 
   void do_set_workspace (bool top_level, bool debug,
-                         const std::list<workspace_element>& ws,
+                         const octave::symbol_scope& scope,
                          bool update_variable_editor);
 
   void do_clear_workspace (void);
@@ -171,14 +176,8 @@
 
   void execute_command_in_terminal_signal (const QString& command);
 
-  void set_workspace_signal (bool top_level,
-                             bool debug,
-                             const QString& scopes,
-                             const QStringList& symbols,
-                             const QStringList& class_names,
-                             const QStringList& dimensions,
-                             const QStringList& values,
-                             const QIntList& complex_flags);
+  void set_workspace_signal (bool top_level, bool debug,
+                             const octave::symbol_scope& scope);
 
   void clear_workspace_signal (void);
 
--- a/libgui/src/workspace-model.cc	Fri Jan 26 19:50:04 2018 -0800
+++ b/libgui/src/workspace-model.cc	Sat Jan 27 09:06:50 2018 -0500
@@ -28,7 +28,9 @@
 #include <QTreeWidget>
 #include <QSettings>
 
+#include "symscope.h"
 #include "utils.h"
+
 #include "resource-manager.h"
 #include "workspace-model.h"
 
@@ -225,22 +227,13 @@
 }
 
 void
-workspace_model::set_workspace (bool top_level,
-                                bool /* debug */,
-                                const QString& scopes,
-                                const QStringList& symbols,
-                                const QStringList& class_names,
-                                const QStringList& dimensions,
-                                const QStringList& values,
-                                const QIntList& complex_flags)
+workspace_model::set_workspace (bool top_level, bool /* debug */,
+                                const octave::symbol_scope& scope)
 {
+  clear_data ();
+
   m_top_level = top_level;
-  m_scopes = scopes;
-  m_symbols = symbols;
-  m_class_names = class_names;
-  m_dimensions = dimensions;
-  m_values = values;
-  m_complex_flags = complex_flags;
+  m_scope = scope;
 
   update_table ();
 }
@@ -273,6 +266,7 @@
 workspace_model::clear_data (void)
 {
   m_top_level = false;
+  m_scope = octave::symbol_scope ();
   m_scopes = QString ();
   m_symbols = QStringList ();
   m_class_names = QStringList ();
@@ -286,7 +280,49 @@
 {
   beginResetModel ();
 
-  // Nothing to do except tell the world to recalc.
+  std::list<octave::symbol_record> sr_list = m_scope.all_variables ();
+
+  octave::symbol_record::context_id context = m_scope.current_context ();
+
+  for (const auto& sr : sr_list)
+    {
+      std::string nm = sr.name ();
+
+      octave_value val = sr.varval (context);
+
+      // FIXME: fix size for objects, see kluge in variables.cc
+      //dim_vector dv = val.dims ();
+      octave_value tmp = val;
+      Matrix sz = tmp.size ();
+      dim_vector dv = dim_vector::alloc (sz.numel ());
+      for (octave_idx_type i = 0; i < dv.ndims (); i++)
+        dv(i) = sz(i);
+
+      char storage = ' ';
+      if (sr.is_global ())
+        storage = 'g';
+      else if (sr.is_persistent ())
+        storage = 'p';
+      else if (sr.is_automatic ())
+        storage = 'a';
+      else if (sr.is_formal ())
+        storage = 'f';
+      else if (sr.is_hidden ())
+        storage = 'h';
+      else if (sr.is_inherited ())
+        storage = 'i';
+
+      std::ostringstream buf;
+      val.short_disp (buf);
+      std::string short_disp_str = buf.str ();
+
+      m_scopes.append (storage);
+      m_symbols.append (QString::fromStdString (nm));
+      m_class_names.append (QString::fromStdString (val.class_name ()));
+      m_dimensions.append (QString::fromStdString (dv.str ()));
+      m_values.append (QString::fromStdString (short_disp_str));
+      m_complex_flags.append (val.iscomplex ());
+    }
 
   endResetModel ();
 
--- a/libgui/src/workspace-model.h	Fri Jan 26 19:50:04 2018 -0800
+++ b/libgui/src/workspace-model.h	Sat Jan 27 09:06:50 2018 -0500
@@ -33,6 +33,8 @@
 #include <QColor>
 #include <QSettings>
 
+#include "symscope.h"
+
 // Defined for purposes of sending QList<int> as part of signal.
 typedef QList<int> QIntList;
 
@@ -72,16 +74,12 @@
     return m_storage_class_colors.at (s_class);
   }
 
+  octave::symbol_scope scope (void) const { return m_scope; }
+
 public slots:
 
-  void set_workspace (bool top_level,
-                      bool debug,
-                      const QString& scopes,
-                      const QStringList& symbols,
-                      const QStringList& class_names,
-                      const QStringList& dimensions,
-                      const QStringList& values,
-                      const QIntList& complex_flags);
+  void set_workspace (bool top_level, bool debug,
+                      const octave::symbol_scope& scope);
 
   void clear_workspace (void);
 
@@ -100,6 +98,7 @@
   void update_table (void);
 
   bool m_top_level;
+  octave::symbol_scope m_scope;
   QString m_scopes;
   QStringList m_symbols;
   QStringList m_class_names;
--- a/libgui/src/workspace-view.cc	Fri Jan 26 19:50:04 2018 -0800
+++ b/libgui/src/workspace-view.cc	Sat Jan 27 09:06:50 2018 -0500
@@ -155,8 +155,9 @@
   connect (this, SIGNAL (command_requested (const QString&)),
            p, SLOT (execute_command_in_terminal (const QString&)));
 
-  connect (this, SIGNAL (edit_variable_signal (const QString&)),
-           p, SLOT (edit_variable (const QString&)));
+  connect (this,
+           SIGNAL (edit_variable_signal (const QString&, const octave_value&)),
+           p, SLOT (edit_variable (const QString&, const octave_value&)));
 }
 
 void workspace_view::setModel (workspace_model *model)
@@ -459,13 +460,17 @@
     {
       index = index.sibling (index.row (), 0);
 
-      QAbstractItemModel *m = m_view->model ();
-
-      QMap<int, QVariant> item_data = m->itemData (index);
+      QMap<int, QVariant> item_data = m_model->itemData (index);
 
       QString var_name = item_data[0].toString ();
 
-      emit edit_variable_signal (var_name);
+      octave::symbol_scope scope = m_model->scope ();
+
+      octave_value val;
+      if (scope)
+        val = scope.varval (var_name.toStdString ());
+
+      emit edit_variable_signal (var_name, val);
     }
 }
 
--- a/libgui/src/workspace-view.h	Fri Jan 26 19:50:04 2018 -0800
+++ b/libgui/src/workspace-view.h	Sat Jan 27 09:06:50 2018 -0500
@@ -32,6 +32,8 @@
 #include <QCheckBox>
 #include <QSignalMapper>
 
+#include "ov.h"
+
 #include "octave-dock-widget.h"
 #include "workspace-model.h"
 
@@ -61,7 +63,7 @@
 
   //! Signal that user wants to edit a variable.
 
-  void edit_variable_signal (const QString&);
+  void edit_variable_signal (const QString&, const octave_value&);
 
 protected:
 
--- a/libinterp/corefcn/module.mk	Fri Jan 26 19:50:04 2018 -0800
+++ b/libinterp/corefcn/module.mk	Sat Jan 27 09:06:50 2018 -0500
@@ -91,7 +91,6 @@
   %reldir%/url-handle-manager.h \
   %reldir%/utils.h \
   %reldir%/variables.h \
-  %reldir%/workspace-element.h \
   %reldir%/xdiv.h \
   %reldir%/xnorm.h \
   %reldir%/xpow.h \
--- a/libinterp/corefcn/octave-link.cc	Fri Jan 26 19:50:04 2018 -0800
+++ b/libinterp/corefcn/octave-link.cc	Sat Jan 27 09:06:50 2018 -0500
@@ -71,13 +71,10 @@
       octave::symbol_table& symtab
         = octave::__get_symbol_table__ ("octave_link::set_workspace");
 
-      std::list<workspace_element> workspace_info;
       octave::symbol_scope scope = symtab.current_scope ();
-      if (scope)
-        workspace_info = scope.workspace_info ();
 
       instance->do_set_workspace (symtab.at_top_level (),
-                                  instance->debugging, workspace_info, true);
+                                  instance->debugging, scope, true);
     }
 }
 
--- a/libinterp/corefcn/octave-link.h	Fri Jan 26 19:50:04 2018 -0800
+++ b/libinterp/corefcn/octave-link.h	Sat Jan 27 09:06:50 2018 -0500
@@ -36,7 +36,11 @@
 
 class octave_value;
 class string_vector;
-class workspace_element;
+
+namespace octave
+{
+  class symbol_scope;
+}
 
 //! Provides threadsafe access to octave.
 //! @author Jacob Dawid
@@ -261,11 +265,11 @@
   static void set_workspace (void);
 
   static void set_workspace (bool top_level,
-                             const std::list<workspace_element>& ws,
+                             const octave::symbol_scope& scope,
                              bool update_variable_editor = true)
   {
     if (enabled ())
-      instance->do_set_workspace (top_level, instance->debugging, ws,
+      instance->do_set_workspace (top_level, instance->debugging, scope,
                                   update_variable_editor);
   }
 
@@ -548,7 +552,7 @@
 
   virtual void
   do_set_workspace (bool top_level, bool debug,
-                    const std::list<workspace_element>& ws,
+                    const octave::symbol_scope& scope,
                     bool update_variable_editor) = 0;
 
   virtual void do_clear_workspace (void) = 0;
--- a/libinterp/corefcn/symscope.cc	Fri Jan 26 19:50:04 2018 -0800
+++ b/libinterp/corefcn/symscope.cc	Sat Jan 27 09:06:50 2018 -0500
@@ -107,60 +107,6 @@
       return p->second;
   }
 
-  std::list<workspace_element>
-  symbol_scope_rep::workspace_info (void) const
-  {
-    std::list<workspace_element> retval;
-
-    for (const auto& nm_sr : m_symbols)
-      {
-        std::string nm = nm_sr.first;
-        symbol_record sr = nm_sr.second;
-
-        if (! sr.is_hidden ())
-          {
-            octave_value val = sr.varval (m_context);
-
-            if (val.is_defined ())
-              {
-                // FIXME: fix size for objects, see kluge in variables.cc
-                //dim_vector dv = val.dims ();
-                octave_value tmp = val;
-                Matrix sz = tmp.size ();
-                dim_vector dv = dim_vector::alloc (sz.numel ());
-                for (octave_idx_type i = 0; i < dv.ndims (); i++)
-                  dv(i) = sz(i);
-
-                char storage = ' ';
-                if (sr.is_global ())
-                  storage = 'g';
-                else if (sr.is_persistent ())
-                  storage = 'p';
-                else if (sr.is_automatic ())
-                  storage = 'a';
-                else if (sr.is_formal ())
-                  storage = 'f';
-                else if (sr.is_hidden ())
-                  storage = 'h';
-                else if (sr.is_inherited ())
-                  storage = 'i';
-
-                std::ostringstream buf;
-                val.short_disp (buf);
-                std::string short_disp_str = buf.str ();
-
-                workspace_element elt (storage, nm, val.class_name (),
-                                       short_disp_str, dv.str (),
-                                       val.iscomplex ());
-
-                retval.push_back (elt);
-              }
-          }
-      }
-
-    return retval;
-  }
-
   octave_value
   symbol_scope_rep::dump (void) const
   {
--- a/libinterp/corefcn/symscope.h	Fri Jan 26 19:50:04 2018 -0800
+++ b/libinterp/corefcn/symscope.h	Sat Jan 27 09:06:50 2018 -0500
@@ -44,7 +44,6 @@
 #include "ov.h"
 #include "ovl.h"
 #include "symrec.h"
-#include "workspace-element.h"
 
 namespace octave
 {
@@ -499,8 +498,6 @@
       return m_subfunction_names;
     }
 
-    std::list<workspace_element> workspace_info (void) const;
-
     octave_value dump (void) const;
 
     std::string name (void) const { return m_name; }
@@ -871,13 +868,6 @@
       return m_rep ? m_rep->subfunction_names () : std::list<std::string> ();
     }
 
-    std::list<workspace_element> workspace_info (void) const
-    {
-      return (m_rep
-              ? m_rep->workspace_info ()
-              : std::list<workspace_element> ());
-    }
-
     octave_value dump (void) const
     {
       return m_rep ? m_rep->dump () : octave_value ();
--- a/libinterp/corefcn/symtab.h	Fri Jan 26 19:50:04 2018 -0800
+++ b/libinterp/corefcn/symtab.h	Sat Jan 27 09:06:50 2018 -0500
@@ -44,7 +44,6 @@
 #include "ov.h"
 #include "ovl.h"
 #include "symscope.h"
-#include "workspace-element.h"
 
 namespace octave
 {
--- a/libinterp/corefcn/workspace-element.h	Fri Jan 26 19:50:04 2018 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/*
-
-Copyright (C) 2013-2017 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Octave is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<https://www.gnu.org/licenses/>.
-
-*/
-
-#if ! defined (octave_workspace_element_h)
-#define octave_workspace_element_h 1
-
-#include "octave-config.h"
-
-#include <string>
-
-class workspace_element
-{
-public:
-
-  workspace_element (char scope_arg = 'l',
-                     const std::string& symbol_arg = "<name>",
-                     const std::string& class_name_arg = "<class>",
-                     const std::string& value_arg = "<value>",
-                     const std::string& dimension_arg = "<dimension>",
-                     bool complex_flag_arg = false)
-    : xscope (scope_arg), xsymbol (symbol_arg),
-      xclass_name (class_name_arg), xvalue (value_arg),
-      xdimension (dimension_arg), xcomplex_flag (complex_flag_arg)
-  { }
-
-  workspace_element (const workspace_element& ws_elt)
-    : xscope (ws_elt.xscope), xsymbol (ws_elt.xsymbol),
-      xclass_name (ws_elt.xclass_name), xvalue (ws_elt.xvalue),
-      xdimension (ws_elt.xdimension), xcomplex_flag (ws_elt.xcomplex_flag)
-  { }
-
-  workspace_element operator = (const workspace_element& ws_elt)
-  {
-    if (this != &ws_elt)
-      {
-        xscope = ws_elt.xscope;
-        xsymbol = ws_elt.xsymbol;
-        xclass_name = ws_elt.xclass_name;
-        xvalue = ws_elt.xvalue;
-        xdimension = ws_elt.xdimension;
-        xcomplex_flag = ws_elt.xcomplex_flag;
-      }
-
-    return *this;
-  }
-
-  ~workspace_element (void) = default;
-
-  char scope (void) const { return xscope; }
-
-  std::string symbol (void) const { return xsymbol; }
-
-  std::string class_name (void) const { return xclass_name; }
-
-  std::string value (void) const { return xvalue; }
-
-  std::string dimension (void) const { return xdimension; }
-
-  bool complex_flag (void) const { return xcomplex_flag; }
-
-private:
-
-  // [g]lobal, [p]ersistent, [l]ocal
-  char xscope;
-  std::string xsymbol;
-  std::string xclass_name;
-  std::string xvalue;
-  std::string xdimension;
-  bool xcomplex_flag;
-};
-
-#endif