##// END OF EJS Templates
named the struct and implemented classInfo() as a member of the struct and not the typedef (this seems to be a GCC issue, it worked well on MSVC8)...
florianlink -
r21:3c0cb2942ee0
parent child
Show More
@@ -1,529 +1,529
1 /*
1 /*
2 *
2 *
3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
4 *
4 *
5 * This library is free software; you can redistribute it and/or
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
8 * version 2.1 of the License, or (at your option) any later version.
9 *
9 *
10 * This library is distributed in the hope that it will be useful,
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
13 * Lesser General Public License for more details.
14 *
14 *
15 * Further, this software is distributed without any warranty that it is
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
20 * other software, or any other product whatsoever.
21 *
21 *
22 * You should have received a copy of the GNU Lesser General Public
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
25 *
26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
27 * 28359 Bremen, Germany or:
27 * 28359 Bremen, Germany or:
28 *
28 *
29 * http://www.mevis.de
29 * http://www.mevis.de
30 *
30 *
31 */
31 */
32
32
33 //----------------------------------------------------------------------------------
33 //----------------------------------------------------------------------------------
34 /*!
34 /*!
35 // \file PythonQtInstanceWrapper.cpp
35 // \file PythonQtInstanceWrapper.cpp
36 // \author Florian Link
36 // \author Florian Link
37 // \author Last changed by $Author: florian $
37 // \author Last changed by $Author: florian $
38 // \date 2006-05
38 // \date 2006-05
39 */
39 */
40 //----------------------------------------------------------------------------------
40 //----------------------------------------------------------------------------------
41
41
42 #include "PythonQtInstanceWrapper.h"
42 #include "PythonQtInstanceWrapper.h"
43 #include <QObject>
43 #include <QObject>
44 #include "PythonQt.h"
44 #include "PythonQt.h"
45 #include "PythonQtSlot.h"
45 #include "PythonQtSlot.h"
46 #include "PythonQtClassInfo.h"
46 #include "PythonQtClassInfo.h"
47 #include "PythonQtConversion.h"
47 #include "PythonQtConversion.h"
48 #include "PythonQtClassWrapper.h"
48 #include "PythonQtClassWrapper.h"
49
49
50 PythonQtClassInfo* PythonQtInstanceWrapper::classInfo()
50 PythonQtClassInfo* PythonQtInstanceWrapperStruct::classInfo()
51 {
51 {
52 // take the class info from our type object
52 // take the class info from our type object
53 return ((PythonQtClassWrapper*)ob_type)->_classInfo;
53 return ((PythonQtClassWrapper*)ob_type)->_classInfo;
54 }
54 }
55
55
56 static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self, bool force = false) {
56 static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self, bool force = false) {
57
57
58 // is this a C++ wrapper?
58 // is this a C++ wrapper?
59 if (self->_wrappedPtr) {
59 if (self->_wrappedPtr) {
60 //mlabDebugConst("Python","c++ wrapper removed " << self->_wrappedPtr << " " << self->_obj->className() << " " << self->classInfo()->wrappedClassName().latin1());
60 //mlabDebugConst("Python","c++ wrapper removed " << self->_wrappedPtr << " " << self->_obj->className() << " " << self->classInfo()->wrappedClassName().latin1());
61
61
62 PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr);
62 PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr);
63 // we own our qobject, so we delete it now:
63 // we own our qobject, so we delete it now:
64 delete self->_obj;
64 delete self->_obj;
65 self->_obj = NULL;
65 self->_obj = NULL;
66 if (force || self->classInfo()->hasOwnerMethodButNoOwner(self->_wrappedPtr) || self->_ownedByPythonQt) {
66 if (force || self->classInfo()->hasOwnerMethodButNoOwner(self->_wrappedPtr) || self->_ownedByPythonQt) {
67 int type = self->classInfo()->metaTypeId();
67 int type = self->classInfo()->metaTypeId();
68 if (self->_useQMetaTypeDestroy && type>=0) {
68 if (self->_useQMetaTypeDestroy && type>=0) {
69 // use QMetaType to destroy the object
69 // use QMetaType to destroy the object
70 QMetaType::destroy(type, self->_wrappedPtr);
70 QMetaType::destroy(type, self->_wrappedPtr);
71 } else {
71 } else {
72 PythonQtSlotInfo* slot = PythonQt::priv()->getDestructorSlot(self->classInfo()->className());
72 PythonQtSlotInfo* slot = PythonQt::priv()->getDestructorSlot(self->classInfo()->className());
73 if (slot) {
73 if (slot) {
74 void* args[2];
74 void* args[2];
75 args[0] = NULL;
75 args[0] = NULL;
76 args[1] = &self->_wrappedPtr;
76 args[1] = &self->_wrappedPtr;
77 slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, slot->slotIndex(), args);
77 slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, slot->slotIndex(), args);
78 self->_wrappedPtr = NULL;
78 self->_wrappedPtr = NULL;
79 } else {
79 } else {
80 if (type>=0) {
80 if (type>=0) {
81 // use QMetaType to destroy the object
81 // use QMetaType to destroy the object
82 QMetaType::destroy(type, self->_wrappedPtr);
82 QMetaType::destroy(type, self->_wrappedPtr);
83 } else {
83 } else {
84 // TODO: warn about not being able to destroy the object?
84 // TODO: warn about not being able to destroy the object?
85 }
85 }
86 }
86 }
87 }
87 }
88 }
88 }
89 } else {
89 } else {
90 //mlabDebugConst("Python","qobject wrapper removed " << self->_obj->className() << " " << self->classInfo()->wrappedClassName().latin1());
90 //mlabDebugConst("Python","qobject wrapper removed " << self->_obj->className() << " " << self->classInfo()->wrappedClassName().latin1());
91 if (self->_objPointerCopy) {
91 if (self->_objPointerCopy) {
92 PythonQt::priv()->removeWrapperPointer(self->_objPointerCopy);
92 PythonQt::priv()->removeWrapperPointer(self->_objPointerCopy);
93 }
93 }
94 if (self->_obj) {
94 if (self->_obj) {
95 if (force || self->_ownedByPythonQt) {
95 if (force || self->_ownedByPythonQt) {
96 if (force || !self->_obj->parent()) {
96 if (force || !self->_obj->parent()) {
97 delete self->_obj;
97 delete self->_obj;
98 }
98 }
99 } else {
99 } else {
100 if (self->_obj->parent()==NULL) {
100 if (self->_obj->parent()==NULL) {
101 // tell someone who is interested that the qobject is no longer wrapped, if it has no parent
101 // tell someone who is interested that the qobject is no longer wrapped, if it has no parent
102 PythonQt::qObjectNoLongerWrappedCB(self->_obj);
102 PythonQt::qObjectNoLongerWrappedCB(self->_obj);
103 }
103 }
104 }
104 }
105 }
105 }
106 }
106 }
107 self->_obj = NULL;
107 self->_obj = NULL;
108 }
108 }
109
109
110 static void PythonQtInstanceWrapper_dealloc(PythonQtInstanceWrapper* self)
110 static void PythonQtInstanceWrapper_dealloc(PythonQtInstanceWrapper* self)
111 {
111 {
112 PythonQtInstanceWrapper_deleteObject(self);
112 PythonQtInstanceWrapper_deleteObject(self);
113 self->_obj.~QPointer<QObject>();
113 self->_obj.~QPointer<QObject>();
114 self->ob_type->tp_free((PyObject*)self);
114 self->ob_type->tp_free((PyObject*)self);
115 }
115 }
116
116
117 static PyObject* PythonQtInstanceWrapper_new(PyTypeObject *type, PyObject * args, PyObject * /*kwds*/)
117 static PyObject* PythonQtInstanceWrapper_new(PyTypeObject *type, PyObject * args, PyObject * /*kwds*/)
118 {
118 {
119 PythonQtClassWrapper *classType = (PythonQtClassWrapper*)type;
119 PythonQtClassWrapper *classType = (PythonQtClassWrapper*)type;
120 PythonQtInstanceWrapper *self;
120 PythonQtInstanceWrapper *self;
121 static PyObject* emptyTuple = NULL;
121 static PyObject* emptyTuple = NULL;
122 if (emptyTuple==NULL) {
122 if (emptyTuple==NULL) {
123 emptyTuple = PyTuple_New(0);
123 emptyTuple = PyTuple_New(0);
124 }
124 }
125
125
126 self = (PythonQtInstanceWrapper*)PyBaseObject_Type.tp_new(type, emptyTuple, NULL);
126 self = (PythonQtInstanceWrapper*)PyBaseObject_Type.tp_new(type, emptyTuple, NULL);
127
127
128 if (self != NULL) {
128 if (self != NULL) {
129 new (&self->_obj) QPointer<QObject>();
129 new (&self->_obj) QPointer<QObject>();
130 self->_wrappedPtr = NULL;
130 self->_wrappedPtr = NULL;
131 self->_ownedByPythonQt = false;
131 self->_ownedByPythonQt = false;
132 self->_useQMetaTypeDestroy = false;
132 self->_useQMetaTypeDestroy = false;
133 }
133 }
134 return (PyObject *)self;
134 return (PyObject *)self;
135 }
135 }
136
136
137 static int PythonQtInstanceWrapper_init(PythonQtInstanceWrapper * self, PyObject * args, PyObject * kwds)
137 static int PythonQtInstanceWrapper_init(PythonQtInstanceWrapper * self, PyObject * args, PyObject * kwds)
138 {
138 {
139 PyObject* result = NULL;
139 PyObject* result = NULL;
140
140
141 if (args == PythonQtPrivate::dummyTuple()) {
141 if (args == PythonQtPrivate::dummyTuple()) {
142 // we are called from the internal PythonQt API, so our data will be filled later on...
142 // we are called from the internal PythonQt API, so our data will be filled later on...
143 return 0;
143 return 0;
144 }
144 }
145
145
146 // we are called from python, try to construct our object
146 // we are called from python, try to construct our object
147 if (self->classInfo()->constructors()) {
147 if (self->classInfo()->constructors()) {
148 void* directCPPPointer = NULL;
148 void* directCPPPointer = NULL;
149 PythonQtSlotFunction_CallImpl(NULL, self->classInfo()->constructors(), args, kwds, NULL, &directCPPPointer);
149 PythonQtSlotFunction_CallImpl(NULL, self->classInfo()->constructors(), args, kwds, NULL, &directCPPPointer);
150 if (PyErr_Occurred()) {
150 if (PyErr_Occurred()) {
151 return -1;
151 return -1;
152 }
152 }
153 if (directCPPPointer) {
153 if (directCPPPointer) {
154 // change ownershipflag to be owned by PythonQt
154 // change ownershipflag to be owned by PythonQt
155 self->_ownedByPythonQt = true;
155 self->_ownedByPythonQt = true;
156 self->_useQMetaTypeDestroy = false;
156 self->_useQMetaTypeDestroy = false;
157 if (self->classInfo()->isCPPWrapper()) {
157 if (self->classInfo()->isCPPWrapper()) {
158 self->_wrappedPtr = directCPPPointer;
158 self->_wrappedPtr = directCPPPointer;
159 // TODO xxx: if there is a wrapper factory, we might want to generate a wrapper for our class?!
159 // TODO xxx: if there is a wrapper factory, we might want to generate a wrapper for our class?!
160 } else {
160 } else {
161 self->setQObject((QObject*)directCPPPointer);
161 self->setQObject((QObject*)directCPPPointer);
162 }
162 }
163 // register with PythonQt
163 // register with PythonQt
164 PythonQt::priv()->addWrapperPointer(directCPPPointer, self);
164 PythonQt::priv()->addWrapperPointer(directCPPPointer, self);
165 }
165 }
166 } else {
166 } else {
167 QString error = QString("No constructors available for ") + self->classInfo()->className();
167 QString error = QString("No constructors available for ") + self->classInfo()->className();
168 PyErr_SetString(PyExc_ValueError, error.toLatin1().data());
168 PyErr_SetString(PyExc_ValueError, error.toLatin1().data());
169 return -1;
169 return -1;
170 }
170 }
171 return 0;
171 return 0;
172 }
172 }
173
173
174 static PyObject *PythonQtInstanceWrapper_classname(PythonQtInstanceWrapper* type)
174 static PyObject *PythonQtInstanceWrapper_classname(PythonQtInstanceWrapper* type)
175 {
175 {
176 return PyString_FromString(type->classInfo()->className());
176 return PyString_FromString(type->classInfo()->className());
177 }
177 }
178
178
179 static PyObject *PythonQtInstanceWrapper_help(PythonQtInstanceWrapper* type)
179 static PyObject *PythonQtInstanceWrapper_help(PythonQtInstanceWrapper* type)
180 {
180 {
181 return PythonQt::self()->helpCalled(type->classInfo());
181 return PythonQt::self()->helpCalled(type->classInfo());
182 }
182 }
183
183
184 static PyObject *PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper * self)
184 static PyObject *PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper * self)
185 {
185 {
186 PythonQtInstanceWrapper_deleteObject(self, true);
186 PythonQtInstanceWrapper_deleteObject(self, true);
187 Py_INCREF(Py_None);
187 Py_INCREF(Py_None);
188 return Py_None;
188 return Py_None;
189 }
189 }
190
190
191
191
192 static PyMethodDef PythonQtInstanceWrapper_methods[] = {
192 static PyMethodDef PythonQtInstanceWrapper_methods[] = {
193 {"className", (PyCFunction)PythonQtInstanceWrapper_classname, METH_NOARGS,
193 {"className", (PyCFunction)PythonQtInstanceWrapper_classname, METH_NOARGS,
194 "Return the classname of the object"
194 "Return the classname of the object"
195 },
195 },
196 {"help", (PyCFunction)PythonQtInstanceWrapper_help, METH_NOARGS,
196 {"help", (PyCFunction)PythonQtInstanceWrapper_help, METH_NOARGS,
197 "Shows the help of available methods for this class"
197 "Shows the help of available methods for this class"
198 },
198 },
199 {"delete", (PyCFunction)PythonQtInstanceWrapper_delete, METH_NOARGS,
199 {"delete", (PyCFunction)PythonQtInstanceWrapper_delete, METH_NOARGS,
200 "Deletes the C++ object (at your own risk, my friend!)"
200 "Deletes the C++ object (at your own risk, my friend!)"
201 },
201 },
202 {NULL, NULL, 0, NULL} /* Sentinel */
202 {NULL, NULL, 0, NULL} /* Sentinel */
203 };
203 };
204
204
205
205
206 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
206 static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
207 {
207 {
208 const char *attributeName;
208 const char *attributeName;
209 PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj;
209 PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj;
210
210
211 if ((attributeName = PyString_AsString(name)) == NULL) {
211 if ((attributeName = PyString_AsString(name)) == NULL) {
212 return NULL;
212 return NULL;
213 }
213 }
214
214
215 if (!wrapper->_obj && !wrapper->_wrappedPtr) {
215 if (!wrapper->_obj && !wrapper->_wrappedPtr) {
216 QString error = QString("Trying to read attribute '") + attributeName + "' from a destroyed " + wrapper->classInfo()->className() + " object";
216 QString error = QString("Trying to read attribute '") + attributeName + "' from a destroyed " + wrapper->classInfo()->className() + " object";
217 PyErr_SetString(PyExc_ValueError, error.toLatin1().data());
217 PyErr_SetString(PyExc_ValueError, error.toLatin1().data());
218 return NULL;
218 return NULL;
219 }
219 }
220
220
221 // mlabDebugConst("Python","get " << attributeName);
221 // mlabDebugConst("Python","get " << attributeName);
222
222
223 // TODO: dynamic properties are missing
223 // TODO: dynamic properties are missing
224
224
225 PythonQtMemberInfo member = wrapper->classInfo()->member(attributeName);
225 PythonQtMemberInfo member = wrapper->classInfo()->member(attributeName);
226 switch (member._type) {
226 switch (member._type) {
227 case PythonQtMemberInfo::Property:
227 case PythonQtMemberInfo::Property:
228 if (wrapper->_obj) {
228 if (wrapper->_obj) {
229 return PythonQtConv::QVariantToPyObject(member._property.read(wrapper->_obj));
229 return PythonQtConv::QVariantToPyObject(member._property.read(wrapper->_obj));
230 }
230 }
231 break;
231 break;
232 case PythonQtMemberInfo::Slot:
232 case PythonQtMemberInfo::Slot:
233 return PythonQtSlotFunction_New(member._slot, obj, NULL);
233 return PythonQtSlotFunction_New(member._slot, obj, NULL);
234 break;
234 break;
235 case PythonQtMemberInfo::EnumValue:
235 case PythonQtMemberInfo::EnumValue:
236 return PyInt_FromLong(member._enumValue);
236 return PyInt_FromLong(member._enumValue);
237 break;
237 break;
238 default:
238 default:
239 // is an invalid type, go on
239 // is an invalid type, go on
240 break;
240 break;
241 }
241 }
242
242
243 // look for the interal methods (className(), help())
243 // look for the interal methods (className(), help())
244 PyObject* internalMethod = Py_FindMethod( PythonQtInstanceWrapper_methods, obj, (char*)attributeName);
244 PyObject* internalMethod = Py_FindMethod( PythonQtInstanceWrapper_methods, obj, (char*)attributeName);
245 if (internalMethod) {
245 if (internalMethod) {
246 return internalMethod;
246 return internalMethod;
247 }
247 }
248 PyErr_Clear();
248 PyErr_Clear();
249
249
250 if (wrapper->_obj) {
250 if (wrapper->_obj) {
251 // look for a child
251 // look for a child
252 QObjectList children = wrapper->_obj->children();
252 QObjectList children = wrapper->_obj->children();
253 for (int i = 0; i < children.count(); i++) {
253 for (int i = 0; i < children.count(); i++) {
254 QObject *child = children.at(i);
254 QObject *child = children.at(i);
255 if (child->objectName() == attributeName) {
255 if (child->objectName() == attributeName) {
256 return PythonQt::self()->priv()->wrapQObject(child);
256 return PythonQt::self()->priv()->wrapQObject(child);
257 }
257 }
258 }
258 }
259 }
259 }
260
260
261 if (qstrcmp(attributeName, "__dict__")==0) {
261 if (qstrcmp(attributeName, "__dict__")==0) {
262 QStringList l = wrapper->classInfo()->memberList(false);
262 QStringList l = wrapper->classInfo()->memberList(false);
263 PyObject* dict = PyDict_New();
263 PyObject* dict = PyDict_New();
264 foreach (QString name, l) {
264 foreach (QString name, l) {
265 //PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data());
265 //PyObject* o = PyObject_GetAttrString(obj, name.toLatin1().data());
266 PyDict_SetItemString(dict, name.toLatin1().data(), Py_None);
266 PyDict_SetItemString(dict, name.toLatin1().data(), Py_None);
267 //Py_DECREF(o);
267 //Py_DECREF(o);
268 }
268 }
269 // Note: we do not put children into the dict, is would look confusing?!
269 // Note: we do not put children into the dict, is would look confusing?!
270 return dict;
270 return dict;
271 }
271 }
272
272
273
273
274 QString error = QString(wrapper->classInfo()->className()) + " has no attribute named '" + QString(attributeName) + "'";
274 QString error = QString(wrapper->classInfo()->className()) + " has no attribute named '" + QString(attributeName) + "'";
275 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
275 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
276 return NULL;
276 return NULL;
277 }
277 }
278
278
279 static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value)
279 static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value)
280 {
280 {
281 QString error;
281 QString error;
282 char *attributeName;
282 char *attributeName;
283 PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj;
283 PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj;
284
284
285 if ((attributeName = PyString_AsString(name)) == NULL)
285 if ((attributeName = PyString_AsString(name)) == NULL)
286 return -1;
286 return -1;
287
287
288 if (!wrapper->_obj) {
288 if (!wrapper->_obj) {
289 error = QString("Trying to set attribute '") + attributeName + "' on a destroyed " + wrapper->classInfo()->className() + " object";
289 error = QString("Trying to set attribute '") + attributeName + "' on a destroyed " + wrapper->classInfo()->className() + " object";
290 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
290 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
291 return -1;
291 return -1;
292 }
292 }
293
293
294 PythonQtMemberInfo member = wrapper->classInfo()->member(attributeName);
294 PythonQtMemberInfo member = wrapper->classInfo()->member(attributeName);
295 if (member._type == PythonQtMemberInfo::Property) {
295 if (member._type == PythonQtMemberInfo::Property) {
296 QMetaProperty prop = member._property;
296 QMetaProperty prop = member._property;
297 if (prop.isWritable()) {
297 if (prop.isWritable()) {
298 QVariant v;
298 QVariant v;
299 if (prop.isEnumType()) {
299 if (prop.isEnumType()) {
300 // this will give us either a string or an int, everything else will probably be an error
300 // this will give us either a string or an int, everything else will probably be an error
301 v = PythonQtConv::PyObjToQVariant(value);
301 v = PythonQtConv::PyObjToQVariant(value);
302 } else {
302 } else {
303 int t = prop.userType();
303 int t = prop.userType();
304 v = PythonQtConv::PyObjToQVariant(value, t);
304 v = PythonQtConv::PyObjToQVariant(value, t);
305 }
305 }
306 bool success = false;
306 bool success = false;
307 if (v.isValid()) {
307 if (v.isValid()) {
308 success = prop.write(wrapper->_obj, v);
308 success = prop.write(wrapper->_obj, v);
309 }
309 }
310 if (success) {
310 if (success) {
311 return 0;
311 return 0;
312 } else {
312 } else {
313 error = QString("Property '") + attributeName + "' of type '" +
313 error = QString("Property '") + attributeName + "' of type '" +
314 prop.typeName() + "' does not accept an object of type "
314 prop.typeName() + "' does not accept an object of type "
315 + QString(value->ob_type->tp_name) + " (" + PythonQtConv::PyObjGetRepresentation(value) + ")";
315 + QString(value->ob_type->tp_name) + " (" + PythonQtConv::PyObjGetRepresentation(value) + ")";
316 }
316 }
317 } else {
317 } else {
318 error = QString("Property '") + attributeName + "' of " + wrapper->classInfo()->className() + " object is not writable";
318 error = QString("Property '") + attributeName + "' of " + wrapper->classInfo()->className() + " object is not writable";
319 }
319 }
320 } else {
320 } else {
321 if (member._type == PythonQtMemberInfo::Slot) {
321 if (member._type == PythonQtMemberInfo::Slot) {
322 error = QString("Slot '") + attributeName + "' can not be overwritten on " + wrapper->classInfo()->className() + " object";
322 error = QString("Slot '") + attributeName + "' can not be overwritten on " + wrapper->classInfo()->className() + " object";
323 } else if (member._type == PythonQtMemberInfo::EnumValue) {
323 } else if (member._type == PythonQtMemberInfo::EnumValue) {
324 error = QString("EnumValue '") + attributeName + "' can not be overwritten on " + wrapper->classInfo()->className() + " object";
324 error = QString("EnumValue '") + attributeName + "' can not be overwritten on " + wrapper->classInfo()->className() + " object";
325 }
325 }
326 }
326 }
327
327
328 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
328 PyErr_SetString(PyExc_AttributeError, error.toLatin1().data());
329 return -1;
329 return -1;
330 }
330 }
331
331
332 static PyObject * PythonQtInstanceWrapper_str(PyObject * obj)
332 static PyObject * PythonQtInstanceWrapper_str(PyObject * obj)
333 {
333 {
334 PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj;
334 PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj;
335 QObject *qobj = wrapper->_obj;
335 QObject *qobj = wrapper->_obj;
336 if (wrapper->_wrappedPtr) {
336 if (wrapper->_wrappedPtr) {
337 QString str = PythonQtConv::CPPObjectToString(wrapper->classInfo()->metaTypeId(), wrapper->_wrappedPtr);
337 QString str = PythonQtConv::CPPObjectToString(wrapper->classInfo()->metaTypeId(), wrapper->_wrappedPtr);
338 if (!str.isEmpty()) {
338 if (!str.isEmpty()) {
339 return PyString_FromFormat("%s", str.toLatin1().constData());
339 return PyString_FromFormat("%s", str.toLatin1().constData());
340 } else
340 } else
341 if (wrapper->_obj) {
341 if (wrapper->_obj) {
342 return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", wrapper->classInfo()->className(), wrapper->_wrappedPtr, wrapper->_obj->metaObject()->className(), qobj);
342 return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", wrapper->classInfo()->className(), wrapper->_wrappedPtr, wrapper->_obj->metaObject()->className(), qobj);
343 } else {
343 } else {
344 return PyString_FromFormat("%s (C++ Object %p)", wrapper->classInfo()->className(), wrapper->_wrappedPtr);
344 return PyString_FromFormat("%s (C++ Object %p)", wrapper->classInfo()->className(), wrapper->_wrappedPtr);
345 }
345 }
346 } else {
346 } else {
347 return PyString_FromFormat("%s (QObject %p)", wrapper->classInfo()->className(), qobj);
347 return PyString_FromFormat("%s (QObject %p)", wrapper->classInfo()->className(), qobj);
348 }
348 }
349 }
349 }
350
350
351 static PyObject * PythonQtInstanceWrapper_repr(PyObject * obj)
351 static PyObject * PythonQtInstanceWrapper_repr(PyObject * obj)
352 {
352 {
353 PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj;
353 PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj;
354 QObject *qobj = wrapper->_obj;
354 QObject *qobj = wrapper->_obj;
355 if (wrapper->_wrappedPtr) {
355 if (wrapper->_wrappedPtr) {
356 QString str = PythonQtConv::CPPObjectToString(wrapper->classInfo()->metaTypeId(), wrapper->_wrappedPtr);
356 QString str = PythonQtConv::CPPObjectToString(wrapper->classInfo()->metaTypeId(), wrapper->_wrappedPtr);
357 if (!str.isEmpty()) {
357 if (!str.isEmpty()) {
358 return PyString_FromFormat("%s(%s, %p)", QMetaType::typeName(wrapper->classInfo()->metaTypeId()), str.toLatin1().constData(), wrapper->_wrappedPtr);
358 return PyString_FromFormat("%s(%s, %p)", QMetaType::typeName(wrapper->classInfo()->metaTypeId()), str.toLatin1().constData(), wrapper->_wrappedPtr);
359 } else
359 } else
360 if (wrapper->_obj) {
360 if (wrapper->_obj) {
361 return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", wrapper->classInfo()->className(), wrapper->_wrappedPtr, wrapper->_obj->metaObject()->className(), qobj);
361 return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", wrapper->classInfo()->className(), wrapper->_wrappedPtr, wrapper->_obj->metaObject()->className(), qobj);
362 } else {
362 } else {
363 return PyString_FromFormat("%s (C++ Object %p)", wrapper->classInfo()->className(), wrapper->_wrappedPtr);
363 return PyString_FromFormat("%s (C++ Object %p)", wrapper->classInfo()->className(), wrapper->_wrappedPtr);
364 }
364 }
365 } else {
365 } else {
366 return PyString_FromFormat("%s (QObject %p)", wrapper->classInfo()->className(), qobj);
366 return PyString_FromFormat("%s (QObject %p)", wrapper->classInfo()->className(), qobj);
367 }
367 }
368 }
368 }
369
369
370 static int PythonQtInstanceWrapper_compare(PyObject * obj1, PyObject * obj2)
370 static int PythonQtInstanceWrapper_compare(PyObject * obj1, PyObject * obj2)
371 {
371 {
372 if (PyObject_TypeCheck(obj1, &PythonQtInstanceWrapper_Type) &&
372 if (PyObject_TypeCheck(obj1, &PythonQtInstanceWrapper_Type) &&
373 PyObject_TypeCheck(obj2, &PythonQtInstanceWrapper_Type)) {
373 PyObject_TypeCheck(obj2, &PythonQtInstanceWrapper_Type)) {
374
374
375 PythonQtInstanceWrapper* w1 = (PythonQtInstanceWrapper*)obj1;
375 PythonQtInstanceWrapper* w1 = (PythonQtInstanceWrapper*)obj1;
376 PythonQtInstanceWrapper* w2 = (PythonQtInstanceWrapper*)obj2;
376 PythonQtInstanceWrapper* w2 = (PythonQtInstanceWrapper*)obj2;
377 // check pointers directly first:
377 // check pointers directly first:
378 if (w1->_wrappedPtr != NULL) {
378 if (w1->_wrappedPtr != NULL) {
379 if (w1->_wrappedPtr == w2->_wrappedPtr) {
379 if (w1->_wrappedPtr == w2->_wrappedPtr) {
380 return 0;
380 return 0;
381 }
381 }
382 } else if (w1->_obj == w2->_obj) {
382 } else if (w1->_obj == w2->_obj) {
383 return 0;
383 return 0;
384 }
384 }
385 const char* class1 = w1->classInfo()->className();
385 const char* class1 = w1->classInfo()->className();
386 const char* class2 = w2->classInfo()->className();
386 const char* class2 = w2->classInfo()->className();
387 if (strcmp(class1, class2) == 0) {
387 if (strcmp(class1, class2) == 0) {
388 // same class names, so we can try the operator_equal
388 // same class names, so we can try the operator_equal
389 PythonQtMemberInfo info = w1->classInfo()->member("operator_equal");
389 PythonQtMemberInfo info = w1->classInfo()->member("operator_equal");
390 if (info._type == PythonQtMemberInfo::Slot) {
390 if (info._type == PythonQtMemberInfo::Slot) {
391 bool result = false;
391 bool result = false;
392 void* obj1 = w1->_wrappedPtr;
392 void* obj1 = w1->_wrappedPtr;
393 if (!obj1) {
393 if (!obj1) {
394 obj1 = w1->_obj;
394 obj1 = w1->_obj;
395 }
395 }
396 if (!obj1) { return -1; }
396 if (!obj1) { return -1; }
397 void* obj2 = w2->_wrappedPtr;
397 void* obj2 = w2->_wrappedPtr;
398 if (!obj2) {
398 if (!obj2) {
399 obj2 = w2->_obj;
399 obj2 = w2->_obj;
400 }
400 }
401 if (!obj2) { return -1; }
401 if (!obj2) { return -1; }
402 if (info._slot->isInstanceDecorator()) {
402 if (info._slot->isInstanceDecorator()) {
403 // call on decorator QObject
403 // call on decorator QObject
404 void* args[3];
404 void* args[3];
405 args[0] = &result;
405 args[0] = &result;
406 args[1] = &obj1; // this is a pointer, so it needs a pointer to a pointer
406 args[1] = &obj1; // this is a pointer, so it needs a pointer to a pointer
407 args[2] = obj2; // this is a reference, so it needs the direct pointer
407 args[2] = obj2; // this is a reference, so it needs the direct pointer
408 info._slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
408 info._slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
409 return result?0:-1;
409 return result?0:-1;
410 } else {
410 } else {
411 // call directly on QObject
411 // call directly on QObject
412 if (w1->_obj && w2->_obj) {
412 if (w1->_obj && w2->_obj) {
413 void* args[2];
413 void* args[2];
414 args[0] = &result;
414 args[0] = &result;
415 args[2] = obj2; // this is a reference, so it needs the direct pointer
415 args[2] = obj2; // this is a reference, so it needs the direct pointer
416 w1->_obj->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
416 w1->_obj->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
417 }
417 }
418 }
418 }
419 }
419 }
420 }
420 }
421 }
421 }
422 return -1;
422 return -1;
423 }
423 }
424
424
425 static int PythonQtInstanceWrapper_nonzero(PyObject *obj)
425 static int PythonQtInstanceWrapper_nonzero(PyObject *obj)
426 {
426 {
427 PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj;
427 PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj;
428 return (wrapper->_wrappedPtr == NULL && wrapper->_obj == NULL)?0:1;
428 return (wrapper->_wrappedPtr == NULL && wrapper->_obj == NULL)?0:1;
429 }
429 }
430
430
431
431
432 static long PythonQtInstanceWrapper_hash(PythonQtInstanceWrapper *obj)
432 static long PythonQtInstanceWrapper_hash(PythonQtInstanceWrapper *obj)
433 {
433 {
434 if (obj->_wrappedPtr != NULL) {
434 if (obj->_wrappedPtr != NULL) {
435 return reinterpret_cast<long>(obj->_wrappedPtr);
435 return reinterpret_cast<long>(obj->_wrappedPtr);
436 } else {
436 } else {
437 QObject* qobj = obj->_obj; // get pointer from QPointer wrapper
437 QObject* qobj = obj->_obj; // get pointer from QPointer wrapper
438 return reinterpret_cast<long>(qobj);
438 return reinterpret_cast<long>(qobj);
439 }
439 }
440 }
440 }
441
441
442
442
443
443
444 // we override nb_nonzero, so that one can do 'if' expressions to test for a NULL ptr
444 // we override nb_nonzero, so that one can do 'if' expressions to test for a NULL ptr
445 static PyNumberMethods PythonQtInstanceWrapper_as_number = {
445 static PyNumberMethods PythonQtInstanceWrapper_as_number = {
446 0, /* nb_add */
446 0, /* nb_add */
447 0, /* nb_subtract */
447 0, /* nb_subtract */
448 0, /* nb_multiply */
448 0, /* nb_multiply */
449 0, /* nb_divide */
449 0, /* nb_divide */
450 0, /* nb_remainder */
450 0, /* nb_remainder */
451 0, /* nb_divmod */
451 0, /* nb_divmod */
452 0, /* nb_power */
452 0, /* nb_power */
453 0, /* nb_negative */
453 0, /* nb_negative */
454 0, /* nb_positive */
454 0, /* nb_positive */
455 0, /* nb_absolute */
455 0, /* nb_absolute */
456 PythonQtInstanceWrapper_nonzero, /* nb_nonzero */
456 PythonQtInstanceWrapper_nonzero, /* nb_nonzero */
457 0, /* nb_invert */
457 0, /* nb_invert */
458 0, /* nb_lshift */
458 0, /* nb_lshift */
459 0, /* nb_rshift */
459 0, /* nb_rshift */
460 0, /* nb_and */
460 0, /* nb_and */
461 0, /* nb_xor */
461 0, /* nb_xor */
462 0, /* nb_or */
462 0, /* nb_or */
463 0, /* nb_coerce */
463 0, /* nb_coerce */
464 0, /* nb_int */
464 0, /* nb_int */
465 0, /* nb_long */
465 0, /* nb_long */
466 0, /* nb_float */
466 0, /* nb_float */
467 0, /* nb_oct */
467 0, /* nb_oct */
468 0, /* nb_hex */
468 0, /* nb_hex */
469 0, /* nb_inplace_add */
469 0, /* nb_inplace_add */
470 0, /* nb_inplace_subtract */
470 0, /* nb_inplace_subtract */
471 0, /* nb_inplace_multiply */
471 0, /* nb_inplace_multiply */
472 0, /* nb_inplace_divide */
472 0, /* nb_inplace_divide */
473 0, /* nb_inplace_remainder */
473 0, /* nb_inplace_remainder */
474 0, /* nb_inplace_power */
474 0, /* nb_inplace_power */
475 0, /* nb_inplace_lshift */
475 0, /* nb_inplace_lshift */
476 0, /* nb_inplace_rshift */
476 0, /* nb_inplace_rshift */
477 0, /* nb_inplace_and */
477 0, /* nb_inplace_and */
478 0, /* nb_inplace_xor */
478 0, /* nb_inplace_xor */
479 0, /* nb_inplace_or */
479 0, /* nb_inplace_or */
480 0, /* nb_floor_divide */
480 0, /* nb_floor_divide */
481 0, /* nb_true_divide */
481 0, /* nb_true_divide */
482 0, /* nb_inplace_floor_divide */
482 0, /* nb_inplace_floor_divide */
483 0, /* nb_inplace_true_divide */
483 0, /* nb_inplace_true_divide */
484 };
484 };
485
485
486 PyTypeObject PythonQtInstanceWrapper_Type = {
486 PyTypeObject PythonQtInstanceWrapper_Type = {
487 PyObject_HEAD_INIT(&PythonQtClassWrapper_Type)
487 PyObject_HEAD_INIT(&PythonQtClassWrapper_Type)
488 0, /*ob_size*/
488 0, /*ob_size*/
489 "PythonQt.PythonQtInstanceWrapper", /*tp_name*/
489 "PythonQt.PythonQtInstanceWrapper", /*tp_name*/
490 sizeof(PythonQtInstanceWrapper), /*tp_basicsize*/
490 sizeof(PythonQtInstanceWrapper), /*tp_basicsize*/
491 0, /*tp_itemsize*/
491 0, /*tp_itemsize*/
492 (destructor)PythonQtInstanceWrapper_dealloc, /*tp_dealloc*/
492 (destructor)PythonQtInstanceWrapper_dealloc, /*tp_dealloc*/
493 0, /*tp_print*/
493 0, /*tp_print*/
494 0, /*tp_getattr*/
494 0, /*tp_getattr*/
495 0, /*tp_setattr*/
495 0, /*tp_setattr*/
496 PythonQtInstanceWrapper_compare, /*tp_compare*/
496 PythonQtInstanceWrapper_compare, /*tp_compare*/
497 PythonQtInstanceWrapper_repr, /*tp_repr*/
497 PythonQtInstanceWrapper_repr, /*tp_repr*/
498 &PythonQtInstanceWrapper_as_number, /*tp_as_number*/
498 &PythonQtInstanceWrapper_as_number, /*tp_as_number*/
499 0, /*tp_as_sequence*/
499 0, /*tp_as_sequence*/
500 0, /*tp_as_mapping*/
500 0, /*tp_as_mapping*/
501 (hashfunc)PythonQtInstanceWrapper_hash, /*tp_hash */
501 (hashfunc)PythonQtInstanceWrapper_hash, /*tp_hash */
502 0, /*tp_call*/
502 0, /*tp_call*/
503 PythonQtInstanceWrapper_str, /*tp_str*/
503 PythonQtInstanceWrapper_str, /*tp_str*/
504 PythonQtInstanceWrapper_getattro, /*tp_getattro*/
504 PythonQtInstanceWrapper_getattro, /*tp_getattro*/
505 PythonQtInstanceWrapper_setattro, /*tp_setattro*/
505 PythonQtInstanceWrapper_setattro, /*tp_setattro*/
506 0, /*tp_as_buffer*/
506 0, /*tp_as_buffer*/
507 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
507 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
508 "PythonQtInstanceWrapper object", /* tp_doc */
508 "PythonQtInstanceWrapper object", /* tp_doc */
509 0, /* tp_traverse */
509 0, /* tp_traverse */
510 0, /* tp_clear */
510 0, /* tp_clear */
511 0, /* tp_richcompare */
511 0, /* tp_richcompare */
512 0, /* tp_weaklistoffset */
512 0, /* tp_weaklistoffset */
513 0, /* tp_iter */
513 0, /* tp_iter */
514 0, /* tp_iternext */
514 0, /* tp_iternext */
515 0, /* tp_methods */
515 0, /* tp_methods */
516 0, /* tp_members */
516 0, /* tp_members */
517 0, /* tp_getset */
517 0, /* tp_getset */
518 0, /* tp_base */
518 0, /* tp_base */
519 0, /* tp_dict */
519 0, /* tp_dict */
520 0, /* tp_descr_get */
520 0, /* tp_descr_get */
521 0, /* tp_descr_set */
521 0, /* tp_descr_set */
522 0, /* tp_dictoffset */
522 0, /* tp_dictoffset */
523 (initproc)PythonQtInstanceWrapper_init, /* tp_init */
523 (initproc)PythonQtInstanceWrapper_init, /* tp_init */
524 0, /* tp_alloc */
524 0, /* tp_alloc */
525 PythonQtInstanceWrapper_new, /* tp_new */
525 PythonQtInstanceWrapper_new, /* tp_new */
526 };
526 };
527
527
528 //-------------------------------------------------------
528 //-------------------------------------------------------
529
529
@@ -1,92 +1,92
1 #ifndef _PYTHONQTINSTANCEWRAPPER_H
1 #ifndef _PYTHONQTINSTANCEWRAPPER_H
2 #define _PYTHONQTINSTANCEWRAPPER_H
2 #define _PYTHONQTINSTANCEWRAPPER_H
3
3
4 /*
4 /*
5 *
5 *
6 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
6 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
7 *
7 *
8 * This library is free software; you can redistribute it and/or
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
11 * version 2.1 of the License, or (at your option) any later version.
12 *
12 *
13 * This library is distributed in the hope that it will be useful,
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
16 * Lesser General Public License for more details.
17 *
17 *
18 * Further, this software is distributed without any warranty that it is
18 * Further, this software is distributed without any warranty that it is
19 * free of the rightful claim of any third person regarding infringement
19 * free of the rightful claim of any third person regarding infringement
20 * or the like. Any license provided herein, whether implied or
20 * or the like. Any license provided herein, whether implied or
21 * otherwise, applies only to this software file. Patent licenses, if
21 * otherwise, applies only to this software file. Patent licenses, if
22 * any, provided herein do not apply to combinations of this program with
22 * any, provided herein do not apply to combinations of this program with
23 * other software, or any other product whatsoever.
23 * other software, or any other product whatsoever.
24 *
24 *
25 * You should have received a copy of the GNU Lesser General Public
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
28 *
29 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
29 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
30 * 28359 Bremen, Germany or:
30 * 28359 Bremen, Germany or:
31 *
31 *
32 * http://www.mevis.de
32 * http://www.mevis.de
33 *
33 *
34 */
34 */
35
35
36 //----------------------------------------------------------------------------------
36 //----------------------------------------------------------------------------------
37 /*!
37 /*!
38 // \file PythonQtInstanceWrapper.h
38 // \file PythonQtInstanceWrapper.h
39 // \author Florian Link
39 // \author Florian Link
40 // \author Last changed by $Author: florian $
40 // \author Last changed by $Author: florian $
41 // \date 2006-05
41 // \date 2006-05
42 */
42 */
43 //----------------------------------------------------------------------------------
43 //----------------------------------------------------------------------------------
44
44
45 #include <Python.h>
45 #include <Python.h>
46
46
47 #include "PythonQtSystem.h"
47 #include "PythonQtSystem.h"
48 #include <QPointer>
48 #include <QPointer>
49
49
50 #include "structmember.h"
50 #include "structmember.h"
51 #include "methodobject.h"
51 #include "methodobject.h"
52 #include "compile.h"
52 #include "compile.h"
53 #include "eval.h"
53 #include "eval.h"
54
54
55 class PythonQtClassInfo;
55 class PythonQtClassInfo;
56 class QObject;
56 class QObject;
57
57
58 extern PYTHONQT_EXPORT PyTypeObject PythonQtInstanceWrapper_Type;
58 extern PYTHONQT_EXPORT PyTypeObject PythonQtInstanceWrapper_Type;
59
59
60 //---------------------------------------------------------------
60 //---------------------------------------------------------------
61 //! a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjects)
61 //! a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjects)
62 typedef struct {
62 typedef struct PythonQtInstanceWrapperStruct {
63 PyObject_HEAD
63 PyObject_HEAD
64
64
65 //! the class information, this is set even if the _obj or _wrappedPtr is NULL to support typed NULL pointers
65 //! the class information, this is set even if the _obj or _wrappedPtr is NULL to support typed NULL pointers
66 PythonQtClassInfo* classInfo();
66 PythonQtClassInfo* classInfo();
67
67
68 //! set the QObject pointer
68 //! set the QObject pointer
69 void setQObject(QObject* object) {
69 void setQObject(QObject* object) {
70 _obj = object;
70 _obj = object;
71 _objPointerCopy = object;
71 _objPointerCopy = object;
72 }
72 }
73
73
74 //! pointer to the wrapped Qt object or if _wrappedPtr is set, the Qt object that wraps the C++ Ptr
74 //! pointer to the wrapped Qt object or if _wrappedPtr is set, the Qt object that wraps the C++ Ptr
75 QPointer<QObject> _obj;
75 QPointer<QObject> _obj;
76 //! a copy of the _obj pointer, which is required because the wrapper needs to
76 //! a copy of the _obj pointer, which is required because the wrapper needs to
77 //! deregister itself via the _obj pointer, even when the QPointer<QObject> object was destroyed
77 //! deregister itself via the _obj pointer, even when the QPointer<QObject> object was destroyed
78 void* _objPointerCopy;
78 void* _objPointerCopy;
79
79
80 //! optional C++ object Ptr that is wrapped by the above _obj
80 //! optional C++ object Ptr that is wrapped by the above _obj
81 void* _wrappedPtr;
81 void* _wrappedPtr;
82
82
83 //! flag that stores if the object is owned by pythonQt
83 //! flag that stores if the object is owned by pythonQt
84 bool _ownedByPythonQt;
84 bool _ownedByPythonQt;
85
85
86 //! stores that the owned object should be destroyed using QMetaType::destroy()
86 //! stores that the owned object should be destroyed using QMetaType::destroy()
87 bool _useQMetaTypeDestroy;
87 bool _useQMetaTypeDestroy;
88
88
89 } PythonQtInstanceWrapper;
89 } PythonQtInstanceWrapper;
90
90
91
91
92 #endif No newline at end of file
92 #endif
General Comments 0
You need to be logged in to leave comments. Login now