Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtConversion.h
3206 views
1
#ifndef _PYTHONQTCONVERSION_H
2
#define _PYTHONQTCONVERSION_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 PythonQtConversion.h
39
// \author Florian Link
40
// \author Last changed by $Author: florian $
41
// \date 2006-05
42
*/
43
//----------------------------------------------------------------------------------
44
45
#include "PythonQt.h"
46
#include "PythonQtMisc.h"
47
#include "PythonQtClassInfo.h"
48
#include "PythonQtMethodInfo.h"
49
50
#include <QWidget>
51
52
//! a static class that offers methods for type conversion
53
class PythonQtConv {
54
55
public:
56
57
//! get a ref counted True or False Python object
58
static PyObject* GetPyBool(bool val);
59
60
//! converts the Qt parameter given in \c data, interpreting it as a \c info parameter, into a Python object,
61
static PyObject* ConvertQtValueToPython(const PythonQtMethodInfo::ParameterInfo& info, void* data);
62
63
//! convert python object to Qt (according to the given parameter) and if the conversion should be strict, the meta object is passed in for enum resolving
64
static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, const QMetaObject* meta);
65
66
//! creates a data storage for the passed parameter type and returns a void pointer to be set as arg[0] of qt_metacall
67
static void* CreateQtReturnValue(const PythonQtMethodInfo::ParameterInfo& info);
68
69
//! converts QString to Python string (unicode!)
70
static PyObject* QStringToPyObject(const QString& str);
71
72
//! converts QStringList to Python tuple
73
static PyObject* QStringListToPyObject(const QStringList& list);
74
75
//! converts QStringList to Python list
76
static PyObject* QStringListToPyList(const QStringList& list);
77
78
//! get string representation of py object
79
static QString PyObjGetRepresentation(PyObject* val);
80
81
//! get string value form py object
82
static QString PyObjGetString(PyObject* val) { bool ok; QString s = PyObjGetString(val, false, ok); return s; }
83
//! get string value form py object
84
static QString PyObjGetString(PyObject* val, bool strict, bool &ok);
85
//! get int from py object
86
static int PyObjGetInt(PyObject* val, bool strict, bool &ok);
87
//! get int64 from py object
88
static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok);
89
//! get int64 from py object
90
static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok);
91
//! get double from py object
92
static double PyObjGetDouble(PyObject* val, bool strict, bool &ok);
93
//! get bool from py object
94
static bool PyObjGetBool(PyObject* val, bool strict, bool &ok);
95
96
//! create a string list from python sequence
97
static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);
98
99
//! convert python object to qvariant, if type is given it will try to create a qvariant of that type, otherwise
100
//! it will guess from the python type
101
static QVariant PyObjToQVariant(PyObject* val, int type = -1);
102
103
//! convert QVariant from PyObject
104
static PyObject* QVariantToPyObject(const QVariant& v);
105
106
static PyObject* QVariantMapToPyObject(const QVariantMap& m);
107
static PyObject* QVariantListToPyObject(const QVariantList& l);
108
109
public:
110
111
static PythonQtValueStorage<qint64, 128> global_valueStorage;
112
static PythonQtValueStorage<void*, 128> global_ptrStorage;
113
static PythonQtValueStorage<QVariant, 32> global_variantStorage;
114
115
protected:
116
//! converts the Qt parameter given in \c data, interpreting it as a \c type registered qvariant/meta type, into a Python object,
117
static PyObject* ConvertQtValueToPythonInternal(int type, void* data);
118
119
};
120
121
#endif
122
123