kernel/qlayoutengine.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 "qlayout.h" -
43#include "private/qlayoutengine_p.h" -
44 -
45#include "qvector.h" -
46#include "qwidget.h" -
47 -
48#include <qlist.h> -
49#include <qalgorithms.h> -
50 -
51#include <qdebug.h> -
52 -
53QT_BEGIN_NAMESPACE -
54 -
55//#define QLAYOUT_EXTRA_DEBUG -
56 -
57typedef qint64 Fixed64; -
58static inline Fixed64 toFixed(int i) { return (Fixed64)i * 256; }
executed: return (Fixed64)i * 256;
Execution Count:26764
26764
59static inline int fRound(Fixed64 i) { -
60 return (i % 256 < 128) ? i / 256 : 1 + i / 256;
executed: return (i % 256 < 128) ? i / 256 : 1 + i / 256;
Execution Count:14496
14496
61} -
62 -
63/* -
64 This is the main workhorse of the QGridLayout. It portions out -
65 available space to the chain's children. -
66 -
67 The calculation is done in fixed point: "fixed" variables are -
68 scaled by a factor of 256. -
69 -
70 If the layout runs "backwards" (i.e. RightToLeft or Up) the layout -
71 is computed mirror-reversed, and it's the caller's responsibility -
72 do reverse the values before use. -
73 -
74 chain contains input and output parameters describing the geometry. -
75 count is the count of items in the chain; pos and space give the -
76 interval (relative to parentWidget topLeft). -
77*/ -
78void qGeomCalc(QVector<QLayoutStruct> &chain, int start, int count, -
79 int pos, int space, int spacer) -
80{ -
81 int cHint = 0;
executed (the execution status of this line is deduced): int cHint = 0;
-
82 int cMin = 0;
executed (the execution status of this line is deduced): int cMin = 0;
-
83 int cMax = 0;
executed (the execution status of this line is deduced): int cMax = 0;
-
84 int sumStretch = 0;
executed (the execution status of this line is deduced): int sumStretch = 0;
-
85 int sumSpacing = 0;
executed (the execution status of this line is deduced): int sumSpacing = 0;
-
86 -
87 bool wannaGrow = false; // anyone who really wants to grow?
executed (the execution status of this line is deduced): bool wannaGrow = false;
-
88 // bool canShrink = false; // anyone who could be persuaded to shrink? -
89 -
90 bool allEmptyNonstretch = true;
executed (the execution status of this line is deduced): bool allEmptyNonstretch = true;
-
91 int pendingSpacing = -1;
executed (the execution status of this line is deduced): int pendingSpacing = -1;
-
92 int spacerCount = 0;
executed (the execution status of this line is deduced): int spacerCount = 0;
-
93 int i;
executed (the execution status of this line is deduced): int i;
-
94 -
95 for (i = start; i < start + count; i++) {
evaluated: i < start + count
TRUEFALSE
yes
Evaluation Count:32690
yes
Evaluation Count:11919
11919-32690
96 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
97 -
98 data->done = false;
executed (the execution status of this line is deduced): data->done = false;
-
99 cHint += data->smartSizeHint();
executed (the execution status of this line is deduced): cHint += data->smartSizeHint();
-
100 cMin += data->minimumSize;
executed (the execution status of this line is deduced): cMin += data->minimumSize;
-
101 cMax += data->maximumSize;
executed (the execution status of this line is deduced): cMax += data->maximumSize;
-
102 sumStretch += data->stretch;
executed (the execution status of this line is deduced): sumStretch += data->stretch;
-
103 if (!data->empty) {
evaluated: !data->empty
TRUEFALSE
yes
Evaluation Count:24980
yes
Evaluation Count:7710
7710-24980
104 /* -
105 Using pendingSpacing, we ensure that the spacing for the last -
106 (non-empty) item is ignored. -
107 */ -
108 if (pendingSpacing >= 0) {
evaluated: pendingSpacing >= 0
TRUEFALSE
yes
Evaluation Count:13665
yes
Evaluation Count:11315
11315-13665
109 sumSpacing += pendingSpacing;
executed (the execution status of this line is deduced): sumSpacing += pendingSpacing;
-
110 ++spacerCount;
executed (the execution status of this line is deduced): ++spacerCount;
-
111 }
executed: }
Execution Count:13665
13665
112 pendingSpacing = data->effectiveSpacer(spacer);
executed (the execution status of this line is deduced): pendingSpacing = data->effectiveSpacer(spacer);
-
113 }
executed: }
Execution Count:24980
24980
114 wannaGrow = wannaGrow || data->expansive || data->stretch > 0;
evaluated: wannaGrow
TRUEFALSE
yes
Evaluation Count:9327
yes
Evaluation Count:23363
evaluated: data->expansive
TRUEFALSE
yes
Evaluation Count:5747
yes
Evaluation Count:17616
evaluated: data->stretch > 0
TRUEFALSE
yes
Evaluation Count:225
yes
Evaluation Count:17391
225-23363
115 allEmptyNonstretch = allEmptyNonstretch && !wannaGrow && data->empty;
evaluated: allEmptyNonstretch
TRUEFALSE
yes
Evaluation Count:15021
yes
Evaluation Count:17669
evaluated: !wannaGrow
TRUEFALSE
yes
Evaluation Count:11118
yes
Evaluation Count:3903
evaluated: data->empty
TRUEFALSE
yes
Evaluation Count:3603
yes
Evaluation Count:7515
3603-17669
116 }
executed: }
Execution Count:32690
32690
117 -
118 int extraspace = 0;
executed (the execution status of this line is deduced): int extraspace = 0;
-
119 -
120 if (space < cMin + sumSpacing) {
evaluated: space < cMin + sumSpacing
TRUEFALSE
yes
Evaluation Count:610
yes
Evaluation Count:11309
610-11309
121 /* -
122 Less space than minimumSize; take from the biggest first -
123 */ -
124 -
125 int minSize = cMin + sumSpacing;
executed (the execution status of this line is deduced): int minSize = cMin + sumSpacing;
-
126 -
127 // shrink the spacers proportionally -
128 if (spacer >= 0) {
evaluated: spacer >= 0
TRUEFALSE
yes
Evaluation Count:214
yes
Evaluation Count:396
214-396
129 spacer = minSize > 0 ? spacer * space / minSize : 0;
partially evaluated: minSize > 0
TRUEFALSE
yes
Evaluation Count:214
no
Evaluation Count:0
0-214
130 sumSpacing = spacer * spacerCount;
executed (the execution status of this line is deduced): sumSpacing = spacer * spacerCount;
-
131 }
executed: }
Execution Count:214
214
132 -
133 QList<int> list;
executed (the execution status of this line is deduced): QList<int> list;
-
134 -
135 for (i = start; i < start + count; i++)
evaluated: i < start + count
TRUEFALSE
yes
Evaluation Count:1935
yes
Evaluation Count:610
610-1935
136 list << chain.at(i).minimumSize;
executed: list << chain.at(i).minimumSize;
Execution Count:1935
1935
137 -
138 qSort(list);
executed (the execution status of this line is deduced): qSort(list);
-
139 -
140 int space_left = space - sumSpacing;
executed (the execution status of this line is deduced): int space_left = space - sumSpacing;
-
141 -
142 int sum = 0;
executed (the execution status of this line is deduced): int sum = 0;
-
143 int idx = 0;
executed (the execution status of this line is deduced): int idx = 0;
-
144 int space_used=0;
executed (the execution status of this line is deduced): int space_used=0;
-
145 int current = 0;
executed (the execution status of this line is deduced): int current = 0;
-
146 while (idx < count && space_used < space_left) {
evaluated: idx < count
TRUEFALSE
yes
Evaluation Count:1624
yes
Evaluation Count:218
evaluated: space_used < space_left
TRUEFALSE
yes
Evaluation Count:1232
yes
Evaluation Count:392
218-1624
147 current = list.at(idx);
executed (the execution status of this line is deduced): current = list.at(idx);
-
148 space_used = sum + current * (count - idx);
executed (the execution status of this line is deduced): space_used = sum + current * (count - idx);
-
149 sum += current;
executed (the execution status of this line is deduced): sum += current;
-
150 ++idx;
executed (the execution status of this line is deduced): ++idx;
-
151 }
executed: }
Execution Count:1232
1232
152 --idx;
executed (the execution status of this line is deduced): --idx;
-
153 int deficit = space_used - space_left;
executed (the execution status of this line is deduced): int deficit = space_used - space_left;
-
154 -
155 int items = count - idx;
executed (the execution status of this line is deduced): int items = count - idx;
-
156 /* -
157 * If we truncate all items to "current", we would get "deficit" too many pixels. Therefore, we have to remove -
158 * deficit/items from each item bigger than maxval. The actual value to remove is deficitPerItem + remainder/items -
159 * "rest" is the accumulated error from using integer arithmetic. -
160 */ -
161 int deficitPerItem = deficit/items;
executed (the execution status of this line is deduced): int deficitPerItem = deficit/items;
-
162 int remainder = deficit % items;
executed (the execution status of this line is deduced): int remainder = deficit % items;
-
163 int maxval = current - deficitPerItem;
executed (the execution status of this line is deduced): int maxval = current - deficitPerItem;
-
164 -
165 int rest = 0;
executed (the execution status of this line is deduced): int rest = 0;
-
166 for (i = start; i < start + count; i++) {
evaluated: i < start + count
TRUEFALSE
yes
Evaluation Count:1935
yes
Evaluation Count:610
610-1935
167 int maxv = maxval;
executed (the execution status of this line is deduced): int maxv = maxval;
-
168 rest += remainder;
executed (the execution status of this line is deduced): rest += remainder;
-
169 if (rest >= items) {
evaluated: rest >= items
TRUEFALSE
yes
Evaluation Count:242
yes
Evaluation Count:1693
242-1693
170 maxv--;
executed (the execution status of this line is deduced): maxv--;
-
171 rest-=items;
executed (the execution status of this line is deduced): rest-=items;
-
172 }
executed: }
Execution Count:242
242
173 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
174 data->size = qMin(data->minimumSize, maxv);
executed (the execution status of this line is deduced): data->size = qMin(data->minimumSize, maxv);
-
175 data->done = true;
executed (the execution status of this line is deduced): data->done = true;
-
176 }
executed: }
Execution Count:1935
1935
177 } else if (space < cHint + sumSpacing) {
executed: }
Execution Count:610
evaluated: space < cHint + sumSpacing
TRUEFALSE
yes
Evaluation Count:140
yes
Evaluation Count:11169
140-11169
178 /* -
179 Less space than smartSizeHint(), but more than minimumSize. -
180 Currently take space equally from each, as in Qt 2.x. -
181 Commented-out lines will give more space to stretchier -
182 items. -
183 */ -
184 int n = count;
executed (the execution status of this line is deduced): int n = count;
-
185 int space_left = space - sumSpacing;
executed (the execution status of this line is deduced): int space_left = space - sumSpacing;
-
186 int overdraft = cHint - space_left;
executed (the execution status of this line is deduced): int overdraft = cHint - space_left;
-
187 -
188 // first give to the fixed ones: -
189 for (i = start; i < start + count; i++) {
evaluated: i < start + count
TRUEFALSE
yes
Evaluation Count:491
yes
Evaluation Count:140
140-491
190 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
191 if (!data->done
partially evaluated: !data->done
TRUEFALSE
yes
Evaluation Count:491
no
Evaluation Count:0
0-491
192 && data->minimumSize >= data->smartSizeHint()) {
evaluated: data->minimumSize >= data->smartSizeHint()
TRUEFALSE
yes
Evaluation Count:259
yes
Evaluation Count:232
232-259
193 data->size = data->smartSizeHint();
executed (the execution status of this line is deduced): data->size = data->smartSizeHint();
-
194 data->done = true;
executed (the execution status of this line is deduced): data->done = true;
-
195 space_left -= data->smartSizeHint();
executed (the execution status of this line is deduced): space_left -= data->smartSizeHint();
-
196 // sumStretch -= data->stretch; -
197 n--;
executed (the execution status of this line is deduced): n--;
-
198 }
executed: }
Execution Count:259
259
199 }
executed: }
Execution Count:491
491
200 bool finished = n == 0;
executed (the execution status of this line is deduced): bool finished = n == 0;
-
201 while (!finished) {
evaluated: !finished
TRUEFALSE
yes
Evaluation Count:164
yes
Evaluation Count:140
140-164
202 finished = true;
executed (the execution status of this line is deduced): finished = true;
-
203 Fixed64 fp_over = toFixed(overdraft);
executed (the execution status of this line is deduced): Fixed64 fp_over = toFixed(overdraft);
-
204 Fixed64 fp_w = 0;
executed (the execution status of this line is deduced): Fixed64 fp_w = 0;
-
205 -
206 for (i = start; i < start+count; i++) {
evaluated: i < start+count
TRUEFALSE
yes
Evaluation Count:697
yes
Evaluation Count:140
140-697
207 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
208 if (data->done)
evaluated: data->done
TRUEFALSE
yes
Evaluation Count:416
yes
Evaluation Count:281
281-416
209 continue;
executed: continue;
Execution Count:416
416
210 // if (sumStretch <= 0) -
211 fp_w += fp_over / n;
executed (the execution status of this line is deduced): fp_w += fp_over / n;
-
212 // else -
213 // fp_w += (fp_over * data->stretch) / sumStretch; -
214 int w = fRound(fp_w);
executed (the execution status of this line is deduced): int w = fRound(fp_w);
-
215 data->size = data->smartSizeHint() - w;
executed (the execution status of this line is deduced): data->size = data->smartSizeHint() - w;
-
216 fp_w -= toFixed(w); // give the difference to the next
executed (the execution status of this line is deduced): fp_w -= toFixed(w);
-
217 if (data->size < data->minimumSize) {
evaluated: data->size < data->minimumSize
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:257
24-257
218 data->done = true;
executed (the execution status of this line is deduced): data->done = true;
-
219 data->size = data->minimumSize;
executed (the execution status of this line is deduced): data->size = data->minimumSize;
-
220 finished = false;
executed (the execution status of this line is deduced): finished = false;
-
221 overdraft -= data->smartSizeHint() - data->minimumSize;
executed (the execution status of this line is deduced): overdraft -= data->smartSizeHint() - data->minimumSize;
-
222 // sumStretch -= data->stretch; -
223 n--;
executed (the execution status of this line is deduced): n--;
-
224 break;
executed: break;
Execution Count:24
24
225 } -
226 }
executed: }
Execution Count:257
257
227 }
executed: }
Execution Count:164
164
228 } else { // extra space
executed: }
Execution Count:140
140
229 int n = count;
executed (the execution status of this line is deduced): int n = count;
-
230 int space_left = space - sumSpacing;
executed (the execution status of this line is deduced): int space_left = space - sumSpacing;
-
231 // first give to the fixed ones, and handle non-expansiveness -
232 for (i = start; i < start + count; i++) {
evaluated: i < start + count
TRUEFALSE
yes
Evaluation Count:30264
yes
Evaluation Count:11169
11169-30264
233 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
234 if (!data->done
partially evaluated: !data->done
TRUEFALSE
yes
Evaluation Count:30264
no
Evaluation Count:0
0-30264
235 && (data->maximumSize <= data->smartSizeHint()
evaluated: data->maximumSize <= data->smartSizeHint()
TRUEFALSE
yes
Evaluation Count:12507
yes
Evaluation Count:17757
12507-17757
236 || (wannaGrow && !data->expansive && data->stretch == 0)
evaluated: wannaGrow
TRUEFALSE
yes
Evaluation Count:10827
yes
Evaluation Count:6930
evaluated: !data->expansive
TRUEFALSE
yes
Evaluation Count:4098
yes
Evaluation Count:6729
evaluated: data->stretch == 0
TRUEFALSE
yes
Evaluation Count:3873
yes
Evaluation Count:225
225-10827
237 || (!allEmptyNonstretch && data->empty &&
evaluated: !allEmptyNonstretch
TRUEFALSE
yes
Evaluation Count:13510
yes
Evaluation Count:374
evaluated: data->empty
TRUEFALSE
yes
Evaluation Count:1870
yes
Evaluation Count:11640
374-13510
238 !data->expansive && data->stretch == 0))) {
evaluated: !data->expansive
TRUEFALSE
yes
Evaluation Count:683
yes
Evaluation Count:1187
partially evaluated: data->stretch == 0
TRUEFALSE
yes
Evaluation Count:683
no
Evaluation Count:0
0-1187
239 data->size = data->smartSizeHint();
executed (the execution status of this line is deduced): data->size = data->smartSizeHint();
-
240 data->done = true;
executed (the execution status of this line is deduced): data->done = true;
-
241 space_left -= data->size;
executed (the execution status of this line is deduced): space_left -= data->size;
-
242 sumStretch -= data->stretch;
executed (the execution status of this line is deduced): sumStretch -= data->stretch;
-
243 n--;
executed (the execution status of this line is deduced): n--;
-
244 }
executed: }
Execution Count:17063
17063
245 }
executed: }
Execution Count:30264
30264
246 extraspace = space_left;
executed (the execution status of this line is deduced): extraspace = space_left;
-
247 -
248 /* -
249 Do a trial distribution and calculate how much it is off. -
250 If there are more deficit pixels than surplus pixels, give -
251 the minimum size items what they need, and repeat. -
252 Otherwise give to the maximum size items, and repeat. -
253 -
254 Paul Olav Tvete has a wonderful mathematical proof of the -
255 correctness of this principle, but unfortunately this -
256 comment is too small to contain it. -
257 */ -
258 int surplus, deficit;
executed (the execution status of this line is deduced): int surplus, deficit;
-
259 do { -
260 surplus = deficit = 0;
executed (the execution status of this line is deduced): surplus = deficit = 0;
-
261 Fixed64 fp_space = toFixed(space_left);
executed (the execution status of this line is deduced): Fixed64 fp_space = toFixed(space_left);
-
262 Fixed64 fp_w = 0;
executed (the execution status of this line is deduced): Fixed64 fp_w = 0;
-
263 for (i = start; i < start + count; i++) {
evaluated: i < start + count
TRUEFALSE
yes
Evaluation Count:32997
yes
Evaluation Count:12104
12104-32997
264 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
265 if (data->done)
evaluated: data->done
TRUEFALSE
yes
Evaluation Count:18782
yes
Evaluation Count:14215
14215-18782
266 continue;
executed: continue;
Execution Count:18782
18782
267 extraspace = 0;
executed (the execution status of this line is deduced): extraspace = 0;
-
268 if (sumStretch <= 0)
evaluated: sumStretch <= 0
TRUEFALSE
yes
Evaluation Count:9613
yes
Evaluation Count:4602
4602-9613
269 fp_w += fp_space / n;
executed: fp_w += fp_space / n;
Execution Count:9613
9613
270 else -
271 fp_w += (fp_space * data->stretch) / sumStretch;
executed: fp_w += (fp_space * data->stretch) / sumStretch;
Execution Count:4602
4602
272 int w = fRound(fp_w);
executed (the execution status of this line is deduced): int w = fRound(fp_w);
-
273 data->size = w;
executed (the execution status of this line is deduced): data->size = w;
-
274 fp_w -= toFixed(w); // give the difference to the next
executed (the execution status of this line is deduced): fp_w -= toFixed(w);
-
275 if (w < data->smartSizeHint()) {
evaluated: w < data->smartSizeHint()
TRUEFALSE
yes
Evaluation Count:782
yes
Evaluation Count:13433
782-13433
276 deficit += data->smartSizeHint() - w;
executed (the execution status of this line is deduced): deficit += data->smartSizeHint() - w;
-
277 } else if (w > data->maximumSize) {
executed: }
Execution Count:782
evaluated: w > data->maximumSize
TRUEFALSE
yes
Evaluation Count:308
yes
Evaluation Count:13125
308-13125
278 surplus += w - data->maximumSize;
executed (the execution status of this line is deduced): surplus += w - data->maximumSize;
-
279 }
executed: }
Execution Count:308
308
280 } -
281 if (deficit > 0 && surplus <= deficit) {
evaluated: deficit > 0
TRUEFALSE
yes
Evaluation Count:627
yes
Evaluation Count:11477
partially evaluated: surplus <= deficit
TRUEFALSE
yes
Evaluation Count:627
no
Evaluation Count:0
0-11477
282 // give to the ones that have too little -
283 for (i = start; i < start+count; i++) {
evaluated: i < start+count
TRUEFALSE
yes
Evaluation Count:2117
yes
Evaluation Count:627
627-2117
284 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
285 if (!data->done && data->size < data->smartSizeHint()) {
evaluated: !data->done
TRUEFALSE
yes
Evaluation Count:1488
yes
Evaluation Count:629
evaluated: data->size < data->smartSizeHint()
TRUEFALSE
yes
Evaluation Count:782
yes
Evaluation Count:706
629-1488
286 data->size = data->smartSizeHint();
executed (the execution status of this line is deduced): data->size = data->smartSizeHint();
-
287 data->done = true;
executed (the execution status of this line is deduced): data->done = true;
-
288 space_left -= data->smartSizeHint();
executed (the execution status of this line is deduced): space_left -= data->smartSizeHint();
-
289 sumStretch -= data->stretch;
executed (the execution status of this line is deduced): sumStretch -= data->stretch;
-
290 n--;
executed (the execution status of this line is deduced): n--;
-
291 }
executed: }
Execution Count:782
782
292 }
executed: }
Execution Count:2117
2117
293 }
executed: }
Execution Count:627
627
294 if (surplus > 0 && surplus >= deficit) {
evaluated: surplus > 0
TRUEFALSE
yes
Evaluation Count:308
yes
Evaluation Count:11796
partially evaluated: surplus >= deficit
TRUEFALSE
yes
Evaluation Count:308
no
Evaluation Count:0
0-11796
295 // take from the ones that have too much -
296 for (i = start; i < start + count; i++) {
evaluated: i < start + count
TRUEFALSE
yes
Evaluation Count:616
yes
Evaluation Count:308
308-616
297 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
298 if (!data->done && data->size > data->maximumSize) {
partially evaluated: !data->done
TRUEFALSE
yes
Evaluation Count:616
no
Evaluation Count:0
evaluated: data->size > data->maximumSize
TRUEFALSE
yes
Evaluation Count:308
yes
Evaluation Count:308
0-616
299 data->size = data->maximumSize;
executed (the execution status of this line is deduced): data->size = data->maximumSize;
-
300 data->done = true;
executed (the execution status of this line is deduced): data->done = true;
-
301 space_left -= data->maximumSize;
executed (the execution status of this line is deduced): space_left -= data->maximumSize;
-
302 sumStretch -= data->stretch;
executed (the execution status of this line is deduced): sumStretch -= data->stretch;
-
303 n--;
executed (the execution status of this line is deduced): n--;
-
304 }
executed: }
Execution Count:308
308
305 }
executed: }
Execution Count:616
616
306 }
executed: }
Execution Count:308
308
307 } while (n > 0 && surplus != deficit);
executed: }
Execution Count:12104
evaluated: n > 0
TRUEFALSE
yes
Evaluation Count:10934
yes
Evaluation Count:1170
evaluated: surplus != deficit
TRUEFALSE
yes
Evaluation Count:935
yes
Evaluation Count:9999
935-12104
308 if (n == 0)
evaluated: n == 0
TRUEFALSE
yes
Evaluation Count:1170
yes
Evaluation Count:9999
1170-9999
309 extraspace = space_left;
executed: extraspace = space_left;
Execution Count:1170
1170
310 }
executed: }
Execution Count:11169
11169
311 -
312 /* -
313 As a last resort, we distribute the unwanted space equally -
314 among the spacers (counting the start and end of the chain). We -
315 could, but don't, attempt a sub-pixel allocation of the extra -
316 space. -
317 */ -
318 int extra = extraspace / (spacerCount + 2);
executed (the execution status of this line is deduced): int extra = extraspace / (spacerCount + 2);
-
319 int p = pos + extra;
executed (the execution status of this line is deduced): int p = pos + extra;
-
320 for (i = start; i < start+count; i++) {
evaluated: i < start+count
TRUEFALSE
yes
Evaluation Count:32690
yes
Evaluation Count:11919
11919-32690
321 QLayoutStruct *data = &chain[i];
executed (the execution status of this line is deduced): QLayoutStruct *data = &chain[i];
-
322 data->pos = p;
executed (the execution status of this line is deduced): data->pos = p;
-
323 p += data->size;
executed (the execution status of this line is deduced): p += data->size;
-
324 if (!data->empty)
evaluated: !data->empty
TRUEFALSE
yes
Evaluation Count:24980
yes
Evaluation Count:7710
7710-24980
325 p += data->effectiveSpacer(spacer) + extra;
executed: p += data->effectiveSpacer(spacer) + extra;
Execution Count:24980
24980
326 }
executed: }
Execution Count:32690
32690
327 -
328#ifdef QLAYOUT_EXTRA_DEBUG -
329 qDebug() << "qGeomCalc" << "start" << start << "count" << count << "pos" << pos -
330 << "space" << space << "spacer" << spacer; -
331 for (i = start; i < start + count; ++i) { -
332 qDebug() << i << ':' << chain[i].minimumSize << chain[i].smartSizeHint() -
333 << chain[i].maximumSize << "stretch" << chain[i].stretch -
334 << "empty" << chain[i].empty << "expansive" << chain[i].expansive -
335 << "spacing" << chain[i].spacing; -
336 qDebug() << "result pos" << chain[i].pos << "size" << chain[i].size; -
337 } -
338#endif -
339}
executed: }
Execution Count:11919
11919
340 -
341Q_WIDGETS_EXPORT QSize qSmartMinSize(const QSize &sizeHint, const QSize &minSizeHint, -
342 const QSize &minSize, const QSize &maxSize, -
343 const QSizePolicy &sizePolicy) -
344{ -
345 QSize s(0, 0);
executed (the execution status of this line is deduced): QSize s(0, 0);
-
346 -
347 if (sizePolicy.horizontalPolicy() != QSizePolicy::Ignored) {
evaluated: sizePolicy.horizontalPolicy() != QSizePolicy::Ignored
TRUEFALSE
yes
Evaluation Count:23216
yes
Evaluation Count:250
250-23216
348 if (sizePolicy.horizontalPolicy() & QSizePolicy::ShrinkFlag)
evaluated: sizePolicy.horizontalPolicy() & QSizePolicy::ShrinkFlag
TRUEFALSE
yes
Evaluation Count:17248
yes
Evaluation Count:5968
5968-17248
349 s.setWidth(minSizeHint.width());
executed: s.setWidth(minSizeHint.width());
Execution Count:17248
17248
350 else -
351 s.setWidth(qMax(sizeHint.width(), minSizeHint.width()));
executed: s.setWidth(qMax(sizeHint.width(), minSizeHint.width()));
Execution Count:5968
5968
352 } -
353 -
354 if (sizePolicy.verticalPolicy() != QSizePolicy::Ignored) {
evaluated: sizePolicy.verticalPolicy() != QSizePolicy::Ignored
TRUEFALSE
yes
Evaluation Count:23450
yes
Evaluation Count:16
16-23450
355 if (sizePolicy.verticalPolicy() & QSizePolicy::ShrinkFlag) {
evaluated: sizePolicy.verticalPolicy() & QSizePolicy::ShrinkFlag
TRUEFALSE
yes
Evaluation Count:16733
yes
Evaluation Count:6717
6717-16733
356 s.setHeight(minSizeHint.height());
executed (the execution status of this line is deduced): s.setHeight(minSizeHint.height());
-
357 } else {
executed: }
Execution Count:16733
16733
358 s.setHeight(qMax(sizeHint.height(), minSizeHint.height()));
executed (the execution status of this line is deduced): s.setHeight(qMax(sizeHint.height(), minSizeHint.height()));
-
359 }
executed: }
Execution Count:6717
6717
360 } -
361 -
362 s = s.boundedTo(maxSize);
executed (the execution status of this line is deduced): s = s.boundedTo(maxSize);
-
363 if (minSize.width() > 0)
evaluated: minSize.width() > 0
TRUEFALSE
yes
Evaluation Count:5456
yes
Evaluation Count:18010
5456-18010
364 s.setWidth(minSize.width());
executed: s.setWidth(minSize.width());
Execution Count:5456
5456
365 if (minSize.height() > 0)
evaluated: minSize.height() > 0
TRUEFALSE
yes
Evaluation Count:1421
yes
Evaluation Count:22045
1421-22045
366 s.setHeight(minSize.height());
executed: s.setHeight(minSize.height());
Execution Count:1421
1421
367 -
368 return s.expandedTo(QSize(0,0));
executed: return s.expandedTo(QSize(0,0));
Execution Count:23466
23466
369} -
370 -
371Q_WIDGETS_EXPORT QSize qSmartMinSize(const QWidgetItem *i) -
372{ -
373 QWidget *w = ((QWidgetItem *)i)->widget();
executed (the execution status of this line is deduced): QWidget *w = ((QWidgetItem *)i)->widget();
-
374 return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(),
executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
Execution Count:55
55
375 w->minimumSize(), w->maximumSize(),
executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
Execution Count:55
55
376 w->sizePolicy());
executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
Execution Count:55
55
377} -
378 -
379Q_WIDGETS_EXPORT QSize qSmartMinSize(const QWidget *w) -
380{ -
381 return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(),
executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
Execution Count:13336
13336
382 w->minimumSize(), w->maximumSize(),
executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
Execution Count:13336
13336
383 w->sizePolicy());
executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy());
Execution Count:13336
13336
384} -
385 -
386Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QSize &sizeHint, -
387 const QSize &minSize, const QSize &maxSize, -
388 const QSizePolicy &sizePolicy, Qt::Alignment align) -
389{ -
390 if (align & Qt::AlignHorizontal_Mask && align & Qt::AlignVertical_Mask)
evaluated: align & Qt::AlignHorizontal_Mask
TRUEFALSE
yes
Evaluation Count:1368
yes
Evaluation Count:10633
evaluated: align & Qt::AlignVertical_Mask
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:1350
18-10633
391 return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
executed: return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
Execution Count:18
18
392 QSize s = maxSize;
executed (the execution status of this line is deduced): QSize s = maxSize;
-
393 QSize hint = sizeHint.expandedTo(minSize);
executed (the execution status of this line is deduced): QSize hint = sizeHint.expandedTo(minSize);
-
394 if (s.width() == QWIDGETSIZE_MAX && !(align & Qt::AlignHorizontal_Mask))
evaluated: s.width() == ((1<<24)-1)
TRUEFALSE
yes
Evaluation Count:9395
yes
Evaluation Count:2588
evaluated: !(align & Qt::AlignHorizontal_Mask)
TRUEFALSE
yes
Evaluation Count:9053
yes
Evaluation Count:342
342-9395
395 if (!(sizePolicy.horizontalPolicy() & QSizePolicy::GrowFlag))
evaluated: !(sizePolicy.horizontalPolicy() & QSizePolicy::GrowFlag)
TRUEFALSE
yes
Evaluation Count:1717
yes
Evaluation Count:7336
1717-7336
396 s.setWidth(hint.width());
executed: s.setWidth(hint.width());
Execution Count:1717
1717
397 -
398 if (s.height() == QWIDGETSIZE_MAX && !(align & Qt::AlignVertical_Mask))
evaluated: s.height() == ((1<<24)-1)
TRUEFALSE
yes
Evaluation Count:8824
yes
Evaluation Count:3159
evaluated: !(align & Qt::AlignVertical_Mask)
TRUEFALSE
yes
Evaluation Count:8769
yes
Evaluation Count:55
55-8824
399 if (!(sizePolicy.verticalPolicy() & QSizePolicy::GrowFlag))
evaluated: !(sizePolicy.verticalPolicy() & QSizePolicy::GrowFlag)
TRUEFALSE
yes
Evaluation Count:4134
yes
Evaluation Count:4635
4134-4635
400 s.setHeight(hint.height());
executed: s.setHeight(hint.height());
Execution Count:4134
4134
401 -
402 if (align & Qt::AlignHorizontal_Mask)
evaluated: align & Qt::AlignHorizontal_Mask
TRUEFALSE
yes
Evaluation Count:1350
yes
Evaluation Count:10633
1350-10633
403 s.setWidth(QLAYOUTSIZE_MAX);
executed: s.setWidth(QLAYOUTSIZE_MAX);
Execution Count:1350
1350
404 if (align & Qt::AlignVertical_Mask)
evaluated: align & Qt::AlignVertical_Mask
TRUEFALSE
yes
Evaluation Count:55
yes
Evaluation Count:11928
55-11928
405 s.setHeight(QLAYOUTSIZE_MAX);
executed: s.setHeight(QLAYOUTSIZE_MAX);
Execution Count:55
55
406 return s;
executed: return s;
Execution Count:11983
11983
407} -
408 -
409Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QWidgetItem *i, Qt::Alignment align) -
410{ -
411 QWidget *w = ((QWidgetItem*)i)->widget();
executed (the execution status of this line is deduced): QWidget *w = ((QWidgetItem*)i)->widget();
-
412 -
413 return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(),
executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
Execution Count:56
56
414 w->sizePolicy(), align);
executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
Execution Count:56
56
415} -
416 -
417Q_WIDGETS_EXPORT QSize qSmartMaxSize(const QWidget *w, Qt::Alignment align) -
418{ -
419 return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(),
executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
Execution Count:78
78
420 w->sizePolicy(), align);
executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align);
Execution Count:78
78
421} -
422 -
423Q_WIDGETS_EXPORT int qSmartSpacing(const QLayout *layout, QStyle::PixelMetric pm) -
424{ -
425 QObject *parent = layout->parent();
executed (the execution status of this line is deduced): QObject *parent = layout->parent();
-
426 if (!parent) {
partially evaluated: !parent
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8555
0-8555
427 return -1;
never executed: return -1;
0
428 } else if (parent->isWidgetType()) {
evaluated: parent->isWidgetType()
TRUEFALSE
yes
Evaluation Count:7876
yes
Evaluation Count:679
679-7876
429 QWidget *pw = static_cast<QWidget *>(parent);
executed (the execution status of this line is deduced): QWidget *pw = static_cast<QWidget *>(parent);
-
430 return pw->style()->pixelMetric(pm, 0, pw);
executed: return pw->style()->pixelMetric(pm, 0, pw);
Execution Count:7876
7876
431 } else { -
432 return static_cast<QLayout *>(parent)->spacing();
executed: return static_cast<QLayout *>(parent)->spacing();
Execution Count:679
679
433 } -
434} -
435 -
436QT_END_NAMESPACE -
437 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial