| 1 |
#ifndef DIALOGS_OPTIONCATEGORYMODEL_H |
| 2 |
#define DIALOGS_OPTIONCATEGORYMODEL_H |
| 3 |
|
| 4 |
#include "../global.h" |
| 5 |
|
| 6 |
#include <QAbstractListModel> |
| 7 |
#include <QList> |
| 8 |
|
| 9 |
namespace QtUtilities { |
| 10 |
|
| 11 |
class OptionPage; |
| 12 |
class OptionCategory; |
| 13 |
|
| 14 |
class QT_UTILITIES_EXPORT OptionCategoryModel : public QAbstractListModel { |
| 15 |
Q_OBJECT |
| 16 |
Q_PROPERTY(QList<OptionCategory *> categories READ categories WRITE setCategories) |
| 17 |
public: |
| 18 |
explicit OptionCategoryModel(QObject *parent = nullptr); |
| 19 |
explicit OptionCategoryModel(const QList<OptionCategory *> &categories, QObject *parent = nullptr); |
| 20 |
~OptionCategoryModel() override; |
| 21 |
|
| 22 |
const QList<OptionCategory *> &categories() const; |
| 23 |
OptionCategory *category(const QModelIndex &index) const; |
| 24 |
OptionCategory *category(int row) const; |
| 25 |
void setCategories(const QList<OptionCategory *> &categories); |
| 26 |
int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 27 |
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 28 |
|
| 29 |
private Q_SLOTS: |
| 30 |
void categoryChangedName(); |
| 31 |
void categoryChangedIcon(); |
| 32 |
|
| 33 |
private: |
| 34 |
QList<OptionCategory *> m_categories; |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
inline const QList<OptionCategory *> &OptionCategoryModel::categories() const |
| 43 |
{ |
| 44 |
return m_categories; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
inline OptionCategory *OptionCategoryModel::category(const QModelIndex &index) const |
| 53 |
{ |
| 54 |
return (index.isValid()) ? category(index.row()) : nullptr; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
inline OptionCategory *OptionCategoryModel::category(int row) const |
| 63 |
{ |
| 64 |
return row < m_categories.size() ? m_categories.at(row) : nullptr; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
#endif |