Mercurial > octave
view libgui/src/octave-qobject.h @ 27588:f0e3f3e28a8e
move qt_interpreter_events object from interpreter_qobject to octave_qobject
* interpreter-qobject.h, interpreter-qobject.cc
(interpreter_qobject::m_qt_link): Delete data member and all uses.
(interpreter_qobject::execute): Don't connect
confirm_shutdown_signal and copy_image_to_clipboard_signal here.
(interpreter_qobject::confirm_shutdown): Delete.
* octave-qobject.h, octave-qobject.cc (base_qobject::octave_qobject):
Connect copy_image_to_clipboard_signal here.
(base_qobject::m_qt_interpreter_events): New data member.
(base_qobject::confirm_shutdown): New function.
(base_qobject::confirm_shutdown_octave): Delete.
(bool gui_qobject::confirm_shutdown): New function.
(base_qobject::get_qt_interpreter_events, base_qobject::qt_link):
New functions.
* interpreter.h, interpreter.cc (interpreter::quit): New arg, confirm.
* main-window.h, main-window.cc (main_window::confirm_shutdown):
Rename from confirm_shutdown_octave. Change all uses.
(main_window::closeEvent): Check confirm_shutdown first, then if exit
is confirmed, call interpreter::quit with extra argument to skip
confirmation.
* qt-interpreter-events.h, qt-interpreter-events.cc
(qt_interpreter_events::m_octave_qobject): New data member.
(qt_interpreter_events::qt_interpreter_events): Connect
confirm_shutdown_signal to confirm_shutdown_octave slot here.
(qt_interpreter_events::confirm_shutdown_octave): New function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 26 Oct 2019 12:20:29 -0400 |
parents | a1907c3fdef4 |
children | 0053b8e0dc56 |
line wrap: on
line source
/* 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_octave_qobject_h) #define octave_octave_qobject_h 1 #include <memory> #include <QApplication> #include <QList> #include <QObject> #include <QString> #include <QStringList> #include "interpreter-qobject.h" namespace octave { class main_window; class qt_application; class qt_interpreter_events; //! This class is a simple wrapper around QApplication so that we can //! reimplement QApplication::notify. The octave_qapplication object //! should behave identically to a QApplication object except that it //! overrides the notify method so we can handle forward Octave //! octave::execution_exception exceptions from the GUI thread to the //! interpreter thread. class octave_qapplication : public QApplication { Q_OBJECT public: octave_qapplication (int& argc, char **argv) : QApplication (argc, argv) { } virtual bool notify (QObject *receiver, QEvent *e) override; ~octave_qapplication (void) { }; signals: void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); }; //! Base class for Octave interfaces that use Qt. There are two //! classes derived from this one. One provides a command-line //! interface that may use Qt graphics and another provides the //! full GUI experience. class base_qobject : public QObject { Q_OBJECT public: base_qobject (qt_application& app_context); ~base_qobject (void); void config_translators (void); void start_main_thread (void); int exec (void); // The Octave application context. qt_application& app_context (void) { return m_app_context; } // The Qt QApplication. QApplication * qapplication (void) { return m_qapplication; }; std::shared_ptr<qt_interpreter_events> get_qt_interpreter_events (void) { return m_qt_interpreter_events; } qt_interpreter_events * qt_link (void) { return m_qt_interpreter_events.get (); } interpreter_qobject * interpreter_qobj (void) { return m_interpreter_qobj; } QThread *main_thread (void) { return m_main_thread; } virtual bool confirm_shutdown (void); public slots: void handle_octave_finished (int); void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); void copy_image_to_clipboard (const QString& file, bool remove_file); protected: qt_application& m_app_context; // Use these to ensure that argc and argv exist for as long as the // QApplication object. int m_argc; char **m_argv; octave_qapplication *m_qapplication; QTranslator *m_qt_tr; QTranslator *m_gui_tr; QTranslator *m_qsci_tr; bool m_translators_installed; std::shared_ptr<qt_interpreter_events> m_qt_interpreter_events; interpreter_qobject *m_interpreter_qobj; QThread *m_main_thread; }; //! This object provides a command-line interface to Octave that may //! use Qt graphics. class cli_qobject : public base_qobject { Q_OBJECT public: cli_qobject (qt_application& app_context); ~cli_qobject (void) = default; }; //! This object provides a full GUI interface to Octave that is //! implemented Qt. class gui_qobject : public base_qobject { Q_OBJECT public: gui_qobject (qt_application& app_context); ~gui_qobject (void); bool confirm_shutdown (void); private: main_window *m_main_window; }; } #endif