##// END OF EJS Templates
changed order of initializers...
florianlink -
r39:1992a84af372
parent child
Show More
@@ -1,243 +1,243
1 1 #ifndef _PYTHONQTCLASSINFO_H
2 2 #define _PYTHONQTCLASSINFO_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 #include <QMetaObject>
37 37 #include <QMetaMethod>
38 38 #include <QHash>
39 39 #include <QByteArray>
40 40 #include <QList>
41 41 #include "PythonQt.h"
42 42
43 43 class PythonQtSlotInfo;
44 44
45 45 struct PythonQtMemberInfo {
46 46 enum Type {
47 47 Invalid, Slot, EnumValue, Property, NotFound
48 48 };
49 49
50 PythonQtMemberInfo():_slot(NULL),_enumValue(0),_type(Invalid) { }
50 PythonQtMemberInfo():_type(Invalid),_slot(NULL),_enumValue(0) { }
51 51
52 52 PythonQtMemberInfo(PythonQtSlotInfo* info) {
53 53 _type = Slot;
54 54 _slot = info;
55 55 _enumValue = 0;
56 56 }
57 57
58 58 PythonQtMemberInfo(unsigned int enumValue) {
59 59 _type = EnumValue;
60 60 _slot = NULL;
61 61 _enumValue = enumValue;
62 62 }
63 63
64 64 PythonQtMemberInfo(const QMetaProperty& prop) {
65 65 _type = Property;
66 66 _slot = NULL;
67 67 _enumValue = 0;
68 68 _property = prop;
69 69 }
70 70
71 71 Type _type;
72 72
73 73 // TODO: this could be a union...
74 74 PythonQtSlotInfo* _slot;
75 75 unsigned int _enumValue;
76 76 QMetaProperty _property;
77 77 };
78 78
79 79 //! a class that stores all required information about a Qt object (and an optional associated C++ class name)
80 80 /*! for fast lookup of slots when calling the object from Python
81 81 */
82 82 class PythonQtClassInfo {
83 83
84 84 public:
85 85 PythonQtClassInfo();
86 86 ~PythonQtClassInfo();
87 87
88 88 //! store information about parent classes
89 89 struct ParentClassInfo {
90 90 ParentClassInfo(PythonQtClassInfo* parent, int upcastingOffset=0):_parent(parent),_upcastingOffset(upcastingOffset)
91 91 {};
92 92
93 93 PythonQtClassInfo* _parent;
94 94 int _upcastingOffset;
95 95 };
96 96
97 97
98 98 //! setup as a QObject, taking the meta object as meta information about the QObject
99 99 void setupQObject(const QMetaObject* meta);
100 100
101 101 //! setup as a CPP (non-QObject), taking the classname
102 102 void setupCPPObject(const QByteArray& classname);
103 103
104 104 //! get the Python method definition for a given slot name (without return type and signature)
105 105 PythonQtMemberInfo member(const char* member);
106 106
107 107 //! get access to the constructor slot (which may be overloaded if there are multiple constructors)
108 108 PythonQtSlotInfo* constructors();
109 109
110 110 //! get access to the destructor slot
111 111 PythonQtSlotInfo* destructor();
112 112
113 113 //! add a constructor, ownership is passed to classinfo
114 114 void addConstructor(PythonQtSlotInfo* info);
115 115
116 116 //! set a destructor, ownership is passed to classinfo
117 117 void setDestructor(PythonQtSlotInfo* info);
118 118
119 119 //! add a decorator slot, ownership is passed to classinfo
120 120 void addDecoratorSlot(PythonQtSlotInfo* info);
121 121
122 122 //! get the classname (either of the QObject or of the wrapped CPP object)
123 123 const char* className();
124 124
125 125 //! returns if the QObject
126 126 bool isQObject() { return _isQObject; }
127 127
128 128 //! returns if the class is a CPP wrapper
129 129 bool isCPPWrapper() { return !_isQObject; }
130 130
131 131 //! get the meta object
132 132 const QMetaObject* metaObject() { return _meta; }
133 133
134 134 //! set the meta object, this will reset the caching
135 135 void setMetaObject(const QMetaObject* meta);
136 136
137 137 //! returns if this class inherits from the given classname
138 138 bool inherits(const char* classname);
139 139
140 140 //! returns if this class inherits from the given classinfo
141 141 bool inherits(PythonQtClassInfo* info);
142 142
143 143 //! casts the given \c ptr to an object of type \c classname, returns the new pointer
144 144 //! which might be different to \c ptr due to C++ multiple inheritance
145 145 //! (if the cast is not possible or if ptr is NULL, NULL is returned)
146 146 void* castTo(void* ptr, const char* classname);
147 147
148 148 //! get help string for the metaobject
149 149 QString help();
150 150
151 151 //! get list of all properties (on QObjects only, otherwise the list is empty)
152 152 QStringList propertyList();
153 153
154 154 //! get list of all members
155 155 QStringList memberList(bool metaOnly = false);
156 156
157 157 //! get the meta type id of this class (only valid for isCPPWrapper() == true)
158 158 int metaTypeId() { return _metaTypeId; }
159 159
160 160 //! set an additional decorator provider that offers additional decorator slots for this class
161 161 void setDecoratorProvider(PythonQtQObjectCreatorFunctionCB* cb) { _decoratorProviderCB = cb; _decoratorProvider = NULL; }
162 162
163 163 //! get the decorator qobject instance
164 164 QObject* decorator();
165 165
166 166 //! add the parent class info of a CPP object
167 167 void addParentClass(const ParentClassInfo& info) { _parentClasses.append(info); }
168 168
169 169 //! check if the special method "hasOwner" is implemented and if it returns false, which means that the object may be destroyed
170 170 bool hasOwnerMethodButNoOwner(void* object);
171 171
172 172 //! set the associated PythonQtClassWrapper (which handles instance creation of this type)
173 173 void setPythonQtClassWrapper(PyObject* obj) { _pythonQtClassWrapper = obj; }
174 174
175 175 //! get the associated PythonQtClassWrapper (which handles instance creation of this type)
176 176 PyObject* pythonQtClassWrapper() { return _pythonQtClassWrapper; }
177 177
178 178 //! set the shell set instance wrapper cb
179 179 void setShellSetInstanceWrapperCB(PythonQtShellSetInstanceWrapperCB* cb) {
180 180 _shellSetInstanceWrapperCB = cb;
181 181 }
182 182
183 183 //! get the shell set instance wrapper cb
184 184 PythonQtShellSetInstanceWrapperCB* shellSetInstanceWrapperCB() {
185 185 return _shellSetInstanceWrapperCB;
186 186 }
187 187
188 188 //! add a handler for polymorphic downcasting
189 189 void addPolymorphicHandler(PythonQtPolymorphicHandlerCB* cb) { _polymorphicHandlers.append(cb); }
190 190
191 191 //! cast the pointer down in the class hierarchy if a polymorphic handler allows to do that
192 192 void* castDownIfPossible(void* ptr, PythonQtClassInfo** resultClassInfo);
193 193
194 194 private:
195 195 //! clear all cached members
196 196 void clearCachedMembers();
197 197
198 198 void* recursiveCastDownIfPossible(void* ptr, char** resultClassName);
199 199
200 200 PythonQtSlotInfo* findDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* inputInfo, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache, int upcastingOffset);
201 201 void listDecoratorSlotsFromDecoratorProvider(QStringList& list, bool metaOnly);
202 202 PythonQtSlotInfo* recursiveFindDecoratorSlotsFromDecoratorProvider(const char* memberName, PythonQtSlotInfo* inputInfo, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache, int upcastingOffset);
203 203
204 204 void recursiveCollectClassInfos(QList<PythonQtClassInfo*>& classInfoObjects);
205 205 void recursiveCollectDecoratorObjects(QList<QObject*>& decoratorObjects);
206 206
207 207 bool lookForPropertyAndCache(const char* memberName);
208 208 bool lookForMethodAndCache(const char* memberName);
209 209 bool lookForEnumAndCache(const QMetaObject* m, const char* memberName);
210 210
211 211 PythonQtSlotInfo* findDecoratorSlots(const char* memberName, int memberNameLen, PythonQtSlotInfo* tail, bool &found, QHash<QByteArray, PythonQtMemberInfo>& memberCache, int upcastingOffset);
212 212 int findCharOffset(const char* sigStart, char someChar);
213 213
214 214 QHash<QByteArray, PythonQtMemberInfo> _cachedMembers;
215 215
216 216 PythonQtSlotInfo* _constructors;
217 217 PythonQtSlotInfo* _destructor;
218 218 QList<PythonQtSlotInfo*> _decoratorSlots;
219 219
220 220 const QMetaObject* _meta;
221 221
222 222 QByteArray _wrappedClassName;
223 223 QList<ParentClassInfo> _parentClasses;
224 224
225 225 QList<PythonQtPolymorphicHandlerCB*> _polymorphicHandlers;
226 226
227 227 QObject* _decoratorProvider;
228 228 PythonQtQObjectCreatorFunctionCB* _decoratorProviderCB;
229 229
230 230 PyObject* _pythonQtClassWrapper;
231 231
232 232 PythonQtShellSetInstanceWrapperCB* _shellSetInstanceWrapperCB;
233 233
234 234 int _metaTypeId;
235 235
236 236 bool _isQObject;
237 237
238 238 };
239 239
240 240 //---------------------------------------------------------------
241 241
242 242
243 243 #endif
General Comments 0
You need to be logged in to leave comments. Login now