MeVisLab Toolbox Reference
|
This could be the interface for a standard item model. More...
#include <mlStandardItemModel.h>
Classes | |
struct | Attribute |
Defines the name of an attribute and its default value. More... | |
Public Types | |
typedef std::vector< Attribute > | AttributeVector |
Vector of attributes. More... | |
typedef boost::unordered_map< int, Variant > | ItemData |
Item data, each attribute is specified via its int identifier and its variant value. More... | |
typedef std::vector< ItemData > | ItemDataVector |
Vector of item data. More... | |
![]() | |
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) | |
Creates new model with given attributes (and defaults). More... | |
StandardItemModel () | |
Creates a model without attributes. More... | |
virtual int | getChildPosition (const ModelIndex &child) |
Returns the index position of child relative to its parent. More... | |
virtual void | clear () |
Clears the entire model. More... | |
virtual void | insertItems (const ModelIndex &parent, unsigned int position, const ItemDataVector &items) |
Inserts new items; this does not generate a insert notification during handling of a ItemChildrenRequestEvent for this very parent. More... | |
virtual ModelIndex | addItem (const ModelIndex &parent, const ItemData &) |
virtual void | removeItems (const ModelIndex &parent, unsigned int position, unsigned int numItems) |
Removes items. More... | |
bool | isFlat () const override |
Overridden methods. More... | |
bool | hasChildren (const ModelIndex &parent) override |
Or rather mightHaveChildren. More... | |
unsigned int | getChildCount (const ModelIndex &parent) override |
Returns the number of children of the given item, an invalid index means number of top-level items. More... | |
ModelIndex | getChild (const ModelIndex &parent, unsigned int index) override |
Returns the n-th child of an item (or n-th top-level item if parent index is invalid). More... | |
ModelIndex | getParent (const ModelIndex &child) override |
Returns the parent of an item. More... | |
int | getAttributeCount () const override |
Attribute discovery. More... | |
std::string | getAttributeName (int index) const override |
Returns the name of n-th attribute. Must be overridden. More... | |
Variant | getAttributeDefault (int index) const override |
Returns the default value of n-th attribute. More... | |
Variant | getData (const ModelIndex &item, int attributeIndex) override |
Data access. More... | |
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 does not need to be checked for valid range, this has already been done when this method is called. More... | |
bool | implementsPersistence (PersistenceInterface iface) const override |
Persistence interface. More... | |
void | writeTo (AbstractPersistenceOutputStream *stream) const override |
Writes the objects state to the data stream object. More... | |
void | readFrom (AbstractPersistenceInputStream *stream, int version) override |
Reads the objects state from the data stream object. More... | |
![]() | |
virtual int | getAttributeIndex (const std::string &name) |
Returns the index of attribute with the given name. More... | |
virtual bool | setData (const ModelIndex &item, int attributeIndex, const Variant &data, void *skipListener=nullptr) |
Updates a single attribute on a single item. More... | |
virtual bool | bulkSetData (const std::vector< ModelIndex > &items, int attributeIndex, const Variant &data, void *skipListener=nullptr) |
This method will be used by views to set selection state to an attribute, so that we only get a single update notification. 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... | |
![]() | |
RefCountedBase () | |
Constructor. More... | |
RefCountedBase (const RefCountedBase &) | |
Explicit copy constructor. More... | |
virtual void | incRefCount () const |
Increases the reference count. More... | |
virtual void | decRefCount () const |
Decreases the reference count (object will be deleted if the reference count is decremented to 0). More... | |
bool | isRefCountedBase () const override |
Returns whether the instance is derived from RefCountedBase. More... | |
![]() | |
EventSource () | |
EventSource (const EventSource &evSource) | |
~EventSource () override | |
void | addEventListener (BaseEventCallback *cb, void *userData) |
Adds event listener callback to this Base object. More... | |
void | removeEventListener (BaseEventCallback *cb, void *userData) |
Removes event listener callback from this Base object. More... | |
bool | hasEventListeners () const |
Checks whether 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... | |
![]() | |
Base () | |
Constructor. More... | |
virtual | ~Base () |
Destructor. More... | |
virtual Base * | deepCopy () const |
Creates a deep copy of the given object. More... | |
bool | isOfAllowedType (const std::vector< const RuntimeType * > &types) const |
Checks whether this object's type is equal to or derived from one of the types given in the argument. More... | |
virtual std::string | detailString () const |
Returns a string describing this object. 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... | |
Protected Member Functions | |
~StandardItemModel () override | |
void | notifyItemChildrenRequest (const ModelIndex &parent) |
![]() | |
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. 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) |
Notifies 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) |
Notifies 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) |
Notifies listeners that attributes have changed on the given items. More... | |
![]() | |
~RefCountedBase () override | |
Macro for the declaration of the runtime type system methods, defined in mlRuntimeSubClass.h. More... | |
![]() | |
void | sendEvent (BaseEvent *event, void *skipListener=nullptr) |
Macro for the declaration of the runtime type system methods, defined in mlRuntimeSubClass.h. More... | |
Additional Inherited Members | |
![]() | |
static void | updateReferenceCountingIfSupported (Base *oldValue, Base *newValue, bool &isRefCountedBase) |
Helper method that handles incrementing/decrementing of the reference count if base instances support it. More... | |
![]() | |
std::atomic_int_least32_t | _refCount |
Reference count. More... | |
This could be the interface for a standard item model.
Definition at line 27 of file mlStandardItemModel.h.
typedef std::vector<Attribute> ml::StandardItemModel::AttributeVector |
Vector of attributes.
Definition at line 47 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 50 of file mlStandardItemModel.h.
typedef std::vector<ItemData> ml::StandardItemModel::ItemDataVector |
Vector of item data.
Definition at line 52 of file mlStandardItemModel.h.
ml::StandardItemModel::StandardItemModel | ( | const AttributeVector & | attributes, |
int | hasChildrenAttribute = -1 , |
||
bool | flat = false |
||
) |
Creates 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 subitems. But this is only a hint and is not enforced. This hint is used in views to avoid displaying subitem indicators.
ml::StandardItemModel::StandardItemModel | ( | ) |
Creates a model without attributes.
|
overrideprotected |
|
virtual |
|
virtual |
Clears the entire model.
|
overridevirtual |
Attribute discovery.
Returns the number of defined attributes for this model. Must be overridden.
Implements ml::AbstractItemModel.
|
overridevirtual |
Returns the 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.
|
overridevirtual |
Returns the name of n-th attribute. Must be overridden.
Implements ml::AbstractItemModel.
|
overridevirtual |
Returns the n-th child of an item (or n-th top-level item if parent index is invalid).
Note: Do not 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.
|
overridevirtual |
Returns the 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.
|
virtual |
Returns the index position of child relative to its parent.
Note: this has to iterate over the children of the parent until the child is found.
|
overridevirtual |
Data access.
Returns the attribute value of a certain item. Must be overridden.
Implements ml::AbstractItemModel.
|
overridevirtual |
Returns the parent of an item.
Will return invalid index for top-level items. Must be overridden.
Implements ml::AbstractItemModel.
|
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.
|
inlineoverridevirtual |
Persistence interface.
Reimplemented from ml::Base.
Definition at line 104 of file mlStandardItemModel.h.
References ml::Base::PersistenceByStream.
|
virtual |
Inserts new items; this does not generate a insert notification during handling of a ItemChildrenRequestEvent for this very parent.
This can be used for dynamically populating the model.
|
inlineoverridevirtual |
Overridden methods.
Reimplemented from ml::AbstractItemModel.
Definition at line 71 of file mlStandardItemModel.h.
|
protected |
|
overridevirtual |
This will be called by setData and bulkSetData, which will do the necessary notifications afterwards; attributeIndex
does not need to be checked for valid range, this has already been done when this method is called.
Implements ml::AbstractItemModel.
|
overridevirtual |
Reads the objects state from the data stream object.
version
is the version number given by 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 subclassing from another Base class that implements persistence, use the macro ML_READFROM_SUPER() to load the superclass data, because this takes care of reading and checking the version number of the superclass.
Reimplemented from ml::Base.
|
virtual |
Removes items.
|
overridevirtual |
Writes the objects state to the data stream object.
Include mlAbstractPersistenceStream.h for the implementation of this method.
If you are subclassing from another Base class that implements persistence, use the macro ML_WRITETO_SUPER() to save the superclass data, because this takes care of writing the version number of the superclass.
Reimplemented from ml::Base.