Qt Utilities 6.14.3
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
|
#include <checklistmodel.h>
Public Member Functions | |
ChecklistModel (QObject *parent=nullptr) | |
Constructs a new checklist model. | |
int | rowCount (const QModelIndex &parent=QModelIndex()) const override |
Qt::ItemFlags | flags (const QModelIndex &index) const override |
QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const override |
QMap< int, QVariant > | itemData (const QModelIndex &index) const override |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole) override |
bool | setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) override |
bool | setChecked (int row, bool checked) |
Sets the checked state of the specified item. | |
bool | setChecked (int row, Qt::CheckState checked) |
Sets the checked state of the specified item. | |
virtual QString | labelForId (const QVariant &id) const |
Returns the label for the specified id. | |
Qt::DropActions | supportedDropActions () const override |
bool | insertRows (int row, int count, const QModelIndex &parent) override |
bool | removeRows (int row, int count, const QModelIndex &parent) override |
const QList< ChecklistItem > & | items () const |
Returns the items. | |
void | setItems (const QList< ChecklistItem > &items) |
Sets the items. | |
void | restore (QSettings &settings, const QString &name) |
Restores the IDs and checkstates read from the specified settings object. | |
void | save (QSettings &settings, const QString &name) const |
Saves the IDs and checkstates to the specified settings object. | |
QVariantList | toVariantList () const |
Returns the checked IDs. | |
void | applyVariantList (const QVariantList &checkedIds) |
Checks all items contained by checkedIds and unchecks other items. | |
Static Public Member Functions | |
static constexpr int | idRole () |
Returns the role used to get or set the item ID. | |
Definition at line 72 of file checklistmodel.h.
|
explicit |
Constructs a new checklist model.
Definition at line 27 of file checklistmodel.cpp.
void QtUtilities::ChecklistModel::applyVariantList | ( | const QVariantList & | checkedIds | ) |
Checks all items contained by checkedIds and unchecks other items.
Definition at line 293 of file checklistmodel.cpp.
|
override |
Definition at line 48 of file checklistmodel.cpp.
|
override |
Definition at line 40 of file checklistmodel.cpp.
|
staticconstexpr |
Returns the role used to get or set the item ID.
Definition at line 120 of file checklistmodel.h.
|
override |
Definition at line 159 of file checklistmodel.cpp.
|
override |
Definition at line 64 of file checklistmodel.cpp.
|
inline |
Returns the items.
Definition at line 104 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() with idRole() or setItems()) this method is called to update or initialize the item's label as well. If this method returns an empty string (default behaviour) the item's label will not be updated.
This is useful when items are moved by the view (eg. for Drag & Drop) and to initialize the ChecklistItem labels more conveniently.
Definition at line 149 of file checklistmodel.cpp.
|
override |
Definition at line 172 of file checklistmodel.cpp.
void QtUtilities::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 210 of file checklistmodel.cpp.
|
override |
Definition at line 32 of file checklistmodel.cpp.
void QtUtilities::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 262 of file checklistmodel.cpp.
|
inline |
Sets the checked state of the specified item.
Definition at line 112 of file checklistmodel.h.
bool QtUtilities::ChecklistModel::setChecked | ( | int | row, |
Qt::CheckState | checked ) |
Sets the checked state of the specified item.
Definition at line 125 of file checklistmodel.cpp.
|
override |
Definition at line 73 of file checklistmodel.cpp.
|
override |
Definition at line 114 of file checklistmodel.cpp.
void QtUtilities::ChecklistModel::setItems | ( | const QList< ChecklistItem > & | items | ) |
|
override |
Definition at line 154 of file checklistmodel.cpp.
QVariantList QtUtilities::ChecklistModel::toVariantList | ( | ) | const |
Returns the checked IDs.
Definition at line 278 of file checklistmodel.cpp.