PythonQt
PythonQtUtils.h
Go to the documentation of this file.
1#ifndef _PYTHONQTUTILS_H
2#define _PYTHONQTUTILS_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
46#include "PythonQtSystem.h"
47
48#include <QByteArray>
49#include <QMetaMethod>
50#include <QMetaType>
51
53{
54 inline QByteArray signature(const QMetaMethod& method) {
55#if( QT_VERSION >= QT_VERSION_CHECK(5,0,0) )
56 return method.methodSignature();
57#else
58 return QByteArray(method.signature());
59#endif
60 }
61
62 inline QByteArray methodName(const QMetaMethod& method) {
63#if( QT_VERSION >= QT_VERSION_CHECK(5,0,0) )
64 return method.name();
65#else
66 QByteArray sig(method.signature());
67 int idx = sig.indexOf('(');
68 sig = sig.left(idx);
69 return sig;
70#endif
71 }
72
73 inline QByteArray typeName(const QMetaMethod& method) {
74#if( QT_VERSION >= QT_VERSION_CHECK(5,0,0) )
75 QByteArray result = method.typeName();
76 if (result == "void") {
77 return QByteArray();
78 } else {
79 return result;
80 }
81#else
82 return method.typeName();
83#endif
84 }
85
88#ifdef PY3K
89 return PyType_Check(obj);
90#else
91 // support old-style classes and new style classes
92 return (obj->ob_type == &PyClass_Type || obj->ob_type == &PyType_Type);
93#endif
94 }
95
97 inline int metaTypeIdFromTypeName(const QByteArray& className) {
98#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
99 return QMetaType::fromName(className.constData()).id();
100#else
101 return QMetaType::type(className.constData());
102#endif
103 }
104
106 inline const char * typeNameFromMetaTypeId(int metaTypeId) {
107#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
108 return QMetaType(metaTypeId).name();
109#else
110 return QMetaType::typeName(metaTypeId);
111#endif
112 }
113}
114
115#endif
116
PyObject * PythonQtConvertPairToPython(const void *inPair, int metaTypeId)
struct _object PyObject
const char * typeNameFromMetaTypeId(int metaTypeId)
Returns the type name from a meta type ID.
QByteArray methodName(const QMetaMethod &method)
QByteArray typeName(const QMetaMethod &method)
bool isPythonClassType(PyObject *obj)
Returns of the python object is a class type.
QByteArray signature(const QMetaMethod &method)
int metaTypeIdFromTypeName(const QByteArray &className)
Returns the meta type ID from a type name.