SourceForge.net Logo
PythonQt
Classes | Defines | Typedefs | Functions
PythonQtConversion.h File Reference
#include "PythonQt.h"
#include "PythonQtMisc.h"
#include "PythonQtClassInfo.h"
#include "PythonQtMethodInfo.h"
#include <QWidget>
#include <QList>
#include <vector>

Go to the source code of this file.

Classes

class  PythonQtConv
 a static class that offers methods for type conversion More...

Defines

#define PythonQtRegisterListTemplateConverter(type, innertype)
#define PythonQtRegisterToolClassesTemplateConverter(innertype)

Typedefs

typedef PyObjectPythonQtConvertMetaTypeToPythonCB (const void *inObject, int metaTypeId)
typedef bool PythonQtConvertPythonToMetaTypeCB (PyObject *inObject, void *outObject, int metaTypeId, bool strict)

Functions

template<class ListType , class T >
PyObjectPythonQtConvertListOfValueTypeToPythonList (const void *inList, int metaTypeId)
template<class ListType , class T >
bool PythonQtConvertPythonListToListOfValueType (PyObject *obj, void *outList, int metaTypeId, bool)

Detailed Description

Author:
Florian Link
Last changed by
Author:
florian
Date:
2006-05

Definition in file PythonQtConversion.h.


Define Documentation

#define PythonQtRegisterListTemplateConverter (   type,
  innertype 
)
Value:
{ int typeId = qRegisterMetaType<type<innertype> >(#type"<"#innertype">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonListToListOfValueType<type<innertype>, innertype>); \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertListOfValueTypeToPythonList<type<innertype>, innertype>); \
}

Definition at line 57 of file PythonQtConversion.h.

#define PythonQtRegisterToolClassesTemplateConverter (   innertype)
Value:

Definition at line 63 of file PythonQtConversion.h.


Typedef Documentation

typedef PyObject* PythonQtConvertMetaTypeToPythonCB(const void *inObject, int metaTypeId)

Definition at line 54 of file PythonQtConversion.h.

typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject *inObject, void *outObject, int metaTypeId, bool strict)

Definition at line 55 of file PythonQtConversion.h.


Function Documentation

template<class ListType , class T >
PyObject* PythonQtConvertListOfValueTypeToPythonList ( const void *  inList,
int  metaTypeId 
)

Definition at line 166 of file PythonQtConversion.h.

References PythonQtConv::ConvertQtValueToPythonInternal(), and PythonQtConv::getInnerTemplateMetaType().

{
  ListType* list = (ListType*)inList; 
  static const int innerType = PythonQtConv::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
  if (innerType == QVariant::Invalid) {
    std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
  }
  PyObject* result = PyTuple_New(list->size());
  int i = 0;
  foreach (const T& value, *list) {
    PyTuple_SET_ITEM(result, i, PythonQtConv::ConvertQtValueToPythonInternal(innerType, &value));
    i++;
  }
  return result;
}
template<class ListType , class T >
bool PythonQtConvertPythonListToListOfValueType ( PyObject obj,
void *  outList,
int  metaTypeId,
bool   
)

Definition at line 183 of file PythonQtConversion.h.

References PythonQtConv::getInnerTemplateMetaType(), and PythonQtConv::PyObjToQVariant().

{
  ListType* list = (ListType*)outList; 
  static const int innerType = PythonQtConv::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId)));
  if (innerType == QVariant::Invalid) {
    std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl;
  }
  bool result = false;
  if (PySequence_Check(obj)) {
    result = true;
    int count = PySequence_Size(obj);
    PyObject* value;
    for (int i = 0;i<count;i++) {
      value = PySequence_GetItem(obj,i);
      // this is quite some overhead, but it avoids having another large switch...
      QVariant v = PythonQtConv::PyObjToQVariant(value, innerType);
      if (v.isValid()) {
        list->push_back(qVariantValue<T>(v));
      } else {
        result = false;
        break;
      }
    }
  }
  return result;
}