##// END OF EJS Templates
cleared cached signature hash to avoid dangling pointers...
florianlink -
r203:64a9f70b03c9
parent child
Show More
@@ -1,377 +1,378
1 /*
1 /*
2 *
2 *
3 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
3 * Copyright (C) 2010 MeVis Medical Solutions AG 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 Medical Solutions AG, Universitaetsallee 29,
26 * Contact information: MeVis Medical Solutions AG, 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 PythonQtMethodInfo.cpp
35 // \file PythonQtMethodInfo.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 "PythonQtMethodInfo.h"
42 #include "PythonQtMethodInfo.h"
43 #include "PythonQtClassInfo.h"
43 #include "PythonQtClassInfo.h"
44 #include <iostream>
44 #include <iostream>
45
45
46 QHash<QByteArray, PythonQtMethodInfo*> PythonQtMethodInfo::_cachedSignatures;
46 QHash<QByteArray, PythonQtMethodInfo*> PythonQtMethodInfo::_cachedSignatures;
47 QHash<QByteArray, QByteArray> PythonQtMethodInfo::_parameterNameAliases;
47 QHash<QByteArray, QByteArray> PythonQtMethodInfo::_parameterNameAliases;
48
48
49 PythonQtMethodInfo::PythonQtMethodInfo(const QMetaMethod& meta, PythonQtClassInfo* classInfo)
49 PythonQtMethodInfo::PythonQtMethodInfo(const QMetaMethod& meta, PythonQtClassInfo* classInfo)
50 {
50 {
51 #ifdef PYTHONQT_DEBUG
51 #ifdef PYTHONQT_DEBUG
52 QByteArray sig(meta.signature());
52 QByteArray sig(meta.signature());
53 sig = sig.mid(sig.indexOf('('));
53 sig = sig.mid(sig.indexOf('('));
54 QByteArray fullSig = QByteArray(meta.typeName()) + " " + sig;
54 QByteArray fullSig = QByteArray(meta.typeName()) + " " + sig;
55 std::cout << "caching " << fullSig.data() << std::endl;
55 std::cout << "caching " << fullSig.data() << std::endl;
56 #endif
56 #endif
57
57
58 ParameterInfo type;
58 ParameterInfo type;
59 fillParameterInfo(type, QByteArray(meta.typeName()), classInfo);
59 fillParameterInfo(type, QByteArray(meta.typeName()), classInfo);
60 _parameters.append(type);
60 _parameters.append(type);
61 QList<QByteArray> names = meta.parameterTypes();
61 QList<QByteArray> names = meta.parameterTypes();
62 foreach (const QByteArray& name, names) {
62 foreach (const QByteArray& name, names) {
63 fillParameterInfo(type, name, classInfo);
63 fillParameterInfo(type, name, classInfo);
64 _parameters.append(type);
64 _parameters.append(type);
65 }
65 }
66 }
66 }
67
67
68 PythonQtMethodInfo::PythonQtMethodInfo(const QByteArray& typeName, const QList<QByteArray>& args)
68 PythonQtMethodInfo::PythonQtMethodInfo(const QByteArray& typeName, const QList<QByteArray>& args)
69 {
69 {
70 ParameterInfo type;
70 ParameterInfo type;
71 fillParameterInfo(type, typeName, NULL);
71 fillParameterInfo(type, typeName, NULL);
72 _parameters.append(type);
72 _parameters.append(type);
73 foreach (const QByteArray& name, args) {
73 foreach (const QByteArray& name, args) {
74 fillParameterInfo(type, name, NULL);
74 fillParameterInfo(type, name, NULL);
75 _parameters.append(type);
75 _parameters.append(type);
76 }
76 }
77 }
77 }
78
78
79 const PythonQtMethodInfo* PythonQtMethodInfo::getCachedMethodInfo(const QMetaMethod& signal, PythonQtClassInfo* classInfo)
79 const PythonQtMethodInfo* PythonQtMethodInfo::getCachedMethodInfo(const QMetaMethod& signal, PythonQtClassInfo* classInfo)
80 {
80 {
81 QByteArray sig(signal.signature());
81 QByteArray sig(signal.signature());
82 sig = sig.mid(sig.indexOf('('));
82 sig = sig.mid(sig.indexOf('('));
83 QByteArray fullSig = QByteArray(signal.typeName()) + " " + sig;
83 QByteArray fullSig = QByteArray(signal.typeName()) + " " + sig;
84 PythonQtMethodInfo* result = _cachedSignatures.value(fullSig);
84 PythonQtMethodInfo* result = _cachedSignatures.value(fullSig);
85 if (!result) {
85 if (!result) {
86 result = new PythonQtMethodInfo(signal, classInfo);
86 result = new PythonQtMethodInfo(signal, classInfo);
87 _cachedSignatures.insert(fullSig, result);
87 _cachedSignatures.insert(fullSig, result);
88 }
88 }
89 return result;
89 return result;
90 }
90 }
91
91
92 const PythonQtMethodInfo* PythonQtMethodInfo::getCachedMethodInfoFromArgumentList(int numArgs, const char** args)
92 const PythonQtMethodInfo* PythonQtMethodInfo::getCachedMethodInfoFromArgumentList(int numArgs, const char** args)
93 {
93 {
94 QByteArray typeName = args[0];
94 QByteArray typeName = args[0];
95 QList<QByteArray> arguments;
95 QList<QByteArray> arguments;
96 QByteArray fullSig = typeName;
96 QByteArray fullSig = typeName;
97 fullSig += "(";
97 fullSig += "(";
98 for (int i =1;i<numArgs; i++) {
98 for (int i =1;i<numArgs; i++) {
99 if (i>1) {
99 if (i>1) {
100 fullSig += ",";
100 fullSig += ",";
101 }
101 }
102 QByteArray arg(args[i]);
102 QByteArray arg(args[i]);
103 fullSig += arg;
103 fullSig += arg;
104 arguments << arg;
104 arguments << arg;
105 }
105 }
106 fullSig += ")";
106 fullSig += ")";
107 PythonQtMethodInfo* result = _cachedSignatures.value(fullSig);
107 PythonQtMethodInfo* result = _cachedSignatures.value(fullSig);
108 if (!result) {
108 if (!result) {
109 result = new PythonQtMethodInfo(typeName, arguments);
109 result = new PythonQtMethodInfo(typeName, arguments);
110 _cachedSignatures.insert(fullSig, result);
110 _cachedSignatures.insert(fullSig, result);
111 }
111 }
112 return result;
112 return result;
113 }
113 }
114
114
115 void PythonQtMethodInfo::fillParameterInfo(ParameterInfo& type, const QByteArray& orgName, PythonQtClassInfo* classInfo)
115 void PythonQtMethodInfo::fillParameterInfo(ParameterInfo& type, const QByteArray& orgName, PythonQtClassInfo* classInfo)
116 {
116 {
117 QByteArray name = orgName;
117 QByteArray name = orgName;
118
118
119 type.enumWrapper = NULL;
119 type.enumWrapper = NULL;
120
120
121 int len = name.length();
121 int len = name.length();
122 if (len>0) {
122 if (len>0) {
123 if (strncmp(name.constData(), "const ", 6)==0) {
123 if (strncmp(name.constData(), "const ", 6)==0) {
124 name = name.mid(6);
124 name = name.mid(6);
125 len -= 6;
125 len -= 6;
126 type.isConst = true;
126 type.isConst = true;
127 } else {
127 } else {
128 type.isConst = false;
128 type.isConst = false;
129 }
129 }
130 char pointerCount = 0;
130 char pointerCount = 0;
131 bool hadReference = false;
131 bool hadReference = false;
132 // remove * and & from the end of the string, handle & and * the same way
132 // remove * and & from the end of the string, handle & and * the same way
133 while (name.at(len-1) == '*') {
133 while (name.at(len-1) == '*') {
134 len--;
134 len--;
135 pointerCount++;
135 pointerCount++;
136 }
136 }
137 while (name.at(len-1) == '&') {
137 while (name.at(len-1) == '&') {
138 len--;
138 len--;
139 hadReference = true;
139 hadReference = true;
140 }
140 }
141 if (len!=name.length()) {
141 if (len!=name.length()) {
142 name = name.left(len);
142 name = name.left(len);
143 }
143 }
144 type.pointerCount = pointerCount;
144 type.pointerCount = pointerCount;
145
145
146 QByteArray alias = _parameterNameAliases.value(name);
146 QByteArray alias = _parameterNameAliases.value(name);
147 if (!alias.isEmpty()) {
147 if (!alias.isEmpty()) {
148 name = alias;
148 name = alias;
149 }
149 }
150
150
151 type.typeId = nameToType(name);
151 type.typeId = nameToType(name);
152 if ((type.pointerCount == 0) && type.typeId == Unknown) {
152 if ((type.pointerCount == 0) && type.typeId == Unknown) {
153 type.typeId = QMetaType::type(name.constData());
153 type.typeId = QMetaType::type(name.constData());
154 if (type.typeId == QMetaType::Void) {
154 if (type.typeId == QMetaType::Void) {
155 type.typeId = Unknown;
155 type.typeId = Unknown;
156 }
156 }
157 }
157 }
158 type.name = name;
158 type.name = name;
159
159
160 if (type.typeId == PythonQtMethodInfo::Unknown || type.typeId >= QMetaType::User) {
160 if (type.typeId == PythonQtMethodInfo::Unknown || type.typeId >= QMetaType::User) {
161 bool isLocalEnum;
161 bool isLocalEnum;
162 // TODOXXX: make use of this flag!
162 // TODOXXX: make use of this flag!
163 type.enumWrapper = PythonQtClassInfo::findEnumWrapper(type.name, classInfo, &isLocalEnum);
163 type.enumWrapper = PythonQtClassInfo::findEnumWrapper(type.name, classInfo, &isLocalEnum);
164 }
164 }
165 } else {
165 } else {
166 type.typeId = QMetaType::Void;
166 type.typeId = QMetaType::Void;
167 type.pointerCount = 0;
167 type.pointerCount = 0;
168 type.isConst = false;
168 type.isConst = false;
169 }
169 }
170 }
170 }
171
171
172 int PythonQtMethodInfo::nameToType(const char* name)
172 int PythonQtMethodInfo::nameToType(const char* name)
173 {
173 {
174 if (_parameterTypeDict.isEmpty()) {
174 if (_parameterTypeDict.isEmpty()) {
175 // we could also use QMetaType::nameToType, but that does a string compare search
175 // we could also use QMetaType::nameToType, but that does a string compare search
176 // and does not support QVariant
176 // and does not support QVariant
177
177
178 // QMetaType names
178 // QMetaType names
179 _parameterTypeDict.insert("long", QMetaType::Long);
179 _parameterTypeDict.insert("long", QMetaType::Long);
180 _parameterTypeDict.insert("int", QMetaType::Int);
180 _parameterTypeDict.insert("int", QMetaType::Int);
181 _parameterTypeDict.insert("short", QMetaType::Short);
181 _parameterTypeDict.insert("short", QMetaType::Short);
182 _parameterTypeDict.insert("char", QMetaType::Char);
182 _parameterTypeDict.insert("char", QMetaType::Char);
183 _parameterTypeDict.insert("ulong", QMetaType::ULong);
183 _parameterTypeDict.insert("ulong", QMetaType::ULong);
184 _parameterTypeDict.insert("unsigned long", QMetaType::ULong);
184 _parameterTypeDict.insert("unsigned long", QMetaType::ULong);
185 _parameterTypeDict.insert("uint", QMetaType::UInt);
185 _parameterTypeDict.insert("uint", QMetaType::UInt);
186 _parameterTypeDict.insert("unsigned int", QMetaType::UInt);
186 _parameterTypeDict.insert("unsigned int", QMetaType::UInt);
187 _parameterTypeDict.insert("ushort", QMetaType::UShort);
187 _parameterTypeDict.insert("ushort", QMetaType::UShort);
188 _parameterTypeDict.insert("unsigned short", QMetaType::UShort);
188 _parameterTypeDict.insert("unsigned short", QMetaType::UShort);
189 _parameterTypeDict.insert("uchar", QMetaType::UChar);
189 _parameterTypeDict.insert("uchar", QMetaType::UChar);
190 _parameterTypeDict.insert("unsigned char", QMetaType::UChar);
190 _parameterTypeDict.insert("unsigned char", QMetaType::UChar);
191 _parameterTypeDict.insert("bool", QMetaType::Bool);
191 _parameterTypeDict.insert("bool", QMetaType::Bool);
192 _parameterTypeDict.insert("float", QMetaType::Float);
192 _parameterTypeDict.insert("float", QMetaType::Float);
193 _parameterTypeDict.insert("double", QMetaType::Double);
193 _parameterTypeDict.insert("double", QMetaType::Double);
194 _parameterTypeDict.insert("qreal", QMetaType::Double);
194 _parameterTypeDict.insert("qreal", QMetaType::Double);
195 _parameterTypeDict.insert("QChar", QMetaType::QChar);
195 _parameterTypeDict.insert("QChar", QMetaType::QChar);
196 _parameterTypeDict.insert("QByteArray", QMetaType::QByteArray);
196 _parameterTypeDict.insert("QByteArray", QMetaType::QByteArray);
197 _parameterTypeDict.insert("QString", QMetaType::QString);
197 _parameterTypeDict.insert("QString", QMetaType::QString);
198 _parameterTypeDict.insert("", QMetaType::Void);
198 _parameterTypeDict.insert("", QMetaType::Void);
199 _parameterTypeDict.insert("void", QMetaType::Void);
199 _parameterTypeDict.insert("void", QMetaType::Void);
200
200
201 // GL types
201 // GL types
202 _parameterTypeDict.insert("GLenum", QMetaType::UInt);
202 _parameterTypeDict.insert("GLenum", QMetaType::UInt);
203 _parameterTypeDict.insert("GLboolean", QMetaType::UChar);
203 _parameterTypeDict.insert("GLboolean", QMetaType::UChar);
204 _parameterTypeDict.insert("GLbitfield", QMetaType::UInt);
204 _parameterTypeDict.insert("GLbitfield", QMetaType::UInt);
205 _parameterTypeDict.insert("GLbyte", QMetaType::Char);
205 _parameterTypeDict.insert("GLbyte", QMetaType::Char);
206 _parameterTypeDict.insert("GLubyte", QMetaType::UChar);
206 _parameterTypeDict.insert("GLubyte", QMetaType::UChar);
207 _parameterTypeDict.insert("GLshort", QMetaType::Short);
207 _parameterTypeDict.insert("GLshort", QMetaType::Short);
208 _parameterTypeDict.insert("GLushort", QMetaType::UShort);
208 _parameterTypeDict.insert("GLushort", QMetaType::UShort);
209 _parameterTypeDict.insert("GLint", QMetaType::Int);
209 _parameterTypeDict.insert("GLint", QMetaType::Int);
210 _parameterTypeDict.insert("GLuint", QMetaType::UInt);
210 _parameterTypeDict.insert("GLuint", QMetaType::UInt);
211 _parameterTypeDict.insert("GLsizei", QMetaType::UInt);
211 _parameterTypeDict.insert("GLsizei", QMetaType::UInt);
212 _parameterTypeDict.insert("GLclampf", QMetaType::Float);
212 _parameterTypeDict.insert("GLclampf", QMetaType::Float);
213 _parameterTypeDict.insert("GLfloat", QMetaType::Float);
213 _parameterTypeDict.insert("GLfloat", QMetaType::Float);
214 _parameterTypeDict.insert("GLclampd", QMetaType::Double);
214 _parameterTypeDict.insert("GLclampd", QMetaType::Double);
215 _parameterTypeDict.insert("GLdouble", QMetaType::Double);
215 _parameterTypeDict.insert("GLdouble", QMetaType::Double);
216 _parameterTypeDict.insert("GLvoid", QMetaType::Void);
216 _parameterTypeDict.insert("GLvoid", QMetaType::Void);
217 if (QT_POINTER_SIZE == 8) {
217 if (QT_POINTER_SIZE == 8) {
218 _parameterTypeDict.insert("qgl_GLintptr", QMetaType::LongLong);
218 _parameterTypeDict.insert("qgl_GLintptr", QMetaType::LongLong);
219 _parameterTypeDict.insert("qgl_GLsizeiptr", QMetaType::LongLong);
219 _parameterTypeDict.insert("qgl_GLsizeiptr", QMetaType::LongLong);
220 } else {
220 } else {
221 _parameterTypeDict.insert("qgl_GLintptr", QMetaType::Int);
221 _parameterTypeDict.insert("qgl_GLintptr", QMetaType::Int);
222 _parameterTypeDict.insert("qgl_GLsizeiptr", QMetaType::Int);
222 _parameterTypeDict.insert("qgl_GLsizeiptr", QMetaType::Int);
223 }
223 }
224
224
225 // QVariant names
225 // QVariant names
226 _parameterTypeDict.insert("Q_LLONG", QMetaType::LongLong);
226 _parameterTypeDict.insert("Q_LLONG", QMetaType::LongLong);
227 _parameterTypeDict.insert("Q_ULLONG", QMetaType::ULongLong);
227 _parameterTypeDict.insert("Q_ULLONG", QMetaType::ULongLong);
228 _parameterTypeDict.insert("qlonglong", QMetaType::LongLong);
228 _parameterTypeDict.insert("qlonglong", QMetaType::LongLong);
229 _parameterTypeDict.insert("qulonglong", QMetaType::ULongLong);
229 _parameterTypeDict.insert("qulonglong", QMetaType::ULongLong);
230 _parameterTypeDict.insert("qint64", QMetaType::LongLong);
230 _parameterTypeDict.insert("qint64", QMetaType::LongLong);
231 _parameterTypeDict.insert("quint64", QMetaType::ULongLong);
231 _parameterTypeDict.insert("quint64", QMetaType::ULongLong);
232 _parameterTypeDict.insert("QVariantMap", QMetaType::QVariantMap);
232 _parameterTypeDict.insert("QVariantMap", QMetaType::QVariantMap);
233 _parameterTypeDict.insert("QVariantList", QMetaType::QVariantList);
233 _parameterTypeDict.insert("QVariantList", QMetaType::QVariantList);
234 _parameterTypeDict.insert("QMap<QString,QVariant>", QMetaType::QVariantMap);
234 _parameterTypeDict.insert("QMap<QString,QVariant>", QMetaType::QVariantMap);
235 _parameterTypeDict.insert("QList<QVariant>", QMetaType::QVariantList);
235 _parameterTypeDict.insert("QList<QVariant>", QMetaType::QVariantList);
236 _parameterTypeDict.insert("QStringList", QMetaType::QStringList);
236 _parameterTypeDict.insert("QStringList", QMetaType::QStringList);
237 _parameterTypeDict.insert("QBitArray", QMetaType::QBitArray);
237 _parameterTypeDict.insert("QBitArray", QMetaType::QBitArray);
238 _parameterTypeDict.insert("QDate", QMetaType::QDate);
238 _parameterTypeDict.insert("QDate", QMetaType::QDate);
239 _parameterTypeDict.insert("QTime", QMetaType::QTime);
239 _parameterTypeDict.insert("QTime", QMetaType::QTime);
240 _parameterTypeDict.insert("QDateTime", QMetaType::QDateTime);
240 _parameterTypeDict.insert("QDateTime", QMetaType::QDateTime);
241 _parameterTypeDict.insert("QUrl", QMetaType::QUrl);
241 _parameterTypeDict.insert("QUrl", QMetaType::QUrl);
242 _parameterTypeDict.insert("QLocale", QMetaType::QLocale);
242 _parameterTypeDict.insert("QLocale", QMetaType::QLocale);
243 _parameterTypeDict.insert("QRect", QMetaType::QRect);
243 _parameterTypeDict.insert("QRect", QMetaType::QRect);
244 _parameterTypeDict.insert("QRectF", QMetaType::QRectF);
244 _parameterTypeDict.insert("QRectF", QMetaType::QRectF);
245 _parameterTypeDict.insert("QSize", QMetaType::QSize);
245 _parameterTypeDict.insert("QSize", QMetaType::QSize);
246 _parameterTypeDict.insert("QSizeF", QMetaType::QSizeF);
246 _parameterTypeDict.insert("QSizeF", QMetaType::QSizeF);
247 _parameterTypeDict.insert("QLine", QMetaType::QLine);
247 _parameterTypeDict.insert("QLine", QMetaType::QLine);
248 _parameterTypeDict.insert("QLineF", QMetaType::QLineF);
248 _parameterTypeDict.insert("QLineF", QMetaType::QLineF);
249 _parameterTypeDict.insert("QPoint", QMetaType::QPoint);
249 _parameterTypeDict.insert("QPoint", QMetaType::QPoint);
250 _parameterTypeDict.insert("QPointF", QMetaType::QPointF);
250 _parameterTypeDict.insert("QPointF", QMetaType::QPointF);
251 _parameterTypeDict.insert("QRegExp", QMetaType::QRegExp);
251 _parameterTypeDict.insert("QRegExp", QMetaType::QRegExp);
252 _parameterTypeDict.insert("QFont", QMetaType::QFont);
252 _parameterTypeDict.insert("QFont", QMetaType::QFont);
253 _parameterTypeDict.insert("QPixmap", QMetaType::QPixmap);
253 _parameterTypeDict.insert("QPixmap", QMetaType::QPixmap);
254 _parameterTypeDict.insert("QBrush", QMetaType::QBrush);
254 _parameterTypeDict.insert("QBrush", QMetaType::QBrush);
255 _parameterTypeDict.insert("QColor", QMetaType::QColor);
255 _parameterTypeDict.insert("QColor", QMetaType::QColor);
256 _parameterTypeDict.insert("QCursor", QMetaType::QCursor);
256 _parameterTypeDict.insert("QCursor", QMetaType::QCursor);
257 _parameterTypeDict.insert("QPalette", QMetaType::QPalette);
257 _parameterTypeDict.insert("QPalette", QMetaType::QPalette);
258 _parameterTypeDict.insert("QIcon", QMetaType::QIcon);
258 _parameterTypeDict.insert("QIcon", QMetaType::QIcon);
259 _parameterTypeDict.insert("QImage", QMetaType::QImage);
259 _parameterTypeDict.insert("QImage", QMetaType::QImage);
260 _parameterTypeDict.insert("QRegion", QMetaType::QRegion);
260 _parameterTypeDict.insert("QRegion", QMetaType::QRegion);
261 _parameterTypeDict.insert("QBitmap", QMetaType::QBitmap);
261 _parameterTypeDict.insert("QBitmap", QMetaType::QBitmap);
262 _parameterTypeDict.insert("QSizePolicy", QMetaType::QSizePolicy);
262 _parameterTypeDict.insert("QSizePolicy", QMetaType::QSizePolicy);
263 _parameterTypeDict.insert("QKeySequence", QMetaType::QKeySequence);
263 _parameterTypeDict.insert("QKeySequence", QMetaType::QKeySequence);
264 _parameterTypeDict.insert("QPen", QMetaType::QPen);
264 _parameterTypeDict.insert("QPen", QMetaType::QPen);
265 _parameterTypeDict.insert("QTextLength", QMetaType::QTextLength);
265 _parameterTypeDict.insert("QTextLength", QMetaType::QTextLength);
266 _parameterTypeDict.insert("QTextFormat", QMetaType::QTextFormat);
266 _parameterTypeDict.insert("QTextFormat", QMetaType::QTextFormat);
267 _parameterTypeDict.insert("QMatrix", QMetaType::QMatrix);
267 _parameterTypeDict.insert("QMatrix", QMetaType::QMatrix);
268 _parameterTypeDict.insert("QVariant", PythonQtMethodInfo::Variant);
268 _parameterTypeDict.insert("QVariant", PythonQtMethodInfo::Variant);
269 // own special types... (none so far, could be e.g. ObjectList
269 // own special types... (none so far, could be e.g. ObjectList
270 }
270 }
271 QHash<QByteArray, int>::const_iterator it = _parameterTypeDict.find(name);
271 QHash<QByteArray, int>::const_iterator it = _parameterTypeDict.find(name);
272 if (it!=_parameterTypeDict.end()) {
272 if (it!=_parameterTypeDict.end()) {
273 return it.value();
273 return it.value();
274 } else {
274 } else {
275 return PythonQtMethodInfo::Unknown;
275 return PythonQtMethodInfo::Unknown;
276 }
276 }
277 }
277 }
278
278
279 void PythonQtMethodInfo::cleanupCachedMethodInfos()
279 void PythonQtMethodInfo::cleanupCachedMethodInfos()
280 {
280 {
281 QHashIterator<QByteArray, PythonQtMethodInfo *> i(_cachedSignatures);
281 QHashIterator<QByteArray, PythonQtMethodInfo *> i(_cachedSignatures);
282 while (i.hasNext()) {
282 while (i.hasNext()) {
283 delete i.next().value();
283 delete i.next().value();
284 }
284 }
285 _cachedSignatures.clear();
285 }
286 }
286
287
287 void PythonQtMethodInfo::addParameterTypeAlias(const QByteArray& alias, const QByteArray& name)
288 void PythonQtMethodInfo::addParameterTypeAlias(const QByteArray& alias, const QByteArray& name)
288 {
289 {
289 _parameterNameAliases.insert(alias, name);
290 _parameterNameAliases.insert(alias, name);
290 }
291 }
291
292
292 //-------------------------------------------------------------------------------------------------
293 //-------------------------------------------------------------------------------------------------
293
294
294 void PythonQtSlotInfo::deleteOverloadsAndThis()
295 void PythonQtSlotInfo::deleteOverloadsAndThis()
295 {
296 {
296 PythonQtSlotInfo* cur = this;
297 PythonQtSlotInfo* cur = this;
297 while(cur->nextInfo()) {
298 while(cur->nextInfo()) {
298 PythonQtSlotInfo* next = cur->nextInfo();
299 PythonQtSlotInfo* next = cur->nextInfo();
299 delete cur;
300 delete cur;
300 cur = next;
301 cur = next;
301 }
302 }
302 }
303 }
303
304
304
305
305 QString PythonQtSlotInfo::fullSignature()
306 QString PythonQtSlotInfo::fullSignature()
306 {
307 {
307 bool skipFirstArg = isInstanceDecorator();
308 bool skipFirstArg = isInstanceDecorator();
308 QString result = _meta.typeName();
309 QString result = _meta.typeName();
309 QByteArray sig = slotName();
310 QByteArray sig = slotName();
310 QList<QByteArray> names = _meta.parameterNames();
311 QList<QByteArray> names = _meta.parameterNames();
311
312
312 bool isStatic = false;
313 bool isStatic = false;
313 bool isConstructor = false;
314 bool isConstructor = false;
314 bool isDestructor = false;
315 bool isDestructor = false;
315
316
316 if (_type == ClassDecorator) {
317 if (_type == ClassDecorator) {
317 if (sig.startsWith("new_")) {
318 if (sig.startsWith("new_")) {
318 sig = sig.mid(4);
319 sig = sig.mid(4);
319 isConstructor = true;
320 isConstructor = true;
320 } else if (sig.startsWith("delete_")) {
321 } else if (sig.startsWith("delete_")) {
321 sig = sig.mid(7);
322 sig = sig.mid(7);
322 isDestructor = true;
323 isDestructor = true;
323 } else if(sig.startsWith("static_")) {
324 } else if(sig.startsWith("static_")) {
324 isStatic = true;
325 isStatic = true;
325 sig = sig.mid(7);
326 sig = sig.mid(7);
326 int idx = sig.indexOf("_");
327 int idx = sig.indexOf("_");
327 if (idx>=0) {
328 if (idx>=0) {
328 sig = sig.mid(idx+1);
329 sig = sig.mid(idx+1);
329 }
330 }
330 }
331 }
331 }
332 }
332
333
333 result += QByteArray(" ") + sig;
334 result += QByteArray(" ") + sig;
334 result += "(";
335 result += "(";
335
336
336 int lastEntry = _parameters.count()-1;
337 int lastEntry = _parameters.count()-1;
337 for (int i = skipFirstArg?2:1; i<_parameters.count(); i++) {
338 for (int i = skipFirstArg?2:1; i<_parameters.count(); i++) {
338 if (_parameters.at(i).isConst) {
339 if (_parameters.at(i).isConst) {
339 result += "const ";
340 result += "const ";
340 }
341 }
341 result += _parameters.at(i).name;
342 result += _parameters.at(i).name;
342 if (_parameters.at(i).pointerCount) {
343 if (_parameters.at(i).pointerCount) {
343 QByteArray stars;
344 QByteArray stars;
344 stars.fill('*', _parameters.at(i).pointerCount);
345 stars.fill('*', _parameters.at(i).pointerCount);
345 result += stars;
346 result += stars;
346 }
347 }
347 if (!names.at(i-1).isEmpty()) {
348 if (!names.at(i-1).isEmpty()) {
348 result += " ";
349 result += " ";
349 result += names.at(i-1);
350 result += names.at(i-1);
350 }
351 }
351 if (i!=lastEntry) {
352 if (i!=lastEntry) {
352 result += ", ";
353 result += ", ";
353 }
354 }
354 }
355 }
355 result += ")";
356 result += ")";
356
357
357 if (isStatic) {
358 if (isStatic) {
358 result = QString("static ") + result;
359 result = QString("static ") + result;
359 }
360 }
360 if (isConstructor) {
361 if (isConstructor) {
361 // result = QString("constructor ") + result;
362 // result = QString("constructor ") + result;
362 }
363 }
363 if (isDestructor) {
364 if (isDestructor) {
364 result = QString("~") + result;
365 result = QString("~") + result;
365 }
366 }
366 return result;
367 return result;
367 }
368 }
368
369
369
370
370 QByteArray PythonQtSlotInfo::slotName()
371 QByteArray PythonQtSlotInfo::slotName()
371 {
372 {
372 QByteArray sig(_meta.signature());
373 QByteArray sig(_meta.signature());
373 int idx = sig.indexOf('(');
374 int idx = sig.indexOf('(');
374 sig = sig.left(idx);
375 sig = sig.left(idx);
375 return sig;
376 return sig;
376 }
377 }
377
378
General Comments 0
You need to be logged in to leave comments. Login now