Mercurial > octave
changeset 27194:f0f3e6856947
define octave_qt_gui_app and octave_qt_cli_app separately
* main-window.h, main-window.cc (octave_qt_gui_app,
octave_qt_cli_app): New classes derived from octave_qt_app. Store
pointer to main_window object in octave_qt_gui_app instead of
octave_qt_app.
(octave_qt_app::confirm_shutdown_octave): Now virtual.
(octave_qt_app::confirm_shutdown_octave_internal): New function.
* octave-gui.cc (gui_application::execute): Make decision about
creating GUI or CLI app here instead of inside octave_qt_app class.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 21 Jun 2019 14:17:02 -0500 |
parents | 01e73e1664ff |
children | d6316d22db34 |
files | libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-gui.cc |
diffstat | 3 files changed, 109 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc Fri Jun 21 10:10:54 2019 -0500 +++ b/libgui/src/main-window.cc Fri Jun 21 14:17:02 2019 -0500 @@ -2727,8 +2727,7 @@ 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_main_thread (new QThread ()), - m_main_window (nullptr) + m_main_thread (new QThread ()) { std::string show_gui_msgs = sys::env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); @@ -2789,32 +2788,10 @@ connect (m_main_thread, SIGNAL (finished (void)), m_main_thread, SLOT (deleteLater (void))); - - if (m_app_context.start_gui_p ()) - create_main_window (); - else - { - // Get settings file. - resource_manager::reload_settings (); - - // After settings. - config_translators (); - - m_qt_app->setQuitOnLastWindowClosed (false); - } - - // 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); - - m_main_thread->start (); } octave_qt_app::~octave_qt_app (void) { - delete m_main_window; delete m_interpreter; delete m_qt_app; @@ -2835,14 +2812,15 @@ m_translators_installed = true; } - void octave_qt_app::create_main_window (void) + void octave_qt_app::start_main_thread (void) { - m_main_window = new main_window (*this, m_octave_qt_link); - - connect (m_interpreter, SIGNAL (octave_ready_signal (void)), - m_main_window, SLOT (handle_octave_ready (void))); - - m_app_context.gui_running (true); + // 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); + + m_main_thread->start (); } int octave_qt_app::exec (void) @@ -2857,20 +2835,7 @@ void octave_qt_app::confirm_shutdown_octave (void) { - bool closenow = true; - - if (m_main_window) - closenow = m_main_window->confirm_shutdown_octave (); - - // Wait for link thread to go to sleep state. - m_octave_qt_link->lock (); - - m_octave_qt_link->shutdown_confirmation (closenow); - - m_octave_qt_link->unlock (); - - // Awake the worker thread so that it continues shutting down (or not). - m_octave_qt_link->wake_all (); + confirm_shutdown_octave_internal (true); } void octave_qt_app::copy_image_to_clipboard (const QString& file, @@ -3006,4 +2971,58 @@ const QString&, const QString&, const QString&))); } + + void octave_qt_app::confirm_shutdown_octave_internal (bool closenow) + { + // Wait for link thread to go to sleep state. + m_octave_qt_link->lock (); + + m_octave_qt_link->shutdown_confirmation (closenow); + + m_octave_qt_link->unlock (); + + // Awake the worker thread so that it continues shutting down (or not). + m_octave_qt_link->wake_all (); + } + + octave_qt_cli_app::octave_qt_cli_app (gui_application& app_context) + : octave_qt_app (app_context) + { + // Get settings file. + resource_manager::reload_settings (); + + // After settings. + config_translators (); + + m_qt_app->setQuitOnLastWindowClosed (false); + + start_main_thread (); + } + + octave_qt_gui_app::octave_qt_gui_app (gui_application& app_context) + : octave_qt_app (app_context), + m_main_window (new main_window (*this, m_octave_qt_link)) + { + connect (m_interpreter, SIGNAL (octave_ready_signal (void)), + m_main_window, SLOT (handle_octave_ready (void))); + + m_app_context.gui_running (true); + + start_main_thread (); + } + + octave_qt_gui_app::~octave_qt_gui_app (void) + { + delete m_main_window; + } + + void octave_qt_gui_app::confirm_shutdown_octave (void) + { + bool closenow = true; + + if (m_main_window) + closenow = m_main_window->confirm_shutdown_octave (); + + confirm_shutdown_octave_internal (closenow); + } }
--- a/libgui/src/main-window.h Fri Jun 21 10:10:54 2019 -0500 +++ b/libgui/src/main-window.h Fri Jun 21 14:17:02 2019 -0500 @@ -492,7 +492,7 @@ void config_translators (void); - void create_main_window (void); + void start_main_thread (void); int exec (void); @@ -502,7 +502,7 @@ void handle_octave_finished (int); - void confirm_shutdown_octave (void); + virtual void confirm_shutdown_octave (void); void copy_image_to_clipboard (const QString& file, bool remove_file); @@ -529,7 +529,7 @@ const QString& dirname, const QString& multimode); - private: + protected: gui_application& m_app_context; @@ -553,9 +553,39 @@ QThread *m_main_thread; - main_window *m_main_window; + void connect_uiwidget_links (void); + + void confirm_shutdown_octave_internal (bool closenow); + }; + + class octave_qt_cli_app : public octave_qt_app + { + Q_OBJECT + + public: + + octave_qt_cli_app (gui_application& app_context); + + ~octave_qt_cli_app (void) = default; + }; - void connect_uiwidget_links (void); + class octave_qt_gui_app : public octave_qt_app + { + Q_OBJECT + + public: + + octave_qt_gui_app (gui_application& app_context); + + ~octave_qt_gui_app (void); + + public slots: + + void confirm_shutdown_octave (void); + + private: + + main_window *m_main_window; }; }
--- a/libgui/src/octave-gui.cc Fri Jun 21 10:10:54 2019 -0500 +++ b/libgui/src/octave-gui.cc Fri Jun 21 14:17:02 2019 -0500 @@ -59,8 +59,15 @@ // Create and show main window. - octave_qt_app oct_qt_app (*this); - - return oct_qt_app.exec (); + if (start_gui_p ()) + { + octave_qt_gui_app octave_app (*this); + return octave_app.exec (); + } + else + { + octave_qt_cli_app octave_app (*this); + return octave_app.exec (); + } } }