1 | /* |
2 | This file is part of the KDE Libraries |
3 | SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KPAGEMODEL_H |
9 | #define KPAGEMODEL_H |
10 | |
11 | #include <kwidgetsaddons_export.h> |
12 | |
13 | #include <QAbstractItemModel> |
14 | #include <memory> |
15 | |
16 | class KPageModelPrivate; |
17 | |
18 | /*! |
19 | * \class KPageModel |
20 | * \inmodule KWidgetsAddons |
21 | * |
22 | * \brief A base class for a model used by KPageView. |
23 | * |
24 | * This class is an abstract base class which must be used to |
25 | * implement custom models for KPageView. Additional to the standard |
26 | * Qt::ItemDataRoles it provides the two roles |
27 | * \list |
28 | * \li HeaderRole |
29 | * \li HeaderVisibleRole |
30 | * \li WidgetRole |
31 | * \endlist |
32 | * |
33 | * which are used to return a header string for a page and a QWidget |
34 | * pointer to the page itself. |
35 | * |
36 | * Example: |
37 | * |
38 | * \code |
39 | * KPageView *view = new KPageView( this ); |
40 | * KPageModel *model = new MyPageModel( this ); |
41 | * |
42 | * view->setModel( model ); |
43 | * \endcode |
44 | * |
45 | * \sa KPageView |
46 | */ |
47 | class KWIDGETSADDONS_EXPORT KPageModel : public QAbstractItemModel |
48 | { |
49 | Q_OBJECT |
50 | Q_DECLARE_PRIVATE(KPageModel) |
51 | |
52 | public: |
53 | /*! |
54 | * Additional roles that KPageView uses. |
55 | * |
56 | * \value HeaderRole A string to be rendered as page header. |
57 | * \value WidgetRole A pointer to the page widget. This is the widget that is shown when the item is selected. |
58 | * You can make QVariant take a QWidget using |
59 | * \code |
60 | * QWidget *myWidget = new QWidget; |
61 | * QVariant v = QVariant::fromValue(myWidget); |
62 | * \endcode |
63 | * \value[since 5.52] When true, show the page header, if false don't |
64 | * \value[since 6.6] The list of actions associated to the page |
65 | */ |
66 | enum Role { |
67 | = Qt::UserRole + 1, |
68 | WidgetRole, |
69 | , |
70 | ActionsRole, |
71 | }; |
72 | |
73 | /*! |
74 | * Constructs a page model with the given parent. |
75 | */ |
76 | explicit KPageModel(QObject *parent = nullptr); |
77 | |
78 | ~KPageModel() override; |
79 | |
80 | protected: |
81 | KWIDGETSADDONS_NO_EXPORT KPageModel(KPageModelPrivate &dd, QObject *parent); |
82 | |
83 | std::unique_ptr<class KPageModelPrivate> const d_ptr; |
84 | }; |
85 | |
86 | #endif |
87 | |