SourceForge.net Logo
PythonQt
PythonQtMethodInfo.h
Go to the documentation of this file.
1 #ifndef _PYTHONQTMETHODINFO_H
2 #define _PYTHONQTMETHODINFO_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 "PythonQtSystem.h"
46 
47 #include <QByteArray>
48 #include <QHash>
49 #include <QList>
50 #include <QMetaMethod>
51 
52 class PythonQtClassInfo;
53 struct _object;
54 typedef struct _object PyObject;
55 
58 {
59 public:
61  Unknown = -1,
62  Variant = -2
63  };
64 
66  struct ParameterInfo {
67  QByteArray name;
68  QByteArray innerName; // if the type is a template, this stores the inner name
69  PyObject* enumWrapper; // if it is an enum, a pointer to the enum wrapper
70  int typeId; // a mixture from QMetaType and ParameterType
71  char pointerCount; // the number of pointer indirections
72  char innerNamePointerCount; // the number of pointer indirections in the inner name
73  bool isConst;
75  bool isQList;
79  };
80 
83  PythonQtMethodInfo(const QMetaMethod& meta, PythonQtClassInfo* classInfo);
84  PythonQtMethodInfo(const QByteArray& typeName, const QList<QByteArray>& args);
86  _parameters = other._parameters;
87  }
88 
91  static const PythonQtMethodInfo* getCachedMethodInfo(const QMetaMethod& method, PythonQtClassInfo* classInfo);
92 
94  static const PythonQtMethodInfo* getCachedMethodInfoFromArgumentList(int numArgs, const char** args);
95 
97  static void cleanupCachedMethodInfos();
98 
100  int parameterCount() const { return _parameters.size(); };
101 
103  static int nameToType(const char* name);
104 
106  const QList<ParameterInfo>& parameters() const { return _parameters; }
107 
109  static void addParameterTypeAlias(const QByteArray& alias, const QByteArray& name);
110 
112  static void fillParameterInfo(ParameterInfo& type, const QByteArray& name, PythonQtClassInfo* classInfo = NULL);
113 
115  static const ParameterInfo& getParameterInfoForMetaType(int type);
116 
118  static int getInnerTemplateMetaType(const QByteArray& typeName);
119 
121  static QByteArray getInnerTemplateTypeName(const QByteArray& typeName);
122 
124  static QByteArray getInnerListTypeName(const QByteArray& typeName);
125 
126 protected:
127 
128  static QHash<QByteArray, int> _parameterTypeDict;
129  static QHash<QByteArray, QByteArray> _parameterNameAliases;
130 
132  static QHash<QByteArray, PythonQtMethodInfo*> _cachedSignatures;
133 
134  static QHash<int, ParameterInfo> _cachedParameterInfos;
135 
136  QList<ParameterInfo> _parameters;
137 };
138 
141 {
142 public:
143  enum Type {
144  MemberSlot, InstanceDecorator, ClassDecorator
145  };
146 
148  _meta = info._meta;
149  _parameters = info._parameters;
150  _slotIndex = info._slotIndex;
151  _next = NULL;
152  _decorator = info._decorator;
153  _type = info._type;
154  _upcastingOffset = 0;
155  }
156 
157  PythonQtSlotInfo(PythonQtClassInfo* classInfo, const QMetaMethod& meta, int slotIndex, QObject* decorator = NULL, Type type = MemberSlot ):PythonQtMethodInfo()
158  {
159  const PythonQtMethodInfo* info = getCachedMethodInfo(meta, classInfo);
160  _meta = meta;
161  _parameters = info->parameters();
162  _slotIndex = slotIndex;
163  _next = NULL;
164  _decorator = decorator;
165  _type = type;
166  _upcastingOffset = 0;
167  }
168 
169 
170 public:
172  QList<ParameterInfo> arguments() const;
173 
174  void deleteOverloadsAndThis();
175 
176  const QMetaMethod* metaMethod() const { return &_meta; }
177 
178  void setUpcastingOffset(int upcastingOffset) { _upcastingOffset = upcastingOffset; }
179 
180  int upcastingOffset() const { return _upcastingOffset; }
181 
183  int slotIndex() const { return _slotIndex; }
184 
186  PythonQtSlotInfo* nextInfo() const { return _next; }
187 
189  void setNextInfo(PythonQtSlotInfo* next) { _next = next; }
190 
192  bool isInstanceDecorator() const { return _decorator!=NULL && _type == InstanceDecorator; }
193 
195  bool isClassDecorator() const { return _decorator!=NULL && _type == ClassDecorator; }
196 
197  QObject* decorator() const { return _decorator; }
198 
200  QString fullSignature(bool skipReturnValue = false, int optionalArgsIndex = -1) const;
201 
203  QByteArray signature() const;
204 
206  QByteArray slotName(bool removeDecorators = false) const;
207 
211  QStringList overloads(bool skipReturnValue = false) const;
212 
215  QByteArray getImplementingClassName() const;
216 
217 private:
218  int _slotIndex;
219  PythonQtSlotInfo* _next;
220  QObject* _decorator;
221  Type _type;
222  QMetaMethod _meta;
223  int _upcastingOffset;
224 };
225 
226 
227 #endif
static const PythonQtMethodInfo * getCachedMethodInfo(const QMetaMethod &method, PythonQtClassInfo *classInfo)
bool isClassDecorator() const
returns if the slot is a constructor slot
void setNextInfo(PythonQtSlotInfo *next)
set the next overloaded slot
a class that stores all required information about a Qt object (and an optional associated C++ class ...
QObject * decorator() const
QByteArray typeName(const QMetaMethod &method)
Definition: PythonQtUtils.h:72
static QHash< QByteArray, QByteArray > _parameterNameAliases
bool isInstanceDecorator() const
returns if the slot is a decorator slot
PythonQtSlotInfo(PythonQtClassInfo *classInfo, const QMetaMethod &meta, int slotIndex, QObject *decorator=NULL, Type type=MemberSlot)
int parameterCount() const
returns the number of parameters including the return value
stores various informations about a parameter/type name
static QHash< int, ParameterInfo > _cachedParameterInfos
int slotIndex() const
get the index of the slot (needed for qt_metacall)
#define PYTHONQT_EXPORT
struct _object PyObject
void setUpcastingOffset(int upcastingOffset)
QByteArray signature(const QMetaMethod &method)
Definition: PythonQtUtils.h:53
const QMetaMethod * metaMethod() const
static QHash< QByteArray, PythonQtMethodInfo * > _cachedSignatures
stores the cached signatures of methods to speedup mapping from Qt to Python types ...
const QList< ParameterInfo > & parameters() const
get the parameter infos
stores information about a specific signal/slot/method
int upcastingOffset() const
static QHash< QByteArray, int > _parameterTypeDict
PythonQtMethodInfo(const PythonQtMethodInfo &other)
stores information about a slot, including a next pointer to overloaded slots
PythonQtSlotInfo(const PythonQtSlotInfo &info)
PythonQtSlotInfo * nextInfo() const
get next overloaded slot (which has the same name)
QList< ParameterInfo > _parameters