Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtMethodInfo.h
3206 views
1
#ifndef _PYTHONQTMETHODINFO_H
2
#define _PYTHONQTMETHODINFO_H
3
4
/*
5
*
6
* Copyright (C) 2006 MeVis Research GmbH 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 Research GmbH, Universitaetsallee 29,
30
* 28359 Bremen, Germany or:
31
*
32
* http://www.mevis.de
33
*
34
*/
35
36
//----------------------------------------------------------------------------------
37
/*!
38
// \file PythonQtMethodInfo.h
39
// \author Florian Link
40
// \author Last changed by $Author: florian $
41
// \date 2006-05
42
*/
43
//----------------------------------------------------------------------------------
44
45
#include <QByteArray>
46
#include <QHash>
47
#include <QList>
48
#include <QMetaMethod>
49
50
//! stores information about a specific signal/slot/method
51
class PythonQtMethodInfo
52
{
53
public:
54
//! this is a funny type union of QMetaType and QVariant, only god knows
55
//! why QMetaType do not support identical types in Qt4,
56
//! especial the support of Long, Short, Char etc. is missing in QVariant
57
//! and QMetaType does not know anything about most variant types and e.g. LongLong
58
enum ParameterType {
59
Unknown = -1,
60
Variant = -2
61
};
62
63
//! stores the QVariant id (if available) and the name of the type
64
struct ParameterInfo {
65
int typeId; // a mixture from QMetaType and ParameterType
66
QByteArray name;
67
bool isPointer;
68
bool isConst;
69
};
70
71
PythonQtMethodInfo() {};
72
~PythonQtMethodInfo() {};
73
PythonQtMethodInfo(const QMetaMethod& meta);
74
PythonQtMethodInfo(const PythonQtMethodInfo& other) {
75
_parameters = other._parameters;
76
}
77
78
//! returns the method info of the signature, uses a cache internally to speed up
79
//! multiple requests for the same method
80
static const PythonQtMethodInfo* getCachedMethodInfo(const QMetaMethod& method);
81
82
//! cleanup the cache
83
static void cleanupCachedMethodInfos();
84
85
//! returns the number of parameters (without the return value)
86
int parameterCount() const { return _parameters.size(); };
87
88
//! returns the id for the given type (using an internal dictionary)
89
static int nameToType(const char* name);
90
91
//! get the parameter infos
92
const QList<ParameterInfo>& parameters() const { return _parameters; }
93
94
protected:
95
static void fillParameterInfo(ParameterInfo& type, const QByteArray& name);
96
97
static QHash<QByteArray, int> _parameterTypeDict;
98
99
//! stores the cached signatures of methods to speedup mapping from Qt to Python types
100
static QHash<QByteArray, PythonQtMethodInfo*> _cachedSignatures;
101
102
QList<ParameterInfo> _parameters;
103
};
104
105
//! stores information about a slot, including a next pointer to overloaded slots
106
class PythonQtSlotInfo : public PythonQtMethodInfo
107
{
108
public:
109
enum Type {
110
MemberSlot, InstanceDecorator, ClassDecorator
111
};
112
113
PythonQtSlotInfo(const PythonQtSlotInfo& info):PythonQtMethodInfo() {
114
_meta = info._meta;
115
_parameters = info._parameters;
116
_slotIndex = info._slotIndex;
117
_next = NULL;
118
_decorator = info._decorator;
119
_type = info._type;
120
}
121
122
PythonQtSlotInfo(const QMetaMethod& meta, int slotIndex, QObject* decorator = NULL, Type type = MemberSlot ):PythonQtMethodInfo()
123
{
124
const PythonQtMethodInfo* info = getCachedMethodInfo(meta);
125
_meta = meta;
126
_parameters = info->parameters();
127
_slotIndex = slotIndex;
128
_next = NULL;
129
_decorator = decorator;
130
_type = type;
131
}
132
133
134
public:
135
const QMetaMethod* metaMethod() const { return &_meta; }
136
137
//! get the index of the slot (needed for qt_metacall)
138
int slotIndex() const { return _slotIndex; }
139
140
//! get next overloaded slot (which has the same name)
141
PythonQtSlotInfo* nextInfo() const { return _next; }
142
143
//! set the next overloaded slot
144
void setNextInfo(PythonQtSlotInfo* next) { _next = next; }
145
146
//! returns if the slot is a decorator slot
147
bool isInstanceDecorator() { return _decorator!=NULL && _type == InstanceDecorator; }
148
149
//! returns if the slot is a constructor slot
150
bool isClassDecorator() { return _decorator!=NULL && _type == ClassDecorator; }
151
152
QObject* decorator() { return _decorator; }
153
154
//! get the full signature including return type
155
QString fullSignature(bool skipFirstArg);
156
157
//! get the short slot name
158
QByteArray slotName();
159
160
private:
161
int _slotIndex;
162
PythonQtSlotInfo* _next;
163
QObject* _decorator;
164
Type _type;
165
QMetaMethod _meta;
166
};
167
168
169
#endif
170
171