OpenCoverage

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

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