GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
qt-interpreter-events.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_qt_interpreter_events_h)
27 #define octave_qt_interpreter_events_h 1
28 
29 #include <list>
30 #include <string>
31 
32 #include <QList>
33 #include <QMutex>
34 #include <QObject>
35 #include <QString>
36 #include <QWaitCondition>
37 
38 #include "dialog.h"
39 #include "gui-settings.h"
40 
41 #include "event-manager.h"
42 
43 // Defined for purposes of sending QList<int> as part of signal.
45 
46 class octave_value;
47 
49 
50 class base_qobject;
51 
52 // The functions in this class are not normally called directly, but
53 // are invoked from the Octave interpreter thead by methods in the
54 // event_manager class. In most cases, they should only translate
55 // data from the types typically used in the interpreter to whatever
56 // is required by the GUI (for example, std::string to QString) and
57 // emit a Qt signal.
58 //
59 // The use of Qt signals provides a thread-safe way for the Octave
60 // interpreter to notify the GUI of events (directory or workspace has
61 // changed, for example) or to request that the GUI perform actions
62 // (display a dialog, for example).
63 //
64 // By using this class as a wrapper around the Qt signals, we maintain
65 // a separation between the Octave interpreter and any specific GUI
66 // toolkit (no Qt headers are used in the Octave interpreter sources).
67 
69 {
70  Q_OBJECT
71 
72 public:
73 
75 
76  // No copying!
77 
79 
81 
82  ~qt_interpreter_events (void) = default;
83 
84  // Note: these functions currently do nothing with the old terminal
85  // widget.
86  void start_gui (bool gui_app = false);
87  void close_gui (void);
88 
89  bool have_dialogs (void) const { return true; }
90 
91  std::list<std::string>
92  file_dialog (const filter_list& filter, const std::string& title,
93  const std::string& filename, const std::string& pathname,
94  const std::string& multimode);
95 
96  std::list<std::string>
97  input_dialog (const std::list<std::string>& prompt,
98  const std::string& title, const std::list<float>& nr,
99  const std::list<float>& nc,
100  const std::list<std::string>& defaults);
101 
102  std::pair<std::list<int>, int>
103  list_dialog (const std::list<std::string>& list,
104  const std::string& mode, int width, int height,
105  const std::list<int>& initial_value,
106  const std::string& name,
107  const std::list<std::string>& prompt,
108  const std::string& ok_string,
109  const std::string& cancel_string);
110 
111  std::string
112  question_dialog (const std::string& msg, const std::string& title,
113  const std::string& btn1, const std::string& btn2,
114  const std::string& btn3, const std::string& btndef);
115 
116  void update_path_dialog (void);
117 
118  void show_preferences (void);
119 
120  void apply_preferences (void);
121 
122  void show_terminal_window (void);
123 
124  bool show_documentation (const std::string& file);
125 
126  void show_file_browser (void);
127 
128  void show_command_history (void);
129 
130  void show_workspace (void);
131 
132  void show_community_news (int serial);
133  void show_release_notes (void);
134 
135  bool edit_file (const std::string& file);
136 
137  void edit_variable (const std::string& name, const octave_value& val);
138 
139  bool confirm_shutdown (void);
140 
141  bool prompt_new_edit_file (const std::string& file);
142 
143  int debug_cd_or_addpath_error (const std::string& file,
144  const std::string& dir,
145  bool addpath_option);
146 
147  uint8NDArray get_named_icon (const std::string& icon_name);
148 
149  std::string gui_preference (const std::string& key,
150  const std::string& value);
151 
152  bool copy_image_to_clipboard (const std::string& file);
153 
154  void focus_window (const std::string win_name);
155 
156  void execute_command_in_terminal (const std::string& command);
157 
158  void register_documentation (const std::string& file);
159 
160  void unregister_documentation (const std::string& file);
161 
162  // Note: this function currently does nothing with the old terminal
163  // widget.
164  void interpreter_output (const std::string& msg);
165 
166  void display_exception (const execution_exception& ee, bool beep);
167 
168  void gui_status_update (const std::string& feature, const std::string& status);
169 
170  void update_gui_lexer (void);
171 
172  void directory_changed (const std::string& dir);
173 
174  void file_remove (const std::string& old_name,
175  const std::string& new_name);
176 
177  void file_renamed (bool load_new = true);
178 
179  void set_workspace (bool top_level, bool debug,
180  const symbol_info_list& syminfo,
181  bool update_variable_editor);
182 
183  void clear_workspace (void);
184 
185  void update_prompt (const std::string& prompt);
186 
187  void set_history (const string_vector& hist);
188 
189  void append_history (const std::string& hist_entry);
190 
191  void clear_history (void);
192 
193  void pre_input_event (void);
194 
195  void post_input_event (void);
196 
197  void enter_debugger_event (const std::string& fcn_name,
198  const std::string& fcn_file_name, int line);
199 
200  void execute_in_debugger_event (const std::string& file, int line);
201 
202  void exit_debugger_event (void);
203 
204  void update_breakpoint (bool insert, const std::string& file, int line,
205  const std::string& cond);
206 
207  void lock (void) { m_mutex.lock (); }
208 
209  void wait (void) { m_waitcondition.wait (&m_mutex); }
210 
211  void unlock (void) { m_mutex.unlock (); }
212 
213  void wake_all (void) { m_waitcondition.wakeAll (); }
214 
215 public slots:
216 
218 
219  void get_named_icon_slot (const QString& name);
220 
221  void gui_preference_slot (const QString& key, const QString& value);
222 
223 signals:
224 
225  // Note: these signals are not currently used by the old terminal widget.
226  void start_gui_signal (bool gui_app);
227  void close_gui_signal (void);
228 
229  void copy_image_to_clipboard_signal (const QString& file, bool remove_file);
230 
231  void focus_window_signal (const QString& win_name);
232 
233  void edit_file_signal (const QString& file);
234 
235  void directory_changed_signal (const QString& dir);
236 
238 
239  void file_remove_signal (const QString& old_name, const QString& new_name);
240 
241  void file_renamed_signal (bool load_new);
242 
243  void execute_command_in_terminal_signal (const QString& command);
244 
245  void set_workspace_signal (bool top_level, bool debug,
246  const symbol_info_list& syminfo);
247 
249 
250  void update_prompt_signal (const QString& prompt);
251 
252  void set_history_signal (const QStringList& hist);
253 
254  void append_history_signal (const QString& hist_entry);
255 
256  void clear_history_signal (void);
257 
259 
260  void exit_debugger_signal (void);
261 
262  void update_breakpoint_marker_signal (bool insert, const QString& file,
263  int line, const QString& cond);
264 
265  void insert_debugger_pointer_signal (const QString&, int);
266 
267  void delete_debugger_pointer_signal (const QString&, int);
268 
270 
271  void gui_preference_signal (const QString& key, const QString& value);
272 
274 
275  void show_documentation_signal (const QString& file);
276 
277  void register_documentation_signal (const QString& file);
278 
279  void unregister_documentation_signal (const QString& file);
280 
282 
284 
286 
287  void show_community_news_signal (int serial);
289 
290  // Note: the next two signals are currently not used by the old terminal widget.
291  void interpreter_output_signal (const QString& msg);
292  void new_command_line_signal (const QString& msg = QString ());
293 
294  void gui_status_update_signal (const QString& feature, const QString& status);
295 
296  void update_gui_lexer_signal (bool update_apis_only);
297 
298  void edit_variable_signal (const QString& name, const octave_value& val);
299 
301 
303 
304  void get_named_icon_signal (const QString& name);
305 
306  void settings_changed (const gui_settings *, bool);
307 
308  void apply_new_settings (void);
309 
310 private:
311 
312  QString gui_preference_adjust (const QString& key, const QString& value);
313 
314  void insert_debugger_pointer (const std::string& file, int line);
315 
316  void delete_debugger_pointer (const std::string& file, int line);
317 
319 
321 
322  QVariant m_result;
323 
324  QMutex m_mutex;
325 
326  QWaitCondition m_waitcondition;
327 };
328 
330 
331 #endif
OCTAVE_END_NAMESPACE(octave)
Base class for Octave interfaces that use Qt.
std::list< std::pair< std::string, std::string > > filter_list
void edit_file_signal(const QString &file)
void focus_window_signal(const QString &win_name)
bool edit_file(const std::string &file)
void confirm_shutdown_signal(void)
bool copy_image_to_clipboard(const std::string &file)
void interpreter_output(const std::string &msg)
void gui_status_update(const std::string &feature, const std::string &status)
void enter_debugger_signal(void)
void show_file_browser_signal(void)
void close_gui_signal(void)
void focus_window(const std::string win_name)
uint8NDArray get_named_icon(const std::string &icon_name)
void confirm_shutdown_octave(void)
void update_prompt(const std::string &prompt)
void update_breakpoint(bool insert, const std::string &file, int line, const std::string &cond)
void set_workspace(bool top_level, bool debug, const symbol_info_list &syminfo, bool update_variable_editor)
void unregister_documentation_signal(const QString &file)
qt_interpreter_events(const qt_interpreter_events &)=delete
void update_breakpoint_marker_signal(bool insert, const QString &file, int line, const QString &cond)
std::pair< std::list< int >, int > list_dialog(const std::list< std::string > &list, const std::string &mode, int width, int height, const std::list< int > &initial_value, const std::string &name, const std::list< std::string > &prompt, const std::string &ok_string, const std::string &cancel_string)
void enter_debugger_event(const std::string &fcn_name, const std::string &fcn_file_name, int line)
std::list< std::string > file_dialog(const filter_list &filter, const std::string &title, const std::string &filename, const std::string &pathname, const std::string &multimode)
void file_remove(const std::string &old_name, const std::string &new_name)
~qt_interpreter_events(void)=default
void insert_debugger_pointer_signal(const QString &, int)
int debug_cd_or_addpath_error(const std::string &file, const std::string &dir, bool addpath_option)
void gui_preference_signal(const QString &key, const QString &value)
void set_workspace_signal(bool top_level, bool debug, const symbol_info_list &syminfo)
bool prompt_new_edit_file(const std::string &file)
std::string gui_preference(const std::string &key, const std::string &value)
void append_history(const std::string &hist_entry)
void delete_debugger_pointer(const std::string &file, int line)
bool have_dialogs(void) const
qt_interpreter_events(base_qobject &oct_qobj)
void interpreter_output_signal(const QString &msg)
void edit_variable(const std::string &name, const octave_value &val)
void unregister_documentation(const std::string &file)
void directory_changed_signal(const QString &dir)
void file_remove_signal(const QString &old_name, const QString &new_name)
void directory_changed(const std::string &dir)
void apply_new_settings(void)
void register_documentation_signal(const QString &file)
void clear_workspace_signal(void)
void set_history_signal(const QStringList &hist)
void insert_debugger_pointer(const std::string &file, int line)
void copy_image_to_clipboard_signal(const QString &file, bool remove_file)
void execute_command_in_terminal_signal(const QString &command)
void new_command_line_signal(const QString &msg=QString())
void register_documentation(const std::string &file)
void append_history_signal(const QString &hist_entry)
void get_named_icon_slot(const QString &name)
void edit_variable_signal(const QString &name, const octave_value &val)
void show_terminal_window_signal(void)
void settings_changed(const gui_settings *, bool)
void file_renamed(bool load_new=true)
void file_renamed_signal(bool load_new)
void get_named_icon_signal(const QString &name)
void show_command_history_signal(void)
std::list< std::string > input_dialog(const std::list< std::string > &prompt, const std::string &title, const std::list< float > &nr, const std::list< float > &nc, const std::list< std::string > &defaults)
void start_gui(bool gui_app=false)
QString gui_preference_adjust(const QString &key, const QString &value)
void clear_history_signal(void)
void gui_preference_slot(const QString &key, const QString &value)
qt_interpreter_events & operator=(const qt_interpreter_events &)=delete
void show_preferences_signal(void)
void display_exception(const execution_exception &ee, bool beep)
void refresh_variable_editor_signal(void)
QUIWidgetCreator m_uiwidget_creator
void update_prompt_signal(const QString &prompt)
bool show_documentation(const std::string &file)
void show_release_notes_signal(void)
void show_community_news_signal(int serial)
void show_workspace_signal(void)
void set_history(const string_vector &hist)
void execute_command_in_terminal(const std::string &command)
void start_gui_signal(bool gui_app)
void exit_debugger_signal(void)
void show_documentation_signal(const QString &file)
void execute_in_debugger_event(const std::string &file, int line)
void gui_status_update_signal(const QString &feature, const QString &status)
void delete_debugger_pointer_signal(const QString &, int)
void update_gui_lexer_signal(bool update_apis_only)
std::string question_dialog(const std::string &msg, const std::string &title, const std::string &btn1, const std::string &btn2, const std::string &btn3, const std::string &btndef)
void show_community_news(int serial)
void update_path_dialog_signal(void)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
Definition: filter.cc:48
QList< int > QIntList