graphicsview/qgraphicslinearlayout.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
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/*! -
43 \class QGraphicsLinearLayout -
44 \brief The QGraphicsLinearLayout class provides a horizontal or vertical -
45 layout for managing widgets in Graphics View. -
46 \since 4.4 -
47 \ingroup graphicsview-api -
48 \inmodule QtWidgets -
49 -
50 The default orientation for a linear layout is Qt::Horizontal. You can -
51 choose a vertical orientation either by calling setOrientation(), or by -
52 passing Qt::Vertical to QGraphicsLinearLayout's constructor. -
53 -
54 The most common way to use QGraphicsLinearLayout is to construct an object -
55 on the heap with no parent, add widgets and layouts by calling addItem(), -
56 and finally assign the layout to a widget by calling -
57 QGraphicsWidget::setLayout(). -
58 -
59 \snippet code/src_gui_graphicsview_qgraphicslinearlayout.cpp 0 -
60 -
61 You can add widgets, layouts, stretches (addStretch(), insertStretch() or -
62 setStretchFactor()), and spacings (setItemSpacing()) to a linear -
63 layout. The layout takes ownership of the items. In some cases when the layout -
64 item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a -
65 ambiguity in ownership because the layout item belongs to two ownership hierarchies. -
66 See the documentation of QGraphicsLayoutItem::setOwnedByLayout() how to handle -
67 this. -
68 You can access each item in the layout by calling count() and itemAt(). Calling -
69 removeAt() or removeItem() will remove an item from the layout, without -
70 destroying it. -
71 -
72 \section1 Size Hints and Size Policies in QGraphicsLinearLayout -
73 -
74 QGraphicsLinearLayout respects each item's size hints and size policies, -
75 and when the layout contains more space than the items can fill, each item -
76 is arranged according to the layout's alignment for that item. You can set -
77 an alignment for each item by calling setAlignment(), and check the -
78 alignment for any item by calling alignment(). By default, items are -
79 aligned to the top left. -
80 -
81 \section1 Spacing within QGraphicsLinearLayout -
82 -
83 Between the items, the layout distributes some space. The actual amount of -
84 space depends on the managed widget's current style, but the common -
85 spacing is 4. You can also set your own spacing by calling setSpacing(), -
86 and get the current spacing value by calling spacing(). If you want to -
87 configure individual spacing for your items, you can call setItemSpacing(). -
88 -
89 \section1 Stretch Factor in QGraphicsLinearLayout -
90 -
91 You can assign a stretch factor to each item to control how much space it -
92 will get compared to the other items. By default, two identical widgets -
93 arranged in a linear layout will have the same size, but if the first -
94 widget has a stretch factor of 1 and the second widget has a stretch -
95 factor of 2, the first widget will get 1/3 of the available space, and the -
96 second will get 2/3. -
97 -
98 QGraphicsLinearLayout calculates the distribution of sizes by adding up -
99 the stretch factors of all items, and then dividing the available space -
100 accordingly. The default stretch factor is 0 for all items; a factor of 0 -
101 means the item does not have any defined stretch factor; effectively this -
102 is the same as setting the stretch factor to 1. The stretch factor only -
103 applies to the available space in the lengthwise direction of the layout -
104 (following its orientation). If you want to control both the item's -
105 horizontal and vertical stretch, you can use QGraphicsGridLayout instead. -
106 -
107 \section1 QGraphicsLinearLayout Compared to Other Layouts -
108 -
109 QGraphicsLinearLayout is very similar to QVBoxLayout and QHBoxLayout, but -
110 in contrast to these classes, it is used to manage QGraphicsWidget and -
111 QGraphicsLayout instead of QWidget and QLayout. -
112 -
113 \sa QGraphicsGridLayout, QGraphicsWidget -
114*/ -
115 -
116#include "qapplication.h" -
117 -
118#ifndef QT_NO_GRAPHICSVIEW -
119 -
120#include "qwidget.h" -
121#include "qgraphicslayout_p.h" -
122#include "qgraphicslayoutitem.h" -
123#include "qgraphicslinearlayout.h" -
124#include "qgraphicswidget.h" -
125#include "qgridlayoutengine_p.h" -
126#ifdef QT_DEBUG -
127#include <QtCore/qdebug.h> -
128#endif -
129 -
130QT_BEGIN_NAMESPACE -
131 -
132class QGraphicsLinearLayoutPrivate : public QGraphicsLayoutPrivate -
133{ -
134public: -
135 QGraphicsLinearLayoutPrivate(Qt::Orientation orientation) : orientation(orientation) { }
executed: }
Execution Count:399
399
136 -
137 void removeGridItem(QGridLayoutItem *gridItem); -
138 QLayoutStyleInfo styleInfo() const; -
139 void fixIndex(int *index) const; -
140 int gridRow(int index) const; -
141 int gridColumn(int index) const; -
142 -
143 Qt::Orientation orientation; -
144 QGridLayoutEngine engine; -
145}; -
146 -
147void QGraphicsLinearLayoutPrivate::removeGridItem(QGridLayoutItem *gridItem) -
148{ -
149 int index = gridItem->firstRow(orientation);
executed (the execution status of this line is deduced): int index = gridItem->firstRow(orientation);
-
150 engine.removeItem(gridItem);
executed (the execution status of this line is deduced): engine.removeItem(gridItem);
-
151 engine.removeRows(index, 1, orientation);
executed (the execution status of this line is deduced): engine.removeRows(index, 1, orientation);
-
152}
executed: }
Execution Count:622
622
153 -
154void QGraphicsLinearLayoutPrivate::fixIndex(int *index) const -
155{ -
156 int count = engine.rowCount(orientation);
executed (the execution status of this line is deduced): int count = engine.rowCount(orientation);
-
157 if (uint(*index) > uint(count))
evaluated: uint(*index) > uint(count)
TRUEFALSE
yes
Evaluation Count:628
yes
Evaluation Count:41
41-628
158 *index = count;
executed: *index = count;
Execution Count:628
628
159}
executed: }
Execution Count:669
669
160 -
161int QGraphicsLinearLayoutPrivate::gridRow(int index) const -
162{ -
163 if (orientation == Qt::Horizontal)
evaluated: orientation == Qt::Horizontal
TRUEFALSE
yes
Evaluation Count:531
yes
Evaluation Count:106
106-531
164 return 0;
executed: return 0;
Execution Count:531
531
165 return int(qMin(uint(index), uint(engine.rowCount())));
executed: return int(qMin(uint(index), uint(engine.rowCount())));
Execution Count:106
106
166} -
167 -
168int QGraphicsLinearLayoutPrivate::gridColumn(int index) const -
169{ -
170 if (orientation == Qt::Vertical)
evaluated: orientation == Qt::Vertical
TRUEFALSE
yes
Evaluation Count:106
yes
Evaluation Count:531
106-531
171 return 0;
executed: return 0;
Execution Count:106
106
172 return int(qMin(uint(index), uint(engine.columnCount())));
executed: return int(qMin(uint(index), uint(engine.columnCount())));
Execution Count:531
531
173} -
174 -
175Q_GLOBAL_STATIC(QWidget, globalStyleInfoWidget)
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:1278
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1276
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-1278
176 -
177QLayoutStyleInfo QGraphicsLinearLayoutPrivate::styleInfo() const -
178{ -
179 QGraphicsItem *item = parentItem();
executed (the execution status of this line is deduced): QGraphicsItem *item = parentItem();
-
180 QStyle *style = (item && item->isWidget()) ? static_cast<QGraphicsWidget*>(item)->style() : QApplication::style();
evaluated: item
TRUEFALSE
yes
Evaluation Count:928
yes
Evaluation Count:350
partially evaluated: item->isWidget()
TRUEFALSE
yes
Evaluation Count:928
no
Evaluation Count:0
0-928
181 return QLayoutStyleInfo(style, globalStyleInfoWidget());
executed: return QLayoutStyleInfo(style, globalStyleInfoWidget());
Execution Count:1278
1278
182} -
183 -
184/*! -
185 Constructs a QGraphicsLinearLayout instance. You can pass the -
186 \a orientation for the layout, either horizontal or vertical, and -
187 \a parent is passed to QGraphicsLayout's constructor. -
188*/ -
189QGraphicsLinearLayout::QGraphicsLinearLayout(Qt::Orientation orientation, QGraphicsLayoutItem *parent) -
190 : QGraphicsLayout(*new QGraphicsLinearLayoutPrivate(orientation), parent) -
191{ -
192}
executed: }
Execution Count:373
373
193 -
194/*! -
195 Constructs a QGraphicsLinearLayout instance using Qt::Horizontal -
196 orientation. \a parent is passed to QGraphicsLayout's constructor. -
197*/ -
198QGraphicsLinearLayout::QGraphicsLinearLayout(QGraphicsLayoutItem *parent) -
199 : QGraphicsLayout(*new QGraphicsLinearLayoutPrivate(Qt::Horizontal), parent) -
200{ -
201}
executed: }
Execution Count:26
26
202 -
203/*! -
204 Destroys the QGraphicsLinearLayout object. -
205*/ -
206QGraphicsLinearLayout::~QGraphicsLinearLayout() -
207{ -
208 for (int i = count() - 1; i >= 0; --i) {
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:595
yes
Evaluation Count:392
392-595
209 QGraphicsLayoutItem *item = itemAt(i);
executed (the execution status of this line is deduced): QGraphicsLayoutItem *item = itemAt(i);
-
210 // The following lines can be removed, but this removes the item -
211 // from the layout more efficiently than the implementation of -
212 // ~QGraphicsLayoutItem. -
213 removeAt(i);
executed (the execution status of this line is deduced): removeAt(i);
-
214 if (item) {
partially evaluated: item
TRUEFALSE
yes
Evaluation Count:595
no
Evaluation Count:0
0-595
215 item->setParentLayoutItem(0);
executed (the execution status of this line is deduced): item->setParentLayoutItem(0);
-
216 if (item->ownedByLayout())
evaluated: item->ownedByLayout()
TRUEFALSE
yes
Evaluation Count:209
yes
Evaluation Count:386
209-386
217 delete item;
executed: delete item;
Execution Count:209
209
218 }
executed: }
Execution Count:595
595
219 }
executed: }
Execution Count:595
595
220}
executed: }
Execution Count:392
392
221 -
222/*! -
223 Change the layout orientation to \a orientation. Changing the layout -
224 orientation will automatically invalidate the layout. -
225 -
226 \sa orientation() -
227*/ -
228void QGraphicsLinearLayout::setOrientation(Qt::Orientation orientation) -
229{ -
230 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
231 if (orientation != d->orientation) {
evaluated: orientation != d->orientation
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:1
1-8
232 d->engine.transpose();
executed (the execution status of this line is deduced): d->engine.transpose();
-
233 d->orientation = orientation;
executed (the execution status of this line is deduced): d->orientation = orientation;
-
234 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
235 }
executed: }
Execution Count:8
8
236}
executed: }
Execution Count:9
9
237 -
238/*! -
239 Returns the layout orientation. -
240 \sa setOrientation() -
241 */ -
242Qt::Orientation QGraphicsLinearLayout::orientation() const -
243{ -
244 Q_D(const QGraphicsLinearLayout);
executed (the execution status of this line is deduced): const QGraphicsLinearLayoutPrivate * const d = d_func();
-
245 return d->orientation;
executed: return d->orientation;
Execution Count:6
6
246} -
247 -
248/*! -
249 \fn void QGraphicsLinearLayout::addItem(QGraphicsLayoutItem *item) -
250 -
251 This convenience function is equivalent to calling -
252 insertItem(-1, \a item). -
253*/ -
254 -
255/*! -
256 \fn void QGraphicsLinearLayout::addStretch(int stretch) -
257 -
258 This convenience function is equivalent to calling -
259 insertStretch(-1, \a stretch). -
260*/ -
261 -
262/*! -
263 Inserts \a item into the layout at \a index, or before any item that is -
264 currently at \a index. -
265 -
266 \sa addItem(), itemAt(), insertStretch(), setItemSpacing() -
267*/ -
268void QGraphicsLinearLayout::insertItem(int index, QGraphicsLayoutItem *item) -
269{ -
270 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
271 if (!item) {
evaluated: !item
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:638
4-638
272 qWarning("QGraphicsLinearLayout::insertItem: cannot insert null item");
executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslinearlayout.cpp", 272, __PRETTY_FUNCTION__).warning("QGraphicsLinearLayout::insertItem: cannot insert null item");
-
273 return;
executed: return;
Execution Count:4
4
274 } -
275 if (item == this) {
evaluated: item == this
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:637
1-637
276 qWarning("QGraphicsLinearLayout::insertItem: cannot insert itself");
executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslinearlayout.cpp", 276, __PRETTY_FUNCTION__).warning("QGraphicsLinearLayout::insertItem: cannot insert itself");
-
277 return;
executed: return;
Execution Count:1
1
278 } -
279 d->addChildLayoutItem(item);
executed (the execution status of this line is deduced): d->addChildLayoutItem(item);
-
280 -
281 Q_ASSERT(item);
executed (the execution status of this line is deduced): qt_noop();
-
282 d->fixIndex(&index);
executed (the execution status of this line is deduced): d->fixIndex(&index);
-
283 d->engine.insertRow(index, d->orientation);
executed (the execution status of this line is deduced): d->engine.insertRow(index, d->orientation);
-
284 new QGridLayoutItem(&d->engine, item, d->gridRow(index), d->gridColumn(index), 1, 1, 0, index);
executed (the execution status of this line is deduced): new QGridLayoutItem(&d->engine, item, d->gridRow(index), d->gridColumn(index), 1, 1, 0, index);
-
285 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
286}
executed: }
Execution Count:637
637
287 -
288/*! -
289 Inserts a stretch of \a stretch at \a index, or before any item that is -
290 currently at \a index. -
291 -
292 \sa addStretch(), setStretchFactor(), setItemSpacing(), insertItem() -
293*/ -
294void QGraphicsLinearLayout::insertStretch(int index, int stretch) -
295{ -
296 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
297 d->fixIndex(&index);
executed (the execution status of this line is deduced): d->fixIndex(&index);
-
298 d->engine.insertRow(index, d->orientation);
executed (the execution status of this line is deduced): d->engine.insertRow(index, d->orientation);
-
299 d->engine.setRowStretchFactor(index, stretch, d->orientation);
executed (the execution status of this line is deduced): d->engine.setRowStretchFactor(index, stretch, d->orientation);
-
300 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
301}
executed: }
Execution Count:32
32
302 -
303/*! -
304 Removes \a item from the layout without destroying it. Ownership of -
305 \a item is transferred to the caller. -
306 -
307 \sa removeAt(), insertItem() -
308*/ -
309void QGraphicsLinearLayout::removeItem(QGraphicsLayoutItem *item) -
310{ -
311 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
312 if (QGridLayoutItem *gridItem = d->engine.findLayoutItem(item)) {
evaluated: QGridLayoutItem *gridItem = d->engine.findLayoutItem(item)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:2
2-6
313 item->setParentLayoutItem(0);
executed (the execution status of this line is deduced): item->setParentLayoutItem(0);
-
314 d->removeGridItem(gridItem);
executed (the execution status of this line is deduced): d->removeGridItem(gridItem);
-
315 delete gridItem;
executed (the execution status of this line is deduced): delete gridItem;
-
316 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
317 }
executed: }
Execution Count:6
6
318}
executed: }
Execution Count:8
8
319 -
320/*! -
321 Removes the item at \a index without destroying it. Ownership of the item -
322 is transferred to the caller. -
323 -
324 \sa removeItem(), insertItem() -
325*/ -
326void QGraphicsLinearLayout::removeAt(int index) -
327{ -
328 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
329 if (index < 0 || index >= d->engine.itemCount()) {
partially evaluated: index < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:616
partially evaluated: index >= d->engine.itemCount()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:616
0-616
330 qWarning("QGraphicsLinearLayout::removeAt: invalid index %d", index);
never executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslinearlayout.cpp", 330, __PRETTY_FUNCTION__).warning("QGraphicsLinearLayout::removeAt: invalid index %d", index);
-
331 return;
never executed: return;
0
332 } -
333 if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) {
partially evaluated: QGridLayoutItem *gridItem = d->engine.itemAt(index)
TRUEFALSE
yes
Evaluation Count:616
no
Evaluation Count:0
0-616
334 if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
partially evaluated: QGraphicsLayoutItem *layoutItem = gridItem->layoutItem()
TRUEFALSE
yes
Evaluation Count:616
no
Evaluation Count:0
0-616
335 layoutItem->setParentLayoutItem(0);
executed: layoutItem->setParentLayoutItem(0);
Execution Count:616
616
336 d->removeGridItem(gridItem);
executed (the execution status of this line is deduced): d->removeGridItem(gridItem);
-
337 delete gridItem;
executed (the execution status of this line is deduced): delete gridItem;
-
338 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
339 }
executed: }
Execution Count:616
616
340}
executed: }
Execution Count:616
616
341 -
342/*! -
343 Sets the layout's spacing to \a spacing. Spacing refers to the -
344 vertical and horizontal distances between items. -
345 -
346 \sa setItemSpacing(), setStretchFactor(), QGraphicsGridLayout::setSpacing() -
347*/ -
348void QGraphicsLinearLayout::setSpacing(qreal spacing) -
349{ -
350 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
351 if (spacing < 0) {
partially evaluated: spacing < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:45
0-45
352 qWarning("QGraphicsLinearLayout::setSpacing: invalid spacing %g", spacing);
never executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslinearlayout.cpp", 352, __PRETTY_FUNCTION__).warning("QGraphicsLinearLayout::setSpacing: invalid spacing %g", spacing);
-
353 return;
never executed: return;
0
354 } -
355 d->engine.setSpacing(spacing, Qt::Horizontal | Qt::Vertical);
executed (the execution status of this line is deduced): d->engine.setSpacing(spacing, Qt::Horizontal | Qt::Vertical);
-
356 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
357}
executed: }
Execution Count:45
45
358 -
359/*! -
360 Returns the layout's spacing. Spacing refers to the -
361 vertical and horizontal distances between items. -
362 -
363 \sa setSpacing() -
364 */ -
365qreal QGraphicsLinearLayout::spacing() const -
366{ -
367 Q_D(const QGraphicsLinearLayout);
executed (the execution status of this line is deduced): const QGraphicsLinearLayoutPrivate * const d = d_func();
-
368 return d->engine.spacing(d->styleInfo(), d->orientation);
executed: return d->engine.spacing(d->styleInfo(), d->orientation);
Execution Count:15
15
369} -
370 -
371/*! -
372 Sets the spacing after item at \a index to \a spacing. -
373*/ -
374void QGraphicsLinearLayout::setItemSpacing(int index, qreal spacing) -
375{ -
376 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
377 d->engine.setRowSpacing(index, spacing, d->orientation);
executed (the execution status of this line is deduced): d->engine.setRowSpacing(index, spacing, d->orientation);
-
378 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
379}
executed: }
Execution Count:15
15
380/*! -
381 Returns the spacing after item at \a index. -
382*/ -
383qreal QGraphicsLinearLayout::itemSpacing(int index) const -
384{ -
385 Q_D(const QGraphicsLinearLayout);
executed (the execution status of this line is deduced): const QGraphicsLinearLayoutPrivate * const d = d_func();
-
386 return d->engine.rowSpacing(index, d->orientation);
executed: return d->engine.rowSpacing(index, d->orientation);
Execution Count:3
3
387} -
388 -
389/*! -
390 Sets the stretch factor for \a item to \a stretch. If an item's stretch -
391 factor changes, this function will invalidate the layout. -
392 -
393 Setting \a stretch to 0 removes the stretch factor from the item, and is -
394 effectively equivalent to setting \a stretch to 1. -
395 -
396 \sa stretchFactor() -
397*/ -
398void QGraphicsLinearLayout::setStretchFactor(QGraphicsLayoutItem *item, int stretch) -
399{ -
400 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
401 if (!item) {
evaluated: !item
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:9
2-9
402 qWarning("QGraphicsLinearLayout::setStretchFactor: cannot assign"
executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslinearlayout.cpp", 402, __PRETTY_FUNCTION__).warning("QGraphicsLinearLayout::setStretchFactor: cannot assign"
-
403 " a stretch factor to a null item");
executed (the execution status of this line is deduced): " a stretch factor to a null item");
-
404 return;
executed: return;
Execution Count:2
2
405 } -
406 if (stretchFactor(item) == stretch)
partially evaluated: stretchFactor(item) == stretch
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
407 return;
never executed: return;
0
408 d->engine.setStretchFactor(item, stretch, d->orientation);
executed (the execution status of this line is deduced): d->engine.setStretchFactor(item, stretch, d->orientation);
-
409 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
410}
executed: }
Execution Count:9
9
411 -
412/*! -
413 Returns the stretch factor for \a item. The default stretch factor is 0, -
414 meaning that the item has no assigned stretch factor. -
415 -
416 \sa setStretchFactor() -
417*/ -
418int QGraphicsLinearLayout::stretchFactor(QGraphicsLayoutItem *item) const -
419{ -
420 Q_D(const QGraphicsLinearLayout);
executed (the execution status of this line is deduced): const QGraphicsLinearLayoutPrivate * const d = d_func();
-
421 if (!item) {
evaluated: !item
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:91
2-91
422 qWarning("QGraphicsLinearLayout::setStretchFactor: cannot return"
executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslinearlayout.cpp", 422, __PRETTY_FUNCTION__).warning("QGraphicsLinearLayout::setStretchFactor: cannot return"
-
423 " a stretch factor for a null item");
executed (the execution status of this line is deduced): " a stretch factor for a null item");
-
424 return 0;
executed: return 0;
Execution Count:2
2
425 } -
426 return d->engine.stretchFactor(item, d->orientation);
executed: return d->engine.stretchFactor(item, d->orientation);
Execution Count:91
91
427} -
428 -
429/*! -
430 Sets the alignment of \a item to \a alignment. If \a item's alignment -
431 changes, the layout is automatically invalidated. -
432 -
433 \sa alignment(), invalidate() -
434*/ -
435void QGraphicsLinearLayout::setAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment) -
436{ -
437 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
438 if (this->alignment(item) == alignment)
evaluated: this->alignment(item) == alignment
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:67
8-67
439 return;
executed: return;
Execution Count:8
8
440 d->engine.setAlignment(item, alignment);
executed (the execution status of this line is deduced): d->engine.setAlignment(item, alignment);
-
441 invalidate();
executed (the execution status of this line is deduced): invalidate();
-
442}
executed: }
Execution Count:67
67
443 -
444/*! -
445 Returns the alignment for \a item. The default alignment is -
446 Qt::AlignTop | Qt::AlignLeft. -
447 -
448 The alignment decides how the item is positioned within its assigned space -
449 in the case where there's more space available in the layout than the -
450 widgets can occupy. -
451 -
452 \sa setAlignment() -
453*/ -
454Qt::Alignment QGraphicsLinearLayout::alignment(QGraphicsLayoutItem *item) const -
455{ -
456 Q_D(const QGraphicsLinearLayout);
executed (the execution status of this line is deduced): const QGraphicsLinearLayoutPrivate * const d = d_func();
-
457 return d->engine.alignment(item);
executed: return d->engine.alignment(item);
Execution Count:142
142
458} -
459 -
460#if 0 // ### -
461QSizePolicy::ControlTypes QGraphicsLinearLayout::controlTypes(LayoutSide side) const -
462{ -
463 return d->engine.controlTypes(side); -
464} -
465#endif -
466 -
467/*! -
468 \reimp -
469*/ -
470int QGraphicsLinearLayout::count() const -
471{ -
472 Q_D(const QGraphicsLinearLayout);
executed (the execution status of this line is deduced): const QGraphicsLinearLayoutPrivate * const d = d_func();
-
473 return d->engine.itemCount();
executed: return d->engine.itemCount();
Execution Count:2050
2050
474} -
475 -
476/*! -
477 \reimp -
478 When iterating from 0 and up, it will return the items in the visual arranged order. -
479*/ -
480QGraphicsLayoutItem *QGraphicsLinearLayout::itemAt(int index) const -
481{ -
482 Q_D(const QGraphicsLinearLayout);
executed (the execution status of this line is deduced): const QGraphicsLinearLayoutPrivate * const d = d_func();
-
483 if (index < 0 || index >= d->engine.itemCount()) {
partially evaluated: index < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2112
partially evaluated: index >= d->engine.itemCount()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2112
0-2112
484 qWarning("QGraphicsLinearLayout::itemAt: invalid index %d", index);
never executed (the execution status of this line is deduced): QMessageLogger("graphicsview/qgraphicslinearlayout.cpp", 484, __PRETTY_FUNCTION__).warning("QGraphicsLinearLayout::itemAt: invalid index %d", index);
-
485 return 0;
never executed: return 0;
0
486 } -
487 QGraphicsLayoutItem *item = 0;
executed (the execution status of this line is deduced): QGraphicsLayoutItem *item = 0;
-
488 if (QGridLayoutItem *gridItem = d->engine.itemAt(index))
partially evaluated: QGridLayoutItem *gridItem = d->engine.itemAt(index)
TRUEFALSE
yes
Evaluation Count:2112
no
Evaluation Count:0
0-2112
489 item = gridItem->layoutItem();
executed: item = gridItem->layoutItem();
Execution Count:2112
2112
490 return item;
executed: return item;
Execution Count:2112
2112
491} -
492 -
493/*! -
494 \reimp -
495*/ -
496void QGraphicsLinearLayout::setGeometry(const QRectF &rect) -
497{ -
498 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
499 QGraphicsLayout::setGeometry(rect);
executed (the execution status of this line is deduced): QGraphicsLayout::setGeometry(rect);
-
500 QRectF effectiveRect = geometry();
executed (the execution status of this line is deduced): QRectF effectiveRect = geometry();
-
501 qreal left, top, right, bottom;
executed (the execution status of this line is deduced): qreal left, top, right, bottom;
-
502 getContentsMargins(&left, &top, &right, &bottom);
executed (the execution status of this line is deduced): getContentsMargins(&left, &top, &right, &bottom);
-
503 Qt::LayoutDirection visualDir = d->visualDirection();
executed (the execution status of this line is deduced): Qt::LayoutDirection visualDir = d->visualDirection();
-
504 d->engine.setVisualDirection(visualDir);
executed (the execution status of this line is deduced): d->engine.setVisualDirection(visualDir);
-
505 if (visualDir == Qt::RightToLeft)
evaluated: visualDir == Qt::RightToLeft
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:323
1-323
506 qSwap(left, right);
executed: qSwap(left, right);
Execution Count:1
1
507 effectiveRect.adjust(+left, +top, -right, -bottom);
executed (the execution status of this line is deduced): effectiveRect.adjust(+left, +top, -right, -bottom);
-
508#ifdef QT_DEBUG -
509 if (qt_graphicsLayoutDebug()) { -
510 static int counter = 0; -
511 qDebug() << counter++ << "QGraphicsLinearLayout::setGeometry - " << rect; -
512 dump(1); -
513 } -
514#endif -
515 d->engine.setGeometries(d->styleInfo(), effectiveRect);
executed (the execution status of this line is deduced): d->engine.setGeometries(d->styleInfo(), effectiveRect);
-
516#ifdef QT_DEBUG -
517 if (qt_graphicsLayoutDebug()) { -
518 qDebug() << "post dump"; -
519 dump(1); -
520 } -
521#endif -
522}
executed: }
Execution Count:324
324
523 -
524/*! -
525 \reimp -
526*/ -
527QSizeF QGraphicsLinearLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const -
528{ -
529 Q_D(const QGraphicsLinearLayout);
executed (the execution status of this line is deduced): const QGraphicsLinearLayoutPrivate * const d = d_func();
-
530 qreal left, top, right, bottom;
executed (the execution status of this line is deduced): qreal left, top, right, bottom;
-
531 getContentsMargins(&left, &top, &right, &bottom);
executed (the execution status of this line is deduced): getContentsMargins(&left, &top, &right, &bottom);
-
532 const QSizeF extraMargins(left + right, top + bottom);
executed (the execution status of this line is deduced): const QSizeF extraMargins(left + right, top + bottom);
-
533 return d->engine.sizeHint(d->styleInfo(), which , constraint - extraMargins) + extraMargins;
executed: return d->engine.sizeHint(d->styleInfo(), which , constraint - extraMargins) + extraMargins;
Execution Count:939
939
534} -
535 -
536/*! -
537 \reimp -
538*/ -
539void QGraphicsLinearLayout::invalidate() -
540{ -
541 Q_D(QGraphicsLinearLayout);
executed (the execution status of this line is deduced): QGraphicsLinearLayoutPrivate * const d = d_func();
-
542 d->engine.invalidate();
executed (the execution status of this line is deduced): d->engine.invalidate();
-
543 QGraphicsLayout::invalidate();
executed (the execution status of this line is deduced): QGraphicsLayout::invalidate();
-
544}
executed: }
Execution Count:1782
1782
545 -
546/*! -
547 \internal -
548*/ -
549void QGraphicsLinearLayout::dump(int indent) const -
550{ -
551#ifdef QT_DEBUG -
552 if (qt_graphicsLayoutDebug()) { -
553 Q_D(const QGraphicsLinearLayout); -
554 qDebug("%*s%s layout", indent, "", -
555 d->orientation == Qt::Horizontal ? "Horizontal" : "Vertical"); -
556 d->engine.dump(indent + 1); -
557 } -
558#else -
559 Q_UNUSED(indent);
never executed (the execution status of this line is deduced): (void)indent;;
-
560#endif -
561}
never executed: }
0
562 -
563QT_END_NAMESPACE -
564 -
565#endif //QT_NO_GRAPHICSVIEW -
566 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial