GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
variable-editor.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2013-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_variable_editor_h)
27 #define octave_variable_editor_h 1
28 
29 #include <QHeaderView>
30 #include <QSignalMapper>
31 #include <QStackedWidget>
32 #include <QTableView>
33 
34 #include "dw-main-window.h"
35 #include "gui-settings.h"
36 #include "octave-dock-widget.h"
37 #include "qt-interpreter-events.h"
38 #include "tab-bar.h"
39 
40 class octave_value;
41 
42 class QModelIndex;
43 class QTextEdit;
44 class QToolBar;
45 
47 
48 class base_qobject;
49 
52 
53 // The individual variable subwindow class
54 
56 {
57  Q_OBJECT
58 
59 public:
60 
62 
63  ~variable_dock_widget (void) = default;
64 
65 signals:
66 
67  void variable_focused_signal (const QString& name);
68 
69 protected:
70 
71  virtual void closeEvent (QCloseEvent *e);
72 
73  void resizeEvent (QResizeEvent *event);
74 
75 public slots:
76 
77  void handle_focus_change (QWidget *old, QWidget *now);
78 
79 private slots:
80 
81  void change_floating (bool);
82 
83  void change_existence (bool);
84 
85  void toplevel_change (bool);
86 
87  void change_fullscreen (void);
88 
89 protected:
90 
91  QFrame *m_frame;
92 
94 
96 
98 
99  QRect m_prev_geom;
100 
101  // See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813
102 #define QTBUG_44813_FIX_VERSION 0x999999
103 signals:
104 
105  void queue_unfloat_float (void);
106 
107  void queue_float (void);
108 
109 protected slots:
110 
111  void unfloat_float (void);
112 
113  void refloat (void);
114 
115 #if (QT_VERSION >= 0x050302) && (QT_VERSION <= QTBUG_44813_FIX_VERSION)
116 protected:
117 
118  bool event (QEvent *event);
119 
120 private:
121 
122  bool m_waiting_for_mouse_move;
123 
124  bool m_waiting_for_mouse_button_release;
125 #endif
126 };
127 
129 {
130  Q_OBJECT
131 
132 public:
133 
135 
136  ~variable_editor_stack (void) = default;
137 
139 
140  QTextEdit * disp_view (void) {return m_disp_view;};
141 
142 signals:
143 
144  void edit_variable_signal (const QString& name, const octave_value& val);
145 
146  void do_save_signal (const QString& format, const QString& save_opts);
147 
148  void interpreter_event (const fcn_callback& fcn);
149  void interpreter_event (const meth_callback& meth);
150 
151 public slots:
152 
153  void set_editable (bool editable);
154 
155  void levelUp (void);
156 
157  void save (const QString& format = QString ());
158 
159  void do_save (const QString& format, const QString& save_opts);
160 
161 private:
162 
163  QTextEdit * make_disp_view (QWidget *parent);
164 
166 
168 
170 };
171 
173 {
174  Q_OBJECT
175 
176 public:
177 
178  variable_editor_view (QWidget *p, base_qobject& oct_qobj);
179 
180  ~variable_editor_view (void) = default;
181 
182  void setModel (QAbstractItemModel *model);
183 
184 signals:
185 
186  void command_signal (const QString& cmd);
187 
188  void add_edit_actions_signal (QMenu *menu, const QString& qualifier_string);
189 
190 public slots:
191 
192  void createVariable (void);
193 
194  void transposeContent (void);
195 
196  QList<int> range_selected (void);
197 
198  void delete_selected (void);
199 
200  void clearContent (void);
201 
202  void cutClipboard (void);
203 
204  void copyClipboard (void);
205 
206  void pasteClipboard (void);
207 
208  void handle_horizontal_scroll_action (int action);
209 
210  void handle_vertical_scroll_action (int action);
211 
212  void createContextMenu (const QPoint& pt);
213 
214  void createColumnMenu (const QPoint& pt);
215 
216  void createRowMenu (const QPoint& pt);
217 
218  void selected_command_requested (const QString& cmd);
219 
220 private:
221 
222  void add_edit_actions (QMenu *menu, const QString& qualifier_string);
223 
225 
227 };
228 
229 // Gadgets to keep track of and restore what variable window was in focus
230 // just prior to selecting something on the menu bar.
231 
233 {
234  Q_OBJECT
235 
236 public:
237 
238  HoverToolButton (QWidget *parent = nullptr);
239 
240  ~HoverToolButton (void) = default;
241 
242 signals:
243 
244  void hovered_signal (void);
245 
246  void popup_shown_signal (void);
247 
248 protected:
249 
250  bool eventFilter (QObject *obj, QEvent *ev);
251 };
252 
254 {
255  Q_OBJECT
256 
257 public:
258 
259  ReturnFocusToolButton (QWidget *parent = nullptr);
260 
261  ~ReturnFocusToolButton (void) = default;
262 
263 signals:
264 
265  void about_to_activate (void);
266 
267 protected:
268 
269  bool eventFilter (QObject *obj, QEvent *ev);
270 };
271 
272 class ReturnFocusMenu : public QMenu
273 {
274  Q_OBJECT
275 
276 public:
277 
278  ReturnFocusMenu (QWidget *parent = nullptr);
279 
280  ~ReturnFocusMenu (void) = default;
281 
282 signals:
283 
284  void about_to_activate (void);
285 
286 protected:
287 
288  bool eventFilter (QObject *obj, QEvent *ev);
289 };
290 
291 // The variable editor class
292 
294 {
295  Q_OBJECT
296 
297 public:
298 
299  variable_editor (QWidget *parent, base_qobject& oct_qobj);
300 
301  ~variable_editor (void);
302 
303  // No copying!
304 
305  variable_editor (const variable_editor&) = delete;
306 
308 
309  void refresh (void);
310 
311  void tab_to_front (void);
312 
313 signals:
314 
315  void updated (void);
316 
317  void finished (void);
318 
319  void command_signal (const QString& cmd);
320 
321  void refresh_signal (void);
322 
323  void clear_content_signal (void);
324 
326 
328 
329  void level_up_signal (void);
330 
331  void save_signal (void);
332 
334 
335  void interpreter_event (const fcn_callback& fcn);
336  void interpreter_event (const meth_callback& meth);
337 
338 public slots:
339 
340  void callUpdate (const QModelIndex&, const QModelIndex&);
341 
342  void notice_settings (const gui_settings *);
343 
344  void edit_variable (const QString& name, const octave_value& val);
345 
346  void variable_destroyed (QObject *obj);
347 
348  void variable_focused (const QString& name);
349 
350  void record_hovered_focus_variable (void);
351 
352  void restore_hovered_focus_variable (void);
353 
354 protected slots:
355 
356  void closeEvent (QCloseEvent *);
357 
358  void save (void);
359 
360  void cutClipboard (void);
361 
362  void copyClipboard (void);
363 
364  void pasteClipboard (void);
365 
366  void levelUp (void);
367 
368 protected:
369 
370  void focusInEvent (QFocusEvent *ev);
371 
372 private:
373 
375 
376  QToolBar *m_tool_bar;
377  QAction *m_save_action;
378 
380 
382 
384 
386 
388 
389  QString m_stylesheet;
390 
391  QFont m_font;
392 
393  // If use_terminal_font is true then this will be different since
394  // "font" will contain the terminal font.
395  QFont m_sel_font;
396 
398 
399  void update_colors (void);
400 
401  QAction * add_tool_bar_button (const QIcon& icon, const QString& text,
402  const QObject *receiver, const char *member);
403 
404  void construct_tool_bar (void);
405 
407 
409 
410  QSignalMapper *m_plot_mapper;
411  QSignalMapper *m_save_mapper;
412 
414 
416 };
417 
419 
420 #endif
OCTAVE_END_NAMESPACE(octave)
void hovered_signal(void)
void popup_shown_signal(void)
bool eventFilter(QObject *obj, QEvent *ev)
~HoverToolButton(void)=default
HoverToolButton(QWidget *parent=nullptr)
void about_to_activate(void)
bool eventFilter(QObject *obj, QEvent *ev)
~ReturnFocusMenu(void)=default
ReturnFocusMenu(QWidget *parent=nullptr)
~ReturnFocusToolButton(void)=default
void about_to_activate(void)
bool eventFilter(QObject *obj, QEvent *ev)
ReturnFocusToolButton(QWidget *parent=nullptr)
Base class for Octave interfaces that use Qt.
QAction * m_fullscreen_action
void variable_focused_signal(const QString &name)
virtual void closeEvent(QCloseEvent *e)
variable_dock_widget(QWidget *p, base_qobject &oct_qobj)
~variable_dock_widget(void)=default
void queue_float(void)
void resizeEvent(QResizeEvent *event)
void handle_focus_change(QWidget *old, QWidget *now)
void queue_unfloat_float(void)
variable_editor_view * edit_view(void)
void save(const QString &format=QString())
void interpreter_event(const meth_callback &meth)
QTextEdit * disp_view(void)
base_qobject & m_octave_qobj
variable_editor_stack(QWidget *p, base_qobject &oct_qobj)
void interpreter_event(const fcn_callback &fcn)
void do_save_signal(const QString &format, const QString &save_opts)
void set_editable(bool editable)
QTextEdit * make_disp_view(QWidget *parent)
variable_editor_view * m_edit_view
~variable_editor_stack(void)=default
void do_save(const QString &format, const QString &save_opts)
void edit_variable_signal(const QString &name, const octave_value &val)
~variable_editor_view(void)=default
void command_signal(const QString &cmd)
variable_editor_model * m_var_model
variable_editor_view(QWidget *p, base_qobject &oct_qobj)
void createColumnMenu(const QPoint &pt)
base_qobject & m_octave_qobj
QList< int > range_selected(void)
void add_edit_actions(QMenu *menu, const QString &qualifier_string)
void setModel(QAbstractItemModel *model)
void handle_horizontal_scroll_action(int action)
void handle_vertical_scroll_action(int action)
void add_edit_actions_signal(QMenu *menu, const QString &qualifier_string)
void createContextMenu(const QPoint &pt)
void selected_command_requested(const QString &cmd)
void createRowMenu(const QPoint &pt)
variable_dock_widget * m_focus_widget_vdw
void paste_clipboard_signal(void)
void record_hovered_focus_variable(void)
QToolBar * m_tool_bar
QAction * m_save_action
void level_up_signal(void)
QString m_current_focus_vname
void callUpdate(const QModelIndex &, const QModelIndex &)
QAction * add_tool_bar_button(const QIcon &icon, const QString &text, const QObject *receiver, const char *member)
QWidget * m_focus_widget
void closeEvent(QCloseEvent *)
void variable_focused(const QString &name)
variable_editor(QWidget *parent, base_qobject &oct_qobj)
void notice_settings(const gui_settings *)
void pasteClipboard(void)
void copyClipboard(void)
dw_main_window * m_main
void copy_clipboard_signal(void)
QList< QColor > m_table_colors
QSignalMapper * m_save_mapper
void focusInEvent(QFocusEvent *ev)
void construct_tool_bar(void)
variable_editor & operator=(const variable_editor &)=delete
void interpreter_event(const meth_callback &meth)
void variable_destroyed(QObject *obj)
void tab_to_front(void)
QString m_hovered_focus_vname
void cutClipboard(void)
void finished(void)
void delete_selected_signal(void)
void restore_hovered_focus_variable(void)
void interpreter_event(const fcn_callback &fcn)
QSignalMapper * m_plot_mapper
void command_signal(const QString &cmd)
void updated(void)
variable_editor(const variable_editor &)=delete
void save_signal(void)
void refresh_signal(void)
void edit_variable(const QString &name, const octave_value &val)
void update_colors(void)
void clear_content_signal(void)
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
std::size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1473