1/*
2 This file is part of the KDE Libraries
3
4 Copyright (C) 2006 Tobias Koenig (tokoe@kde.org)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KPAGEMODEL_H
23#define KPAGEMODEL_H
24
25#include <kdeui_export.h>
26
27#include <QtCore/QAbstractItemModel>
28
29class KPageModelPrivate;
30
31/**
32 * @short A base class for a model used by KPageView.
33 *
34 * This class is an abstract base class which must be used to
35 * implement custom models for KPageView. Additional to the standard
36 * Qt::ItemDataRoles it provides the two roles
37 *
38 * @li HeaderRole
39 * @li WidgetRole
40 *
41 * which are used to return a header string for a page and a QWidget
42 * pointer to the page itself.
43 *
44 * <b>Example:</b>\n
45 *
46 * \code
47 * KPageView *view = new KPageView( this );
48 * KPageModel *model = new MyPageModel( this );
49 *
50 * view->setModel( model );
51 * \endcode
52 *
53 * @see KPageView
54 * @author Tobias Koenig <tokoe@kde.org>
55 */
56class KDEUI_EXPORT KPageModel : public QAbstractItemModel
57{
58 Q_OBJECT
59 Q_DECLARE_PRIVATE(KPageModel)
60
61 public:
62 /**
63 * Additional roles that KPageView uses.
64 */
65 enum Role {
66 /**
67 * A string to be rendered as page header.
68 */
69 HeaderRole = Qt::UserRole + 1,
70 /**
71 * A pointer to the page widget. This is the widget that is shown when the item is
72 * selected.
73 *
74 * You can make QVariant take a QWidget using
75 * \code
76 * QWidget *myWidget = new QWidget;
77 * QVariant v = QVariant::fromValue(myWidget);
78 * \endcode
79 */
80 WidgetRole
81 };
82
83 /**
84 * Constructs a page model with the given parent.
85 */
86 explicit KPageModel( QObject *parent = 0 );
87
88 /**
89 * Destroys the page model.
90 */
91 virtual ~KPageModel();
92
93 protected:
94 KPageModel(KPageModelPrivate &dd, QObject *parent);
95 KPageModelPrivate *const d_ptr;
96};
97
98#endif
99