MeVisLab Toolbox Reference
ml::StandardItemModel Class Reference

This could be the interface for a standard item model. More...

#include <mlStandardItemModel.h>

Inheritance diagram for ml::StandardItemModel:
ml::AbstractItemModel ml::RefCountedBase ml::EventSource ml::Base

Classes

struct  Attribute
 Defines the name of an attribute and its default value. More...
 

Public Types

typedef std::vector< AttributeAttributeVector
 Vector of attributes.
 
typedef boost::unordered_map< int, VariantItemData
 Item data, each attribute is specified via its int identifier and its variant value.
 
typedef std::vector< ItemDataItemDataVector
 Vector of item data.
 
- Public Types inherited from ml::Base
enum  PersistenceInterface { PersistenceByString , PersistenceByTreeNode , PersistenceByStream }
 This enum describes the different persistence interfaces available. More...
 

Public Member Functions

 StandardItemModel (const AttributeVector &attributes, int hasChildrenAttribute=-1, bool flat=false)
 Create new model with given attributes (and defaults); The second argument gives an attribute that should be used to tell if an item has children.
 
 StandardItemModel ()
 Create model without attributes.
 
 ~StandardItemModel () override
 
virtual int getChildPosition (const ModelIndex &child)
 get index position of child relative to its parent
 
virtual void clear ()
 clear the complete model
 
virtual void insertItems (const ModelIndex &parent, unsigned int position, const ItemDataVector &items)
 insert new items; this doesn't generate a insert notification during handling of a ItemChildrenRequestEvent for this very parent - this can be used for dynamically populating the model
 
virtual ModelIndex addItem (const ModelIndex &parent, const ItemData &)
 
virtual void removeItems (const ModelIndex &parent, unsigned int position, unsigned int numItems)
 remove items
 
bool isFlat () const override
 overridden methods
 
bool hasChildren (const ModelIndex &parent) override
 Or rather mightHaveChildren.
 
unsigned int getChildCount (const ModelIndex &parent) override
 Get number of children of the given item, an invalid index means number of top-level items.
 
ModelIndex getChild (const ModelIndex &parent, unsigned int index) override
 Get n-th child of an item (or n-th top-level item if parent index is invalid).
 
ModelIndex getParent (const ModelIndex &child) override
 Get parent of an item.
 
int getAttributeCount () const override
 attribute discovery
 
std::string getAttributeName (int index) const override
 Get name of n-th attribute. Must be overridden.
 
Variant getAttributeDefault (int index) const override
 Return default value of n-th attribute.
 
Variant getData (const ModelIndex &item, int attributeIndex) override
 data access
 
bool rawSetData (const ModelIndex &item, int attributeIndex, const Variant &data) override
 This will be called by setData and bulkSetData, which will do the necessary notifications afterwards; attributeIndex doesn't need to be checked for valid range, this has already been done when this method is called.
 
bool implementsPersistence (PersistenceInterface iface) const override
 Persistence interface.
 
void writeTo (AbstractPersistenceOutputStream *stream) const override
 Write the objects state to the data stream object.
 
void readFrom (AbstractPersistenceInputStream *stream, int version) override
 Read the objects state from the data stream object.
 
- Public Member Functions inherited from ml::AbstractItemModel
virtual int getAttributeIndex (const std::string &name)
 Get index of attribute with the given name.
 
virtual bool setData (const ModelIndex &item, int attributeIndex, const Variant &data, void *skipListener=nullptr)
 Update a single attribute on a single item.
 
virtual bool bulkSetData (const std::vector< ModelIndex > &items, int attributeIndex, const Variant &data, void *skipListener=nullptr)
 bulkSetData will be used by views to set selection state to an attribute, so that we only get a single update notification, this is important for remote handling.
 
virtual bool bulkSetData (const std::vector< ModelIndex > &items, int attributeIndex, const std::vector< Variant > &data, void *skipListener=nullptr)
 This method can be used to update whole columns with varying data.
 
- Public Member Functions inherited from ml::RefCountedBase
 RefCountedBase ()
 Constructor.
 
 RefCountedBase (const RefCountedBase &)
 Explicit copy constructor.
 
virtual void incRefCount () const
 Increase reference count.
 
virtual void decRefCount () const
 Decrease ref count (object will be deleted if ref count is decremented to 0)
 
bool isRefCountedBase () const override
 Returns if the instance is derived from RefCountedBase.
 
- Public Member Functions inherited from ml::EventSource
 EventSource ()
 
 EventSource (const EventSource &evSource)
 
 ~EventSource () override
 
void addEventListener (BaseEventCallback *cb, void *userData)
 add event listener callback to this Base object - the userData will be the first argument when the callback is called
 
void removeEventListener (BaseEventCallback *cb, void *userData)
 remove event listener callback from this Base object - arguments must be the same as for the addEventListener call
 
