13#ifndef ML_ABSTRACT_ITEM_MODEL_H
14#define ML_ABSTRACT_ITEM_MODEL_H
34class AbstractItemModel;
55 inline bool isValid()
const {
return _model !=
nullptr; }
58 inline void*
userPtr()
const {
return _userPtr; }
61 inline size_t userID()
const {
return _userID; }
99 virtual bool isFlat()
const {
return false; }
226 const std::vector<int>& attributeIndices,
255 bool after()
const {
return _after; }
272 unsigned int position()
const {
return _position; }
280 ModelIndex _parentIndex;
281 unsigned int _position;
282 unsigned int _itemsInserted;
294 unsigned int position()
const {
return _position; }
302 ModelIndex _parentIndex;
303 unsigned int _position;
304 unsigned int _itemsRemoved;
333 const std::vector<int>& attributeIndices);
335 const std::vector<ModelIndex>&
itemIndices()
const {
return _itemIndices; }
343 std::vector<ModelIndex> _itemIndices;
344 std::vector<int> _attributeIndices;
#define MLITEMMODEL_EXPORT
defined Header file mlItemModelSystem.h
This class represents an abstract hierarchical item model where the items have named attributes which...
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 bool setData(const ModelIndex &item, int attributeIndex, const Variant &data, void *skipListener=nullptr)
Update a single attribute on a single item.
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;...
virtual ModelIndex getParent(const ModelIndex &child)=0
Get parent of an item.
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 notifyItemChanged(const ModelIndex &item, bool after, void *skipListener=nullptr)
change notifications
virtual std::string getAttributeName(int index) const =0
Get name of n-th attribute. Must be overridden.
virtual int getAttributeIndex(const std::string &name)
Get index of attribute with the given name.
virtual void incItemRefCount(void *)
implement this if the pointer in the model indices needs explicit reference counting
virtual int getAttributeCount() const =0
attribute discovery
virtual Variant getAttributeDefault(int index) const
Return default value of n-th attribute.
virtual bool isFlat() const
item traversal interface
virtual Variant getData(const ModelIndex &item, int attributeIndex)=0
data access
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.
ModelIndex createIndex(size_t data)
ModelIndex createIndex(void *data)
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 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 singl...
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.
virtual bool hasChildren(const ModelIndex &parent)
Or rather mightHaveChildren.
virtual void decItemRefCount(void *)
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.
BaseEvent is the base class for all events emitted from EventSourceBase.
This event tells us that the children of the item have changed completely (for an invalid ModelIndex ...
const ModelIndex & index() const
ItemChangedEvent(const ModelIndex &index, bool after)
This intermediate class only exists to conveniently get the source() as the model() from an event.
AbstractItemModel * model() const
This event informs about attributes that have changed their values.
const std::vector< ModelIndex > & itemIndices() const
const std::vector< int > & attributeIndices() const
ItemsDataChangedEvent(const std::vector< ModelIndex > &itemIndices, const std::vector< int > &attributeIndices)
This event informs about inserted items.
unsigned int position() const
unsigned int itemsInserted() const
ItemsInsertedEvent(const ModelIndex &parentIndex, unsigned int position, unsigned int itemsInserted, bool after)
const ModelIndex & parentIndex() const
This event informs about removed items.
const ModelIndex & parentIndex() const
ItemsRemovedEvent(const ModelIndex &parentIndex, unsigned int position, unsigned int itemsInserted, bool after)
unsigned int itemsRemoved() const
unsigned int position() const
This class serves as an index into an AbstractItemModel.
ModelIndex()
The only public constructor creates an "invalid" model index, which represents the virtual/invisible ...
AbstractItemModel * model() const
get the model of this index (this will be NULL for invalid indices)
bool isValid() const
return if this index is valid i.e. it points at an item in the model
size_t userID() const
access the internal user value (same as user pointer)
Variant getData(int attributeIndex) const
convenience method, this calls model()->getData(this, attributeIndex);
void * userPtr() const
access the internal user pointer (same as user value)
ModelIndex(const ModelIndex &other)
RefCountedBase class adds intrusive reference counting support to the Base class.
This is the base class for all events that are sent before and after a change.
TwoPhaseItemModelEvent(bool afterArg=false)
The Variant class stores different data types.
#define ML_ABSTRACT_CLASS_HEADER(className)
Same like ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non existing export symbol.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_REFCOUNTED_PTR(CLASSNAME)
Macro that defines convenience Ptr/ConstPtr typedefs to be used instead of intrusive_ptr templates.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.