KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
AbstractModelItem Class Reference

Base class for items managed by AbstractItemModel. More...

#include <abstractmodelitem.h>

Classes

class  List
 A list of AbstractModelItem pointers with UUID and entity-type search helpers. More...
 

Public Member Functions

 AbstractModelItem ()
 Default constructor — creates an unowned, untyped item.
 
 AbstractModelItem (AbstractItemModel *model)
 Construct an item owned by a model with no metadata.
 
 AbstractModelItem (const EntityMetadata &entityMetadata, AbstractItemModel *model, const QUuid &uuid=QUuid())
 Construct an item with metadata, a model, and an optional UUID.
 
 AbstractModelItem (const EntityMetadata &entityMetadata, const QUuid &uuid, AbstractItemModel *model)
 Construct an item with metadata, a UUID, and a model.
 
virtual ~AbstractModelItem ()
 Destructor — deletes all child items.
 
virtual EntityMetadata entityMetadata () const
 Return the entity metadata for this item.
 
virtual EntityMetadata & entityMetadataRef ()
 Return a mutable reference to the entity metadata.
 
virtual void setEntityMetadata (const EntityMetadata &metadata)
 Set the entity metadata for this item.
 
virtual int entityType () const
 Return the entity type integer from this item's metadata.
 
virtual QUuid uuid () const
 Return the UUID for this item.
 
virtual QIcon icon () const
 Return the icon for this item.
 
virtual QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Return display or decoration data for a model index.
 
virtual void updateFromMetadata (const EntityMetadata &metadata)
 Update this item's data from new entity metadata.
 
virtual void updateFromVariant (int headerType, const QVariant &value)
 Update a single cell from a raw variant value (no-op by default).
 
int row () const
 Return the row index of this item within its parent's children.
 
AbstractModelItemparent () const
 Return this item's parent item, or nullptr if it is a root item.
 
AbstractModelItemchild (int row) const
 Return the child item at the given row.
 
List children () const
 Return the list of child items.
 
ListchildrenRef ()
 Return a mutable reference to the child items list.
 
List siblings () const
 Return the list of sibling items (all children of this item's parent).
 
int childCount (int entityType=0) const
 Return the number of direct children, optionally filtered by entity type.
 
int childCountRecursive (int entityType=0) const
 Return the total number of descendants, optionally filtered by entity type.
 
AbstractModelIteminsertChild (int index, AbstractModelItem *child)
 Insert a child item at the given index.
 
AbstractModelItemappendChild (AbstractModelItem *child)
 Append a child item.
 
void deleteChild (AbstractModelItem *child)
 Delete a specific child item.
 
void deleteAllChildren ()
 Delete and remove all child items.
 
template<typename T >
QList< T > findChildren (bool recursive=false) const
 Find all direct (or recursive) children castable to type T.
 
template<typename T >
firstChild () const
 Return the first direct child castable to type T.
 
AbstractItemModelmodel () const
 Return the model that owns this item.
 

Protected Member Functions

void setIcon (const QIcon &value)
 Set the icon for this item.
 

Detailed Description

Base class for items managed by AbstractItemModel.

Each item holds an EntityMetadata descriptor, a UUID, an optional icon, and references to its parent model, parent item, and child items. Subclass this to attach domain-specific data and override data() to supply display values.

Definition at line 31 of file abstractmodelitem.h.

Constructor & Destructor Documentation

◆ AbstractModelItem() [1/3]

AbstractModelItem::AbstractModelItem ( AbstractItemModel model)

Construct an item owned by a model with no metadata.

Parameters
modelModel that owns this item

◆ AbstractModelItem() [2/3]

AbstractModelItem::AbstractModelItem ( const EntityMetadata &  entityMetadata,
AbstractItemModel model,
const QUuid &  uuid = QUuid() 
)

Construct an item with metadata, a model, and an optional UUID.

Parameters
entityMetadataMetadata describing the entity
modelModel that owns this item
uuidOptional UUID for this item

◆ AbstractModelItem() [3/3]

AbstractModelItem::AbstractModelItem ( const EntityMetadata &  entityMetadata,
const QUuid &  uuid,
AbstractItemModel model 
)

Construct an item with metadata, a UUID, and a model.

Parameters
entityMetadataMetadata describing the entity
uuidUUID for this item
modelModel that owns this item

◆ ~AbstractModelItem()

virtual AbstractModelItem::~AbstractModelItem ( )
inlinevirtual

Destructor — deletes all child items.

Definition at line 60 of file abstractmodelitem.h.

Member Function Documentation

◆ appendChild()

AbstractModelItem * AbstractModelItem::appendChild ( AbstractModelItem child)

Append a child item.

Parameters
childChild item to append
Returns
Pointer to the appended child

◆ child()

AbstractModelItem * AbstractModelItem::child ( int  row) const

Return the child item at the given row.

Parameters
rowRow index
Returns
Child item pointer, or nullptr if row is out of range

◆ childCount()

int AbstractModelItem::childCount ( int  entityType = 0) const

Return the number of direct children, optionally filtered by entity type.

Parameters
entityTypeEntity type filter (0 = count all types)
Returns
Count of matching children

◆ childCountRecursive()

int AbstractModelItem::childCountRecursive ( int  entityType = 0) const

Return the total number of descendants, optionally filtered by entity type.

Parameters
entityTypeEntity type filter (0 = count all types)
Returns
Total count of matching descendants

◆ children()

List AbstractModelItem::children ( ) const
inline

Return the list of child items.

Definition at line 212 of file abstractmodelitem.h.

◆ childrenRef()

List & AbstractModelItem::childrenRef ( )
inline

Return a mutable reference to the child items list.

Definition at line 214 of file abstractmodelitem.h.

◆ data()

virtual QVariant AbstractModelItem::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

Return display or decoration data for a model index.

Parameters
indexModel index being queried
roleQt item data role
Returns
Data for the given role

◆ deleteChild()

void AbstractModelItem::deleteChild ( AbstractModelItem child)

Delete a specific child item.

Parameters
childChild item to remove and delete

◆ entityMetadata()

virtual EntityMetadata AbstractModelItem::entityMetadata ( ) const
inlinevirtual

Return the entity metadata for this item.

Definition at line 66 of file abstractmodelitem.h.

◆ entityMetadataRef()

virtual EntityMetadata & AbstractModelItem::entityMetadataRef ( )
inlinevirtual

Return a mutable reference to the entity metadata.

Definition at line 68 of file abstractmodelitem.h.

◆ entityType()

virtual int AbstractModelItem::entityType ( ) const
inlinevirtual

Return the entity type integer from this item's metadata.

Definition at line 75 of file abstractmodelitem.h.

Referenced by AbstractModelItem::List::firstIndexOfEntityType(), and AbstractModelItem::List::lastIndexOfEntityType().

◆ findChildren()

template<typename T >
QList< T > AbstractModelItem::findChildren ( bool  recursive = false) const
inline

Find all direct (or recursive) children castable to type T.

Template Parameters
TPointer type to find
Parameters
recursiveWhether to recurse into grandchildren (default false)
Returns
List of matching children cast to T

Definition at line 263 of file abstractmodelitem.h.

◆ firstChild()

template<typename T >
T AbstractModelItem::firstChild ( ) const
inline

Return the first direct child castable to type T.

Template Parameters
TPointer type to find
Returns
First matching child cast to T, or nullptr if none

Definition at line 275 of file abstractmodelitem.h.

◆ icon()

virtual QIcon AbstractModelItem::icon ( ) const
inlinevirtual

Return the icon for this item.

Definition at line 79 of file abstractmodelitem.h.

◆ insertChild()

AbstractModelItem * AbstractModelItem::insertChild ( int  index,
AbstractModelItem child 
)

Insert a child item at the given index.

Parameters
indexPosition to insert at
childChild item to insert
Returns
Pointer to the inserted child

◆ model()

AbstractItemModel * AbstractModelItem::model ( ) const
inline

Return the model that owns this item.

Definition at line 289 of file abstractmodelitem.h.

◆ parent()

AbstractModelItem * AbstractModelItem::parent ( ) const
inline

Return this item's parent item, or nullptr if it is a root item.

Definition at line 202 of file abstractmodelitem.h.

◆ row()

int AbstractModelItem::row ( ) const

Return the row index of this item within its parent's children.

Returns
Row index, or 0 if this item has no parent

◆ setEntityMetadata()

virtual void AbstractModelItem::setEntityMetadata ( const EntityMetadata &  metadata)
inlinevirtual

Set the entity metadata for this item.

Parameters
metadataNew metadata

Definition at line 73 of file abstractmodelitem.h.

◆ setIcon()

void AbstractModelItem::setIcon ( const QIcon &  value)
inlineprotected

Set the icon for this item.

Parameters
valueIcon to assign

Definition at line 296 of file abstractmodelitem.h.

◆ updateFromMetadata()

virtual void AbstractModelItem::updateFromMetadata ( const EntityMetadata &  metadata)
virtual

Update this item's data from new entity metadata.

Parameters
metadataNew metadata to apply

◆ updateFromVariant()

virtual void AbstractModelItem::updateFromVariant ( int  headerType,
const QVariant &  value 
)
inlinevirtual

Update a single cell from a raw variant value (no-op by default).

Parameters
headerTypeColumn header type
valueNew cell value

Definition at line 97 of file abstractmodelitem.h.

◆ uuid()

virtual QUuid AbstractModelItem::uuid ( ) const
inlinevirtual

Return the UUID for this item.

Definition at line 77 of file abstractmodelitem.h.

Referenced by AbstractModelItem::List::findByUuid(), and AbstractModelItem::List::indexOfUuid().


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