GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
qt-graphics-toolkit.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_graphics_toolkit_h)
27 #define octave_qt_graphics_toolkit_h 1
28 
29 #include <QObject>
30 
31 #include "event-manager.h"
32 #include "graphics.h"
33 
35 
36 class interpreter;
37 class base_qobject;
38 
39 class Object;
40 class ObjectProxy;
41 
43  : public QObject, public octave::base_graphics_toolkit
44 {
45  Q_OBJECT
46 
47 public:
48 
49  qt_graphics_toolkit (octave::interpreter& interp,
50  octave::base_qobject& oct_qobj);
51 
52  ~qt_graphics_toolkit (void) = default;
53 
54  // The interpreter may call graphics toolkit functions that we
55  // implement here. The Qt GUI that manages these actions runs in a
56  // separate thread. So in order to correctly cross from the
57  // interpreter thread to the GUI thread, these functions should emit
58  // signals (in the interpreter thread) that are handled by slots
59  // that will run in the GUI thread. This design is similar to the
60  // event_manager, interpreter_events, and qt_interpreter_events
61  // classes work to pass messages from the interpreter to the GUI.
62  //
63  // FIXME: currently most of these functions do not emit signals.
64  // They may work because they use locking and the gh_manager class,
65  // but it might be better to use Qt signals and slots. In any case,
66  // we should ensure that they are correctly handling the connection
67  // between the interpreter and GUI threads.
68 
69  bool is_valid (void) const { return true; }
70 
71  void redraw_figure (const graphics_object& h) const;
72 
73  void show_figure (const graphics_object& h) const;
74 
75  void update (const graphics_object& obj, int pId);
76 
77  bool initialize (const graphics_object& obj);
78 
79  void finalize (const graphics_object& obj);
80 
81  void print_figure (const graphics_object& go,
82  const std::string& term,
83  const std::string& file_cmd,
84  const std::string& /*debug_file*/) const;
85 
86  uint8NDArray get_pixels (const graphics_object& go) const;
87 
88  Matrix get_text_extent (const graphics_object& go) const;
89 
90  static Object * toolkitObject (const graphics_object& go);
91 
92  static ObjectProxy * toolkitObjectProxy (const graphics_object& go);
93 
94 signals:
95 
96  void create_object_signal (double handle);
97 
98 public slots:
99 
100  void interpreter_event (const octave::fcn_callback& fcn);
101  void interpreter_event (const octave::meth_callback& meth);
102 
103  void create_object (double handle);
104 
105  void gh_callback_event (const graphics_handle& h, const std::string& name);
106 
107  void gh_callback_event (const graphics_handle& h, const std::string& name,
108  const octave_value& data);
109 
110  void gh_set_event (const graphics_handle& h, const std::string& name,
111  const octave_value& value);
112 
113  void gh_set_event (const graphics_handle& h, const std::string& name,
114  const octave_value& value, bool notify_toolkit);
115 
116  void gh_set_event (const graphics_handle& h, const std::string& name,
117  const octave_value& value, bool notify_toolkit,
118  bool redraw_figure);
119 private:
120 
121  octave::interpreter& m_interpreter;
122 
123  octave::base_qobject& m_octave_qobj;
124 };
125 
127 
128 #endif
OCTAVE_END_NAMESPACE(octave)
Definition: dMatrix.h:42
Definition: Object.h:47
Base class for Octave interfaces that use Qt.
qt_graphics_toolkit(octave::interpreter &interp, octave::base_qobject &oct_qobj)
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value)
void print_figure(const graphics_object &go, const std::string &term, const std::string &file_cmd, const std::string &) const
void show_figure(const graphics_object &h) const
void interpreter_event(const octave::fcn_callback &fcn)
void gh_callback_event(const graphics_handle &h, const std::string &name)
void create_object_signal(double handle)
void redraw_figure(const graphics_object &h) const
uint8NDArray get_pixels(const graphics_object &go) const
void finalize(const graphics_object &obj)
bool is_valid(void) const
octave::interpreter & m_interpreter
octave::base_qobject & m_octave_qobj
void create_object(double handle)
static Object * toolkitObject(const graphics_object &go)
~qt_graphics_toolkit(void)=default
void update(const graphics_object &obj, int pId)
bool initialize(const graphics_object &obj)
static ObjectProxy * toolkitObjectProxy(const graphics_object &go)
Matrix get_text_extent(const graphics_object &go) const
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