kernel/qstackedlayout.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2012 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 "qstackedlayout.h" -
43#include "qlayout_p.h" -
44 -
45#include <qlist.h> -
46#include <qwidget.h> -
47#include "private/qlayoutengine_p.h" -
48 -
49QT_BEGIN_NAMESPACE -
50 -
51class QStackedLayoutPrivate : public QLayoutPrivate -
52{ -
53 Q_DECLARE_PUBLIC(QStackedLayout) -
54public: -
55 QStackedLayoutPrivate() : index(-1), stackingMode(QStackedLayout::StackOne) {}
executed: }
Execution Count:164
164
56 QList<QLayoutItem *> list; -
57 int index; -
58 QStackedLayout::StackingMode stackingMode; -
59}; -
60 -
61/*! -
62 \class QStackedLayout -
63 -
64 \brief The QStackedLayout class provides a stack of widgets where -
65 only one widget is visible at a time. -
66 -
67 \ingroup geomanagement -
68 \inmodule QtWidgets -
69 -
70 QStackedLayout can be used to create a user interface similar to -
71 the one provided by QTabWidget. There is also a convenience -
72 QStackedWidget class built on top of QStackedLayout. -
73 -
74 A QStackedLayout can be populated with a number of child widgets -
75 ("pages"). For example: -
76 -
77 \snippet qstackedlayout/main.cpp 0 -
78 \codeline -
79 \snippet qstackedlayout/main.cpp 2 -
80 \snippet qstackedlayout/main.cpp 3 -
81 -
82 QStackedLayout provides no intrinsic means for the user to switch -
83 page. This is typically done through a QComboBox or a QListWidget -
84 that stores the titles of the QStackedLayout's pages. For -
85 example: -
86 -
87 \snippet qstackedlayout/main.cpp 1 -
88 -
89 When populating a layout, the widgets are added to an internal -
90 list. The indexOf() function returns the index of a widget in that -
91 list. The widgets can either be added to the end of the list using -
92 the addWidget() function, or inserted at a given index using the -
93 insertWidget() function. The removeWidget() function removes the -
94 widget at the given index from the layout. The number of widgets -
95 contained in the layout, can be obtained using the count() -
96 function. -
97 -
98 The widget() function returns the widget at a given index -
99 position. The index of the widget that is shown on screen is given -
100 by currentIndex() and can be changed using setCurrentIndex(). In a -
101 similar manner, the currently shown widget can be retrieved using -
102 the currentWidget() function, and altered using the -
103 setCurrentWidget() function. -
104 -
105 Whenever the current widget in the layout changes or a widget is -
106 removed from the layout, the currentChanged() and widgetRemoved() -
107 signals are emitted respectively. -
108 -
109 \sa QStackedWidget, QTabWidget -
110*/ -
111 -
112/*! -
113 \fn void QStackedLayout::currentChanged(int index) -
114 -
115 This signal is emitted whenever the current widget in the layout -
116 changes. The \a index specifies the index of the new current -
117 widget, or -1 if there isn't a new one (for example, if there -
118 are no widgets in the QStackedLayout) -
119 -
120 \sa currentWidget(), setCurrentWidget() -
121*/ -
122 -
123/*! -
124 \fn void QStackedLayout::widgetRemoved(int index) -
125 -
126 This signal is emitted whenever a widget is removed from the -
127 layout. The widget's \a index is passed as parameter. -
128 -
129 \sa removeWidget() -
130*/ -
131 -
132/*! -
133 \fn QWidget *QStackedLayout::widget() -
134 \internal -
135*/ -
136 -
137/*! -
138 Constructs a QStackedLayout with no parent. -
139 -
140 This QStackedLayout must be installed on a widget later on to -
141 become effective. -
142 -
143 \sa addWidget(), insertWidget() -
144*/ -
145QStackedLayout::QStackedLayout() -
146 : QLayout(*new QStackedLayoutPrivate, 0, 0) -
147{ -
148}
executed: }
Execution Count:2
2
149 -
150/*! -
151 Constructs a new QStackedLayout with the given \a parent. -
152 -
153 This layout will install itself on the \a parent widget and -
154 manage the geometry of its children. -
155*/ -
156QStackedLayout::QStackedLayout(QWidget *parent) -
157 : QLayout(*new QStackedLayoutPrivate, 0, parent) -
158{ -
159}
executed: }
Execution Count:162
162
160 -
161/*! -
162 Constructs a new QStackedLayout and inserts it into -
163 the given \a parentLayout. -
164*/ -
165QStackedLayout::QStackedLayout(QLayout *parentLayout) -
166 : QLayout(*new QStackedLayoutPrivate, parentLayout, 0) -
167{ -
168}
never executed: }
0
169 -
170/*! -
171 Destroys this QStackedLayout. Note that the layout's widgets are -
172 \e not destroyed. -
173*/ -
174QStackedLayout::~QStackedLayout() -
175{ -
176 Q_D(QStackedLayout);
executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func();
-
177 qDeleteAll(d->list);
executed (the execution status of this line is deduced): qDeleteAll(d->list);
-
178}
executed: }
Execution Count:161
161
179 -
180/*! -
181 Adds the given \a widget to the end of this layout and returns the -
182 index position of the \a widget. -
183 -
184 If the QStackedLayout is empty before this function is called, -
185 the given \a widget becomes the current widget. -
186 -
187 \sa insertWidget(), removeWidget(), setCurrentWidget() -
188*/ -
189int QStackedLayout::addWidget(QWidget *widget) -
190{ -
191 Q_D(QStackedLayout);
executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func();
-
192 return insertWidget(d->list.count(), widget);
executed: return insertWidget(d->list.count(), widget);
Execution Count:255
255
193} -
194 -
195/*! -
196 Inserts the given \a widget at the given \a index in this -
197 QStackedLayout. If \a index is out of range, the widget is -
198 appended (in which case it is the actual index of the \a widget -
199 that is returned). -
200 -
201 If the QStackedLayout is empty before this function is called, the -
202 given \a widget becomes the current widget. -
203 -
204 Inserting a new widget at an index less than or equal to the current index -
205 will increment the current index, but keep the current widget. -
206 -
207 \sa addWidget(), removeWidget(), setCurrentWidget() -
208*/ -
209int QStackedLayout::insertWidget(int index, QWidget *widget) -
210{ -
211 Q_D(QStackedLayout);
executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func();
-
212 addChildWidget(widget);
executed (the execution status of this line is deduced): addChildWidget(widget);
-
213 index = qMin(index, d->list.count());
executed (the execution status of this line is deduced): index = qMin(index, d->list.count());
-
214 if (index < 0)
evaluated: index < 0
TRUEFALSE
yes
Evaluation Count:52
yes
Evaluation Count:256
52-256
215 index = d->list.count();
executed: index = d->list.count();
Execution Count:52
52
216 QWidgetItem *wi = QLayoutPrivate::createWidgetItem(this, widget);
executed (the execution status of this line is deduced): QWidgetItem *wi = QLayoutPrivate::createWidgetItem(this, widget);
-
217 d->list.insert(index, wi);
executed (the execution status of this line is deduced): d->list.insert(index, wi);
-
218 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
219 if (d->index < 0) {
evaluated: d->index < 0
TRUEFALSE
yes
Evaluation Count:156
yes
Evaluation Count:152
152-156
220 setCurrentIndex(index);
executed (the execution status of this line is deduced): setCurrentIndex(index);
-
221 } else {
executed: }
Execution Count:156
156
222 if (index <= d->index)
evaluated: index <= d->index
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:151
1-151
223 ++d->index;
executed: ++d->index;
Execution Count:1
1
224 if (d->stackingMode == StackOne)
partially evaluated: d->stackingMode == StackOne
TRUEFALSE
yes
Evaluation Count:152
no
Evaluation Count:0
0-152
225 widget->hide();
executed: widget->hide();
Execution Count:152
152
226 widget->lower();
executed (the execution status of this line is deduced): widget->lower();
-
227 }
executed: }
Execution Count:152
152
228 return index;
executed: return index;
Execution Count:308
308
229} -
230 -
231/*! -
232 \reimp -
233*/ -
234QLayoutItem *QStackedLayout::itemAt(int index) const -
235{ -
236 Q_D(const QStackedLayout);
executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func();
-
237 return d->list.value(index);
executed: return d->list.value(index);
Execution Count:1445
1445
238} -
239 -
240// Code that enables proper handling of the case that takeAt() is -
241// called somewhere inside QObject destructor (can't call hide() -
242// on the object then) -
243 -
244class QtFriendlyLayoutWidget : public QWidget -
245{ -
246public: -
247 inline bool wasDeleted() const { return d_ptr->wasDeleted; }
executed: return d_ptr->wasDeleted;
Execution Count:33
33
248}; -
249 -
250static bool qt_wasDeleted(const QWidget *w) { return static_cast<const QtFriendlyLayoutWidget*>(w)->wasDeleted(); }
executed: return static_cast<const QtFriendlyLayoutWidget*>(w)->wasDeleted();
Execution Count:33
33
251 -
252 -
253/*! -
254 \reimp -
255*/ -
256QLayoutItem *QStackedLayout::takeAt(int index) -
257{ -
258 Q_D(QStackedLayout);
executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func();
-
259 if (index <0 || index >= d->list.size())
partially evaluated: index <0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
partially evaluated: index >= d->list.size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
0-33
260 return 0;
never executed: return 0;
0
261 QLayoutItem *item = d->list.takeAt(index);
executed (the execution status of this line is deduced): QLayoutItem *item = d->list.takeAt(index);
-
262 if (index == d->index) {
evaluated: index == d->index
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:8
8-25
263 d->index = -1;
executed (the execution status of this line is deduced): d->index = -1;
-
264 if ( d->list.count() > 0 ) {
evaluated: d->list.count() > 0
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:16
9-16
265 int newIndex = (index == d->list.count()) ? index-1 : index;
evaluated: (index == d->list.count())
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:5
4-5
266 setCurrentIndex(newIndex);
executed (the execution status of this line is deduced): setCurrentIndex(newIndex);
-
267 } else {
executed: }
Execution Count:9
9
268 emit currentChanged(-1);
executed (the execution status of this line is deduced): currentChanged(-1);
-
269 }
executed: }
Execution Count:16
16
270 } else if (index < d->index) {
evaluated: index < d->index
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:1
1-7
271 --d->index;
executed (the execution status of this line is deduced): --d->index;
-
272 }
executed: }
Execution Count:7
7
273 emit widgetRemoved(index);
executed (the execution status of this line is deduced): widgetRemoved(index);
-
274 if (item->widget() && !qt_wasDeleted(item->widget()))
partially evaluated: item->widget()
TRUEFALSE
yes
Evaluation Count:33
no
Evaluation Count:0
evaluated: !qt_wasDeleted(item->widget())
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:5
0-33
275 item->widget()->hide();
executed: item->widget()->hide();
Execution Count:28
28
276 return item;
executed: return item;
Execution Count:33
33
277} -
278 -
279/*! -
280 \property QStackedLayout::currentIndex -
281 \brief the index position of the widget that is visible -
282 -
283 The current index is -1 if there is no current widget. -
284 -
285 \sa currentWidget(), indexOf() -
286*/ -
287void QStackedLayout::setCurrentIndex(int index) -
288{ -
289 Q_D(QStackedLayout);
executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func();
-
290 QWidget *prev = currentWidget();
executed (the execution status of this line is deduced): QWidget *prev = currentWidget();
-
291 QWidget *next = widget(index);
executed (the execution status of this line is deduced): QWidget *next = widget(index);
-
292 if (!next || next == prev)
evaluated: !next
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:435
evaluated: next == prev
TRUEFALSE
yes
Evaluation Count:232
yes
Evaluation Count:203
6-435
293 return;
executed: return;
Execution Count:238
238
294 -
295 bool reenableUpdates = false;
executed (the execution status of this line is deduced): bool reenableUpdates = false;
-
296 QWidget *parent = parentWidget();
executed (the execution status of this line is deduced): QWidget *parent = parentWidget();
-
297 -
298 if (parent && parent->updatesEnabled()) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:2
partially evaluated: parent->updatesEnabled()
TRUEFALSE
yes
Evaluation Count:201
no
Evaluation Count:0
0-201
299 reenableUpdates = true;
executed (the execution status of this line is deduced): reenableUpdates = true;
-
300 parent->setUpdatesEnabled(false);
executed (the execution status of this line is deduced): parent->setUpdatesEnabled(false);
-
301 }
executed: }
Execution Count:201
201
302 -
303 QWidget *fw = parent ? parent->window()->focusWidget() : 0;
evaluated: parent
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:2
2-201
304 if (prev) {
evaluated: prev
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:165
38-165
305 prev->clearFocus();
executed (the execution status of this line is deduced): prev->clearFocus();
-
306 if (d->stackingMode == StackOne)
partially evaluated: d->stackingMode == StackOne
TRUEFALSE
yes
Evaluation Count:38
no
Evaluation Count:0
0-38
307 prev->hide();
executed: prev->hide();
Execution Count:38
38
308 }
executed: }
Execution Count:38
38
309 -
310 d->index = index;
executed (the execution status of this line is deduced): d->index = index;
-
311 next->raise();
executed (the execution status of this line is deduced): next->raise();
-
312 next->show();
executed (the execution status of this line is deduced): next->show();
-
313 -
314 // try to move focus onto the incoming widget if focus -
315 // was somewhere on the outgoing widget. -
316 -
317 if (parent) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:2
2-201
318 if (fw && (prev && prev->isAncestorOf(fw))) { // focus was on old page
evaluated: fw
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:179
evaluated: prev
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:1
evaluated: prev->isAncestorOf(fw)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:16
1-179
319 // look for the best focus widget we can find -
320 if (QWidget *nfw = next->focusWidget())
evaluated: QWidget *nfw = next->focusWidget()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:3
2-3
321 nfw->setFocus();
executed: nfw->setFocus();
Execution Count:2
2
322 else { -
323 // second best: first child widget in the focus chain -
324 QWidget *i = fw;
executed (the execution status of this line is deduced): QWidget *i = fw;
-
325 while ((i = i->nextInFocusChain()) != fw) {
partially evaluated: (i = i->nextInFocusChain()) != fw
TRUEFALSE
yes
Evaluation Count:43
no
Evaluation Count:0
0-43
326 if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
evaluated: ((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:32
11-32
327 && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
evaluated: !i->focusProxy()
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:2
evaluated: i->isVisibleTo(next)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:4
partially evaluated: i->isEnabled()
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-9
328 && next->isAncestorOf(i)) {
evaluated: next->isAncestorOf(i)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
329 i->setFocus();
executed (the execution status of this line is deduced): i->setFocus();
-
330 break;
executed: break;
Execution Count:3
3
331 } -
332 }
executed: }
Execution Count:40
40
333 // third best: incoming widget -
334 if (i == fw )
partially evaluated: i == fw
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
335 next->setFocus();
never executed: next->setFocus();
0
336 }
executed: }
Execution Count:3
3
337 } -
338 }
executed: }
Execution Count:201
201
339 if (reenableUpdates)
evaluated: reenableUpdates
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:2
2-201
340 parent->setUpdatesEnabled(true);
executed: parent->setUpdatesEnabled(true);
Execution Count:201
201
341 emit currentChanged(index);
executed (the execution status of this line is deduced): currentChanged(index);
-
342}
executed: }
Execution Count:203
203
343 -
344int QStackedLayout::currentIndex() const -
345{ -
346 Q_D(const QStackedLayout);
executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func();
-
347 return d->index;
executed: return d->index;
Execution Count:19
19
348} -
349 -
350 -
351/*! -
352 \fn void QStackedLayout::setCurrentWidget(QWidget *widget) -
353 -
354 Sets the current widget to be the specified \a widget. The new -
355 current widget must already be contained in this stacked layout. -
356 -
357 \sa setCurrentIndex(), currentWidget() -
358 */ -
359void QStackedLayout::setCurrentWidget(QWidget *widget) -
360{ -
361 int index = indexOf(widget);
executed (the execution status of this line is deduced): int index = indexOf(widget);
-
362 if (index == -1) {
evaluated: index == -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:77
1-77
363 qWarning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget);
executed (the execution status of this line is deduced): QMessageLogger("kernel/qstackedlayout.cpp", 363, __PRETTY_FUNCTION__).warning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget);
-
364 return;
executed: return;
Execution Count:1
1
365 } -
366 setCurrentIndex(index);
executed (the execution status of this line is deduced): setCurrentIndex(index);
-
367}
executed: }
Execution Count:77
77
368 -
369 -
370/*! -
371 Returns the current widget, or 0 if there are no widgets in this -
372 layout. -
373 -
374 \sa currentIndex(), setCurrentWidget() -
375*/ -
376QWidget *QStackedLayout::currentWidget() const -
377{ -
378 Q_D(const QStackedLayout);
executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func();
-
379 return d->index >= 0 ? d->list.at(d->index)->widget() : 0;
executed: return d->index >= 0 ? d->list.at(d->index)->widget() : 0;
Execution Count:746
746
380} -
381 -
382/*! -
383 Returns the widget at the given \a index, or 0 if there is no -
384 widget at the given position. -
385 -
386 \sa currentWidget(), indexOf() -
387*/ -
388QWidget *QStackedLayout::widget(int index) const -
389{ -
390 Q_D(const QStackedLayout);
executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func();
-
391 if (index < 0 || index >= d->list.size())
evaluated: index < 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:489
evaluated: index >= d->list.size()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:485
4-489
392 return 0;
executed: return 0;
Execution Count:9
9
393 return d->list.at(index)->widget();
executed: return d->list.at(index)->widget();
Execution Count:485
485
394} -
395 -
396/*! -
397 \property QStackedLayout::count -
398 \brief the number of widgets contained in the layout -
399 -
400 \sa currentIndex(), widget() -
401*/ -
402int QStackedLayout::count() const -
403{ -
404 Q_D(const QStackedLayout);
executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func();
-
405 return d->list.size();
executed: return d->list.size();
Execution Count:621
621
406} -
407 -
408 -
409/*! -
410 \reimp -
411*/ -
412void QStackedLayout::addItem(QLayoutItem *item) -
413{ -
414 QWidget *widget = item->widget();
never executed (the execution status of this line is deduced): QWidget *widget = item->widget();
-
415 if (widget) {
never evaluated: widget
0
416 addWidget(widget);
never executed (the execution status of this line is deduced): addWidget(widget);
-
417 delete item;
never executed (the execution status of this line is deduced): delete item;
-
418 } else {
never executed: }
0
419 qWarning("QStackedLayout::addItem: Only widgets can be added");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qstackedlayout.cpp", 419, __PRETTY_FUNCTION__).warning("QStackedLayout::addItem: Only widgets can be added");
-
420 }
never executed: }
0
421} -
422 -
423/*! -
424 \reimp -
425*/ -
426QSize QStackedLayout::sizeHint() const -
427{ -
428 Q_D(const QStackedLayout);
executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func();
-
429 QSize s(0, 0);
executed (the execution status of this line is deduced): QSize s(0, 0);
-
430 int n = d->list.count();
executed (the execution status of this line is deduced): int n = d->list.count();
-
431 -
432 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:354
yes
Evaluation Count:193
193-354
433 if (QWidget *widget = d->list.at(i)->widget()) {
partially evaluated: QWidget *widget = d->list.at(i)->widget()
TRUEFALSE
yes
Evaluation Count:354
no
Evaluation Count:0
0-354
434 QSize ws(widget->sizeHint());
executed (the execution status of this line is deduced): QSize ws(widget->sizeHint());
-
435 if (widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)
partially evaluated: widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:354
0-354
436 ws.setWidth(0);
never executed: ws.setWidth(0);
0
437 if (widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)
partially evaluated: widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:354
0-354
438 ws.setHeight(0);
never executed: ws.setHeight(0);
0
439 s = s.expandedTo(ws);
executed (the execution status of this line is deduced): s = s.expandedTo(ws);
-
440 }
executed: }
Execution Count:354
354
441 return s;
executed: return s;
Execution Count:193
193
442} -
443 -
444/*! -
445 \reimp -
446*/ -
447QSize QStackedLayout::minimumSize() const -
448{ -
449 Q_D(const QStackedLayout);
executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func();
-
450 QSize s(0, 0);
executed (the execution status of this line is deduced): QSize s(0, 0);
-
451 int n = d->list.count();
executed (the execution status of this line is deduced): int n = d->list.count();
-
452 -
453 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:408
yes
Evaluation Count:236
236-408
454 if (QWidget *widget = d->list.at(i)->widget())
partially evaluated: QWidget *widget = d->list.at(i)->widget()
TRUEFALSE
yes
Evaluation Count:408
no
Evaluation Count:0
0-408
455 s = s.expandedTo(qSmartMinSize(widget));
executed: s = s.expandedTo(qSmartMinSize(widget));
Execution Count:408
408
456 return s;
executed: return s;
Execution Count:236
236
457} -
458 -
459/*! -
460 \reimp -
461*/ -
462void QStackedLayout::setGeometry(const QRect &rect) -
463{ -
464 Q_D(QStackedLayout);
executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func();
-
465 switch (d->stackingMode) { -
466 case StackOne: -
467 if (QWidget *widget = currentWidget())
evaluated: QWidget *widget = currentWidget()
TRUEFALSE
yes
Evaluation Count:128
yes
Evaluation Count:7
7-128
468 widget->setGeometry(rect);
executed: widget->setGeometry(rect);
Execution Count:128
128
469 break;
executed: break;
Execution Count:135
135
470 case StackAll: -
471 if (const int n = d->list.count())
never evaluated: const int n = d->list.count()
0
472 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
473 if (QWidget *widget = d->list.at(i)->widget())
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
474 widget->setGeometry(rect);
never executed: widget->setGeometry(rect);
0
475 break;
never executed: break;
0
476 } -
477}
executed: }
Execution Count:135
135
478 -
479/*! -
480 \reimp -
481*/ -
482bool QStackedLayout::hasHeightForWidth() const -
483{ -
484 const int n = count();
executed (the execution status of this line is deduced): const int n = count();
-
485 -
486 for (int i = 0; i < n; ++i) {
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:852
yes
Evaluation Count:385
385-852
487 if (QLayoutItem *item = itemAt(i)) {
partially evaluated: QLayoutItem *item = itemAt(i)
TRUEFALSE
yes
Evaluation Count:852
no
Evaluation Count:0
0-852
488 if (item->hasHeightForWidth())
evaluated: item->hasHeightForWidth()
TRUEFALSE
yes
Evaluation Count:102
yes
Evaluation Count:750
102-750
489 return true;
executed: return true;
Execution Count:102
102
490 }
executed: }
Execution Count:750
750
491 }
executed: }
Execution Count:750
750
492 return false;
executed: return false;
Execution Count:385
385
493} -
494 -
495/*! -
496 \reimp -
497*/ -
498int QStackedLayout::heightForWidth(int width) const -
499{ -
500 const int n = count();
executed (the execution status of this line is deduced): const int n = count();
-
501 -
502 int hfw = 0;
executed (the execution status of this line is deduced): int hfw = 0;
-
503 for (int i = 0; i < n; ++i) {
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:47
yes
Evaluation Count:44
44-47
504 if (QLayoutItem *item = itemAt(i)) {
partially evaluated: QLayoutItem *item = itemAt(i)
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
505 if (QWidget *w = item->widget())
partially evaluated: QWidget *w = item->widget()
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
506 /* -
507 Note: Does not query the layout item, but bypasses it and asks the widget -
508 directly. This is consistent with how QStackedLayout::sizeHint() is -
509 implemented. This also avoids an issue where QWidgetItem::heightForWidth() -
510 returns -1 if the widget is hidden. -
511 */ -
512 hfw = qMax(hfw, w->heightForWidth(width));
executed: hfw = qMax(hfw, w->heightForWidth(width));
Execution Count:47
47
513 }
executed: }
Execution Count:47
47
514 }
executed: }
Execution Count:47
47
515 hfw = qMax(hfw, minimumSize().height());
executed (the execution status of this line is deduced): hfw = qMax(hfw, minimumSize().height());
-
516 return hfw;
executed: return hfw;
Execution Count:44
44
517} -
518 -
519/*! -
520 \enum QStackedLayout::StackingMode -
521 \since 4.4 -
522 -
523 This enum specifies how the layout handles its child widgets -
524 regarding their visibility. -
525 -
526 \value StackOne -
527 Only the current widget is visible. This is the default. -
528 -
529 \value StackAll -
530 All widgets are visible. The current widget is merely raised. -
531*/ -
532 -
533 -
534/*! -
535 \property QStackedLayout::stackingMode -
536 \brief determines the way visibility of child widgets are handled. -
537 \since 4.4 -
538 -
539 The default value is StackOne. Setting the property to StackAll -
540 allows you to make use of the layout for overlay widgets -
541 that do additional drawing on top of other widgets, for example, -
542 graphical editors. -
543*/ -
544 -
545QStackedLayout::StackingMode QStackedLayout::stackingMode() const -
546{ -
547 Q_D(const QStackedLayout);
never executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func();
-
548 return d->stackingMode;
never executed: return d->stackingMode;
0
549} -
550 -
551void QStackedLayout::setStackingMode(StackingMode stackingMode) -
552{ -
553 Q_D(QStackedLayout);
never executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func();
-
554 if (d->stackingMode == stackingMode)
never evaluated: d->stackingMode == stackingMode
0
555 return;
never executed: return;
0
556 d->stackingMode = stackingMode;
never executed (the execution status of this line is deduced): d->stackingMode = stackingMode;
-
557 -
558 const int n = d->list.count();
never executed (the execution status of this line is deduced): const int n = d->list.count();
-
559 if (n == 0)
never evaluated: n == 0
0
560 return;
never executed: return;
0
561 -
562 switch (d->stackingMode) { -
563 case StackOne: -
564 if (const int idx = currentIndex())
never evaluated: const int idx = currentIndex()
0
565 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
566 if (QWidget *widget = d->list.at(i)->widget())
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
567 widget->setVisible(i == idx);
never executed: widget->setVisible(i == idx);
0
568 break;
never executed: break;
0
569 case StackAll: { // Turn overlay on: Make sure all widgets are the same size -
570 QRect geometry;
never executed (the execution status of this line is deduced): QRect geometry;
-
571 if (const QWidget *widget = currentWidget())
never evaluated: const QWidget *widget = currentWidget()
0
572 geometry = widget->geometry();
never executed: geometry = widget->geometry();
0
573 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
574 if (QWidget *widget = d->list.at(i)->widget()) {
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
575 if (!geometry.isNull())
never evaluated: !geometry.isNull()
0
576 widget->setGeometry(geometry);
never executed: widget->setGeometry(geometry);
0
577 widget->setVisible(true);
never executed (the execution status of this line is deduced): widget->setVisible(true);
-
578 }
never executed: }
0
579 } -
580 break;
never executed: break;
0
581 } -
582}
never executed: }
0
583 -
584QT_END_NAMESPACE -
585 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial