GNU Octave  4.4.1
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-2018 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_Object_h)
24 #define octave_Object_h 1
25 
26 #include <QObject>
27 
28 #include "graphics.h"
29 
30 class QObject;
31 class QString;
32 class QWidget;
33 
34 namespace QtHandles
35 {
36 
37  class Container;
38  class ObjectProxy;
39 
40  class Object : public QObject
41  {
42  Q_OBJECT
43 
44  public:
45  Object (const graphics_object& go, QObject *obj = nullptr);
46 
47  virtual ~Object (void);
48 
50  { return object ().get_properties (); }
51 
52  const base_properties& properties (void) const
53  { return object ().get_properties (); }
54 
55  template <typename T>
56  typename T::properties& properties (void)
57  {
58  return dynamic_cast<typename T::properties&>
59  (object ().get_properties ());
60  }
61 
62  template <typename T>
63  const typename T::properties& properties (void) const
64  {
65  return dynamic_cast<const typename T::properties&>
66  (object ().get_properties ());
67  }
68 
69  graphics_object object (void) const;
70 
71  virtual QObject * qObject (void) { return m_qobject; }
72 
73  template <typename T>
74  T * qWidget (void) { return qobject_cast<T *>(qObject ()); }
75 
76  virtual Container * innerContainer (void) = 0;
77 
78  static Object * fromQObject (QObject *obj);
79 
80  public slots:
81  void slotUpdate (int pId);
82  void slotFinalize (void);
83  void slotRedraw (void);
84  void slotPrint (const QString& file_cmd, const QString& term);
85 
86  void objectDestroyed (QObject *obj = nullptr);
87 
88  protected:
89  static Object * parentObject (const graphics_object& go);
90  void init (QObject *obj, bool callBase = false);
91 
92  virtual void update (int pId);
93  virtual void finalize (void);
94  virtual void redraw (void);
95  virtual void print (const QString& file_cmd, const QString& term);
96 
97  virtual void beingDeleted (void);
98 
99  protected:
100 
101  // Store the graphics object directly so that it will exist when
102  // we need it. Previously, it was possible for the graphics
103  // backend to get a handle to a figure, then have the interpreter
104  // thread delete the corresponding object before the backend (GUI)
105  // thread had a chance to display it. It should be OK to store
106  // this object and use it in both threads (graphics_object uses a
107  // std::shared_ptr) provided that we protect access with mutex locks.
109 
110  // Handle to the graphics object. This may be redundant now.
111  // Also, the whole ObjectProxy thing may not need to store a
112  // pointer now? Maybe we can just have a lookup table from figure
113  // handle to Object? What does the FLTK toolkit do? Why does
114  // this seem to be so complicated?
116 
118  };
119 
120 }
121 
122 #endif
const base_properties & properties(void) const
Definition: Object.h:52
virtual void redraw(void)
Definition: Object.cc:147
T::properties & properties(void)
Definition: Object.h:56
void slotUpdate(int pId)
Definition: Object.cc:85
static Object * parentObject(const graphics_object &go)
Definition: Object.cc:165
virtual Container * innerContainer(void)=0
void slotFinalize(void)
Definition: Object.cc:106
virtual ~Object(void)
Definition: Object.cc:68
void slotRedraw(void)
Definition: Object.cc:114
void init(QObject *obj, bool callBase=false)
Definition: Object.cc:51
graphics_handle m_handle
Definition: Object.h:115
T * qWidget(void)
Definition: Object.h:74
static Object * fromQObject(QObject *obj)
Definition: Object.cc:176
virtual void beingDeleted(void)
Definition: Object.cc:155
base_properties & get_properties(void)
Definition: graphics.in.h:2788
QObject * m_qobject
Definition: Object.h:117
virtual QObject * qObject(void)
Definition: Object.h:71
graphics_object object(void) const
Definition: Object.cc:72
const T::properties & properties(void) const
Definition: Object.h:63
virtual void finalize(void)
Definition: Object.cc:136
Object(const graphics_object &go, QObject *obj=nullptr)
Definition: Object.cc:37
virtual void update(int pId)
Definition: Object.cc:132
void objectDestroyed(QObject *obj=nullptr)
Definition: Object.cc:158
virtual void print(const QString &file_cmd, const QString &term)
Definition: Object.cc:151
graphics_object m_go
Definition: Object.h:108
void slotPrint(const QString &file_cmd, const QString &term)
Definition: Object.cc:123
base_properties & properties(void)
Definition: Object.h:49
T::properties & properties(graphics_object obj)