Qt Utilities  5.8.1
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
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 
9 namespace Dialogs {
10 
11 class OptionPage;
12 class OptionCategory;
13 
14 class QT_UTILITIES_EXPORT OptionCategoryModel : public QAbstractListModel {
15  Q_OBJECT
16 public:
17  explicit OptionCategoryModel(QObject *parent = nullptr);
18  explicit OptionCategoryModel(const QList<OptionCategory *> &categories, QObject *parent = nullptr);
19  virtual ~OptionCategoryModel();
20 
21  const QList<OptionCategory *> &categories() const;
22  OptionCategory *category(const QModelIndex &index) const;
23  OptionCategory *category(int row) const;
24  void setCategories(const QList<OptionCategory *> categories);
25  int rowCount(const QModelIndex &parent = QModelIndex()) const;
26  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
27 
28 private Q_SLOTS:
29  void categoryChangedName();
30  void categoryChangedIcon();
31 
32 private:
33  QList<OptionCategory *> m_categories;
34 };
35 
41 inline const QList<OptionCategory *> &OptionCategoryModel::categories() const
42 {
43  return m_categories;
44 }
45 
51 inline OptionCategory *OptionCategoryModel::category(const QModelIndex &index) const
52 {
53  return (index.isValid()) ? category(index.row()) : nullptr;
54 }
55 
62 {
63  return row < m_categories.size() ? m_categories.at(row) : nullptr;
64 }
65 } // namespace Dialogs
66 
67 #endif // DIALOGS_OPTIONCATEGORYMODEL_H
The OptionCategoryModel class is used by SettingsDialog to store and display option categories...
The OptionCategory class wraps associated option pages.
OptionCategory * category(const QModelIndex &index) const
Returns the category for the specified model index.
const QList< OptionCategory * > & categories() const
Returns the categories.
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Provides common dialogs such as AboutDialog, EnterPasswordDialog and SettingsDialog.
Definition: dialogutils.h:12