PythonQt
PythonQtInstanceWrapper.h
Go to the documentation of this file.
1 #ifndef _PYTHONQTINSTANCEWRAPPER_H
2 #define _PYTHONQTINSTANCEWRAPPER_H
3 
4 /*
5  *
6  * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * Further, this software is distributed without any warranty that it is
19  * free of the rightful claim of any third person regarding infringement
20  * or the like. Any license provided herein, whether implied or
21  * otherwise, applies only to this software file. Patent licenses, if
22  * any, provided herein do not apply to combinations of this program with
23  * other software, or any other product whatsoever.
24  *
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
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28  *
29  * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
30  * 28359 Bremen, Germany or:
31  *
32  * http://www.mevis.de
33  *
34  */
35 
36 //----------------------------------------------------------------------------------
43 //----------------------------------------------------------------------------------
44 
45 #include "PythonQtPythonInclude.h"
46 
47 #include "PythonQtSystem.h"
48 #include "PythonQtClassWrapper.h"
49 #include <QPointer>
50 
51 #include "structmember.h"
52 #include "methodobject.h"
53 #include "compile.h"
54 
55 class PythonQtClassInfo;
56 class QObject;
57 
59 
60 //---------------------------------------------------------------
63  PyObject_HEAD
64 
67  { return ((PythonQtClassWrapper*)Py_TYPE(this))->_classInfo; }
68 
70  { return ((PythonQtClassWrapper*)Py_TYPE(this))->_dynamicClassInfo; }
71 
73  void setQObject(QObject* object) {
74  _obj = object;
75  _objPointerCopy = object;
76  }
77 
80  // we pass the ownership to C++
81  _ownedByPythonQt = false;
82  // handle shell instance
83  if (_isShellInstance) {
85  // ref count the wrapper, so that the Python part of the shell instance can not go
86  // away until the C++ object gets deleted...
87  Py_INCREF((PyObject*)this);
89  }
90  }
91  }
92 
95  _ownedByPythonQt = true;
96  // if the shell instance was owned by C++ and the ownership goes to Python,
97  // we need to remove the extra ref count that kept the Python part alive from the C++ side.
99  Py_DECREF((PyObject*)this);
101  }
102  }
103 
104 
106  QPointer<QObject> _obj;
110 
112  void* _wrappedPtr;
113 
114  // TODO xxx: put booleans into int that holds flags
115 
118 
121 
124 
127 
128 };
129 
131 
133 
134 #endif
135 
int PythonQtInstanceWrapper_init(PythonQtInstanceWrapper *self, PyObject *args, PyObject *kwds)
PYTHONQT_EXPORT PyTypeObject PythonQtInstanceWrapper_Type
PyObject * PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper *self)
struct _object PyObject
#define PYTHONQT_EXPORT
a class that stores all required information about a Qt object (and an optional associated C++ class ...
a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjec...
void * _wrappedPtr
optional C++ object Ptr that is wrapped by the above _obj
void passOwnershipToCPP()
Passes the ownership of the wrapped object to C++.
bool _shellInstanceRefCountsWrapper
stores if the shell instance (C++) owns the wrapper with its ref count
void setQObject(QObject *object)
set the QObject pointer
bool _ownedByPythonQt
flag that stores if the object is owned by pythonQt
bool _useQMetaTypeDestroy
stores that the owned object should be destroyed using QMetaType::destroy()
PyObject_HEAD PythonQtClassInfo * classInfo()
the class information, this is set even if the _obj or _wrappedPtr is NULL to support typed NULL poin...
PythonQtDynamicClassInfo * dynamicClassInfo()
void passOwnershipToPython()
Passes the ownership to Python.
bool _isShellInstance
stores if the object is a shell instance
QPointer< QObject > _obj
pointer to the wrapped Qt object or if _wrappedPtr is set, the Qt object that wraps the C++ Ptr