Qt Utilities
5.10.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
|
The ChecklistModel class provides a generic model for storing checkable items. More...
#include <checklistmodel.h>
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... | |
The ChecklistModel class provides a generic model for storing checkable items.
Definition at line 72 of file checklistmodel.h.
|
explicit |
Constructs a new checklist model.
Definition at line 27 of file checklistmodel.cpp.
QVariant Models::ChecklistModel::data | ( | const QModelIndex & | index, |
int | role = Qt::DisplayRole |
||
) | const |
Definition at line 48 of file checklistmodel.cpp.
Qt::ItemFlags Models::ChecklistModel::flags | ( | const QModelIndex & | index | ) | const |
Definition at line 40 of file checklistmodel.cpp.
|
static |
Returns the role used to get or set the item ID.
Definition at line 108 of file checklistmodel.h.
bool Models::ChecklistModel::insertRows | ( | int | row, |
int | count, | ||
const QModelIndex & | parent | ||
) |
Definition at line 137 of file checklistmodel.cpp.
QMap< int, QVariant > Models::ChecklistModel::itemData | ( | const QModelIndex & | index | ) | const |
Definition at line 64 of file checklistmodel.cpp.
|
inline |
Returns the items.
Definition at line 100 of file checklistmodel.h.
|
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 127 of file checklistmodel.cpp.
bool Models::ChecklistModel::removeRows | ( | int | row, |
int | count, | ||
const QModelIndex & | parent | ||
) |
Definition at line 150 of file checklistmodel.cpp.
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 183 of file checklistmodel.cpp.
int Models::ChecklistModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const |
Definition at line 32 of file checklistmodel.cpp.
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 216 of file checklistmodel.cpp.
bool Models::ChecklistModel::setData | ( | const QModelIndex & | index, |
const QVariant & | value, | ||
int | role = Qt::DisplayRole |
||
) |
Definition at line 73 of file checklistmodel.cpp.
bool Models::ChecklistModel::setItemData | ( | const QModelIndex & | index, |
const QMap< int, QVariant > & | roles | ||
) |
Definition at line 109 of file checklistmodel.cpp.
void Models::ChecklistModel::setItems | ( | const QList< ChecklistItem > & | items | ) |
Qt::DropActions Models::ChecklistModel::supportedDropActions | ( | ) | const |
Definition at line 132 of file checklistmodel.cpp.