graphicsview/qgraphicslayoutitem.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#include "qglobal.h" -
43 -
44#ifndef QT_NO_GRAPHICSVIEW -
45 -
46#include "qgraphicslayout.h" -
47#include "qgraphicsscene.h" -
48#include "qgraphicslayoutitem.h" -
49#include "qgraphicslayoutitem_p.h" -
50#include "qwidget.h" -
51#include "qgraphicswidget.h" -
52 -
53#include <QtDebug> -
54 -
55QT_BEGIN_NAMESPACE -
56 -
57/* -
58 COMBINE_SIZE() is identical to combineSize(), except that it -
59 doesn't evaluate 'size' unless necessary. -
60*/ -
61#define COMBINE_SIZE(result, size) \ -
62 do { \ -
63 if ((result).width() < 0 || (result).height() < 0) \ -
64 combineSize((result), (size)); \ -
65 } while (false) -
66 -
67static void combineSize(QSizeF &result, const QSizeF &size) -
68{ -
69 if (result.width() < 0)
evaluated: result.width() < 0
TRUEFALSE
yes
Evaluation Count:16679
yes
Evaluation Count:4814
4814-16679
70 result.setWidth(size.width());
executed: result.setWidth(size.width());
Execution Count:16679
16679
71 if (result.height() < 0)
evaluated: result.height() < 0
TRUEFALSE
yes
Evaluation Count:17270
yes
Evaluation Count:4223
4223-17270
72 result.setHeight(size.height());
executed: result.setHeight(size.height());
Execution Count:17270
17270
73}
executed: }
Execution Count:21493
21493
74 -
75static void boundSize(QSizeF &result, const QSizeF &size) -
76{ -
77 if (size.width() >= 0 && size.width() < result.width())
evaluated: size.width() >= 0
TRUEFALSE
yes
Evaluation Count:13829
yes
Evaluation Count:2891
evaluated: size.width() < result.width()
TRUEFALSE
yes
Evaluation Count:317
yes
Evaluation Count:13512
317-13829
78 result.setWidth(size.width());
executed: result.setWidth(size.width());
Execution Count:317
317
79 if (size.height() >= 0 && size.height() < result.height())
evaluated: size.height() >= 0
TRUEFALSE
yes
Evaluation Count:13805
yes
Evaluation Count:2915
evaluated: size.height() < result.height()
TRUEFALSE
yes
Evaluation Count:341
yes
Evaluation Count:13464
341-13805
80 result.setHeight(size.height());
executed: result.setHeight(size.height());
Execution Count:341
341
81}
executed: }
Execution Count:16720
16720
82 -
83static void expandSize(QSizeF &result, const QSizeF &size) -
84{ -
85 if (size.width() >= 0 && size.width() > result.width())
evaluated: size.width() >= 0
TRUEFALSE
yes
Evaluation Count:11966
yes
Evaluation Count:4754
evaluated: size.width() > result.width()
TRUEFALSE
yes
Evaluation Count:367
yes
Evaluation Count:11599
367-11966
86 result.setWidth(size.width());
executed: result.setWidth(size.width());
Execution Count:367
367
87 if (size.height() >= 0 && size.height() > result.height())
evaluated: size.height() >= 0
TRUEFALSE
yes
Evaluation Count:11926
yes
Evaluation Count:4794
evaluated: size.height() > result.height()
TRUEFALSE
yes
Evaluation Count:207
yes
Evaluation Count:11719
207-11926
88 result.setHeight(size.height());
executed: result.setHeight(size.height());
Execution Count:207
207
89}
executed: }
Execution Count:16720
16720
90 -
91static void normalizeHints(qreal &minimum, qreal &preferred, qreal &maximum, qreal &descent) -
92{ -
93 if (minimum >= 0 && maximum >= 0 && minimum > maximum)
evaluated: minimum >= 0
TRUEFALSE
yes
Evaluation Count:4618
yes
Evaluation Count:3742
evaluated: maximum >= 0
TRUEFALSE
yes
Evaluation Count:2052
yes
Evaluation Count:2566
evaluated: minimum > maximum
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:2048
4-4618
94 minimum = maximum;
executed: minimum = maximum;
Execution Count:4
4
95 -
96 if (preferred >= 0) {
evaluated: preferred >= 0
TRUEFALSE
yes
Evaluation Count:2554
yes
Evaluation Count:5806
2554-5806
97 if (minimum >= 0 && preferred < minimum) {
evaluated: minimum >= 0
TRUEFALSE
yes
Evaluation Count:2517
yes
Evaluation Count:37
partially evaluated: preferred < minimum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2517
0-2517
98 preferred = minimum;
never executed (the execution status of this line is deduced): preferred = minimum;
-
99 } else if (maximum >= 0 && preferred > maximum) {
never executed: }
evaluated: maximum >= 0
TRUEFALSE
yes
Evaluation Count:1388
yes
Evaluation Count:1166
partially evaluated: preferred > maximum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1388
0-1388
100 preferred = maximum;
never executed (the execution status of this line is deduced): preferred = maximum;
-
101 }
never executed: }
0
102 } -
103 -
104 if (minimum >= 0 && descent > minimum)
evaluated: minimum >= 0
TRUEFALSE
yes
Evaluation Count:4618
yes
Evaluation Count:3742
partially evaluated: descent > minimum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4618
0-4618
105 descent = minimum;
never executed: descent = minimum;
0
106}
executed: }
Execution Count:8360
8360
107 -
108/*! -
109 \internal -
110*/ -
111QGraphicsLayoutItemPrivate::QGraphicsLayoutItemPrivate(QGraphicsLayoutItem *par, bool layout) -
112 : parent(par), userSizeHints(0), isLayout(layout), ownedByLayout(false), graphicsItem(0) -
113{ -
114}
executed: }
Execution Count:2159
2159
115 -
116/*! -
117 \internal -
118*/ -
119QGraphicsLayoutItemPrivate::~QGraphicsLayoutItemPrivate() -
120{ -
121 // Remove any lazily allocated data -
122 delete[] userSizeHints;
executed (the execution status of this line is deduced): delete[] userSizeHints;
-
123}
executed: }
Execution Count:1589
1589
124 -
125/*! -
126 \internal -
127*/ -
128void QGraphicsLayoutItemPrivate::init() -
129{ -
130 sizeHintCacheDirty = true;
executed (the execution status of this line is deduced): sizeHintCacheDirty = true;
-
131 sizeHintWithConstraintCacheDirty = true;
executed (the execution status of this line is deduced): sizeHintWithConstraintCacheDirty = true;
-
132}
executed: }
Execution Count:2159
2159
133 -
134/*! -
135 \internal -
136*/ -
137QSizeF *QGraphicsLayoutItemPrivate::effectiveSizeHints(const QSizeF &constraint) const -
138{ -
139 Q_Q(const QGraphicsLayoutItem);
executed (the execution status of this line is deduced): const QGraphicsLayoutItem * const q = q_func();
-
140 QSizeF *sizeHintCache;
executed (the execution status of this line is deduced): QSizeF *sizeHintCache;
-
141 const bool hasConstraint = constraint.width() >= 0 || constraint.height() >= 0;
evaluated: constraint.width() >= 0
TRUEFALSE
yes
Evaluation Count:933
yes
Evaluation Count:55594
evaluated: constraint.height() >= 0
TRUEFALSE
yes
Evaluation Count:93
yes
Evaluation Count:55501
93-55594
142 if (hasConstraint) {
evaluated: hasConstraint
TRUEFALSE
yes
Evaluation Count:1026
yes
Evaluation Count:55501
1026-55501
143 if (!sizeHintWithConstraintCacheDirty && constraint == cachedConstraint)
evaluated: !sizeHintWithConstraintCacheDirty
TRUEFALSE
yes
Evaluation Count:877
yes
Evaluation Count:149
evaluated: constraint == cachedConstraint
TRUEFALSE
yes
Evaluation Count:830
yes
Evaluation Count:47
47-877
144 return cachedSizeHintsWithConstraints;
executed: return cachedSizeHintsWithConstraints;
Execution Count:830
830
145 sizeHintCache = cachedSizeHintsWithConstraints;
executed (the execution status of this line is deduced): sizeHintCache = cachedSizeHintsWithConstraints;
-
146 } else {
executed: }
Execution Count:196
196
147 if (!sizeHintCacheDirty)
evaluated: !sizeHintCacheDirty
TRUEFALSE
yes
Evaluation Count:51517
yes
Evaluation Count:3984
3984-51517
148 return cachedSizeHints;
executed: return cachedSizeHints;
Execution Count:51517
51517
149 sizeHintCache = cachedSizeHints;
executed (the execution status of this line is deduced): sizeHintCache = cachedSizeHints;
-
150 }
executed: }
Execution Count:3984
3984
151 -
152 for (int i = 0; i < Qt::NSizeHints; ++i) {
evaluated: i < Qt::NSizeHints
TRUEFALSE
yes
Evaluation Count:16720
yes
Evaluation Count:4180
4180-16720
153 sizeHintCache[i] = constraint;
executed (the execution status of this line is deduced): sizeHintCache[i] = constraint;
-
154 if (userSizeHints)
evaluated: userSizeHints
TRUEFALSE
yes
Evaluation Count:9308
yes
Evaluation Count:7412
7412-9308
155 combineSize(sizeHintCache[i], userSizeHints[i]);
executed: combineSize(sizeHintCache[i], userSizeHints[i]);
Execution Count:9308
9308
156 }
executed: }
Execution Count:16720
16720
157 -
158 QSizeF &minS = sizeHintCache[Qt::MinimumSize];
executed (the execution status of this line is deduced): QSizeF &minS = sizeHintCache[Qt::MinimumSize];
-
159 QSizeF &prefS = sizeHintCache[Qt::PreferredSize];
executed (the execution status of this line is deduced): QSizeF &prefS = sizeHintCache[Qt::PreferredSize];
-
160 QSizeF &maxS = sizeHintCache[Qt::MaximumSize];
executed (the execution status of this line is deduced): QSizeF &maxS = sizeHintCache[Qt::MaximumSize];
-
161 QSizeF &descentS = sizeHintCache[Qt::MinimumDescent];
executed (the execution status of this line is deduced): QSizeF &descentS = sizeHintCache[Qt::MinimumDescent];
-
162 -
163 normalizeHints(minS.rwidth(), prefS.rwidth(), maxS.rwidth(), descentS.rwidth());
executed (the execution status of this line is deduced): normalizeHints(minS.rwidth(), prefS.rwidth(), maxS.rwidth(), descentS.rwidth());
-
164 normalizeHints(minS.rheight(), prefS.rheight(), maxS.rheight(), descentS.rheight());
executed (the execution status of this line is deduced): normalizeHints(minS.rheight(), prefS.rheight(), maxS.rheight(), descentS.rheight());
-
165 -
166 // if the minimum, preferred and maximum sizes contradict each other -
167 // (e.g. the minimum is larger than the maximum) we give priority to -
168 // the maximum size, then the minimum size and finally the preferred size -
169 COMBINE_SIZE(maxS, q->sizeHint(Qt::MaximumSize, maxS));
executed: combineSize((maxS), (q->sizeHint(Qt::MaximumSize, maxS)));
Execution Count:3163
executed: }
Execution Count:4180
partially evaluated: false
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4180
evaluated: (maxS).width() < 0
TRUEFALSE
yes
Evaluation Count:3115
yes
Evaluation Count:1065
evaluated: (maxS).height() < 0
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:1017
0-4180
170 combineSize(maxS, QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
executed (the execution status of this line is deduced): combineSize(maxS, QSizeF(((1<<24)-1), ((1<<24)-1)));
-
171 expandSize(maxS, prefS);
executed (the execution status of this line is deduced): expandSize(maxS, prefS);
-
172 expandSize(maxS, minS);
executed (the execution status of this line is deduced): expandSize(maxS, minS);
-
173 boundSize(maxS, QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
executed (the execution status of this line is deduced): boundSize(maxS, QSizeF(((1<<24)-1), ((1<<24)-1)));
-
174 -
175 COMBINE_SIZE(minS, q->sizeHint(Qt::MinimumSize, minS));
executed: combineSize((minS), (q->sizeHint(Qt::MinimumSize, minS)));
Execution Count:1903
executed: }
Execution Count:4180
partially evaluated: false
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4180
evaluated: (minS).width() < 0
TRUEFALSE
yes
Evaluation Count:1863
yes
Evaluation Count:2317
evaluated: (minS).height() < 0
TRUEFALSE
yes
Evaluation Count:40
yes
Evaluation Count:2277
0-4180
176 expandSize(minS, QSizeF(0, 0));
executed (the execution status of this line is deduced): expandSize(minS, QSizeF(0, 0));
-
177 boundSize(minS, prefS);
executed (the execution status of this line is deduced): boundSize(minS, prefS);
-
178 boundSize(minS, maxS);
executed (the execution status of this line is deduced): boundSize(minS, maxS);
-
179 -
180 COMBINE_SIZE(prefS, q->sizeHint(Qt::PreferredSize, prefS));
executed: combineSize((prefS), (q->sizeHint(Qt::PreferredSize, prefS)));
Execution Count:2939
executed: }
Execution Count:4180
partially evaluated: false
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4180
evaluated: (prefS).width() < 0
TRUEFALSE
yes
Evaluation Count:2891
yes
Evaluation Count:1289
evaluated: (prefS).height() < 0
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:1241
0-4180
181 expandSize(prefS, minS);
executed (the execution status of this line is deduced): expandSize(prefS, minS);
-
182 boundSize(prefS, maxS);
executed (the execution status of this line is deduced): boundSize(prefS, maxS);
-
183 -
184 // Not supported yet -
185 // COMBINE_SIZE(descentS, q->sizeHint(Qt::MinimumDescent, constraint)); -
186 -
187 if (hasConstraint) {
evaluated: hasConstraint
TRUEFALSE
yes
Evaluation Count:196
yes
Evaluation Count:3984
196-3984
188 cachedConstraint = constraint;
executed (the execution status of this line is deduced): cachedConstraint = constraint;
-
189 sizeHintWithConstraintCacheDirty = false;
executed (the execution status of this line is deduced): sizeHintWithConstraintCacheDirty = false;
-
190 } else {
executed: }
Execution Count:196
196
191 sizeHintCacheDirty = false;
executed (the execution status of this line is deduced): sizeHintCacheDirty = false;
-
192 }
executed: }
Execution Count:3984
3984
193 return sizeHintCache;
executed: return sizeHintCache;
Execution Count:4180
4180
194} -
195 -
196 -
197/*! -
198 \internal -
199 -
200 Returns the parent item of this layout, or 0 if this layout is -
201 not installed on any widget. -
202 -
203 If this is the item that the layout is installed on, it will return "itself". -
204 -
205 If the layout is a sub-layout, this function returns the parent -
206 widget of the parent layout. -
207 -
208 Note that it will traverse up the layout item hierarchy instead of just calling -
209 QGraphicsItem::parentItem(). This is on purpose. -
210 -
211 \sa parent() -
212*/ -
213QGraphicsItem *QGraphicsLayoutItemPrivate::parentItem() const -
214{ -
215 Q_Q(const QGraphicsLayoutItem);
executed (the execution status of this line is deduced): const QGraphicsLayoutItem * const q = q_func();
-
216 -
217 const QGraphicsLayoutItem *parent = q;
executed (the execution status of this line is deduced): const QGraphicsLayoutItem *parent = q;
-
218 while (parent && parent->isLayout()) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:8878
yes
Evaluation Count:1120
evaluated: parent->isLayout()
TRUEFALSE
yes
Evaluation Count:5330
yes
Evaluation Count:3548
1120-8878
219 parent = parent->parentLayoutItem();
executed (the execution status of this line is deduced): parent = parent->parentLayoutItem();
-
220 }
executed: }
Execution Count:5330
5330
221 return parent ? parent->graphicsItem() : 0;
executed: return parent ? parent->graphicsItem() : 0;
Execution Count:4668
4668
222} -
223 -
224/*! -
225 \internal -
226 -
227 Ensures that userSizeHints is allocated. -
228 This function must be called before any dereferencing. -
229*/ -
230void QGraphicsLayoutItemPrivate::ensureUserSizeHints() -
231{ -
232 if (!userSizeHints)
evaluated: !userSizeHints
TRUEFALSE
yes
Evaluation Count:799
yes
Evaluation Count:1203
799-1203
233 userSizeHints = new QSizeF[Qt::NSizeHints];
executed: userSizeHints = new QSizeF[Qt::NSizeHints];
Execution Count:799
799
234}
executed: }
Execution Count:2002
2002
235 -
236/*! -
237 \internal -
238 -
239 Sets the user size hint \a which to \a size. Use an invalid size to unset the size hint. -
240 */ -
241void QGraphicsLayoutItemPrivate::setSize(Qt::SizeHint which, const QSizeF &size) -
242{ -
243 Q_Q(QGraphicsLayoutItem);
executed (the execution status of this line is deduced): QGraphicsLayoutItem * const q = q_func();
-
244 -
245 if (userSizeHints) {
evaluated: userSizeHints
TRUEFALSE
yes
Evaluation Count:1204
yes
Evaluation Count:810
810-1204
246 if (size == userSizeHints[which])
evaluated: size == userSizeHints[which]
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1202
2-1202
247 return;
executed: return;
Execution Count:2
2
248 } else if (size.width() < 0 && size.height() < 0) {
executed: }
Execution Count:1202
evaluated: size.width() < 0
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:799
partially evaluated: size.height() < 0
TRUEFALSE
yes
Evaluation Count:11
no
Evaluation Count:0
0-1202
249 return;
executed: return;
Execution Count:11
11
250 } -
251 -
252 ensureUserSizeHints();
executed (the execution status of this line is deduced): ensureUserSizeHints();
-
253 userSizeHints[which] = size;
executed (the execution status of this line is deduced): userSizeHints[which] = size;
-
254 q->updateGeometry();
executed (the execution status of this line is deduced): q->updateGeometry();
-
255}
executed: }
Execution Count:2001
2001
256 -
257/*! -
258 \internal -
259 -
260 Sets the width of the user size hint \a which to \a width. -
261 */ -
262void QGraphicsLayoutItemPrivate::setSizeComponent( -
263 Qt::SizeHint which, SizeComponent component, qreal value) -
264{ -
265 Q_Q(QGraphicsLayoutItem);
executed (the execution status of this line is deduced): QGraphicsLayoutItem * const q = q_func();
-
266 ensureUserSizeHints();
executed (the execution status of this line is deduced): ensureUserSizeHints();
-
267 qreal &userValue = (component == Width)
partially evaluated: (component == Width)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
268 ? userSizeHints[which].rwidth()
executed (the execution status of this line is deduced): ? userSizeHints[which].rwidth()
-
269 : userSizeHints[which].rheight();
executed (the execution status of this line is deduced): : userSizeHints[which].rheight();
-
270 if (value == userValue)
partially evaluated: value == userValue
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
271 return;
never executed: return;
0
272 userValue = value;
executed (the execution status of this line is deduced): userValue = value;
-
273 q->updateGeometry();
executed (the execution status of this line is deduced): q->updateGeometry();
-
274}
executed: }
Execution Count:1
1
275 -
276 -
277bool QGraphicsLayoutItemPrivate::hasHeightForWidth() const -
278{ -
279 Q_Q(const QGraphicsLayoutItem);
executed (the execution status of this line is deduced): const QGraphicsLayoutItem * const q = q_func();
-
280 if (isLayout) {
evaluated: isLayout
TRUEFALSE
yes
Evaluation Count:480
yes
Evaluation Count:4518
480-4518
281 const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q);
executed (the execution status of this line is deduced): const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q);
-
282 for (int i = l->count() - 1; i >= 0; --i) {
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:332
yes
Evaluation Count:480
332-480
283 if (QGraphicsLayoutItemPrivate::get(l->itemAt(i))->hasHeightForWidth())
partially evaluated: QGraphicsLayoutItemPrivate::get(l->itemAt(i))->hasHeightForWidth()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:332
0-332
284 return true;
never executed: return true;
0
285 }
executed: }
Execution Count:332
332
286 } else if (QGraphicsItem *item = q->graphicsItem()) {
executed: }
Execution Count:480
partially evaluated: QGraphicsItem *item = q->graphicsItem()
TRUEFALSE
yes
Evaluation Count:4518
no
Evaluation Count:0
0-4518
287 if (item->isWidget()) {
evaluated: item->isWidget()
TRUEFALSE
yes
Evaluation Count:4500
yes
Evaluation Count:18
18-4500
288 QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
executed (the execution status of this line is deduced): QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
-
289 if (w->layout()) {
evaluated: w->layout()
TRUEFALSE
yes
Evaluation Count:66
yes
Evaluation Count:4434
66-4434
290 return QGraphicsLayoutItemPrivate::get(w->layout())->hasHeightForWidth();
executed: return QGraphicsLayoutItemPrivate::get(w->layout())->hasHeightForWidth();
Execution Count:66
66
291 } -
292 }
executed: }
Execution Count:4434
4434
293 }
executed: }
Execution Count:4452
4452
294 return q->sizePolicy().hasHeightForWidth();
executed: return q->sizePolicy().hasHeightForWidth();
Execution Count:4932
4932
295} -
296 -
297bool QGraphicsLayoutItemPrivate::hasWidthForHeight() const -
298{ -
299 Q_Q(const QGraphicsLayoutItem);
executed (the execution status of this line is deduced): const QGraphicsLayoutItem * const q = q_func();
-
300 if (isLayout) {
evaluated: isLayout
TRUEFALSE
yes
Evaluation Count:480
yes
Evaluation Count:3306
480-3306
301 const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q);
executed (the execution status of this line is deduced): const QGraphicsLayout *l = static_cast<const QGraphicsLayout *>(q);
-
302 for (int i = l->count() - 1; i >= 0; --i) {
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:332
yes
Evaluation Count:480
332-480
303 if (QGraphicsLayoutItemPrivate::get(l->itemAt(i))->hasWidthForHeight())
partially evaluated: QGraphicsLayoutItemPrivate::get(l->itemAt(i))->hasWidthForHeight()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:332
0-332
304 return true;
never executed: return true;
0
305 }
executed: }
Execution Count:332
332
306 } else if (QGraphicsItem *item = q->graphicsItem()) {
executed: }
Execution Count:480
partially evaluated: QGraphicsItem *item = q->graphicsItem()
TRUEFALSE
yes
Evaluation Count:3306
no
Evaluation Count:0
0-3306
307 if (item->isWidget()) {
evaluated: item->isWidget()
TRUEFALSE
yes
Evaluation Count:3288
yes
Evaluation Count:18
18-3288
308 QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
executed (the execution status of this line is deduced): QGraphicsWidget *w = static_cast<QGraphicsWidget *>(item);
-
309 if (w->layout()) {
evaluated: w->layout()
TRUEFALSE
yes
Evaluation Count:66
yes
Evaluation Count:3222
66-3222
310 return QGraphicsLayoutItemPrivate::get(w->layout())->hasWidthForHeight();
executed: return QGraphicsLayoutItemPrivate::get(w->layout())->hasWidthForHeight();
Execution Count:66
66
311 } -
312 }
executed: }
Execution Count:3222
3222
313 }
executed: }
Execution Count:3240
3240
314 return q->sizePolicy().hasWidthForHeight();
executed: return q->sizePolicy().hasWidthForHeight();
Execution Count:3720
3720
315} -
316 -
317/*! -
318 \class QGraphicsLayoutItem -
319 \brief The QGraphicsLayoutItem class can be inherited to allow your custom -
320 items to be managed by layouts. -
321 \since 4.4 -
322 \ingroup graphicsview-api -
323 \inmodule QtWidgets -
324 -
325 QGraphicsLayoutItem is an abstract class that defines a set of virtual -
326 functions describing sizes, size policies, and size hints for any object -
327 arranged by QGraphicsLayout. The API contains functions relevant -
328 for both the item itself and for the user of the item as most of -
329 QGraphicsLayoutItem's functions are also part of the subclass' public API. -
330 -
331 In most cases, existing layout-aware classes such as QGraphicsWidget and -
332 QGraphicsLayout already provide the functionality you require. However, -
333 subclassing these classes will enable you to create both graphical -
334 elements that work well with layouts (QGraphicsWidget) or custom layouts -
335 (QGraphicsLayout). -
336 -
337 \section1 Subclassing QGraphicsLayoutItem -
338 -
339 If you create a subclass of QGraphicsLayoutItem and reimplement its -
340 virtual functions, you will enable the layout to resize and position your -
341 item along with other QGraphicsLayoutItems including QGraphicsWidget -
342 and QGraphicsLayout. -
343 -
344 You can start by reimplementing important functions: the protected -
345 sizeHint() function, as well as the public setGeometry() -
346 function. If you want your items to be aware of immediate geometry -
347 changes, you can also reimplement updateGeometry(). -
348 -
349 The geometry, size hint, and size policy affect the item's size and -
350 position. Calling setGeometry() will always resize and reposition the item -
351 immediately. Normally, this function is called by QGraphicsLayout after -
352 the layout has been activated, but it can also be called by the item's user -
353 at any time. -
354 -
355 The sizeHint() function returns the item' minimum, preferred and maximum -
356 size hints. You can override these properties by calling setMinimumSize(), -
357 setPreferredSize() or setMaximumSize(). You can also use functions such as -
358 setMinimumWidth() or setMaximumHeight() to set only the width or height -
359 component if desired. -
360 -
361 The effectiveSizeHint() function, on the other hand, returns a size hint -
362 for any given Qt::SizeHint, and guarantees that the returned size is bound -
363 to the minimum and maximum sizes and size hints. You can set the item's -
364 vertical and horizontal size policy by calling setSizePolicy(). The -
365 sizePolicy property is used by the layout system to describe how this item -
366 prefers to grow or shrink. -
367 -
368 \section1 Nesting QGraphicsLayoutItems -
369 -
370 QGraphicsLayoutItems can be nested within other QGraphicsLayoutItems, -
371 similar to layouts that can contain sublayouts. This is done either by -
372 passing a QGraphicsLayoutItem pointer to QGraphicsLayoutItem's -
373 protected constructor, or by calling setParentLayoutItem(). The -
374 parentLayoutItem() function returns a pointer to the item's layoutItem -
375 parent. If the item's parent is 0 or if the parent does not inherit -
376 from QGraphicsItem, the parentLayoutItem() function then returns 0. -
377 isLayout() returns true if the QGraphicsLayoutItem subclass is itself a -
378 layout, or false otherwise. -
379 -
380 Qt uses QGraphicsLayoutItem to provide layout functionality in the -
381 \l{Graphics View Framework}, but in the future its use may spread -
382 throughout Qt itself. -
383 -
384 \sa QGraphicsWidget, QGraphicsLayout, QGraphicsLinearLayout, -
385 QGraphicsGridLayout -
386*/ -
387 -
388/*! -
389 Constructs the QGraphicsLayoutItem object. \a parent becomes the object's -
390 parent. If \a isLayout is true the item is a layout, otherwise -
391 \a isLayout is false. -
392*/ -
393QGraphicsLayoutItem::QGraphicsLayoutItem(QGraphicsLayoutItem *parent, bool isLayout) -
394 : d_ptr(new QGraphicsLayoutItemPrivate(parent, isLayout)) -
395{ -
396 Q_D(QGraphicsLayoutItem);
executed (the execution status of this line is deduced): QGraphicsLayoutItemPrivate * const d = d_func();
-
397 d->init();
executed (the execution status of this line is deduced): d->init();
-
398 d->sizePolicy = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
executed (the execution status of this line is deduced): d->sizePolicy = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
-
399 d->q_ptr = this;
executed (the execution status of this line is deduced): d->q_ptr = this;
-
400}
executed: }
Execution Count:1489
1489
401 -
402/*! -
403 \internal -
404*/ -
405QGraphicsLayoutItem::QGraphicsLayoutItem(QGraphicsLayoutItemPrivate &dd) -
406 : d_ptr(&dd) -
407{ -
408 Q_D(QGraphicsLayoutItem);
executed (the execution status of this line is deduced): QGraphicsLayoutItemPrivate * const d = d_func();
-
409 d->init();
executed (the execution status of this line is deduced): d->init();
-
410 d->q_ptr = this;
executed (the execution status of this line is deduced): d->q_ptr = this;
-
411}
executed: }
Execution Count:670
670
412 -
413/*! -
414 Destroys the QGraphicsLayoutItem object. -
415*/ -
416QGraphicsLayoutItem::~QGraphicsLayoutItem() -
417{ -
418 QGraphicsLayoutItem *parentLI = parentLayoutItem();
executed (the execution status of this line is deduced): QGraphicsLayoutItem *parentLI = parentLayoutItem();
-
419 if (parentLI && parentLI->isLayout()) {
evaluated: parentLI
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:1388
evaluated: parentLI->isLayout()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:195
6-1388
420 QGraphicsLayout *lay = static_cast<QGraphicsLayout*>(parentLI);
executed (the execution status of this line is deduced): QGraphicsLayout *lay = static_cast<QGraphicsLayout*>(parentLI);
-
421 // this is not optimal -
422 for (int i = lay->count() - 1; i >= 0; --i) {
partially evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
423 if (lay->itemAt(i) == this) {
evaluated: lay->itemAt(i) == this
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:6
6
424 lay->removeAt(i);
executed (the execution status of this line is deduced): lay->removeAt(i);
-
425 break;
executed: break;
Execution Count:6
6
426 } -
427 }
executed: }
Execution Count:6
6
428 }
executed: }
Execution Count:6
6
429}
executed: }
Execution Count:1589
1589
430 -
431/*! -
432 \fn virtual QSizeF QGraphicsLayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const = 0; -
433 -
434 This pure virtual function returns the size hint for \a which of the -
435 QGraphicsLayoutItem, using the width or height of \a constraint to -
436 constrain the output. -
437 -
438 Reimplement this function in a subclass of QGraphicsLayoutItem to -
439 provide the necessary size hints for your items. -
440 -
441 \sa effectiveSizeHint() -
442*/ -
443 -
444/*! -
445 Sets the size policy to \a policy. The size policy describes how the item -
446 should grow horizontally and vertically when arranged in a layout. -
447 -
448 QGraphicsLayoutItem's default size policy is (QSizePolicy::Fixed, -
449 QSizePolicy::Fixed, QSizePolicy::DefaultType), but it is common for -
450 subclasses to change the default. For example, QGraphicsWidget defaults -
451 to (QSizePolicy::Preferred, QSizePolicy::Preferred, -
452 QSizePolicy::DefaultType). -
453 -
454 \sa sizePolicy(), QWidget::sizePolicy() -
455*/ -
456void QGraphicsLayoutItem::setSizePolicy(const QSizePolicy &policy) -
457{ -
458 Q_D(QGraphicsLayoutItem);
executed (the execution status of this line is deduced): QGraphicsLayoutItemPrivate * const d = d_func();
-
459 if (d->sizePolicy == policy)
evaluated: d->sizePolicy == policy
TRUEFALSE
yes
Evaluation Count:1764
yes
Evaluation Count:321
321-1764
460 return;
executed: return;
Execution Count:1764
1764
461 d->sizePolicy = policy;
executed (the execution status of this line is deduced): d->sizePolicy = policy;
-
462 updateGeometry();
executed (the execution status of this line is deduced): updateGeometry();
-
463}
executed: }
Execution Count:321
321
464 -
465/*! -
466 \overload -
467 -
468 This function is equivalent to calling -
469 setSizePolicy(QSizePolicy(\a hPolicy, \a vPolicy, \a controlType)). -
470 -
471 \sa sizePolicy(), QWidget::sizePolicy() -
472*/ -
473void QGraphicsLayoutItem::setSizePolicy(QSizePolicy::Policy hPolicy, -
474 QSizePolicy::Policy vPolicy, -
475 QSizePolicy::ControlType controlType) -
476{ -
477 setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType));
executed (the execution status of this line is deduced): setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType));
-
478}
executed: }
Execution Count:133
133
479 -
480/*! -
481 Returns the current size policy. -
482 -
483 \sa setSizePolicy(), QWidget::sizePolicy() -
484*/ -
485QSizePolicy QGraphicsLayoutItem::sizePolicy() const -
486{ -
487 Q_D(const QGraphicsLayoutItem);
executed (the execution status of this line is deduced): const QGraphicsLayoutItemPrivate * const d = d_func();
-
488 return d->sizePolicy;
executed: return d->sizePolicy;
Execution Count:53795
53795
489} -
490 -
491/*! -
492 Sets the minimum size to \a size. This property overrides sizeHint() for -
493 Qt::MinimumSize and ensures that effectiveSizeHint() will never return -
494 a size smaller than \a size. In order to unset the minimum size, use an -
495 invalid size. -
496 -
497 \sa minimumSize(), maximumSize(), preferredSize(), Qt::MinimumSize, -
498 sizeHint(), setMinimumWidth(), setMinimumHeight() -
499*/ -
500void QGraphicsLayoutItem::setMinimumSize(const QSizeF &size) -
501{ -
502 d_ptr->setSize(Qt::MinimumSize, size);
executed (the execution status of this line is deduced): d_ptr->setSize(Qt::MinimumSize, size);
-
503}
executed: }
Execution Count:782
782
504 -
505/*! -
506 \fn QGraphicsLayoutItem::setMinimumSize(qreal w, qreal h) -
507 -
508 This convenience function is equivalent to calling -
509 setMinimumSize(QSizeF(\a w, \a h)). -
510 -
511 \sa minimumSize(), setMaximumSize(), setPreferredSize(), sizeHint() -
512*/ -
513 -
514/*! -
515 Returns the minimum size. -
516 -
517 \sa setMinimumSize(), preferredSize(), maximumSize(), Qt::MinimumSize, -
518 sizeHint() -
519*/ -
520QSizeF QGraphicsLayoutItem::minimumSize() const -
521{ -
522 return effectiveSizeHint(Qt::MinimumSize);
executed: return effectiveSizeHint(Qt::MinimumSize);
Execution Count:58
58
523} -
524 -
525/*! -
526 Sets the minimum width to \a width. -
527 -
528 \sa minimumWidth(), setMinimumSize(), minimumSize() -
529*/ -
530void QGraphicsLayoutItem::setMinimumWidth(qreal width) -
531{ -
532 d_ptr->setSizeComponent(Qt::MinimumSize, d_ptr->Width, width);
never executed (the execution status of this line is deduced): d_ptr->setSizeComponent(Qt::MinimumSize, d_ptr->Width, width);
-
533}
never executed: }
0
534 -
535/*! -
536 Sets the minimum height to \a height. -
537 -
538 \sa minimumHeight(), setMinimumSize(), minimumSize() -
539*/ -
540void QGraphicsLayoutItem::setMinimumHeight(qreal height) -
541{ -
542 d_ptr->setSizeComponent(Qt::MinimumSize, d_ptr->Height, height);
never executed (the execution status of this line is deduced): d_ptr->setSizeComponent(Qt::MinimumSize, d_ptr->Height, height);
-
543}
never executed: }
0
544 -
545 -
546/*! -
547 Sets the preferred size to \a size. This property overrides sizeHint() for -
548 Qt::PreferredSize and provides the default value for effectiveSizeHint(). -
549 In order to unset the preferred size, use an invalid size. -
550 -
551 \sa preferredSize(), minimumSize(), maximumSize(), Qt::PreferredSize, -
552 sizeHint() -
553*/ -
554void QGraphicsLayoutItem::setPreferredSize(const QSizeF &size) -
555{ -
556 d_ptr->setSize(Qt::PreferredSize, size);
executed (the execution status of this line is deduced): d_ptr->setSize(Qt::PreferredSize, size);
-
557}
executed: }
Execution Count:532
532
558 -
559/*! -
560 \fn QGraphicsLayoutItem::setPreferredSize(qreal w, qreal h) -
561 -
562 This convenience function is equivalent to calling -
563 setPreferredSize(QSizeF(\a w, \a h)). -
564 -
565 \sa preferredSize(), setMaximumSize(), setMinimumSize(), sizeHint() -
566*/ -
567 -
568/*! -
569 Returns the preferred size. -
570 -
571 \sa setPreferredSize(), minimumSize(), maximumSize(), Qt::PreferredSize, -
572 sizeHint() -
573*/ -
574QSizeF QGraphicsLayoutItem::preferredSize() const -
575{ -
576 return effectiveSizeHint(Qt::PreferredSize);
executed: return effectiveSizeHint(Qt::PreferredSize);
Execution Count:30
30
577} -
578 -
579/*! -
580 Sets the preferred height to \a height. -
581 -
582 \sa preferredWidth(), setPreferredSize(), preferredSize() -
583*/ -
584void QGraphicsLayoutItem::setPreferredHeight(qreal height) -
585{ -
586 d_ptr->setSizeComponent(Qt::PreferredSize, d_ptr->Height, height);
never executed (the execution status of this line is deduced): d_ptr->setSizeComponent(Qt::PreferredSize, d_ptr->Height, height);
-
587}
never executed: }
0
588 -
589/*! -
590 Sets the preferred width to \a width. -
591 -
592 \sa preferredHeight(), setPreferredSize(), preferredSize() -
593*/ -
594void QGraphicsLayoutItem::setPreferredWidth(qreal width) -
595{ -
596 d_ptr->setSizeComponent(Qt::PreferredSize, d_ptr->Width, width);
never executed (the execution status of this line is deduced): d_ptr->setSizeComponent(Qt::PreferredSize, d_ptr->Width, width);
-
597}
never executed: }
0
598 -
599/*! -
600 Sets the maximum size to \a size. This property overrides sizeHint() for -
601 Qt::MaximumSize and ensures that effectiveSizeHint() will never return a -
602 size larger than \a size. In order to unset the maximum size, use an -
603 invalid size. -
604 -
605 \sa maximumSize(), minimumSize(), preferredSize(), Qt::MaximumSize, -
606 sizeHint() -
607*/ -
608void QGraphicsLayoutItem::setMaximumSize(const QSizeF &size) -
609{ -
610 d_ptr->setSize(Qt::MaximumSize, size);
executed (the execution status of this line is deduced): d_ptr->setSize(Qt::MaximumSize, size);
-
611}
executed: }
Execution Count:700
700
612 -
613/*! -
614 \fn QGraphicsLayoutItem::setMaximumSize(qreal w, qreal h) -
615 -
616 This convenience function is equivalent to calling -
617 setMaximumSize(QSizeF(\a w, \a h)). -
618 -
619 \sa maximumSize(), setMinimumSize(), setPreferredSize(), sizeHint() -
620*/ -
621 -
622/*! -
623 Returns the maximum size. -
624 -
625 \sa setMaximumSize(), minimumSize(), preferredSize(), Qt::MaximumSize, -
626 sizeHint() -
627*/ -
628QSizeF QGraphicsLayoutItem::maximumSize() const -
629{ -
630 return effectiveSizeHint(Qt::MaximumSize);
executed: return effectiveSizeHint(Qt::MaximumSize);
Execution Count:67
67
631} -
632 -
633/*! -
634 Sets the maximum width to \a width. -
635 -
636 \sa maximumWidth(), setMaximumSize(), maximumSize() -
637*/ -
638void QGraphicsLayoutItem::setMaximumWidth(qreal width) -
639{ -
640 d_ptr->setSizeComponent(Qt::MaximumSize, d_ptr->Width, width);
never executed (the execution status of this line is deduced): d_ptr->setSizeComponent(Qt::MaximumSize, d_ptr->Width, width);
-
641}
never executed: }
0
642 -
643/*! -
644 Sets the maximum height to \a height. -
645 -
646 \sa maximumHeight(), setMaximumSize(), maximumSize() -
647*/ -
648void QGraphicsLayoutItem::setMaximumHeight(qreal height) -
649{ -
650 d_ptr->setSizeComponent(Qt::MaximumSize, d_ptr->Height, height);
executed (the execution status of this line is deduced): d_ptr->setSizeComponent(Qt::MaximumSize, d_ptr->Height, height);
-
651}
executed: }
Execution Count:1
1
652 -
653/*! -
654 \fn qreal QGraphicsLayoutItem::minimumWidth() const -
655 -
656 Returns the minimum width. -
657 -
658 \sa setMinimumWidth(), setMinimumSize(), minimumSize() -
659*/ -
660 -
661/*! -
662 \fn qreal QGraphicsLayoutItem::minimumHeight() const -
663 -
664 Returns the minimum height. -
665 -
666 \sa setMinimumHeight(), setMinimumSize(), minimumSize() -
667*/ -
668 -
669/*! -
670 \fn qreal QGraphicsLayoutItem::preferredWidth() const -
671 -
672 Returns the preferred width. -
673 -
674 \sa setPreferredWidth(), setPreferredSize(), preferredSize() -
675*/ -
676 -
677/*! -
678 \fn qreal QGraphicsLayoutItem::preferredHeight() const -
679 -
680 Returns the preferred height. -
681 -
682 \sa setPreferredHeight(), setPreferredSize(), preferredSize() -
683*/ -
684 -
685/*! -
686 \fn qreal QGraphicsLayoutItem::maximumWidth() const -
687 -
688 Returns the maximum width. -
689 -
690 \sa setMaximumWidth(), setMaximumSize(), maximumSize() -
691*/ -
692 -
693/*! -
694 \fn qreal QGraphicsLayoutItem::maximumHeight() const -
695 -
696 Returns the maximum height. -
697 -
698 \sa setMaximumHeight(), setMaximumSize(), maximumSize() -
699*/ -
700 -
701/*! -
702 \fn virtual void QGraphicsLayoutItem::setGeometry(const QRectF &rect) -
703 -
704 This virtual function sets the geometry of the QGraphicsLayoutItem to -
705 \a rect, which is in parent coordinates (e.g., the top-left corner of \a rect -
706 is equivalent to the item's position in parent coordinates). -
707 -
708 You must reimplement this function in a subclass of QGraphicsLayoutItem to -
709 receive geometry updates. The layout will call this function when it does a -
710 rearrangement. -
711 -
712 If \a rect is outside of the bounds of minimumSize and maximumSize, it -
713 will be adjusted to its closest size so that it is within the legal -
714 bounds. -
715 -
716 \sa geometry() -
717*/ -
718void QGraphicsLayoutItem::setGeometry(const QRectF &rect) -
719{ -
720 Q_D(QGraphicsLayoutItem);
executed (the execution status of this line is deduced): QGraphicsLayoutItemPrivate * const d = d_func();
-
721 QSizeF effectiveSize = rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize))
executed (the execution status of this line is deduced): QSizeF effectiveSize = rect.size().expandedTo(effectiveSizeHint(Qt::MinimumSize))
-
722 .boundedTo(effectiveSizeHint(Qt::MaximumSize));
executed (the execution status of this line is deduced): .boundedTo(effectiveSizeHint(Qt::MaximumSize));
-
723 d->geom = QRectF(rect.topLeft(), effectiveSize);
executed (the execution status of this line is deduced): d->geom = QRectF(rect.topLeft(), effectiveSize);
-
724}
executed: }
Execution Count:2473
2473
725 -
726/*! -
727 \fn QRectF QGraphicsLayoutItem::geometry() const -
728 -
729 Returns the item's geometry (e.g., position and size) as a -
730 QRectF. This function is equivalent to QRectF(pos(), size()). -
731 -
732 \sa setGeometry() -
733*/ -
734QRectF QGraphicsLayoutItem::geometry() const -
735{ -
736 Q_D(const QGraphicsLayoutItem);
executed (the execution status of this line is deduced): const QGraphicsLayoutItemPrivate * const d = d_func();
-
737 return d->geom;
executed: return d->geom;
Execution Count:10101
10101
738} -
739 -
740/*! -
741 This virtual function provides the \a left, \a top, \a right and \a bottom -
742 contents margins for this QGraphicsLayoutItem. The default implementation -
743 assumes all contents margins are 0. The parameters point to values stored -
744 in qreals. If any of the pointers is 0, that value will not be updated. -
745 -
746 \sa QGraphicsWidget::setContentsMargins() -
747*/ -
748void QGraphicsLayoutItem::getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const -
749{ -
750 if (left)
partially evaluated: left
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
751 *left = 0;
executed: *left = 0;
Execution Count:3
3
752 if (top)
partially evaluated: top
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
753 *top = 0;
executed: *top = 0;
Execution Count:3
3
754 if (right)
partially evaluated: right
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
755 *right = 0;
executed: *right = 0;
Execution Count:3
3
756 if (bottom)
partially evaluated: bottom
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
757 *bottom = 0;
executed: *bottom = 0;
Execution Count:3
3
758}
executed: }
Execution Count:3
3
759 -
760/*! -
761 Returns the contents rect in local coordinates. -
762 -
763 The contents rect defines the subrectangle used by an associated layout -
764 when arranging subitems. This function is a convenience function that -
765 adjusts the item's geometry() by its contents margins. Note that -
766 getContentsMargins() is a virtual function that you can reimplement to -
767 return the item's contents margins. -
768 -
769 \sa getContentsMargins(), geometry() -
770*/ -
771QRectF QGraphicsLayoutItem::contentsRect() const -
772{ -
773 qreal left, top, right, bottom;
executed (the execution status of this line is deduced): qreal left, top, right, bottom;
-
774 getContentsMargins(&left, &top, &right, &bottom);
executed (the execution status of this line is deduced): getContentsMargins(&left, &top, &right, &bottom);
-
775 return QRectF(QPointF(), geometry().size()).adjusted(+left, +top, -right, -bottom);
executed: return QRectF(QPointF(), geometry().size()).adjusted(+left, +top, -right, -bottom);
Execution Count:370
370
776} -
777 -
778/*! -
779 Returns the effective size hint for this QGraphicsLayoutItem. -
780 -
781 \a which is the size hint in question. -
782 \a constraint is an optional argument that defines a special constrain -
783 when calculating the effective size hint. By default, \a constraint is -
784 QSizeF(-1, -1), which means there is no constraint to the size hint. -
785 -
786 If you want to specify the widget's size hint for a given width or height, -
787 you can provide the fixed dimension in \a constraint. This is useful for -
788 widgets that can grow only either vertically or horizontally, and need to -
789 set either their width or their height to a special value. -
790 -
791 For example, a text paragraph item fit into a column width of 200 may -
792 grow vertically. You can pass QSizeF(200, -1) as a constraint to get a -
793 suitable minimum, preferred and maximum height). -
794 -
795 You can adjust the effective size hint by reimplementing sizeHint() -
796 in a QGraphicsLayoutItem subclass, or by calling one of the following -
797 functions: setMinimumSize(), setPreferredSize, or setMaximumSize() -
798 (or a combination of both). -
799 -
800 This function caches each of the size hints and guarantees that -
801 sizeHint() will be called only once for each value of \a which - unless -
802 \a constraint is not specified and updateGeometry() has been called. -
803 -
804 \sa sizeHint() -
805*/ -
806QSizeF QGraphicsLayoutItem::effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint) const -
807{ -
808 Q_D(const QGraphicsLayoutItem);
executed (the execution status of this line is deduced): const QGraphicsLayoutItemPrivate * const d = d_func();
-
809 -
810 if (!d->userSizeHints && constraint.isValid())
evaluated: !d->userSizeHints
TRUEFALSE
yes
Evaluation Count:18556
yes
Evaluation Count:37981
evaluated: constraint.isValid()
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:18546
10-37981
811 return constraint;
executed: return constraint;
Execution Count:10
10
812 -
813 // ### should respect size policy??? -
814 return d_ptr->effectiveSizeHints(constraint)[which];
executed: return d_ptr->effectiveSizeHints(constraint)[which];
Execution Count:56527
56527
815} -
816 -
817/*! -
818 This virtual function discards any cached size hint information. You -
819 should always call this function if you change the return value of the -
820 sizeHint() function. Subclasses must always call the base implementation -
821 when reimplementing this function. -
822 -
823 \sa effectiveSizeHint() -
824*/ -
825void QGraphicsLayoutItem::updateGeometry() -
826{ -
827 Q_D(QGraphicsLayoutItem);
executed (the execution status of this line is deduced): QGraphicsLayoutItemPrivate * const d = d_func();
-
828 d->sizeHintCacheDirty = true;
executed (the execution status of this line is deduced): d->sizeHintCacheDirty = true;
-
829 d->sizeHintWithConstraintCacheDirty = true;
executed (the execution status of this line is deduced): d->sizeHintWithConstraintCacheDirty = true;
-
830}
executed: }
Execution Count:3571
3571
831 -
832/*! -
833 Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, -
834 or if the parent does not inherit from QGraphicsLayoutItem -
835 (QGraphicsLayoutItem is often used through multiple inheritance with -
836 QObject-derived classes). -
837 -
838 \sa setParentLayoutItem() -
839*/ -
840QGraphicsLayoutItem *QGraphicsLayoutItem::parentLayoutItem() const -
841{ -
842 return d_func()->parent;
executed: return d_func()->parent;
Execution Count:25841
25841
843} -
844 -
845/*! -
846 Sets the parent of this QGraphicsLayoutItem to \a parent. -
847 -
848 \sa parentLayoutItem() -
849*/ -
850void QGraphicsLayoutItem::setParentLayoutItem(QGraphicsLayoutItem *parent) -
851{ -
852 d_func()->parent = parent;
executed (the execution status of this line is deduced): d_func()->parent = parent;
-
853}
executed: }
Execution Count:5012
5012
854 -
855/*! -
856 Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited -
857 by an object that arranges other QGraphicsLayoutItem objects); otherwise -
858 returns false. -
859 -
860 \sa QGraphicsLayout -
861*/ -
862bool QGraphicsLayoutItem::isLayout() const -
863{ -
864 return d_func()->isLayout;
executed: return d_func()->isLayout;
Execution Count:30024
30024
865} -
866 -
867/*! -
868 \since 4.6 -
869 -
870 Returns whether a layout should delete this item in its destructor. -
871 If its true, then the layout will delete it. If its false, then it is -
872 assumed that another object has the ownership of it, and the layout won't -
873 delete this item. -
874 -
875 If the item inherits both QGraphicsItem and QGraphicsLayoutItem (such -
876 as QGraphicsWidget does) the item is really part of two ownership -
877 hierarchies. This property informs what the layout should do with its -
878 child items when it is destructed. In the case of QGraphicsWidget, it -
879 is preferred that when the layout is deleted it won't delete its children -
880 (since they are also part of the graphics item hierarchy). -
881 -
882 By default this value is initialized to false in QGraphicsLayoutItem, -
883 but it is overridden by QGraphicsLayout to return true. This is because -
884 QGraphicsLayout is not normally part of the QGraphicsItem hierarchy, so the -
885 parent layout should delete it. -
886 Subclasses might override this default behaviour by calling -
887 setOwnedByLayout(true). -
888 -
889 \sa setOwnedByLayout() -
890*/ -
891bool QGraphicsLayoutItem::ownedByLayout() const -
892{ -
893 return d_func()->ownedByLayout;
executed: return d_func()->ownedByLayout;
Execution Count:1071
1071
894} -
895/*! -
896 \since 4.6 -
897 -
898 Sets whether a layout should delete this item in its destructor or not. -
899 \a ownership must be true to in order for the layout to delete it. -
900 \sa ownedByLayout() -
901*/ -
902void QGraphicsLayoutItem::setOwnedByLayout(bool ownership) -
903{ -
904 d_func()->ownedByLayout = ownership;
executed (the execution status of this line is deduced): d_func()->ownedByLayout = ownership;
-
905}
executed: }
Execution Count:673
673
906 -
907/*! -
908 * Returns the QGraphicsItem that this layout item represents. -
909 * For QGraphicsWidget it will return itself. For custom items it can return an -
910 * aggregated value. -
911 * -
912 * \sa setGraphicsItem() -
913 */ -
914QGraphicsItem *QGraphicsLayoutItem::graphicsItem() const -
915{ -
916 return d_func()->graphicsItem;
executed: return d_func()->graphicsItem;
Execution Count:12761
12761
917} -
918 -
919/*! -
920 * If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take -
921 * advantage of the automatic reparenting capabilities of QGraphicsLayout it -
922 * should set this value. -
923 * Note that if you delete \a item and not delete the layout item, you are -
924 * responsible of calling setGraphicsItem(0) in order to avoid having a -
925 * dangling pointer. -
926 * -
927 * \sa graphicsItem() -
928 */ -
929void QGraphicsLayoutItem::setGraphicsItem(QGraphicsItem *item) -
930{ -
931 d_func()->graphicsItem = item;
executed (the execution status of this line is deduced): d_func()->graphicsItem = item;
-
932}
executed: }
Execution Count:1447
1447
933 -
934QT_END_NAMESPACE -
935 -
936#endif //QT_NO_GRAPHICSVIEW -
937 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial