Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtClassInfo.h
3206 views
1
#ifndef _PYTHONQTCLASSINFO_H
2
#define _PYTHONQTCLASSINFO_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
#include <QMetaObject>
37
#include <QMetaMethod>
38
#include <QHash>
39
#include <QByteArray>
40
#include <QList>
41
42
class PythonQtSlotInfo;
43
44
struct PythonQtMemberInfo {
45
enum Type {
46
Invalid, Slot, EnumValue, Property
47
};
48
49
PythonQtMemberInfo() { _type = Invalid; }
50
51
PythonQtMemberInfo(PythonQtSlotInfo* info) {
52
_type = Slot;
53
_slot = info;
54
_enumValue = 0;
55
}
56
57
PythonQtMemberInfo(unsigned int enumValue) {
58
_type = EnumValue;
59
_slot = NULL;
60
_enumValue = enumValue;
61
}
62
63
PythonQtMemberInfo(const QMetaProperty& prop) {
64
_type = Property;
65
_slot = NULL;
66
_enumValue = 0;
67
_property = prop;
68
}
69
70
PythonQtSlotInfo* _slot;
71
unsigned int _enumValue;
72
QMetaProperty _property;
73
Type _type;
74
};
75
76
//! a class that stores all required information about a Qt object (and an optional associated C++ class name)
77
/*! for fast lookup of slots when calling the object from Python
78
*/
79
class PythonQtClassInfo {
80
81
public:
82
PythonQtClassInfo(const QMetaObject* meta, const QByteArray& wrappedClassName = QByteArray());
83
84
~PythonQtClassInfo();
85
86
//! get the Python method definition for a given slot name (without return type and signature)
87
PythonQtMemberInfo member(const char* member);
88
89
PythonQtSlotInfo* constructors();
90
91
//! get the Qt classname
92
const char* className();
93
94
//! get the classname of the wrapped C++ class
95
const QByteArray& wrappedCPPClassName();
96
97
//! returns if the object is a CPP wrapper
98
bool isCPPWrapper() { return !_wrappedClassName.isEmpty(); }
99
100
//! get the meta object
101
const QMetaObject* metaObject() { return _meta; }
102
103
//! set the meta object, this will reset the caching
104
void setMetaObject(const QMetaObject* meta);
105
106
//! returns if the meta object inherits the given classname
107
bool inherits(const char* name);
108
109
//! get help string for the metaobject
110
QString help();
111
112
//! get list of all members
113
QStringList memberList(bool metaOnly = false);
114
115
private:
116
PythonQtSlotInfo* findDecoratorSlots(const char* classname, const char* memberName, int memberNameLen, PythonQtSlotInfo* tail, bool &found);
117
int findCharOffset(const char* sigStart, char someChar);
118
QHash<QByteArray, PythonQtMemberInfo> _cachedMembers;
119
PythonQtSlotInfo* _constructors;
120
const QMetaObject* _meta;
121
QByteArray _wrappedClassName;
122
};
123
124
//---------------------------------------------------------------
125
126
127
#endif
128
129