Qt Utilities: settingsdialog/optioncategorymodel.h Source File

Qt Utilities 6.22.1 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
14 class 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
42 inline const QList<OptionCategory *> &OptionCategoryModel::categories() const
43{
44 return m_categories;
45}
46
52 inline OptionCategory *OptionCategoryModel::category(const QModelIndex &index) const
53{
54 return (index.isValid()) ? category(index.row()) : nullptr;
55}
56
62 inline OptionCategory *OptionCategoryModel::category(int row) const
63{
64 return row < m_categories.size() ? m_categories.at(row) : nullptr;
65}
66} // namespace QtUtilities
67
68#endif // DIALOGS_OPTIONCATEGORYMODEL_H
QtUtilities::OptionCategoryModel::category
OptionCategory * category(const QModelIndex &index) const
Returns the category for the specified model index.
Definition optioncategorymodel.h:52
QtUtilities::OptionCategoryModel::OptionCategoryModel
OptionCategoryModel(QObject *parent=nullptr)
Constructs an option category model.
Definition optioncategorymodel.cpp:22
QtUtilities::OptionCategoryModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition optioncategorymodel.cpp:70
QtUtilities::OptionCategoryModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition optioncategorymodel.cpp:65
QtUtilities::OptionCategoryModel::categories
QList< OptionCategory * > categories
Definition optioncategorymodel.h:16
QtUtilities::OptionCategoryModel::setCategories
void setCategories(const QList< OptionCategory * > &categories)
Sets the categories for the model.
Definition optioncategorymodel.cpp:52
QtUtilities::OptionCategory
The OptionCategory class wraps associated option pages.
Definition optioncategory.h:18
QtUtilities::OptionPage
The OptionPage class is the base class for SettingsDialog pages.
Definition optionpage.h:34
global.h
QT_UTILITIES_EXPORT
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Definition global.h:14
QtUtilities
!
Definition trylocker.h:8