Mercurial > octave
changeset 29774:aa46787ed8b7
eliminate direct dependence on octave intepreter from workspace_view
* octave-qobject.cc (base_qobject::workspace_widget):
Connect workspace_view::edit_variable_signal to lambda expression that
emits interpreter_event that will find value and use the event manager
to open the variable editor instead of connecting to
base_qobject::show_variable_editor_window.
Connect workspace_view::copy_variable_value_to_clipboard to a lambda
expression that emits an interpreter_event to find the value and copy
it to the clipboard.
* workspace-view.h, workspace-view.cc: Don't include octave
interpreter header files in workspace-view source files.
(workspace_view::edit_variable_signal): Eliminate octave_value
argument. Expect receiver to find the variable value given the name.
(workspace_view::copy_variable_value_to_clipboard): New signal.
(workspace_view::handle_contextmenu_copy_value): Simply emit
copy_variable_value_to_clipboard signal.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 17 Jun 2021 15:43:08 -0400 |
parents | 5f404ae822ee |
children | a64352cadda8 |
files | libgui/src/octave-qobject.cc libgui/src/workspace-view.cc libgui/src/workspace-view.h |
diffstat | 3 files changed, 46 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/octave-qobject.cc Thu Jun 17 14:11:04 2021 -0400 +++ b/libgui/src/octave-qobject.cc Thu Jun 17 15:43:08 2021 -0400 @@ -508,8 +508,29 @@ connect (qt_link (), &qt_interpreter_events::clear_workspace_signal, m_workspace_model, &workspace_model::clear_workspace); - connect (m_workspace_widget, &workspace_view::edit_variable_signal, - this, &base_qobject::show_variable_editor_window); + connect (m_workspace_widget, + &workspace_view::copy_variable_value_to_clipboard, + [=] (const QString& var_name) { + emit interpreter_event + ([=] (interpreter& interp) + { + // INTERPRETER THREAD + + octave_value val = interp.varval (var_name.toStdString ()); + + if (val.is_undefined ()) + val = 0; + + std::ostringstream buf; + val.print_raw (buf, true); + + // FIXME: is the following operation thread safe or should + // it be done with a signal/slot connection? + + QClipboard *clipboard = QApplication::clipboard (); + clipboard->setText (QString::fromStdString (buf.str ())); + }); + }); connect (m_workspace_widget, &workspace_view::rename_variable_signal, [=] (const QString& old_name, const QString& new_name) { @@ -535,6 +556,21 @@ // display that info in the GUI? }); }); + + connect (m_workspace_widget, &workspace_view::edit_variable_signal, + [=] (const QString& var_name) { + emit interpreter_event + ([=] (interpreter& interp) { + // INTERPRETER THREAD + + std::string name = var_name.toStdString (); + octave_value val = interp.varval (name); + + event_manager& xevmgr = interp.get_event_manager (); + + xevmgr.edit_variable (name, val); + }); + }); } return m_workspace_widget;
--- a/libgui/src/workspace-view.cc Thu Jun 17 14:11:04 2021 -0400 +++ b/libgui/src/workspace-view.cc Thu Jun 17 15:43:08 2021 -0400 @@ -46,10 +46,6 @@ #include "octave-qtutils.h" #include "workspace-view.h" -#include "interpreter-private.h" -#include "interpreter.h" -#include "syminfo.h" - namespace octave { workspace_view::workspace_view (QWidget *p, base_qobject& oct_qobj) @@ -429,29 +425,7 @@ QModelIndex index = m_view->currentIndex (); if (index.isValid ()) - { - QString var_name = get_var_name (index); - - emit interpreter_event - ([=] (interpreter& interp) - { - // INTERPRETER THREAD - - octave_value val = interp.varval (var_name.toStdString ()); - - if (val.is_undefined ()) - val = 0; - - std::ostringstream buf; - val.print_raw (buf, true); - - // FIXME: is the following operation thread safe or should - // it be done with a signal/slot connection? - - QClipboard *clipboard = QApplication::clipboard (); - clipboard->setText (QString::fromStdString (buf.str ())); - }); - } + emit copy_variable_value_to_clipboard (get_var_name (index)); } void @@ -484,14 +458,7 @@ QModelIndex index = m_view->currentIndex (); if (index.isValid ()) - { - QString var_name = get_var_name (index); - - symbol_info_list syminfo = m_model->get_symbol_info (); - octave_value val = syminfo.varval (var_name.toStdString ()); - - emit edit_variable_signal (var_name, val); - } + emit edit_variable_signal (get_var_name (index)); } void
--- a/libgui/src/workspace-view.h Thu Jun 17 14:11:04 2021 -0400 +++ b/libgui/src/workspace-view.h Thu Jun 17 15:43:08 2021 -0400 @@ -37,8 +37,6 @@ #include "octave-dock-widget.h" #include "workspace-model.h" -class octave_value; - namespace octave { class base_qobject; @@ -59,13 +57,18 @@ void command_requested (const QString& cmd); + //! Signal that user wnats to copy a variable value to the + //! clipboard. + + void copy_variable_value_to_clipboard (const QString&); + //! Signal that user wants to rename a variable. void rename_variable_signal (const QString&, const QString&); //! Signal that user wants to edit a variable. - void edit_variable_signal (const QString&, const octave_value&); + void edit_variable_signal (const QString&); public slots: