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{ int typeId = qRegisterMetaType<type<innertype > >(#type"<"#innertype">"); \
60PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfValueType<type<innertype >, innertype>); \
61PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfValueTypeToPythonList<type<innertype >, innertype>); \
62}
63
64#define PythonQtRegisterListTemplateConverterForKnownClass(type, innertype) \
65{ int typeId = qRegisterMetaType<type<innertype > >(#type"<"#innertype">"); \
66 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfKnownClass<type<innertype >, innertype>); \
67 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfKnownClassToPythonList<type<innertype >, innertype>); \
68}
69
70#define PythonQtRegisterQPairConverter(type1, type2) \
71{ int typeId = qRegisterMetaType<QPair<type1, type2> >("QPair<"#type1","#type2">"); \
72 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToPair<type1, type2>); \
73 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertPairToPython<type1, type2>); \
74}
75
76#define PythonQtRegisterIntegerMapConverter(type, innertype) \
77{ int typeId = qRegisterMetaType<type<int, innertype > >(#type"<int, "#innertype">"); \
78 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToIntegerMap<type<int, innertype >, innertype>); \
79 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertIntegerMapToPython<type<int, innertype >, innertype>); \
80}
81
82#define PythonQtRegisterListTemplateQPairConverter(listtype, type1, type2) \
83{ \
84 qRegisterMetaType<QPair<type1, type2> >("QPair<"#type1","#type2">"); \
85 int typeId = qRegisterMetaType<listtype<QPair<type1, type2> > >(#listtype"<QPair<"#type1","#type2">>"); \
86 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfPair<listtype<QPair<type1, type2> >, type1, type2>); \
87 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfPairToPythonList<listtype<QPair<type1, type2> >, type1, type2>); \
88}
89
90#define PythonQtRegisterToolClassesTemplateConverter(innertype) \
91 PythonQtRegisterListTemplateConverter(QList, innertype); \
92 PythonQtRegisterListTemplateConverter(QVector, innertype); \
93 PythonQtRegisterListTemplateConverter(std::vector, innertype);
94
95#define PythonQtRegisterToolClassesTemplateConverterForKnownClass(innertype) \
96 PythonQtRegisterListTemplateConverterForKnownClass(QList, innertype); \
97 PythonQtRegisterListTemplateConverterForKnownClass(QVector, innertype); \
98 PythonQtRegisterListTemplateConverterForKnownClass(std::vector, innertype);
99
102
103public:
104
106 static PyObject* GetPyBool(bool val);
107
110
112 static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, PythonQtClassInfo* classInfo, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame = nullptr);
113
116
118 static PyObject* QStringToPyObject(const QString& str);
119
121 static PyObject* QStringListToPyObject(const QStringList& list);
122
124 static PyObject* QStringListToPyList(const QStringList& list);
125
127 static QString PyObjGetRepresentation(PyObject* val);
128
130 static QString PyObjGetString(PyObject* val) { bool ok; QString s = PyObjGetString(val, false, ok); return s; }
132 static QString PyObjGetString(PyObject* val, bool strict, bool &ok);
134 static QByteArray PyObjGetBytes(PyObject* val, bool strict, bool &ok);
136 static QByteArray PyObjGetBytesAllowString(PyObject* val, bool strict, bool& ok);
138 static int PyObjGetInt(PyObject* val, bool strict, bool &ok);
140 static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok);
142 static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok);
144 static double PyObjGetDouble(PyObject* val, bool strict, bool &ok);
146 static bool PyObjGetBool(PyObject* val, bool strict, bool &ok);
147
149 static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);
150
153 static QVariant PyObjToQVariant(PyObject* val, int type = -1);
154
156 static PyObject* QVariantToPyObject(const QVariant& v);
157
158 static PyObject* QVariantHashToPyObject(const QVariantHash& m);
159 static PyObject* QVariantMapToPyObject(const QVariantMap& m);
160 static PyObject* QVariantListToPyObject(const QVariantList& l);
161
163 static QString CPPObjectToString(int type, const void* data);
164
166 static void registerPythonToMetaTypeConverter(int metaTypeId, PythonQtConvertPythonToMetaTypeCB* cb) { _pythonToMetaTypeConverters.insert(metaTypeId, cb); }
167
169 static void registerMetaTypeToPythonConverter(int metaTypeId, PythonQtConvertMetaTypeToPythonCB* cb) { _metaTypeToPythonConverters.insert(metaTypeId, cb); }
170
173 static void setPythonSequenceToQVariantListCallback(PythonQtConvertPythonSequenceToQVariantListCB* cb) { _pythonSequenceToQVariantListCB = cb; }
174
176 static PyObject* convertQtValueToPythonInternal(int type, const void* data);
177
179 static PyObject* createCopyFromMetaType( int type, const void* object );
180
182 static void* castWrapperTo(PythonQtInstanceWrapper* wrapper, const QByteArray& className, bool& ok);
183
184 static bool convertToPythonQtObjectPtr(PyObject* obj, void* /* PythonQtObjectPtr* */ outPtr, int /*metaTypeId*/, bool /*strict*/);
185 static PyObject* convertFromPythonQtObjectPtr(const void* /* PythonQtObjectPtr* */ inObject, int /*metaTypeId*/);
186 static bool convertToPythonQtSafeObjectPtr(PyObject* obj, void* /* PythonQtObjectPtr* */ outPtr, int /*metaTypeId*/, bool /*strict*/);
187 static PyObject* convertFromPythonQtSafeObjectPtr(const void* /* PythonQtObjectPtr* */ inObject, int /*metaTypeId*/);
188 static bool convertToQListOfPythonQtObjectPtr(PyObject* obj, void* /* QList<PythonQtObjectPtr>* */ outList, int /*metaTypeId*/, bool /*strict*/);
189 static PyObject* convertFromQListOfPythonQtObjectPtr(const void* /* QList<PythonQtObjectPtr>* */ inObject, int /*metaTypeId*/);
190#if QT_VERSION < 0x060000
191 static PyObject* convertFromStringRef(const void* inObject, int /*metaTypeId*/);
192#else
193 static PyObject* convertFromStringView(const void* inObject, int /*metaTypeId*/);
194 static PyObject* convertFromAnyStringView(const void* inObject, int /*metaTypeId*/);
195 static PyObject* convertFromByteArrayView(const void* inObject, int /*metaTypeId*/);
196#endif
197
199 static QByteArray getCPPTypeName(PyObject* type);
200
202 static bool isStringType(PyTypeObject* type);
203
206
207protected:
208 static QHash<int, PythonQtConvertMetaTypeToPythonCB*> _metaTypeToPythonConverters;
209 static QHash<int, PythonQtConvertPythonToMetaTypeCB*> _pythonToMetaTypeConverters;
211
213 static void* handlePythonToQtAutoConversion(int typeId, PyObject* obj, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame);
214
218 static bool ConvertPythonListToQListOfPointerType(PyObject* obj, QList<void*>* list, const PythonQtMethodInfo::ParameterInfo& info, bool strict);
219
221 template <typename Map>
222 static void pythonToMapVariant(PyObject* val, QVariant& result);
224 template <typename Map>
225 static PyObject* mapToPython (const Map& m);
226
227#if QT_VERSION < 0x060000
228 static int stringRefTypeId;
229#else
230 static int stringViewTypeId;
231 static int anyStringViewTypeId;
232 static int byteArrayViewTypeId;
233#endif
234};
235
236template<class ListType, class T>
237PyObject* PythonQtConvertListOfValueTypeToPythonList(const void* /*QList<T>* */ inList, int metaTypeId)
238{
239 ListType* list = (ListType*)inList;
240 static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
241 if (innerType == QVariant::Invalid) {
242 std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
243 }
244 PyObject* result = PyTuple_New(list->size());
245 int i = 0;
246 Q_FOREACH (const T& value, *list) {
247 PyTuple_SET_ITEM(result, i, PythonQtConv::convertQtValueToPythonInternal(innerType, &value));
248 i++;
249 }
250 return result;
251}
252
253template<class ListType, class T>
254bool PythonQtConvertPythonListToListOfValueType(PyObject* obj, void* /*QList<T>* */ outList, int metaTypeId, bool /*strict*/)
255{
256 ListType* list = (ListType*)outList;
257 static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
258 if (innerType == QVariant::Invalid) {
259 std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
260 }
261 bool result = false;
262 if (PySequence_Check(obj)) {
263 int count = PySequence_Size(obj);
264 if (count >= 0) {
265 result = true;
266 PyObject* value;
267 for (int i = 0;i<count;i++) {
268 value = PySequence_GetItem(obj,i);
269 // this is quite some overhead, but it avoids having another large switch...
270 QVariant v = PythonQtConv::PyObjToQVariant(value, innerType);
271 Py_XDECREF(value);
272 if (v.isValid()) {
273 list->push_back(qvariant_cast<T>(v));
274 } else {
275 result = false;
276 break;
277 }
278 }
279 }
280 }
281 return result;
282}
283
284//--------------------------------------------------------------------------------------------------------------------
285
286template<class ListType, class T>
287PyObject* PythonQtConvertListOfKnownClassToPythonList(const void* /*QList<T>* */ inList, int metaTypeId)
288{
289 ListType* list = (ListType*)inList;
290 static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(PythonQtMethodInfo::getInnerListTypeName(QByteArray(QMetaType::typeName(metaTypeId))));
291 if (innerType == nullptr) {
292 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for " << QMetaType::typeName(metaTypeId) << std::endl;
293 }
294 PyObject* result = PyTuple_New(list->size());
295 int i = 0;
296 Q_FOREACH(const T& value, *list) {
297 T* newObject = new T(value);
299 wrap->_ownedByPythonQt = true;
300 PyTuple_SET_ITEM(result, i, (PyObject*)wrap);
301 i++;
302 }
303 return result;
304}
305
306template<class ListType, class T>
307bool PythonQtConvertPythonListToListOfKnownClass(PyObject* obj, void* /*QList<T>* */ outList, int metaTypeId, bool /*strict*/)
308{
309 ListType* list = (ListType*)outList;
310 static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(PythonQtMethodInfo::getInnerListTypeName(QByteArray(QMetaType::typeName(metaTypeId))));
311 if (innerType == nullptr) {
312 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for " << QMetaType::typeName(metaTypeId) << std::endl;
313 }
314 bool result = false;
315 if (PySequence_Check(obj)) {
316 int count = PySequence_Size(obj);
317 if (count >= 0) {
318 result = true;
319 PyObject* value;
320 for (int i = 0; i < count; i++) {
321 value = PySequence_GetItem(obj, i);
322 if (PyObject_TypeCheck(value, &PythonQtInstanceWrapper_Type)) {
324 bool ok;
325 T* object = (T*)PythonQtConv::castWrapperTo(wrap, innerType->className(), ok);
326 Py_XDECREF(value);
327 if (ok) {
328 list->push_back(*object);
329 } else {
330 result = false;
331 break;
332 }
333 } else {
334 Py_XDECREF(value);
335 result = false;
336 break;
337 }
338 }
339 }
340 }
341 return result;
342}
343
344//--------------------------------------------------------------------------------------------------------------------
345
346template<class T1, class T2>
347PyObject* PythonQtConvertPairToPython(const void* /*QPair<T1,T2>* */ inPair, int metaTypeId)
348{
349 QPair<T1, T2>* pair = (QPair<T1, T2>*)inPair;
350 static int innerType1 = -1;
351 static int innerType2 = -1;
352 if (innerType1==-1) {
353 QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId)));
354 QList<QByteArray> names = innerTypes.split(',');
355 innerType1 = QMetaType::type(names.at(0).trimmed());
356 innerType2 = QMetaType::type(names.at(1).trimmed());
357 }
358 if (innerType1 == QVariant::Invalid || innerType2 == QVariant::Invalid) {
359 std::cerr << "PythonQtConvertPairToPython: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
360 }
361 PyObject* result = PyTuple_New(2);
362 PyTuple_SET_ITEM(result, 0, PythonQtConv::convertQtValueToPythonInternal(innerType1, &pair->first));
363 PyTuple_SET_ITEM(result, 1, PythonQtConv::convertQtValueToPythonInternal(innerType2, &pair->second));
364 return result;
365}
366
367template<class T1, class T2>
368bool PythonQtConvertPythonToPair(PyObject* obj, void* /*QPair<T1,T2>* */ outPair, int metaTypeId, bool /*strict*/)
369{
370 QPair<T1, T2>* pair = (QPair<T1, T2>*)outPair;
371 static int innerType1 = -1;
372 static int innerType2 = -1;
373 if (innerType1 == -1) {
374 QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId)));
375 QList<QByteArray> names = innerTypes.split(',');
376 innerType1 = QMetaType::type(names.at(0).trimmed());
377 innerType2 = QMetaType::type(names.at(1).trimmed());
378 }
379 if (innerType1 == QVariant::Invalid || innerType2 == QVariant::Invalid) {
380 std::cerr << "PythonQtConvertPythonToPair: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
381 }
382 bool result = false;
383 if (PySequence_Check(obj)) {
384 int count = PySequence_Size(obj);
385 if (count == 2) {
386 result = true;
387 PyObject* value;
388
389 value = PySequence_GetItem(obj, 0);
390 // this is quite some overhead, but it avoids having another large switch...
391 QVariant v = PythonQtConv::PyObjToQVariant(value, innerType1);
392 Py_XDECREF(value);
393 if (v.isValid()) {
394 pair->first = qvariant_cast<T1>(v);
395 } else {
396 return false;
397 }
398
399 value = PySequence_GetItem(obj, 1);
400 // this is quite some overhead, but it avoids having another large switch...
401 v = PythonQtConv::PyObjToQVariant(value, innerType2);
402 Py_XDECREF(value);
403 if (v.isValid()) {
404 pair->second = qvariant_cast<T2>(v);
405 } else {
406 return false;
407 }
408 }
409 }
410 return result;
411}
412
413//--------------------------------------------------------------------------------------------------------------------
414
415template<class ListType, class T1, class T2>
416PyObject* PythonQtConvertListOfPairToPythonList(const void* /*QList<QPair<T1,T2> >* */ inList, int metaTypeId)
417{
418 ListType* list = (ListType*)inList;
419 static int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
420 if (innerType == QVariant::Invalid) {
421 std::cerr << "PythonQtConvertListOfPairToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
422 }
423 PyObject* result = PyTuple_New(list->size());
424 int i = 0;
425 typedef const QPair<T1, T2> Pair;
426 Q_FOREACH(Pair& value, *list) {
428 PyTuple_SET_ITEM(result, i, object);
429 i++;
430 }
431 return result;
432}
433
434template<class ListType, class T1, class T2>
435bool PythonQtConvertPythonListToListOfPair(PyObject* obj, void* /*QList<QPair<T1,T2> >* */ outList, int metaTypeId, bool /*strict*/)
436{
438 static int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
439 if (innerType == QVariant::Invalid) {
440 std::cerr << "PythonQtConvertPythonListToListOfPair: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
441 }
442 bool result = false;
443 if (PySequence_Check(obj)) {
445 if (count >= 0) {
446 result = true;
448 for (int i = 0; i < count; i++) {
453 list->push_back(pair);
454 } else {
456 result = false;
457 break;
458 }
459 }
460 }
461 }
462 return result;
463}
464
465//--------------------------------------------------------------------------------------------------------------------
466
467template<class MapType, class T>
468PyObject* PythonQtConvertIntegerMapToPython(const void* /*QMap<int, T>* */ inMap, int metaTypeId)
469{
471 static int innerType = -1;
472 if (innerType == -1) {
475 innerType = QMetaType::type(names.at(1).trimmed());
476 }
477 if (innerType == QVariant::Invalid) {
478 std::cerr << "PythonQtConvertIntegerMapToPython: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
479 }
480
482 typename MapType::const_iterator t = map->constBegin();
483 PyObject* key;
484 PyObject* val;
485 for (; t != map->constEnd(); t++) {
486 key = PyInt_FromLong(t.key());
489 Py_DECREF(key);
490 Py_DECREF(val);
491 }
492 return result;
493}
494
495template<class MapType, class T>
496bool PythonQtConvertPythonToIntegerMap(PyObject* val, void* /*QMap<int, T>* */ outMap, int metaTypeId, bool /*strict*/)
497{
499 static int innerType = -1;
500 if (innerType == -1) {
503 innerType = QMetaType::type(names.at(1).trimmed());
504 }
505 if (innerType == QVariant::Invalid) {
506 std::cerr << "PythonQtConvertPythonToIntegerMap: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
507 }
508 bool result = false;
509 if (PyMapping_Check(val)) {
510 result = true;
512 if (items) {
513 int count = PyList_Size(items);
515 PyObject* key;
517 for (int i = 0; i < count; i++) {
521
522 bool ok;
523 int intKey = PythonQtConv::PyObjGetInt(key, false, ok);
524 // this is quite some overhead, but it avoids having another large switch...
526 if (v.isValid() && ok) {
527 map->insert(intKey, qvariant_cast<T>(v));
528 } else {
529 result = false;
530 break;
531 }
532 }
534 }
535 }
536 return result;
537}
538
539
540#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:557
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