Qt Utilities 6.14.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
QtUtilities::ChecklistModel Class Reference

#include <checklistmodel.h>

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

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.
 

Detailed Description

Definition at line 72 of file checklistmodel.h.

Constructor & Destructor Documentation

◆ ChecklistModel()

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

Constructs a new checklist model.

Definition at line 27 of file checklistmodel.cpp.

Member Function Documentation

◆ applyVariantList()

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.

◆ data()

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

Definition at line 48 of file checklistmodel.cpp.

◆ flags()

Qt::ItemFlags QtUtilities::ChecklistModel::flags ( const QModelIndex & index) const
override

Definition at line 40 of file checklistmodel.cpp.

◆ idRole()

constexpr int QtUtilities::ChecklistModel::idRole ( )
staticconstexpr

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

Definition at line 120 of file checklistmodel.h.

◆ insertRows()

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

Definition at line 159 of file checklistmodel.cpp.

◆ itemData()

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

Definition at line 64 of file checklistmodel.cpp.

◆ items()

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

Returns the items.

Definition at line 104 of file checklistmodel.h.

◆ labelForId()

QString QtUtilities::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() 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.

◆ removeRows()

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

Definition at line 172 of file checklistmodel.cpp.

◆ restore()

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.

◆ rowCount()

int QtUtilities::ChecklistModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 32 of file checklistmodel.cpp.

◆ save()

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.

◆ setChecked() [1/2]

bool QtUtilities::ChecklistModel::setChecked ( int row,
bool checked )
inline

Sets the checked state of the specified item.

Definition at line 112 of file checklistmodel.h.

◆ setChecked() [2/2]

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.

◆ setData()

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

Definition at line 73 of file checklistmodel.cpp.

◆ setItemData()

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

Definition at line 114 of file checklistmodel.cpp.

◆ setItems()

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

Sets the items.

Resets the model.

Definition at line 188 of file checklistmodel.cpp.

◆ supportedDropActions()

Qt::DropActions QtUtilities::ChecklistModel::supportedDropActions ( ) const
override

Definition at line 154 of file checklistmodel.cpp.

◆ toVariantList()

QVariantList QtUtilities::ChecklistModel::toVariantList ( ) const

Returns the checked IDs.

Definition at line 278 of file checklistmodel.cpp.


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