GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Object.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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_handle (go.get_handle ()), m_qobject (0)
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 
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).
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 = 0;
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 = 0;
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 0;
184  }
185 
186 }
graphics_handle get_parent(void) const
Definition: graphics.h:3272
virtual void redraw(void)
Definition: Object.cc:147
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
double value(void) const
Definition: oct-handle.h:74
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:100
static Object * fromQObject(QObject *obj)
Definition: Object.cc:176
virtual void beingDeleted(void)
Definition: Object.cc:155
QObject * m_qobject
Definition: Object.h:101
Object(const graphics_object &go, QObject *obj=0)
Definition: Object.cc:37
graphics_object object(void) const
Definition: Object.cc:72
virtual void finalize(void)
Definition: Object.cc:136
static Object * toolkitObject(const graphics_object &go)
Definition: Backend.cc:199
virtual void update(int pId)
Definition: Object.cc:132
virtual void print(const QString &file_cmd, const QString &term)
Definition: Object.cc:151
static graphics_object get_object(double val)
Definition: graphics.h:13794
void objectDestroyed(QObject *obj=0)
Definition: Object.cc:158
void slotPrint(const QString &file_cmd, const QString &term)
Definition: Object.cc:123