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

Extended QAbstractItemModel providing EntityMetadata-based item lookup and header management. More...

#include <abstractitemmodel.h>

+ Inheritance diagram for AbstractItemModel:
+ Collaboration diagram for AbstractItemModel:

Public Slots

virtual void clear ()
 Remove all root items from the model.
 
virtual void addEntity (const EntityMetadata &metadata)
 Handle an entity-added event (no-op by default).
 
virtual void deleteEntity (const EntityMetadata &metadata)
 Handle an entity-deleted event (no-op by default).
 
virtual void updateEntity (const EntityMetadata &metadata)
 Handle an entity-updated event (no-op by default).
 

Signals

void entityAdded (const EntityMetadata &metadata)
 Emitted after an entity is added to the model.
 
void entityDeleted (const EntityMetadata &metadata)
 Emitted after an entity is deleted from the model.
 
void entityUpdated (const EntityMetadata &metadata)
 Emitted after an entity in the model is updated.
 

Public Member Functions

 AbstractItemModel (QObject *parent=nullptr)
 Construct with an optional parent.
 
 AbstractItemModel (const QString &loggingCategory, QObject *parent=nullptr)
 Construct with a logging category and optional parent.
 
virtual ~AbstractItemModel ()
 Destructor — deletes all root items.
 
virtual QModelIndexList indexesOfEntityType (int type) const
 Return all indexes whose item has the given entity type.
 
virtual QModelIndexList indexesOfEntity (int type, const QVariant &data, int role=Qt::DisplayRole) const
 Return all indexes matching entity type and a role value.
 
virtual QModelIndexList indexesOfEntityUuid (const QUuid &uuid) const
 Return all indexes whose item UUID matches.
 
virtual QModelIndex firstIndexOfEntityType (int type) const
 Return the first index whose item has the given entity type.
 
virtual QModelIndex firstIndexOfEntity (int type, const QVariant &data, int role=Qt::DisplayRole) const
 Return the first index matching entity type and a role value.
 
virtual QModelIndex firstIndexOfEntityUuid (const QUuid &uuid) const
 Return the first index whose item UUID matches.
 
virtual QModelIndex firstIndexOfChildEntityType (const QModelIndex &parent, int type, bool recursive=true) const
 Return the first child index under parent with the given entity type.
 
virtual QModelIndex firstIndexOfChildEntityUuid (const QModelIndex &parent, const QUuid &uuid, bool recursive=true) const
 Return the first child index under parent whose UUID matches.
 
