4 #ifdef QT_UTILITIES_GUI_QTWIDGETS
5 #include <QApplication>
21 : QAbstractListModel(parent)
30 : QAbstractListModel(parent)
31 , m_categories(categories)
53 qDeleteAll(m_categories);
65 return parent.isValid() ? 0 : m_categories.size();
70 if (!index.isValid() || index.row() >= m_categories.size()) {
75 return m_categories.at(index.row())->displayName();
76 case Qt::DecorationRole: {
77 const QIcon &icon = m_categories.at(index.row())->icon();
80 #ifdef QT_UTILITIES_GUI_QTWIDGETS
81 QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize)
95 void OptionCategoryModel::categoryChangedName()
97 const auto *
const senderCategory = qobject_cast<const OptionCategory *>(QObject::sender());
98 if (!senderCategory) {
101 for (
int i = 0, end = m_categories.size(); i < end; ++i) {
102 if (senderCategory == m_categories.at(i)) {
103 QModelIndex index = this->index(i);
104 emit dataChanged(index, index, QVector<int>({ Qt::DisplayRole }));
112 void OptionCategoryModel::categoryChangedIcon()
114 const auto *
const senderCategory = qobject_cast<const OptionCategory *>(QObject::sender());
115 if (!senderCategory) {
118 for (
int i = 0, end = m_categories.size(); i < end; ++i) {
119 if (senderCategory == m_categories.at(i)) {
120 QModelIndex index = this->index(i);
121 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.