changeset 24641:7d177be54c37

pass variable value to variable editor in addition to variable name * main-window.h, main-window.cc (main_window::edit_variable): Also pass value. Change all uses. * octave-qt-link.h, octave-qt-link.cc (octave_qt_link::octave_qt_link): Call qRegisterMetaType for octave_value. (octave_qt_link::do_edit_variable): Rename from octave_qt_link::do_openvar. Change all uses. (edit_variable_signal): Rename from open_variable_signal. * variable-editor-model.h, variable-editor-model.cc (variable_editor_model::variable_editor_model): Also pass value. Change all uses. * variable-editor.h, variable-editor.cc (variable_editor::edit_variable): Also pass value. Change all uses. Align label at top of vbox layout. * octave-link.h, octave-link.cc (Fopenvar): Use DEFMETHOD. Get value from current scope and pass to octave_link::edit_variable. (octave_link::edit_variable): Rename from octave_link::openvar. Change all uses. (octave_link::do_edit_variable): Rename from octave_link::do_openvar. Change all uses.
author John W. Eaton <jwe@octave.org>
date Thu, 25 Jan 2018 23:59:57 -0500
parents 534436fd5607
children d58543eb53e9
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-qt-link.cc libgui/src/octave-qt-link.h libgui/src/variable-editor-model.cc libgui/src/variable-editor-model.h libgui/src/variable-editor.cc libgui/src/variable-editor.h libinterp/corefcn/octave-link.cc libinterp/corefcn/octave-link.h
diffstat 10 files changed, 53 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Tue Jan 23 14:36:00 2018 -0500
+++ b/libgui/src/main-window.cc	Thu Jan 25 23:59:57 2018 -0500
@@ -1736,9 +1736,9 @@
 }
 
 void