virtual QModelIndex firstMatch (const QModelIndex &startSearchIndex, int role, const QVariant &value, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Return the first match starting from startSearchIndex.
 
virtual QModelIndex firstMatch (int role, const QVariant &value, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Return the first match anywhere in the model.
 
virtual QModelIndexList childIndexes (const QModelIndex &parent, int type=-1, bool recursive=true) const
 Return child indexes under parent, optionally filtered by entity type.
 
TableHeader::List columnHeaders () const
 Return all column headers as a sorted list.
 
TableHeader columnHeader (int section) const
 Return the column header for a given section.
 
TableHeader rowHeader (int row) const
 Return the row header for a given row.
 
int columnForHeader (int type) const
 Return the column index for a header type.
 
QModelIndexList getPersistentIndexes () const
 Return all persistent model indexes.
 
virtual void refresh (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 Emit dataChanged for the rectangular region from topLeft to bottomRight.
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 Return the model index for the item at row/column under parent.
 
virtual QModelIndex parent (const QModelIndex &child) const override
 Return the parent index of a child index.
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const override
 Return the number of rows under parent.
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const override
 Return the number of columns under parent.
 
virtual QVariant data (const QModelIndex &index, int role) const override
 Return the data for the given index and role.
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 Return header data for the given section, orientation, and role.
 
virtual bool removeRows (int row, int count, const QModelIndex &parentIndex) override
 Remove count rows starting at row under parentIndex.
 
virtual bool hasChildren (const QModelIndex &parent) const override
 Return true if parent has child items.
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role) override
 Set header data for the given section, orientation, and role.
 
void setColumnHeaderVisible (int type, bool visible)
 Show or hide the column whose header has the given type.
 

Static Public Member Functions

static QString indexToString (const QModelIndex &index, bool includeText=false)
 Format a QModelIndex as a debug string.
 
static QString toString (const QModelIndex &index, bool includeText=false)
 Format a QModelIndex as a debug string (static alias).
 

Protected Member Functions

AbstractModelItem::List rootItems () const
 Return the list of root items.
 
AbstractModelItem::ListrootItemsRef ()
 Return a mutable reference to the root items list.
 
const AbstractModelItem::List rootItemsConst () const
 Return a const copy of the root items list.
 
int rootItemCount () const
 Return the number of root items.
 
AbstractModelIteminsertRootItem (int row, AbstractModelItem *item)
 Insert an item at the given row among root items.
 
AbstractModelItemappendRootItem (AbstractModelItem *item)
 Append an item to the root items list.
 
void appendRootItems (QList< AbstractModelItem * > items)
 Append multiple items to the root items list.
 
void appendColumnHeader (int type, const QString &text)
 Append a column header with the given type and display text.
 
void appendColumnHeader (int type, const QColor &columnTextColor, const QString &text)
 Append a column header with a custom text color.
 
void insertColumnHeader (int type, int index, const QString &text)
 Insert a column header at the given index.
 
void appendAdHocColumnHeader (int type, const QString &value)
 Append a column header (ad-hoc alias for appendColumnHeader).
 
void insertAdHocColumnHeader (int type, int index, const QString &value)
 Insert a column header at the given index (ad-hoc alias for insertColumnHeader).
 
void deleteColumnHeader (int section)
 Delete the column header at the given section.
 
void appendRowHeader (int type, const QString &value=QString())
 Append a row header with optional display text.
 
void appendAdHocRowHeader (int type, const QString &value)
 Append a row header (ad-hoc alias for appendRowHeader).
 
void setColumnHeaderText (int section, const QString &text)
 Change the display text of a column header.
 
void setColumnHeaderEntityMetadata (int type, const EntityMetadata &metadata)
 Associate an EntityMetadata with a column header type.
 
EntityMetadata columnEntityMetadata (int type) const
 Retrieve the EntityMetadata for a column header type.
 
void setColumnTextColor (int type, const QColor &color)
 Set the text color for all cells in the column of the given type.
 
void deleteRootItem (AbstractModelItem *item)
 Delete a root item from the model.
 
void deleteRootItems (const QUuid &uuid)
 Delete all root items with the given UUID.
 
void deleteRootItems (const EntityMetadata &metadata)
 Delete all root items matching the given EntityMetadata.
 
void deleteItem (const QUuid &uuid)
 Delete any item (at any level) with the given UUID.
 
void updateItemAtIndex (const QModelIndex &itemIndex, const EntityMetadata &metadata)
 Update the item at itemIndex with new metadata and emit dataChanged.
 
void updateItemsAtIndexes (const QModelIndexList &indexes, const EntityMetadata &metadata)
 Update items at multiple indexes with new metadata.
 
void refreshAll ()
 Emit dataChanged for the entire model.
 
template<typename T >
QList< T > findItems () const
 Find all items of type T in the model (root and their children).
 
QModelIndex findFirstDirectChild (const QModelIndex &parentIndex, const QVariant &value, int role) const
 Find the first direct child of parentIndex matching a role/value pair.
 
TableHeader::IntMap columnHeadersIntMap () const
 Return the column headers as an int-keyed map.
 
TableHeader::IntMap rowHeadersIntMap () const
 Return the row headers as an int-keyed map.
 
void emitRowChanged (const QModelIndex &rowIndex)
 Emit dataChanged for all columns of the given row index.
 

Friends

class AbstractModelItem
 

Detailed Description

Extended QAbstractItemModel providing EntityMetadata-based item lookup and header management.

Subclass this together with AbstractModelItem to build tree, table, or list models. Column and row headers are managed internally; entity lookup helpers search by type or UUID.

Definition at line 32 of file abstractitemmodel.h.

Constructor & Destructor Documentation

◆ AbstractItemModel()

AbstractItemModel::AbstractItemModel ( const QString &  loggingCategory,
QObject *  parent = nullptr 
)

Construct with a logging category and optional parent.

Parameters
loggingCategoryCategory name used for log output
parentOptional QObject parent

◆ ~AbstractItemModel()

virtual AbstractItemModel::~AbstractItemModel ( )
inlinevirtual

Destructor — deletes all root items.

Definition at line 48 of file abstractitemmodel.h.

Member Function Documentation

◆ addEntity

virtual void AbstractItemModel::addEntity ( const EntityMetadata &  metadata)
inlinevirtualslot

Handle an entity-added event (no-op by default).

Definition at line 439 of file abstractitemmodel.h.

◆ appendAdHocColumnHeader()

void AbstractItemModel::appendAdHocColumnHeader ( int  type,
const QString &  value 
)
inlineprotected

Append a column header (ad-hoc alias for appendColumnHeader).

Definition at line 278 of file abstractitemmodel.h.

◆ appendAdHocRowHeader()

void AbstractItemModel::appendAdHocRowHeader ( int  type,
const QString &  value 
)
inlineprotected

Append a row header (ad-hoc alias for appendRowHeader).

Definition at line 297 of file abstractitemmodel.h.

◆ appendColumnHeader() [1/2]

void AbstractItemModel::appendColumnHeader ( int  type,
const QColor &  columnTextColor,
const QString &  text 
)
protected

Append a column header with a custom text color.

Parameters
typeColumn type identifier
columnTextColorText color for cells in this column
textHeader display text

◆ appendColumnHeader() [2/2]

void AbstractItemModel::appendColumnHeader ( int  type,
const QString &  text 
)
protected

Append a column header with the given type and display text.

Parameters
typeColumn type identifier
textHeader display text

◆ appendRootItem()

AbstractModelItem * AbstractItemModel::appendRootItem ( AbstractModelItem item)
protected

Append an item to the root items list.

Parameters
itemItem to append
Returns
Pointer to the appended item

◆ appendRootItems()

void AbstractItemModel::appendRootItems ( QList< AbstractModelItem * >  items)
protected

Append multiple items to the root items list.

Parameters
itemsItems to append

◆ appendRowHeader()

void AbstractItemModel::appendRowHeader ( int  type,
const QString &  value = QString() 
)
protected

Append a row header with optional display text.

Parameters
typeRow type identifier
valueOptional display text

◆ childIndexes()

virtual QModelIndexList AbstractItemModel::childIndexes ( const QModelIndex &  parent,
int  type = -1,
bool  recursive = true 
) const
virtual

Return child indexes under parent, optionally filtered by entity type.

Parameters
parentParent index
typeEntity type filter (-1 to return all types)
recursiveWhether to search recursively (default true)
Returns
List of matching child indexes

◆ columnCount()

virtual int AbstractItemModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
overridevirtual

Return the number of columns under parent.

Reimplemented in AbstractTableModel.

◆ columnEntityMetadata()

EntityMetadata AbstractItemModel::columnEntityMetadata ( int  type) const
protected

Retrieve the EntityMetadata for a column header type.

Parameters
typeColumn type identifier
Returns
Associated EntityMetadata

◆ columnForHeader()

int AbstractItemModel::columnForHeader ( int  type) const

Return the column index for a header type.

Parameters
typeHeader type identifier
Returns
Column index, or -1 if not found

◆ columnHeader()

TableHeader AbstractItemModel::columnHeader ( int  section) const
inline

Return the column header for a given section.

Parameters
sectionColumn section index
Returns
TableHeader for that section

Definition at line 156 of file abstractitemmodel.h.

◆ columnHeaders()

TableHeader::List AbstractItemModel::columnHeaders ( ) const

Return all column headers as a sorted list.

Returns
List of TableHeader objects ordered by column index

◆ columnHeadersIntMap()

TableHeader::IntMap AbstractItemModel::columnHeadersIntMap ( ) const
inlineprotected

Return the column headers as an int-keyed map.

Definition at line 397 of file abstractitemmodel.h.

◆ data()

virtual QVariant AbstractItemModel::data ( const QModelIndex &  index,
int  role 
) const
overridevirtual

Return the data for the given index and role.

Reimplemented in AbstractListModel, and AbstractTableModel.

◆ deleteColumnHeader()

void AbstractItemModel::deleteColumnHeader ( int  section)
protected

Delete the column header at the given section.

Parameters
sectionSection index to remove

◆ deleteEntity

virtual void AbstractItemModel::deleteEntity ( const EntityMetadata &  metadata)
inlinevirtualslot

Handle an entity-deleted event (no-op by default).

Definition at line 441 of file abstractitemmodel.h.

◆ deleteItem()

void AbstractItemModel::deleteItem ( const QUuid &  uuid)
protected

Delete any item (at any level) with the given UUID.

Parameters
uuidUUID to match

◆ deleteRootItem()

void AbstractItemModel::deleteRootItem ( AbstractModelItem item)
protected

Delete a root item from the model.

Parameters
itemRoot item to delete

◆ deleteRootItems() [1/2]

void AbstractItemModel::deleteRootItems ( const EntityMetadata &  metadata)
protected

Delete all root items matching the given EntityMetadata.

Parameters
metadataMetadata to match

◆ deleteRootItems() [2/2]

void AbstractItemModel::deleteRootItems ( const QUuid &  uuid)
protected

Delete all root items with the given UUID.

Parameters
uuidUUID to match

◆ emitRowChanged()

void AbstractItemModel::emitRowChanged ( const QModelIndex &  rowIndex)
protected

Emit dataChanged for all columns of the given row index.

Parameters
rowIndexRow index whose data changed

◆ findFirstDirectChild()

QModelIndex AbstractItemModel::findFirstDirectChild ( const QModelIndex &  parentIndex,
const QVariant &  value,
int  role 
) const
protected

Find the first direct child of parentIndex matching a role/value pair.

Parameters
parentIndexParent index to search under
valueValue to match
roleRole to compare
Returns
First matching child index, or invalid index

◆ findItems()

template<typename T >
QList< T > AbstractItemModel::findItems ( ) const
inlineprotected

Find all items of type T in the model (root and their children).

Template Parameters
TPointer type of items to find (must derive from AbstractModelItem)
Returns
List of matching items cast to T

Definition at line 374 of file abstractitemmodel.h.

◆ firstIndexOfChildEntityType()

virtual QModelIndex AbstractItemModel::firstIndexOfChildEntityType ( const QModelIndex &  parent,
int  type,
bool  recursive = true 
) const
virtual

Return the first child index under parent with the given entity type.

Parameters
parentParent index to search under
typeEntity type to search for
recursiveWhether to search recursively (default true)
Returns
First matching child index, or invalid index if not found

◆ firstIndexOfChildEntityUuid()

virtual QModelIndex AbstractItemModel::firstIndexOfChildEntityUuid ( const QModelIndex &  parent,
const QUuid &  uuid,
bool  recursive = true 
) const
virtual

Return the first child index under parent whose UUID matches.

Parameters
parentParent index to search under
uuidUUID to search for
recursiveWhether to search recursively (default true)
Returns
First matching child index, or invalid index if not found

◆ firstIndexOfEntity()

virtual QModelIndex AbstractItemModel::firstIndexOfEntity ( int  type,
const QVariant &  data,
int  role = Qt::DisplayRole 
) const
virtual

Return the first index matching entity type and a role value.

Parameters
typeEntity type to search for
dataValue to match against the given role
roleModel role to compare (default Qt::DisplayRole)
Returns
First matching index, or invalid index if not found

◆ firstIndexOfEntityType()

virtual QModelIndex AbstractItemModel::firstIndexOfEntityType ( int  type) const
virtual

Return the first index whose item has the given entity type.

Parameters
typeEntity type to search for
Returns
First matching index, or invalid index if not found

◆ firstIndexOfEntityUuid()

virtual QModelIndex AbstractItemModel::firstIndexOfEntityUuid ( const QUuid &  uuid) const
virtual

Return the first index whose item UUID matches.

Parameters
uuidUUID to search for
Returns
First matching index, or invalid index if not found

◆ firstMatch() [1/2]

virtual QModelIndex AbstractItemModel::firstMatch ( const QModelIndex &  startSearchIndex,
int  role,
const QVariant &  value,
Qt::MatchFlags  flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap) 
) const
virtual

Return the first match starting from startSearchIndex.

Parameters
startSearchIndexIndex to begin searching from
roleModel role to compare
valueValue to match
flagsMatch flags
Returns
First matching index, or invalid index if not found

◆ firstMatch() [2/2]

virtual QModelIndex AbstractItemModel::firstMatch ( int  role,
const QVariant &  value,
Qt::MatchFlags  flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap) 
) const
virtual

