widgets/qstackedwidget.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui 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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qstackedwidget.h" -
43 -
44#ifndef QT_NO_STACKEDWIDGET -
45 -
46#include <qstackedlayout.h> -
47#include <qevent.h> -
48#include <private/qframe_p.h> -
49 -
50QT_BEGIN_NAMESPACE -
51 -
52class QStackedWidgetPrivate : public QFramePrivate -
53{ -
54 Q_DECLARE_PUBLIC(QStackedWidget) -
55public: -
56 QStackedWidgetPrivate():layout(0){}
executed: }
Execution Count:232
232
57 QStackedLayout *layout; -
58 bool blockChildAdd; -
59}; -
60 -
61/*! -
62 \class QStackedWidget -
63 \brief The QStackedWidget class provides a stack of widgets where -
64 only one widget is visible at a time. -
65 -
66 \ingroup organizers -
67 \ingroup geomanagement -
68 \inmodule QtWidgets -
69 -
70 QStackedWidget can be used to create a user interface similar to -
71 the one provided by QTabWidget. It is a convenience layout widget -
72 built on top of the QStackedLayout class. -
73 -
74 Like QStackedLayout, QStackedWidget can be constructed and -
75 populated with a number of child widgets ("pages"): -
76 -
77 \snippet qstackedwidget/main.cpp 0 -
78 \snippet qstackedwidget/main.cpp 2 -
79 \snippet qstackedwidget/main.cpp 3 -
80 -
81 QStackedWidget provides no intrinsic means for the user to switch -
82 page. This is typically done through a QComboBox or a QListWidget -
83 that stores the titles of the QStackedWidget's pages. For -
84 example: -
85 -
86 \snippet qstackedwidget/main.cpp 1 -
87 -
88 When populating a stacked widget, the widgets are added to an -
89 internal list. The indexOf() function returns the index of a -
90 widget in that list. The widgets can either be added to the end of -
91 the list using the addWidget() function, or inserted at a given -
92 index using the insertWidget() function. The removeWidget() -
93 function removes a widget from the stacked widget. The number of -
94 widgets contained in the stacked widget, can -
95 be obtained using the count() function. -
96 -
97 The widget() function returns the widget at a given index -
98 position. The index of the widget that is shown on screen is given -
99 by currentIndex() and can be changed using setCurrentIndex(). In a -
100 similar manner, the currently shown widget can be retrieved using -
101 the currentWidget() function, and altered using the -
102 setCurrentWidget() function. -
103 -
104 Whenever the current widget in the stacked widget changes or a -
105 widget is removed from the stacked widget, the currentChanged() -
106 and widgetRemoved() signals are emitted respectively. -
107 -
108 \sa QStackedLayout, QTabWidget, {Config Dialog Example} -
109*/ -
110 -
111/*! -
112 \fn void QStackedWidget::currentChanged(int index) -
113 -
114 This signal is emitted whenever the current widget changes. -
115 -
116 The parameter holds the \a index of the new current widget, or -1 -
117 if there isn't a new one (for example, if there are no widgets in -
118 the QStackedWidget). -
119 -
120 \sa currentWidget(), setCurrentWidget() -
121*/ -
122 -
123/*! -
124 \fn void QStackedWidget::widgetRemoved(int index) -
125 -
126 This signal is emitted whenever a widget is removed. The widget's -
127 \a index is passed as parameter. -
128 -
129 \sa removeWidget() -
130*/ -
131 -
132/*! -
133 Constructs a QStackedWidget with the given \a parent. -
134 -
135 \sa addWidget(), insertWidget() -
136*/ -
137QStackedWidget::QStackedWidget(QWidget *parent) -
138 : QFrame(*new QStackedWidgetPrivate, parent) -
139{ -
140 Q_D(QStackedWidget);
executed (the execution status of this line is deduced): QStackedWidgetPrivate * const d = d_func();
-
141 d->layout = new QStackedLayout(this);
executed (the execution status of this line is deduced): d->layout = new QStackedLayout(this);
-
142 connect(d->layout, SIGNAL(widgetRemoved(int)), this, SIGNAL(widgetRemoved(int)));
executed (the execution status of this line is deduced): connect(d->layout, "2""widgetRemoved(int)", this, "2""widgetRemoved(int)");
-
143 connect(d->layout, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));
executed (the execution status of this line is deduced): connect(d->layout, "2""currentChanged(int)", this, "2""currentChanged(int)");
-
144}
executed: }
Execution Count:232
232
145 -
146/*! -
147 Destroys this stacked widget, and frees any allocated resources. -
148*/ -
149QStackedWidget::~QStackedWidget() -
150{ -
151} -
152 -
153/*! -
154 Appends the given \a widget to the QStackedWidget and returns the -
155 index position. Ownership of \a widget is passed on to the -
156 QStackedWidget. -
157 -
158 If the QStackedWidget is empty before this function is called, -
159 \a widget becomes the current widget. -
160 -
161 \sa insertWidget(), removeWidget(), setCurrentWidget() -
162*/ -
163int QStackedWidget::addWidget(QWidget *widget) -
164{ -
165 return d_func()->layout->addWidget(widget);
executed: return d_func()->layout->addWidget(widget);
Execution Count:382
382
166} -
167 -
168/*! -
169 Inserts the given \a widget at the given \a index in the -
170 QStackedWidget. Ownership of \a widget is passed on to the -
171 QStackedWidget. If \a index is out of range, the \a widget is -
172 appended (in which case it is the actual index of the \a widget -
173 that is returned). -
174 -
175 If the QStackedWidget was empty before this function is called, -
176 the given \a widget becomes the current widget. -
177 -
178 Inserting a new widget at an index less than or equal to the current index -
179 will increment the current index, but keep the current widget. -
180 -
181 \sa addWidget(), removeWidget(), setCurrentWidget() -
182*/ -
183int QStackedWidget::insertWidget(int index, QWidget *widget) -
184{ -
185 return d_func()->layout->insertWidget(index, widget);
executed: return d_func()->layout->insertWidget(index, widget);
Execution Count:53
53
186} -
187 -
188/*! -
189 Removes \a widget from the QStackedWidget. i.e., \a widget is \e -
190 not deleted but simply removed from the stacked layout, causing it -
191 to be hidden. -
192 -
193 \b{Note:} Ownership of \a widget reverts to the application. -
194 -
195 \sa addWidget(), insertWidget(), currentWidget() -
196*/ -
197void QStackedWidget::removeWidget(QWidget *widget) -
198{ -
199 d_func()->layout->removeWidget(widget);
executed (the execution status of this line is deduced): d_func()->layout->removeWidget(widget);
-
200}
executed: }
Execution Count:20
20
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);
executed (the execution status of this line is deduced): d_func()->layout->setCurrentIndex(index);
-
217}
executed: }
Execution Count:262
262
218 -
219int QStackedWidget::currentIndex() const -
220{ -
221 return d_func()->layout->currentIndex();
executed: return d_func()->layout->currentIndex();
Execution Count:3
3
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();
executed: return d_func()->layout->currentWidget();
Execution Count:227
227
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);
executed (the execution status of this line is deduced): QStackedWidgetPrivate * const d = d_func();
-
246 if (d->layout->indexOf(widget) == -1) {
partially evaluated: d->layout->indexOf(widget) == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:130
0-130
247 qWarning("QStackedWidget::setCurrentWidget: widget %p not contained in stack", widget);
never executed (the execution status of this line is deduced): QMessageLogger("widgets/qstackedwidget.cpp", 247, __PRETTY_FUNCTION__).warning("QStackedWidget::setCurrentWidget: widget %p not contained in stack", widget);
-
248 return;
never executed: return;
0
249 } -
250 d->layout->setCurrentWidget(widget);
executed (the execution status of this line is deduced): d->layout->setCurrentWidget(widget);
-
251}
executed: }
Execution Count:130
130
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);
executed: return d_func()->layout->indexOf(widget);
Execution Count:18
18
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);
executed: return d_func()->layout->widget(index);
Execution Count:53
53
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();
executed: return d_func()->layout->count();
Execution Count:85
85
286} -
287 -
288/*! \reimp */ -
289bool QStackedWidget::event(QEvent *e) -
290{ -
291 return QFrame::event(e);
executed: return QFrame::event(e);
Execution Count:2088
2088
292} -
293 -
294QT_END_NAMESPACE -
295 -
296#endif // QT_NO_STACKEDWIDGET -
297 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial