GNU Octave  6.2.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-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_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 
48 namespace octave
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  std::list<std::string>
85  file_dialog (const filter_list& filter, const std::string& title,
86  const std::string& filename, const std::string& pathname,
87  const std::string& multimode);
88 
89  std::list<std::string>
90  input_dialog (const std::list<std::string>& prompt,
91  const std::string& title, const std::list<float>& nr,
92  const std::list<float>& nc,
93  const std::list<std::string>& defaults);
94 
95  std::pair<std::list<int>, int>
96  list_dialog (const std::list<std::string>& list,
97  const std::string& mode, int width, int height,
98  const std::list<int>& initial_value,
99  const std::string& name,
100  const std::list<std::string>& prompt,
101  const std::string& ok_string,
102  const std::string& cancel_string);
103 
104  std::string
105  question_dialog (const std::string& msg, const std::string& title,
106  const std::string& btn1, const std::string& btn2,
107  const std::string& btn3, const std::string& btndef);
108 
109  void update_path_dialog (void);
110 
111  void show_preferences (void);
112 
113  void apply_preferences (void);
114 
115  void show_doc (const std::string& file);
116 
117  bool edit_file (const std::string& file);
118 
119  void edit_variable (const std::string& name, const octave_value& val);
120 
121  bool confirm_shutdown (void);
122 
123  bool prompt_new_edit_file (const std::string& file);
124 
125  int debug_cd_or_addpath_error (const std::string& file,
126  const std::string& dir,
127  bool addpath_option);
128 
129  uint8NDArray get_named_icon (const std::string& icon_name);
130 
131  std::string gui_preference (const std::string& key,
132  const std::string& value);
133 
134  bool copy_image_to_clipboard (const std::string& file);
135 
136  void focus_window (const std::string win_name);
137 
138  void execute_command_in_terminal (const std::string& command);
139 
140  void register_doc (const std::string& file);
141 
142  void unregister_doc (const std::string& file);
143 
144  void directory_changed (const std::string& dir);
145 
146  void file_remove (const std::string& old_name,
147  const std::string& new_name);
148 
149  void file_renamed (bool load_new = true);
150 
151  void set_workspace (bool top_level, bool debug,
152  const symbol_info_list& syminfo,
153  bool update_variable_editor);
154 
155  void clear_workspace (void);
156 
157  void set_history (const string_vector& hist);
158 
159  void append_history (const std::string& hist_entry);
160 
161  void clear_history (void);
162 
163  void pre_input_event (void);
164 
165  void post_input_event (void);
166 
167  void enter_debugger_event (const std::string& fcn_name,
168  const std::string& fcn_file_name, int line);
169 
170  void execute_in_debugger_event (const std::string& file, int line);
171 
172  void exit_debugger_event (void);
173 
174  void update_breakpoint (bool insert, const std::string& file, int line,
175  const std::string& cond);
176 
177  void lock (void) { m_mutex.lock (); }
178 
179  void wait (void) { m_waitcondition.wait (&m_mutex); }
180 
181  void unlock (void) { m_mutex.unlock (); }
182 
183  void wake_all (void) { m_waitcondition.wakeAll (); }
184 
185  public slots:
186 
188 
189  void get_named_icon_slot (const QString& name);
190 
191  void gui_preference_slot (const QString& key, const QString& value);
192 
193  signals:
194 
195  void copy_image_to_clipboard_signal (const QString& file, bool remove_file);
196 
197  void focus_window_signal (const QString& win_name);
198 
199  void edit_file_signal (const QString& file);
200 
201  void directory_changed_signal (const QString& dir);
202 
204 
205  void file_remove_signal (const QString& old_name, const QString& new_name);
206 
207  void file_renamed_signal (bool load_new);
208 
209  void execute_command_in_terminal_signal (const QString& command);
210 
211  void set_workspace_signal (bool top_level, bool debug,
212  const symbol_info_list& syminfo);
213 
215 
216  void set_history_signal (const QStringList& hist);
217 
218  void append_history_signal (const QString& hist_entry);
219 
220  void clear_history_signal (void);
221 
223 
224  void exit_debugger_signal (void);
225 
226  void update_breakpoint_marker_signal (bool insert, const QString& file,
227  int line, const QString& cond);
228 
229  void insert_debugger_pointer_signal (const QString&, int);
230 
231  void delete_debugger_pointer_signal (const QString&, int);
232 
234 
235  void gui_preference_signal (const QString& key, const QString& value);
236 
237  void show_doc_signal (const QString& file);
238 
239  void register_doc_signal (const QString& file);
240 
241  void unregister_doc_signal (const QString& file);
242 
243  void edit_variable_signal (const QString& name, const octave_value& val);
244 
246 
248 
249  void get_named_icon_signal (const QString& name);
250 
251  void settings_changed (const gui_settings *, bool);
252 
253  void apply_new_settings (void);
254 
255  private:
256 
257  QString gui_preference_adjust (const QString& key, const QString& value);
258 
259  void insert_debugger_pointer (const std::string& file, int line);
260 
261  void delete_debugger_pointer (const std::string& file, int line);
262 
264 
266 
267  QVariant m_result;
268 
269  QMutex m_mutex;
270 
271  QWaitCondition m_waitcondition;
272  };
273 }
274 
275 #endif
Base class for Octave interfaces that use Qt.
std::list< std::pair< std::string, std::string > > filter_list
Definition: event-manager.h:90
void enter_debugger_event(const std::string &fcn_name, const std::string &fcn_file_name, int line)
void register_doc_signal(const QString &file)
void file_renamed(bool load_new=true)
void unregister_doc_signal(const QString &file)
void file_remove_signal(const QString &old_name, const QString &new_name)
void insert_debugger_pointer_signal(const QString &, int)
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 get_named_icon_slot(const QString &name)
void edit_variable(const std::string &name, const octave_value &val)
void set_workspace(bool top_level, bool debug, const symbol_info_list &syminfo, bool update_variable_editor)
void file_renamed_signal(bool load_new)
bool edit_file(const std::string &file)
void file_remove(const std::string &old_name, const std::string &new_name)
void edit_file_signal(const QString &file)
void focus_window_signal(const QString &win_name)
void append_history_signal(const QString &hist_entry)
void set_history_signal(const QStringList &hist)
void update_breakpoint(bool insert, const std::string &file, int line, const std::string &cond)
~qt_interpreter_events(void)=default
void insert_debugger_pointer(const std::string &file, int line)
void show_doc_signal(const QString &file)
bool copy_image_to_clipboard(const std::string &file)
void copy_image_to_clipboard_signal(const QString &file, bool remove_file)
void edit_variable_signal(const QString &name, const octave_value &val)
uint8NDArray get_named_icon(const std::string &icon_name)
void execute_command_in_terminal(const std::string &command)
void directory_changed(const std::string &dir)
void gui_preference_signal(const QString &key, const QString &value)
void get_named_icon_signal(const QString &name)
bool prompt_new_edit_file(const std::string &file)
void show_doc(const std::string &file)
void update_breakpoint_marker_signal(bool insert, const QString &file, int line, const QString &cond)
int debug_cd_or_addpath_error(const std::string &file, const std::string &dir, bool addpath_option)
QString gui_preference_adjust(const QString &key, const QString &value)
void delete_debugger_pointer_signal(const QString &, int)
qt_interpreter_events & operator=(const qt_interpreter_events &)=delete
void directory_changed_signal(const QString &dir)
std::string gui_preference(const std::string &key, const std::string &value)
void unregister_doc(const std::string &file)
void execute_in_debugger_event(const std::string &file, int line)
void focus_window(const std::string win_name)
void set_history(const string_vector &hist)
void settings_changed(const gui_settings *, bool)
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 register_doc(const std::string &file)
void delete_debugger_pointer(const std::string &file, int line)
void refresh_variable_editor_signal(void)
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 execute_command_in_terminal_signal(const QString &command)
void gui_preference_slot(const QString &key, const QString &value)
void set_workspace_signal(bool top_level, bool debug, const symbol_info_list &syminfo)
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)
qt_interpreter_events(base_qobject &oct_qobj)
qt_interpreter_events(const qt_interpreter_events &)=delete
void append_history(const std::string &hist_entry)
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
Definition: filter.cc:46
QString name
static bool debug
QList< int > QIntList