OpenCoverage

qlayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qlayout.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 "qlayout.h"-
41-
42#include "qapplication.h"-
43#include "qlayoutengine_p.h"-
44#include "qmenubar.h"-
45#include "qtoolbar.h"-
46#include "qsizegrip.h"-
47#include "qevent.h"-
48#include "qstyle.h"-
49#include "qvariant.h"-
50#include "qwidget_p.h"-
51#include "qlayout_p.h"-
52#include "qformlayout.h"-
53-
54QT_BEGIN_NAMESPACE-
55-
56static int menuBarHeightForWidth(QWidget *menubar, int w)-
57{-
58 if (menubar && !menubar->isHidden() && !menubar->isWindow()) {
menubarDescription
TRUEnever evaluated
FALSEnever evaluated
!menubar->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
!menubar->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
59 int result = menubar->heightForWidth(qMax(w, menubar->minimumWidth()));-
60 if (result == -1)
result == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
61 result = menubar->sizeHint().height();
never executed: result = menubar->sizeHint().height();
0
62 const int min = qSmartMinSize(menubar).height();-
63 result = qBound(min, result, menubar->maximumSize().height());-
64 if (result != -1)
result != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
65 return result;
never executed: return result;
0
66 }
never executed: end of block
0
67 return 0;
never executed: return 0;
0
68}-
69-
70/*!-
71 \class QLayout-
72 \brief The QLayout class is the base class of geometry managers.-
73-
74 \ingroup geomanagement-
75 \inmodule QtWidgets-
76-
77 This is an abstract base class inherited by the concrete classes-
78 QBoxLayout, QGridLayout, QFormLayout, and QStackedLayout.-
79-
80 For users of QLayout subclasses or of QMainWindow there is seldom-
81 any need to use the basic functions provided by QLayout, such as-
82 setSizeConstraint() or setMenuBar(). See \l{Layout Management}-
83 for more information.-
84-
85 To make your own layout manager, implement the functions-
86 addItem(), sizeHint(), setGeometry(), itemAt() and takeAt(). You-
87 should also implement minimumSize() to ensure your layout isn't-
88 resized to zero size if there is too little space. To support-
89 children whose heights depend on their widths, implement-
90 hasHeightForWidth() and heightForWidth(). See the-
91 \l{layouts/borderlayout}{Border Layout} and-
92 \l{layouts/flowlayout}{Flow Layout} examples for-
93 more information about implementing custom layout managers.-
94-
95 Geometry management stops when the layout manager is deleted.-
96-
97 \sa QLayoutItem, {Layout Management}, {Basic Layouts Example},-
98 {Border Layout Example}, {Flow Layout Example}-
99*/-
100-
101-
102/*!-
103 Constructs a new top-level QLayout, with parent \a parent.-
104 \a parent may not be 0.-
105-
106 There can be only one top-level layout for a widget. It is-
107 returned by QWidget::layout().-
108*/-
109QLayout::QLayout(QWidget *parent)-
110 : QObject(*new QLayoutPrivate, parent)-
111{-
112 if (!parent)
!parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
113 return;
never executed: return;
0
114 parent->setLayout(this);-
115}
never executed: end of block
0
116-
117/*!-
118 Constructs a new child QLayout.-
119-
120 This layout has to be inserted into another layout before geometry-
121 management will work.-
122*/-
123QLayout::QLayout()-
124 : QObject(*new QLayoutPrivate, 0)-
125{-
126}
never executed: end of block
0
127-
128-
129/*! \internal-
130 */-
131QLayout::QLayout(QLayoutPrivate &dd, QLayout *lay, QWidget *w)-
132 : QObject(dd, lay ? static_cast<QObject*>(lay) : static_cast<QObject*>(w))-
133{-
134 Q_D(QLayout);-
135 if (lay) {
layDescription
TRUEnever evaluated
FALSEnever evaluated
0
136 lay->addItem(this);-
137 } else if (w) {
never executed: end of block
wDescription
TRUEnever evaluated
FALSEnever evaluated
0
138 if (Q_UNLIKELY(w->layout())) {
__builtin_expe...out()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
139 qWarning("QLayout: Attempting to add QLayout \"%ls\" to %s \"%ls\", which"-
140 " already has a layout",-
141 qUtf16Printable(QObject::objectName()), w->metaObject()->className(),-
142 qUtf16Printable(w->objectName()));-
143 setParent(0);-
144 } else {
never executed: end of block
0
145 d->topLevel = true;-
146 w->d_func()->layout = this;-
147 QT_TRY {-
148 invalidate();-
149 } QT_CATCH(...) {
never executed: end of block
dead code: { w->d_func()->layout = 0; qt_noop(); }
-
150 w->d_func()->layout = 0;
dead code: { w->d_func()->layout = 0; qt_noop(); }
-
151 QT_RETHROW;
dead code: { w->d_func()->layout = 0; qt_noop(); }
-
152 }
dead code: { w->d_func()->layout = 0; qt_noop(); }
-
153 }-
154 }-
155}
never executed: end of block
0
156-
157QLayoutPrivate::QLayoutPrivate()-
158 : QObjectPrivate(), insideSpacing(-1), userLeftMargin(-1), userTopMargin(-1), userRightMargin(-1),-
159 userBottomMargin(-1), topLevel(false), enabled(true), activated(true), autoNewChild(false),-
160 constraint(QLayout::SetDefaultConstraint), menubar(0)-
161{-
162}
never executed: end of block
0
163-
164void QLayoutPrivate::getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const-
165{-
166 if (!result)
!resultDescription
TRUEnever evaluated
FALSEnever evaluated
0
167 return;
never executed: return;
0
168-
169 Q_Q(const QLayout);-
170 if (userMargin >= 0) {
userMargin >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
171 *result = userMargin;-
172 } else if (!topLevel) {
never executed: end of block
!topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
173 *result = 0;-
174 } else if (QWidget *pw = q->parentWidget()) {
never executed: end of block
QWidget *pw = ...parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
175 *result = pw->style()->pixelMetric(pm, 0, pw);-
176 } else {
never executed: end of block
0
177 *result = 0;-
178 }
never executed: end of block
0
179}-
180-
181// Static item factory functions that allow for hooking things in Designer-
182-
183QLayoutPrivate::QWidgetItemFactoryMethod QLayoutPrivate::widgetItemFactoryMethod = 0;-
184QLayoutPrivate::QSpacerItemFactoryMethod QLayoutPrivate::spacerItemFactoryMethod = 0;-
185-
186QWidgetItem *QLayoutPrivate::createWidgetItem(const QLayout *layout, QWidget *widget)-
187{-
188 if (widgetItemFactoryMethod)
widgetItemFactoryMethodDescription
TRUEnever evaluated
FALSEnever evaluated
0
189 if (QWidgetItem *wi = (*widgetItemFactoryMethod)(layout, widget))
QWidgetItem *w...ayout, widget)Description
TRUEnever evaluated
FALSEnever evaluated
0
190 return wi;
never executed: return wi;
0
191 return new QWidgetItemV2(widget);
never executed: return new QWidgetItemV2(widget);
0
192}-
193-
194QSpacerItem *QLayoutPrivate::createSpacerItem(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy)-
195{-
196 if (spacerItemFactoryMethod)
spacerItemFactoryMethodDescription
TRUEnever evaluated
FALSEnever evaluated
0
197 if (QSpacerItem *si = (*spacerItemFactoryMethod)(layout, w, h, hPolicy, vPolicy))
QSpacerItem *s...licy, vPolicy)Description
TRUEnever evaluated
FALSEnever evaluated
0
198 return si;
never executed: return si;
0
199 return new QSpacerItem(w, h, hPolicy, vPolicy);
never executed: return new QSpacerItem(w, h, hPolicy, vPolicy);
0
200}-
201-
202-
203-
204/*!-
205 \fn void QLayout::addItem(QLayoutItem *item)-
206-
207 Implemented in subclasses to add an \a item. How it is added is-
208 specific to each subclass.-
209-
210 This function is not usually called in application code. To add a widget-
211 to a layout, use the addWidget() function; to add a child layout, use the-
212 addLayout() function provided by the relevant QLayout subclass.-
213-
214 \b{Note:} The ownership of \a item is transferred to the layout, and it's-
215 the layout's responsibility to delete it.-
216-
217 \sa addWidget(), QBoxLayout::addLayout(), QGridLayout::addLayout()-
218*/-
219-
220/*!-
221 Adds widget \a w to this layout in a manner specific to the-
222 layout. This function uses addItem().-
223*/-
224void QLayout::addWidget(QWidget *w)-
225{-
226 addChildWidget(w);-
227 addItem(QLayoutPrivate::createWidgetItem(this, w));-
228}
never executed: end of block
0
229-
230-
231-
232/*!-
233 Sets the alignment for widget \a w to \a alignment and returns-
234 true if \a w is found in this layout (not including child-
235 layouts); otherwise returns \c false.-
236*/-
237bool QLayout::setAlignment(QWidget *w, Qt::Alignment alignment)-
238{-
239 int i = 0;-
240 QLayoutItem *item = itemAt(i);-
241 while (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
242 if (item->widget() == w) {
item->widget() == wDescription
TRUEnever evaluated
FALSEnever evaluated
0
243 item->setAlignment(alignment);-
244 invalidate();-
245 return true;
never executed: return true;
0
246 }-
247 ++i;-
248 item = itemAt(i);-
249 }
never executed: end of block
0
250 return false;
never executed: return false;
0
251}-
252-
253/*!-
254 \overload-
255-
256 Sets the alignment for the layout \a l to \a alignment and-
257 returns \c true if \a l is found in this layout (not including child-
258 layouts); otherwise returns \c false.-
259*/-
260bool QLayout::setAlignment(QLayout *l, Qt::Alignment alignment)-
261{-
262 int i = 0;-
263 QLayoutItem *item = itemAt(i);-
264 while (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
265 if (item->layout() == l) {
item->layout() == lDescription
TRUEnever evaluated
FALSEnever evaluated
0
266 item->setAlignment(alignment);-
267 invalidate();-
268 return true;
never executed: return true;
0
269 }-
270 ++i;-
271 item = itemAt(i);-
272 }
never executed: end of block
0
273 return false;
never executed: return false;
0
274}-
275-
276/*!-
277 \property QLayout::margin-
278 \brief the width of the outside border of the layout-
279 \obsolete-
280-
281 Use setContentsMargins() and getContentsMargins() instead.-
282-
283 \sa contentsRect(), spacing-
284*/-
285-
286/*!-
287 \obsolete-
288*/-
289int QLayout::margin() const-
290{-
291 int left, top, right, bottom;-
292 getContentsMargins(&left, &top, &right, &bottom);-
293 if (left == top && top == right && right == bottom) {
left == topDescription
TRUEnever evaluated
FALSEnever evaluated
top == rightDescription
TRUEnever evaluated
FALSEnever evaluated
right == bottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
294 return left;
never executed: return left;
0
295 } else {-
296 return -1;
never executed: return -1;
0
297 }-
298}-
299-
300/*!-
301 \property QLayout::spacing-
302 \brief the spacing between widgets inside the layout-
303-
304 If no value is explicitly set, the layout's spacing is inherited-
305 from the parent layout, or from the style settings for the parent-
306 widget.-
307-
308 For QGridLayout and QFormLayout, it is possible to set different horizontal and-
309 vertical spacings using \l{QGridLayout::}{setHorizontalSpacing()}-
310 and \l{QGridLayout::}{setVerticalSpacing()}. In that case,-
311 spacing() returns -1.-
312-
313 \sa contentsRect(), getContentsMargins(), QStyle::layoutSpacing(),-
314 QStyle::pixelMetric()-
315*/-
316-
317int QLayout::spacing() const-
318{-
319 if (const QBoxLayout* boxlayout = qobject_cast<const QBoxLayout*>(this)) {
const QBoxLayo...Layout*>(this)Description
TRUEnever evaluated
FALSEnever evaluated
0
320 return boxlayout->spacing();
never executed: return boxlayout->spacing();
0
321 } else if (const QGridLayout* gridlayout = qobject_cast<const QGridLayout*>(this)) {
const QGridLay...Layout*>(this)Description
TRUEnever evaluated
FALSEnever evaluated
0
322 return gridlayout->spacing();
never executed: return gridlayout->spacing();
0
323 } else if (const QFormLayout* formlayout = qobject_cast<const QFormLayout*>(this)) {
const QFormLay...Layout*>(this)Description
TRUEnever evaluated
FALSEnever evaluated
0
324 return formlayout->spacing();
never executed: return formlayout->spacing();
0
325 } else {-
326 Q_D(const QLayout);-
327 if (d->insideSpacing >=0) {
d->insideSpacing >=0Description
TRUEnever evaluated
FALSEnever evaluated
0
328 return d->insideSpacing;
never executed: return d->insideSpacing;
0
329 } else {-
330 // arbitrarily prefer horizontal spacing to vertical spacing-
331 return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing);
never executed: return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing);
0
332 }-
333 }-
334}-
335-
336/*!-
337 \obsolete-
338*/-
339void QLayout::setMargin(int margin)-
340{-
341 setContentsMargins(margin, margin, margin, margin);-
342}
never executed: end of block
0
343-
344void QLayout::setSpacing(int spacing)-
345{-
346 if (QBoxLayout* boxlayout = qobject_cast<QBoxLayout*>(this)) {
QBoxLayout* bo...Layout*>(this)Description
TRUEnever evaluated
FALSEnever evaluated
0
347 boxlayout->setSpacing(spacing);-
348 } else if (QGridLayout* gridlayout = qobject_cast<QGridLayout*>(this)) {
never executed: end of block
QGridLayout* g...Layout*>(this)Description
TRUEnever evaluated
FALSEnever evaluated
0
349 gridlayout->setSpacing(spacing);-
350 } else if (QFormLayout* formlayout = qobject_cast<QFormLayout*>(this)) {
never executed: end of block
QFormLayout* f...Layout*>(this)Description
TRUEnever evaluated
FALSEnever evaluated
0
351 formlayout->setSpacing(spacing);-
352 } else {
never executed: end of block
0
353 Q_D(QLayout);-
354 d->insideSpacing = spacing;-
355 invalidate();-
356 }
never executed: end of block
0
357}-
358-
359/*!-
360 \since 4.3-
361-
362 Sets the \a left, \a top, \a right, and \a bottom margins to use-
363 around the layout.-
364-
365 By default, QLayout uses the values provided by the style. On-
366 most platforms, the margin is 11 pixels in all directions.-
367-
368 \sa getContentsMargins(), QStyle::pixelMetric(),-
369 {QStyle::}{PM_LayoutLeftMargin},-
370 {QStyle::}{PM_LayoutTopMargin},-
371 {QStyle::}{PM_LayoutRightMargin},-
372 {QStyle::}{PM_LayoutBottomMargin}-
373*/-
374void QLayout::setContentsMargins(int left, int top, int right, int bottom)-
375{-
376 Q_D(QLayout);-
377-
378 if (d->userLeftMargin == left && d->userTopMargin == top &&
d->userLeftMargin == leftDescription
TRUEnever evaluated
FALSEnever evaluated
d->userTopMargin == topDescription
TRUEnever evaluated
FALSEnever evaluated
0
379 d->userRightMargin == right && d->userBottomMargin == bottom)
d->userRightMargin == rightDescription
TRUEnever evaluated
FALSEnever evaluated
d->userBottomMargin == bottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 return;
never executed: return;
0
381-
382 d->userLeftMargin = left;-
383 d->userTopMargin = top;-
384 d->userRightMargin = right;-
385 d->userBottomMargin = bottom;-
386 invalidate();-
387}
never executed: end of block
0
388-
389/*!-
390 \since 4.6-
391-
392 Sets the \a margins to use around the layout.-
393-
394 By default, QLayout uses the values provided by the style. On-
395 most platforms, the margin is 11 pixels in all directions.-
396-
397 \sa contentsMargins()-
398*/-
399void QLayout::setContentsMargins(const QMargins &margins)-
400{-
401 setContentsMargins(margins.left(), margins.top(), margins.right(), margins.bottom());-
402}
never executed: end of block
0
403-
404/*!-
405 \since 4.3-
406-
407 Extracts the left, top, right, and bottom margins used around the-
408 layout, and assigns them to *\a left, *\a top, *\a right, and *\a-
409 bottom (unless they are null pointers).-
410-
411 By default, QLayout uses the values provided by the style. On-
412 most platforms, the margin is 11 pixels in all directions.-
413-
414 \sa setContentsMargins(), QStyle::pixelMetric(),-
415 {QStyle::}{PM_LayoutLeftMargin},-
416 {QStyle::}{PM_LayoutTopMargin},-
417 {QStyle::}{PM_LayoutRightMargin},-
418 {QStyle::}{PM_LayoutBottomMargin}-
419*/-
420void QLayout::getContentsMargins(int *left, int *top, int *right, int *bottom) const-
421{-
422 Q_D(const QLayout);-
423 d->getMargin(left, d->userLeftMargin, QStyle::PM_LayoutLeftMargin);-
424 d->getMargin(top, d->userTopMargin, QStyle::PM_LayoutTopMargin);-
425 d->getMargin(right, d->userRightMargin, QStyle::PM_LayoutRightMargin);-
426 d->getMargin(bottom, d->userBottomMargin, QStyle::PM_LayoutBottomMargin);-
427}
never executed: end of block
0
428-
429/*!-
430 \since 4.6-
431-
432 Returns the margins used around the layout.-
433-
434 By default, QLayout uses the values provided by the style. On-
435 most platforms, the margin is 11 pixels in all directions.-
436-
437 \sa setContentsMargins()-
438*/-
439QMargins QLayout::contentsMargins() const-
440{-
441 int left, top, right, bottom;-
442 getContentsMargins(&left, &top, &right, &bottom);-
443 return QMargins(left, top, right, bottom);
never executed: return QMargins(left, top, right, bottom);
0
444}-
445-
446/*!-
447 \since 4.3-
448-
449 Returns the layout's geometry() rectangle, but taking into account the-
450 contents margins.-
451-
452 \sa setContentsMargins(), getContentsMargins()-
453*/-
454QRect QLayout::contentsRect() const-
455{-
456 Q_D(const QLayout);-
457 int left, top, right, bottom;-
458 getContentsMargins(&left, &top, &right, &bottom);-
459 return d->rect.adjusted(+left, +top, -right, -bottom);
never executed: return d->rect.adjusted(+left, +top, -right, -bottom);
0
460}-
461-
462-
463/*!-
464 Returns the parent widget of this layout, or 0 if this layout is-
465 not installed on any widget.-
466-
467 If the layout is a sub-layout, this function returns the parent-
468 widget of the parent layout.-
469-
470 \sa parent()-
471*/-
472QWidget *QLayout::parentWidget() const-
473{-
474 Q_D(const QLayout);-
475 if (!d->topLevel) {
!d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
476 if (parent()) {
parent()Description
TRUEnever evaluated
FALSEnever evaluated
0
477 QLayout *parentLayout = qobject_cast<QLayout*>(parent());-
478 if (Q_UNLIKELY(!parentLayout)) {
__builtin_expe...ayout), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
479 qWarning("QLayout::parentWidget: A layout can only have another layout as a parent.");-
480 return 0;
never executed: return 0;
0
481 }-
482 return parentLayout->parentWidget();
never executed: return parentLayout->parentWidget();
0
483 } else {-
484 return 0;
never executed: return 0;
0
485 }-
486 } else {-
487 Q_ASSERT(parent() && parent()->isWidgetType());-
488 return static_cast<QWidget *>(parent());
never executed: return static_cast<QWidget *>(parent());
0
489 }-
490}-
491-
492/*!-
493 \reimp-
494*/-
495bool QLayout::isEmpty() const-
496{-
497 int i = 0;-
498 QLayoutItem *item = itemAt(i);-
499 while (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
500 if (!item->isEmpty())
!item->isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
501 return false;
never executed: return false;
0
502 ++i;-
503 item = itemAt(i);-
504 }
never executed: end of block
0
505 return true;
never executed: return true;
0
506}-
507-
508/*!-
509 \reimp-
510*/-
511QSizePolicy::ControlTypes QLayout::controlTypes() const-
512{-
513 if (count() == 0)
count() == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
514 return QSizePolicy::DefaultType;
never executed: return QSizePolicy::DefaultType;
0
515 QSizePolicy::ControlTypes types;-
516 for (int i = count() - 1; i >= 0; --i)
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
517 types |= itemAt(i)->controlTypes();
never executed: types |= itemAt(i)->controlTypes();
0
518 return types;
never executed: return types;
0
519}-
520-
521/*!-
522 \reimp-
523*/-
524void QLayout::setGeometry(const QRect &r)-
525{-
526 Q_D(QLayout);-
527 d->rect = r;-
528}
never executed: end of block
0
529-
530/*!-
531 \reimp-
532*/-
533QRect QLayout::geometry() const-
534{-
535 Q_D(const QLayout);-
536 return d->rect;
never executed: return d->rect;
0
537}-
538-
539/*!-
540 \reimp-
541*/-
542void QLayout::invalidate()-
543{-
544 Q_D(QLayout);-
545 d->rect = QRect();-
546 update();-
547}
never executed: end of block
0
548-
549static bool removeWidgetRecursively(QLayoutItem *li, QObject *w)-
550{-
551 QLayout *lay = li->layout();-
552 if (!lay)
!layDescription
TRUEnever evaluated
FALSEnever evaluated
0
553 return false;
never executed: return false;
0
554 int i = 0;-
555 QLayoutItem *child;-
556 while ((child = lay->itemAt(i))) {
(child = lay->itemAt(i))Description
TRUEnever evaluated
FALSEnever evaluated
0
557 if (child->widget() == w) {
child->widget() == wDescription
TRUEnever evaluated
FALSEnever evaluated
0
558 delete lay->takeAt(i);-
559 lay->invalidate();-
560 return true;
never executed: return true;
0
561 } else if (removeWidgetRecursively(child, w)) {
removeWidgetRe...vely(child, w)Description
TRUEnever evaluated
FALSEnever evaluated
0
562 return true;
never executed: return true;
0
563 } else {-
564 ++i;-
565 }
never executed: end of block
0
566 }-
567 return false;
never executed: return false;
0
568}-
569-
570-
571void QLayoutPrivate::doResize(const QSize &r)-
572{-
573 Q_Q(QLayout);-
574 int mbh = menuBarHeightForWidth(menubar, r.width());-
575 QWidget *mw = q->parentWidget();-
576 QRect rect = mw->testAttribute(Qt::WA_LayoutOnEntireRect) ? mw->rect() : mw->contentsRect();
mw->testAttrib...tOnEntireRect)Description
TRUEnever evaluated
FALSEnever evaluated
0
577 const int mbTop = rect.top();-
578 rect.setTop(rect.top() + mbh);-
579 q->setGeometry(rect);-
580#ifndef QT_NO_MENUBAR-
581 if (menubar)
menubarDescription
TRUEnever evaluated
FALSEnever evaluated
0
582 menubar->setGeometry(rect.left(), mbTop, r.width(), mbh);
never executed: menubar->setGeometry(rect.left(), mbTop, r.width(), mbh);
0
583#endif-
584}
never executed: end of block
0
585-
586-
587/*!-
588 \internal-
589 Performs child widget layout when the parent widget is-
590 resized. Also handles removal of widgets. \a e is the-
591 event-
592*/-
593void QLayout::widgetEvent(QEvent *e)-
594{-
595 Q_D(QLayout);-
596 if (!d->enabled)
!d->enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
597 return;
never executed: return;
0
598-
599 switch (e->type()) {-
600 case QEvent::Resize:
never executed: case QEvent::Resize:
0
601 if (d->activated) {
d->activatedDescription
TRUEnever evaluated
FALSEnever evaluated
0
602 QResizeEvent *r = (QResizeEvent *)e;-
603 d->doResize(r->size());-
604 } else {
never executed: end of block
0
605 activate();-
606 }
never executed: end of block
0
607 break;
never executed: break;
0
608 case QEvent::ChildRemoved:
never executed: case QEvent::ChildRemoved:
0
609 {-
610 QChildEvent *c = (QChildEvent *)e;-
611 if (c->child()->isWidgetType()) {
c->child()->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
612#ifndef QT_NO_MENUBAR-
613 if (c->child() == d->menubar)
c->child() == d->menubarDescription
TRUEnever evaluated
FALSEnever evaluated
0
614 d->menubar = 0;
never executed: d->menubar = 0;
0
615#endif-
616 removeWidgetRecursively(this, c->child());-
617 }
never executed: end of block
0
618 }-
619 break;
never executed: break;
0
620 case QEvent::LayoutRequest:
never executed: case QEvent::LayoutRequest:
0
621 if (static_cast<QWidget *>(parent())->isVisible())
static_cast<QW...)->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
622 activate();
never executed: activate();
0
623 break;
never executed: break;
0
624 default:
never executed: default:
0
625 break;
never executed: break;
0
626 }-
627}-
628-
629/*!-
630 \reimp-
631*/-
632void QLayout::childEvent(QChildEvent *e)-
633{-
634 Q_D(QLayout);-
635 if (!d->enabled)
!d->enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
636 return;
never executed: return;
0
637-
638 if (e->type() == QEvent::ChildRemoved) {
e->type() == Q...::ChildRemovedDescription
TRUEnever evaluated
FALSEnever evaluated
0
639 QChildEvent *c = (QChildEvent*)e;-
640 int i = 0;-
641-
642 QLayoutItem *item;-
643 while ((item = itemAt(i))) {
(item = itemAt(i))Description
TRUEnever evaluated
FALSEnever evaluated
0
644 if (item == static_cast<QLayout*>(c->child())) {
item == static...*>(c->child())Description
TRUEnever evaluated
FALSEnever evaluated
0
645 takeAt(i);-
646 invalidate();-
647 break;
never executed: break;
0
648 } else {-
649 ++i;-
650 }
never executed: end of block
0
651 }-
652 }
never executed: end of block
0
653}
never executed: end of block
0
654-
655/*!-
656 \internal-
657 Also takes contentsMargins and menu bar into account.-
658*/-
659int QLayout::totalHeightForWidth(int w) const-
660{-
661 Q_D(const QLayout);-
662 int side=0, top=0;-
663 if (d->topLevel) {
d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
664 QWidget *parent = parentWidget();-
665 parent->ensurePolished();-
666 QWidgetPrivate *wd = parent->d_func();-
667 side += wd->leftmargin + wd->rightmargin;-
668 top += wd->topmargin + wd->bottommargin;-
669 }
never executed: end of block
0
670 int h = heightForWidth(w - side) + top;-
671#ifndef QT_NO_MENUBAR-
672 h += menuBarHeightForWidth(d->menubar, w);-
673#endif-
674 return h;
never executed: return h;
0
675}-
676-
677/*!-
678 \internal-
679 Also takes contentsMargins and menu bar into account.-
680*/-
681QSize QLayout::totalMinimumSize() const-
682{-
683 Q_D(const QLayout);-
684 int side=0, top=0;-
685 if (d->topLevel) {
d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
686 QWidget *pw = parentWidget();-
687 pw->ensurePolished();-
688 QWidgetPrivate *wd = pw->d_func();-
689 side += wd->leftmargin + wd->rightmargin;-
690 top += wd->topmargin + wd->bottommargin;-
691 }
never executed: end of block
0
692-
693 QSize s = minimumSize();-
694#ifndef QT_NO_MENUBAR-
695 top += menuBarHeightForWidth(d->menubar, s.width() + side);-
696#endif-
697 return s + QSize(side, top);
never executed: return s + QSize(side, top);
0
698}-
699-
700/*!-
701 \internal-
702 Also takes contentsMargins and menu bar into account.-
703*/-
704QSize QLayout::totalSizeHint() const-
705{-
706 Q_D(const QLayout);-
707 int side=0, top=0;-
708 if (d->topLevel) {
d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
709 QWidget *pw = parentWidget();-
710 pw->ensurePolished();-
711 QWidgetPrivate *wd = pw->d_func();-
712 side += wd->leftmargin + wd->rightmargin;-
713 top += wd->topmargin + wd->bottommargin;-
714 }
never executed: end of block
0
715-
716 QSize s = sizeHint();-
717 if (hasHeightForWidth())
hasHeightForWidth()Description
TRUEnever evaluated
FALSEnever evaluated
0
718 s.setHeight(heightForWidth(s.width() + side));
never executed: s.setHeight(heightForWidth(s.width() + side));
0
719#ifndef QT_NO_MENUBAR-
720 top += menuBarHeightForWidth(d->menubar, s.width());-
721#endif-
722 return s + QSize(side, top);
never executed: return s + QSize(side, top);
0
723}-
724-
725/*!-
726 \internal-
727 Also takes contentsMargins and menu bar into account.-
728*/-
729QSize QLayout::totalMaximumSize() const-
730{-
731 Q_D(const QLayout);-
732 int side=0, top=0;-
733 if (d->topLevel) {
d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
734 QWidget *pw = parentWidget();-
735 pw->ensurePolished();-
736 QWidgetPrivate *wd = pw->d_func();-
737 side += wd->leftmargin + wd->rightmargin;-
738 top += wd->topmargin + wd->bottommargin;-
739 }
never executed: end of block
0
740-
741 QSize s = maximumSize();-
742#ifndef QT_NO_MENUBAR-
743 top += menuBarHeightForWidth(d->menubar, s.width());-
744#endif-
745-
746 if (d->topLevel)
d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
747 s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX),
never executed: s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX), qMin(s.height() + top, QLAYOUTSIZE_MAX));
0
748 qMin(s.height() + top, QLAYOUTSIZE_MAX));
never executed: s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX), qMin(s.height() + top, QLAYOUTSIZE_MAX));
0
749 return s;
never executed: return s;
0
750}-
751-
752/*!-
753 \internal-
754 Destroys the layout, deleting all child layouts.-
755 Geometry management stops when a top-level layout is deleted.-
756-
757 The layout classes will probably be fatally confused if you delete-
758 a sublayout.-
759*/-
760QLayout::~QLayout()-
761{-
762 Q_D(QLayout);-
763 /*-
764 This function may be called during the QObject destructor,-
765 when the parent no longer is a QWidget.-
766 */-
767 if (d->topLevel && parent() && parent()->isWidgetType() &&
d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
parent()Description
TRUEnever evaluated
FALSEnever evaluated
parent()->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
768 ((QWidget*)parent())->layout() == this)
((QWidget*)par...yout() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
769 ((QWidget*)parent())->d_func()->layout = 0;
never executed: ((QWidget*)parent())->d_func()->layout = 0;
0
770}
never executed: end of block
0
771-
772-
773/*!-
774 This function is called from \c addLayout() or \c insertLayout() functions in-
775 subclasses to add layout \a l as a sub-layout.-
776-
777 The only scenario in which you need to call it directly is if you-
778 implement a custom layout that supports nested layouts.-
779-
780 \sa QBoxLayout::addLayout(), QBoxLayout::insertLayout(), QGridLayout::addLayout()-
781*/-
782void QLayout::addChildLayout(QLayout *l)-
783{-
784 if (Q_UNLIKELY(l->parent())) {
__builtin_expe...ent()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
785 qWarning("QLayout::addChildLayout: layout \"%ls\" already has a parent",-
786 qUtf16Printable(l->objectName()));-
787 return;
never executed: return;
0
788 }-
789 l->setParent(this);-
790-
791 if (QWidget *mw = parentWidget()) {
QWidget *mw = parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
792 l->d_func()->reparentChildWidgets(mw);-
793 }
never executed: end of block
0
794-
795}
never executed: end of block
0
796-
797/*!-
798 \internal-
799 */-
800bool QLayout::adoptLayout(QLayout *layout)-
801{-
802 const bool ok = !layout->parent();-
803 addChildLayout(layout);-
804 return ok;
never executed: return ok;
0
805}-
806-
807#ifdef QT_DEBUG-
808static bool layoutDebug()-
809{-
810 static int checked_env = -1;-
811 if(checked_env == -1)
checked_env == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
812 checked_env = !!qgetenv("QT_LAYOUT_DEBUG").toInt();
never executed: checked_env = !!qgetenv("QT_LAYOUT_DEBUG").toInt();
0
813-
814 return checked_env;
never executed: return checked_env;
0
815}-
816#endif-
817-
818void QLayoutPrivate::reparentChildWidgets(QWidget *mw)-
819{-
820 Q_Q(QLayout);-
821 int n = q->count();-
822-
823#ifndef QT_NO_MENUBAR-
824 if (menubar && menubar->parentWidget() != mw) {
menubarDescription
TRUEnever evaluated
FALSEnever evaluated
menubar->parentWidget() != mwDescription
TRUEnever evaluated
FALSEnever evaluated
0
825 menubar->setParent(mw);-
826 }
never executed: end of block
0
827#endif-
828 bool mwVisible = mw && mw->isVisible();
mwDescription
TRUEnever evaluated
FALSEnever evaluated
mw->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
829 for (int i = 0; i < n; ++i) {
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
830 QLayoutItem *item = q->itemAt(i);-
831 if (QWidget *w = item->widget()) {
QWidget *w = item->widget()Description
TRUEnever evaluated
FALSEnever evaluated
0
832 QWidget *pw = w->parentWidget();-
833#ifdef QT_DEBUG-
834 if (Q_UNLIKELY(pw && pw != mw && layoutDebug())) {
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
835 qWarning("QLayout::addChildLayout: widget %s \"%ls\" in wrong parent; moved to correct parent",-
836 w->metaObject()->className(), qUtf16Printable(w->objectName()));-
837 }
never executed: end of block
0
838#endif-
839 bool needShow = mwVisible && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
mwVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
w->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
w->testAttribu...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
0
840 if (pw != mw)
pw != mwDescription
TRUEnever evaluated
FALSEnever evaluated
0
841 w->setParent(mw);
never executed: w->setParent(mw);
0
842 if (needShow)
needShowDescription
TRUEnever evaluated
FALSEnever evaluated
0
843 QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later
never executed: QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection);
0
844 } else if (QLayout *l = item->layout()) {
never executed: end of block
QLayout *l = item->layout()Description
TRUEnever evaluated
FALSEnever evaluated
0
845 l->d_func()->reparentChildWidgets(mw);-
846 }
never executed: end of block
0
847 }
never executed: end of block
0
848}
never executed: end of block
0
849-
850/*!-
851 Returns \c true if the \a widget can be added to the \a layout;-
852 otherwise returns \c false.-
853*/-
854bool QLayoutPrivate::checkWidget(QWidget *widget) const-
855{-
856 Q_Q(const QLayout);-
857 if (Q_UNLIKELY(!widget)) {
__builtin_expe...idget), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
858 qWarning("QLayout: Cannot add a null widget to %s/%ls", q->metaObject()->className(),-
859 qUtf16Printable(q->objectName()));-
860 return false;
never executed: return false;
0
861 }-
862 if (Q_UNLIKELY(widget == q->parentWidget())) {
__builtin_expe...get()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
863 qWarning("QLayout: Cannot add parent widget %s/%ls to its child layout %s/%ls",-
864 widget->metaObject()->className(), qUtf16Printable(widget->objectName()),-
865 q->metaObject()->className(), qUtf16Printable(q->objectName()));-
866 return false;
never executed: return false;
0
867 }-
868 return true;
never executed: return true;
0
869}-
870-
871/*!-
872 Returns \c true if the \a otherLayout can be added to the \a layout;-
873 otherwise returns \c false.-
874*/-
875bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const-
876{-
877 Q_Q(const QLayout);-
878 if (Q_UNLIKELY(!otherLayout)) {
__builtin_expe...ayout), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
879 qWarning("QLayout: Cannot add a null layout to %s/%ls",-
880 q->metaObject()->className(), qUtf16Printable(q->objectName()));-
881 return false;
never executed: return false;
0
882 }-
883 if (Q_UNLIKELY(otherLayout == q)) {
__builtin_expe... == q), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
884 qWarning("QLayout: Cannot add layout %s/%ls to itself",-
885 q->metaObject()->className(), qUtf16Printable(q->objectName()));-
886 return false;
never executed: return false;
0
887 }-
888 return true;
never executed: return true;
0
889}-
890-
891/*!-
892 This function is called from \c addWidget() functions in-
893 subclasses to add \a w as a managed widget of a layout.-
894-
895 If \a w is already managed by a layout, this function will give a warning-
896 and remove \a w from that layout. This function must therefore be-
897 called before adding \a w to the layout's data structure.-
898*/-
899void QLayout::addChildWidget(QWidget *w)-
900{-
901 QWidget *mw = parentWidget();-
902 QWidget *pw = w->parentWidget();-
903-
904 //Qt::WA_LaidOut is never reset. It only means that the widget at some point has-
905 //been in a layout.-
906 if (pw && w->testAttribute(Qt::WA_LaidOut)) {
pwDescription
TRUEnever evaluated
FALSEnever evaluated
w->testAttribu...t::WA_LaidOut)Description
TRUEnever evaluated
FALSEnever evaluated
0
907 QLayout *l = pw->layout();-
908 if (l && removeWidgetRecursively(l, w)) {
lDescription
TRUEnever evaluated
FALSEnever evaluated
removeWidgetRecursively(l, w)Description
TRUEnever evaluated
FALSEnever evaluated
0
909#ifdef QT_DEBUG-
910 if (Q_UNLIKELY(layoutDebug()))
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
911 qWarning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout",
never executed: QMessageLogger(__FILE__, 911, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout", w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName()).utf16())));
0
912 w->metaObject()->className(), qUtf16Printable(w->objectName()));
never executed: QMessageLogger(__FILE__, 911, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout", w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName()).utf16())));
0
913#endif-
914 }
never executed: end of block
0
915 }
never executed: end of block
0
916 if (pw && mw && pw != mw) {
pwDescription
TRUEnever evaluated
FALSEnever evaluated
mwDescription
TRUEnever evaluated
FALSEnever evaluated
pw != mwDescription
TRUEnever evaluated
FALSEnever evaluated
0
917#ifdef QT_DEBUG-
918 if (Q_UNLIKELY(layoutDebug()))
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
919 qWarning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent",
never executed: QMessageLogger(__FILE__, 919, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent", w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName()).utf16())));
0
920 w->metaObject()->className(), qUtf16Printable(w->objectName()));
never executed: QMessageLogger(__FILE__, 919, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent", w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName()).utf16())));
0
921#endif-
922 pw = 0;-
923 }
never executed: end of block
0
924 bool needShow = mw && mw->isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
mwDescription
TRUEnever evaluated
FALSEnever evaluated
mw->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
w->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
w->testAttribu...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
0
925 if (!pw && mw)
!pwDescription
TRUEnever evaluated
FALSEnever evaluated
mwDescription
TRUEnever evaluated
FALSEnever evaluated
0
926 w->setParent(mw);
never executed: w->setParent(mw);
0
927 w->setAttribute(Qt::WA_LaidOut);-
928 if (needShow)
needShowDescription
TRUEnever evaluated
FALSEnever evaluated
0
929 QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later
never executed: QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection);
0
930}
never executed: end of block
0
931-
932-
933-
934-
935-
936-
937-
938-
939/*!-
940 Tells the geometry manager to place the menu bar \a widget at the-
941 top of parentWidget(), outside QWidget::contentsMargins(). All-
942 child widgets are placed below the bottom edge of the menu bar.-
943*/-
944void QLayout::setMenuBar(QWidget *widget)-
945{-
946 Q_D(QLayout);-
947-
948#ifdef Q_OS_WINCE_WM-
949 if (widget && widget->size().height() > 0)-
950#else-
951 if (widget)
widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
952#endif-
953 addChildWidget(widget);
never executed: addChildWidget(widget);
0
954 d->menubar = widget;-
955}
never executed: end of block
0
956-
957/*!-
958 Returns the menu bar set for this layout, or 0 if no menu bar is-
959 set.-
960*/-
961-
962QWidget *QLayout::menuBar() const-
963{-
964 Q_D(const QLayout);-
965 return d->menubar;
never executed: return d->menubar;
0
966}-
967-
968-
969/*!-
970 Returns the minimum size of this layout. This is the smallest-
971 size that the layout can have while still respecting the-
972 specifications.-
973-
974 The returned value doesn't include the space required by-
975 QWidget::setContentsMargins() or menuBar().-
976-
977 The default implementation allows unlimited resizing.-
978*/-
979QSize QLayout::minimumSize() const-
980{-
981 return QSize(0, 0);
never executed: return QSize(0, 0);
0
982}-
983-
984/*!-
985 Returns the maximum size of this layout. This is the largest size-
986 that the layout can have while still respecting the-
987 specifications.-
988-
989 The returned value doesn't include the space required by-
990 QWidget::setContentsMargins() or menuBar().-
991-
992 The default implementation allows unlimited resizing.-
993*/-
994QSize QLayout::maximumSize() const-
995{-
996 return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
never executed: return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
0
997}-
998-
999/*!-
1000 Returns whether this layout can make use of more space than-
1001 sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that-
1002 it wants to grow in only one dimension, whereas Qt::Vertical |-
1003 Qt::Horizontal means that it wants to grow in both dimensions.-
1004-
1005 The default implementation returns Qt::Horizontal | Qt::Vertical.-
1006 Subclasses reimplement it to return a meaningful value based on-
1007 their child widgets's \l{QSizePolicy}{size policies}.-
1008-
1009 \sa sizeHint()-
1010*/-
1011Qt::Orientations QLayout::expandingDirections() const-
1012{-
1013 return Qt::Horizontal | Qt::Vertical;
never executed: return Qt::Horizontal | Qt::Vertical;
0
1014}-
1015-
1016void QLayout::activateRecursiveHelper(QLayoutItem *item)-
1017{-
1018 item->invalidate();-
1019 QLayout *layout = item->layout();-
1020 if (layout) {
layoutDescription
TRUEnever evaluated
FALSEnever evaluated
0
1021 QLayoutItem *child;-
1022 int i=0;-
1023 while ((child = layout->itemAt(i++)))
(child = layout->itemAt(i++))Description
TRUEnever evaluated
FALSEnever evaluated
0
1024 activateRecursiveHelper(child);
never executed: activateRecursiveHelper(child);
0
1025 layout->d_func()->activated = true;-
1026 }
never executed: end of block
0
1027}
never executed: end of block
0
1028-
1029/*!-
1030 Updates the layout for parentWidget().-
1031-
1032 You should generally not need to call this because it is-
1033 automatically called at the most appropriate times.-
1034-
1035 \sa activate(), invalidate()-
1036*/-
1037-
1038void QLayout::update()-
1039{-
1040 QLayout *layout = this;-
1041 while (layout && layout->d_func()->activated) {
layoutDescription
TRUEnever evaluated
FALSEnever evaluated
layout->d_func()->activatedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1042 layout->d_func()->activated = false;-
1043 if (layout->d_func()->topLevel) {
layout->d_func()->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1044 Q_ASSERT(layout->parent()->isWidgetType());-
1045 QWidget *mw = static_cast<QWidget*>(layout->parent());-
1046 QApplication::postEvent(mw, new QEvent(QEvent::LayoutRequest));-
1047 break;
never executed: break;
0
1048 }-
1049 layout = static_cast<QLayout*>(layout->parent());-
1050 }
never executed: end of block
0
1051}
never executed: end of block
0
1052-
1053/*!-
1054 Redoes the layout for parentWidget() if necessary.-
1055-
1056 You should generally not need to call this because it is-
1057 automatically called at the most appropriate times. It returns-
1058 true if the layout was redone.-
1059-
1060 \sa update(), QWidget::updateGeometry()-
1061*/-
1062bool QLayout::activate()-
1063{-
1064 Q_D(QLayout);-
1065 if (!d->enabled || !parent())
!d->enabledDescription
TRUEnever evaluated
FALSEnever evaluated
!parent()Description
TRUEnever evaluated
FALSEnever evaluated
0
1066 return false;
never executed: return false;
0
1067 if (!d->topLevel)
!d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
0
1068 return static_cast<QLayout*>(parent())->activate();
never executed: return static_cast<QLayout*>(parent())->activate();
0
1069 if (d->activated)
d->activatedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1070 return false;
never executed: return false;
0
1071 QWidget *mw = static_cast<QWidget*>(parent());-
1072 if (Q_UNLIKELY(!mw)) {
__builtin_expe...!(!mw), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1073 qWarning("QLayout::activate: %s \"%ls\" does not have a main widget",-
1074 metaObject()->className(), qUtf16Printable(objectName()));-
1075 return false;
never executed: return false;
0
1076 }-
1077 activateRecursiveHelper(this);-
1078-
1079 QWidgetPrivate *md = mw->d_func();-
1080 uint explMin = md->extra ? md->extra->explicitMinSize : 0;
md->extraDescription
TRUEnever evaluated
FALSEnever evaluated
0
1081 uint explMax = md->extra ? md->extra->explicitMaxSize : 0;
md->extraDescription
TRUEnever evaluated
FALSEnever evaluated
0
1082-
1083 switch (d->constraint) {-
1084 case SetFixedSize:
never executed: case SetFixedSize:
0
1085 // will trigger resize-
1086 mw->setFixedSize(totalSizeHint());-
1087 break;
never executed: break;
0
1088 case SetMinimumSize:
never executed: case SetMinimumSize:
0
1089 mw->setMinimumSize(totalMinimumSize());-
1090 break;
never executed: break;
0
1091 case SetMaximumSize:
never executed: case SetMaximumSize:
0
1092 mw->setMaximumSize(totalMaximumSize());-
1093 break;
never executed: break;
0
1094 case SetMinAndMaxSize:
never executed: case SetMinAndMaxSize:
0
1095 mw->setMinimumSize(totalMinimumSize());-
1096 mw->setMaximumSize(totalMaximumSize());-
1097 break;
never executed: break;
0
1098 case SetDefaultConstraint: {
never executed: case SetDefaultConstraint:
0
1099 bool widthSet = explMin & Qt::Horizontal;-
1100 bool heightSet = explMin & Qt::Vertical;-
1101 if (mw->isWindow()) {
mw->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
1102 QSize ms = totalMinimumSize();-
1103 if (widthSet)
widthSetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1104 ms.setWidth(mw->minimumSize().width());
never executed: ms.setWidth(mw->minimumSize().width());
0
1105 if (heightSet)
heightSetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1106 ms.setHeight(mw->minimumSize().height());
never executed: ms.setHeight(mw->minimumSize().height());
0
1107 mw->setMinimumSize(ms);-
1108 } else if (!widthSet || !heightSet) {
never executed: end of block
!widthSetDescription
TRUEnever evaluated
FALSEnever evaluated
!heightSetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1109 QSize ms = mw->minimumSize();-
1110 if (!widthSet)
!widthSetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1111 ms.setWidth(0);
never executed: ms.setWidth(0);
0
1112 if (!heightSet)
!heightSetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1113 ms.setHeight(0);
never executed: ms.setHeight(0);
0
1114 mw->setMinimumSize(ms);-
1115 }
never executed: end of block
0
1116 break;
never executed: break;
0
1117 }-
1118 case SetNoConstraint:
never executed: case SetNoConstraint:
0
1119 break;
never executed: break;
0
1120 }-
1121-
1122 d->doResize(mw->size());-
1123-
1124 if (md->extra) {
md->extraDescription
TRUEnever evaluated
FALSEnever evaluated
0
1125 md->extra->explicitMinSize = explMin;-
1126 md->extra->explicitMaxSize = explMax;-
1127 }
never executed: end of block
0
1128 // ideally only if sizeHint() or sizePolicy() has changed-
1129 mw->updateGeometry();-
1130 return true;
never executed: return true;
0
1131}-
1132-
1133/*!-
1134 \since 5.2-
1135-
1136 Searches for widget \a from and replaces it with widget \a to if found.-
1137 Returns the layout item that contains the widget \a from on success.-
1138 Otherwise \c 0 is returned. If \a options contains \c Qt::FindChildrenRecursively-
1139 (the default), sub-layouts are searched for doing the replacement.-
1140 Any other flag in \a options is ignored.-
1141-
1142 Notice that the returned item therefore might not belong to this layout,-
1143 but to a sub-layout.-
1144-
1145 The returned layout item is no longer owned by the layout and should be-
1146 either deleted or inserted to another layout. The widget \a from is no-
1147 longer managed by the layout and may need to be deleted or hidden. The-
1148 parent of widget \a from is left unchanged.-
1149-
1150 This function works for the built-in Qt layouts, but might not work for-
1151 custom layouts.-
1152-
1153 \sa indexOf()-
1154*/-
1155-
1156QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options)-
1157{-
1158 Q_D(QLayout);-
1159 if (!from || !to)
!fromDescription
TRUEnever evaluated
FALSEnever evaluated
!toDescription
TRUEnever evaluated
FALSEnever evaluated
0
1160 return 0;
never executed: return 0;
0
1161-
1162 int index = -1;-
1163 QLayoutItem *item = 0;-
1164 for (int u = 0; u < count(); ++u) {
u < count()Description
TRUEnever evaluated
FALSEnever evaluated
0
1165 item = itemAt(u);-
1166 if (!item)
!itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1167 continue;
never executed: continue;
0
1168-
1169 if (item->widget() == from) {
item->widget() == fromDescription
TRUEnever evaluated
FALSEnever evaluated
0
1170 index = u;-
1171 break;
never executed: break;
0
1172 }-
1173-
1174 if (item->layout() && (options & Qt::FindChildrenRecursively)) {
item->layout()Description
TRUEnever evaluated
FALSEnever evaluated
(options & Qt:...enRecursively)Description
TRUEnever evaluated
FALSEnever evaluated
0
1175 QLayoutItem *r = item->layout()->replaceWidget(from, to, options);-
1176 if (r)
rDescription
TRUEnever evaluated
FALSEnever evaluated
0
1177 return r;
never executed: return r;
0
1178 }
never executed: end of block
0
1179 }
never executed: end of block
0
1180 if (index == -1)
index == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1181 return 0;
never executed: return 0;
0
1182-
1183 addChildWidget(to);-
1184 QLayoutItem *newitem = new QWidgetItem(to);-
1185 newitem->setAlignment(item->alignment());-
1186 QLayoutItem *r = d->replaceAt(index, newitem);-
1187 if (!r)
!rDescription
TRUEnever evaluated
FALSEnever evaluated
0
1188 delete newitem;
never executed: delete newitem;
0
1189 return r;
never executed: return r;
0
1190}-
1191-
1192/*!-
1193 \fn QLayoutItem *QLayout::itemAt(int index) const-
1194-
1195 Must be implemented in subclasses to return the layout item at \a-
1196 index. If there is no such item, the function must return 0.-
1197 Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.-
1198-
1199 This function can be used to iterate over a layout. The following-
1200 code will draw a rectangle for each layout item in the layout structure of the widget.-
1201-
1202 \snippet code/src_gui_kernel_qlayout.cpp 0-
1203-
1204 \sa count(), takeAt()-
1205*/-
1206-
1207/*!-
1208 \fn QLayoutItem *QLayout::takeAt(int index)-
1209-
1210 Must be implemented in subclasses to remove the layout item at \a-
1211 index from the layout, and return the item. If there is no such-
1212 item, the function must do nothing and return 0. Items are numbered-
1213 consecutively from 0. If an item is removed, other items will be-
1214 renumbered.-
1215-
1216 The following code fragment shows a safe way to remove all items-
1217 from a layout:-
1218-
1219 \snippet code/src_gui_kernel_qlayout.cpp 1-
1220-
1221 \sa itemAt(), count()-
1222*/-
1223-
1224/*!-
1225 \fn int *QLayout::count() const-
1226-
1227 Must be implemented in subclasses to return the number of items-
1228 in the layout.-
1229-
1230 \sa itemAt()-
1231*/-
1232-
1233/*!-
1234 Searches for widget \a widget in this layout (not including child-
1235 layouts).-
1236-
1237 Returns the index of \a widget, or -1 if \a widget is not found.-
1238-
1239 The default implementation iterates over all items using itemAt()-
1240*/-
1241int QLayout::indexOf(QWidget *widget) const-
1242{-
1243 int i = 0;-
1244 QLayoutItem *item = itemAt(i);-
1245 while (item) {
itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1246 if (item->widget() == widget)
item->widget() == widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1247 return i;
never executed: return i;
0
1248 ++i;-
1249 item = itemAt(i);-
1250 }
never executed: end of block
0
1251 return -1;
never executed: return -1;
0
1252}-
1253-
1254/*!-
1255 \enum QLayout::SizeConstraint-
1256-
1257 The possible values are:-
1258-
1259 \value SetDefaultConstraint The main widget's minimum size is set-
1260 to minimumSize(), unless the widget already has-
1261 a minimum size.-
1262-
1263 \value SetFixedSize The main widget's size is set to sizeHint(); it-
1264 cannot be resized at all.-
1265 \value SetMinimumSize The main widget's minimum size is set to-
1266 minimumSize(); it cannot be smaller.-
1267-
1268 \value SetMaximumSize The main widget's maximum size is set to-
1269 maximumSize(); it cannot be larger.-
1270-
1271 \value SetMinAndMaxSize The main widget's minimum size is set to-
1272 minimumSize() and its maximum size is set to-
1273 maximumSize().-
1274-
1275 \value SetNoConstraint The widget is not constrained.-
1276-
1277 \sa setSizeConstraint()-
1278*/-
1279-
1280/*!-
1281 \property QLayout::sizeConstraint-
1282 \brief the resize mode of the layout-
1283-
1284 The default mode is \l {QLayout::SetDefaultConstraint}-
1285 {SetDefaultConstraint}.-
1286*/-
1287void QLayout::setSizeConstraint(SizeConstraint constraint)-
1288{-
1289 Q_D(QLayout);-
1290 if (constraint == d->constraint)
constraint == d->constraintDescription
TRUEnever evaluated
FALSEnever evaluated
0
1291 return;
never executed: return;
0
1292-
1293 d->constraint = constraint;-
1294 invalidate();-
1295}
never executed: end of block
0
1296-
1297QLayout::SizeConstraint QLayout::sizeConstraint() const-
1298{-
1299 Q_D(const QLayout);-
1300 return d->constraint;
never executed: return d->constraint;
0
1301}-
1302-
1303/*!-
1304 Returns the rectangle that should be covered when the geometry of-
1305 this layout is set to \a r, provided that this layout supports-
1306 setAlignment().-
1307-
1308 The result is derived from sizeHint() and expanding(). It is never-
1309 larger than \a r.-
1310*/-
1311QRect QLayout::alignmentRect(const QRect &r) const-
1312{-
1313 QSize s = sizeHint();-
1314 Qt::Alignment a = alignment();-
1315-
1316 /*-
1317 This is a hack to obtain the real maximum size, not-
1318 QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX), the value consistently-
1319 returned by QLayoutItems that have an alignment.-
1320 */-
1321 QLayout *that = const_cast<QLayout *>(this);-
1322 that->setAlignment(0);-
1323 QSize ms = that->maximumSize();-
1324 that->setAlignment(a);-
1325-
1326 if ((expandingDirections() & Qt::Horizontal) ||
(expandingDire...t::Horizontal)Description
TRUEnever evaluated
FALSEnever evaluated
0
1327 !(a & Qt::AlignHorizontal_Mask)) {
!(a & Qt::Alig...rizontal_Mask)Description
TRUEnever evaluated
FALSEnever evaluated
0
1328 s.setWidth(qMin(r.width(), ms.width()));-
1329 }
never executed: end of block
0
1330 if ((expandingDirections() & Qt::Vertical) ||
(expandingDire... Qt::Vertical)Description
TRUEnever evaluated
FALSEnever evaluated
0
1331 !(a & Qt::AlignVertical_Mask)) {
!(a & Qt::AlignVertical_Mask)Description
TRUEnever evaluated
FALSEnever evaluated
0
1332 s.setHeight(qMin(r.height(), ms.height()));-
1333 } else if (hasHeightForWidth()) {
never executed: end of block
hasHeightForWidth()Description
TRUEnever evaluated
FALSEnever evaluated
0
1334 int hfw = heightForWidth(s.width());-
1335 if (hfw < s.height())
hfw < s.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
1336 s.setHeight(qMin(hfw, ms.height()));
never executed: s.setHeight(qMin(hfw, ms.height()));
0
1337 }
never executed: end of block
0
1338-
1339 s = s.boundedTo(r.size());-
1340 int x = r.x();-
1341 int y = r.y();-
1342-
1343 if (a & Qt::AlignBottom)
a & Qt::AlignBottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
1344 y += (r.height() - s.height());
never executed: y += (r.height() - s.height());
0
1345 else if (!(a & Qt::AlignTop))
!(a & Qt::AlignTop)Description
TRUEnever evaluated
FALSEnever evaluated
0
1346 y += (r.height() - s.height()) / 2;
never executed: y += (r.height() - s.height()) / 2;
0
1347-
1348 QWidget *parent = parentWidget();-
1349 a = QStyle::visualAlignment(parent ? parent->layoutDirection() : QApplication::layoutDirection(), a);-
1350 if (a & Qt::AlignRight)
a & Qt::AlignRightDescription
TRUEnever evaluated
FALSEnever evaluated
0
1351 x += (r.width() - s.width());
never executed: x += (r.width() - s.width());
0
1352 else if (!(a & Qt::AlignLeft))
!(a & Qt::AlignLeft)Description
TRUEnever evaluated
FALSEnever evaluated
0
1353 x += (r.width() - s.width()) / 2;
never executed: x += (r.width() - s.width()) / 2;
0
1354-
1355 return QRect(x, y, s.width(), s.height());
never executed: return QRect(x, y, s.width(), s.height());
0
1356}-
1357-
1358/*!-
1359 Removes the widget \a widget from the layout. After this call, it-
1360 is the caller's responsibility to give the widget a reasonable-
1361 geometry or to put the widget back into a layout.-
1362-
1363 \b{Note:} The ownership of \a widget remains the same as-
1364 when it was added.-
1365-
1366 \sa removeItem(), QWidget::setGeometry(), addWidget()-
1367*/-
1368void QLayout::removeWidget(QWidget *widget)-
1369{-
1370 int i = 0;-
1371 QLayoutItem *child;-
1372 while ((child = itemAt(i))) {
(child = itemAt(i))Description
TRUEnever evaluated
FALSEnever evaluated
0
1373 if (child->widget() == widget) {
child->widget() == widgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
1374 delete takeAt(i);-
1375 invalidate();-
1376 } else {
never executed: end of block
0
1377 ++i;-
1378 }
never executed: end of block
0
1379 }-
1380}
never executed: end of block
0
1381-
1382/*!-
1383 Removes the layout item \a item from the layout. It is the-
1384 caller's responsibility to delete the item.-
1385-
1386 Notice that \a item can be a layout (since QLayout inherits-
1387 QLayoutItem).-
1388-
1389 \sa removeWidget(), addItem()-
1390*/-
1391void QLayout::removeItem(QLayoutItem *item)-
1392{-
1393 int i = 0;-
1394 QLayoutItem *child;-
1395 while ((child = itemAt(i))) {
(child = itemAt(i))Description
TRUEnever evaluated
FALSEnever evaluated
0
1396 if (child == item) {
child == itemDescription
TRUEnever evaluated
FALSEnever evaluated
0
1397 takeAt(i);-
1398 invalidate();-
1399 } else {
never executed: end of block
0
1400 ++i;-
1401 }
never executed: end of block
0
1402 }-
1403}
never executed: end of block
0
1404-
1405/*!-
1406 Enables this layout if \a enable is true, otherwise disables it.-
1407-
1408 An enabled layout adjusts dynamically to changes; a disabled-
1409 layout acts as if it did not exist.-
1410-
1411 By default all layouts are enabled.-
1412-
1413 \sa isEnabled()-
1414*/-
1415void QLayout::setEnabled(bool enable)-
1416{-
1417 Q_D(QLayout);-
1418 d->enabled = enable;-
1419}
never executed: end of block
0
1420-
1421/*!-
1422 Returns \c true if the layout is enabled; otherwise returns \c false.-
1423-
1424 \sa setEnabled()-
1425*/-
1426bool QLayout::isEnabled() const-
1427{-
1428 Q_D(const QLayout);-
1429 return d->enabled;
never executed: return d->enabled;
0
1430}-
1431-
1432/*!-
1433 Returns a size that satisfies all size constraints on \a widget,-
1434 including heightForWidth() and that is as close as possible to \a-
1435 size.-
1436*/-
1437-
1438QSize QLayout::closestAcceptableSize(const QWidget *widget, const QSize &size)-
1439{-
1440 QSize result = size.boundedTo(qSmartMaxSize(widget));-
1441 result = result.expandedTo(qSmartMinSize(widget));-
1442 QLayout *l = widget->layout();-
1443 if (l && l->hasHeightForWidth() && result.height() < l->minimumHeightForWidth(result.width()) ) {
lDescription
TRUEnever evaluated
FALSEnever evaluated
l->hasHeightForWidth()Description
TRUEnever evaluated
FALSEnever evaluated
result.height(...esult.width())Description
TRUEnever evaluated
FALSEnever evaluated
0
1444 QSize current = widget->size();-
1445 int currentHfw = l->minimumHeightForWidth(current.width());-
1446 int newHfw = l->minimumHeightForWidth(result.width());-
1447 if (current.height() < currentHfw || currentHfw == newHfw) {
current.height() < currentHfwDescription
TRUEnever evaluated
FALSEnever evaluated
currentHfw == newHfwDescription
TRUEnever evaluated
FALSEnever evaluated
0
1448 //handle the constant hfw case and the vertical-only case, as well as the-
1449 // current-size-is-not-correct case-
1450 result.setHeight(newHfw);-
1451 } else {
never executed: end of block
0
1452 // binary search; assume hfw is decreasing ###-
1453-
1454 int maxw = qMax(widget->width(),result.width());-
1455 int maxh = qMax(widget->height(), result.height());-
1456 int minw = qMin(widget->width(),result.width());-
1457 int minh = qMin(widget->height(), result.height());-
1458-
1459 int minhfw = l->minimumHeightForWidth(minw);-
1460 int maxhfw = l->minimumHeightForWidth(maxw);-
1461 while (minw < maxw) {
minw < maxwDescription
TRUEnever evaluated
FALSEnever evaluated
0
1462 if (minhfw > maxh) { //assume decreasing
minhfw > maxhDescription
TRUEnever evaluated
FALSEnever evaluated
0
1463 minw = maxw - (maxw-minw)/2;-
1464 minhfw = l->minimumHeightForWidth(minw);-
1465 } else if (maxhfw < minh ) { //assume decreasing
never executed: end of block
maxhfw < minhDescription
TRUEnever evaluated
FALSEnever evaluated
0
1466 maxw = minw + (maxw-minw)/2;-
1467 maxhfw = l->minimumHeightForWidth(maxw);-
1468 } else {
never executed: end of block
0
1469 break;
never executed: break;
0
1470 }-
1471 }-
1472 result = result.expandedTo(QSize(minw, minhfw));-
1473 }
never executed: end of block
0
1474 }-
1475 return result;
never executed: return result;
0
1476}-
1477-
1478QT_END_NAMESPACE-
1479-
1480#include "moc_qlayout.cpp"-
Source codeSwitch to Preprocessed file

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