GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Object.cc
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 (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <QString>
28 #include <QVariant>
29 
30 #include "Backend.h"
31 #include "Object.h"
32 #include "QtHandlesUtils.h"
33 
34 namespace QtHandles
35 {
36 
38  : QObject (), m_go (go), m_handle (go.get_handle ()), m_qobject (nullptr)
39  {
40  gh_manager::auto_lock lock (false);
41 
42  if (! lock)
43  qCritical ("QtHandles::Object::Object: "
44  "creating Object (h=%g) without a valid lock!!!",
45  m_handle.value ());
46 
47  init (obj);
48  }
49 
50  void
51  Object::init (QObject *obj, bool)
52  {
53  if (m_qobject)
54  qCritical ("QtHandles::Object::init: "
55  "resetting QObject while in invalid state");
56 
57  m_qobject = obj;
58 
59  if (m_qobject)
60  {
61  m_qobject->setProperty ("QtHandles::Object",
62  qVariantFromValue<void*> (this));
63  connect (m_qobject, SIGNAL (destroyed (QObject*)),
64  SLOT (objectDestroyed (QObject*)));
65  }
66  }
67 
69  { }
70 
72  Object::object (void) const
73  {
74  gh_manager::auto_lock lock (false);
75 
76  if (! lock)
77  qCritical ("QtHandles::Object::object: "
78  "accessing graphics object (h=%g) without a valid lock!!!",
79  m_handle.value ());
80 
81  return m_go;
82  }
83 
84  void
86  {
88 
89  switch (pId)
90  {
91  // Special case for objects being deleted, as it's very likely
92  // that the graphics_object already has been destroyed when this
93  // is executed (because of the async behavior).
94  case base_properties::ID_BEINGDELETED:
95  beingDeleted ();
96  break;
97 
98  default:
99  if (object ().valid_object ())
100  update (pId);
101  break;
102  }
103  }
104 
105  void
107  {
109 
110  finalize ();
111  }
112 
113  void
115  {
117 
118  if (object ().valid_object ())
119  redraw ();
120  }
121 
122  void
123  Object::slotPrint (const QString& file_cmd, const QString& term)
124  {
126 
127  if (object ().valid_object ())
128  print (file_cmd, term);
129  }
130 
131  void
132  Object::update (int /* pId */)
133  { }
134 
135  void
137  {
138  if (m_qobject)
139  {
140  delete m_qobject;
141  m_qobject = nullptr;
142  }
143  deleteLater ();
144  }
145 
146  void
148  { }
149 
150  void
151  Object::print (const QString& /* file_cmd */, const QString& /* term */)
152  { }
153 
154  void
156  { }
157 
159  {
160  if (obj && obj == m_qobject)
161  m_qobject = nullptr;
162  }
163 
164  Object*
166  {
168 
171 
172  return parent;
173  }
174 
175  Object*
177  {
178  QVariant v = obj->property ("QtHandles::Object");
179 
180  if (v.isValid ())
181  return reinterpret_cast<Object *> (qvariant_cast<void*> (v));
182 
183  return nullptr;
184  }
185 
186 }
virtual void redraw(void)
Definition: Object.cc:147
double value(void) const
Definition: oct-handle.h:74
void slotUpdate(int pId)
Definition: Object.cc:85
static Object * parentObject(const graphics_object &go)
Definition: Object.cc:165
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
static Object * fromQObject(QObject *obj)
Definition: Object.cc:176
virtual void beingDeleted(void)
Definition: Object.cc:155
QObject * m_qobject
Definition: Object.h:117
graphics_object object(void) const
Definition: Object.cc:72
graphics_handle get_parent(void) const
Definition: graphics.in.h:2772
virtual void finalize(void)
Definition: Object.cc:136
static Object * toolkitObject(const graphics_object &go)
Definition: Backend.cc:212
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
static graphics_object get_object(double val)
Definition: graphics.in.h:6098
void slotPrint(const QString &file_cmd, const QString &term)
Definition: Object.cc:123