GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Object.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_Object_h)
27 #define octave_Object_h 1
28 
29 #include <QObject>
30 
31 #include "event-manager.h"
32 #include "graphics.h"
33 
34 class QObject;
35 class QString;
36 class QWidget;
37 
39 
40 class base_qobject;
41 class interpreter;
42 
43 class Container;
44 class ObjectProxy;
45 
46 class Object : public QObject
47 {
48  Q_OBJECT
49 
50 public:
51  Object (octave::base_qobject& qobj, octave::interpreter& interp,
52  const graphics_object& go, QObject *obj = nullptr);
53 
54  virtual ~Object (void);
55 
56  base_properties& properties (void)
57  { return object ().get_properties (); }
58 
59  const base_properties& properties (void) const
60  { return object ().get_properties (); }
61 
62  template <typename T>
63  typename T::properties& properties (void)
64  {
65  return dynamic_cast<typename T::properties&>
66  (object ().get_properties ());
67  }
68 
69  template <typename T>
70  const typename T::properties& properties (void) const
71  {
72  return dynamic_cast<const typename T::properties&>
73  (object ().get_properties ());
74  }
75 
76  graphics_object object (void) const;
77 
78  virtual QObject * qObject (void) { return m_qobject; }
79 
80  template <typename T>
81  T * qWidget (void) { return qobject_cast<T *>(qObject ()); }
82 
83  virtual Container * innerContainer (void) = 0;
84 
85  static Object * fromQObject (QObject *obj);
86 
87  virtual void do_connections (const QObject *receiver,
88  const QObject *emitter = nullptr);
89 
90 signals:
91 
94 
95  void gh_callback_event (const graphics_handle& h, const std::string& name);
96 
97  void gh_callback_event (const graphics_handle& h, const std::string& name,
98  const octave_value& data);
99 
100  void gh_set_event (const graphics_handle& h, const std::string& name,
101  const octave_value& value);
102 
103  void gh_set_event (const graphics_handle& h, const std::string& name,
104  const octave_value& value, bool notify_toolkit);
105 
106  void gh_set_event (const graphics_handle& h, const std::string& name,
107  const octave_value& value, bool notify_toolkit,
108  bool redraw_figure);
109 
110 public slots:
111  void slotUpdate (int pId);
112  void slotFinalize (void);
113  void slotRedraw (void);
114  void slotShow (void);
115  void slotPrint (const QString& file_cmd, const QString& term);
116 
117  void objectDestroyed (QObject *obj = nullptr);
118 
119 protected:
120  static Object *
121  parentObject (octave::interpreter& interp, const graphics_object& go);
122 
123  void init (QObject *obj, bool callBase = false);
124 
125  virtual void update (int pId);
126  virtual void finalize (void);
127  virtual void redraw (void);
128  virtual void show (void);
129  virtual void print (const QString& file_cmd, const QString& term);
130 
131  virtual void beingDeleted (void);
132 
133 protected:
134 
135  octave::base_qobject& m_octave_qobj;
136  octave::interpreter& m_interpreter;
137 
138  // Store the graphics object directly so that it will exist when
139  // we need it. Previously, it was possible for the graphics
140  // toolkit to get a handle to a figure, then have the interpreter
141  // thread delete the corresponding object before the graphics
142  // toolkit (GUI) thread had a chance to display it. It should be OK
143  // to store this object and use it in both threads (graphics_object
144  // uses a std::shared_ptr) provided that we protect access with
145  // mutex locks.
146  graphics_object m_go;
147 
148  // Handle to the graphics object. This may be redundant now.
149  // Also, the whole ObjectProxy thing may not need to store a
150  // pointer now? Maybe we can just have a lookup table from figure
151  // handle to Object? What does the FLTK toolkit do? Why does
152  // this seem to be so complicated?
154 
156 };
157 
159 
160 #endif
OCTAVE_END_NAMESPACE(octave)
Definition: Object.h:47
const T::properties & properties(void) const
Definition: Object.h:70
void gh_callback_event(const graphics_handle &h, const std::string &name)
virtual void print(const QString &file_cmd, const QString &term)
Definition: Object.cc:186
T * qWidget(void)
Definition: Object.h:81
static Object * parentObject(octave::interpreter &interp, const graphics_object &go)
Definition: Object.cc:200
virtual void do_connections(const QObject *receiver, const QObject *emitter=nullptr)
Definition: Object.cc:224
graphics_handle m_handle
Definition: Object.h:153
static Object * fromQObject(QObject *obj)
Definition: Object.cc:213
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value)
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit)
base_properties & properties(void)
Definition: Object.h:56
virtual void show(void)
Definition: Object.cc:182
Object(octave::base_qobject &qobj, octave::interpreter &interp, const graphics_object &go, QObject *obj=nullptr)
Definition: Object.cc:43
virtual void beingDeleted(void)
Definition: Object.cc:190
octave::base_qobject & m_octave_qobj
Definition: Object.h:135
graphics_object object(void) const
Definition: Object.cc:82
void objectDestroyed(QObject *obj=nullptr)
Definition: Object.cc:193
void interpreter_event(const octave::fcn_callback &fcn)
void interpreter_event(const octave::meth_callback &meth)
void slotPrint(const QString &file_cmd, const QString &term)
Definition: Object.cc:152
virtual void redraw(void)
Definition: Object.cc:178
QObject * m_qobject
Definition: Object.h:155
virtual QObject * qObject(void)
Definition: Object.h:78
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit, bool redraw_figure)
void slotShow(void)
Definition: Object.cc:141
virtual void finalize(void)
Definition: Object.cc:167
const base_properties & properties(void) const
Definition: Object.h:59
void slotFinalize(void)
Definition: Object.cc:120
void gh_callback_event(const graphics_handle &h, const std::string &name, const octave_value &data)
virtual ~Object(void)
Definition: Object.cc:78
graphics_object m_go
Definition: Object.h:146
virtual Container * innerContainer(void)=0
void slotUpdate(int pId)
Definition: Object.cc:97
virtual void update(int pId)
Definition: Object.cc:163
octave::interpreter & m_interpreter
Definition: Object.h:136
void slotRedraw(void)
Definition: Object.cc:130
T::properties & properties(void)
Definition: Object.h:63
void init(QObject *obj, bool callBase=false)
Definition: Object.cc:61
Base class for Octave interfaces that use Qt.
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
T::properties & properties(graphics_object obj)