Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qapplication.h" | - |
43 | | - |
44 | #ifndef QT_NO_GRAPHICSVIEW | - |
45 | #include "qgraphicslayout.h" | - |
46 | #include "qgraphicslayout_p.h" | - |
47 | #include "qgraphicslayoutitem.h" | - |
48 | #include "qgraphicslayoutitem_p.h" | - |
49 | #include "qgraphicswidget.h" | - |
50 | #include "qgraphicswidget_p.h" | - |
51 | #include "qgraphicsscene.h" | - |
52 | | - |
53 | QT_BEGIN_NAMESPACE | - |
54 | | - |
55 | /*! | - |
56 | \class QGraphicsLayout | - |
57 | \brief The QGraphicsLayout class provides the base class for all layouts | - |
58 | in Graphics View. | - |
59 | \since 4.4 | - |
60 | \ingroup graphicsview-api | - |
61 | \inmodule QtWidgets | - |
62 | | - |
63 | QGraphicsLayout is an abstract class that defines a virtual API for | - |
64 | arranging QGraphicsWidget children and other QGraphicsLayoutItem objects | - |
65 | for a QGraphicsWidget. QGraphicsWidget assigns responsibility to a | - |
66 | QGraphicsLayout through QGraphicsWidget::setLayout(). As the widget | - |
67 | is resized, the layout will automatically arrange the widget's children. | - |
68 | QGraphicsLayout inherits QGraphicsLayoutItem, so, it can be managed by | - |
69 | any layout, including its own subclasses. | - |
70 | | - |
71 | \section1 Writing a Custom Layout | - |
72 | | - |
73 | You can use QGraphicsLayout as a base to write your own custom layout | - |
74 | (e.g., a flowlayout), but it is more common to use one of its subclasses | - |
75 | instead - QGraphicsLinearLayout or QGraphicsGridLayout. When creating | - |
76 | a custom layout, the following functions must be reimplemented as a bare | - |
77 | minimum: | - |
78 | | - |
79 | \table | - |
80 | \header \li Function \li Description | - |
81 | \row \li QGraphicsLayoutItem::setGeometry() | - |
82 | \li Notifies you when the geometry of the layout is set. You can | - |
83 | store the geometry in your own layout class in a reimplementation | - |
84 | of this function. | - |
85 | \row \li QGraphicsLayoutItem::sizeHint() | - |
86 | \li Returns the layout's size hints. | - |
87 | \row \li QGraphicsLayout::count() | - |
88 | \li Returns the number of items in your layout. | - |
89 | \row \li QGraphicsLayout::itemAt() | - |
90 | \li Returns a pointer to an item in your layout. | - |
91 | \row \li QGraphicsLayout::removeAt() | - |
92 | \li Removes an item from your layout without destroying it. | - |
93 | \endtable | - |
94 | | - |
95 | For more details on how to implement each function, refer to the individual | - |
96 | function documentation. | - |
97 | | - |
98 | Each layout defines its own API for arranging widgets and layout items. | - |
99 | For example, with a grid layout, you require a row and a | - |
100 | column index with optional row and column spans, alignment, spacing, and more. | - |
101 | A linear layout, however, requires a single row or column index to position its | - |
102 | items. For a grid layout, the order of insertion does not affect the layout in | - |
103 | any way, but for a linear layout, the order is essential. When writing your own | - |
104 | layout subclass, you are free to choose the API that best suits your layout. | - |
105 | | - |
106 | QGraphicsLayout provides the addChildLayoutItem() convenience function to add | - |
107 | layout items to a custom layout. The function will automatically reparent | - |
108 | graphics items, if required. | - |
109 | | - |
110 | \section1 Activating the Layout | - |
111 | | - |
112 | When the layout's geometry changes, QGraphicsLayout immediately rearranges | - |
113 | all of its managed items by calling setGeometry() on each item. This | - |
114 | rearrangement is called \e activating the layout. | - |
115 | | - |
116 | QGraphicsLayout updates its own geometry to match the contentsRect() of the | - |
117 | QGraphicsLayoutItem it is managing. Thus, it will automatically rearrange all | - |
118 | its items when the widget is resized. QGraphicsLayout caches the sizes of all | - |
119 | its managed items to avoid calling setGeometry() too often. | - |
120 | | - |
121 | \note A QGraphicsLayout will have the same geometry as the contentsRect() | - |
122 | of the widget (not the layout) it is assigned to. | - |
123 | | - |
124 | \section2 Activating the Layout Implicitly | - |
125 | | - |
126 | The layout can be activated implicitly using one of two ways: by calling | - |
127 | activate() or by calling invalidate(). Calling activate() activates the layout | - |
128 | immediately. In contrast, calling invalidate() is delayed, as it posts a | - |
129 | \l{QEvent::LayoutRequest}{LayoutRequest} event to the managed widget. Due | - |
130 | to event compression, the activate() will only be called once after control has | - |
131 | returned to the event loop. This is referred to as \e invalidating the layout. | - |
132 | Invalidating the layout also invalidates any cached information. Also, the | - |
133 | invalidate() function is a virtual function. So, you can invalidate your own | - |
134 | cache in a subclass of QGraphicsLayout by reimplementing this function. | - |
135 | | - |
136 | \section1 Event Handling | - |
137 | | - |
138 | QGraphicsLayout listens to events for the widget it manages through the | - |
139 | virtual widgetEvent() event handler. When the layout is assigned to a | - |
140 | widget, all events delivered to the widget are first processed by | - |
141 | widgetEvent(). This allows the layout to be aware of any relevant state | - |
142 | changes on the widget such as visibility changes or layout direction changes. | - |
143 | | - |
144 | \section1 Margin Handling | - |
145 | | - |
146 | The margins of a QGraphicsLayout can be modified by reimplementing | - |
147 | setContentsMargins() and getContentsMargins(). | - |
148 | | - |
149 | */ | - |
150 | | - |
151 | /*! | - |
152 | Contructs a QGraphicsLayout object. | - |
153 | | - |
154 | \a parent is passed to QGraphicsLayoutItem's constructor and the | - |
155 | QGraphicsLayoutItem's isLayout argument is set to \e true. | - |
156 | | - |
157 | If \a parent is a QGraphicsWidget the layout will be installed | - |
158 | on that widget. (Note that installing a layout will delete the old one | - |
159 | installed.) | - |
160 | */ | - |
161 | QGraphicsLayout::QGraphicsLayout(QGraphicsLayoutItem *parent) | - |
162 | : QGraphicsLayoutItem(*new QGraphicsLayoutPrivate) | - |
163 | { | - |
164 | setParentLayoutItem(parent); executed (the execution status of this line is deduced): setParentLayoutItem(parent); | - |
165 | if (parent && !parent->isLayout()) { evaluated: parent yes Evaluation Count:1 | yes Evaluation Count:5 |
partially evaluated: !parent->isLayout() yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-5 |
166 | // If a layout has a parent that is not a layout it must be a QGraphicsWidget. | - |
167 | QGraphicsItem *itemParent = parent->graphicsItem(); executed (the execution status of this line is deduced): QGraphicsItem *itemParent = parent->graphicsItem(); | - |
168 | if (itemParent && itemParent->isWidget()) { partially evaluated: itemParent yes Evaluation Count:1 | no Evaluation Count:0 |
partially evaluated: itemParent->isWidget() yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
169 | static_cast<QGraphicsWidget *>(itemParent)->d_func()->setLayout_helper(this); executed (the execution status of this line is deduced): static_cast<QGraphicsWidget *>(itemParent)->d_func()->setLayout_helper(this); | - |
170 | } else { executed: } Execution Count:1 | 1 |
171 | qWarning("QGraphicsLayout::QGraphicsLayout: Attempt to create a layout with a parent that is" never executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslayout.cpp", 171, __PRETTY_FUNCTION__).warning("QGraphicsLayout::QGraphicsLayout: Attempt to create a layout with a parent that is" | - |
172 | " neither a QGraphicsWidget nor QGraphicsLayout"); never executed (the execution status of this line is deduced): " neither a QGraphicsWidget nor QGraphicsLayout"); | - |
173 | } | 0 |
174 | } | - |
175 | d_func()->sizePolicy = QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, QSizePolicy::DefaultType); executed (the execution status of this line is deduced): d_func()->sizePolicy = QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, QSizePolicy::DefaultType); | - |
176 | setOwnedByLayout(true); executed (the execution status of this line is deduced): setOwnedByLayout(true); | - |
177 | } executed: } Execution Count:6 | 6 |
178 | | - |
179 | /*! | - |
180 | \internal | - |
181 | */ | - |
182 | QGraphicsLayout::QGraphicsLayout(QGraphicsLayoutPrivate &dd, QGraphicsLayoutItem *parent) | - |
183 | : QGraphicsLayoutItem(dd) | - |
184 | { | - |
185 | setParentLayoutItem(parent); executed (the execution status of this line is deduced): setParentLayoutItem(parent); | - |
186 | if (parent && !parent->isLayout()) { evaluated: parent yes Evaluation Count:26 | yes Evaluation Count:638 |
partially evaluated: !parent->isLayout() yes Evaluation Count:26 | no Evaluation Count:0 |
| 0-638 |
187 | // If a layout has a parent that is not a layout it must be a QGraphicsWidget. | - |
188 | QGraphicsItem *itemParent = parent->graphicsItem(); executed (the execution status of this line is deduced): QGraphicsItem *itemParent = parent->graphicsItem(); | - |
189 | if (itemParent && itemParent->isWidget()) { partially evaluated: itemParent yes Evaluation Count:26 | no Evaluation Count:0 |
partially evaluated: itemParent->isWidget() yes Evaluation Count:26 | no Evaluation Count:0 |
| 0-26 |
190 | static_cast<QGraphicsWidget *>(itemParent)->d_func()->setLayout_helper(this); executed (the execution status of this line is deduced): static_cast<QGraphicsWidget *>(itemParent)->d_func()->setLayout_helper(this); | - |
191 | } else { executed: } Execution Count:26 | 26 |
192 | qWarning("QGraphicsLayout::QGraphicsLayout: Attempt to create a layout with a parent that is" never executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslayout.cpp", 192, __PRETTY_FUNCTION__).warning("QGraphicsLayout::QGraphicsLayout: Attempt to create a layout with a parent that is" | - |
193 | " neither a QGraphicsWidget nor QGraphicsLayout"); never executed (the execution status of this line is deduced): " neither a QGraphicsWidget nor QGraphicsLayout"); | - |
194 | } | 0 |
195 | } | - |
196 | d_func()->sizePolicy = QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, QSizePolicy::DefaultType); executed (the execution status of this line is deduced): d_func()->sizePolicy = QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, QSizePolicy::DefaultType); | - |
197 | setOwnedByLayout(true); executed (the execution status of this line is deduced): setOwnedByLayout(true); | - |
198 | } executed: } Execution Count:664 | 664 |
199 | | - |
200 | /*! | - |
201 | Destroys the QGraphicsLayout object. | - |
202 | */ | - |
203 | QGraphicsLayout::~QGraphicsLayout() | - |
204 | { | - |
205 | } | - |
206 | | - |
207 | /*! | - |
208 | Sets the contents margins to \a left, \a top, \a right and \a bottom. The | - |
209 | default contents margins for toplevel layouts are style dependent | - |
210 | (by querying the pixelMetric for QStyle::PM_LayoutLeftMargin, | - |
211 | QStyle::PM_LayoutTopMargin, QStyle::PM_LayoutRightMargin and | - |
212 | QStyle::PM_LayoutBottomMargin). | - |
213 | | - |
214 | For sublayouts the default margins are 0. | - |
215 | | - |
216 | Changing the contents margins automatically invalidates the layout. | - |
217 | | - |
218 | \sa invalidate() | - |
219 | */ | - |
220 | void QGraphicsLayout::setContentsMargins(qreal left, qreal top, qreal right, qreal bottom) | - |
221 | { | - |
222 | Q_D(QGraphicsLayout); executed (the execution status of this line is deduced): QGraphicsLayoutPrivate * const d = d_func(); | - |
223 | if (d->left == left && d->top == top && d->right == right && d->bottom == bottom) partially evaluated: d->left == left no Evaluation Count:0 | yes Evaluation Count:241 |
never evaluated: d->top == top never evaluated: d->right == right never evaluated: d->bottom == bottom | 0-241 |
224 | return; | 0 |
225 | d->left = left; executed (the execution status of this line is deduced): d->left = left; | - |
226 | d->right = right; executed (the execution status of this line is deduced): d->right = right; | - |
227 | d->top = top; executed (the execution status of this line is deduced): d->top = top; | - |
228 | d->bottom = bottom; executed (the execution status of this line is deduced): d->bottom = bottom; | - |
229 | invalidate(); executed (the execution status of this line is deduced): invalidate(); | - |
230 | } executed: } Execution Count:241 | 241 |
231 | | - |
232 | /*! | - |
233 | \reimp | - |
234 | */ | - |
235 | void QGraphicsLayout::getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const | - |
236 | { | - |
237 | Q_D(const QGraphicsLayout); executed (the execution status of this line is deduced): const QGraphicsLayoutPrivate * const d = d_func(); | - |
238 | d->getMargin(left, d->left, QStyle::PM_LayoutLeftMargin); executed (the execution status of this line is deduced): d->getMargin(left, d->left, QStyle::PM_LayoutLeftMargin); | - |
239 | d->getMargin(top, d->top, QStyle::PM_LayoutTopMargin); executed (the execution status of this line is deduced): d->getMargin(top, d->top, QStyle::PM_LayoutTopMargin); | - |
240 | d->getMargin(right, d->right, QStyle::PM_LayoutRightMargin); executed (the execution status of this line is deduced): d->getMargin(right, d->right, QStyle::PM_LayoutRightMargin); | - |
241 | d->getMargin(bottom, d->bottom, QStyle::PM_LayoutBottomMargin); executed (the execution status of this line is deduced): d->getMargin(bottom, d->bottom, QStyle::PM_LayoutBottomMargin); | - |
242 | } executed: } Execution Count:2031 | 2031 |
243 | | - |
244 | /*! | - |
245 | Activates the layout, causing all items in the layout to be immediately | - |
246 | rearranged. This function is based on calling count() and itemAt(), and | - |
247 | then calling setGeometry() on all items sequentially. When activated, | - |
248 | the layout will adjust its geometry to its parent's contentsRect(). | - |
249 | The parent will then invalidate any layout of its own. | - |
250 | | - |
251 | If called in sequence or recursively, e.g., by one of the arranged items | - |
252 | in response to being resized, this function will do nothing. | - |
253 | | - |
254 | Note that the layout is free to use geometry caching to optimize this | - |
255 | process. To forcefully invalidate any such cache, you can call | - |
256 | invalidate() before calling activate(). | - |
257 | | - |
258 | \sa invalidate() | - |
259 | */ | - |
260 | void QGraphicsLayout::activate() | - |
261 | { | - |
262 | Q_D(QGraphicsLayout); executed (the execution status of this line is deduced): QGraphicsLayoutPrivate * const d = d_func(); | - |
263 | if (d->activated) evaluated: d->activated yes Evaluation Count:204 | yes Evaluation Count:252 |
| 204-252 |
264 | return; executed: return; Execution Count:204 | 204 |
265 | | - |
266 | d->activateRecursive(this); executed (the execution status of this line is deduced): d->activateRecursive(this); | - |
267 | | - |
268 | // we don't call activate on a sublayout, but somebody might. | - |
269 | // Therefore, we walk to the parentitem of the toplevel layout. | - |
270 | QGraphicsLayoutItem *parentItem = this; executed (the execution status of this line is deduced): QGraphicsLayoutItem *parentItem = this; | - |
271 | while (parentItem && parentItem->isLayout()) partially evaluated: parentItem yes Evaluation Count:504 | no Evaluation Count:0 |
evaluated: parentItem->isLayout() yes Evaluation Count:252 | yes Evaluation Count:252 |
| 0-504 |
272 | parentItem = parentItem->parentLayoutItem(); executed: parentItem = parentItem->parentLayoutItem(); Execution Count:252 | 252 |
273 | if (!parentItem) partially evaluated: !parentItem no Evaluation Count:0 | yes Evaluation Count:252 |
| 0-252 |
274 | return; | 0 |
275 | Q_ASSERT(!parentItem->isLayout()); executed (the execution status of this line is deduced): qt_noop(); | - |
276 | | - |
277 | if (QGraphicsLayout::instantInvalidatePropagation()) { evaluated: QGraphicsLayout::instantInvalidatePropagation() yes Evaluation Count:18 | yes Evaluation Count:234 |
| 18-234 |
278 | QGraphicsWidget *parentWidget = static_cast<QGraphicsWidget*>(parentItem); executed (the execution status of this line is deduced): QGraphicsWidget *parentWidget = static_cast<QGraphicsWidget*>(parentItem); | - |
279 | if (!parentWidget->parentLayoutItem()) { evaluated: !parentWidget->parentLayoutItem() yes Evaluation Count:8 | yes Evaluation Count:10 |
| 8-10 |
280 | // we've reached the topmost widget, resize it | - |
281 | bool wasResized = parentWidget->testAttribute(Qt::WA_Resized); executed (the execution status of this line is deduced): bool wasResized = parentWidget->testAttribute(Qt::WA_Resized); | - |
282 | parentWidget->resize(parentWidget->size()); executed (the execution status of this line is deduced): parentWidget->resize(parentWidget->size()); | - |
283 | parentWidget->setAttribute(Qt::WA_Resized, wasResized); executed (the execution status of this line is deduced): parentWidget->setAttribute(Qt::WA_Resized, wasResized); | - |
284 | } executed: } Execution Count:8 | 8 |
285 | | - |
286 | setGeometry(parentItem->contentsRect()); // relayout children executed (the execution status of this line is deduced): setGeometry(parentItem->contentsRect()); | - |
287 | } else { executed: } Execution Count:18 | 18 |
288 | setGeometry(parentItem->contentsRect()); // relayout children executed (the execution status of this line is deduced): setGeometry(parentItem->contentsRect()); | - |
289 | parentLayoutItem()->updateGeometry(); executed (the execution status of this line is deduced): parentLayoutItem()->updateGeometry(); | - |
290 | } executed: } Execution Count:234 | 234 |
291 | } | - |
292 | | - |
293 | /*! | - |
294 | Returns true if the layout is currently being activated; otherwise, | - |
295 | returns false. If the layout is being activated, this means that it is | - |
296 | currently in the process of rearranging its items (i.e., the activate() | - |
297 | function has been called, and has not yet returned). | - |
298 | | - |
299 | \sa activate(), invalidate() | - |
300 | */ | - |
301 | bool QGraphicsLayout::isActivated() const | - |
302 | { | - |
303 | Q_D(const QGraphicsLayout); executed (the execution status of this line is deduced): const QGraphicsLayoutPrivate * const d = d_func(); | - |
304 | return d->activated; executed: return d->activated; Execution Count:332 | 332 |
305 | } | - |
306 | | - |
307 | /*! | - |
308 | Clears any cached geometry and size hint information in the layout, and | - |
309 | posts a \l{QEvent::LayoutRequest}{LayoutRequest} event to the managed | - |
310 | parent QGraphicsLayoutItem. | - |
311 | | - |
312 | \sa activate(), setGeometry() | - |
313 | */ | - |
314 | void QGraphicsLayout::invalidate() | - |
315 | { | - |
316 | if (QGraphicsLayout::instantInvalidatePropagation()) { evaluated: QGraphicsLayout::instantInvalidatePropagation() yes Evaluation Count:39 | yes Evaluation Count:3802 |
| 39-3802 |
317 | updateGeometry(); executed (the execution status of this line is deduced): updateGeometry(); | - |
318 | } else { executed: } Execution Count:39 | 39 |
319 | // only mark layouts as invalid (activated = false) if we can post a LayoutRequest event. | - |
320 | QGraphicsLayoutItem *layoutItem = this; executed (the execution status of this line is deduced): QGraphicsLayoutItem *layoutItem = this; | - |
321 | while (layoutItem && layoutItem->isLayout()) { evaluated: layoutItem yes Evaluation Count:6491 | yes Evaluation Count:1189 |
evaluated: layoutItem->isLayout() yes Evaluation Count:3878 | yes Evaluation Count:2613 |
| 1189-6491 |
322 | // we could call updateGeometry(), but what if that method | - |
323 | // does not call the base implementation? In addition, updateGeometry() | - |
324 | // does more than we need. | - |
325 | layoutItem->d_func()->sizeHintCacheDirty = true; executed (the execution status of this line is deduced): layoutItem->d_func()->sizeHintCacheDirty = true; | - |
326 | layoutItem->d_func()->sizeHintWithConstraintCacheDirty = true; executed (the execution status of this line is deduced): layoutItem->d_func()->sizeHintWithConstraintCacheDirty = true; | - |
327 | layoutItem = layoutItem->parentLayoutItem(); executed (the execution status of this line is deduced): layoutItem = layoutItem->parentLayoutItem(); | - |
328 | } executed: } Execution Count:3878 | 3878 |
329 | if (layoutItem) { evaluated: layoutItem yes Evaluation Count:2613 | yes Evaluation Count:1189 |
| 1189-2613 |
330 | layoutItem->d_func()->sizeHintCacheDirty = true; executed (the execution status of this line is deduced): layoutItem->d_func()->sizeHintCacheDirty = true; | - |
331 | layoutItem->d_func()->sizeHintWithConstraintCacheDirty = true; executed (the execution status of this line is deduced): layoutItem->d_func()->sizeHintWithConstraintCacheDirty = true; | - |
332 | } executed: } Execution Count:2613 | 2613 |
333 | | - |
334 | bool postIt = layoutItem ? !layoutItem->isLayout() : false; evaluated: layoutItem yes Evaluation Count:2613 | yes Evaluation Count:1189 |
| 1189-2613 |
335 | if (postIt) { evaluated: postIt yes Evaluation Count:2613 | yes Evaluation Count:1189 |
| 1189-2613 |
336 | layoutItem = this; executed (the execution status of this line is deduced): layoutItem = this; | - |
337 | while (layoutItem && layoutItem->isLayout() partially evaluated: layoutItem yes Evaluation Count:3102 | no Evaluation Count:0 |
evaluated: layoutItem->isLayout() yes Evaluation Count:2685 | yes Evaluation Count:417 |
| 0-3102 |
338 | && static_cast<QGraphicsLayout*>(layoutItem)->d_func()->activated) { evaluated: static_cast<QGraphicsLayout*>(layoutItem)->d_func()->activated yes Evaluation Count:489 | yes Evaluation Count:2196 |
| 489-2196 |
339 | static_cast<QGraphicsLayout*>(layoutItem)->d_func()->activated = false; executed (the execution status of this line is deduced): static_cast<QGraphicsLayout*>(layoutItem)->d_func()->activated = false; | - |
340 | layoutItem = layoutItem->parentLayoutItem(); executed (the execution status of this line is deduced): layoutItem = layoutItem->parentLayoutItem(); | - |
341 | } executed: } Execution Count:489 | 489 |
342 | if (layoutItem && !layoutItem->isLayout()) { partially evaluated: layoutItem yes Evaluation Count:2613 | no Evaluation Count:0 |
evaluated: !layoutItem->isLayout() yes Evaluation Count:417 | yes Evaluation Count:2196 |
| 0-2613 |
343 | // If a layout has a parent that is not a layout it must be a QGraphicsWidget. | - |
344 | QApplication::postEvent(static_cast<QGraphicsWidget *>(layoutItem), new QEvent(QEvent::LayoutRequest)); executed (the execution status of this line is deduced): QApplication::postEvent(static_cast<QGraphicsWidget *>(layoutItem), new QEvent(QEvent::LayoutRequest)); | - |
345 | } executed: } Execution Count:417 | 417 |
346 | } executed: } Execution Count:2613 | 2613 |
347 | } executed: } Execution Count:3802 | 3802 |
348 | } | - |
349 | | - |
350 | /*! | - |
351 | \reimp | - |
352 | */ | - |
353 | void QGraphicsLayout::updateGeometry() | - |
354 | { | - |
355 | Q_D(QGraphicsLayout); executed (the execution status of this line is deduced): QGraphicsLayoutPrivate * const d = d_func(); | - |
356 | if (QGraphicsLayout::instantInvalidatePropagation()) { evaluated: QGraphicsLayout::instantInvalidatePropagation() yes Evaluation Count:39 | yes Evaluation Count:300 |
| 39-300 |
357 | d->activated = false; executed (the execution status of this line is deduced): d->activated = false; | - |
358 | QGraphicsLayoutItem::updateGeometry(); executed (the execution status of this line is deduced): QGraphicsLayoutItem::updateGeometry(); | - |
359 | | - |
360 | QGraphicsLayoutItem *parentItem = parentLayoutItem(); executed (the execution status of this line is deduced): QGraphicsLayoutItem *parentItem = parentLayoutItem(); | - |
361 | if (!parentItem) partially evaluated: !parentItem no Evaluation Count:0 | yes Evaluation Count:39 |
| 0-39 |
362 | return; | 0 |
363 | | - |
364 | if (parentItem->isLayout()) partially evaluated: parentItem->isLayout() no Evaluation Count:0 | yes Evaluation Count:39 |
| 0-39 |
365 | static_cast<QGraphicsLayout *>(parentItem)->invalidate(); never executed: static_cast<QGraphicsLayout *>(parentItem)->invalidate(); | 0 |
366 | else | - |
367 | parentItem->updateGeometry(); executed: parentItem->updateGeometry(); Execution Count:39 | 39 |
368 | } else { | - |
369 | QGraphicsLayoutItem::updateGeometry(); executed (the execution status of this line is deduced): QGraphicsLayoutItem::updateGeometry(); | - |
370 | if (QGraphicsLayoutItem *parentItem = parentLayoutItem()) { evaluated: QGraphicsLayoutItem *parentItem = parentLayoutItem() yes Evaluation Count:193 | yes Evaluation Count:107 |
| 107-193 |
371 | if (parentItem->isLayout()) { evaluated: parentItem->isLayout() yes Evaluation Count:15 | yes Evaluation Count:178 |
| 15-178 |
372 | parentItem->updateGeometry(); executed (the execution status of this line is deduced): parentItem->updateGeometry(); | - |
373 | } else { executed: } Execution Count:15 | 15 |
374 | invalidate(); executed (the execution status of this line is deduced): invalidate(); | - |
375 | } executed: } Execution Count:178 | 178 |
376 | } | - |
377 | } executed: } Execution Count:300 | 300 |
378 | } | - |
379 | | - |
380 | /*! | - |
381 | This virtual event handler receives all events for the managed | - |
382 | widget. QGraphicsLayout uses this event handler to listen for layout | - |
383 | related events such as geometry changes, layout changes or layout | - |
384 | direction changes. | - |
385 | | - |
386 | \a e is a pointer to the event. | - |
387 | | - |
388 | You can reimplement this event handler to track similar events for your | - |
389 | own custom layout. | - |
390 | | - |
391 | \sa QGraphicsWidget::event(), QGraphicsItem::sceneEvent() | - |
392 | */ | - |
393 | void QGraphicsLayout::widgetEvent(QEvent *e) | - |
394 | { | - |
395 | switch (e->type()) { | - |
396 | case QEvent::GraphicsSceneResize: | - |
397 | if (isActivated()) { evaluated: isActivated() yes Evaluation Count:116 | yes Evaluation Count:142 |
| 116-142 |
398 | setGeometry(parentLayoutItem()->contentsRect()); executed (the execution status of this line is deduced): setGeometry(parentLayoutItem()->contentsRect()); | - |
399 | } else { executed: } Execution Count:116 | 116 |
400 | activate(); // relies on that activate() will call updateGeometry() executed (the execution status of this line is deduced): activate(); | - |
401 | } executed: } Execution Count:142 | 142 |
402 | break; executed: break; Execution Count:258 | 258 |
403 | case QEvent::LayoutRequest: | - |
404 | activate(); executed (the execution status of this line is deduced): activate(); | - |
405 | break; executed: break; Execution Count:201 | 201 |
406 | case QEvent::LayoutDirectionChange: | - |
407 | invalidate(); executed (the execution status of this line is deduced): invalidate(); | - |
408 | break; executed: break; Execution Count:3 | 3 |
409 | default: | - |
410 | break; executed: break; Execution Count:318 | 318 |
411 | } | - |
412 | } executed: } Execution Count:780 | 780 |
413 | | - |
414 | /*! | - |
415 | \fn virtual int QGraphicsLayout::count() const = 0 | - |
416 | | - |
417 | This pure virtual function must be reimplemented in a subclass of | - |
418 | QGraphicsLayout to return the number of items in the layout. | - |
419 | | - |
420 | The subclass is free to decide how to store the items. | - |
421 | | - |
422 | \sa itemAt(), removeAt() | - |
423 | */ | - |
424 | | - |
425 | /*! | - |
426 | \fn virtual QGraphicsLayoutItem *QGraphicsLayout::itemAt(int i) const = 0 | - |
427 | | - |
428 | This pure virtual function must be reimplemented in a subclass of | - |
429 | QGraphicsLayout to return a pointer to the item at index \a i. The | - |
430 | reimplementation can assume that \a i is valid (i.e., it respects the | - |
431 | value of count()). | - |
432 | Together with count(), it is provided as a means of iterating over all items in a layout. | - |
433 | | - |
434 | The subclass is free to decide how to store the items, and the visual arrangement | - |
435 | does not have to be reflected through this function. | - |
436 | | - |
437 | \sa count(), removeAt() | - |
438 | */ | - |
439 | | - |
440 | /*! | - |
441 | \fn virtual void QGraphicsLayout::removeAt(int index) = 0 | - |
442 | | - |
443 | This pure virtual function must be reimplemented in a subclass of | - |
444 | QGraphicsLayout to remove the item at \a index. The | - |
445 | reimplementation can assume that \a index is valid (i.e., it | - |
446 | respects the value of count()). | - |
447 | | - |
448 | The implementation must ensure that the parentLayoutItem() of | - |
449 | the removed item does not point to this layout, since the item is | - |
450 | considered to be removed from the layout hierarchy. | - |
451 | | - |
452 | If the layout is to be reused between applications, we recommend | - |
453 | that the layout deletes the item, but the graphics view framework | - |
454 | does not depend on this. | - |
455 | | - |
456 | The subclass is free to decide how to store the items. | - |
457 | | - |
458 | \sa itemAt(), count() | - |
459 | */ | - |
460 | | - |
461 | /*! | - |
462 | \since 4.6 | - |
463 | | - |
464 | This function is a convenience function provided for custom layouts, and will go through | - |
465 | all items in the layout and reparent their graphics items to the closest QGraphicsWidget | - |
466 | ancestor of the layout. | - |
467 | | - |
468 | If \a layoutItem is already in a different layout, it will be removed from that layout. | - |
469 | | - |
470 | If custom layouts want special behaviour they can ignore to use this function, and implement | - |
471 | their own behaviour. | - |
472 | | - |
473 | \sa graphicsItem() | - |
474 | */ | - |
475 | void QGraphicsLayout::addChildLayoutItem(QGraphicsLayoutItem *layoutItem) | - |
476 | { | - |
477 | Q_D(QGraphicsLayout); never executed (the execution status of this line is deduced): QGraphicsLayoutPrivate * const d = d_func(); | - |
478 | d->addChildLayoutItem(layoutItem); never executed (the execution status of this line is deduced): d->addChildLayoutItem(layoutItem); | - |
479 | } | 0 |
480 | | - |
481 | static bool g_instantInvalidatePropagation = false; | - |
482 | | - |
483 | /*! | - |
484 | \internal | - |
485 | \since 4.8 | - |
486 | \sa instantInvalidatePropagation() | - |
487 | | - |
488 | Calling this function with \a enable set to true will enable a feature that | - |
489 | makes propagation of invalidation up to ancestor layout items to be done in | - |
490 | one go. It will propagate up the parentLayoutItem() hierarchy until it has | - |
491 | reached the root. If the root item is a QGraphicsWidget, it will *post* a | - |
492 | layout request to it. When the layout request is consumed it will traverse | - |
493 | down the hierarchy of layouts and widgets and activate all layouts that is | - |
494 | invalid (not activated). This is the recommended behaviour. | - |
495 | | - |
496 | If not set it will also propagate up the parentLayoutItem() hierarchy, but | - |
497 | it will stop at the \e{first widget} it encounters, and post a layout | - |
498 | request to the widget. When the layout request is consumed, this might | - |
499 | cause it to continue propagation up to the parentLayoutItem() of the | - |
500 | widget. It will continue in this fashion until it has reached a widget with | - |
501 | no parentLayoutItem(). This strategy might cause drawing artifacts, since | - |
502 | it is not done in one go, and the consumption of layout requests might be | - |
503 | interleaved by consumption of paint events, which might cause significant | - |
504 | flicker. | - |
505 | Note, this is not the recommended behavior, but for compatibility reasons | - |
506 | this is the default behaviour. | - |
507 | */ | - |
508 | void QGraphicsLayout::setInstantInvalidatePropagation(bool enable) | - |
509 | { | - |
510 | g_instantInvalidatePropagation = enable; executed (the execution status of this line is deduced): g_instantInvalidatePropagation = enable; | - |
511 | } executed: } Execution Count:2 | 2 |
512 | | - |
513 | /*! | - |
514 | \internal | - |
515 | \since 4.8 | - |
516 | \sa setInstantInvalidatePropagation() | - |
517 | | - |
518 | returns true if the complete widget/layout hierarchy is rearranged in one go. | - |
519 | */ | - |
520 | bool QGraphicsLayout::instantInvalidatePropagation() | - |
521 | { | - |
522 | return g_instantInvalidatePropagation; executed: return g_instantInvalidatePropagation; Execution Count:16885 | 16885 |
523 | } | - |
524 | | - |
525 | QT_END_NAMESPACE | - |
526 | | - |
527 | #endif //QT_NO_GRAPHICSVIEW | - |
528 | | - |
| | |