MeVisLab Scripting Reference
MLPythonItemModelWrapper Class Reference

#include <mlPythonItemModelWrapper.h>

Inherits MLAbstractItemModelWrapper.

Public Slots

bool isCaching () const
 
void setDataSource (PyObject *object, bool caching=false)
 
- Public Slots inherited from MLAbstractItemModelWrapper
QObject * qmlModel () const
 
bool isFlat () const
 
bool hasChildren (const ModelIndexWrapper *parent)
 
int getChildCount (const ModelIndexWrapper *parent)
 
ModelIndexWrappergetChild (const ModelIndexWrapper *parent, unsigned int index)
 
ModelIndexWrappergetParent (const ModelIndexWrapper *child)
 
ModelIndexWrapperfindFirst (const QVariant &attribute, const QVariant &value)
 
ModelIndexWrappersearchItem (const QVariant &attribute, const QVariantList &values)
 
int getAttributeCount () const
 
QStringList getAttributeNames () const
 
QString getAttributeName (int index) const
 
QVariant getAttributeDefault (int index) const
 
int getAttributeIndex (const QString &name)
 
QVariant getData (const ModelIndexWrapper *item, int attributeIndex)
 
bool setData (const ModelIndexWrapper *item, int attributeIndex, const QVariant &data)
 
bool bulkSetData (const QList< ModelIndexWrapper * > &items, int attributeIndex, const QVariant &data)
 

Static Public Member Functions

static ml::RefCountedBase * createObject (const QVariantList &arguments)
 

Additional Inherited Members

- Signals inherited from MLAbstractItemModelWrapper
void itemChanged (ModelIndexWrapper *item, bool after)
 
void itemsInserted (ModelIndexWrapper *parent, unsigned int childIndex, unsigned int itemsInserted, bool after)
 
void itemsRemoved (ModelIndexWrapper *parent, unsigned int childIndex, unsigned int itemsRemoved, bool after)
 
void dataChanged (const QList< ModelIndexWrapper * > &items, const QList< int > &attributeIndices)
 

Detailed Description

This class wraps the class ml::PythonItemModel and thus provides an item model that takes its data from a Python object.


You should not use this wrapper directly.

Instead you should derive from class ItemModelDataSource contained in the ItemModelSupport Python module (source code at Packages/MeVisLab/Standard/Modules/Scripts/python/ItemModelSupport.py).

You can also have a look at the TestItemModelView module for an example. This module implements both the StandardItemModel and PythonItemModel and you can switch between these implementations.

Member Function Documentation

◆ createObject()

static ml::RefCountedBase * MLPythonItemModelWrapper::createObject ( const QVariantList & arguments)
static

Create new Python item model; this is used by MLAB.createMLBaseObject to create a PythonItemModel. This takes a list with 1 or 2 arguments.

The first, required element is the list of attribute names.

The second, optional element is a bool. If set this is a hint that the model will have no sub-items. This can be used by views to avoid reserving space for sub-item indicators.

Example:

myModel = MLAB.createMLBaseObject("PythonItemModel",
[["name", "size", "directory", "writable"], False])
Access to all global functions and objects of MLAB.
Definition mlabGlobalScriptAccess.h:79
QObject * createMLBaseObject(const QString &baseClassName, const QVariantList &arguments=QVariantList())
Creates a new reference-counted ml::Base object, conveniently wrapped for scripting; which arguments ...

◆ isCaching

bool MLPythonItemModelWrapper::isCaching ( ) const
inlineslot

Return if the model is caching the values.

◆ setDataSource

void MLPythonItemModelWrapper::setDataSource ( PyObject * object,
bool caching = false )
slot

Changing the data source object for the model.

If caching is set to true, most results obtained from the data source are cached.

The object must have certain methods, as e.g. found in the ItemModelDataSource class mentioned above.