MeVisLabToolboxReference
|
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>
Public Member Functions | |
virtual bool | isFlat () const |
Return hint if this model is flat (in contrast to being hierarchical, i.e. | |
virtual bool | hasChildren (const ModelIndex &parent) |
Or rather mightHaveChildren. | |
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. | |
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). | |
virtual ModelIndex | getParent (const ModelIndex &child)=0 |
Get parent of an item. | |
virtual int | getAttributeCount () const =0 |
Get number of defined attributes for this model. Must be overriden. | |
virtual std::string | getAttributeName (int index) const =0 |
Get name of n-th attribute. Must be overriden. | |
virtual Variant | getAttributeDefault (int index) const |
Return default value of n-th attribute. | |
virtual int | getAttributeIndex (const std::string &name) |
Get index of attribute with the given name. | |
virtual Variant | getData (const ModelIndex &item, int attributeIndex)=0 |
Get attribute value of a certain item. Must be overriden. | |
virtual bool | setData (const ModelIndex &item, int attributeIndex, const Variant &data, void *skipListener=NULL) |
Update a single attribute on a single item. | |
virtual bool | bulkSetData (const std::vector< ModelIndex > &items, int attributeIndex, const Variant &data, void *skipListener=NULL) |
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=NULL) |
This method can be used to update whole columns with varying data. | |
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. | |
ModelIndex | createIndex (void *data) |
ModelIndex | createIndex (size_t data) |
virtual void | notifyItemChanged (const ModelIndex &item, bool after, void *skipListener=NULL) |
Notify listeners that an items children have completely changed. | |
virtual void | notifyItemsInserted (const ModelIndex &parent, unsigned int childIndex, unsigned int itemsInserted, bool after, void *skipListener=NULL) |
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=NULL) |
Notify listeners that an item loses/lost additional children. | |
virtual void | notifyItemsDataChanged (const std::vector< ModelIndex > &items, const std::vector< int > &attributeIndices, void *skipListener=NULL) |
Notify listeners that attributes have changed on the given items. |
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 78 of file mlAbstractItemModel.h.
ml::AbstractItemModel::AbstractItemModel | ( | ) | [inline, protected] |
Definition at line 159 of file mlAbstractItemModel.h.
virtual bool ml::AbstractItemModel::bulkSetData | ( | const std::vector< ModelIndex > & | items, |
int | attributeIndex, | ||
const Variant & | data, | ||
void * | skipListener = NULL |
||
) | [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.
virtual bool ml::AbstractItemModel::bulkSetData | ( | const std::vector< ModelIndex > & | items, |
int | attributeIndex, | ||
const std::vector< Variant > & | data, | ||
void * | skipListener = NULL |
||
) | [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.
ModelIndex ml::AbstractItemModel::createIndex | ( | size_t | data | ) | [protected] |
ModelIndex ml::AbstractItemModel::createIndex | ( | void * | data | ) | [protected] |
virtual int ml::AbstractItemModel::getAttributeCount | ( | ) | const [pure virtual] |
Get number of defined attributes for this model. Must be overriden.
Implemented in ml::StandardItemModel.
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.
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.
virtual std::string ml::AbstractItemModel::getAttributeName | ( | int | index | ) | const [pure virtual] |
Get name of n-th attribute. Must be overriden.
Implemented in ml::StandardItemModel.
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 overriden.
Implemented in ml::StandardItemModel.
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 overriden.
Implemented in ml::StandardItemModel.
virtual Variant ml::AbstractItemModel::getData | ( | const ModelIndex & | item, |
int | attributeIndex | ||
) | [pure virtual] |
Get attribute value of a certain item. Must be overriden.
Implemented in ml::StandardItemModel.
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 overriden.
Implemented in ml::StandardItemModel.
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.
virtual bool ml::AbstractItemModel::isFlat | ( | ) | const [inline, virtual] |
Return hint if this model is flat (in contrast to being hierarchical, i.e.
if it will have sub-items).
Definition at line 85 of file mlAbstractItemModel.h.
virtual void ml::AbstractItemModel::notifyItemChanged | ( | const ModelIndex & | item, |
bool | after, | ||
void * | skipListener = NULL |
||
) | [protected, virtual] |
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.
virtual void ml::AbstractItemModel::notifyItemsDataChanged | ( | const std::vector< ModelIndex > & | items, |
const std::vector< int > & | attributeIndices, | ||
void * | skipListener = NULL |
||
) | [protected, virtual] |
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.
virtual void ml::AbstractItemModel::notifyItemsInserted | ( | const ModelIndex & | parent, |
unsigned int | childIndex, | ||
unsigned int | itemsInserted, | ||
bool | after, | ||
void * | skipListener = NULL |
||
) | [protected, virtual] |
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.
virtual void ml::AbstractItemModel::notifyItemsRemoved | ( | const ModelIndex & | parent, |
unsigned int | childIndex, | ||
unsigned int | itemsRemoved, | ||
bool | after, | ||
void * | skipListener = NULL |
||
) | [protected, virtual] |
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.
virtual bool ml::AbstractItemModel::rawSetData | ( | const ModelIndex & | item, |
int | attributeIndex, | ||
const Variant & | data | ||
) | [protected, pure 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.
virtual bool ml::AbstractItemModel::setData | ( | const ModelIndex & | item, |
int | attributeIndex, | ||
const Variant & | data, | ||
void * | skipListener = NULL |
||
) | [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 overriden