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 
45 #include "PythonQtPythonInclude.h"
46 #include "PythonQt.h"
47 #include "PythonQtMisc.h"
48 #include "PythonQtClassInfo.h"
49 #include "PythonQtMethodInfo.h"
50 
51 #include <QList>
52 #include <vector>
53 
54 typedef PyObject* PythonQtConvertMetaTypeToPythonCB(const void* inObject, int metaTypeId);
55 typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject* inObject, void* outObject, int metaTypeId, bool strict);
57 
58 #define PythonQtRegisterListTemplateConverter(type, innertype) \
59 { int typeId = qRegisterMetaType<type<innertype > >(#type"<"#innertype">"); \
60 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfValueType<type<innertype >, innertype>); \
61 PythonQtConv::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 
103 public:
104 
106  static PyObject* GetPyBool(bool val);
107 
109  static PyObject* ConvertQtValueToPython(const PythonQtMethodInfo::ParameterInfo& info, const void* data);
110 
112  static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, PythonQtClassInfo* classInfo, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame = NULL);
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 int PyObjGetInt(PyObject* val, bool strict, bool &ok);
138  static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok);
140  static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok);
142  static double PyObjGetDouble(PyObject* val, bool strict, bool &ok);
144  static bool PyObjGetBool(PyObject* val, bool strict, bool &ok);
145 
147  static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);
148 
151  static QVariant PyObjToQVariant(PyObject* val, int type = -1);
152 
154  static PyObject* QVariantToPyObject(const QVariant& v);
155 
156  static PyObject* QVariantHashToPyObject(const QVariantHash& m);
157  static PyObject* QVariantMapToPyObject(const QVariantMap& m);
158  static PyObject* QVariantListToPyObject(const QVariantList& l);
159 
161  static QString CPPObjectToString(int type, const void* data);
162 
164  static void registerPythonToMetaTypeConverter(int metaTypeId, PythonQtConvertPythonToMetaTypeCB* cb) { _pythonToMetaTypeConverters.insert(metaTypeId, cb); }
165 
167  static void registerMetaTypeToPythonConverter(int metaTypeId, PythonQtConvertMetaTypeToPythonCB* cb) { _metaTypeToPythonConverters.insert(metaTypeId, cb); }
168 
171  static void setPythonSequenceToQVariantListCallback(PythonQtConvertPythonSequenceToQVariantListCB* cb) { _pythonSequenceToQVariantListCB = cb; }
172 
174  static PyObject* convertQtValueToPythonInternal(int type, const void* data);
175 
177  static PyObject* createCopyFromMetaType( int type, const void* object );
178 
180  static void* castWrapperTo(PythonQtInstanceWrapper* wrapper, const QByteArray& className, bool& ok);
181 
182  static bool convertToPythonQtObjectPtr(PyObject* obj, void* /* PythonQtObjectPtr* */ outPtr, int /*metaTypeId*/, bool /*strict*/);
183  static PyObject* convertFromPythonQtObjectPtr(const void* /* PythonQtObjectPtr* */ inObject, int /*metaTypeId*/);
184  static bool convertToPythonQtSafeObjectPtr(PyObject* obj, void* /* PythonQtObjectPtr* */ outPtr, int /*metaTypeId*/, bool /*strict*/);
185  static PyObject* convertFromPythonQtSafeObjectPtr(const void* /* PythonQtObjectPtr* */ inObject, int /*metaTypeId*/);
186  static bool convertToQListOfPythonQtObjectPtr(PyObject* obj, void* /* QList<PythonQtObjectPtr>* */ outList, int /*metaTypeId*/, bool /*strict*/);
187  static PyObject* convertFromQListOfPythonQtObjectPtr(const void* /* QList<PythonQtObjectPtr>* */ inObject, int /*metaTypeId*/);
188  static PyObject* convertFromStringRef(const void* inObject, int /*metaTypeId*/);
189 
191  static QByteArray getCPPTypeName(PyObject* type);
192 
194  static bool isStringType(PyTypeObject* type);
195 
196 protected:
197  static QHash<int, PythonQtConvertMetaTypeToPythonCB*> _metaTypeToPythonConverters;
198  static QHash<int, PythonQtConvertPythonToMetaTypeCB*> _pythonToMetaTypeConverters;
200 
202  static void* handlePythonToQtAutoConversion(int typeId, PyObject* obj, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame);
203 
207  static bool ConvertPythonListToQListOfPointerType(PyObject* obj, QList<void*>* list, const PythonQtMethodInfo::ParameterInfo& info, bool strict);
208 
210  template <typename Map>
211  static void pythonToMapVariant(PyObject* val, QVariant& result);
213  template <typename Map>
214  static PyObject* mapToPython (const Map& m);
215 
216 };
217 
218 template<class ListType, class T>
219 PyObject* PythonQtConvertListOfValueTypeToPythonList(const void* /*QList<T>* */ inList, int metaTypeId)
220 {
221  ListType* list = (ListType*)inList;
222  static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
223  if (innerType == QVariant::Invalid) {
224  std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
225  }
226  PyObject* result = PyTuple_New(list->size());
227  int i = 0;
228  Q_FOREACH (const T& value, *list) {
229  PyTuple_SET_ITEM(result, i, PythonQtConv::convertQtValueToPythonInternal(innerType, &value));
230  i++;
231  }
232  return result;
233 }
234 
235 template<class ListType, class T>
236 bool PythonQtConvertPythonListToListOfValueType(PyObject* obj, void* /*QList<T>* */ outList, int metaTypeId, bool /*strict*/)
237 {
238  ListType* list = (ListType*)outList;
239  static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
240  if (innerType == QVariant::Invalid) {
241  std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
242  }
243  bool result = false;
244  if (PySequence_Check(obj)) {
245  int count = PySequence_Size(obj);
246  if (count >= 0) {
247  result = true;
248  PyObject* value;
249  for (int i = 0;i<count;i++) {
250  value = PySequence_GetItem(obj,i);
251  // this is quite some overhead, but it avoids having another large switch...
252  QVariant v = PythonQtConv::PyObjToQVariant(value, innerType);
253  Py_XDECREF(value);
254  if (v.isValid()) {
255  list->push_back(qvariant_cast<T>(v));
256  } else {
257  result = false;
258  break;
259  }
260  }
261  }
262  }
263  return result;
264 }
265 
266 //--------------------------------------------------------------------------------------------------------------------
267 
268 template<class ListType, class T>
269 PyObject* PythonQtConvertListOfKnownClassToPythonList(const void* /*QList<T>* */ inList, int metaTypeId)
270 {
271  ListType* list = (ListType*)inList;
273  if (innerType == NULL) {
274  std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type " << innerType->className().constData() << std::endl;
275  }
276  PyObject* result = PyTuple_New(list->size());
277  int i = 0;
278  Q_FOREACH(const T& value, *list) {
279  T* newObject = new T(value);
281  wrap->_ownedByPythonQt = true;
282  PyTuple_SET_ITEM(result, i, (PyObject*)wrap);
283  i++;
284  }
285  return result;
286 }
287 
288 template<class ListType, class T>
289 bool PythonQtConvertPythonListToListOfKnownClass(PyObject* obj, void* /*QList<T>* */ outList, int metaTypeId, bool /*strict*/)
290 {
291  ListType* list = (ListType*)outList;
293  if (innerType == NULL) {
294  std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type " << innerType->className().constData() << std::endl;
295  }
296  bool result = false;
297  if (PySequence_Check(obj)) {
298  int count = PySequence_Size(obj);
299  if (count >= 0) {
300  result = true;
301  PyObject* value;
302  for (int i = 0; i < count; i++) {
303  value = PySequence_GetItem(obj, i);
304  if (PyObject_TypeCheck(value, &PythonQtInstanceWrapper_Type)) {
306  bool ok;
307  T* object = (T*)PythonQtConv::castWrapperTo(wrap, innerType->className(), ok);
308  Py_XDECREF(value);
309  if (ok) {
310  list->push_back(*object);
311  } else {
312  result = false;
313  break;
314  }
315  } else {
316  Py_XDECREF(value);
317  result = false;
318  break;
319  }
320  }
321  }
322  }
323  return result;
324 }
325 
326 //--------------------------------------------------------------------------------------------------------------------
327 
328 template<class T1, class T2>
329 PyObject* PythonQtConvertPairToPython(const void* /*QPair<T1,T2>* */ inPair, int metaTypeId)
330 {
331  QPair<T1, T2>* pair = (QPair<T1, T2>*)inPair;
332  static int innerType1 = -1;
333  static int innerType2 = -1;
334  if (innerType1==-1) {
335  QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId)));
336  QList<QByteArray> names = innerTypes.split(',');
337  innerType1 = QMetaType::type(names.at(0).trimmed());
338  innerType2 = QMetaType::type(names.at(1).trimmed());
339  }
340  if (innerType1 == QVariant::Invalid || innerType2 == QVariant::Invalid) {
341  std::cerr << "PythonQtConvertPairToPython: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
342  }
343  PyObject* result = PyTuple_New(2);
344  PyTuple_SET_ITEM(result, 0, PythonQtConv::convertQtValueToPythonInternal(innerType1, &pair->first));
345  PyTuple_SET_ITEM(result, 1, PythonQtConv::convertQtValueToPythonInternal(innerType2, &pair->second));
346  return result;
347 }
348 
349 template<class T1, class T2>
350 bool PythonQtConvertPythonToPair(PyObject* obj, void* /*QPair<T1,T2>* */ outPair, int metaTypeId, bool /*strict*/)
351 {
352  QPair<T1, T2>* pair = (QPair<T1, T2>*)outPair;
353  static int innerType1 = -1;
354  static int innerType2 = -1;
355  if (innerType1 == -1) {
356  QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId)));
357  QList<QByteArray> names = innerTypes.split(',');
358  innerType1 = QMetaType::type(names.at(0).trimmed());
359  innerType2 = QMetaType::type(names.at(1).trimmed());
360  }
361  if (innerType1 == QVariant::Invalid || innerType2 == QVariant::Invalid) {
362  std::cerr << "PythonQtConvertPythonToPair: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
363  }
364  bool result = false;
365  if (PySequence_Check(obj)) {
366  int count = PySequence_Size(obj);
367  if (count == 2) {
368  result = true;
369  PyObject* value;
370 
371  value = PySequence_GetItem(obj, 0);
372  // this is quite some overhead, but it avoids having another large switch...
373  QVariant v = PythonQtConv::PyObjToQVariant(value, innerType1);
374  Py_XDECREF(value);
375  if (v.isValid()) {
376  pair->first = qvariant_cast<T1>(v);
377  } else {
378  return false;
379  }
380 
381  value = PySequence_GetItem(obj, 1);
382  // this is quite some overhead, but it avoids having another large switch...
383  v = PythonQtConv::PyObjToQVariant(value, innerType2);
384  Py_XDECREF(value);
385  if (v.isValid()) {
386  pair->second = qvariant_cast<T2>(v);
387  } else {
388  return false;
389  }
390  }
391  }
392  return result;
393 }
394 
395 //--------------------------------------------------------------------------------------------------------------------
396 
397 template<class ListType, class T1, class T2>
398 PyObject* PythonQtConvertListOfPairToPythonList(const void* /*QList<QPair<T1,T2> >* */ inList, int metaTypeId)
399 {
400  ListType* list = (ListType*)inList;
401  static int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
402  if (innerType == QVariant::Invalid) {
403  std::cerr << "PythonQtConvertListOfPairToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
404  }
405  PyObject* result = PyTuple_New(list->size());
406  int i = 0;
407  typedef const QPair<T1, T2> Pair;
408  Q_FOREACH(Pair& value, *list) {
409  PyObject* object = PythonQtConvertPairToPython<T1, T2>(&value, innerType);
410  PyTuple_SET_ITEM(result, i, object);
411  i++;
412  }
413  return result;
414 }
415 
416 template<class ListType, class T1, class T2>
417 bool PythonQtConvertPythonListToListOfPair(PyObject* obj, void* /*QList<QPair<T1,T2> >* */ outList, int metaTypeId, bool /*strict*/)
418 {
419  ListType* list = (ListType*)outList;
420  static int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
421  if (innerType == QVariant::Invalid) {
422  std::cerr << "PythonQtConvertPythonListToListOfPair: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
423  }
424  bool result = false;
425  if (PySequence_Check(obj)) {
426  int count = PySequence_Size(obj);
427  if (count >= 0) {
428  result = true;
429  PyObject* value;
430  for (int i = 0; i < count; i++) {
431  QPair<T1, T2> pair;
432  value = PySequence_GetItem(obj, i);
433  if (PythonQtConvertPythonToPair<T1,T2>(value, &pair, innerType, false)) {
434  Py_XDECREF(value);
435  list->push_back(pair);
436  } else {
437  Py_XDECREF(value);
438  result = false;
439  break;
440  }
441  }
442  }
443  }
444  return result;
445 }
446 
447 //--------------------------------------------------------------------------------------------------------------------
448 
449 template<class MapType, class T>
450 PyObject* PythonQtConvertIntegerMapToPython(const void* /*QMap<int, T>* */ inMap, int metaTypeId)
451 {
452  MapType* map = (MapType*)inMap;
453  static int innerType = -1;
454  if (innerType == -1) {
455  QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId)));
456  QList<QByteArray> names = innerTypes.split(',');
457  innerType = QMetaType::type(names.at(1).trimmed());
458  }
459  if (innerType == QVariant::Invalid) {
460  std::cerr << "PythonQtConvertIntegerMapToPython: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
461  }
462 
463  PyObject* result = PyDict_New();
464  typename MapType::const_iterator t = map->constBegin();
465  PyObject* key;
466  PyObject* val;
467  for (; t != map->constEnd(); t++) {
468  key = PyInt_FromLong(t.key());
469  val = PythonQtConv::convertQtValueToPythonInternal(innerType, &t.value());
470  PyDict_SetItem(result, key, val);
471  Py_DECREF(key);
472  Py_DECREF(val);
473  }
474  return result;
475 }
476 
477 template<class MapType, class T>
478 bool PythonQtConvertPythonToIntegerMap(PyObject* val, void* /*QMap<int, T>* */ outMap, int metaTypeId, bool /*strict*/)
479 {
480  MapType* map = (MapType*)outMap;
481  static int innerType = -1;
482  if (innerType == -1) {
483  QByteArray innerTypes = PythonQtMethodInfo::getInnerTemplateTypeName(QByteArray(QMetaType::typeName(metaTypeId)));
484  QList<QByteArray> names = innerTypes.split(',');
485  innerType = QMetaType::type(names.at(1).trimmed());
486  }
487  if (innerType == QVariant::Invalid) {
488  std::cerr << "PythonQtConvertPythonToIntegerMap: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
489  }
490  bool result = false;
491  if (PyMapping_Check(val)) {
492  result = true;
493  PyObject* items = PyMapping_Items(val);
494  if (items) {
495  int count = PyList_Size(items);
496  PyObject* value;
497  PyObject* key;
498  PyObject* tuple;
499  for (int i = 0; i < count; i++) {
500  tuple = PyList_GetItem(items, i);
501  key = PyTuple_GetItem(tuple, 0);
502  value = PyTuple_GetItem(tuple, 1);
503 
504  bool ok;
505  int intKey = PythonQtConv::PyObjGetInt(key, false, ok);
506  // this is quite some overhead, but it avoids having another large switch...
507  QVariant v = PythonQtConv::PyObjToQVariant(value, innerType);
508  if (v.isValid() && ok) {
509  map->insert(intKey, qvariant_cast<T>(v));
510  } else {
511  result = false;
512  break;
513  }
514  }
515  Py_DECREF(items);
516  }
517  }
518  return result;
519 }
520 
521 
522 #endif
QVariant PythonQtConvertPythonSequenceToQVariantListCB(PyObject *inObject)
PyObject * PythonQtConvertIntegerMapToPython(const void *inMap, int metaTypeId)
PyObject * PythonQtConvertListOfKnownClassToPythonList(const void *inList, int metaTypeId)
PyObject * PythonQtConvertMetaTypeToPythonCB(const void *inObject, int metaTypeId)
bool PythonQtConvertPythonToIntegerMap(PyObject *val, void *outMap, int metaTypeId, bool)
PyObject * PythonQtConvertPairToPython(const void *inPair, int metaTypeId)
bool PythonQtConvertPythonListToListOfPair(PyObject *obj, void *outList, int metaTypeId, bool)
PyObject * PythonQtConvertListOfValueTypeToPythonList(const void *inList, int metaTypeId)
bool PythonQtConvertPythonToMetaTypeCB(PyObject *inObject, void *outObject, int metaTypeId, bool strict)
bool PythonQtConvertPythonToPair(PyObject *obj, void *outPair, int metaTypeId, bool)
PyObject * PythonQtConvertListOfPairToPythonList(const void *inList, int metaTypeId)
bool PythonQtConvertPythonListToListOfKnownClass(PyObject *obj, void *outList, int metaTypeId, bool)
bool PythonQtConvertPythonListToListOfValueType(PyObject *obj, void *outList, int metaTypeId, bool)
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++)
Definition: PythonQtMisc.h:78
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 void * ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo &info, PyObject *obj, bool strict, PythonQtClassInfo *classInfo, void *alreadyAllocatedCPPObject, PythonQtArgumentFrame *frame=NULL)
convert python object to Qt (according to the given parameter) and if the conversion should be strict...
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 PyObject * ConvertQListOfPointerTypeToPythonList(QList< void * > *list, const PythonQtMethodInfo::ParameterInfo &info)
converts the list of pointers of given type to Python
static bool isStringType(PyTypeObject *type)
Returns if the given object is a string (or unicode string)
static PyObject * convertFromPythonQtSafeObjectPtr(const void *inObject, int)
static qint64 PyObjGetLongLong(PyObject *val, bool strict, bool &ok)
get int64 from py object
static PyObject * createCopyFromMetaType(int type, const void *object)
creates a copy of given object, using the QMetaType
static QHash< int, PythonQtConvertPythonToMetaTypeCB * > _pythonToMetaTypeConverters
static bool convertToQListOfPythonQtObjectPtr(PyObject *obj, void *outList, int, bool)
static void setPythonSequenceToQVariantListCallback(PythonQtConvertPythonSequenceToQVariantListCB *cb)
static double PyObjGetDouble(PyObject *val, bool strict, bool &ok)
get double from py object
static void * castWrapperTo(PythonQtInstanceWrapper *wrapper, const QByteArray &className, bool &ok)
cast wrapper to given className if possible
static void * handlePythonToQtAutoConversion(int typeId, PyObject *obj, void *alreadyAllocatedCPPObject, PythonQtArgumentFrame *frame)
handle automatic conversion of some special types (QColor, QBrush, ...)
static bool convertToPythonQtSafeObjectPtr(PyObject *obj, void *outPtr, int, bool)
static QVariant PyObjToQVariant(PyObject *val, int type=-1)
static PyObject * QVariantListToPyObject(const QVariantList &l)
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 PyObject * convertFromQListOfPythonQtObjectPtr(const void *inObject, int)
static PyObject * QVariantToPyObject(const QVariant &v)
convert QVariant from PyObject
static PyObject * QStringListToPyList(const QStringList &list)
converts QStringList to Python list
static PyObject * mapToPython(const Map &m)
helper template function for QVariantMapToPyObject/QVariantHashToPyObject
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 PyObject * convertFromStringRef(const void *inObject, int)
static PyObject * QVariantHashToPyObject(const QVariantHash &m)
static PyObject * QStringToPyObject(const QString &str)
converts QString to Python string (unicode!)
static QString PyObjGetString(PyObject *val)
get string value from py object
static PyObject * convertFromPythonQtObjectPtr(const void *inObject, int)
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 QString PyObjGetString(PyObject *val, bool strict, bool &ok)
get string value from py object
static void pythonToMapVariant(PyObject *val, QVariant &result)
helper template method for conversion from Python to QVariantMap/Hash
static PyObject * QVariantMapToPyObject(const QVariantMap &m)
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 PyObject * GetPyBool(bool val)
get a ref counted True or False Python object
static int PyObjGetInt(PyObject *val, bool strict, bool &ok)
get int from py object
static PythonQtConvertPythonSequenceToQVariantListCB * _pythonSequenceToQVariantListCB
static QString PyObjGetRepresentation(PyObject *val)
get string representation of py object
static QHash< int, PythonQtConvertMetaTypeToPythonCB * > _metaTypeToPythonConverters
static void registerPythonToMetaTypeConverter(int metaTypeId, PythonQtConvertPythonToMetaTypeCB *cb)
register a converter callback from python to cpp for given metatype
static QStringList PyObjToStringList(PyObject *val, bool strict, bool &ok)
create a string list from python sequence
static PyObject * QStringListToPyObject(const QStringList &list)
converts QStringList to Python tuple
static void registerMetaTypeToPythonConverter(int metaTypeId, PythonQtConvertMetaTypeToPythonCB *cb)
register a converter callback from cpp to python for given metatype
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
QByteArray typeName(const QMetaMethod &method)
Definition: PythonQtUtils.h:72
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