Return the first match anywhere in the model.

Parameters
roleModel role to compare
valueValue to match
flagsMatch flags
Returns
First matching index, or invalid index if not found

◆ getPersistentIndexes()

QModelIndexList AbstractItemModel::getPersistentIndexes ( ) const

Return all persistent model indexes.

Returns
List of persistent indexes currently held by the model

◆ indexesOfEntity()

virtual QModelIndexList AbstractItemModel::indexesOfEntity ( int  type,
const QVariant &  data,
int  role = Qt::DisplayRole 
) const
virtual

Return all indexes matching entity type and a role value.

Parameters
typeEntity type to search for
dataValue to match against the given role
roleModel role to compare (default Qt::DisplayRole)
Returns
List of matching model indexes

◆ indexesOfEntityType()

virtual QModelIndexList AbstractItemModel::indexesOfEntityType ( int  type) const
virtual

Return all indexes whose item has the given entity type.

Parameters
typeEntity type to search for
Returns
List of matching model indexes

◆ indexesOfEntityUuid()

virtual QModelIndexList AbstractItemModel::indexesOfEntityUuid ( const QUuid &  uuid) const
virtual

Return all indexes whose item UUID matches.

Parameters
uuidUUID to search for
Returns
List of matching model indexes

◆ indexToString()

