MeVisLab Toolbox Reference
ml::AbstractItemModel Class Referenceabstract

This class represents an abstract hierarchical item model where the items have named attributes which can be queried and even modified. More...

#include <mlAbstractItemModel.h>

Inheritance diagram for ml::AbstractItemModel:
ml::RefCountedBase ml::EventSource ml::Base ml::ItemModelProxy ml::StandardItemModel ml::ItemModelAttributeFilter ml::ItemModelItemFilter

Public Member Functions

virtual bool isFlat () const
 item traversal interface More...
 
virtual bool hasChildren (const ModelIndex &parent)
 Or rather mightHaveChildren. More...
 
virtual unsigned int getChildCount (const ModelIndex &parent)=0
 Get number of children of the given item, an invalid index means number of top-level items. More...
 
virtual ModelIndex getChild (const ModelIndex &parent, unsigned int index)=0
 Get n-th child of an item (or n-th top-level item if parent index is invalid). More...
 
virtual ModelIndex getParent (const ModelIndex &child)=0
 Get parent of an item. More...
 
virtual int getAttributeCount () const =0
 attribute discovery More...
 
virtual std::string getAttributeName (int index) const =0
 Get name of n-th attribute. Must be overridden. More...
 
virtual Variant getAttributeDefault (int index) const
 Return default value of n-th attribute. More...
 
virtual int getAttributeIndex (const std::string &name)
 Get index of attribute with the given name. More...
 
virtual Variant getData (const ModelIndex &item, int attributeIndex)=0
 data access More...
 
virtual bool setData (const ModelIndex &item, int attributeIndex, const Variant &data, void *skipListener=nullptr)
 Update a single attribute on a single item. More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from ml::RefCountedBase
 RefCountedBase ()
 Constructor. More...
 
 RefCountedBase (const RefCountedBase &)
 Explicit copy constructor. More...
 
virtual void incRefCount () const
 Increase reference count. More...
 
virtual void decRefCount () const
 Decrease ref count (object will be deleted if ref count is decremented to 0) More...
 
bool isRefCountedBase () const override
 Returns if the instance is derived from RefCountedBase. More...
 
- 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 More...
 
void removeEventListener (BaseEventCallback *cb, void *userData)
 remove event listener callback from this Base object - arguments must be the same as for the addEventListener call More...
 
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 More...
 
- Public Member Functions inherited from ml::Base
 Base ()
 Constructor. More...
 
virtual ~Base ()
 Destructor. More...
 
virtual BasedeepCopy () const
 Set addStateToTree version number that can be accessed via getAddStateVersion() More...
 
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. More...
 
virtual std::string detailString () const
 Return a string describing this object. More...
 
virtual bool implementsPersistence (PersistenceInterface) const
 Override this method to declare which persistence interfaces are implemented by your derived class. More...
 
virtual std::string persistentState () const
 Returns a string describing the object's internal state. More...
 
virtual void setPersistentState (const std::string &state)
 Restores the object's internal state from a string that had been previously generated using persistentState(). More...
 
virtual void addStateToTree (TreeNode *) const
 Attaches the object state as children of the given parent node. More...
 
virtual void readStateFromTree (TreeNode *)
 Reads the object state from the children of the given parent node. More...
 
virtual void writeTo (AbstractPersistenceOutputStream *) const
 Write the objects state to the data stream object. More...
 
virtual void readFrom (AbstractPersistenceInputStream *, int)
 Read the objects state from the data stream object. More...
 

Protected Member Functions

 AbstractItemModel ()
 
virtual bool rawSetData (const ModelIndex &item, int attributeIndex, const Variant &data)=0
 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. More...
 
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 More...
 
virtual void decItemRefCount (void *)
 
virtual void notifyItemChanged (const ModelIndex &item, bool after, void *skipListener=nullptr)
 change notifications More...
 
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. More...
 
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. More...
 
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. More...
 
- Protected Member Functions inherited from ml::RefCountedBase
 ~RefCountedBase () override
 Macro for the declaration of the runtime type system methods, defined in mlRuntimeSubClass.h. More...
 
- 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. More...
 
- Protected Member Functions inherited from ml::Base
virtual char * getPersistentState () const
 Returns a C string describing the object's internal state. More...
 
virtual void setPersistentState (const char *)
 Restores the object's internal state from a string that had been previously generated using getPersistentState(). More...
 
virtual void clearPersistentState (char *) const
 Disposes a string previously allocated by getPersistentState(). More...
 

Friends

class ItemModelProxy
 
class ModelIndex
 

Additional Inherited Members

- Public Types inherited from ml::Base
enum  PersistenceInterface { PersistenceByString , PersistenceByTreeNode , PersistenceByStream }
 This enum describes the different persistence interfaces available. More...
 
- 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. More...
 
- Protected Attributes inherited from ml::RefCountedBase
MLint32 _refCount
 Reference count. More...
 

Detailed Description

This class represents an abstract hierarchical item model where the items have named attributes which can be queried and even modified.

It has a notification system in place to inform about changes to the model. This is loosely modeled after the QAbstractItemModel class from Qt.

Definition at line 90 of file mlAbstractItemModel.h.

Constructor & Destructor Documentation

◆ AbstractItemModel()

ml::AbstractItemModel::AbstractItemModel ( )
inlineprotected

Definition at line 175 of file mlAbstractItemModel.h.

Member Function Documentation

◆ bulkSetData() [1/2]

virtual bool ml::AbstractItemModel::bulkSetData ( const std::vector< ModelIndex > &  items,
int  attributeIndex,
const std::vector< Variant > &  data,
void *  skipListener = nullptr 
)
virtual

This method can be used to update whole columns with varying data.

