SourceForge.net Logo
Public Member Functions | Protected Member Functions

PythonQtObjectPtr Class Reference

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

#include <PythonQtObjectPtr.h>

List of all members.

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.
 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.
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)
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
QVariant evalCode (PyObject *pycode)
void evalFile (const QString &filename)
 evaluates the given code in the context
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)
void addVariable (const QString &name, const QVariant &v)
 add the given variable to the module
void removeVariable (const QString &name)
 remove the given variable
QVariant getVariable (const QString &name)
 get the variable with the name of the module, returns an invalid QVariant on error
QVariant call (const QString &callable, const QVariantList &args=QVariantList())
 call the given python object (in the scope of the current object), returns the result converted to a QVariant
QVariant call (const QVariantList &args=QVariantList())
 call the contained python object directly, returns the result converted to a QVariant

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 51 of file PythonQtObjectPtr.h.


Constructor & Destructor Documentation

PythonQtObjectPtr::PythonQtObjectPtr (  )  [inline]

Definition at line 54 of file PythonQtObjectPtr.h.

:_object(NULL) {}

PythonQtObjectPtr::PythonQtObjectPtr ( const PythonQtObjectPtr p  )  [inline]

Definition at line 56 of file PythonQtObjectPtr.h.

References object().

                                               :_object(NULL) {
    setObject(p.object());
  }

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 61 of file PythonQtObjectPtr.h.

                                            :_object(NULL) {
      fromVariant(variant); 
  }

PythonQtObjectPtr::PythonQtObjectPtr ( PyObject o  )  [inline]

Definition at line 65 of file PythonQtObjectPtr.h.

                                 {
    _object = o;
    if (o) Py_INCREF(_object);
  }

PythonQtObjectPtr::~PythonQtObjectPtr (  )  [inline]

Definition at line 70 of file PythonQtObjectPtr.h.

{ if (_object) Py_DECREF(_object); }


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() 
)

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()  ) 

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.

{ return !object(); }

PyObject* PythonQtObjectPtr::object (  )  const [inline]

Definition at line 124 of file PythonQtObjectPtr.h.

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

                           {
    return _object;
  }

PythonQtObjectPtr::operator PyObject * (  )  const [inline]

Definition at line 114 of file PythonQtObjectPtr.h.

{ return object(); }

bool PythonQtObjectPtr::operator!= ( PyObject p  )  const [inline]

Definition at line 104 of file PythonQtObjectPtr.h.

                                        {
    return object() != p;
  }

bool PythonQtObjectPtr::operator!= ( const PythonQtObjectPtr p  )  const [inline]

Definition at line 96 of file PythonQtObjectPtr.h.

                                                       {
    return !( *this == p );
  }

PyObject& PythonQtObjectPtr::operator* (  )  const [inline]

Definition at line 112 of file PythonQtObjectPtr.h.

{ return *( object() ); }

PyObject* PythonQtObjectPtr::operator-> (  )  const [inline]

Definition at line 110 of file PythonQtObjectPtr.h.

{ return object(); }

PythonQtObjectPtr& PythonQtObjectPtr::operator= ( const QVariant &  variant  )  [inline]

Definition at line 86 of file PythonQtObjectPtr.h.

                                                        {
      fromVariant(variant);
      return *this;
  }

PythonQtObjectPtr& PythonQtObjectPtr::operator= ( const PythonQtObjectPtr p  )  [inline]

Definition at line 75 of file PythonQtObjectPtr.h.

References object().

                                                           {
    setObject(p.object());
    return *this;
  }

PythonQtObjectPtr& PythonQtObjectPtr::operator= ( PyObject o  )  [inline]

Definition at line 80 of file PythonQtObjectPtr.h.

                                            {
    setObject(o);
    return *this;
  }

bool PythonQtObjectPtr::operator== ( PyObject p  )  const [inline]

Definition at line 100 of file PythonQtObjectPtr.h.

                                       {
    return object() == p;
  }

bool PythonQtObjectPtr::operator== ( const PythonQtObjectPtr p  )  const [inline]

Definition at line 92 of file PythonQtObjectPtr.h.

References object().

                                                      {
    return object() == p.object();
  }

void PythonQtObjectPtr::removeVariable ( const QString &  name  ) 

remove the given variable

void PythonQtObjectPtr::setNewRef ( PyObject o  )  [inline]

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

Definition at line 117 of file PythonQtObjectPtr.h.

                              {
    if (o != _object) {
      if (_object) Py_DECREF(_object);
      _object = o;
    }
  }

void PythonQtObjectPtr::setObject ( PyObject o  )  [inline, protected]

Definition at line 158 of file PythonQtObjectPtr.h.

                              {
    if (o != _object) {
      if (_object) Py_DECREF(_object);
      _object = o;
      if (_object) Py_INCREF(_object);
    }
  }


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