qstackedwidget.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qstackedwidget.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qstackedwidget.h"-
35-
36#ifndef QT_NO_STACKEDWIDGET-
37-
38#include <qstackedlayout.h>-
39#include <qevent.h>-
40#include <private/qframe_p.h>-
41-
42QT_BEGIN_NAMESPACE-
43-
44class QStackedWidgetPrivate : public QFramePrivate-
45{-
46 Q_DECLARE_PUBLIC(QStackedWidget)-
47public:-
48 QStackedWidgetPrivate():layout(0){}
never executed: end of block
0
49 QStackedLayout *layout;-
50 bool blockChildAdd;-
51};-
52-
53/*!-
54 \class QStackedWidget-
55 \brief The QStackedWidget class provides a stack of widgets where-
56 only one widget is visible at a time.-
57-
58 \ingroup organizers-
59 \ingroup geomanagement-
60 \inmodule QtWidgets-
61-
62 QStackedWidget can be used to create a user interface similar to-
63 the one provided by QTabWidget. It is a convenience layout widget-
64 built on top of the QStackedLayout class.-
65-
66 Like QStackedLayout, QStackedWidget can be constructed and-
67 populated with a number of child widgets ("pages"):-
68-
69 \snippet qstackedwidget/main.cpp 0-
70 \snippet qstackedwidget/main.cpp 2-
71 \snippet qstackedwidget/main.cpp 3-
72-
73 QStackedWidget provides no intrinsic means for the user to switch-
74 page. This is typically done through a QComboBox or a QListWidget-
75 that stores the titles of the QStackedWidget's pages. For-
76 example:-
77-
78 \snippet qstackedwidget/main.cpp 1-
79-
80 When populating a stacked widget, the widgets are added to an-
81 internal list. The indexOf() function returns the index of a-
82 widget in that list. The widgets can either be added to the end of-
83 the list using the addWidget() function, or inserted at a given-
84 index using the insertWidget() function. The removeWidget()-
85 function removes a widget from the stacked widget. The number of-
86 widgets contained in the stacked widget can-
87 be obtained using the count() function.-
88-
89 The widget() function returns the widget at a given index-
90 position. The index of the widget that is shown on screen is given-
91 by currentIndex() and can be changed using setCurrentIndex(). In a-
92 similar manner, the currently shown widget can be retrieved using-
93 the currentWidget() function, and altered using the-
94 setCurrentWidget() function.-
95-
96 Whenever the current widget in the stacked widget changes or a-
97 widget is removed from the stacked widget, the currentChanged()-
98 and widgetRemoved() signals are emitted respectively.-
99-
100 \sa QStackedLayout, QTabWidget, {Config Dialog Example}-
101*/-
102-
103/*!-
104 \fn void QStackedWidget::currentChanged(int index)-
105-
106 This signal is emitted whenever the current widget changes.-
107-
108 The parameter holds the \a index of the new current widget, or -1-
109 if there isn't a new one (for example, if there are no widgets in-
110 the QStackedWidget).-
111-
112 \sa currentWidget(), setCurrentWidget()-
113*/-
114-
115/*!-
116 \fn void QStackedWidget::widgetRemoved(int index)-
117-
118 This signal is emitted whenever a widget is removed. The widget's-
119 \a index is passed as parameter.-
120-
121 \sa removeWidget()-
122*/-
123-
124/*!-
125 Constructs a QStackedWidget with the given \a parent.-
126-
127 \sa addWidget(), insertWidget()-
128*/-
129QStackedWidget::QStackedWidget(QWidget *parent)-
130 : QFrame(*new QStackedWidgetPrivate, parent)-
131{-
132 Q_D(QStackedWidget);-
133 d->layout = new QStackedLayout(this);-
134 connect(d->layout, SIGNAL(widgetRemoved(int)), this, SIGNAL(widgetRemoved(int)));-
135 connect(d->layout, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));-
136}
never executed: end of block
0
137-
138/*!-
139 Destroys this stacked widget, and frees any allocated resources.-
140*/-
141QStackedWidget::~QStackedWidget()-
142{-
143}-
144-
145/*!-
146 Appends the given \a widget to the QStackedWidget and returns the-
147 index position. Ownership of \a widget is passed on to the-
148 QStackedWidget.-
149-
150 If the QStackedWidget is empty before this function is called,-
151 \a widget becomes the current widget.-
152-
153 \sa insertWidget(), removeWidget(), setCurrentWidget()-
154*/-
155int QStackedWidget::addWidget(QWidget *widget)-
156{-
157 return d_func()->layout->addWidget(widget);
never executed: return d_func()->layout->addWidget(widget);
0
158}-
159-
160/*!-
161 Inserts the given \a widget at the given \a index in the-
162 QStackedWidget. Ownership of \a widget is passed on to the-
163 QStackedWidget. If \a index is out of range, the \a widget is-
164 appended (in which case it is the actual index of the \a widget-
165 that is returned).-
166-
167 If the QStackedWidget was empty before this function is called,-
168 the given \a widget becomes the current widget.-
169-
170 Inserting a new widget at an index less than or equal to the current index-
171 will increment the current index, but keep the current widget.-
172-
173 \sa addWidget(), removeWidget(), setCurrentWidget()-
174*/-
175int QStackedWidget::insertWidget(int index, QWidget *widget)-
176{-
177 return d_func()->layout->insertWidget(index, widget);
never executed: return d_func()->layout->insertWidget(index, widget);
0
178}-
179-
180/*!-
181 Removes \a widget from the QStackedWidget. i.e., \a widget is \e-
182 not deleted but simply removed from the stacked layout, causing it-
183 to be hidden.-
184-
185 \note Parent object and parent widget of \a widget will remain the-
186 QStackedWidget. If the application wants to reuse the removed-
187 \a widget, then it is recommended to re-parent it.-
188-
189 \sa addWidget(), insertWidget(), currentWidget()-
190*/-
191void QStackedWidget::removeWidget(QWidget *widget)-
192{-
193 d_func()->layout->removeWidget(widget);-
194}
never executed: end of block
0
195-
196/*!-
197 \property QStackedWidget::currentIndex-
198 \brief the index position of the widget that is visible-
199-
200 The current index is -1 if there is no current widget.-
201-
202 By default, this property contains a value of -1 because the stack-
203 is initially empty.-
204-
205 \sa currentWidget(), indexOf()-
206*/-
207-
208void QStackedWidget::setCurrentIndex(int index)-
209{-
210 d_func()->layout->setCurrentIndex(index);-
211}
never executed: end of block
0
212-
213int QStackedWidget::currentIndex() const-
214{-
215 return d_func()->layout->currentIndex();
never executed: return d_func()->layout->currentIndex();
0
216}-
217-
218/*!-
219 Returns the current widget, or 0 if there are no child widgets.-
220-
221 \sa currentIndex(), setCurrentWidget()-
222*/-
223QWidget *QStackedWidget::currentWidget() const-
224{-
225 return d_func()->layout->currentWidget();
never executed: return d_func()->layout->currentWidget();
0
226}-
227-
228-
229/*!-
230 \fn void QStackedWidget::setCurrentWidget(QWidget *widget)-
231-
232 Sets the current widget to be the specified \a widget. The new-
233 current widget must already be contained in this stacked widget.-
234-
235 \sa currentWidget(), setCurrentIndex()-
236 */-
237void QStackedWidget::setCurrentWidget(QWidget *widget)-
238{-
239 Q_D(QStackedWidget);-
240 if (d->layout->indexOf(widget) == -1) {
d->layout->ind...(widget) == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
241 qWarning("QStackedWidget::setCurrentWidget: widget %p not contained in stack", widget);-
242 return;
never executed: return;
0
243 }-
244 d->layout->setCurrentWidget(widget);-
245}
never executed: end of block
0
246-
247/*!-
248 Returns the index of the given \a widget, or -1 if the given \a-
249 widget is not a child of the QStackedWidget.-
250-
251 \sa currentIndex(), widget()-
252*/-
253int QStackedWidget::indexOf(QWidget *widget) const-
254{-
255 return d_func()->layout->indexOf(widget);
never executed: return d_func()->layout->indexOf(widget);
0
256}-
257-
258/*!-
259 Returns the widget at the given \a index, or 0 if there is no such-
260 widget.-
261-
262 \sa currentWidget(), indexOf()-
263*/-
264QWidget *QStackedWidget::widget(int index) const-
265{-
266 return d_func()->layout->widget(index);
never executed: return d_func()->layout->widget(index);
0
267}-
268-
269/*!-
270 \property QStackedWidget::count-
271 \brief the number of widgets contained by this stacked widget-
272-
273 By default, this property contains a value of 0.-
274-
275 \sa currentIndex(), widget()-
276*/-
277int QStackedWidget::count() const-
278{-
279 return d_func()->layout->count();
never executed: return d_func()->layout->count();
0
280}-
281-
282/*! \reimp */-
283bool QStackedWidget::event(QEvent *e)-
284{-
285 return QFrame::event(e);
never executed: return QFrame::event(e);
0
286}-
287-
288QT_END_NAMESPACE-
289-
290#include "moc_qstackedwidget.cpp"-
291-
292#endif // QT_NO_STACKEDWIDGET-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9