bool hasEventListeners () const
 check if any event listeners have been added to this Base object; this can be used to skip the sendEvent call (and the potentially expensive building of the event object) altogether
 
- Public Member Functions inherited from ml::Base
 Base ()
 Constructor.
 
virtual ~Base ()
 Destructor.
 
virtual BasedeepCopy () const
 Set addStateToTree version number that can be accessed via getAddStateVersion()
 
bool isOfAllowedType (const std::vector< const RuntimeType * > &types) const
 Check if this object's type is equal to or derived from one of the types given in the argument.
 
virtual std::string detailString () const
 Return a string describing this object.
 
virtual std::string persistentState () const
 Returns a string describing the object's internal state.
 
virtual void setPersistentState (const std::string &state)
 Restores the object's internal state from a string that had been previously generated using persistentState().
 
virtual void addStateToTree (TreeNode *) const
 Attaches the object state as children of the given parent node.
 
virtual void readStateFromTree (TreeNode *)
 Reads the object state from the children of the given parent node.
 

Protected Member Functions

void notifyItemChildrenRequest (const ModelIndex &parent)
 
- Protected Member Functions inherited from ml::AbstractItemModel
 AbstractItemModel ()
 
ModelIndex createIndex (void *data)
 
ModelIndex createIndex (size_t data)
 
virtual void incItemRefCount (void *)
 implement this if the pointer in the model indices needs explicit reference counting
 
virtual void decItemRefCount (void *)
 
virtual void notifyItemChanged (const ModelIndex &item, bool after, void *skipListener=nullptr)
 change notifications
 
virtual void notifyItemsInserted (const ModelIndex &parent, unsigned int childIndex, unsigned int itemsInserted, bool after, void *skipListener=nullptr)
 Notify listeners that an item gets/got additional children.
 
virtual void notifyItemsRemoved (const ModelIndex &parent, unsigned int childIndex, unsigned int itemsRemoved, bool after, void *skipListener=nullptr)
 Notify listeners that an item loses/lost additional children.
 
virtual void notifyItemsDataChanged (const std::vector< ModelIndex > &items, const std::vector< int > &attributeIndices, void *skipListener=nullptr)
 Notify listeners that attributes have changed on the given items.
 
- Protected Member Functions inherited from ml::RefCountedBase
 ~RefCountedBase () override
 Macro for the declaration of the runtime type system methods, defined in mlRuntimeSubClass.h.
 
- Protected Member Functions inherited from ml::EventSource
void sendEvent (BaseEvent *event, void *skipListener=nullptr)
 Macro for the declaration of the runtime type system methods, defined in mlRuntimeSubClass.h.
 

Additional Inherited Members

- Static Public Member Functions inherited from ml::RefCountedBase
static void updateReferenceCountingIfSupported (Base *oldValue, Base *newValue, bool &isRefCountedBase)
 Helper method that handles inc/dec of ref count if base instances support it.
 
- Protected Attributes inherited from ml::RefCountedBase
MLint32 _refCount
 Reference count.
 

Detailed Description

This could be the interface for a standard item model.

Definition at line 27 of file mlStandardItemModel.h.

Member Typedef Documentation

◆ AttributeVector

Vector of attributes.

Definition at line 47 of file mlStandardItemModel.h.

◆ ItemData

Item data, each attribute is specified via its int identifier and its variant value.

Definition at line 50 of file mlStandardItemModel.h.

◆ ItemDataVector

Vector of item data.

Definition at line 52 of file mlStandardItemModel.h.

Constructor & Destructor Documentation

◆ StandardItemModel() [1/2]

ml::StandardItemModel::StandardItemModel ( const AttributeVector & attributes,
int hasChildrenAttribute = -1,
bool flat = false )

Create new model with given attributes (and defaults); The second argument gives an attribute that should be used to tell if an item has children.

This is necessary if you want to add children dynamically when requested. If not given no ItemChildrenRequestEvents are emitted and hasChildren maps to getChildCount directly. If the third argument is set to true, this model should be a flat model, i.e. there should be no sub-items. But this is only a hint and is not enforced. This hint is used in views to avoid displaying sub-item indicators.

◆ StandardItemModel() [2/2]

ml::StandardItemModel::StandardItemModel ( )

Create model without attributes.

◆ ~StandardItemModel()

ml::StandardItemModel::~StandardItemModel ( )
override

Member Function Documentation

◆ addItem()

virtual ModelIndex ml::StandardItemModel::addItem ( const ModelIndex & parent,
const ItemData &  )
virtual

◆ clear()

virtual void ml::StandardItemModel::clear ( )
virtual

clear the complete model

◆ getAttributeCount()

int ml::StandardItemModel::getAttributeCount ( ) const
overridevirtual

attribute discovery

Get number of defined attributes for this model. Must be overridden.

