4#ifdef QT_UTILITIES_GUI_QTWIDGETS
23 : QAbstractListModel(parent)
32 : QAbstractListModel(parent)
33 , m_categories(categories)
55 qDeleteAll(m_categories);
67 return parent.isValid() ? 0 :
static_cast<int>(m_categories.size());
72 if (!index.isValid() || index.row() >= m_categories.size()) {
77 return m_categories.at(index.row())->displayName();
78 case Qt::DecorationRole: {
79 const QIcon &icon = m_categories.at(index.row())->icon();
82#ifdef QT_UTILITIES_GUI_QTWIDGETS
83 QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize)
97void OptionCategoryModel::categoryChangedName()
99 const auto *
const senderCategory = qobject_cast<const OptionCategory *>(QObject::sender());
100 if (!senderCategory) {
103 for (
int i = 0, end =
static_cast<int>(m_categories.size()); i < end; ++i) {
104 if (senderCategory == m_categories.at(i)) {
105 QModelIndex index = this->index(i);
106 emit dataChanged(index, index, QVector<int>({ Qt::DisplayRole }));
114void OptionCategoryModel::categoryChangedIcon()
116 const auto *
const senderCategory = qobject_cast<const OptionCategory *>(QObject::sender());
117 if (!senderCategory) {
120 for (
int i = 0, end =
static_cast<int>(m_categories.size()); i < end; ++i) {
121 if (senderCategory == m_categories.at(i)) {
122 QModelIndex index = this->index(i);
123 emit dataChanged(index, index, QVector<int>({ Qt::DecorationRole }));
OptionCategory * category(const QModelIndex &index) const
Returns the category for the specified model index.
~OptionCategoryModel() override
Destroys the option category model.
OptionCategoryModel(QObject *parent=nullptr)
Constructs an option category model.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QList< OptionCategory * > categories
void setCategories(const QList< OptionCategory * > &categories)
Sets the categories for the model.
The OptionCategory class wraps associated option pages.
void displayNameChanged(const QString &displayName)
Emitted when the display name changed.
void iconChanged(const QIcon &icon)
Emitted when the icon changed.