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

AbstractItemModel specialization for flat list models. More...

#include <abstractlistmodel.h>

+ Inheritance diagram for AbstractListModel:
+ Collaboration diagram for AbstractListModel:

Public Member Functions

 AbstractListModel (QObject *parent=nullptr)
 Construct with an optional parent.
 
 AbstractListModel (const QString &loggingCategory, QObject *parent=nullptr)
 Construct with a logging category and optional parent.
 
void deleteRowAtIndex (const QModelIndex &index)
 Remove the row at the given index from the model.
 
- Public Member Functions inherited from AbstractItemModel
 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 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.
 

Protected Member Functions

virtual QVariant data (const QModelIndex &index, int role) const override
 Return the data for the given index and role.
 
- Protected Member Functions inherited from AbstractItemModel
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.
 

Additional Inherited Members

- Public Slots inherited from AbstractItemModel
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 inherited from AbstractItemModel
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.
 
- Static Public Member Functions inherited from AbstractItemModel
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).
 

Detailed Description

AbstractItemModel specialization for flat list models.

Provides a data() override suitable for list views and adds a convenience method for deleting the item at a given index.

Definition at line 11 of file abstractlistmodel.h.

Constructor & Destructor Documentation

◆ AbstractListModel()

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

Construct with a logging category and optional parent.

Parameters
loggingCategoryCategory name used for log output
parentOptional QObject parent

Member Function Documentation

◆ data()

virtual QVariant AbstractListModel::data ( const QModelIndex &  index,
int  role 
) const
overrideprotectedvirtual

Return the data for the given index and role.

Reimplemented from AbstractItemModel.

◆ deleteRowAtIndex()

void AbstractListModel::deleteRowAtIndex ( const QModelIndex &  index)

Remove the row at the given index from the model.

Parameters
indexModel index of the row to delete

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