Implements ml::AbstractItemModel.

◆ getAttributeDefault()

Variant ml::StandardItemModel::getAttributeDefault ( int index) const
overridevirtual

Return default value of n-th attribute.

This is used to conserve space during serialization of items. This method returns an invalid value by default.

Reimplemented from ml::AbstractItemModel.

◆ getAttributeName()

std::string ml::StandardItemModel::getAttributeName ( int index) const
overridevirtual

Get name of n-th attribute. Must be overridden.

Implements ml::AbstractItemModel.

◆ getChild()

ModelIndex ml::StandardItemModel::getChild ( const ModelIndex & parent,
unsigned int index )
overridevirtual

Get n-th child of an item (or n-th top-level item if parent index is invalid).

Note: Don't call this before calling getChildCount on the parent, since this is the signal for the model that the children must really be provided! Must be overridden.

Implements ml::AbstractItemModel.

◆ getChildCount()

unsigned int ml::StandardItemModel::getChildCount ( const ModelIndex & parent)
overridevirtual

Get number of children of the given item, an invalid index means number of top-level items.

This will be only called if the children are really accessed, so the children might be dynamically created the first time this method is called for an item. Must be overridden.

Implements ml::AbstractItemModel.

◆ getChildPosition()

virtual int ml::StandardItemModel::getChildPosition ( const ModelIndex & child)
virtual

get index position of child relative to its parent

Note: this has to iterate over the children of the parent until the child is found

◆ getData()

Variant ml::StandardItemModel::getData ( const ModelIndex & item,
int attributeIndex )
overridevirtual

data access

Get attribute value of a certain item. Must be overridden.

Implements ml::AbstractItemModel.

◆ getParent()

ModelIndex ml::StandardItemModel::getParent ( const ModelIndex & child)
overridevirtual

Get parent of an item.

Will return invalid index for top-level items. Must be overridden.

Implements ml::AbstractItemModel.

◆ hasChildren()

bool ml::StandardItemModel::hasChildren ( const ModelIndex & parent)
overridevirtual

Or rather mightHaveChildren.

This method tells us if an item has children - at least in principle. This is used to display the item as having children, even if it might turn out that is has none actually. The default for this method is to return true if getChildCount returns a number != 0 or if the model index is invalid.

Reimplemented from ml::AbstractItemModel.

◆ implementsPersistence()

bool ml::StandardItemModel::implementsPersistence ( PersistenceInterface iface) const
inlineoverridevirtual

Persistence interface.

Reimplemented from ml::Base.

Definition at line 106 of file mlStandardItemModel.h.

References mlrange_cast(), and ml::Base::PersistenceByStream.

◆ insertItems()

virtual void ml::StandardItemModel::insertItems ( const ModelIndex & parent,
unsigned int position,
const ItemDataVector & items )
virtual

insert new items; this doesn't generate a insert notification during handling of a ItemChildrenRequestEvent for this very parent - this can be used for dynamically populating the model

◆ isFlat()

bool ml::StandardItemModel::isFlat ( ) const
inlineoverridevirtual

overridden methods

Reimplemented from ml::AbstractItemModel.

Definition at line 73 of file mlStandardItemModel.h.

◆ notifyItemChildrenRequest()

void ml::StandardItemModel::notifyItemChildrenRequest ( const ModelIndex & parent)
protected

◆ rawSetData()

bool ml::StandardItemModel::rawSetData ( const ModelIndex & item,
int attributeIndex,
const Variant & data )
overridevirtual

This will be called by setData and bulkSetData, which will do the necessary notifications afterwards; attributeIndex doesn't need to be checked for valid range, this has already been done when this method is called.

Implements ml::AbstractItemModel.

◆ readFrom()

void ml::StandardItemModel::readFrom ( AbstractPersistenceInputStream * ,
int  )
overridevirtual

Read the objects state from the data stream object.

version is the version number given through ML_PERSISTENCE_VERSION at the time the object was written to the AbstractPersistenceOutStream.

Include mlAbstractPersistenceStream.h for the implementation of this method.

If you are sub-classing from another Base class that implements persistence, use the macro ML_READFROM_SUPER() to load the super-class data, because this takes care of reading and checking the version number of the super class.

Reimplemented from ml::Base.

◆ removeItems()

virtual void ml::StandardItemModel::removeItems ( const ModelIndex & parent,
unsigned int position,
unsigned int numItems )
virtual

remove items

◆ writeTo()

void ml::StandardItemModel::writeTo ( AbstractPersistenceOutputStream * ) const
overridevirtual

Write the objects state to the data stream object.

Include mlAbstractPersistenceStream.h for the implementation of this method.

If you are sub-classing from another Base class that implements persistence, use the macro ML_WRITETO_SUPER() to save the super-class data, because this takes care of writing the version number of the super class.

Reimplemented from ml::Base.


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