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