MeVisLabToolboxReference
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

List of all members.

Classes

struct  Attribute
 Defines the name of an attribute and its default value. More...
class  ItemEntry
 ItemEntry stores the structure and data of the items.

Public Types

typedef std::vector< AttributeAttributeVector
 Vector of attributes.
typedef boost::unordered_map
< int, Variant
ItemData
 Item data, each attribute is specified via its int identifier and its variant value.
typedef std::vector< ItemDataItemDataVector
 Vector of item data.

Public Member Functions

 StandardItemModel (const AttributeVector &attributes, int hasChildrenAttribute=-1)
 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.
virtual ~StandardItemModel ()
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 void removeItems (const ModelIndex &parent, unsigned int position, unsigned int numItems)
 remove items
virtual bool hasChildren (const ModelIndex &parent)
 Or rather mightHaveChildren.
virtual unsigned int getChildCount (const ModelIndex &parent)
 Get number of children of the given item, an invalid index means number of top-level items.
virtual ModelIndex getChild (const ModelIndex &parent, unsigned int index)
 Get n-th child of an item (or n-th top-level item if parent index is invalid).
virtual ModelIndex getParent (const ModelIndex &child)
 Get parent of an item.
virtual int getAttributeCount () const
 Get number of defined attributes for this model. Must be overriden.
virtual std::string getAttributeName (int index) const
 Get name of n-th attribute. Must be overriden.
virtual Variant getAttributeDefault (int index) const
 Return default value of n-th attribute.
virtual Variant getData (const ModelIndex &item, int attributeIndex)
 Get attribute value of a certain item. Must be overriden.
virtual bool rawSetData (const ModelIndex &item, int attributeIndex, const Variant &data)
 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.
virtual bool implementsPersistence (PersistenceInterface iface) const
 Persistence interface.
virtual void writeTo (AbstractPersistenceOutputStream *stream) const
 Write the objects state to the data stream object.
virtual void readFrom (AbstractPersistenceInputStream *stream, int version)
 Read the objects state from the data stream object.

Protected Member Functions

void notifyItemChildrenRequest (const ModelIndex &parent)

Detailed Description

This could be the interface for a standard item model.

Definition at line 22 of file mlStandardItemModel.h.


Member Typedef Documentation

Vector of attributes.

Definition at line 42 of file mlStandardItemModel.h.

typedef boost::unordered_map<int, Variant> ml::StandardItemModel::ItemData

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

Definition at line 45 of file mlStandardItemModel.h.

Vector of item data.

Definition at line 47 of file mlStandardItemModel.h.


Constructor & Destructor Documentation

ml::StandardItemModel::StandardItemModel ( const AttributeVector attributes,
int  hasChildrenAttribute = -1 
)

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.

ml::StandardItemModel::StandardItemModel ( )

Create model without attributes.

virtual ml::StandardItemModel::~StandardItemModel ( ) [virtual]

Member Function Documentation

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

clear the complete model

virtual int ml::StandardItemModel::getAttributeCount ( ) const [virtual]

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

Implements ml::AbstractItemModel.

virtual Variant ml::StandardItemModel::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 from ml::AbstractItemModel.

virtual std::string ml::StandardItemModel::getAttributeName ( int  index) const [virtual]

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

Implements ml::AbstractItemModel.

virtual ModelIndex ml::StandardItemModel::getChild ( const ModelIndex parent,
unsigned int  index 
) [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 overriden.

Implements ml::AbstractItemModel.

virtual unsigned int ml::StandardItemModel::getChildCount ( const ModelIndex parent) [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 overriden.

Implements ml::AbstractItemModel.

virtual Variant ml::StandardItemModel::getData ( const ModelIndex item,
int  attributeIndex 
) [virtual]

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

Implements ml::AbstractItemModel.

virtual ModelIndex ml::StandardItemModel::getParent ( const ModelIndex child) [virtual]

Get parent of an item.

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

Implements ml::AbstractItemModel.

virtual bool ml::StandardItemModel::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 from ml::AbstractItemModel.

virtual bool ml::StandardItemModel::implementsPersistence ( PersistenceInterface  iface) const [inline, virtual]

Persistence interface.

Reimplemented from ml::Base.

Definition at line 89 of file mlStandardItemModel.h.

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

void ml::StandardItemModel::notifyItemChildrenRequest ( const ModelIndex parent) [protected]
virtual bool ml::StandardItemModel::rawSetData ( const ModelIndex item,
int  attributeIndex,
const Variant data 
) [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.

Implements ml::AbstractItemModel.

virtual void ml::StandardItemModel::readFrom ( AbstractPersistenceInputStream ,
int   
) [virtual]

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.

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

remove items

virtual void ml::StandardItemModel::writeTo ( AbstractPersistenceOutputStream ) const [virtual]

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: