qgraphicslayout_p.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicslayout_p.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qglobal.h"-
35-
36#ifndef QT_NO_GRAPHICSVIEW-
37-
38#include "qgraphicslayout_p.h"-
39#include "qgraphicslayout.h"-
40#include "qgraphicswidget.h"-
41#include "qapplication.h"-
42-
43QT_BEGIN_NAMESPACE-
44-
45/*!-
46 \internal-
47-
48 \a mw is the new parent. all items in the layout will be a child of \a mw.-
49 */-
50void QGraphicsLayoutPrivate::reparentChildItems(QGraphicsItem *newParent)-
51{-
52 Q_Q(QGraphicsLayout);-
53 int n = q->count();-
54 //bool mwVisible = mw && mw->isVisible();-
55 for (int i = 0; i < n; ++i) {
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
56 QGraphicsLayoutItem *layoutChild = q->itemAt(i);-
57 if (!layoutChild) {
!layoutChildDescription
TRUEnever evaluated
FALSEnever evaluated
0
58 // Skip stretch items-
59 continue;
never executed: continue;
0
60 }-
61 if (layoutChild->isLayout()) {
layoutChild->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
62 QGraphicsLayout *l = static_cast<QGraphicsLayout*>(layoutChild);-
63 l->d_func()->reparentChildItems(newParent);-
64 } else if (QGraphicsItem *itemChild = layoutChild->graphicsItem()){
never executed: end of block
QGraphicsItem ...graphicsItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
65 QGraphicsItem *childParent = itemChild->parentItem();-
66#ifdef QT_DEBUG-
67 if (childParent && childParent != newParent && itemChild->isWidget() && qt_graphicsLayoutDebug()) {
childParentDescription
TRUEnever evaluated
FALSEnever evaluated
childParent != newParentDescription
TRUEnever evaluated
FALSEnever evaluated
itemChild->isWidget()Description
TRUEnever evaluated
FALSEnever evaluated
qt_graphicsLayoutDebug()Description
TRUEnever evaluated
FALSEnever evaluated
0
68 QGraphicsWidget *w = static_cast<QGraphicsWidget*>(layoutChild);-
69 qWarning("QGraphicsLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent",-
70 w->metaObject()->className(), w->objectName().toLocal8Bit().constData());-
71 }
never executed: end of block
0
72#endif-
73 if (childParent != newParent)
childParent != newParentDescription
TRUEnever evaluated
FALSEnever evaluated
0
74 itemChild->setParentItem(newParent);
never executed: itemChild->setParentItem(newParent);
0
75 }
never executed: end of block
0
76 }
never executed: end of block
0
77}
never executed: end of block
0
78-
79void QGraphicsLayoutPrivate::getMargin(qreal *result, qreal userMargin, QStyle::PixelMetric pm) const-
80{-
81 if (!result)
!resultDescription
TRUEnever evaluated
FALSEnever evaluated
0
82 return;
never executed: return;
0
83 Q_Q(const QGraphicsLayout);-
84-
85 QGraphicsLayoutItem *parent = q->parentLayoutItem();-
86 if (userMargin >= 0.0) {
userMargin >= 0.0Description
TRUEnever evaluated
FALSEnever evaluated
0
87 *result = userMargin;-
88 } else if (!parent) {
never executed: end of block
!parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
89 *result = 0.0;-
90 } else if (parent->isLayout()) { // sublayouts have 0 margin by default
never executed: end of block
parent->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
91 *result = 0.0;-
92 } else {
never executed: end of block
0
93 *result = 0.0;-
94 if (QGraphicsItem *layoutParentItem = parentItem()) {
QGraphicsItem ...= parentItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
95 if (layoutParentItem->isWidget())
layoutParentItem->isWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
96 *result = (qreal)static_cast<QGraphicsWidget*>(layoutParentItem)->style()->pixelMetric(pm, 0);
never executed: *result = (qreal)static_cast<QGraphicsWidget*>(layoutParentItem)->style()->pixelMetric(pm, 0);
0
97 }
never executed: end of block
0
98 }
never executed: end of block
0
99}-
100-
101Qt::LayoutDirection QGraphicsLayoutPrivate::visualDirection() const-
102{-
103 if (QGraphicsItem *maybeWidget = parentItem()) {
QGraphicsItem ...= parentItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
104 if (maybeWidget->isWidget())
maybeWidget->isWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
105 return static_cast<QGraphicsWidget*>(maybeWidget)->layoutDirection();
never executed: return static_cast<QGraphicsWidget*>(maybeWidget)->layoutDirection();
0
106 }
never executed: end of block
0
107 return QApplication::layoutDirection();
never executed: return QApplication::layoutDirection();
0
108}-
109-
110static bool removeLayoutItemFromLayout(QGraphicsLayout *lay, QGraphicsLayoutItem *layoutItem)-
111{-
112 if (!lay)
!layDescription
TRUEnever evaluated
FALSEnever evaluated
0
113 return false;
never executed: return false;
0
114-
115 for (int i = lay->count() - 1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
116 QGraphicsLayoutItem *child = lay->itemAt(i);-
117 if (child && child->isLayout()) {
childDescription
TRUEnever evaluated
FALSEnever evaluated
child->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
118 if (removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(child), layoutItem))
removeLayoutIt...), layoutItem)Description
TRUEnever evaluated
FALSEnever evaluated
0
119 return true;
never executed: return true;
0
120 } else if (child == layoutItem) {
never executed: end of block
child == layoutItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
121 lay->removeAt(i);-
122 return true;
never executed: return true;
0
123 }-
124 }
never executed: end of block
0
125 return false;
never executed: return false;
0
126}-
127-
128/*!-
129 \internal-
130-
131 This function is called from subclasses to add a layout item \a layoutItem-
132 to a layout.-
133-
134 It takes care of automatically reparenting graphics items, if needed.-
135-
136 If \a layoutItem is a is already in a layout, it will remove it from that layout.-
137-
138*/-
139void QGraphicsLayoutPrivate::addChildLayoutItem(QGraphicsLayoutItem *layoutItem)-
140{-
141 Q_Q(QGraphicsLayout);-
142 if (QGraphicsLayoutItem *maybeLayout = layoutItem->parentLayoutItem()) {
QGraphicsLayou...ntLayoutItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
143 if (maybeLayout->isLayout())
maybeLayout->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
144 removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(maybeLayout), layoutItem);
never executed: removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(maybeLayout), layoutItem);
0
145 }
never executed: end of block
0
146 layoutItem->setParentLayoutItem(q);-
147 if (layoutItem->isLayout()) {
layoutItem->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
148 if (QGraphicsItem *parItem = parentItem()) {
QGraphicsItem ...= parentItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
149 static_cast<QGraphicsLayout*>(layoutItem)->d_func()->reparentChildItems(parItem);-
150 }
never executed: end of block
0
151 } else {
never executed: end of block
0
152 if (QGraphicsItem *item = layoutItem->graphicsItem()) {
QGraphicsItem ...graphicsItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
153 QGraphicsItem *newParent = parentItem();-
154 QGraphicsItem *oldParent = item->parentItem();-
155 if (oldParent == newParent || !newParent)
oldParent == newParentDescription
TRUEnever evaluated
FALSEnever evaluated
!newParentDescription
TRUEnever evaluated
FALSEnever evaluated
0
156 return;
never executed: return;
0
157-
158#ifdef QT_DEBUG-
159 if (oldParent && item->isWidget()) {
oldParentDescription
TRUEnever evaluated
FALSEnever evaluated
item->isWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
160 QGraphicsWidget *w = static_cast<QGraphicsWidget*>(item);-
161 qWarning("QGraphicsLayout::addChildLayoutItem: %s \"%s\" in wrong parent; moved to correct parent",-
162 w->metaObject()->className(), w->objectName().toLocal8Bit().constData());-
163 }
never executed: end of block
0
164#endif-
165-
166 item->setParentItem(newParent);-
167 }
never executed: end of block
0
168 }
never executed: end of block
0
169}-
170-
171void QGraphicsLayoutPrivate::activateRecursive(QGraphicsLayoutItem *item)-
172{-
173 if (item->isLayout()) {
item->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
174 QGraphicsLayout *layout = static_cast<QGraphicsLayout *>(item);-
175 if (layout->d_func()->activated) {
layout->d_func()->activatedDescription
TRUEnever evaluated
FALSEnever evaluated
0
176 if (QGraphicsLayout::instantInvalidatePropagation()) {
QGraphicsLayou...ePropagation()Description
TRUEnever evaluated
FALSEnever evaluated
0
177 return;
never executed: return;
0
178 } else {-
179 layout->invalidate(); // ### LOOKS SUSPICIOUSLY WRONG!!???-
180 }
never executed: end of block
0
181 }-
182-
183 for (int i = layout->count() - 1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
184 QGraphicsLayoutItem *childItem = layout->itemAt(i);-
185 if (childItem)
childItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
186 activateRecursive(childItem);
never executed: activateRecursive(childItem);
0
187 }
never executed: end of block
0
188 layout->d_func()->activated = true;-
189 }
never executed: end of block
0
190}
never executed: end of block
0
191-
192-
193QT_END_NAMESPACE-
194-
195#endif //QT_NO_GRAPHICSVIEW-
Source codeSwitch to Preprocessed file

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