GNU Octave  6.2.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-2021 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 
41 namespace octave
42 {
43  class main_window;
44  class qt_application;
45  class qt_interpreter_events;
46 
47  //! This class is a simple wrapper around QApplication so that we can
48  //! reimplement QApplication::notify. The octave_qapplication object
49  //! should behave identically to a QApplication object except that it
50  //! overrides the notify method so we can handle forward Octave
51  //! octave::execution_exception exceptions from the GUI thread to the
52  //! interpreter thread.
53 
55  {
56  Q_OBJECT
57 
58  public:
59 
60  octave_qapplication (int& argc, char **argv)
61  : QApplication (argc, argv)
62  { }
63 
64  virtual bool notify (QObject *receiver, QEvent *e) override;
65 
67 
68  signals:
69 
70  void interpreter_event (const fcn_callback& fcn);
71  void interpreter_event (const meth_callback& meth);
72  };
73 
74  //! Base class for Octave interfaces that use Qt. There are two
75  //! classes derived from this one. One provides a command-line
76  //! interface that may use Qt graphics and another provides the
77  //! full GUI experience.
78 
79  class base_qobject : public QObject
80  {
81  Q_OBJECT
82 
83  public:
84 
86 
87  ~base_qobject (void);
88 
89  void config_translators (void);
90 
91  void start_main_thread (void);
92 
93  int exec (void);
94 
95  // The Octave application context.
97 
98  // The Qt QApplication.
100 
102  {
103  return m_resource_manager;
104  }
105 
107  {
108  return m_shortcut_manager;
109  }
110 
111  std::shared_ptr<qt_interpreter_events> get_qt_interpreter_events (void)
112  {
114  }
115 
117  {
118  return m_qt_interpreter_events.get ();
119  }
120 
122  {
123  return m_interpreter_qobj;
124  }
125 
126  QThread *main_thread (void) { return m_main_thread; }
127 
128  virtual bool confirm_shutdown (void);
129 
130  signals:
131 
133 
134  public slots:
135 
137 
139 
140  void interpreter_event (const fcn_callback& fcn);
141 
142  void interpreter_event (const meth_callback& meth);
143 
144  void copy_image_to_clipboard (const QString& file, bool remove_file);
145 
146  protected:
147 
149 
150  // Use these to ensure that argc and argv exist for as long as the
151  // QApplication object.
152 
153  int m_argc;
154  char **m_argv;
155 
157 
159 
161 
162  QTranslator *m_qt_tr;
163  QTranslator *m_gui_tr;
164  QTranslator *m_qsci_tr;
165 
167 
168  std::shared_ptr<qt_interpreter_events> m_qt_interpreter_events;
169 
171 
173  };
174 
175  //! This object provides a command-line interface to Octave that may
176  //! use Qt graphics.
177 
178  class cli_qobject : public base_qobject
179  {
180  Q_OBJECT
181 
182  public:
183 
185 
186  ~cli_qobject (void) = default;
187  };
188 
189  //! This object provides a full GUI interface to Octave that is
190  //! implemented Qt.
191 
192  class gui_qobject : public base_qobject
193  {
194  Q_OBJECT
195 
196  public:
197 
199 
200  ~gui_qobject (void);
201 
202  bool confirm_shutdown (void);
203 
204  private:
205 
207  };
208 }
209 
210 #endif
Base class for Octave interfaces that use Qt.
qt_application & app_context(void)
std::shared_ptr< qt_interpreter_events > m_qt_interpreter_events
void copy_image_to_clipboard(const QString &file, bool remove_file)
void handle_interpreter_execution_finished(int)
interpreter_qobject * m_interpreter_qobj
std::shared_ptr< qt_interpreter_events > get_qt_interpreter_events(void)
qt_interpreter_events * qt_link(void)
shortcut_manager m_shortcut_manager
qt_application & m_app_context
QTranslator * m_qt_tr
interpreter_qobject * interpreter_qobj(void)
base_qobject(qt_application &app_context)
void start_main_thread(void)
resource_manager m_resource_manager
QTranslator * m_qsci_tr
void request_interpreter_shutdown(int)
resource_manager & get_resource_manager(void)
void handle_interpreter_shutdown_finished(int)
QApplication * qapplication(void)
QTranslator * m_gui_tr
virtual bool confirm_shutdown(void)
shortcut_manager & get_shortcut_manager(void)
octave_qapplication * m_qapplication
void config_translators(void)
QThread * main_thread(void)
void interpreter_event(const fcn_callback &fcn)
This object provides a command-line interface to Octave that may use Qt graphics.
~cli_qobject(void)=default
cli_qobject(qt_application &app_context)
This object provides a full GUI interface to Octave that is implemented Qt.
bool confirm_shutdown(void)
main_window * m_main_window
gui_qobject(qt_application &app_context)
Represents the main window.
Definition: main-window.h:76
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.
void interpreter_event(const fcn_callback &fcn)
void interpreter_event(const meth_callback &meth)
octave_qapplication(int &argc, char **argv)
This class inherits from the pure-virtual base class octave::application and provides an implementati...
std::function< void(octave::interpreter &)> meth_callback
Definition: event-manager.h:47
std::function< void(void)> fcn_callback
Definition: event-manager.h:46