Qt Utilities  5.6.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Public Member Functions | Static Public Member Functions | List of all members
Models::ChecklistModel Class Reference

The ChecklistModel class provides a generic model for storing checkable items. More...

#include <checklistmodel.h>

Inheritance diagram for Models::ChecklistModel:
[legend]
Collaboration diagram for Models::ChecklistModel:
[legend]

Public Member Functions

 ChecklistModel (QObject *parent=nullptr)
 Constructs a new checklist model. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
Qt::ItemFlags flags (const QModelIndex &index) const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
QMap< int, QVariant > itemData (const QModelIndex &index) const
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
 
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 
virtual QString labelForId (const QVariant &id) const
 Returns the label for the specified id. More...
 
Qt::DropActions supportedDropActions () const
 
bool insertRows (int row, int count, const QModelIndex &parent)
 
bool removeRows (int row, int count, const QModelIndex &parent)
 
const QList< ChecklistItem > & items () const
 Returns the items. More...
 
void setItems (const QList< ChecklistItem > &items)
 Sets the items. More...
 
void restore (QSettings &settings, const QString &name)
 Restores the IDs and checkstates read from the specified settings object. More...
 
void save (QSettings &settings, const QString &name) const
 Saves the IDs and checkstates to the specified settings object. More...
 

Static Public Member Functions

static constexpr int idRole ()
 Returns the role used to get or set the item ID. More...
 

Detailed Description

The ChecklistModel class provides a generic model for storing checkable items.

Definition at line 72 of file checklistmodel.h.

Constructor & Destructor Documentation

◆ ChecklistModel()

Models::ChecklistModel::ChecklistModel ( QObject *  parent = nullptr)
explicit

Constructs a new checklist model.

Definition at line 25 of file checklistmodel.cpp.

Member Function Documentation

◆ data()

QVariant Models::ChecklistModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const

Definition at line 45 of file checklistmodel.cpp.

◆ flags()

Qt::ItemFlags Models::ChecklistModel::flags ( const QModelIndex &  index) const

Definition at line 37 of file checklistmodel.cpp.

◆ idRole()

constexpr int Models::ChecklistModel::idRole ( )
inlinestatic

Returns the role used to get or set the item ID.

Definition at line 110 of file checklistmodel.h.

◆ insertRows()

bool Models::ChecklistModel::insertRows ( int  row,
int  count,
const QModelIndex &  parent 
)

Definition at line 135 of file checklistmodel.cpp.

◆ itemData()

QMap< int, QVariant > Models::ChecklistModel::itemData ( const QModelIndex &  index) const

Definition at line 62 of file checklistmodel.cpp.

◆ items()

const QList< ChecklistItem > & Models::ChecklistModel::items ( ) const
inline

Returns the items.

Definition at line 102 of file checklistmodel.h.

◆ labelForId()

QString Models::ChecklistModel::labelForId ( const QVariant &  id) const
virtual

Returns the label for the specified id.

This method might be reimplemented when subclassing to provide labels for the item IDs.

If an item's ID is set (using setData() and idRole()) this method is called to update the item's label as well. If this method returns an empty string (default behaviour) the item's label will not be updated.

Definition at line 125 of file checklistmodel.cpp.

◆ removeRows()

bool Models::ChecklistModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent 
)

Definition at line 148 of file checklistmodel.cpp.

◆ restore()

void Models::ChecklistModel::restore ( QSettings &  settings,
const QString &  name 
)

Restores the IDs and checkstates read from the specified settings object.

The items will be read from the array with the specified name.

Resets the model (current items are cleared).

Does not restore any labels. Labels are meant to be restored from the ID.

Definition at line 180 of file checklistmodel.cpp.

◆ rowCount()

int Models::ChecklistModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 29 of file checklistmodel.cpp.

◆ save()

void Models::ChecklistModel::save ( QSettings &  settings,
const QString &  name 
) const

Saves the IDs and checkstates to the specified settings object.

The items will be stored using an array with the specified name.

Does not save any labels.

Definition at line 213 of file checklistmodel.cpp.

◆ setData()

bool Models::ChecklistModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::DisplayRole 
)

Definition at line 71 of file checklistmodel.cpp.

◆ setItemData()

bool Models::ChecklistModel::setItemData ( const QModelIndex &  index,
const QMap< int, QVariant > &  roles 
)

Definition at line 107 of file checklistmodel.cpp.

◆ setItems()

void Models::ChecklistModel::setItems ( const QList< ChecklistItem > &  items)

Sets the items.

Resets the model.

Definition at line 164 of file checklistmodel.cpp.

◆ supportedDropActions()

Qt::DropActions Models::ChecklistModel::supportedDropActions ( ) const

Definition at line 130 of file checklistmodel.cpp.


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