KWidgetsAddons

kpagewidget.cpp
1 /*
2  This file is part of the KDE Libraries
3  SPDX-FileCopyrightText: 2006 Tobias Koenig <[email protected]>
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 
13 KPageWidgetPrivate::KPageWidgetPrivate(KPageWidget *qq)
14  : KPageViewPrivate(qq)
15 {
16 }
17 
18 void 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 
34 KPageWidget::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 
49 }
50 
52  : KPageWidget(*new KPageWidgetPrivate(this), parent)
53 {
54 }
55 
57 {
58 }
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 {
104  Q_D(KPageWidget);
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 {
112  Q_D(KPageWidget);
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"
void setModel(QAbstractItemModel *model)
Sets the model of the page view.
Definition: kpageview.cpp:341
void setCurrentPage(const QModelIndex &index)
Sets the page with.
Definition: kpageview.cpp:389
Q_EMITQ_EMIT
A base class which can handle multiple pages.
Definition: kpageview.h:49
void pageToggled(KPageWidgetItem *page, bool checked)
This signal is emitted whenever a checkable page changes its state.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void toggled(KPageWidgetItem *page, bool checked)
This signal is emitted whenever a checkable page changes its state.
QModelIndex currentPage() const
Returns the index for the current page or an invalid index if no current page exists.
Definition: kpageview.cpp:399
KPageWidgetItem * addPage(QWidget *widget, const QString &name)
Adds a new top level page to the widget.
Definition: kpagewidget.cpp:60
void pageRemoved(KPageWidgetItem *page)
This signal is emitted when a page is removed.
Page widget with many layouts (faces). A KPageView with hierarchical page model.
Definition: kpagewidget.h:24
~KPageWidget() override
Destroys the page widget.
Definition: kpagewidget.cpp:56
KPageWidgetItem * addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name)
Inserts a new sub page in the widget.
Definition: kpagewidget.cpp:88
bool isValid() const const
void currentPageChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted whenever the current page changes.
KPageWidgetItem * currentPage() const
Returns the KPageWidgetItem for the current page or a null pointer if there is no current page.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const=0
KPageWidgetItem * insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name)
Inserts a new page in the widget.
Definition: kpagewidget.cpp:74
void setCurrentPage(KPageWidgetItem *item)
Sets the page which is associated with the given KPageWidgetItem to be the current page and emits the...
void removePage(KPageWidgetItem *item)
Removes the page associated with the given KPageWidgetItem.
QObject * parent() const const
const QAbstractItemModel * model() const const
KPageWidget(QWidget *parent=nullptr)
Creates a new page widget.
Definition: kpagewidget.cpp:51
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Oct 6 2022 04:18:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.