1#ifndef MODELS_CHECKLISTMODEL_H
2#define MODELS_CHECKLISTMODEL_H
6#include <QAbstractListModel>
9QT_FORWARD_DECLARE_CLASS(QSettings)
19 ChecklistItem(
const QVariant &
id = QVariant(),
const QString &
label = QString(), Qt::CheckState checked = Qt::Unchecked);
21 const QVariant &
id()
const;
22 const QString &
label()
const;
29 Qt::CheckState m_checkState;
69 return m_checkState == Qt::Checked;
77 int rowCount(
const QModelIndex &parent = QModelIndex())
const override;
78 Qt::ItemFlags
flags(
const QModelIndex &index)
const override;
79 QVariant
data(
const QModelIndex &index,
int role = Qt::DisplayRole)
const override;
80 QMap<int, QVariant>
itemData(
const QModelIndex &index)
const override;
81 bool setData(
const QModelIndex &index,
const QVariant &value,
int role = Qt::DisplayRole)
override;
82 bool setItemData(
const QModelIndex &index,
const QMap<int, QVariant> &roles)
override;
84 bool setChecked(
int row, Qt::CheckState checked);
85 virtual QString
labelForId(
const QVariant &
id)
const;
87 bool insertRows(
int row,
int count,
const QModelIndex &parent)
override;
88 bool removeRows(
int row,
int count,
const QModelIndex &parent)
override;
89 const QList<ChecklistItem> &
items()
const;
91 void restore(QSettings &settings,
const QString &name);
92 void save(QSettings &settings,
const QString &name)
const;
95 static constexpr int idRole();
98 QList<ChecklistItem> m_items;
114 return setChecked(row, checked ? Qt::Checked : Qt::Unchecked);
122 return Qt::UserRole + 1;
Qt::CheckState checkState() const
Returns the check state.
ChecklistItem(const QVariant &id=QVariant(), const QString &label=QString(), Qt::CheckState checked=Qt::Unchecked)
friend class ChecklistModel
const QVariant & id() const
Returns the ID of the item.
bool isChecked() const
Returns whether the item is checked.
const QString & label() const
Returns the label.
void setItems(const QList< ChecklistItem > &items)
Sets the items.
ChecklistModel(QObject *parent=nullptr)
Constructs a new checklist model.
bool removeRows(int row, int count, const QModelIndex &parent) override
bool setChecked(int row, bool checked)
Sets the checked state of the specified item.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole) override
void save(QSettings &settings, const QString &name) const
Saves the IDs and checkstates to the specified settings object.
virtual QString labelForId(const QVariant &id) const
Returns the label for the specified id.
void applyVariantList(const QVariantList &checkedIds)
Checks all items contained by checkedIds and unchecks other items.
bool insertRows(int row, int count, const QModelIndex &parent) override
Qt::DropActions supportedDropActions() const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void restore(QSettings &settings, const QString &name)
Restores the IDs and checkstates read from the specified settings object.
QMap< int, QVariant > itemData(const QModelIndex &index) const override
const QList< ChecklistItem > & items() const
Returns the items.
QVariantList toVariantList() const
Returns the checked IDs.
static constexpr int idRole()
Returns the role used to get or set the item ID.
bool setItemData(const QModelIndex &index, const QMap< int, QVariant > &roles) override
Qt::ItemFlags flags(const QModelIndex &index) const override
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.