-main_window::edit_variable (const QString &expr)
+main_window::edit_variable (const QString &expr, const octave_value& val)
 {
-  m_variable_editor_window->edit_variable (expr);
+  m_variable_editor_window->edit_variable (expr, val);
 
   if (! m_variable_editor_window->isVisible ())
     {
@@ -1804,8 +1804,11 @@
       connect (m_workspace_model, SIGNAL (model_changed (void)),
                m_workspace_window, SLOT (handle_model_changed (void)));
 
-      connect (m_octave_qt_link, SIGNAL (open_variable_signal (const QString&)),
-               this, SLOT (edit_variable (const QString&)));
+      connect (m_octave_qt_link,
+               SIGNAL (edit_variable_signal (const QString&,
+                                             const octave_value&)),
+               this,
+               SLOT (edit_variable (const QString&, const octave_value&)));
 
       connect (m_octave_qt_link, SIGNAL (refresh_variable_editor_signal (void)),
                this, SLOT (refresh_variable_editor (void)));
--- a/libgui/src/main-window.h	Tue Jan 23 14:36:00 2018 -0500
+++ b/libgui/src/main-window.h	Thu Jan 25 23:59:57 2018 -0500
@@ -64,6 +64,8 @@
 
 class settings_dialog;
 
+class octave_value;
+
 //! QObject to manage the Octave interpreter.
 
 class octave_interpreter : public QObject
@@ -282,7 +284,7 @@
 
   //! Opens the variable editor for @p name.
 
-  void edit_variable (const QString &name);
+  void edit_variable (const QString &name, const octave_value&);
 
   void refresh_variable_editor (void);
 
--- a/libgui/src/octave-qt-link.cc	Tue Jan 23 14:36:00 2018 -0500
+++ b/libgui/src/octave-qt-link.cc	Thu Jan 25 23:59:57 2018 -0500
@@ -26,10 +26,11 @@
 #  include "config.h"
 #endif
 
-#include <QStringList>
 #include <QDialog>
 #include <QDir>
+#include <QMetaType>
 #include <QPushButton>
+#include <QStringList>
 
 #include "oct-env.h"
 #include "str-vec.h"
@@ -39,6 +40,7 @@
 #include "error.h"
 #include "interpreter-private.h"
 #include "load-path.h"
+#include "ov.h"
 #include "utils.h"
 
 #include "octave-gui.h"
@@ -49,7 +51,9 @@
 octave_qt_link::octave_qt_link (QWidget *,
                                 octave::gui_application *app_context)
   : octave_link (), m_app_context (app_context)
-{ }
+{
+  qRegisterMetaType<octave_value> ("octave_value");
+}
 
 bool
 octave_qt_link::do_confirm_shutdown (void)
@@ -616,9 +620,9 @@
 }
 
 void
-octave_qt_link::do_openvar (const std::string &expr)
+octave_qt_link::do_edit_variable (const std::string& expr, const octave_value& val)
 {
-  emit open_variable_signal (QString::fromStdString (expr));
+  emit edit_variable_signal (QString::fromStdString (expr), val);
 }
 
 void
--- a/libgui/src/octave-qt-link.h	Tue Jan 23 14:36:00 2018 -0500
+++ b/libgui/src/octave-qt-link.h	Thu Jan 25 23:59:57 2018 -0500
@@ -40,6 +40,8 @@
 // Defined for purposes of sending QList<int> as part of signal.
 typedef QList<int> QIntList;
 
+class octave_value;
+
 //! Provides threadsafe access to octave.
 //! @author Jacob Dawid
 //!
@@ -138,7 +140,7 @@
 
   void do_show_doc (const std::string& file);
 
-  void do_openvar (const std::string &name);
+  void do_edit_variable (const std::string& name, const octave_value& val);
 
   void shutdown_confirmation (bool sd) { m_shutdown_confirm_result = sd; }
 
@@ -197,7 +199,7 @@
 
   void show_doc_signal (const QString& file);
 
-  void open_variable_signal (const QString &name);
+  void edit_variable_signal (const QString& name, const octave_value& val);
 
   void refresh_variable_editor_signal (void);
 
--- a/libgui/src/variable-editor-model.cc	Tue Jan 23 14:36:00 2018 -0500
+++ b/libgui/src/variable-editor-model.cc	Thu Jan 25 23:59:57 2018 -0500
@@ -214,6 +214,7 @@
 };
 
 variable_editor_model::variable_editor_model (const QString& expr,
+                                              const octave_value&,
                                               QLabel *label,
                                               QObject *parent)
   : QAbstractTableModel (parent), m_parent (parent), m_d (new impl (expr, label))
--- a/libgui/src/variable-editor-model.h	Tue Jan 23 14:36:00 2018 -0500
+++ b/libgui/src/variable-editor-model.h	Thu Jan 25 23:59:57 2018 -0500
@@ -46,8 +46,8 @@
 
 public:
 
-  variable_editor_model (const QString &expr, QLabel *label,
-                         QObject *p = nullptr);
+  variable_editor_model (const QString &expr, const octave_value& val,
+                         QLabel *label, QObject *p = nullptr);
 
   ~variable_editor_model (void);
 
--- a/libgui/src/variable-editor.cc	Tue Jan 23 14:36:00 2018 -0500
+++ b/libgui/src/variable-editor.cc	Thu Jan 25 23:59:57 2018 -0500
@@ -109,8 +109,10 @@
 
   m_tab_widget->setTabsClosable (true);
   m_tab_widget->setMovable (true);
+
   connect (m_tab_widget, SIGNAL (tabCloseRequested (int)),
            this, SLOT (closeTab (int)));
+
   m_main->setCentralWidget (m_tab_widget);
 
   // Main.
@@ -130,7 +132,7 @@
 }
 
 void
