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
126 static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict,
127 PythonQtClassInfo* classInfo, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame = nullptr);
128
131
133 static PyObject* QStringToPyObject(const QString& str);
134
136 static PyObject* QStringListToPyObject(const QStringList& list);
137
139 static PyObject* QStringListToPyList(const QStringList& list);
140
142 static QString PyObjGetRepresentation(PyObject* val);
143
145 static QString PyObjGetString(PyObject* val)
146 {
147 bool ok;
148 QString s = PyObjGetString(val, false, ok);
149 return s;
150 }
152 static QString PyObjGetString(PyObject* val, bool strict, bool& ok);
154 static QByteArray PyObjGetBytes(PyObject* val, bool strict, bool& ok);
156 static QByteArray PyObjGetBytesAllowString(PyObject* val, bool strict, bool& ok);
158 static int PyObjGetInt(PyObject* val, bool strict, bool& ok);
160 static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool& ok);
162 static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool& ok);
164 static double PyObjGetDouble(PyObject* val, bool strict, bool& ok);
166 static bool PyObjGetBool(PyObject* val, bool strict, bool& ok);
167
169 static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);
170
173 static QVariant PyObjToQVariant(PyObject* val, int type = -1);
174
176 static PyObject* QVariantToPyObject(const QVariant& v);
177
178 static PyObject* QVariantHashToPyObject(const QVariantHash& m);
179 static PyObject* QVariantMapToPyObject(const QVariantMap& m);
180 static PyObject* QVariantListToPyObject(const QVariantList& l);
181
183 static QString CPPObjectToString(int type, const void* data);
184
187 {
188 _pythonToMetaTypeConverters.insert(metaTypeId, cb);
189 }
190
193 {
194 _metaTypeToPythonConverters.insert(metaTypeId, cb);
195 }
196
200 {
201 _pythonSequenceToQVariantListCB = cb;
202 }
203
205 static PyObject* convertQtValueToPythonInternal(int type, const void* data);
206
208 static PyObject* createCopyFromMetaType(int type, const void* object);
209
211 static void* castWrapperTo(PythonQtInstanceWrapper* wrapper, const QByteArray& className, bool& ok);
212
213 static bool convertToPythonQtObjectPtr(PyObject* obj, void* /* PythonQtObjectPtr* */ outPtr, int /*metaTypeId*/,
214 bool /*strict*/);
215 static PyObject* convertFromPythonQtObjectPtr(const void* /* PythonQtObjectPtr* */ inObject, int /*metaTypeId*/);
216 static bool convertToPythonQtSafeObjectPtr(PyObject* obj, void* /* PythonQtObjectPtr* */ outPtr, int /*metaTypeId*/,
217 bool /*strict*/);
218 static PyObject* convertFromPythonQtSafeObjectPtr(const void* /* PythonQtObjectPtr* */ inObject, int /*metaTypeId*/);
219 static bool convertToQListOfPythonQtObjectPtr(PyObject* obj, void* /* QList<PythonQtObjectPtr>* */ outList,
220 int /*metaTypeId*/, bool /*strict*/);
221 static PyObject* convertFromQListOfPythonQtObjectPtr(const void* /* QList<PythonQtObjectPtr>* */ inObject,
222 int /*metaTypeId*/);
223#if QT_VERSION < 0x060000
224 static PyObject* convertFromStringRef(const void* inObject, int /*metaTypeId*/);
225#else
226 static PyObject* convertFromStringView(const void* inObject, int /*metaTypeId*/);
227 static PyObject* convertFromAnyStringView(const void* inObject, int /*metaTypeId*/);
228 static PyObject* convertFromByteArrayView(const void* inObject, int /*metaTypeId*/);
229#endif
230
232 static QByteArray getCPPTypeName(PyObject* type);
233
235 static bool isStringType(PyTypeObject* type);
236
239
240protected:
241 static QHash<int, PythonQtConvertMetaTypeToPythonCB*> _metaTypeToPythonConverters;
242 static QHash<int, PythonQtConvertPythonToMetaTypeCB*> _pythonToMetaTypeConverters;
244
246 static void* handlePythonToQtAutoConversion(int typeId, PyObject* obj, void* alreadyAllocatedCPPObject,
247 PythonQtArgumentFrame* frame);
248
253 static bool ConvertPythonListToQListOfPointerType(PyObject* obj, QList<void*>* list,
254 const PythonQtMethodInfo::ParameterInfo& info, bool strict);
255
257 template<typename Map>
258 static void pythonToMapVariant(PyObject* val, QVariant& result);
260 template<typename Map>
261 static PyObject* mapToPython(const Map& m);
262
263#if QT_VERSION < 0x060000
264 static int stringRefTypeId;
265#else
266 static int stringViewTypeId;
267 static int anyStringViewTypeId;
268 static int byteArrayViewTypeId;
269#endif
270};
271
272template<class ListType, class T>
273PyObject* PythonQtConvertListOfValueTypeToPythonList(const void* /*QList<T>* */ inList, int metaTypeId)
274{
275 ListType* list = (ListType*)inList;
276 static const int innerType =
278 if (innerType == QMetaType::UnknownType) {
279 std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type "
280 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
281 }
282 PyObject* result = PyTuple_New(list->size());
283 int i = 0;
284 for (const T& value : *list) {
285 PyTuple_SET_ITEM(result, i, PythonQtConv::convertQtValueToPythonInternal(innerType, &value));
286 i++;
287 }
288 return result;
289}
290
291template<class ListType, class T>
292bool PythonQtConvertPythonListToListOfValueType(PyObject* obj, void* /*QList<T>* */ outList, int metaTypeId,
293 bool /*strict*/)
294{
295 ListType* list = (ListType*)outList;
296 static const int innerType =
298 if (innerType == QMetaType::UnknownType) {
299 std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type "
300 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
301 }
302 bool result = false;
303 if (PySequence_Check(obj)) {
304 int count = PySequence_Size(obj);
305 if (count >= 0) {
306 result = true;
307 PyObject* value;
308 for (int i = 0; i < count; i++) {
309 value = PySequence_GetItem(obj, i);
310 // this is quite some overhead, but it avoids having another large switch...
311 QVariant v = PythonQtConv::PyObjToQVariant(value, innerType);
312 Py_XDECREF(value);
313 if (v.isValid()) {
314 list->push_back(qvariant_cast<T>(v));
315 } else {
316 result = false;
317 break;
318 }
319 }
320 }
321 }
322 return result;
323}
324
325//--------------------------------------------------------------------------------------------------------------------
326
327template<class ListType, class T>
328PyObject* PythonQtConvertListOfKnownClassToPythonList(const void* /*QList<T>* */ inList, int metaTypeId)
329{
330 ListType* list = (ListType*)inList;
331 static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(
333 if (innerType == nullptr) {
334 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for "
335 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
336 }
337 PyObject* result = PyTuple_New(list->size());
338 int i = 0;
339 for (const T& value : *list) {
340 T* newObject = new T(value);
342 (PythonQtInstanceWrapper*)PythonQt::priv()->wrapPtr(newObject, innerType->className());
343 wrap->_ownedByPythonQt = true;
344 PyTuple_SET_ITEM(result, i, (PyObject*)wrap);
345 i++;
346 }
347 return result;
348}
349
350template<class ListType, class T>
351bool PythonQtConvertPythonListToListOfKnownClass(PyObject* obj, void* /*QList<T>* */ outList, int metaTypeId,
352 bool /*strict*/)
353{
354 ListType* list = (ListType*)outList;
355 static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(
357 if (innerType == nullptr) {
358 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for "
359 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
360 }
361 bool result = false;
362 if (PySequence_Check(obj)) {
363 int count = PySequence_Size(obj);
364 if (count >= 0) {
365 result = true;
366 PyObject* value;
367 for (int i = 0; i < count; i++) {
368 value = PySequence_GetItem(obj, i);
369 if (PyObject_TypeCheck(value, &PythonQtInstanceWrapper_Type)) {
371 bool ok;
372 T* object = (T*)PythonQtConv::castWrapperTo(wrap, innerType->className(), ok);
373 Py_XDECREF(value);
374 if (ok) {
375 list->push_back(*object);
376 } else {
377 result = false;
378 break;
379 }
380 } else {
381 Py_XDECREF(value);
382 result = false;
383 break;
384 }
385 }
386 }
387 }
388 return result;
389}
390
391//--------------------------------------------------------------------------------------------------------------------
392
393template<class T1, class T2>
394PyObject* PythonQtConvertPairToPython(const void* /*QPair<T1,T2>* */ inPair, int metaTypeId)
395{
396 QPair<T1, T2>* pair = (QPair<T1, T2>*)inPair;
397 static int innerType1 = -1;
398 static int innerType2 = -1;
399 if (innerType1 == -1) {
400 QByteArray innerTypes =
402 QList<QByteArray> names = innerTypes.split(',');
403 innerType1 = PythonQtUtils::metaTypeIdFromTypeName(names.at(0).trimmed());
404 innerType2 = PythonQtUtils::metaTypeIdFromTypeName(names.at(1).trimmed());
405 }
406 if (innerType1 == QMetaType::UnknownType || innerType2 == QMetaType::UnknownType) {
407 std::cerr << "PythonQtConvertPairToPython: unknown inner type " << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId)
408 << std::endl;
409 }
410 PyObject* result = PyTuple_New(2);
411 PyTuple_SET_ITEM(result, 0, PythonQtConv::convertQtValueToPythonInternal(innerType1, &pair->first));
412 PyTuple_SET_ITEM(result, 1, PythonQtConv::convertQtValueToPythonInternal(innerType2, &pair->second));
413 return result;
414}
415
416template<class T1, class T2>
417bool PythonQtConvertPythonToPair(PyObject* obj, void* /*QPair<T1,T2>* */ outPair, int metaTypeId, bool /*strict*/)
418{
419 QPair<T1, T2>* pair = (QPair<T1, T2>*)outPair;
420 static int innerType1 = -1;
421 static int innerType2 = -1;
422 if (innerType1 == -1) {
423 QByteArray innerTypes =
425 QList<QByteArray> names = innerTypes.split(',');
426 innerType1 = PythonQtUtils::metaTypeIdFromTypeName(names.at(0).trimmed());
427 innerType2 = PythonQtUtils::metaTypeIdFromTypeName(names.at(1).trimmed());
428 }
429 if (innerType1 == QMetaType::UnknownType || innerType2 == QMetaType::UnknownType) {
430 std::cerr << "PythonQtConvertPythonToPair: unknown inner type " << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId)
431 << std::endl;
432 }
433 bool result = false;
434 if (PySequence_Check(obj)) {
435 int count = PySequence_Size(obj);
436 if (count == 2) {
437 result = true;
438 PyObject* value;
439
440 value = PySequence_GetItem(obj, 0);
441 // this is quite some overhead, but it avoids having another large switch...
442 QVariant v = PythonQtConv::PyObjToQVariant(value, innerType1);
443 Py_XDECREF(value);
444 if (v.isValid()) {
445 pair->first = qvariant_cast<T1>(v);
446 } else {
447 return false;
448 }
449
450 value = PySequence_GetItem(obj, 1);
451 // this is quite some overhead, but it avoids having another large switch...
452 v = PythonQtConv::PyObjToQVariant(value, innerType2);
453 Py_XDECREF(value);
454 if (v.isValid()) {
455 pair->second = qvariant_cast<T2>(v);
456 } else {
457 return false;
458 }
459 }
460 }
461 return result;
462}
463
464//--------------------------------------------------------------------------------------------------------------------
465
466template<class ListType, class T1, class T2>
467PyObject* PythonQtConvertListOfPairToPythonList(const void* /*QList<QPair<T1,T2> >* */ inList, int metaTypeId)
468{
469 ListType* list = (ListType*)inList;
470 static int innerType =
472 if (innerType == QMetaType::UnknownType) {
473 std::cerr << "PythonQtConvertListOfPairToPythonList: unknown inner type "
474 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
475 }
476 PyObject* result = PyTuple_New(list->size());
477 int i = 0;
478 typedef const QPair<T1, T2> Pair;
479 for (Pair& value : *list) {
481 PyTuple_SET_ITEM(result, i, object);
482 i++;
483 }
484 return result;
485}
486
487template<class ListType, class T1, class T2>
488bool PythonQtConvertPythonListToListOfPair(PyObject* obj, void* /*QList<QPair<T1,T2> >* */ outList, int metaTypeId,
489 bool /*strict*/)
490{
492 static int innerType =
494 if (innerType == QMetaType::UnknownType) {
495 std::cerr << "PythonQtConvertPythonListToListOfPair: unknown inner type "
496 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
497 }
498 bool result = false;
499 if (PySequence_Check(obj)) {
501 if (count >= 0) {
502 result = true;
504 for (int i = 0; i < count; i++) {
509 list->push_back(pair);
510 } else {
512 result = false;
513 break;
514 }
515 }
516 }
517 }
518 return result;
519}
520
521//--------------------------------------------------------------------------------------------------------------------
522
523template<class MapType, class T>
524PyObject* PythonQtConvertIntegerMapToPython(const void* /*QMap<int, T>* */ inMap, int metaTypeId)
525{
527 static int innerType = -1;
528 if (innerType == -1) {
533 }
534 if (innerType == QMetaType::UnknownType) {
535 std::cerr << "PythonQtConvertIntegerMapToPython: unknown inner type "
536 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
537 }
538
540 typename MapType::const_iterator t = map->constBegin();
541 PyObject* key;
542 PyObject* val;
543 for (; t != map->constEnd(); t++) {
544 key = PyLong_FromLong(t.key());
547 Py_DECREF(key);
548 Py_DECREF(val);
549 }
550 return result;
551}
552
553template<class MapType, class T>
554bool PythonQtConvertPythonToIntegerMap(PyObject* val, void* /*QMap<int, T>* */ outMap, int metaTypeId, bool /*strict*/)
555{
557 static int innerType = -1;
558 if (innerType == -1) {
563 }
564 if (innerType == QMetaType::UnknownType) {
565 std::cerr << "PythonQtConvertPythonToIntegerMap: unknown inner type "
566 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
567 }
568 bool result = false;
569 if (PyMapping_Check(val)) {
570 result = true;
572 if (items) {
573 int count = PyList_Size(items);
575 PyObject* key;
577 for (int i = 0; i < count; i++) {
581
582 bool ok;
583 int intKey = PythonQtConv::PyObjGetInt(key, false, ok);
584 // this is quite some overhead, but it avoids having another large switch...
586 if (v.isValid() && ok) {
587 map->insert(intKey, qvariant_cast<T>(v));
588 } else {
589 result = false;
590 break;
591 }
592 }
594 }
595 }
596 return result;
597}
598
599#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)
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