Mercurial > octave
changeset 27196:d993642352d0
rename octave_interpreter object in GUI
* interpreter-qobject.h, interpreter-qobject.cc: New files. Move
octave_interpreter object here from main-window.h and main-window.cc
and rename to interpreter_qobject so that it will (I hope) be clearer
that this object provides a QObject wrapper around Octave's
interpreter object. Change all uses.
* libgui/src/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 21 Jun 2019 14:41:04 -0500 |
parents | d6316d22db34 |
children | b8c0d5ad024f |
files | libgui/src/interpreter-qobject.cc libgui/src/interpreter-qobject.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/module.mk |
diffstat | 5 files changed, 161 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/interpreter-qobject.cc Fri Jun 21 14:41:04 2019 -0500 @@ -0,0 +1,86 @@ +/* + +Copyright (C) 2013-2019 John W. Eaton +Copyright (C) 2011-2019 Jacob Dawid + +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 (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "interpreter-qobject.h" +#include "octave-gui.h" + +#include "input.h" +#include "interpreter.h" + +namespace octave +{ + interpreter_qobject::interpreter_qobject (gui_application& app_context) + : QObject (), m_app_context (app_context) + { } + + void interpreter_qobject::execute (void) + { + // The application context owns the interpreter. + + interpreter& interp = m_app_context.create_interpreter (); + + int exit_status = 0; + + try + { + // Final initialization. + + interp.initialize (); + + if (m_app_context.start_gui_p ()) + { + input_system& input_sys = interp.get_input_system (); + + input_sys.PS1 (">> "); + input_sys.PS2 (""); + } + + if (interp.initialized ()) + { + // The interpreter should be completely ready at this point so let + // the GUI know. + + emit octave_ready_signal (); + + // Start executing commands in the command window. + + exit_status = interp.execute (); + } + } + catch (const exit_exception& ex) + { + exit_status = ex.exit_status (); + } + + // Whether or not initialization succeeds we need to clean up the + // interpreter once we are done with it. + + m_app_context.delete_interpreter (); + + emit octave_finished_signal (exit_status); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/interpreter-qobject.h Fri Jun 21 14:41:04 2019 -0500 @@ -0,0 +1,60 @@ +/* + +Copyright (C) 2013-2019 John W. Eaton +Copyright (C) 2011-2019 Jacob Dawid + +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_interpreter_qobject_h) +#define octave_interpreter_qobject_h 1 + +#include <QObject> + +namespace octave +{ + class gui_application; + + class interpreter_qobject : public QObject + { + Q_OBJECT + + public: + + interpreter_qobject (gui_application& app_context); + + ~interpreter_qobject (void) = default; + + signals: + + void octave_ready_signal (void); + void octave_finished_signal (int); + + public slots: + + //! Initialize and execute the octave interpreter. + + void execute (void); + + private: + + gui_application& m_app_context; + }; +} + +#endif
--- a/libgui/src/main-window.cc Fri Jun 21 15:06:55 2019 -0500 +++ b/libgui/src/main-window.cc Fri Jun 21 14:41:04 2019 -0500 @@ -55,6 +55,7 @@ #if defined (HAVE_QSCINTILLA) # include "file-editor.h" #endif +#include "interpreter-qobject.h" #include "main-window.h" #include "news-reader.h" #include "settings-dialog.h" @@ -105,57 +106,6 @@ #endif { } - octave_interpreter::octave_interpreter (gui_application& app_context) - : QObject (), m_app_context (app_context) - { } - - void octave_interpreter::execute (void) - { - // The application context owns the interpreter. - - interpreter& interp = m_app_context.create_interpreter (); - - int exit_status = 0; - - try - { - // Final initialization. - - interp.initialize (); - - if (m_app_context.start_gui_p ()) - { - input_system& input_sys = interp.get_input_system (); - - input_sys.PS1 (">> "); - input_sys.PS2 (""); - } - - if (interp.initialized ()) - { - // The interpreter should be completely ready at this point so let - // the GUI know. - - emit octave_ready_signal (); - - // Start executing commands in the command window. - - exit_status = interp.execute (); - } - } - catch (const exit_exception& ex) - { - exit_status = ex.exit_status (); - } - - // Whether or not initialization succeeds we need to clean up the - // interpreter once we are done with it. - - m_app_context.delete_interpreter (); - - emit octave_finished_signal (exit_status); - } - main_window::main_window (octave_qt_app& oct_qt_app, octave_qt_link *oct_qt_lnk) : QMainWindow (), @@ -2726,7 +2676,7 @@ m_qt_tr (new QTranslator ()), m_gui_tr (new QTranslator ()), m_qsci_tr (new QTranslator ()), m_translators_installed (false), m_octave_qt_link (new octave_qt_link ()), - m_interpreter (new octave_interpreter (m_app_context)), + m_interpreter_qobject (new interpreter_qobject (m_app_context)), m_main_thread (new QThread ()) { std::string show_gui_msgs = @@ -2780,10 +2730,10 @@ connect_uiwidget_links (); - connect (m_interpreter, SIGNAL (octave_finished_signal (int)), + connect (m_interpreter_qobject, SIGNAL (octave_finished_signal (int)), this, SLOT (handle_octave_finished (int))); - connect (m_interpreter, SIGNAL (octave_finished_signal (int)), + connect (m_interpreter_qobject, SIGNAL (octave_finished_signal (int)), m_main_thread, SLOT (quit (void))); connect (m_main_thread, SIGNAL (finished (void)), @@ -2792,7 +2742,7 @@ octave_qt_app::~octave_qt_app (void) { - delete m_interpreter; + delete m_interpreter_qobject; delete m_qt_app; string_vector::delete_c_str_vec (m_argv); @@ -2816,9 +2766,9 @@ { // Defer initializing and executing the interpreter until after the main // window and QApplication are running to prevent race conditions - QTimer::singleShot (0, m_interpreter, SLOT (execute (void))); - - m_interpreter->moveToThread (m_main_thread); + QTimer::singleShot (0, m_interpreter_qobject, SLOT (execute (void))); + + m_interpreter_qobject->moveToThread (m_main_thread); m_main_thread->start (); } @@ -3003,7 +2953,7 @@ : octave_qt_app (app_context), m_main_window (new main_window (*this, m_octave_qt_link)) { - connect (m_interpreter, SIGNAL (octave_ready_signal (void)), + connect (m_interpreter_qobject, SIGNAL (octave_ready_signal (void)), m_main_window, SLOT (handle_octave_ready (void))); m_app_context.gui_running (true);
--- a/libgui/src/main-window.h Fri Jun 21 15:06:55 2019 -0500 +++ b/libgui/src/main-window.h Fri Jun 21 14:41:04 2019 -0500 @@ -66,32 +66,6 @@ { class settings_dialog; - class octave_interpreter : public QObject - { - Q_OBJECT - - public: - - octave_interpreter (gui_application& app_context); - - ~octave_interpreter (void) = default; - - signals: - - void octave_ready_signal (void); - void octave_finished_signal (int); - - public slots: - - //! Initialize and execute the octave interpreter. - - void execute (void); - - private: - - gui_application& m_app_context; - }; - class octave_qt_app; //! Represents the main window. @@ -480,6 +454,8 @@ ~octave_qapplication (void) { }; }; + class interpreter_qobject; + class octave_qt_app : public QObject { Q_OBJECT @@ -549,7 +525,7 @@ octave_qt_link *m_octave_qt_link; - octave_interpreter *m_interpreter; + interpreter_qobject *m_interpreter_qobject; QThread *m_main_thread;
--- a/libgui/src/module.mk Fri Jun 21 15:06:55 2019 -0500 +++ b/libgui/src/module.mk Fri Jun 21 14:41:04 2019 -0500 @@ -138,6 +138,7 @@ %reldir%/moc-dw-main-window.cc \ %reldir%/moc-files-dock-widget.cc \ %reldir%/moc-history-dock-widget.cc \ + %reldir%/moc-interpreter-qobject.cc \ %reldir%/moc-main-window.cc \ %reldir%/moc-news-reader.cc \ %reldir%/moc-octave-cmd.cc \ @@ -188,6 +189,7 @@ %reldir%/external-editor-interface.h \ %reldir%/files-dock-widget.h \ %reldir%/history-dock-widget.h \ + %reldir%/interpreter-qobject.h \ %reldir%/m-editor/file-editor-interface.h \ %reldir%/m-editor/file-editor-tab.h \ %reldir%/m-editor/file-editor.h \ @@ -222,6 +224,7 @@ %reldir%/external-editor-interface.cc \ %reldir%/files-dock-widget.cc \ %reldir%/history-dock-widget.cc \ + %reldir%/interpreter-qobject.cc \ %reldir%/m-editor/file-editor-tab.cc \ %reldir%/m-editor/file-editor.cc \ %reldir%/m-editor/find-dialog.cc \