SourceForge.net Logo
PythonQt
PythonQtClassInfo.h
Go to the documentation of this file.
1 #ifndef _PYTHONQTCLASSINFO_H
2 #define _PYTHONQTCLASSINFO_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 #include <QMetaObject>
37 #include <QMetaMethod>
38 #include <QHash>
39 #include <QByteArray>
40 #include <QList>
41 #include "PythonQt.h"
42 
43 class PythonQtSlotInfo;
44 class PythonQtClassInfo;
45 
47 {
50 
51  const QMetaObject* _dynamicMetaObject;
53 };
54 
56  enum Type {
58  };
59 
61 
63 
64  PythonQtMemberInfo(const PythonQtObjectPtr& enumValue);
65 
66  PythonQtMemberInfo(const QMetaProperty& prop);
67 
69 
70  // TODO: this could be a union...
74  QMetaProperty _property;
75 };
76 
78 
81 
82 public:
85 
87  struct ParentClassInfo {
88  ParentClassInfo(PythonQtClassInfo* parent, int upcastingOffset=0):_parent(parent),_upcastingOffset(upcastingOffset)
89  {};
90 
91  PythonQtClassInfo* _parent;
93  };
94 
95 
97  void setupQObject(const QMetaObject* meta);
98 
100  void setupCPPObject(const QByteArray& classname);
101 
103  void setTypeSlots(int typeSlots) { _typeSlots = typeSlots; }
105  int typeSlots() const { return _typeSlots; }
106 
108  PythonQtMemberInfo member(const char* member);
109 
111  PythonQtSlotInfo* constructors();
112 
114  PythonQtSlotInfo* destructor();
115 
117  void addConstructor(PythonQtSlotInfo* info);
118 
120  void setDestructor(PythonQtSlotInfo* info);
121 
123  void addDecoratorSlot(PythonQtSlotInfo* info);
124 
126  void addNestedClass(PythonQtClassInfo* info);
127 
129  const QByteArray& className() const;
130 
132  QByteArray unscopedClassName() const;
133 
135  bool isQObject() { return _isQObject; }
136 
138  bool isCPPWrapper() { return !_isQObject; }
139 
141  const QMetaObject* metaObject() { return _meta; }
142 
144  void setMetaObject(const QMetaObject* meta);
145 
147  bool inherits(const char* classname);
148 
150  bool inherits(PythonQtClassInfo* info);
151 
155  void* castTo(void* ptr, const char* classname);
156 
158  QString help();
159 
161  QStringList propertyList();
162 
164  QStringList memberList();
165 
167  int metaTypeId() { return _metaTypeId; }
168 
170  void setDecoratorProvider(PythonQtQObjectCreatorFunctionCB* cb);
171 
173  QObject* decorator();
174 
176  void addParentClass(const ParentClassInfo& info) { _parentClasses.append(info); }
177 
179  void setPythonQtClassWrapper(PyObject* obj) { _pythonQtClassWrapper = obj; }
180 
182  PyObject* pythonQtClassWrapper() { return _pythonQtClassWrapper; }
183 
186  _shellSetInstanceWrapperCB = cb;
187  }
188 
191  return _shellSetInstanceWrapperCB;
192  }
193 
195  void addPolymorphicHandler(PythonQtPolymorphicHandlerCB* cb) { _polymorphicHandlers.append(cb); }
196 
198  void* castDownIfPossible(void* ptr, PythonQtClassInfo** resultClassInfo);
199 
201  static PyObject* findEnumWrapper(const QByteArray& name, PythonQtClassInfo* localScope, bool* isLocalEnum = NULL);
202 
204  void clearNotFoundCachedMembers();
205 
207  const QList<PythonQtClassInfo*>& nestedClasses() { return _nestedClasses; }
208 
213  PyObject* copyObject(void* cppObject);
214 
216  PythonQtSlotInfo* getCopyConstructor();
217 
219  void setReferenceCounting(PythonQtVoidPtrCB* refCB, PythonQtVoidPtrCB* unrefCB);
220 
222  PythonQtVoidPtrCB* referenceCountingRefCB();
224  PythonQtVoidPtrCB* referenceCountingUnrefCB();
225 
228  PyObject* getPythonTypeForProperty(const QString& name);
229 
231  PythonQtClassInfo* getClassInfoForProperty( const QString& name );
232 
233 private:
234  void updateRefCountingCBs();
235 
236  void createEnumWrappers();
237  void createEnumWrappers(const QMetaObject* meta);
238  PyObject* findEnumWrapper(const char* name);
239 
241  void clearCachedMembers();
242 
243  void* recursiveCastDownIfPossible(void* ptr, const char** resultClassName);
244 
245  PythonQtSlotInfo* findDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* inputInfo, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache, int upcastingOffset);
246  void listDecoratorSlotsFromDecoratorProvider(QStringList& list, bool metaOnly);
247  PythonQtSlotInfo* recursiveFindDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* inputInfo, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache, int upcastingOffset);
248 
249  void recursiveCollectClassInfos(QList<PythonQtClassInfo*>& classInfoObjects);
250  void recursiveCollectDecoratorObjects(QList<QObject*>& decoratorObjects);
251 
252  bool lookForPropertyAndCache(const char* memberName);
253  bool lookForMethodAndCache(const char* memberName);
254  bool lookForEnumAndCache(const QMetaObject* m, const char* memberName);
255 
256  PythonQtSlotInfo* findDecoratorSlots(const char* memberName, PythonQtSlotInfo* tail, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache, int upcastingOffset);
257  int findCharOffset(const char* sigStart, char someChar);
258 
259  QHash<QByteArray, PythonQtMemberInfo> _cachedMembers;
260 
261  PythonQtSlotInfo* _constructors;
262  PythonQtSlotInfo* _destructor;
263 
264  PythonQtVoidPtrCB* _refCallback;
265  PythonQtVoidPtrCB* _unrefCallback;
266 
267  QList<PythonQtSlotInfo*> _decoratorSlots;
268 
269  QList<PythonQtObjectPtr> _enumWrappers;
270 
271  const QMetaObject* _meta;
272 
273  QByteArray _wrappedClassName;
274  QList<ParentClassInfo> _parentClasses;
275 
276  QList<PythonQtPolymorphicHandlerCB*> _polymorphicHandlers;
277 
278  QList<PythonQtClassInfo*> _nestedClasses;
279 
280  QObject* _decoratorProvider;
281  PythonQtQObjectCreatorFunctionCB* _decoratorProviderCB;
282 
283  PyObject* _pythonQtClassWrapper;
284 
285  PythonQtShellSetInstanceWrapperCB* _shellSetInstanceWrapperCB;
286 
287  int _metaTypeId;
288  int _typeSlots;
289 
290  bool _isQObject;
291  bool _enumsCreated;
292  bool _searchPolymorphicHandlerOnParent;
293  bool _searchRefCountCB;
294 
295 };
296 
297 //---------------------------------------------------------------
298 
299 
300 #endif
ParentClassInfo(PythonQtClassInfo *parent, int upcastingOffset=0)
PythonQtObjectPtr _enumValue
void * PythonQtPolymorphicHandlerCB(const void *ptr, const char **class_name)
Definition: PythonQt.h:74
store information about parent classes
PyObject * pythonQtClassWrapper()
get the associated PythonQtClassWrapper (which handles instance creation of this type) ...
a class that stores all required information about a Qt object (and an optional associated C++ class ...
void setShellSetInstanceWrapperCB(PythonQtShellSetInstanceWrapperCB *cb)
set the shell set instance wrapper cb
void PythonQtVoidPtrCB(void *object)
Definition: PythonQt.h:71
const QList< PythonQtClassInfo * > & nestedClasses()
get nested classes
const QMetaObject * metaObject()
get the meta object
bool isQObject()
returns if the QObject
int metaTypeId()
get the meta type id of this class (only valid for isCPPWrapper() == true)
#define PYTHONQT_EXPORT
struct _object PyObject
void addPolymorphicHandler(PythonQtPolymorphicHandlerCB *cb)
add a handler for polymorphic downcasting
const QMetaObject * _dynamicMetaObject
QMetaProperty _property
bool isCPPWrapper()
returns if the class is a CPP wrapper
a smart pointer that stores a PyObject pointer and that handles reference counting automatically ...
void PythonQtShellSetInstanceWrapperCB(void *object, PythonQtInstanceWrapper *wrapper)
Definition: PythonQt.h:76
int typeSlots() const
get the type capabilities
QObject * PythonQtQObjectCreatorFunctionCB()
callback to create a QObject lazily
Definition: PythonQt.h:141
PythonQtSlotInfo * _slot
PythonQtShellSetInstanceWrapperCB * shellSetInstanceWrapperCB()
get the shell set instance wrapper cb
stores information about a slot, including a next pointer to overloaded slots
void setPythonQtClassWrapper(PyObject *obj)
set the associated PythonQtClassWrapper (which handles instance creation of this type) ...
void setTypeSlots(int typeSlots)
set the type capabilities
void addParentClass(const ParentClassInfo &info)
add the parent class info of a CPP object
PythonQtClassInfo * _classInfo