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