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) 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 "qglobal.h"-
41-
42#ifndef QT_NO_GRAPHICSVIEW-
43-
44#include "qgraphicslayout_p.h"-
45#include "qgraphicslayout.h"-
46#include "qgraphicswidget.h"-
47#include "qapplication.h"-
48-
49QT_BEGIN_NAMESPACE-
50-
51/*!-
52 \internal-
53-
54 \a mw is the new parent. all items in the layout will be a child of \a mw.-
55 */-
56void QGraphicsLayoutPrivate::reparentChildItems(QGraphicsItem *newParent)-
57{-
58 Q_Q(QGraphicsLayout);-
59 int n = q->count();-
60 //bool mwVisible = mw && mw->isVisible();-
61 for (int i = 0; i < n; ++i) {
i < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
62 QGraphicsLayoutItem *layoutChild = q->itemAt(i);-
63 if (!layoutChild) {
!layoutChildDescription
TRUEnever evaluated
FALSEnever evaluated
0
64 // Skip stretch items-
65 continue;
never executed: continue;
0
66 }-
67 if (layoutChild->isLayout()) {
layoutChild->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
68 QGraphicsLayout *l = static_cast<QGraphicsLayout*>(layoutChild);-
69 l->d_func()->reparentChildItems(newParent);-
70 } else if (QGraphicsItem *itemChild = layoutChild->graphicsItem()){
never executed: end of block
QGraphicsItem ...graphicsItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
71 QGraphicsItem *childParent = itemChild->parentItem();-
72#ifdef QT_DEBUG-
73 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
74 QGraphicsWidget *w = static_cast<QGraphicsWidget*>(layoutChild);-
75 qWarning("QGraphicsLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent",-
76 w->metaObject()->className(), w->objectName().toLocal8Bit().constData());-
77 }
never executed: end of block
0
78#endif-
79 if (childParent != newParent)
childParent != newParentDescription
TRUEnever evaluated
FALSEnever evaluated
0
80 itemChild->setParentItem(newParent);
never executed: itemChild->setParentItem(newParent);
0
81 }
never executed: end of block
0
82 }
never executed: end of block
0
83}
never executed: end of block
0
84-
85void QGraphicsLayoutPrivate::getMargin(qreal *result, qreal userMargin, QStyle::PixelMetric pm) const-
86{-
87 if (!result)
!resultDescription
TRUEnever evaluated
FALSEnever evaluated
0
88 return;
never executed: return;
0
89 Q_Q(const QGraphicsLayout);-
90-
91 QGraphicsLayoutItem *parent = q->parentLayoutItem();-
92 if (userMargin >= 0.0) {
userMargin >= 0.0Description
TRUEnever evaluated
FALSEnever evaluated
0
93 *result = userMargin;-
94 } else if (!parent) {
never executed: end of block
!parentDescription
TRUEnever evaluated
FALSEnever evaluated
0
95 *result = 0.0;-
96 } else if (parent->isLayout()) { // sublayouts have 0 margin by default
never executed: end of block
parent->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
97 *result = 0.0;-
98 } else {
never executed: end of block
0
99 *result = 0.0;-
100 if (QGraphicsItem *layoutParentItem = parentItem()) {
QGraphicsItem ...= parentItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
101 if (layoutParentItem->isWidget())
layoutParentItem->isWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
102 *result = (qreal)static_cast<QGraphicsWidget*>(layoutParentItem)->style()->pixelMetric(pm, 0);
never executed: *result = (qreal)static_cast<QGraphicsWidget*>(layoutParentItem)->style()->pixelMetric(pm, 0);
0
103 }
never executed: end of block
0
104 }
never executed: end of block
0
105}-
106-
107Qt::LayoutDirection QGraphicsLayoutPrivate::visualDirection() const-
108{-
109 if (QGraphicsItem *maybeWidget = parentItem()) {
QGraphicsItem ...= parentItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
110 if (maybeWidget->isWidget())
maybeWidget->isWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
111 return static_cast<QGraphicsWidget*>(maybeWidget)->layoutDirection();
never executed: return static_cast<QGraphicsWidget*>(maybeWidget)->layoutDirection();
0
112 }
never executed: end of block
0
113 return QApplication::layoutDirection();
never executed: return QApplication::layoutDirection();
0
114}-
115-
116static bool removeLayoutItemFromLayout(QGraphicsLayout *lay, QGraphicsLayoutItem *layoutItem)-
117{-
118 if (!lay)
!layDescription
TRUEnever evaluated
FALSEnever evaluated
0
119 return false;
never executed: return false;
0
120-
121 for (int i = lay->count() - 1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
122 QGraphicsLayoutItem *child = lay->itemAt(i);-
123 if (child && child->isLayout()) {
childDescription
TRUEnever evaluated
FALSEnever evaluated
child->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
124 if (removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(child), layoutItem))
removeLayoutIt...), layoutItem)Description
TRUEnever evaluated
FALSEnever evaluated
0
125 return true;
never executed: return true;
0
126 } else if (child == layoutItem) {
never executed: end of block
child == layoutItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
127 lay->removeAt(i);-
128 return true;
never executed: return true;
0
129 }-
130 }
never executed: end of block
0
131 return false;
never executed: return false;
0
132}-
133-
134/*!-
135 \internal-
136-
137 This function is called from subclasses to add a layout item \a layoutItem-
138 to a layout.-
139-
140 It takes care of automatically reparenting graphics items, if needed.-
141-
142 If \a layoutItem is a is already in a layout, it will remove it from that layout.-
143-
144*/-
145void QGraphicsLayoutPrivate::addChildLayoutItem(QGraphicsLayoutItem *layoutItem)-
146{-
147 Q_Q(QGraphicsLayout);-
148 if (QGraphicsLayoutItem *maybeLayout = layoutItem->parentLayoutItem()) {
QGraphicsLayou...ntLayoutItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
149 if (maybeLayout->isLayout())
maybeLayout->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
150 removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(maybeLayout), layoutItem);
never executed: removeLayoutItemFromLayout(static_cast<QGraphicsLayout*>(maybeLayout), layoutItem);
0
151 }
never executed: end of block
0
152 layoutItem->setParentLayoutItem(q);-
153 if (layoutItem->isLayout()) {
layoutItem->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
154 if (QGraphicsItem *parItem = parentItem()) {
QGraphicsItem ...= parentItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
155 static_cast<QGraphicsLayout*>(layoutItem)->d_func()->reparentChildItems(parItem);-
156 }
never executed: end of block
0
157 } else {
never executed: end of block
0
158 if (QGraphicsItem *item = layoutItem->graphicsItem()) {
QGraphicsItem ...graphicsItem()Description
TRUEnever evaluated
FALSEnever evaluated
0
159 QGraphicsItem *newParent = parentItem();-
160 QGraphicsItem *oldParent = item->parentItem();-
161 if (oldParent == newParent || !newParent)
oldParent == newParentDescription
TRUEnever evaluated
FALSEnever evaluated
!newParentDescription
TRUEnever evaluated
FALSEnever evaluated
0
162 return;
never executed: return;
0
163-
164#ifdef QT_DEBUG-
165 if (oldParent && item->isWidget()) {
oldParentDescription
TRUEnever evaluated
FALSEnever evaluated
item->isWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
166 QGraphicsWidget *w = static_cast<QGraphicsWidget*>(item);-
167 qWarning("QGraphicsLayout::addChildLayoutItem: %s \"%s\" in wrong parent; moved to correct parent",-
168 w->metaObject()->className(), w->objectName().toLocal8Bit().constData());-
169 }
never executed: end of block
0
170#endif-
171-
172 item->setParentItem(newParent);-
173 }
never executed: end of block
0
174 }
never executed: end of block
0
175}-
176-
177void QGraphicsLayoutPrivate::activateRecursive(QGraphicsLayoutItem *item)-
178{-
179 if (item->isLayout()) {
item->isLayout()Description
TRUEnever evaluated
FALSEnever evaluated
0
180 QGraphicsLayout *layout = static_cast<QGraphicsLayout *>(item);-
181 if (layout->d_func()->activated) {
layout->d_func()->activatedDescription
TRUEnever evaluated
FALSEnever evaluated
0
182 if (QGraphicsLayout::instantInvalidatePropagation()) {
QGraphicsLayou...ePropagation()Description
TRUEnever evaluated
FALSEnever evaluated
0
183 return;
never executed: return;
0
184 } else {-
185 layout->invalidate(); // ### LOOKS SUSPICIOUSLY WRONG!!???-
186 }
never executed: end of block
0
187 }-
188-
189 for (int i = layout->count() - 1; i >= 0; --i) {
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
190 QGraphicsLayoutItem *childItem = layout->itemAt(i);-
191 if (childItem)
childItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
192 activateRecursive(childItem);
never executed: activateRecursive(childItem);
0
193 }
never executed: end of block
0
194 layout->d_func()->activated = true;-
195 }
never executed: end of block
0
196}
never executed: end of block
0
197-
198-
199QT_END_NAMESPACE-
200-
201#endif //QT_NO_GRAPHICSVIEW-
Source codeSwitch to Preprocessed file

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