This will return false if not all changes were accepted. This will call rawSetData.

Reimplemented in ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ bulkSetData() [2/2]

virtual bool ml::AbstractItemModel::bulkSetData ( const std::vector< ModelIndex > &  items,
int  attributeIndex,
const Variant data,
void *  skipListener = nullptr 
)
virtual

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.

This will return false if not all changes were accepted. This will call rawSetData.

Reimplemented in ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ createIndex() [1/2]

ModelIndex ml::AbstractItemModel::createIndex ( size_t  data)
protected

◆ createIndex() [2/2]

ModelIndex ml::AbstractItemModel::createIndex ( void *  data)
protected

create a model index, either with a pointer value or with an integer value Note: this does not call incItemRef

◆ decItemRefCount()

virtual void ml::AbstractItemModel::decItemRefCount ( void *  )
inlineprotectedvirtual

Reimplemented in ml::ItemModelProxy.

Definition at line 191 of file mlAbstractItemModel.h.

◆ getAttributeCount()

virtual int ml::AbstractItemModel::getAttributeCount ( ) const
pure virtual

attribute discovery

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

Implemented in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ getAttributeDefault()

virtual Variant ml::AbstractItemModel::getAttributeDefault ( int  index) const
virtual

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 in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ getAttributeIndex()

virtual int ml::AbstractItemModel::getAttributeIndex ( const std::string &  name)
virtual

Get index of attribute with the given name.

Returns -1 if the attribute name doesn't exist in the model.

Reimplemented in ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ getAttributeName()

virtual std::string ml::AbstractItemModel::getAttributeName ( int  index) const
pure virtual

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

Implemented in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ getChild()

virtual ModelIndex ml::AbstractItemModel::getChild ( const ModelIndex parent,
unsigned int  index 
)
pure virtual

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.

Implemented in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ getChildCount()

virtual unsigned int ml::AbstractItemModel::getChildCount ( const ModelIndex parent)
pure virtual

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.

Implemented in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ getData()

virtual Variant ml::AbstractItemModel::getData ( const ModelIndex item,
int  attributeIndex 
)
pure virtual

data access

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

Implemented in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ getParent()

virtual ModelIndex ml::AbstractItemModel::getParent ( const ModelIndex child)
pure virtual

Get parent of an item.

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

Implemented in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ hasChildren()

virtual bool ml::AbstractItemModel::hasChildren ( const ModelIndex parent)
virtual

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 in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ incItemRefCount()

virtual void ml::AbstractItemModel::incItemRefCount ( void *  )
inlineprotectedvirtual

implement this if the pointer in the model indices needs explicit reference counting

Reimplemented in ml::ItemModelProxy.

Definition at line 190 of file mlAbstractItemModel.h.

◆ isFlat()

virtual bool ml::AbstractItemModel::isFlat ( ) const
inlinevirtual

item traversal interface

Return hint if this model is flat (in contrast to being hierarchical, i.e. if it will have sub-items).

Reimplemented in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

Definition at line 99 of file mlAbstractItemModel.h.

◆ notifyItemChanged()

virtual void ml::AbstractItemModel::notifyItemChanged ( const ModelIndex item,
bool  after,
void *  skipListener = nullptr 
)
protectedvirtual

change notifications

Notify listeners that an items children have completely changed. This must be called once before the changed and once after the change (set second argument accordingly).

If a skipListener is specified, all event listeners with this value for userData are not notified of the change.

◆ notifyItemsDataChanged()

virtual void ml::AbstractItemModel::notifyItemsDataChanged ( const std::vector< ModelIndex > &  items,
const std::vector< int > &  attributeIndices,
void *  skipListener = nullptr 
)
protectedvirtual

Notify listeners that attributes have changed on the given items.

This must be called after the change.

If a skipListener is specified, all event listeners with this value for userData are not notified of the change.

◆ notifyItemsInserted()

virtual void ml::AbstractItemModel::notifyItemsInserted ( const ModelIndex parent,
unsigned int  childIndex,
unsigned int  itemsInserted,
bool  after,
void *  skipListener = nullptr 
)
protectedvirtual

Notify listeners that an item gets/got additional children.

This must be called once before the changed and once after the change (set second argument accordingly).

If a skipListener is specified, all event listeners with this value for userData are not notified of the change.

◆ notifyItemsRemoved()

virtual void ml::AbstractItemModel::notifyItemsRemoved ( const ModelIndex parent,
unsigned int  childIndex,
unsigned int  itemsRemoved,
bool  after,
void *  skipListener = nullptr 
)
protectedvirtual

Notify listeners that an item loses/lost additional children.

This must be called once before the changed and once after the change (set second argument accordingly).

If a skipListener is specified, all event listeners with this value for userData are not notified of the change.

◆ rawSetData()

virtual bool ml::AbstractItemModel::rawSetData ( const ModelIndex item,
int  attributeIndex,
const Variant data 
)
protectedpure virtual

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.

Implemented in ml::StandardItemModel, ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

◆ setData()

virtual bool ml::AbstractItemModel::setData ( const ModelIndex item,
int  attributeIndex,
const Variant data,
void *  skipListener = nullptr 
)
virtual

Update a single attribute on a single item.

This will return false if the change wasn't accepted by the model. skipListener denotes an event listener which should not be notified of this change. This will call rawSetData, which must be overridden

Reimplemented in ml::ItemModelItemFilter, and ml::ItemModelAttributeFilter.

Friends And Related Function Documentation

◆ ItemModelProxy

friend class ItemModelProxy
friend

Definition at line 92 of file mlAbstractItemModel.h.

◆ ModelIndex

friend class ModelIndex
friend

Definition at line 173 of file mlAbstractItemModel.h.


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