PythonQt
PythonQtConversion.h
Go to the documentation of this file.
1#ifndef _PYTHONQTCONVERSION_H
2#define _PYTHONQTCONVERSION_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 "PythonQt.h"
47#include "PythonQtMisc.h"
48#include "PythonQtClassInfo.h"
49#include "PythonQtMethodInfo.h"
50
51#include <QList>
52#include <vector>
53
54typedef PyObject* PythonQtConvertMetaTypeToPythonCB(const void* inObject, int metaTypeId);
55typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject* inObject, void* outObject, int metaTypeId, bool strict);
57
58#define PythonQtRegisterListTemplateConverter(type, innertype) \
59 { \
60 int typeId = qRegisterMetaType<type<innertype>>(#type "<" #innertype ">"); \
61 PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
62 PythonQtConvertPythonListToListOfValueType<type<innertype>, innertype>); \
63 PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
64 PythonQtConvertListOfValueTypeToPythonList<type<innertype>, innertype>); \
65 }
66
67#define PythonQtRegisterListTemplateConverterForKnownClass(type, innertype) \
68 { \
69 int typeId = qRegisterMetaType<type<innertype>>(#type "<" #innertype ">"); \
70 PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
71 PythonQtConvertPythonListToListOfKnownClass<type<innertype>, innertype>); \
72 PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
73 PythonQtConvertListOfKnownClassToPythonList<type<innertype>, innertype>); \
74 }
75
76#define PythonQtRegisterQPairConverter(type1, type2) \
77 { \
78 int typeId = qRegisterMetaType<QPair<type1, type2>>("QPair<" #type1 "," #type2 ">"); \
79 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToPair<type1, type2>); \
80 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertPairToPython<type1, type2>); \
81 }
82
83#define PythonQtRegisterIntegerMapConverter(type, innertype) \
84 { \
85 int typeId = qRegisterMetaType<type<int, innertype>>(#type "<int, " #innertype ">"); \
86 PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
87 PythonQtConvertPythonToIntegerMap<type<int, innertype>, innertype>); \
88 PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
89 PythonQtConvertIntegerMapToPython<type<int, innertype>, innertype>); \
90 }
91
92#define PythonQtRegisterListTemplateQPairConverter(listtype, type1, type2) \
93 { \
94 qRegisterMetaType<QPair<type1, type2>>("QPair<" #type1 "," #type2 ">"); \
95 int typeId = qRegisterMetaType<listtype<QPair<type1, type2>>>(#listtype "<QPair<" #type1 "," #type2 ">>"); \
96 PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
97 PythonQtConvertPythonListToListOfPair<listtype<QPair<type1, type2>>, type1, type2>); \
98 PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
99 PythonQtConvertListOfPairToPythonList<listtype<QPair<type1, type2>>, type1, type2>); \
100 }
101
102#define PythonQtRegisterToolClassesTemplateConverter(innertype) \
103 PythonQtRegisterListTemplateConverter(QList, innertype); \
104 PythonQtRegisterListTemplateConverter(QVector, innertype); \
105 PythonQtRegisterListTemplateConverter(std::vector, innertype);
106
107#define PythonQtRegisterToolClassesTemplateConverterForKnownClass(innertype) \
108 PythonQtRegisterListTemplateConverterForKnownClass(QList, innertype); \
109 PythonQtRegisterListTemplateConverterForKnownClass(QVector, innertype); \
110 PythonQtRegisterListTemplateConverterForKnownClass(std::vector, innertype);
111
114{
115
116public:
117
119 static PyObject* GetPyBool(bool val);
120
123
125 static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict,
126 PythonQtClassInfo* classInfo, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame = nullptr);
127
130
132 static PyObject* QStringToPyObject(const QString& str);
133
135 static PyObject* QStringListToPyObject(const QStringList& list);
136
138 static PyObject* QStringListToPyList(const QStringList& list);
139
141 static QString PyObjGetRepresentation(PyObject* val);
142
144 static QString PyObjGetString(PyObject* val)
145 {
146 bool ok;
147 QString s = PyObjGetString(val, false, ok);
148 return s;
149 }
151 static QString PyObjGetString(PyObject* val, bool strict, bool& ok);
153 static QByteArray PyObjGetBytes(PyObject* val, bool strict, bool& ok);
155 static QByteArray PyObjGetBytesAllowString(PyObject* val, bool strict, bool& ok);
157 static int PyObjGetInt(PyObject* val, bool strict, bool& ok);
159 static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool& ok);
161 static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool& ok);
163 static double PyObjGetDouble(PyObject* val, bool strict, bool& ok);
165 static bool PyObjGetBool(PyObject* val, bool strict, bool& ok);
166
168 static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);
169
172 static QVariant PyObjToQVariant(PyObject* val, int type = -1);
173
175 static PyObject* QVariantToPyObject(const QVariant& v);
176
177 static PyObject* QVariantHashToPyObject(const QVariantHash& m);
178 static PyObject* QVariantMapToPyObject(const QVariantMap& m);
179 static PyObject* QVariantListToPyObject(const QVariantList& l);
180
182 static QString CPPObjectToString(int type, const void* data);
183
186 {
187 _pythonToMetaTypeConverters.insert(metaTypeId, cb);
188 }
189
192 {
193 _metaTypeToPythonConverters.insert(metaTypeId, cb);
194 }
195
199 {
200 _pythonSequenceToQVariantListCB = cb;
201 }
202
204 static PyObject* convertQtValueToPythonInternal(int type, const void* data);
205
207 static PyObject* createCopyFromMetaType(int type, const void* object);
208
210 static void* castWrapperTo(PythonQtInstanceWrapper* wrapper, const QByteArray& className, bool& ok);
211
212 static bool convertToPythonQtObjectPtr(PyObject* obj, void* /* PythonQtObjectPtr* */ outPtr, int /*metaTypeId*/,
213 bool /*strict*/);
214 static PyObject* convertFromPythonQtObjectPtr(const void* /* PythonQtObjectPtr* */ inObject, int /*metaTypeId*/);
215 static bool convertToPythonQtSafeObjectPtr(PyObject* obj, void* /* PythonQtObjectPtr* */ outPtr, int /*metaTypeId*/,
216 bool /*strict*/);
217 static PyObject* convertFromPythonQtSafeObjectPtr(const void* /* PythonQtObjectPtr* */ inObject, int /*metaTypeId*/);
218 static bool convertToQListOfPythonQtObjectPtr(PyObject* obj, void* /* QList<PythonQtObjectPtr>* */ outList,
219 int /*metaTypeId*/, bool /*strict*/);
220 static PyObject* convertFromQListOfPythonQtObjectPtr(const void* /* QList<PythonQtObjectPtr>* */ inObject,
221 int /*metaTypeId*/);
222#if QT_VERSION < 0x060000
223 static PyObject* convertFromStringRef(const void* inObject, int /*metaTypeId*/);
224#else
225 static PyObject* convertFromStringView(const void* inObject, int /*metaTypeId*/);
226 static PyObject* convertFromAnyStringView(const void* inObject, int /*metaTypeId*/);
227 static PyObject* convertFromByteArrayView(const void* inObject, int /*metaTypeId*/);
228#endif
229
231 static QByteArray getCPPTypeName(PyObject* type);
232
234 static bool isStringType(PyTypeObject* type);
235
238
239protected:
240 static QHash<int, PythonQtConvertMetaTypeToPythonCB*> _metaTypeToPythonConverters;
241 static QHash<int, PythonQtConvertPythonToMetaTypeCB*> _pythonToMetaTypeConverters;
243
245 static void* handlePythonToQtAutoConversion(int typeId, PyObject* obj, void* alreadyAllocatedCPPObject,
246 PythonQtArgumentFrame* frame);
247
252 static bool ConvertPythonListToQListOfPointerType(PyObject* obj, QList<void*>* list,
253 const PythonQtMethodInfo::ParameterInfo& info, bool strict);
254
256 template<typename Map>
257 static void pythonToMapVariant(PyObject* val, QVariant& result);
259 template<typename Map>
260 static PyObject* mapToPython(const Map& m);
261
262#if QT_VERSION < 0x060000
263 static int stringRefTypeId;
264#else
265 static int stringViewTypeId;
266 static int anyStringViewTypeId;
267 static int byteArrayViewTypeId;
268#endif
269};
270
271template<class ListType, class T>
272PyObject* PythonQtConvertListOfValueTypeToPythonList(const void* /*QList<T>* */ inList, int metaTypeId)
273{
274 ListType* list = (ListType*)inList;
275 static const int innerType =
277 if (innerType == QMetaType::UnknownType) {
278 std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type "
279 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
280 }
281 PyObject* result = PyTuple_New(list->size());
282 int i = 0;
283 for (const T& value : *list) {
284 PyTuple_SET_ITEM(result, i, PythonQtConv::convertQtValueToPythonInternal(innerType, &value));
285 i++;
286 }
287 return result;
288}
289
290template<class ListType, class T>
291bool PythonQtConvertPythonListToListOfValueType(PyObject* obj, void* /*QList<T>* */ outList, int metaTypeId,
292 bool /*strict*/)
293{
294 ListType* list = (ListType*)outList;
295 static const int innerType =
297 if (innerType == QMetaType::UnknownType) {
298 std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type "
299 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
300 }
301 bool result = false;
302 if (PySequence_Check(obj)) {
303 int count = PySequence_Size(obj);
304 if (count >= 0) {
305 result = true;
306 PyObject* value;
307 for (int i = 0; i < count; i++) {
308 value = PySequence_GetItem(obj, i);
309 // this is quite some overhead, but it avoids having another large switch...
310 QVariant v = PythonQtConv::PyObjToQVariant(value, innerType);
311 Py_XDECREF(value);
312 if (v.isValid()) {
313 list->push_back(qvariant_cast<T>(v));
314 } else {
315 result = false;
316 break;
317 }
318 }
319 }
320 }
321 return result;
322}
323
324//--------------------------------------------------------------------------------------------------------------------
325
326template<class ListType, class T>
327PyObject* PythonQtConvertListOfKnownClassToPythonList(const void* /*QList<T>* */ inList, int metaTypeId)
328{
329 ListType* list = (ListType*)inList;
330 static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(
332 if (innerType == nullptr) {
333 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for "
334 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
335 }
336 PyObject* result = PyTuple_New(list->size());
337 int i = 0;
338 for (const T& value : *list) {
339 T* newObject = new T(value);
341 (PythonQtInstanceWrapper*)PythonQt::priv()->wrapPtr(newObject, innerType->className());
342 wrap->_ownedByPythonQt = true;
343 PyTuple_SET_ITEM(result, i, (PyObject*)wrap);
344 i++;
345 }
346 return result;
347}
348
349template<class ListType, class T>
350bool PythonQtConvertPythonListToListOfKnownClass(PyObject* obj, void* /*QList<T>* */ outList, int metaTypeId,
351 bool /*strict*/)
352{
353 ListType* list = (ListType*)outList;
354 static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(
356 if (innerType == nullptr) {
357 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for "
358 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
359 }
360 bool result = false;
361 if (PySequence_Check(obj)) {
362 int count = PySequence_Size(obj);
363 if (count >= 0) {
364 result = true;
365 PyObject* value;
366 for (int i = 0; i < count; i++) {
367 value = PySequence_GetItem(obj, i);
368 if (PyObject_TypeCheck(value, &PythonQtInstanceWrapper_Type)) {
370 bool ok;
371 T* object = (T*)PythonQtConv::castWrapperTo(wrap, innerType->className(), ok);
372 Py_XDECREF(value);
373 if (ok) {
374 list->push_back(*object);
375 } else {
376 result = false;
377 break;
378 }
379 } else {
380 Py_XDECREF(value);
381 result = false;
382 break;
383 }
384 }
385 }
386 }
387 return result;
388}
389
390//--------------------------------------------------------------------------------------------------------------------
391
392template<class T1, class T2>
393PyObject* PythonQtConvertPairToPython(const void* /*QPair<T1,T2>* */ inPair, int metaTypeId)
394{
395 QPair<T1, T2>* pair = (QPair<T1, T2>*)inPair;
396 static int innerType1 = -1;
397 static int innerType2 = -1;
398 if (innerType1 == -1) {
399 QByteArray innerTypes =
401 QList<QByteArray> names = innerTypes.split(',');
402 innerType1 = PythonQtUtils::metaTypeIdFromTypeName(names.at(0).trimmed());
403 innerType2 = PythonQtUtils::metaTypeIdFromTypeName(names.at(1).trimmed());
404 }
405 if (innerType1 == QMetaType::UnknownType || innerType2 == QMetaType::UnknownType) {
406 std::cerr << "PythonQtConvertPairToPython: unknown inner type " << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId)
407 << std::endl;
408 }
409 PyObject* result = PyTuple_New(2);
410 PyTuple_SET_ITEM(result, 0, PythonQtConv::convertQtValueToPythonInternal(innerType1, &pair->first));
411 PyTuple_SET_ITEM(result, 1, PythonQtConv::convertQtValueToPythonInternal(innerType2, &pair->second));
412 return result;
413}
414
415template<class T1, class T2>
416bool PythonQtConvertPythonToPair(PyObject* obj, void* /*QPair<T1,T2>* */ outPair, int metaTypeId, bool /*strict*/)
417{
418 QPair<T1, T2>* pair = (QPair<T1, T2>*)outPair;
419 static int innerType1 = -1;
420 static int innerType2 = -1;
421 if (innerType1 == -1) {
422 QByteArray innerTypes =
424 QList<QByteArray> names = innerTypes.split(',');
425 innerType1 = PythonQtUtils::metaTypeIdFromTypeName(names.at(0).trimmed());
426 innerType2 = PythonQtUtils::metaTypeIdFromTypeName(names.at(1).trimmed());
427 }
428 if (innerType1 == QMetaType::UnknownType || innerType2 == QMetaType::UnknownType) {
429 std::cerr << "PythonQtConvertPythonToPair: unknown inner type " << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId)
430 << std::endl;
431 }
432 bool result = false;
433 if (PySequence_Check(obj)) {
434 int count = PySequence_Size(obj);
435 if (count == 2) {
436 result = true;
437 PyObject* value;
438
439 value = PySequence_GetItem(obj, 0);
440 // this is quite some overhead, but it avoids having another large switch...
441 QVariant v = PythonQtConv::PyObjToQVariant(value, innerType1);
442 Py_XDECREF(value);
443 if (v.isValid()) {
444 pair->first = qvariant_cast<T1>(v);
445 } else {
446 return false;
447 }
448
449 value = PySequence_GetItem(obj, 1);
450 // this is quite some overhead, but it avoids having another large switch...
451 v = PythonQtConv::PyObjToQVariant(value, innerType2);
452 Py_XDECREF(value);
453 if (v.isValid()) {
454 pair->second = qvariant_cast<T2>(v);
455 } else {
456 return false;
457 }
458 }
459 }
460 return result;
461}
462
463//--------------------------------------------------------------------------------------------------------------------
464
465template<class ListType, class T1, class T2>
466PyObject* PythonQtConvertListOfPairToPythonList(const void* /*QList<QPair<T1,T2> >* */ inList, int metaTypeId)
467{
468 ListType* list = (ListType*)inList;
469 static int innerType =
471 if (innerType == QMetaType::UnknownType) {
472 std::cerr << "PythonQtConvertListOfPairToPythonList: unknown inner type "
473 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
474 }
475 PyObject* result = PyTuple_New(list->size());
476 int i = 0;
477 typedef const QPair<T1, T2> Pair;
478 for (Pair& value : *list) {
480 PyTuple_SET_ITEM(result, i, object);
481 i++;
482 }
483 return result;
484}
485
486template<class ListType, class T1, class T2>
487bool PythonQtConvertPythonListToListOfPair(PyObject* obj, void* /*QList<QPair<T1,T2> >* */ outList, int metaTypeId,
488 bool /*strict*/)
489{
491 static int innerType =
493 if (innerType == QMetaType::UnknownType) {
494 std::cerr << "PythonQtConvertPythonListToListOfPair: unknown inner type "
495 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
496 }
497 bool result = false;
498 if (PySequence_Check(obj)) {
500 if (count >= 0) {
501 result = true;
503 for (int i = 0; i < count; i++) {
508 list->push_back(pair);
509 } else {
511 result = false;
512 break;
513 }
514 }
515 }
516 }
517 return result;
518}
519
520//--------------------------------------------------------------------------------------------------------------------
521
522template<class MapType, class T>
523PyObject* PythonQtConvertIntegerMapToPython(const void* /*QMap<int, T>* */ inMap, int metaTypeId)
524{
526 static int innerType = -1;
527 if (innerType == -1) {
532 }
533 if (innerType == QMetaType::UnknownType) {
534 std::cerr << "PythonQtConvertIntegerMapToPython: unknown inner type "
535 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
536 }
537
539 typename MapType::const_iterator t = map->constBegin();
540 PyObject* key;
541 PyObject* val;
542 for (; t != map->constEnd(); t++) {
543 key = PyLong_FromLong(t.key());
546 Py_DECREF(key);
547 Py_DECREF(val);
548 }
549 return result;
550}
551
552template<class MapType, class T>
553bool PythonQtConvertPythonToIntegerMap(PyObject* val, void* /*QMap<int, T>* */ outMap, int metaTypeId, bool /*strict*/)
554{
556 static int innerType = -1;
557 if (innerType == -1) {
562 }
563 if (innerType == QMetaType::UnknownType) {
564 std::cerr << "PythonQtConvertPythonToIntegerMap: unknown inner type "
565 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
566 }
567 bool result = false;
568 if (PyMapping_Check(val)) {
569 result = true;
571 if (items) {
572 int count = PyList_Size(items);
574 PyObject* key;
576 for (int i = 0; i < count; i++) {
580
581 bool ok;
582 int intKey = PythonQtConv::PyObjGetInt(key, false, ok);
583 // this is quite some overhead, but it avoids having another large switch...
585 if (v.isValid() && ok) {
586 map->insert(intKey, qvariant_cast<T>(v));
587 } else {
588 result = false;
589 break;
590 }
591 }
593 }
594 }
595 return result;
596}
597
598#endif
QVariant PythonQtConvertPythonSequenceToQVariantListCB(PyObject *inObject)
PyObject * PythonQtConvertPairToPython(const void *inPair, int metaTypeId)
PyObject * PythonQtConvertIntegerMapToPython(const void *inMap, int metaTypeId)
PyObject * PythonQtConvertMetaTypeToPythonCB(const void *inObject, int metaTypeId)
bool PythonQtConvertPythonToIntegerMap(PyObject *val, void *outMap, int metaTypeId, bool)
bool PythonQtConvertPythonListToListOfPair(PyObject *obj, void *outList, int metaTypeId, bool)
bool PythonQtConvertPythonToMetaTypeCB(PyObject *inObject, void *outObject, int metaTypeId, bool strict)
bool PythonQtConvertPythonToPair(PyObject *obj, void *outPair, int metaTypeId, bool)
bool PythonQtConvertPythonListToListOfKnownClass(PyObject *obj, void *outList, int metaTypeId, bool)
PyObject * PythonQtConvertListOfValueTypeToPythonList(const void *inList, int metaTypeId)
bool PythonQtConvertPythonListToListOfValueType(PyObject *obj, void *outList, int metaTypeId, bool)
PyObject * PythonQtConvertListOfPairToPythonList(const void *inList, int metaTypeId)
PyObject * PythonQtConvertListOfKnownClassToPythonList(const void *inList, int metaTypeId)
PYTHONQT_EXPORT PyTypeObject PythonQtInstanceWrapper_Type
struct _object PyObject
#define PYTHONQT_EXPORT
Stores C++ arguments for a qt_metacall (which are created when converting data from Python to C++)
a class that stores all required information about a Qt object (and an optional associated C++ class ...
const QByteArray & className() const
get the classname (either of the QObject or of the wrapped CPP object)
a static class that offers methods for type conversion
static quint64 PyObjGetULongLong(PyObject *val, bool strict, bool &ok)
get int64 from py object
static bool convertToPythonQtObjectPtr(PyObject *obj, void *outPtr, int, bool)
static PyObject * QVariantHashToPyObject(const QVariantHash &m)
static PyObject * QVariantMapToPyObject(const QVariantMap &m)
static void * ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo &info, PyObject *obj, bool strict, PythonQtClassInfo *classInfo, void *alreadyAllocatedCPPObject, PythonQtArgumentFrame *frame=nullptr)
convert python object to Qt (according to the given parameter) and if the conversion should be strict...
static bool isStringType(PyTypeObject *type)
Returns if the given object is a string (or unicode string)
static qint64 PyObjGetLongLong(PyObject *val, bool strict, bool &ok)
get int64 from py object
static QHash< int, PythonQtConvertPythonToMetaTypeCB * > _pythonToMetaTypeConverters
static bool convertToQListOfPythonQtObjectPtr(PyObject *obj, void *outList, int, bool)
static void setPythonSequenceToQVariantListCallback(PythonQtConvertPythonSequenceToQVariantListCB *cb)
static PyObject * mapToPython(const Map &m)
helper template function for QVariantMapToPyObject/QVariantHashToPyObject
static PyObject * convertFromPythonQtSafeObjectPtr(const void *inObject, int)
static double PyObjGetDouble(PyObject *val, bool strict, bool &ok)
get double from py object
static void * CreateQtReturnValue(const PythonQtMethodInfo::ParameterInfo &info, PythonQtArgumentFrame *frame)
creates a data storage for the passed parameter type and returns a void pointer to be set as arg[0] o...
static bool convertToPythonQtSafeObjectPtr(PyObject *obj, void *outPtr, int, bool)
static PyObject * QStringListToPyList(const QStringList &list)
converts QStringList to Python list
static QVariant PyObjToQVariant(PyObject *val, int type=-1)
static QByteArray getCPPTypeName(PyObject *type)
Returns the name of the equivalent CPP type (for signals and slots)
static bool ConvertPythonListToQListOfPointerType(PyObject *obj, QList< void * > *list, const PythonQtMethodInfo::ParameterInfo &info, bool strict)
tries to convert the python object to a QList of pointers to type objects, returns true on success
static int stringRefTypeId
static PyObject * GetPyBool(bool val)
get a ref counted True or False Python object
static PyObject * QStringToPyObject(const QString &str)
converts QString to Python string (unicode!)
static QString PyObjGetString(PyObject *val)
get string value from py object
static QByteArray PyObjGetBytes(PyObject *val, bool strict, bool &ok)
get bytes from py object
static QString CPPObjectToString(int type, const void *data)
get human readable string from CPP object (when the metatype is known)
static bool PyObjGetBool(PyObject *val, bool strict, bool &ok)
get bool from py object
static PyObject * ConvertQListOfPointerTypeToPythonList(QList< void * > *list, const PythonQtMethodInfo::ParameterInfo &info)
converts the list of pointers of given type to Python
static void * handlePythonToQtAutoConversion(int typeId, PyObject *obj, void *alreadyAllocatedCPPObject, PythonQtArgumentFrame *frame)
handle automatic conversion of some special types (QColor, QBrush, ...)
static QByteArray PyObjGetBytesAllowString(PyObject *val, bool strict, bool &ok)
get bytes from py object, also allows Python string
static QString PyObjGetString(PyObject *val, bool strict, bool &ok)
get string value from py object
static PyObject * convertFromPythonQtObjectPtr(const void *inObject, int)
static void pythonToMapVariant(PyObject *val, QVariant &result)
helper template method for conversion from Python to QVariantMap/Hash
static PyObject * QStringListToPyObject(const QStringList &list)
converts QStringList to Python tuple
static PyObject * convertFromStringRef(const void *inObject, int)
static PyObject * createCopyFromMetaType(int type, const void *object)
creates a copy of given object, using the QMetaType
static int PyObjGetInt(PyObject *val, bool strict, bool &ok)
get int from py object
static PyObject * convertQtValueToPythonInternal(int type, const void *data)
converts the Qt parameter given in data, interpreting it as a type registered qvariant/meta type,...
static PythonQtConvertPythonSequenceToQVariantListCB * _pythonSequenceToQVariantListCB
static PyObject * QVariantToPyObject(const QVariant &v)
convert QVariant from PyObject
static QString PyObjGetRepresentation(PyObject *val)
get string representation of py object
static void * castWrapperTo(PythonQtInstanceWrapper *wrapper, const QByteArray &className, bool &ok)
cast wrapper to given className if possible
static QHash< int, PythonQtConvertMetaTypeToPythonCB * > _metaTypeToPythonConverters
static PyObject * ConvertQtValueToPython(const PythonQtMethodInfo::ParameterInfo &info, const void *data)
converts the Qt parameter given in data, interpreting it as a info parameter, into a Python object,
static void registerPythonToMetaTypeConverter(int metaTypeId, PythonQtConvertPythonToMetaTypeCB *cb)
register a converter callback from python to cpp for given metatype
static PyObject * convertFromQListOfPythonQtObjectPtr(const void *inObject, int)
static PyObject * QVariantListToPyObject(const QVariantList &l)
static QStringList PyObjToStringList(PyObject *val, bool strict, bool &ok)
create a string list from python sequence
static void registerMetaTypeToPythonConverter(int metaTypeId, PythonQtConvertMetaTypeToPythonCB *cb)
register a converter callback from cpp to python for given metatype
static void registerStringViewTypes()
Register QStringView like types, that need to be handled specially.
static QByteArray getInnerTemplateTypeName(const QByteArray &typeName)
returns the inner type name of a simple template of the form SomeObject<InnerType>
static int getInnerTemplateMetaType(const QByteArray &typeName)
returns the inner type id of a simple template of the form SomeObject<InnerType>
static QByteArray getInnerListTypeName(const QByteArray &typeName)
returns the inner type name of a simple template or the typename without appended "List".
PyObject * wrapPtr(void *ptr, const QByteArray &name, bool passOwnership=false)
PythonQtClassInfo * getClassInfo(const QMetaObject *meta)
get the class info for a meta object (if available)
static PythonQtPrivate * priv()
get access to internal data (should not be used on the public API, but is used by some C functions)
Definition PythonQt.h:572
const char * typeNameFromMetaTypeId(int metaTypeId)
Returns the type name from a meta type ID.
int metaTypeIdFromTypeName(const QByteArray &className)
Returns the meta type ID from a type name.
a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjec...
bool _ownedByPythonQt
flag that stores if the object is owned by pythonQt
stores various informations about a parameter/type name