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
optioncategorymodel.h
Go to the documentation of this file.
1#ifndef DIALOGS_OPTIONCATEGORYMODEL_H
2#define DIALOGS_OPTIONCATEGORYMODEL_H
3
4#include "../global.h"
5
6#include <QAbstractListModel>
7#include <QList>
8
9namespace QtUtilities {
10
11class OptionPage;
12class OptionCategory;
13
14class QT_UTILITIES_EXPORT OptionCategoryModel : public QAbstractListModel {
15 Q_OBJECT
16 Q_PROPERTY(QList<OptionCategory *> categories READ categories WRITE setCategories)
17public:
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
29private Q_SLOTS:
30 void categoryChangedName();
31 void categoryChangedIcon();
32
33private:
34 QList<OptionCategory *> m_categories;
35};
36
42inline const QList<OptionCategory *> &OptionCategoryModel::categories() const
43{
44 return m_categories;
45}
46
52inline OptionCategory *OptionCategoryModel::category(const QModelIndex &index) const
53{
54 return (index.isValid()) ? category(index.row()) : nullptr;
55}
56
63{
64 return row < m_categories.size() ? m_categories.at(row) : nullptr;
65}
66} // namespace QtUtilities
67
68#endif // DIALOGS_OPTIONCATEGORYMODEL_H
The OptionCategoryModel class is used by SettingsDialog to store and display option categories.
OptionCategory * category(const QModelIndex &index) const
Returns the category for the specified model index.
QList< OptionCategory * > categories
The OptionCategory class wraps associated option pages.
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Definition global.h:14