SourceForge.net Logo
PythonQt
Public Member Functions | Protected Member Functions | List of all members
PythonQtObjectPtr Class Reference

a smart pointer that stores a PyObject pointer and that handles reference counting automatically More...

#include <PythonQtObjectPtr.h>

Public Member Functions

 PythonQtObjectPtr ()
 
 PythonQtObjectPtr (const PythonQtObjectPtr &p)
 
 PythonQtObjectPtr (const QVariant &variant)
 If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference. This results in an increment of the reference count. More...
 
 PythonQtObjectPtr (PyObject *o)
 
 ~PythonQtObjectPtr ()
 
bool fromVariant (const QVariant &variant)
 If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference. This results in an increment of the reference count. More...
 
PythonQtObjectPtroperator= (const PythonQtObjectPtr &p)
 
PythonQtObjectPtroperator= (PyObject *o)
 
PythonQtObjectPtroperator= (const QVariant &variant)
 
bool operator== (const PythonQtObjectPtr &p) const
 
bool operator!= (const PythonQtObjectPtr &p) const
 
bool operator== (PyObject *p) const
 
bool operator!= (PyObject *p) const
 
bool isNull () const
 
PyObjectoperator-> () const
 
PyObjectoperator* () const
 
 operator PyObject * () const
 
void setNewRef (PyObject *o)
 sets the object and passes the ownership (stealing the reference, in Python slang) More...
 
PyObjectobject () const
 
QVariant evalScript (const QString &script, int start=Py_file_input)
 evaluates the given script code in the context of this object and returns the result value More...
 
QVariant evalCode (PyObject *pycode)
 
void evalFile (const QString &filename)
 evaluates the given code in the context More...
 
void addObject (const QString &name, QObject *object)
 add the given object to the module as a variable with name (it can be removed via clearVariable) More...
 
void addVariable (const QString &name, const QVariant &v)
 add the given variable to the module More...
 
void removeVariable (const QString &name)
 remove the given variable More...
 
QVariant getVariable (const QString &name)
 get the variable with the name of the module, returns an invalid QVariant on error More...
 
QVariant call (const QString &callable, const QVariantList &args=QVariantList(), const QVariantMap &kwargs=QVariantMap())
 call the given python object (in the scope of the current object), returns the result converted to a QVariant More...
 
QVariant call (const QVariantList &args=QVariantList(), const QVariantMap &kwargs=QVariantMap())
 call the contained python object directly, returns the result converted to a QVariant More...
 

Protected Member Functions

void setObject (PyObject *o)
 

Detailed Description

a smart pointer that stores a PyObject pointer and that handles reference counting automatically

Definition at line 53 of file PythonQtObjectPtr.h.

Constructor & Destructor Documentation

PythonQtObjectPtr::PythonQtObjectPtr ( )
inline

Definition at line 56 of file PythonQtObjectPtr.h.

56 :_object(NULL) {}
PythonQtObjectPtr::PythonQtObjectPtr ( const PythonQtObjectPtr p)
inline

Definition at line 58 of file PythonQtObjectPtr.h.

References object().

59  :_object(NULL) {
60  setObject(p.object());
61  }
void setObject(PyObject *o)
PyObject * object() const
PythonQtObjectPtr::PythonQtObjectPtr ( const QVariant &  variant)
inline

If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference. This results in an increment of the reference count.

Definition at line 64 of file PythonQtObjectPtr.h.

64  :_object(NULL) {
65  fromVariant(variant);
66  }
bool fromVariant(const QVariant &variant)
If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference...
PythonQtObjectPtr::PythonQtObjectPtr ( PyObject o)
PythonQtObjectPtr::~PythonQtObjectPtr ( )

Member Function Documentation

void PythonQtObjectPtr::addObject ( const QString &  name,
QObject *  object 
)

add the given object to the module as a variable with name (it can be removed via clearVariable)

void PythonQtObjectPtr::addVariable ( const QString &  name,
const QVariant &  v 
)

add the given variable to the module

QVariant PythonQtObjectPtr::call ( const QString &  callable,
const QVariantList &  args = QVariantList(),
const QVariantMap &  kwargs = QVariantMap() 
)