-variable_editor::edit_variable (const QString& name)
+variable_editor::edit_variable (const QString& name, const octave_value& val)
 {
   if (m_stylesheet.isEmpty ())
     {
@@ -160,11 +162,11 @@
   QLabel *label = new QLabel (page);
   label->setTextFormat (Qt::PlainText);
   label->setText (name);
-  vbox->addWidget (label);
+  vbox->addWidget (label, 0, Qt::AlignTop);
 
   QTableView *table = new QTableView (page);
   variable_editor_model *model =
-    new variable_editor_model (name, label, table);
+    new variable_editor_model (name, val, label, table);
 
   table->setModel (model);
   table->setWordWrap (false);
@@ -778,7 +780,7 @@
     = qobject_cast<variable_editor_model *> (table->model ());
 
   if (model->requires_sub_editor (idx))
-    edit_variable (name + model->subscript_expression (idx));
+    edit_variable (name + model->subscript_expression (idx), octave_value ());
 }
 
 void
@@ -1012,7 +1014,7 @@
   if (name.endsWith (')') || name.endsWith ('}'))
     {
       name.remove (QRegExp ("(\\(|\\{)[^({]*(\\)|\\})$"));
-      edit_variable (name);
+      edit_variable (name, octave_value ());
 
       // FIXME: What was the intent here?
       // emit command_requested (QString ("openvar ('%1');").arg (name));
--- a/libgui/src/variable-editor.h	Tue Jan 23 14:36:00 2018 -0500
+++ b/libgui/src/variable-editor.h	Thu Jan 25 23:59:57 2018 -0500
@@ -30,6 +30,8 @@
 
 #include "octave-dock-widget.h"
 
+class octave_value;
+
 class QTabWidget;
 class QToolBar;
 class QMainWindow;
@@ -52,7 +54,7 @@
 
   variable_editor& operator = (const variable_editor&) = delete;
 
-  void edit_variable (const QString& name);
+  void edit_variable (const QString& name, const octave_value& val);
 
   // Clear all the models' data cache.
   void clear_data_cache (void);
--- a/libinterp/corefcn/octave-link.cc	Tue Jan 23 14:36:00 2018 -0500
+++ b/libinterp/corefcn/octave-link.cc	Thu Jan 25 23:59:57 2018 -0500
@@ -36,6 +36,7 @@
 #include "oct-mutex.h"
 #include "ovl.h"
 #include "pager.h"
+#include "symscope.h"
 
 static int
 octave_readline_hook (void)
@@ -384,8 +385,8 @@
   return ovl (octave_link::show_preferences ());
 }
 
-DEFUN (openvar, args, ,
-       doc: /* -*- texinfo -*-
+DEFMETHOD (openvar, interp, args, ,
+           doc: /* -*- texinfo -*-
 @deftypefn {} {} openvar (@var{name})
 Open the variable @var{name} in the graphical Variable Editor.
 @end deftypefn */)
@@ -401,7 +402,16 @@
   if (! (Fisguirunning ())(0).is_true ())
     warning ("openvar: GUI is not running, can't start Variable Editor");
   else
-    octave_link::openvar (name);
+    {
+      octave::symbol_scope scope = interp.require_current_scope ("openvar");
+
+      octave_value val = scope.varval (name);
+
+      if (val.is_undefined ())
+        error ("openvar: '%s' is not a variable", name.c_str ());
+
+      octave_link::edit_variable (name, val);
+    }
 
   return ovl ();
 }
--- a/libinterp/corefcn/octave-link.h	Tue Jan 23 14:36:00 2018 -0500
+++ b/libinterp/corefcn/octave-link.h	Thu Jan 25 23:59:57 2018 -0500
@@ -34,6 +34,7 @@
 
 #include "event-queue.h"
 
+class octave_value;
 class string_vector;
 class workspace_element;
 
@@ -418,11 +419,11 @@
   }
 
   static bool
-  openvar (const std::string &name)
+  edit_variable (const std::string &name, const octave_value& val)
   {
     if (enabled ())
       {
-        instance->do_openvar (name);
+        instance->do_edit_variable (name, val);
         return true;
       }
     else
@@ -578,7 +579,8 @@
 
   virtual void do_show_doc (const std::string& file) = 0;
 
-  virtual void do_openvar (const std::string& name) = 0;
+  virtual void
+  do_edit_variable (const std::string& name, const octave_value& val) = 0;
 };
 
 #endif