KWidgetsAddons

kpagewidget.cpp
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#include "kpagewidget.h"
9#include "kpagewidget_p.h"
10
11#include "kpagewidgetmodel.h"
12
13KPageWidgetPrivate::KPageWidgetPrivate(KPageWidget *qq)
14 : KPageViewPrivate(qq)
15{
16}
17
18void KPageWidgetPrivate::slotCurrentPageChanged(const QModelIndex &current, const QModelIndex &before)
19{
20 KPageWidgetItem *currentItem = nullptr;
21 if (current.isValid()) {
22 currentItem = model()->item(current);
23 }
24
25 KPageWidgetItem *beforeItem = nullptr;
26 if (before.isValid()) {
27 beforeItem = model()->item(before);
28 }
29
30 Q_Q(KPageWidget);
31 Q_EMIT q->currentPageChanged(currentItem, beforeItem);
32}
33
34KPageWidget::KPageWidget(KPageWidgetPrivate &dd, QWidget *parent)
35 : KPageView(dd, parent)
36{
38 connect(this, &KPageView::currentPageChanged, this, [d](const QModelIndex &current, const QModelIndex &before) {
39 d->slotCurrentPageChanged(current, before);
40 });
41
42 if (!d->KPageViewPrivate::model) {
43 setModel(new KPageWidgetModel(this));
44 } else {
45 Q_ASSERT(qobject_cast<KPageWidgetModel *>(d->KPageViewPrivate::model));
46 }
47
48 connect(d->model(), &KPageWidgetModel::toggled, this, &KPageWidget::pageToggled);
49}
50
52 : KPageWidget(*new KPageWidgetPrivate(this), parent)
53{
54}
55
59
61{
63
64 return d->model()->addPage(widget, name);
65}
66
68{
70
71 d->model()->addPage(item);
72}
73
75{
77
78 return d->model()->insertPage(before, widget, name);
79}
80
82{
84
85 d->model()->insertPage(before, item);
86}
87
89{
91
92 return d->model()->addSubPage(parent, widget, name);
93}
94
96{
98
99 d->model()->addSubPage(parent, item);
100}
101
103{
105
106 Q_EMIT pageRemoved(item); // Q_EMIT signal before we remove it, because the item will be deleted in the model
107 d->model()->removePage(item);
108}
109
111{
113
114 const QModelIndex index = d->model()->index(item);
115 if (!index.isValid()) {
116 return;
117 }
118
120}
121
123{
124 Q_D(const KPageWidget);
125
126 const QModelIndex index = KPageView::currentPage();
127
128 if (!index.isValid()) {
129 return nullptr;
130 }
131
132 return d->model()->item(index);
133}
134
135#include "moc_kpagewidget.cpp"
A base class which can handle multiple pages.
Definition kpageview.h:50
void setCurrentPage(const QModelIndex &index)
Sets the page with.
QModelIndex currentPage() const
Returns the index for the current page or an invalid index if no current page exists.
void currentPageChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted whenever the current page changes.
KPageWidgetItem is used by KPageWidget and represents a page.
This page model is used by KPageWidget to provide a hierarchical layout of pages.
void toggled(KPageWidgetItem *page, bool checked)
This signal is emitted whenever a checkable page changes its state.
Page widget with many layouts (faces).
Definition kpagewidget.h:25
KPageWidget(QWidget *parent=nullptr)
Creates a new page widget.
~KPageWidget() override
Destroys the page widget.
KPageWidgetItem * addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name)
Inserts a new sub page in the widget.
void removePage(KPageWidgetItem *item)
Removes the page associated with the given KPageWidgetItem.
KPageWidgetItem * currentPage() const
Returns the KPageWidgetItem for the current page or a null pointer if there is no current page.
void pageToggled(KPageWidgetItem *page, bool checked)
This signal is emitted whenever a checkable page changes its state.
KPageWidgetItem * insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name)
Inserts a new page in the widget.
KPageWidgetItem * addPage(QWidget *widget, const QString &name)
Adds a new top level page to the widget.
void setCurrentPage(KPageWidgetItem *item)
Sets the page which is associated with the given KPageWidgetItem to be the current page and emits the...
void pageRemoved(KPageWidgetItem *page)
This signal is emitted when a page is removed.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
bool isValid() const const
const QAbstractItemModel * model() const const
Q_EMITQ_EMIT
QObject * parent() const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:40:26 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.