call the given python object (in the scope of the current object), returns the result converted to a QVariant

QVariant PythonQtObjectPtr::call ( const QVariantList &  args = QVariantList(),
const QVariantMap &  kwargs = QVariantMap() 
)

call the contained python object directly, returns the result converted to a QVariant

QVariant PythonQtObjectPtr::evalCode ( PyObject pycode)

evaluates the given code and returns the result value (use Py_Compile etc. to create pycode from string) If pycode is NULL, a python error is printed.

void PythonQtObjectPtr::evalFile ( const QString &  filename)

evaluates the given code in the context

QVariant PythonQtObjectPtr::evalScript ( const QString &  script,
int  start = Py_file_input 
)

evaluates the given script code in the context of this object and returns the result value

bool PythonQtObjectPtr::fromVariant ( const QVariant &  variant)

If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference. This results in an increment of the reference count.

QVariant PythonQtObjectPtr::getVariable ( const QString &  name)

get the variable with the name of the module, returns an invalid QVariant on error

bool PythonQtObjectPtr::isNull ( ) const
inline

Definition at line 108 of file PythonQtObjectPtr.h.

108 { return !object(); }
PyObject * object() const
PyObject* PythonQtObjectPtr::object ( ) const
inline

Definition at line 119 of file PythonQtObjectPtr.h.

Referenced by operator=(), operator==(), and PythonQtObjectPtr().

119  {
120  return _object;
121  }
PythonQtObjectPtr::operator PyObject * ( ) const
inline

Definition at line 114 of file PythonQtObjectPtr.h.

114 { return object(); }
PyObject * object() const
bool PythonQtObjectPtr::operator!= ( const PythonQtObjectPtr p) const
inline

Definition at line 96 of file PythonQtObjectPtr.h.

96  {
97  return !( *this == p );
98  }
bool PythonQtObjectPtr::operator!= ( PyObject p) const
inline

Definition at line 104 of file PythonQtObjectPtr.h.

104  {
105  return object() != p;
106  }
PyObject * object() const
PyObject& PythonQtObjectPtr::operator* ( ) const
inline

Definition at line 112 of file PythonQtObjectPtr.h.

112 { return *( object() ); }
PyObject * object() const
PyObject* PythonQtObjectPtr::operator-> ( ) const
inline

Definition at line 110 of file PythonQtObjectPtr.h.

110 { return object(); }
PyObject * object() const
PythonQtObjectPtr& PythonQtObjectPtr::operator= ( const PythonQtObjectPtr p)
inline

Definition at line 75 of file PythonQtObjectPtr.h.

References object().

75  {
76  setObject(p.object());
77  return *this;
78  }
void setObject(PyObject *o)
PyObject * object() const
PythonQtObjectPtr& PythonQtObjectPtr::operator= ( PyObject o)
inline

Definition at line 80 of file PythonQtObjectPtr.h.

80  {
81  setObject(o);
82  return *this;
83  }
void setObject(PyObject *o)
PythonQtObjectPtr& PythonQtObjectPtr::operator= ( const QVariant &  variant)
inline

Definition at line 86 of file PythonQtObjectPtr.h.

86  {
87  fromVariant(variant);
88  return *this;
89  }
bool fromVariant(const QVariant &variant)
If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference...
bool PythonQtObjectPtr::operator== ( const PythonQtObjectPtr p) const
inline

Definition at line 92 of file PythonQtObjectPtr.h.

References object().

92  {
93  return object() == p.object();
94  }
PyObject * object() const
bool PythonQtObjectPtr::operator== ( PyObject p) const
inline

Definition at line 100 of file PythonQtObjectPtr.h.

100  {
101  return object() == p;
102  }
PyObject * object() const
void PythonQtObjectPtr::removeVariable ( const QString &  name)

remove the given variable

void PythonQtObjectPtr::setNewRef ( PyObject o)

sets the object and passes the ownership (stealing the reference, in Python slang)

void PythonQtObjectPtr::setObject ( PyObject o)
protected

The documentation for this class was generated from the following file: