File indexing completed on 2024-04-28 03:59:09

0001 /*
0002     This file is part of the KDE Libraries
0003     SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KPAGEMODEL_H
0009 #define KPAGEMODEL_H
0010 
0011 #include <kwidgetsaddons_export.h>
0012 
0013 #include <QAbstractItemModel>
0014 #include <memory>
0015 
0016 class KPageModelPrivate;
0017 
0018 /**
0019  *  @class KPageModel kpagemodel.h KPageModel
0020  *
0021  *  @short A base class for a model used by KPageView.
0022  *
0023  *  This class is an abstract base class which must be used to
0024  *  implement custom models for KPageView. Additional to the standard
0025  *  Qt::ItemDataRoles it provides the two roles
0026  *
0027  *    @li HeaderRole
0028  *    @li HeaderVisibleRole
0029  *    @li WidgetRole
0030  *
0031  *  which are used to return a header string for a page and a QWidget
0032  *  pointer to the page itself.
0033  *
0034  *  <b>Example:</b>\n
0035  *
0036  *  \code
0037  *    KPageView *view = new KPageView( this );
0038  *    KPageModel *model = new MyPageModel( this );
0039  *
0040  *    view->setModel( model );
0041  *  \endcode
0042  *
0043  *  @see KPageView
0044  *  @author Tobias Koenig <tokoe@kde.org>
0045  */
0046 class KWIDGETSADDONS_EXPORT KPageModel : public QAbstractItemModel
0047 {
0048     Q_OBJECT
0049     Q_DECLARE_PRIVATE(KPageModel)
0050 
0051 public:
0052     /**
0053      * Additional roles that KPageView uses.
0054      */
0055     enum Role {
0056         /**
0057          * A string to be rendered as page header.
0058          */
0059         HeaderRole = Qt::UserRole + 1,
0060         /**
0061          * A pointer to the page widget. This is the widget that is shown when the item is
0062          * selected.
0063          *
0064          * You can make QVariant take a QWidget using
0065          * \code
0066          * QWidget *myWidget = new QWidget;
0067          * QVariant v = QVariant::fromValue(myWidget);
0068          * \endcode
0069          */
0070         WidgetRole,
0071         /**
0072          * when true, show the page header, if false don't
0073          * @since 5.52
0074          */
0075         HeaderVisibleRole,
0076     };
0077 
0078     /**
0079      * Constructs a page model with the given parent.
0080      */
0081     explicit KPageModel(QObject *parent = nullptr);
0082 
0083     /**
0084      * Destroys the page model.
0085      */
0086     ~KPageModel() override;
0087 
0088 protected:
0089     KWIDGETSADDONS_NO_EXPORT KPageModel(KPageModelPrivate &dd, QObject *parent);
0090 
0091     std::unique_ptr<class KPageModelPrivate> const d_ptr;
0092 };
0093 
0094 #endif