Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtConversion.h
3206 views
#ifndef _PYTHONQTCONVERSION_H1#define _PYTHONQTCONVERSION_H23/*4*5* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.6*7* This library is free software; you can redistribute it and/or8* modify it under the terms of the GNU Lesser General Public9* License as published by the Free Software Foundation; either10* version 2.1 of the License, or (at your option) any later version.11*12* This library is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU15* Lesser General Public License for more details.16*17* Further, this software is distributed without any warranty that it is18* free of the rightful claim of any third person regarding infringement19* or the like. Any license provided herein, whether implied or20* otherwise, applies only to this software file. Patent licenses, if21* any, provided herein do not apply to combinations of this program with22* other software, or any other product whatsoever.23*24* You should have received a copy of the GNU Lesser General Public25* License along with this library; if not, write to the Free Software26* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA27*28* Contact information: MeVis Research GmbH, Universitaetsallee 29,29* 28359 Bremen, Germany or:30*31* http://www.mevis.de32*33*/3435//----------------------------------------------------------------------------------36/*!37// \file PythonQtConversion.h38// \author Florian Link39// \author Last changed by $Author: florian $40// \date 2006-0541*/42//----------------------------------------------------------------------------------4344#include "PythonQt.h"45#include "PythonQtMisc.h"46#include "PythonQtClassInfo.h"47#include "PythonQtMethodInfo.h"4849#include <QWidget>5051//! a static class that offers methods for type conversion52class PythonQtConv {5354public:5556//! get a ref counted True or False Python object57static PyObject* GetPyBool(bool val);5859//! converts the Qt parameter given in \c data, interpreting it as a \c info parameter, into a Python object,60static PyObject* ConvertQtValueToPython(const PythonQtMethodInfo::ParameterInfo& info, void* data);6162//! convert python object to Qt (according to the given parameter) and if the conversion should be strict, the meta object is passed in for enum resolving63static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, const QMetaObject* meta);6465//! creates a data storage for the passed parameter type and returns a void pointer to be set as arg[0] of qt_metacall66static void* CreateQtReturnValue(const PythonQtMethodInfo::ParameterInfo& info);6768//! converts QString to Python string (unicode!)69static PyObject* QStringToPyObject(const QString& str);7071//! converts QStringList to Python tuple72static PyObject* QStringListToPyObject(const QStringList& list);7374//! converts QStringList to Python list75static PyObject* QStringListToPyList(const QStringList& list);7677//! get string representation of py object78static QString PyObjGetRepresentation(PyObject* val);7980//! get string value form py object81static QString PyObjGetString(PyObject* val) { bool ok; QString s = PyObjGetString(val, false, ok); return s; }82//! get string value form py object83static QString PyObjGetString(PyObject* val, bool strict, bool &ok);84//! get int from py object85static int PyObjGetInt(PyObject* val, bool strict, bool &ok);86//! get int64 from py object87static qint64 PyObjGetLongLong(PyObject* val, bool strict, bool &ok);88//! get int64 from py object89static quint64 PyObjGetULongLong(PyObject* val, bool strict, bool &ok);90//! get double from py object91static double PyObjGetDouble(PyObject* val, bool strict, bool &ok);92//! get bool from py object93static bool PyObjGetBool(PyObject* val, bool strict, bool &ok);9495//! create a string list from python sequence96static QStringList PyObjToStringList(PyObject* val, bool strict, bool& ok);9798//! convert python object to qvariant, if type is given it will try to create a qvariant of that type, otherwise99//! it will guess from the python type100static QVariant PyObjToQVariant(PyObject* val, int type = -1);101102//! convert QVariant from PyObject103static PyObject* QVariantToPyObject(const QVariant& v);104105static PyObject* QVariantMapToPyObject(const QVariantMap& m);106static PyObject* QVariantListToPyObject(const QVariantList& l);107108public:109110static PythonQtValueStorage<qint64, 128> global_valueStorage;111static PythonQtValueStorage<void*, 128> global_ptrStorage;112static PythonQtValueStorage<QVariant, 32> global_variantStorage;113114protected:115//! converts the Qt parameter given in \c data, interpreting it as a \c type registered qvariant/meta type, into a Python object,116static PyObject* ConvertQtValueToPythonInternal(int type, void* data);117118};119120#endif121122123