Qt Utilities  5.6.0
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 <QList>
7 #include <QAbstractListModel>
8 
9 namespace Dialogs {
10 
11 class OptionPage;
12 class OptionCategory;
13 
14 class QT_UTILITIES_EXPORT OptionCategoryModel : public QAbstractListModel
15 {
16  Q_OBJECT
17 public:
18  explicit OptionCategoryModel(QObject *parent = nullptr);
19  explicit OptionCategoryModel(const QList<OptionCategory *> &categories, QObject *parent = nullptr);
20  virtual ~OptionCategoryModel();
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;
27  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
28 
29 private Q_SLOTS:
30  void categoryChangedName();
31  void categoryChangedIcon();
32 
33 private:
34  QList<OptionCategory *> m_categories;
35 
36 };
37 
43 inline const QList<OptionCategory *> &OptionCategoryModel::categories() const
44 {
45  return m_categories;
46 }
47 
53 inline OptionCategory *OptionCategoryModel::category(const QModelIndex &index) const
54 {
55  return (index.isValid())
56  ? category(index.row())
57  : nullptr;
58 }
59 
66 {
67  return row < m_categories.size() ? m_categories.at(row) : nullptr;
68 }
69 
70 }
71 
72 #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