GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
octave-qobject.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2011-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_octave_qobject_h)
27 #define octave_octave_qobject_h 1
28 
29 #include <memory>
30 
31 #include <QApplication>
32 #include <QList>
33 #include <QObject>
34 #include <QString>
35 #include <QStringList>
36 
37 #include "interpreter-qobject.h"
38 #include "resource-manager.h"
39 #include "shortcut-manager.h"
40 
42 
43 class community_news;
44 class main_window;
45 class qt_application;
47 class release_notes;
48 
49 //! This class is a simple wrapper around QApplication so that we can
50 //! reimplement QApplication::notify. The octave_qapplication object
51 //! should behave identically to a QApplication object except that it
52 //! overrides the notify method so we can handle forward Octave
53 //! execution_exception exceptions from the GUI thread to the
54 //! interpreter thread.
55 
57 {
58  Q_OBJECT
59 
60 public:
61 
62  octave_qapplication (int& argc, char **argv)
63  : QApplication (argc, argv)
64  { }
65 
66  virtual bool notify (QObject *receiver, QEvent *e) override;
67 
69 
70 signals:
71 
72  void interpreter_event (const fcn_callback& fcn);
73  void interpreter_event (const meth_callback& meth);
74 };
75 
76 //! Container for windows that may be created from the command line or
77 //! docked with the main GUI window. Any of these windows that are
78 //! created in command line mode will be adopted by the main window if
79 //! it is opened from the command line. Any that are undocked from
80 //! the main window will remain open if control returns to the command
81 //! line.
82 
83 class base_qobject;
86 class files_dock_widget;
89 class variable_editor;
90 class workspace_model;
91 class workspace_view;
92 
93 //! Base class for Octave interfaces that use Qt. There are two
94 //! classes derived from this one. One provides a command-line
95 //! interface that may use Qt graphics and another provides the
96 //! full GUI experience.
97 
98 class base_qobject : public QObject
99 {
100  Q_OBJECT
101 
102 public:
103 
104  // Note: the GUI_APP argument is not needed with the new
105  // experimental terminal widget.
106  base_qobject (qt_application& app_context, bool gui_app = false);
107 
108  ~base_qobject (void);
109 
110  void config_translators (void);
111 
112  void start_main_thread (void);
113 
114  int exec (void);
115 
116  // The Octave application context.
118 
119  // The Qt QApplication.
121 
122  // Provided for convenience. Will be removed once we eliminate the
123  // old terminal widget.
124  bool experimental_terminal_widget (void) const;
125 
126  // Provided for convenience.
127  bool gui_running (void) const;
128 
129  bool have_terminal_window (void) const
130  {
131  return ! m_terminal_widget.isNull ();
132  }
133 
135  {
136  return m_main_window;
137  }
138 
140  {
141  return m_resource_manager;
142  }
143 
145  {
146  return m_shortcut_manager;
147  }
148 
149  std::shared_ptr<qt_interpreter_events> get_qt_interpreter_events (void)
150  {
152  }
153 
155  {
156  return m_qt_interpreter_events.get ();
157  }
158 
160  {
161  return m_interpreter_qobj;
162  }
163 
165  {
166  return m_workspace_model;
167  }
168 
169  QPointer<terminal_dock_widget>
170  terminal_widget (main_window *mw = nullptr);
171 
172  QPointer<documentation_dock_widget>
173  documentation_widget (main_window *mw = nullptr);
174 
175  QPointer<files_dock_widget>
176  file_browser_widget (main_window *mw = nullptr);
177 
178  QPointer<history_dock_widget>
179  history_widget (main_window *mw = nullptr);
180 
181  QPointer<workspace_view>
182  workspace_widget (main_window *mw = nullptr);
183 
184  // FIXME: The file_editor_interface needs to be a proper generic
185  // interface for all editors (internal and external) for this to
186  // work properly.
187  QPointer<file_editor_interface>
188  editor_widget (main_window *mw = nullptr);
189 
190  QPointer<variable_editor>
191  variable_editor_widget (main_window *mw = nullptr);
192 
193  QPointer<community_news> community_news_widget (int serial = -1);
194 
195  QPointer<release_notes> release_notes_widget (void);
196 
197  QThread * main_thread (void) { return m_main_thread; }
198 
199  // Declared virtual so that a derived class may redefine this
200  // method.
201 
202  virtual bool confirm_shutdown (void);
203 
204  bool is_gui_app (void) const { return m_gui_app; }
205 
206  template <typename T> void connect_interpreter_events (T *widget)
207  {
208  connect (widget, QOverload<const fcn_callback&>::of (&T::interpreter_event),
210 
211  connect (widget, QOverload<const meth_callback&>::of (&T::interpreter_event),
213  }
214 
215 public slots:
216 
217  void execute_command (const QString& command);
218 
219  // Note: START_GUI and CLOSE_GUI don't currently perform any work
220  // with the old terminal widget.
221  void start_gui (bool gui_app);
222  void close_gui (void);
223 
224  void show_terminal_window (void);
225 
226  void show_documentation_window (const QString& file);
227 
228  void show_file_browser_window (void);
229 
230  void show_command_history_window (void);
231 
232  void show_workspace_window (void);
233 
234  void show_variable_editor_window (const QString& name,
235  const octave_value& value);
236 
237  void handle_variable_editor_update (void);
238 
239  void show_community_news (int serial);
240 
241  void show_release_notes (void);
242 
243  void interpreter_ready (void);
244 
245  void interpreter_event (const fcn_callback& fcn);
246 
247  void interpreter_event (const meth_callback& meth);
248 
249  void interpreter_interrupt (void);
250 
251  // Note: these currently only work with the new experimental
252  // terminal widget.
253  void interpreter_pause (void);
254  void interpreter_stop (void);
255  void interpreter_resume (void);
256 
257  void copy_image_to_clipboard (const QString& file, bool remove_file);
258 
259 protected:
260 
262 
263  // Use these to ensure that argc and argv exist for as long as the
264  // QApplication object.
265 
266  int m_argc;
267  char **m_argv;
268 
270 
272 
274 
275  QTranslator *m_qt_tr;
276  QTranslator *m_gui_tr;
277  QTranslator *m_qsci_tr;
278 
280 
281  std::shared_ptr<qt_interpreter_events> m_qt_interpreter_events;
282 
284 
286 
287  bool m_gui_app;
288 
290 
292 
293  // Dock widgets that may be used from the command line. They are
294  // adopted by the desktop (main window) if it is also started from
295  // the command line.
296 
297  QPointer<terminal_dock_widget> m_terminal_widget;
298 
299  QPointer<documentation_dock_widget> m_documentation_widget;
300 
301  QPointer<files_dock_widget> m_file_browser_widget;
302 
303  QPointer<history_dock_widget> m_history_widget;
304 
305  QPointer<workspace_view> m_workspace_widget;
306 
307  QPointer<file_editor_interface> m_editor_widget;
308 
309  QPointer<variable_editor> m_variable_editor_widget;
310 
311  QPointer<community_news> m_community_news;
312 
313  QPointer<release_notes> m_release_notes;
314 
316 };
317 
319 
320 #endif
OCTAVE_END_NAMESPACE(octave)
Base class for Octave interfaces that use Qt.
QThread * m_main_thread
QPointer< files_dock_widget > m_file_browser_widget
QPointer< history_dock_widget > history_widget(main_window *mw=nullptr)
void interpreter_pause(void)
void show_variable_editor_window(const QString &name, const octave_value &value)
workspace_model * m_workspace_model
resource_manager m_resource_manager
QPointer< files_dock_widget > file_browser_widget(main_window *mw=nullptr)
void show_release_notes(void)
QPointer< community_news > community_news_widget(int serial=-1)
void connect_interpreter_events(T *widget)
void interpreter_ready(void)
void show_file_browser_window(void)
void execute_command(const QString &command)
bool is_gui_app(void) const
virtual bool confirm_shutdown(void)
void interpreter_resume(void)
void copy_image_to_clipboard(const QString &file, bool remove_file)
QPointer< documentation_dock_widget > m_documentation_widget
QApplication * qapplication(void)
void show_workspace_window(void)
QTranslator * m_qt_tr
QTranslator * m_qsci_tr
bool experimental_terminal_widget(void) const
void handle_variable_editor_update(void)
interpreter_qobject * interpreter_qobj(void)
bool gui_running(void) const
qt_application & m_app_context
int exec(void)
QPointer< workspace_view > m_workspace_widget
main_window * m_main_window
qt_interpreter_events * qt_link(void)
qt_application & app_context(void)
QPointer< file_editor_interface > m_editor_widget
octave_qapplication * m_qapplication
void interpreter_interrupt(void)
void interpreter_stop(void)
void close_gui(void)
void show_command_history_window(void)
resource_manager & get_resource_manager(void)
QTranslator * m_gui_tr
QPointer< variable_editor > variable_editor_widget(main_window *mw=nullptr)
shortcut_manager m_shortcut_manager
void show_documentation_window(const QString &file)
void interpreter_event(const fcn_callback &fcn)
void show_community_news(int serial)
shortcut_manager & get_shortcut_manager(void)
bool m_translators_installed
main_window * get_main_window(void)
bool m_interpreter_ready
QPointer< file_editor_interface > editor_widget(main_window *mw=nullptr)
base_qobject(qt_application &app_context, bool gui_app=false)
QPointer< variable_editor > m_variable_editor_widget
QPointer< terminal_dock_widget > terminal_widget(main_window *mw=nullptr)
workspace_model * get_workspace_model(void)
bool have_terminal_window(void) const
void show_terminal_window(void)
void start_main_thread(void)
std::shared_ptr< qt_interpreter_events > get_qt_interpreter_events(void)
QPointer< history_dock_widget > m_history_widget
void start_gui(bool gui_app)
interpreter_qobject * m_interpreter_qobj
void config_translators(void)
QPointer< release_notes > release_notes_widget(void)
std::shared_ptr< qt_interpreter_events > m_qt_interpreter_events
QThread * main_thread(void)
QPointer< community_news > m_community_news
QPointer< workspace_view > workspace_widget(main_window *mw=nullptr)
QPointer< terminal_dock_widget > m_terminal_widget
QPointer< documentation_dock_widget > documentation_widget(main_window *mw=nullptr)
QPointer< release_notes > m_release_notes
Dock widget to display files in the current directory.
Represents the main window.
Definition: main-window.h:73
This class is a simple wrapper around QApplication so that we can reimplement QApplication::notify.
virtual bool notify(QObject *receiver, QEvent *e) override
Reimplement QApplication::notify.
octave_qapplication(int &argc, char **argv)
void interpreter_event(const meth_callback &meth)
void interpreter_event(const fcn_callback &fcn)
This class inherits from the pure-virtual base class application and provides an implementation of th...
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::function< void(void)> fcn_callback
Definition: event-manager.h:43
std::function< void(interpreter &)> meth_callback
Definition: event-manager.h:48