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 kpagemodel.h KPageModel
20  *
21  *  @short A base class for a model used by KPageView.
22  *
23  *  This class is an abstract base class which must be used to
24  *  implement custom models for KPageView. Additional to the standard
25  *  Qt::ItemDataRoles it provides the two roles
26  *
27  *    @li HeaderRole
28  *    @li HeaderVisibleRole
29  *    @li WidgetRole
30  *
31  *  which are used to return a header string for a page and a QWidget
32  *  pointer to the page itself.
33  *
34  *  <b>Example:</b>\n
35  *
36  *  \code
37  *    KPageView *view = new KPageView( this );
38  *    KPageModel *model = new MyPageModel( this );
39  *
40  *    view->setModel( model );
41  *  \endcode
42  *
43  *  @see KPageView
44  *  @author Tobias Koenig <tokoe@kde.org>
45  */
46 class KWIDGETSADDONS_EXPORT KPageModel : public QAbstractItemModel
47 {
48     Q_OBJECT
49     Q_DECLARE_PRIVATE(KPageModel)
50 
51 public:
52     /**
53      * Additional roles that KPageView uses.
54      */
55     enum Role {
56         /**
57          * A string to be rendered as page header.
58          */
59         HeaderRole = Qt::UserRole + 1,
60         /**
61          * A pointer to the page widget. This is the widget that is shown when the item is
62          * selected.
63          *
64          * You can make QVariant take a QWidget using
65          * \code
66          * QWidget *myWidget = new QWidget;
67          * QVariant v = QVariant::fromValue(myWidget);
68          * \endcode
69          */
70         WidgetRole,
71         /**
72          * when true, show the page header, if false don't
73          * @since 5.52
74          */
75         HeaderVisibleRole,
76     };
77 
78     /**
79      * Constructs a page model with the given parent.
80      */
81     explicit KPageModel(QObject *parent = nullptr);
82 
83     /**
84      * Destroys the page model.
85      */
86     ~KPageModel() override;
87 
88 protected:
89     KPageModel(KPageModelPrivate &dd, QObject *parent);
90     std::unique_ptr<class KPageModelPrivate> const d_ptr;
91 };
92 
93 #endif
94