GNU Octave  4.0.0
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-2015 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 #ifdef 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 }
71 
73 Object::object (void) const
74 {
75  gh_manager::auto_lock lock (false);
76 
77  if (! lock)
78  qCritical ("QtHandles::Object::object: "
79  "accessing graphics object (h=%g) without a valid lock!!!",
80  m_handle.value ());
81 
83 }
84 
85 void
87 {
89 
90  switch (pId)
91  {
92  // Special case for objects being deleted, as it's very likely
93  // that the graphics_object already has been destroyed when this
94  // is executed (because of the async behavior).
96  beingDeleted ();
97  break;
98 
99  default:
100  if (object ().valid_object ())
101  update (pId);
102  break;
103  }
104 }
105 
106 void
108 {
110 
111  finalize ();
112 }
113 
114 void
116 {
118 
119  if (object ().valid_object ())
120  redraw ();
121 }
122 
123 void
124 Object::slotPrint (const QString& file_cmd, const QString& term)
125 {
127 
128  if (object ().valid_object ())
129  print (file_cmd, term);
130 }
131 
132 void
133 Object::update (int /* pId */)
134 {
135 }
136 
137 void
139 {
140  if (m_qobject)
141  {
142  delete m_qobject;
143  m_qobject = 0;
144  }
145  deleteLater ();
146 }
147 
148 void
150 {
151 }
152 
153 void
154 Object::print (const QString& /* file_cmd */, const QString& /* term */)
155 {
156 }
157 
158 void
160 {
161 }
162 
164 {
165  if (obj && obj == m_qobject)
166  m_qobject = 0;
167 }
168 
169 Object*
171 {
173 
176 
177  return parent;
178 }
179 
180 Object*
182 {
183  QVariant v = obj->property ("QtHandles::Object");
184 
185  if (v.isValid ())
186  return reinterpret_cast<Object*> (qVariantValue<void*> (v));
187 
188  return 0;
189 }
190 
191 }; // namespace QtHandles
graphics_handle get_parent(void) const
Definition: graphics.h:3361
virtual void redraw(void)
Definition: Object.cc:149
void slotUpdate(int pId)
Definition: Object.cc:86
static Object * parentObject(const graphics_object &go)
Definition: Object.cc:170
void slotFinalize(void)
Definition: Object.cc:107
double value(void) const
Definition: oct-handle.h:70
virtual ~Object(void)
Definition: Object.cc:68
void slotRedraw(void)
Definition: Object.cc:115
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:181
virtual void beingDeleted(void)
Definition: Object.cc:159
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:73
virtual void finalize(void)
Definition: Object.cc:138
static Object * toolkitObject(const graphics_object &go)
Definition: Backend.cc:197
virtual void update(int pId)
Definition: Object.cc:133
virtual void print(const QString &file_cmd, const QString &term)
Definition: Object.cc:154
static graphics_object get_object(double val)
Definition: graphics.h:13212
void objectDestroyed(QObject *obj=0)
Definition: Object.cc:163
void slotPrint(const QString &file_cmd, const QString &term)
Definition: Object.cc:124