|
PythonQt
|
00001 #ifndef _PYTHONQTOBJECTPTR_H 00002 #define _PYTHONQTOBJECTPTR_H 00003 00004 /* 00005 * 00006 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * Further, this software is distributed without any warranty that it is 00019 * free of the rightful claim of any third person regarding infringement 00020 * or the like. Any license provided herein, whether implied or 00021 * otherwise, applies only to this software file. Patent licenses, if 00022 * any, provided herein do not apply to combinations of this program with 00023 * other software, or any other product whatsoever. 00024 * 00025 * You should have received a copy of the GNU Lesser General Public 00026 * License along with this library; if not, write to the Free Software 00027 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 * 00029 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, 00030 * 28359 Bremen, Germany or: 00031 * 00032 * http://www.mevis.de 00033 * 00034 */ 00035 00036 //---------------------------------------------------------------------------------- 00043 //---------------------------------------------------------------------------------- 00044 00045 #include "PythonQtPythonInclude.h" 00046 00047 #include "PythonQtSystem.h" 00048 #include <QVariant> 00049 #include <QVariantList> 00050 00052 class PYTHONQT_EXPORT PythonQtObjectPtr 00053 { 00054 public: 00055 PythonQtObjectPtr():_object(NULL) {} 00056 00057 PythonQtObjectPtr(const PythonQtObjectPtr &p) 00058 :_object(NULL) { 00059 setObject(p.object()); 00060 } 00061 00063 PythonQtObjectPtr(const QVariant& variant):_object(NULL) { 00064 fromVariant(variant); 00065 } 00066 00067 PythonQtObjectPtr(PyObject* o); 00068 00069 ~PythonQtObjectPtr(); 00070 00072 bool fromVariant(const QVariant& variant); 00073 00074 PythonQtObjectPtr &operator=(const PythonQtObjectPtr &p) { 00075 setObject(p.object()); 00076 return *this; 00077 } 00078 00079 PythonQtObjectPtr &operator=(PyObject* o) { 00080 setObject(o); 00081 return *this; 00082 } 00083 00084 00085 PythonQtObjectPtr &operator=(const QVariant& variant) { 00086 fromVariant(variant); 00087 return *this; 00088 } 00089 00090 00091 bool operator==( const PythonQtObjectPtr &p ) const { 00092 return object() == p.object(); 00093 } 00094 00095 bool operator!= ( const PythonQtObjectPtr& p ) const { 00096 return !( *this == p ); 00097 } 00098 00099 bool operator==( PyObject* p ) const { 00100 return object() == p; 00101 } 00102 00103 bool operator!= ( PyObject* p ) const { 00104 return object() != p; 00105 } 00106 00107 bool isNull() const { return !object(); } 00108 00109 PyObject* operator->() const { return object(); } 00110 00111 PyObject& operator*() const { return *( object() ); } 00112 00113 operator PyObject*() const { return object(); } 00114 00116 void setNewRef(PyObject* o); 00117 00118 PyObject* object() const { 00119 return _object; 00120 } 00121 00123 QVariant evalScript(const QString& script, int start = Py_file_input); 00124 00127 QVariant evalCode(PyObject* pycode); 00128 00130 void evalFile(const QString& filename); 00131 00133 void addObject(const QString& name, QObject* object); 00134 00136 void addVariable(const QString& name, const QVariant& v); 00137 00139 void removeVariable(const QString& name); 00140 00142 QVariant getVariable(const QString& name); 00143 00145 QVariant call(const QString& callable, const QVariantList& args = QVariantList()); 00146 00148 QVariant call(const QVariantList& args = QVariantList()); 00149 00150 protected: 00151 00152 void setObject(PyObject* o); 00153 00154 private: 00155 PyObject* _object; 00156 }; 00157 00158 00159 // register it to the meta type system 00160 Q_DECLARE_METATYPE(PythonQtObjectPtr) 00161 00162 #endif 00163
1.7.4