static QString AbstractItemModel::indexToString ( const QModelIndex &  index,
bool  includeText = false 
)
static

Format a QModelIndex as a debug string.

Parameters
indexIndex to format
includeTextWhether to include display text (default false)
Returns
Human-readable string describing the index

◆ insertAdHocColumnHeader()

void AbstractItemModel::insertAdHocColumnHeader ( int  type,
int  index,
const QString &  value 
)
inlineprotected

Insert a column header at the given index (ad-hoc alias for insertColumnHeader).

Definition at line 281 of file abstractitemmodel.h.

◆ insertColumnHeader()

void AbstractItemModel::insertColumnHeader ( int  type,
int  index,
const QString &  text 
)
protected

Insert a column header at the given index.

Parameters
typeColumn type identifier
indexPosition to insert at
textHeader display text

◆ insertRootItem()

AbstractModelItem * AbstractItemModel::insertRootItem ( int  row,
AbstractModelItem item 
)
protected

Insert an item at the given row among root items.

Parameters
rowInsertion row index
itemItem to insert
Returns
Pointer to the inserted item

◆ refresh()

virtual void AbstractItemModel::refresh ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight 
)
virtual

Emit dataChanged for the rectangular region from topLeft to bottomRight.

Parameters
topLeftTop-left corner of the changed region
bottomRightBottom-right corner of the changed region

