qlayout.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qlayout.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5static int menuBarHeightForWidth(QWidget *menubar, int w)-
6{-
7 if (menubar && !menubar->isHidden() && !menubar->isWindow()) {-
8 int result = menubar->heightForWidth(qMax(w, menubar->minimumWidth()));-
9 if (result == -1)-
10 result = menubar->sizeHint().height();-
11 const int min = qSmartMinSize(menubar).height();-
12 result = qBound(min, result, menubar->maximumSize().height());-
13 if (result != -1)-
14 return result;-
15 }-
16 return 0;-
17}-
18QLayout::QLayout(QWidget *parent)-
19 : QObject(*new QLayoutPrivate, parent)-
20{-
21 if (!parent)-
22 return;-
23 parent->setLayout(this);-
24}-
25-
26-
27-
28-
29-
30-
31-
32QLayout::QLayout()-
33 : QObject(*new QLayoutPrivate, 0)-
34{-
35}-
36-
37-
38-
39-
40QLayout::QLayout(QLayoutPrivate &dd, QLayout *lay, QWidget *w)-
41 : QObject(dd, lay ? static_cast<QObject*>(lay) : static_cast<QObject*>(w))-
42{-
43 QLayoutPrivate * const d = d_func();-
44 if (lay
layDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
45 lay->addItem(this);-
46 }
never executed: end of block
else if (w
wDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
47 if (__builtin_expect(!!(
__builtin_expe...out()), false)Description
TRUEnever evaluated
FALSEnever evaluated
w->layout())()), false)
__builtin_expe...out()), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
48 QMessageLogger(__FILE__, 133139, __PRETTY_FUNCTION__).warning("QLayout: Attempting to add QLayout \"%s\"\"%ls\" to %s \"%s\"\"%ls\", which"-
49 " already has a layout",-
50 static_cast<const wchar_t*>(static_cast<const void*>(QString(QObject::objectName()).toLocal8Bit().constData(),utf16())), w->metaObject()->className(),-
51 static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName().toLocal8Bit().data());()).utf16())));-
52 setParent(0);-
53 }
never executed: end of block
else {
0
54 d->topLevel = true;-
55 w->d_func()->layout = this;-
56 if (true) {-
57 invalidate();-
58 }
never executed: end of block
else {
dead code: { w->d_func()->layout = 0; qt_noop(); }
-
59 w->d_func()->layout = 0;
dead code: { w->d_func()->layout = 0; qt_noop(); }
-
60 qt_noop();
dead code: { w->d_func()->layout = 0; qt_noop(); }
-
61 }
dead code: { w->d_func()->layout = 0; qt_noop(); }
-
62 }-
63 }-
64}
never executed: end of block
0
65-
66QLayoutPrivate::QLayoutPrivate()-
67 : QObjectPrivate(), insideSpacing(-1), userLeftMargin(-1), userTopMargin(-1), userRightMargin(-1),-
68 userBottomMargin(-1), topLevel(false), enabled(true), activated(true), autoNewChild(false),-
69 constraint(QLayout::SetDefaultConstraint), menubar(0)-
70{-
71}-
72-
73void QLayoutPrivate::getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const-
74{-
75 if (!result)-
76 return;-
77-
78 const QLayout * const q = q_func();-
79 if (userMargin >= 0) {-
80 *result = userMargin;-
81 } else if (!topLevel) {-
82 *result = 0;-
83 } else if (QWidget *pw = q->parentWidget()) {-
84 *result = pw->style()->pixelMetric(pm, 0, pw);-
85 } else {-
86 *result = 0;-
87 }-
88}-
89-
90-
91-
92QLayoutPrivate::QWidgetItemFactoryMethod QLayoutPrivate::widgetItemFactoryMethod = 0;-
93QLayoutPrivate::QSpacerItemFactoryMethod QLayoutPrivate::spacerItemFactoryMethod = 0;-
94-
95QWidgetItem *QLayoutPrivate::createWidgetItem(const QLayout *layout, QWidget *widget)-
96{-
97 if (widgetItemFactoryMethod)-
98 if (QWidgetItem *wi = (*widgetItemFactoryMethod)(layout, widget))-
99 return wi;-
100 return new QWidgetItemV2(widget);-
101}-
102-
103QSpacerItem *QLayoutPrivate::createSpacerItem(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy)-
104{-
105 if (spacerItemFactoryMethod)-
106 if (QSpacerItem *si = (*spacerItemFactoryMethod)(layout, w, h, hPolicy, vPolicy))-
107 return si;-
108 return new QSpacerItem(w, h, hPolicy, vPolicy);-
109}-
110void QLayout::addWidget(QWidget *w)-
111{-
112 addChildWidget(w);-
113 addItem(QLayoutPrivate::createWidgetItem(this, w));-
114}-
115bool QLayout::setAlignment(QWidget *w, Qt::Alignment alignment)-
116{-
117 int i = 0;-
118 QLayoutItem *item = itemAt(i);-
119 while (item) {-
120 if (item->widget() == w) {-
121 item->setAlignment(alignment);-
122 invalidate();-
123 return true;-
124 }-
125 ++i;-
126 item = itemAt(i);-
127 }-
128 return false;-
129}-
130bool QLayout::setAlignment(QLayout *l, Qt::Alignment alignment)-
131{-
132 int i = 0;-
133 QLayoutItem *item = itemAt(i);-
134 while (item) {-
135 if (item->layout() == l) {-
136 item->setAlignment(alignment);-
137 invalidate();-
138 return true;-
139 }-
140 ++i;-
141 item = itemAt(i);-
142 }-
143 return false;-
144}-
145int QLayout::margin() const-
146{-
147 int left, top, right, bottom;-
148 getContentsMargins(&left, &top, &right, &bottom);-
149 if (left == top && top == right && right == bottom) {-
150 return left;-
151 } else {-
152 return -1;-
153 }-
154}-
155int QLayout::spacing() const-
156{-
157 if (const QBoxLayout* boxlayout = qobject_cast<const QBoxLayout*>(this)) {-
158 return boxlayout->spacing();-
159 } else if (const QGridLayout* gridlayout = qobject_cast<const QGridLayout*>(this)) {-
160 return gridlayout->spacing();-
161 } else if (const QFormLayout* formlayout = qobject_cast<const QFormLayout*>(this)) {-
162 return formlayout->spacing();-
163 } else {-
164 const QLayoutPrivate * const d = d_func();-
165 if (d->insideSpacing >=0) {-
166 return d->insideSpacing;-
167 } else {-
168-
169 return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing);-
170 }-
171 }-
172}-
173-
174-
175-
176-
177void QLayout::setMargin(int margin)-
178{-
179 setContentsMargins(margin, margin, margin, margin);-
180}-
181-
182void QLayout::setSpacing(int spacing)-
183{-
184 if (QBoxLayout* boxlayout = qobject_cast<QBoxLayout*>(this)) {-
185 boxlayout->setSpacing(spacing);-
186 } else if (QGridLayout* gridlayout = qobject_cast<QGridLayout*>(this)) {-
187 gridlayout->setSpacing(spacing);-
188 } else if (QFormLayout* formlayout = qobject_cast<QFormLayout*>(this)) {-
189 formlayout->setSpacing(spacing);-
190 } else {-
191 QLayoutPrivate * const d = d_func();-
192 d->insideSpacing = spacing;-
193 invalidate();-
194 }-
195}-
196void QLayout::setContentsMargins(int left, int top, int right, int bottom)-
197{-
198 QLayoutPrivate * const d = d_func();-
199-
200 if (d->userLeftMargin == left && d->userTopMargin == top &&-
201 d->userRightMargin == right && d->userBottomMargin == bottom)-
202 return;-
203-
204 d->userLeftMargin = left;-
205 d->userTopMargin = top;-
206 d->userRightMargin = right;-
207 d->userBottomMargin = bottom;-
208 invalidate();-
209}-
210void QLayout::setContentsMargins(const QMargins &margins)-
211{-
212 setContentsMargins(margins.left(), margins.top(), margins.right(), margins.bottom());-
213}-
214void QLayout::getContentsMargins(int *left, int *top, int *right, int *bottom) const-
215{-
216 const QLayoutPrivate * const d = d_func();-
217 d->getMargin(left, d->userLeftMargin, QStyle::PM_LayoutLeftMargin);-
218 d->getMargin(top, d->userTopMargin, QStyle::PM_LayoutTopMargin);-
219 d->getMargin(right, d->userRightMargin, QStyle::PM_LayoutRightMargin);-
220 d->getMargin(bottom, d->userBottomMargin, QStyle::PM_LayoutBottomMargin);-
221}-
222QMargins QLayout::contentsMargins() const-
223{-
224 int left, top, right, bottom;-
225 getContentsMargins(&left, &top, &right, &bottom);-
226 return QMargins(left, top, right, bottom);-
227}-
228QRect QLayout::contentsRect() const-
229{-
230 const QLayoutPrivate * const d = d_func();-
231 int left, top, right, bottom;-
232 getContentsMargins(&left, &top, &right, &bottom);-
233 return d->rect.adjusted(+left, +top, -right, -bottom);-
234}-
235QWidget *QLayout::parentWidget() const-
236{-
237 const QLayoutPrivate * const d = d_func();-
238 if (!d->topLevel
!d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
239 if (parent()
parent()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
240 QLayout *parentLayout = qobject_cast<QLayout*>(parent());-
241 if (!(__builtin_expect(!!(!
__builtin_expe...ayout), false)Description
TRUEnever evaluated
FALSEnever evaluated
parentLayout)), false)
__builtin_expe...ayout), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
242 QMessageLogger(__FILE__, 473479, __PRETTY_FUNCTION__).warning("QLayout::parentWidget: A layout can only have another layout as a parent.");-
243 return
never executed: return 0;
0;
never executed: return 0;
0
244 }-
245 return
never executed: return parentLayout->parentWidget();
parentLayout->parentWidget();
never executed: return parentLayout->parentWidget();
0
246 } else {-
247 return
never executed: return 0;
0;
never executed: return 0;
0
248 }-
249 } else {-
250 ((!(parent() && parent()->isWidgetType())) ? qt_assert("parent() && parent()->isWidgetType()",__FILE__,481487) : qt_noop());-
251 return
never executed: return static_cast<QWidget *>(parent());
static_cast<QWidget *>(parent());
never executed: return static_cast<QWidget *>(parent());
0
252 }-
253}-
254-
255-
256-
257-
258bool QLayout::isEmpty() const-
259{-
260 int i = 0;-
261 QLayoutItem *item = itemAt(i);-
262 while (item) {-
263 if (!item->isEmpty())-
264 return false;-
265 ++i;-
266 item = itemAt(i);-
267 }-
268 return true;-
269}-
270-
271-
272-
273-
274QSizePolicy::ControlTypes QLayout::controlTypes() const-
275{-
276 if (count() == 0)-
277 return QSizePolicy::DefaultType;-
278 QSizePolicy::ControlTypes types;-
279 for (int i = count() - 1; i >= 0; --i)-
280 types |= itemAt(i)->controlTypes();-
281 return types;-
282}-
283-
284-
285-
286-
287void QLayout::setGeometry(const QRect &r)-
288{-
289 QLayoutPrivate * const d = d_func();-
290 d->rect = r;-
291}-
292-
293-
294-
295-
296QRect QLayout::geometry() const-
297{-
298 const QLayoutPrivate * const d = d_func();-
299 return d->rect;-
300}-
301-
302-
303-
304-
305void QLayout::invalidate()-
306{-
307 QLayoutPrivate * const d = d_func();-
308 d->rect = QRect();-
309 update();-
310}-
311-
312static bool removeWidgetRecursively(QLayoutItem *li, QObject *w)-
313{-
314 QLayout *lay = li->layout();-
315 if (!lay)-
316 return false;-
317 int i = 0;-
318 QLayoutItem *child;-
319 while ((child = lay->itemAt(i))) {-
320 if (child->widget() == w) {-
321 delete lay->takeAt(i);-
322 lay->invalidate();-
323 return true;-
324 } else if (removeWidgetRecursively(child, w)) {-
325 return true;-
326 } else {-
327 ++i;-
328 }-
329 }-
330 return false;-
331}-
332-
333-
334void QLayoutPrivate::doResize(const QSize &r)-
335{-
336 QLayout * const q = q_func();-
337 int mbh = menuBarHeightForWidth(menubar, r.width());-
338 QWidget *mw = q->parentWidget();-
339 QRect rect = mw->testAttribute(Qt::WA_LayoutOnEntireRect) ? mw->rect() : mw->contentsRect();-
340 const int mbTop = rect.top();-
341 rect.setTop(rect.top() + mbh);-
342 q->setGeometry(rect);-
343-
344 if (menubar)-
345 menubar->setGeometry(rect.left(), mbTop, r.width(), mbh);-
346-
347}-
348void QLayout::widgetEvent(QEvent *e)-
349{-
350 QLayoutPrivate * const d = d_func();-
351 if (!d->enabled)-
352 return;-
353-
354 switch (e->type()) {-
355 case QEvent::Resize:-
356 if (d->activated) {-
357 QResizeEvent *r = (QResizeEvent *)e;-
358 d->doResize(r->size());-
359 } else {-
360 activate();-
361 }-
362 break;-
363 case QEvent::ChildRemoved:-
364 {-
365 QChildEvent *c = (QChildEvent *)e;-
366 if (c->child()->isWidgetType()) {-
367-
368 if (c->child() == d->menubar)-
369 d->menubar = 0;-
370-
371 removeWidgetRecursively(this, c->child());-
372 }-
373 }-
374 break;-
375 case QEvent::LayoutRequest:-
376 if (static_cast<QWidget *>(parent())->isVisible())-
377 activate();-
378 break;-
379 default:-
380 break;-
381 }-
382}-
383-
384-
385-
386-
387void QLayout::childEvent(QChildEvent *e)-
388{-
389 QLayoutPrivate * const d = d_func();-
390 if (!d->enabled)-
391 return;-
392-
393 if (e->type() == QEvent::ChildRemoved) {-
394 QChildEvent *c = (QChildEvent*)e;-
395 int i = 0;-
396-
397 QLayoutItem *item;-
398 while ((item = itemAt(i))) {-
399 if (item == static_cast<QLayout*>(c->child())) {-
400 takeAt(i);-
401 invalidate();-
402 break;-
403 } else {-
404 ++i;-
405 }-
406 }-
407 }-
408}-
409-
410-
411-
412-
413-
414int QLayout::totalHeightForWidth(int w) const-
415{-
416 const QLayoutPrivate * const d = d_func();-
417 int side=0, top=0;-
418 if (d->topLevel) {-
419 QWidget *parent = parentWidget();-
420 parent->ensurePolished();-
421 QWidgetPrivate *wd = parent->d_func();-
422 side += wd->leftmargin + wd->rightmargin;-
423 top += wd->topmargin + wd->bottommargin;-
424 }-
425 int h = heightForWidth(w - side) + top;-
426-
427 h += menuBarHeightForWidth(d->menubar, w);-
428-
429 return h;-
430}-
431-
432-
433-
434-
435-
436QSize QLayout::totalMinimumSize() const-
437{-
438 const QLayoutPrivate * const d = d_func();-
439 int side=0, top=0;-
440 if (d->topLevel) {-
441 QWidget *pw = parentWidget();-
442 pw->ensurePolished();-
443 QWidgetPrivate *wd = pw->d_func();-
444 side += wd->leftmargin + wd->rightmargin;-
445 top += wd->topmargin + wd->bottommargin;-
446 }-
447-
448 QSize s = minimumSize();-
449-
450 top += menuBarHeightForWidth(d->menubar, s.width() + side);-
451-
452 return s + QSize(side, top);-
453}-
454-
455-
456-
457-
458-
459QSize QLayout::totalSizeHint() const-
460{-
461 const QLayoutPrivate * const d = d_func();-
462 int side=0, top=0;-
463 if (d->topLevel) {-
464 QWidget *pw = parentWidget();-
465 pw->ensurePolished();-
466 QWidgetPrivate *wd = pw->d_func();-
467 side += wd->leftmargin + wd->rightmargin;-
468 top += wd->topmargin + wd->bottommargin;-
469 }-
470-
471 QSize s = sizeHint();-
472 if (hasHeightForWidth())-
473 s.setHeight(heightForWidth(s.width() + side));-
474-
475 top += menuBarHeightForWidth(d->menubar, s.width());-
476-
477 return s + QSize(side, top);-
478}-
479-
480-
481-
482-
483-
484QSize QLayout::totalMaximumSize() const-
485{-
486 const QLayoutPrivate * const d = d_func();-
487 int side=0, top=0;-
488 if (d->topLevel) {-
489 QWidget *pw = parentWidget();-
490 pw->ensurePolished();-
491 QWidgetPrivate *wd = pw->d_func();-
492 side += wd->leftmargin + wd->rightmargin;-
493 top += wd->topmargin + wd->bottommargin;-
494 }-
495-
496 QSize s = maximumSize();-
497-
498 top += menuBarHeightForWidth(d->menubar, s.width());-
499-
500-
501 if (d->topLevel)-
502 s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX),-
503 qMin(s.height() + top, QLAYOUTSIZE_MAX));-
504 return s;-
505}-
506QLayout::~QLayout()-
507{-
508 QLayoutPrivate * const d = d_func();-
509-
510-
511-
512-
513 if (d->topLevel && parent() && parent()->isWidgetType() &&-
514 ((QWidget*)parent())->layout() == this)-
515 ((QWidget*)parent())->d_func()->layout = 0;-
516}-
517void QLayout::addChildLayout(QLayout *l)-
518{-
519 if (__builtin_expect(!!(
__builtin_expe...ent()), false)Description
TRUEnever evaluated
FALSEnever evaluated
l->parent())()), false)
__builtin_expe...ent()), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
520 QMessageLogger(__FILE__, 779785, __PRETTY_FUNCTION__).warning("QLayout::addChildLayout: layout \"%s\"\"%ls\" already has a parent",-
521 static_cast<const wchar_t*>(static_cast<const void*>(QString(l->objectName().toLocal8Bit().data());()).utf16())));-
522 return;
never executed: return;
0
523 }-
524 l->setParent(this);-
525-
526 if (QWidget *mw = parentWidget()
QWidget *mw = parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
527 l->d_func()->reparentChildWidgets(mw);-
528 }
never executed: end of block
0
529-
530}
never executed: end of block
0
531-
532-
533-
534-
535bool QLayout::adoptLayout(QLayout *layout)-
536{-
537 const bool ok = !layout->parent();-
538 addChildLayout(layout);-
539 return ok;-
540}-
541-
542-
543static bool layoutDebug()-
544{-
545 static int checked_env = -1;-
546 if(checked_env == -1)-
547 checked_env = !!qgetenv("QT_LAYOUT_DEBUG").toInt();-
548-
549 return checked_env;-
550}-
551-
552-
553void QLayoutPrivate::reparentChildWidgets(QWidget *mw)-
554{-
555 QLayout * const q = q_func();-
556 int n = q->count();-
557-
558-
559 if (menubar
menubarDescription
TRUEnever evaluated
FALSEnever evaluated
&& menubar->parentWidget() != mw
menubar->parentWidget() != mwDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
560 menubar->setParent(mw);-
561 }
never executed: end of block
0
562-
563 bool mwVisible = mw
mwDescription
TRUEnever evaluated
FALSEnever evaluated
&& mw->isVisible()
mw->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
;
0
564 for (int i = 0; i < n
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
565 QLayoutItem *item = q->itemAt(i);-
566 if (QWidget *w = item->widget()
QWidget *w = item->widget()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
567 QWidget *pw = w->parentWidget();-
568-
569 if (__builtin_expect(!!(
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
pw && pw != mw && layoutDebug())()), false)
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
570 QMessageLogger(__FILE__, 829835, __PRETTY_FUNCTION__).warning("QLayout::addChildLayout: widget %s \"%s\"\"%ls\" in wrong parent; moved to correct parent",-
571 w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName().toLocal8Bit().data());()).utf16())));-
572 }
never executed: end of block
0
573-
574 bool needShow = mwVisible
mwVisibleDescription
TRUEnever evaluated
FALSEnever evaluated
&& !(w->isHidden()
w->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
&& w->testAttribute(Qt::WA_WState_ExplicitShowHide)
w->testAttribu...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
);
0
575 if (pw != mw
pw != mwDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
576 w->setParent(mw);
never executed: w->setParent(mw);
0
577 if (needShow
needShowDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
578 QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection);
never executed: QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection);
0
579 }
never executed: end of block
else if (QLayout *l = item->layout()
QLayout *l = item->layout()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
580 l->d_func()->reparentChildWidgets(mw);-
581 }
never executed: end of block
0
582 }
never executed: end of block
0
583}
never executed: end of block
0
584-
585-
586-
587-
588-
589bool QLayoutPrivate::checkWidget(QWidget *widget) const-
590{-
591 const QLayout * const q = q_func();-
592 if (!(__builtin_expect(!!(!
__builtin_expe...idget), false)Description
TRUEnever evaluated
FALSEnever evaluated
widget)), false)
__builtin_expe...idget), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
593 QMessageLogger(__FILE__, 852858, __PRETTY_FUNCTION__).warning("QLayout: Cannot add a null widget to %s/%s"%ls", q->metaObject()->className(),-
594 static_cast<const wchar_t*>(static_cast<const void*>(QString(q->objectName()).toLocal8Bit().constData());utf16())));-
595 return
never executed: return false;
false;
never executed: return false;
0
596 }-
597 if (__builtin_expect(!!(
__builtin_expe...get()), false)Description
TRUEnever evaluated
FALSEnever evaluated
widget == q->parentWidget())()), false)
__builtin_expe...get()), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
598 QMessageLogger(__FILE__, 857863, __PRETTY_FUNCTION__).warning("QLayout: Cannot add parent widget %s/%s%ls to its child layout %s/%s"%ls",-
599 widget->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(widget->objectName()).toLocal8Bit().constData(),utf16())),-
600 q->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(q->objectName()).toLocal8Bit().constData());utf16())));-
601 return
never executed: return false;
false;
never executed: return false;
0
602 }-
603 return
never executed: return true;
true;
never executed: return true;
0
604}-
605-
606-
607-
608-
609-
610bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const-
611{-
612 const QLayout * const q = q_func();-
613 if (!(__builtin_expect(!!(!
__builtin_expe...ayout), false)Description
TRUEnever evaluated
FALSEnever evaluated
otherLayout)), false)
__builtin_expe...ayout), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
614 QMessageLogger(__FILE__, 873879, __PRETTY_FUNCTION__).warning("QLayout: Cannot add a null layout to %s/%s"%ls",-
615 q->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(q->objectName()).toLocal8Bit().constData());utf16())));-
616 return
never executed: return false;
false;
never executed: return false;
0
617 }-
618 if (__builtin_expect(!!(
__builtin_expe... == q), false)Description
TRUEnever evaluated
FALSEnever evaluated
otherLayout == q)), false)
__builtin_expe... == q), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
619 QMessageLogger(__FILE__, 878884, __PRETTY_FUNCTION__).warning("QLayout: Cannot add layout %s/%s%ls to itself",-
620 q->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(q->objectName()).toLocal8Bit().constData());utf16())));-
621 return
never executed: return false;
false;
never executed: return false;
0
622 }-
623 return
never executed: return true;
true;
never executed: return true;
0
624}-
625void QLayout::addChildWidget(QWidget *w)-
626{-
627 QWidget *mw = parentWidget();-
628 QWidget *pw = w->parentWidget();-
629-
630-
631-
632 if (pw
pwDescription
TRUEnever evaluated
FALSEnever evaluated
&& w->testAttribute(Qt::WA_LaidOut)
w->testAttribu...t::WA_LaidOut)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
633 QLayout *l = pw->layout();-
634 if (l
lDescription
TRUEnever evaluated
FALSEnever evaluated
&& removeWidgetRecursively(l, w)
removeWidgetRecursively(l, w)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
635-
636 if (__builtin_expect(!!(
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
layoutDebug())()), false)
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
637 QMessageLogger(__FILE__, 905911, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%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
638 w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName().toLocal8Bit().data());()).utf16())));
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
639-
640 }
never executed: end of block
0
641 }
never executed: end of block
0
642 if (pw
pwDescription
TRUEnever evaluated
FALSEnever evaluated
&& mw
mwDescription
TRUEnever evaluated
FALSEnever evaluated
&& pw != mw
pw != mwDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
643-
644 if (__builtin_expect(!!(
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
layoutDebug())()), false)
__builtin_expe...bug()), false)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
645 QMessageLogger(__FILE__, 913919, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%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
646 w->metaObject()->className(), static_cast<const wchar_t*>(static_cast<const void*>(QString(w->objectName().toLocal8Bit().data());()).utf16())));
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
647-
648 pw = 0;-
649 }
never executed: end of block
0
650 bool needShow = mw
mwDescription
TRUEnever evaluated
FALSEnever evaluated
&& mw->isVisible()
mw->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
&& !(w->isHidden()
w->isHidden()Description
TRUEnever evaluated
FALSEnever evaluated
&& w->testAttribute(Qt::WA_WState_ExplicitShowHide)
w->testAttribu...licitShowHide)Description
TRUEnever evaluated
FALSEnever evaluated
);
0
651 if (!pw
!pwDescription
TRUEnever evaluated
FALSEnever evaluated
&& mw
mwDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
652 w->setParent(mw);
never executed: w->setParent(mw);
0
653 w->setAttribute(Qt::WA_LaidOut);-
654 if (needShow
needShowDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
655 QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection);
never executed: QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection);
0
656}
never executed: end of block
0
657void QLayout::setMenuBar(QWidget *widget)-
658{-
659 QLayoutPrivate * const d = d_func();-
660-
661-
662-
663-
664 if (widget)-
665-
666 addChildWidget(widget);-
667 d->menubar = widget;-
668}-
669-
670-
671-
672-
673-
674-
675QWidget *QLayout::menuBar() const-
676{-
677 const QLayoutPrivate * const d = d_func();-
678 return d->menubar;-
679}-
680QSize QLayout::minimumSize() const-
681{-
682 return QSize(0, 0);-
683}-
684QSize QLayout::maximumSize() const-
685{-
686 return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);-
687}-
688Qt::Orientations QLayout::expandingDirections() const-
689{-
690 return Qt::Horizontal | Qt::Vertical;-
691}-
692-
693void QLayout::activateRecursiveHelper(QLayoutItem *item)-
694{-
695 item->invalidate();-
696 QLayout *layout = item->layout();-
697 if (layout) {-
698 QLayoutItem *child;-
699 int i=0;-
700 while ((child = layout->itemAt(i++)))-
701 activateRecursiveHelper(child);-
702 layout->d_func()->activated = true;-
703 }-
704}-
705void QLayout::update()-
706{-
707 QLayout *layout = this;-
708 while (layout && layout->d_func()->activated) {-
709 layout->d_func()->activated = false;-
710 if (layout->d_func()->topLevel) {-
711 ((!(layout->parent()->isWidgetType())) ? qt_assert("layout->parent()->isWidgetType()",__FILE__,10381044) : qt_noop());-
712 QWidget *mw = static_cast<QWidget*>(layout->parent());-
713 QApplication::postEvent(mw, new QEvent(QEvent::LayoutRequest));-
714 break;-
715 }-
716 layout = static_cast<QLayout*>(layout->parent());-
717 }-
718}-
719bool QLayout::activate()-
720{-
721 QLayoutPrivate * const d = d_func();-
722 if (!d->enabled
!d->enabledDescription
TRUEnever evaluated
FALSEnever evaluated
|| !parent()
!parent()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
723 return
never executed: return false;
false;
never executed: return false;
0
724 if (!d->topLevel
!d->topLevelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
725 return
never executed: return static_cast<QLayout*>(parent())->activate();
static_cast<QLayout*>(parent())->activate();
never executed: return static_cast<QLayout*>(parent())->activate();
0
726 if (d->activated
d->activatedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
727 return
never executed: return false;
false;
never executed: return false;
0
728 QWidget *mw = static_cast<QWidget*>(parent());-
729 if (__builtin_expect(!!(!
__builtin_expe...!(!mw), false)Description
TRUEnever evaluated
FALSEnever evaluated
mw== 0)), false)
__builtin_expe...!(!mw), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
730 QMessageLogger(__FILE__, 10671073, __PRETTY_FUNCTION__).warning("QLayout::activate: %s \"%s\"\"%ls\" does not have a main widget",-
731 QObject::metaObject()->className(), QObject::static_cast<const wchar_t*>(static_cast<const void*>(QString(objectName().toLocal8Bit().data());()).utf16())));-
732 return
never executed: return false;
false;
never executed: return false;
0
733 }-
734 activateRecursiveHelper(this);-
735-
736 QWidgetPrivate *md = mw->d_func();-
737 uint explMin = md->extra
md->extraDescription
TRUEnever evaluated
FALSEnever evaluated
? md->extra->explicitMinSize : 0;
0
738 uint explMax = md->extra
md->extraDescription
TRUEnever evaluated
FALSEnever evaluated
? md->extra->explicitMaxSize : 0;
0
739-
740 switch (d->constraint) {-
741 case
never executed: case SetFixedSize:
SetFixedSize:
never executed: case SetFixedSize:
0
742-
743 mw->setFixedSize(totalSizeHint());-
744 break;
never executed: break;
0
745 case
never executed: case SetMinimumSize:
SetMinimumSize:
never executed: case SetMinimumSize:
0
746 mw->setMinimumSize(totalMinimumSize());-
747 break;
never executed: break;
0
748 case
never executed: case SetMaximumSize:
SetMaximumSize:
never executed: case SetMaximumSize:
0
749 mw->setMaximumSize(totalMaximumSize());-
750 break;
never executed: break;
0
751 case
never executed: case SetMinAndMaxSize:
SetMinAndMaxSize:
never executed: case SetMinAndMaxSize:
0
752 mw->setMinimumSize(totalMinimumSize());-
753 mw->setMaximumSize(totalMaximumSize());-
754 break;
never executed: break;
0
755 case
never executed: case SetDefaultConstraint:
SetDefaultConstraint:
never executed: case SetDefaultConstraint:
{
0
756 bool widthSet = explMin & Qt::Horizontal;-
757 bool heightSet = explMin & Qt::Vertical;-
758 if (mw->isWindow()
mw->isWindow()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
759 QSize ms = totalMinimumSize();-
760 if (widthSet
widthSetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
761 ms.setWidth(mw->minimumSize().width());
never executed: ms.setWidth(mw->minimumSize().width());
0
762 if (heightSet
heightSetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
763 ms.setHeight(mw->minimumSize().height());
never executed: ms.setHeight(mw->minimumSize().height());
0
764 mw->setMinimumSize(ms);-
765 }
never executed: end of block
else if (!widthSet
!widthSetDescription
TRUEnever evaluated
FALSEnever evaluated
|| !heightSet
!heightSetDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
766 QSize ms = mw->minimumSize();-
767 if (!widthSet
!widthSetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
768 ms.setWidth(0);
never executed: ms.setWidth(0);
0
769 if (!heightSet
!heightSetDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
770 ms.setHeight(0);
never executed: ms.setHeight(0);
0
771 mw->setMinimumSize(ms);-
772 }
never executed: end of block
0
773 break;
never executed: break;
0
774 }-
775 case
never executed: case SetNoConstraint:
SetNoConstraint:
never executed: case SetNoConstraint:
0
776 break;
never executed: break;
0
777 }-
778-
779 d->doResize(mw->size());-
780-
781 if (md->extra
md->extraDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
782 md->extra->explicitMinSize = explMin;-
783 md->extra->explicitMaxSize = explMax;-
784 }
never executed: end of block
0
785-
786 mw->updateGeometry();-
787 return
never executed: return true;
true;
never executed: return true;
0
788}-
789QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options)-
790{-
791 QLayoutPrivate * const d = d_func();-
792 if (!from || !to)-
793 return 0;-
794-
795 int index = -1;-
796 QLayoutItem *item = 0;-
797 for (int u = 0; u < count(); ++u) {-
798 item = itemAt(u);-
799 if (!item)-
800 continue;-
801-
802 if (item->widget() == from) {-
803 index = u;-
804 break;-
805 }-
806-
807 if (item->layout() && (options & Qt::FindChildrenRecursively)) {-
808 QLayoutItem *r = item->layout()->replaceWidget(from, to, options);-
809 if (r)-
810 return r;-
811 }-
812 }-
813 if (index == -1)-
814 return 0;-
815-
816 addChildWidget(to);-
817 QLayoutItem *newitem = new QWidgetItem(to);-
818 newitem->setAlignment(item->alignment());-
819 QLayoutItem *r = d->replaceAt(index, newitem);-
820 if (!r)-
821 delete newitem;-
822 return r;-
823}-
824int QLayout::indexOf(QWidget *widget) const-
825{-
826 int i = 0;-
827 QLayoutItem *item = itemAt(i);-
828 while (item) {-
829 if (item->widget() == widget)-
830 return i;-
831 ++i;-
832 item = itemAt(i);-
833 }-
834 return -1;-
835}-
836void QLayout::setSizeConstraint(SizeConstraint constraint)-
837{-
838 QLayoutPrivate * const d = d_func();-
839 if (constraint == d->constraint)-
840 return;-
841-
842 d->constraint = constraint;-
843 invalidate();-
844}-
845-
846QLayout::SizeConstraint QLayout::sizeConstraint() const-
847{-
848 const QLayoutPrivate * const d = d_func();-
849 return d->constraint;-
850}-
851QRect QLayout::alignmentRect(const QRect &r) const-
852{-
853 QSize s = sizeHint();-
854 Qt::Alignment a = alignment();-
855-
856-
857-
858-
859-
860-
861 QLayout *that = const_cast<QLayout *>(this);-
862 that->setAlignment(0);-
863 QSize ms = that->maximumSize();-
864 that->setAlignment(a);-
865-
866 if ((expandingDirections() & Qt::Horizontal) ||-
867 !(a & Qt::AlignHorizontal_Mask)) {-
868 s.setWidth(qMin(r.width(), ms.width()));-
869 }-
870 if ((expandingDirections() & Qt::Vertical) ||-
871 !(a & Qt::AlignVertical_Mask)) {-
872 s.setHeight(qMin(r.height(), ms.height()));-
873 } else if (hasHeightForWidth()) {-
874 int hfw = heightForWidth(s.width());-
875 if (hfw < s.height())-
876 s.setHeight(qMin(hfw, ms.height()));-
877 }-
878-
879 s = s.boundedTo(r.size());-
880 int x = r.x();-
881 int y = r.y();-
882-
883 if (a & Qt::AlignBottom)-
884 y += (r.height() - s.height());-
885 else if (!(a & Qt::AlignTop))-
886 y += (r.height() - s.height()) / 2;-
887-
888 QWidget *parent = parentWidget();-
889 a = QStyle::visualAlignment(parent ? parent->layoutDirection() : QApplication::layoutDirection(), a);-
890 if (a & Qt::AlignRight)-
891 x += (r.width() - s.width());-
892 else if (!(a & Qt::AlignLeft))-
893 x += (r.width() - s.width()) / 2;-
894-
895 return QRect(x, y, s.width(), s.height());-
896}-
897void QLayout::removeWidget(QWidget *widget)-
898{-
899 int i = 0;-
900 QLayoutItem *child;-
901 while ((child = itemAt(i))) {-
902 if (child->widget() == widget) {-
903 delete takeAt(i);-
904 invalidate();-
905 } else {-
906 ++i;-
907 }-
908 }-
909}-
910void QLayout::removeItem(QLayoutItem *item)-
911{-
912 int i = 0;-
913 QLayoutItem *child;-
914 while ((child = itemAt(i))) {-
915 if (child == item) {-
916 takeAt(i);-
917 invalidate();-
918 } else {-
919 ++i;-
920 }-
921 }-
922}-
923void QLayout::setEnabled(bool enable)-
924{-
925 QLayoutPrivate * const d = d_func();-
926 d->enabled = enable;-
927}-
928-
929-
930-
931-
932-
933-
934bool QLayout::isEnabled() const-
935{-
936 const QLayoutPrivate * const d = d_func();-
937 return d->enabled;-
938}-
939-
940-
941-
942-
943-
944-
945-
946QSize QLayout::closestAcceptableSize(const QWidget *widget, const QSize &size)-
947{-
948 QSize result = size.boundedTo(qSmartMaxSize(widget));-
949 result = result.expandedTo(qSmartMinSize(widget));-
950 QLayout *l = widget->layout();-
951 if (l && l->hasHeightForWidth() && result.height() < l->minimumHeightForWidth(result.width()) ) {-
952 QSize current = widget->size();-
953 int currentHfw = l->minimumHeightForWidth(current.width());-
954 int newHfw = l->minimumHeightForWidth(result.width());-
955 if (current.height() < currentHfw || currentHfw == newHfw) {-
956-
957-
958 result.setHeight(newHfw);-
959 } else {-
960-
961-
962 int maxw = qMax(widget->width(),result.width());-
963 int maxh = qMax(widget->height(), result.height());-
964 int minw = qMin(widget->width(),result.width());-
965 int minh = qMin(widget->height(), result.height());-
966-
967 int minhfw = l->minimumHeightForWidth(minw);-
968 int maxhfw = l->minimumHeightForWidth(maxw);-
969 while (minw < maxw) {-
970 if (minhfw > maxh) {-
971 minw = maxw - (maxw-minw)/2;-
972 minhfw = l->minimumHeightForWidth(minw);-
973 } else if (maxhfw < minh ) {-
974 maxw = minw + (maxw-minw)/2;-
975 maxhfw = l->minimumHeightForWidth(maxw);-
976 } else {-
977 break;-
978 }-
979 }-
980 result = result.expandedTo(QSize(minw, minhfw));-
981 }-
982 }-
983 return result;-
984}-
985-
986-
987-
Switch to Source codePreprocessed file

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