◆ rootItemCount()

int AbstractItemModel::rootItemCount ( ) const
inlineprotected

Return the number of root items.

Definition at line 231 of file abstractitemmodel.h.

◆ rootItems()

AbstractModelItem::List AbstractItemModel::rootItems ( ) const
inlineprotected

Return the list of root items.

Definition at line 225 of file abstractitemmodel.h.

◆ rootItemsConst()

const AbstractModelItem::List AbstractItemModel::rootItemsConst ( ) const
inlineprotected

Return a const copy of the root items list.

Definition at line 229 of file abstractitemmodel.h.

◆ rootItemsRef()

AbstractModelItem::List & AbstractItemModel::rootItemsRef ( )
inlineprotected

Return a mutable reference to the root items list.

Definition at line 227 of file abstractitemmodel.h.

◆ rowHeader()

TableHeader AbstractItemModel::rowHeader ( int  row) const
inline

Return the row header for a given row.

Parameters
rowRow index
Returns
TableHeader for that row

Definition at line 163 of file abstractitemmodel.h.

◆ rowHeadersIntMap()

TableHeader::IntMap AbstractItemModel::rowHeadersIntMap ( ) const
inlineprotected

Return the row headers as an int-keyed map.

Definition at line 399 of file abstractitemmodel.h.

◆ setColumnHeaderEntityMetadata()

void AbstractItemModel::setColumnHeaderEntityMetadata ( int  type,
const EntityMetadata &  metadata 
)
protected

Associate an EntityMetadata with a column header type.

Parameters
typeColumn type identifier
metadataMetadata to associate

◆ setColumnHeaderText()

void AbstractItemModel::setColumnHeaderText ( int  section,
const QString &  text 
)
protected

Change the display text of a column header.

Parameters
sectionSection index to update
textNew display text

◆ setColumnHeaderVisible()

void AbstractItemModel::setColumnHeaderVisible ( int  type,
bool  visible 
)

Show or hide the column whose header has the given type.

Parameters
typeColumn header type identifier
visibleWhether to make the column visible

◆ setColumnTextColor()

void AbstractItemModel::setColumnTextColor ( int  type,
const QColor &  color 
)
protected

Set the text color for all cells in the column of the given type.

Parameters
typeColumn type identifier
colorText color to apply

◆ toString()

static QString AbstractItemModel::toString ( const QModelIndex &  index,
bool  includeText = false 
)
static

Format a QModelIndex as a debug string (static alias).

Parameters
indexIndex to format
includeTextWhether to include display text
Returns
Human-readable string

◆ updateEntity

virtual void AbstractItemModel::updateEntity ( const EntityMetadata &  metadata)
inlinevirtualslot

Handle an entity-updated event (no-op by default).

Definition at line 443 of file abstractitemmodel.h.

◆ updateItemAtIndex()

void AbstractItemModel::updateItemAtIndex ( const QModelIndex &  itemIndex,
const EntityMetadata &  metadata 
)
protected

Update the item at itemIndex with new metadata and emit dataChanged.

Parameters
itemIndexIndex of the item to update
metadataNew metadata to apply

◆ updateItemsAtIndexes()

void AbstractItemModel::updateItemsAtIndexes ( const QModelIndexList &  indexes,
const EntityMetadata &  metadata 
)
protected

Update items at multiple indexes with new metadata.

Parameters
indexesIndexes of items to update
metadataNew metadata to apply

Friends And Related Symbol Documentation

◆ AbstractModelItem

friend class AbstractModelItem
friend

Definition at line 425 of file abstractitemmodel.h.


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