Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2012 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 | | - |
53 | QT_BEGIN_NAMESPACE | - |
54 | | - |
55 | //#define QLAYOUT_EXTRA_DEBUG | - |
56 | | - |
57 | typedef qint64 Fixed64; | - |
58 | static inline Fixed64 toFixed(int i) { return (Fixed64)i * 256; } executed: return (Fixed64)i * 256; Execution Count:22627 | 22627 |
59 | static 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:12370 | 12370 |
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 | */ | - |
78 | void 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 yes Evaluation Count:28349 | yes Evaluation Count:9935 |
| 9935-28349 |
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 yes Evaluation Count:20917 | yes Evaluation Count:7432 |
| 7432-20917 |
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 yes Evaluation Count:11566 | yes Evaluation Count:9351 |
| 9351-11566 |
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:11566 | 11566 |
112 | pendingSpacing = data->effectiveSpacer(spacer); executed (the execution status of this line is deduced): pendingSpacing = data->effectiveSpacer(spacer); | - |
113 | } executed: } Execution Count:20917 | 20917 |
114 | wannaGrow = wannaGrow || data->expansive || data->stretch > 0; evaluated: wannaGrow yes Evaluation Count:8253 | yes Evaluation Count:20096 |
evaluated: data->expansive yes Evaluation Count:4816 | yes Evaluation Count:15280 |
evaluated: data->stretch > 0 yes Evaluation Count:168 | yes Evaluation Count:15112 |
| 168-20096 |
115 | allEmptyNonstretch = allEmptyNonstretch && !wannaGrow && data->empty; evaluated: allEmptyNonstretch yes Evaluation Count:12866 | yes Evaluation Count:15483 |
evaluated: !wannaGrow yes Evaluation Count:9471 | yes Evaluation Count:3395 |
evaluated: data->empty yes Evaluation Count:3412 | yes Evaluation Count:6059 |
| 3395-15483 |
116 | } executed: } Execution Count:28349 | 28349 |
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 yes Evaluation Count:492 | yes Evaluation Count:9443 |
| 492-9443 |
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 yes Evaluation Count:122 | yes Evaluation Count:370 |
| 122-370 |
129 | spacer = minSize > 0 ? spacer * space / minSize : 0; partially evaluated: minSize > 0 yes Evaluation Count:122 | no Evaluation Count:0 |
| 0-122 |
130 | sumSpacing = spacer * spacerCount; executed (the execution status of this line is deduced): sumSpacing = spacer * spacerCount; | - |
131 | } executed: } Execution Count:122 | 122 |
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 yes Evaluation Count:1528 | yes Evaluation Count:492 |
| 492-1528 |
136 | list << chain.at(i).minimumSize; executed: list << chain.at(i).minimumSize; Execution Count:1528 | 1528 |
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 yes Evaluation Count:1217 | yes Evaluation Count:188 |
evaluated: space_used < space_left yes Evaluation Count:913 | yes Evaluation Count:304 |
| 188-1217 |
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:913 | 913 |
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 yes Evaluation Count:1528 | yes Evaluation Count:492 |
| 492-1528 |
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 yes Evaluation Count:240 | yes Evaluation Count:1288 |
| 240-1288 |
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:240 | 240 |
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:1528 | 1528 |
177 | } else if (space < cHint + sumSpacing) { executed: } Execution Count:492 evaluated: space < cHint + sumSpacing yes Evaluation Count:131 | yes Evaluation Count:9312 |
| 131-9312 |
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 yes Evaluation Count:358 | yes Evaluation Count:131 |
| 131-358 |
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 yes Evaluation Count:358 | no Evaluation Count:0 |
| 0-358 |
192 | && data->minimumSize >= data->smartSizeHint()) { evaluated: data->minimumSize >= data->smartSizeHint() yes Evaluation Count:167 | yes Evaluation Count:191 |
| 167-191 |
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:167 | 167 |
199 | } executed: } Execution Count:358 | 358 |
200 | bool finished = n == 0; executed (the execution status of this line is deduced): bool finished = n == 0; | - |
201 | while (!finished) { evaluated: !finished yes Evaluation Count:147 | yes Evaluation Count:131 |
| 131-147 |
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 yes Evaluation Count:432 | yes Evaluation Count:131 |
| 131-432 |
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 yes Evaluation Count:240 | yes Evaluation Count:192 |
| 192-240 |
209 | continue; executed: continue; Execution Count:240 | 240 |
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 yes Evaluation Count:16 | yes Evaluation Count:176 |
| 16-176 |
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:16 | 16 |
225 | } | - |
226 | } executed: } Execution Count:176 | 176 |
227 | } executed: } Execution Count:147 | 147 |
228 | } else { // extra space executed: } Execution Count:131 | 131 |
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 yes Evaluation Count:26463 | yes Evaluation Count:9312 |
| 9312-26463 |
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 yes Evaluation Count:26463 | no Evaluation Count:0 |
| 0-26463 |
235 | && (data->maximumSize <= data->smartSizeHint() evaluated: data->maximumSize <= data->smartSizeHint() yes Evaluation Count:10847 | yes Evaluation Count:15616 |
| 10847-15616 |
236 | || (wannaGrow && !data->expansive && data->stretch == 0) evaluated: wannaGrow yes Evaluation Count:9688 | yes Evaluation Count:5928 |
evaluated: !data->expansive yes Evaluation Count:3811 | yes Evaluation Count:5877 |
evaluated: data->stretch == 0 yes Evaluation Count:3643 | yes Evaluation Count:168 |
| 168-9688 |
237 | || (!allEmptyNonstretch && data->empty && evaluated: !allEmptyNonstretch yes Evaluation Count:11610 | yes Evaluation Count:363 |
evaluated: data->empty yes Evaluation Count:1805 | yes Evaluation Count:9805 |
| 363-11610 |
238 | !data->expansive && data->stretch == 0))) { evaluated: !data->expansive yes Evaluation Count:672 | yes Evaluation Count:1133 |
partially evaluated: data->stretch == 0 yes Evaluation Count:672 | no Evaluation Count:0 |
| 0-1133 |
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:15162 | 15162 |
245 | } executed: } Execution Count:26463 | 26463 |
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 yes Evaluation Count:28910 | yes Evaluation Count:10110 |
| 10110-28910 |
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 yes Evaluation Count:16732 | yes Evaluation Count:12178 |
| 12178-16732 |
266 | continue; executed: continue; Execution Count:16732 | 16732 |
267 | extraspace = 0; executed (the execution status of this line is deduced): extraspace = 0; | - |
268 | if (sumStretch <= 0) evaluated: sumStretch <= 0 yes Evaluation Count:8162 | yes Evaluation Count:4016 |
| 4016-8162 |
269 | fp_w += fp_space / n; executed: fp_w += fp_space / n; Execution Count:8162 | 8162 |
270 | else | - |
271 | fp_w += (fp_space * data->stretch) / sumStretch; executed: fp_w += (fp_space * data->stretch) / sumStretch; Execution Count:4016 | 4016 |
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() yes Evaluation Count:773 | yes Evaluation Count:11405 |
| 773-11405 |
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:773 evaluated: w > data->maximumSize yes Evaluation Count:180 | yes Evaluation Count:11225 |
| 180-11225 |
278 | surplus += w - data->maximumSize; executed (the execution status of this line is deduced): surplus += w - data->maximumSize; | - |
279 | } executed: } Execution Count:180 | 180 |
280 | } | - |
281 | if (deficit > 0 && surplus <= deficit) { evaluated: deficit > 0 yes Evaluation Count:618 | yes Evaluation Count:9492 |
partially evaluated: surplus <= deficit yes Evaluation Count:618 | no Evaluation Count:0 |
| 0-9492 |
282 | // give to the ones that have too little | - |
283 | for (i = start; i < start+count; i++) { evaluated: i < start+count yes Evaluation Count:2087 | yes Evaluation Count:618 |
| 618-2087 |
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 yes Evaluation Count:1470 | yes Evaluation Count:617 |
evaluated: data->size < data->smartSizeHint() yes Evaluation Count:773 | yes Evaluation Count:697 |
| 617-1470 |
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:773 | 773 |
292 | } executed: } Execution Count:2087 | 2087 |
293 | } executed: } Execution Count:618 | 618 |
294 | if (surplus > 0 && surplus >= deficit) { evaluated: surplus > 0 yes Evaluation Count:180 | yes Evaluation Count:9930 |
partially evaluated: surplus >= deficit yes Evaluation Count:180 | no Evaluation Count:0 |
| 0-9930 |
295 | // take from the ones that have too much | - |
296 | for (i = start; i < start + count; i++) { evaluated: i < start + count yes Evaluation Count:360 | yes Evaluation Count:180 |
| 180-360 |
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 yes Evaluation Count:360 | no Evaluation Count:0 |
evaluated: data->size > data->maximumSize yes Evaluation Count:180 | yes Evaluation Count:180 |
| 0-360 |
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:180 | 180 |
305 | } executed: } Execution Count:360 | 360 |
306 | } executed: } Execution Count:180 | 180 |
307 | } while (n > 0 && surplus != deficit); executed: } Execution Count:10110 evaluated: n > 0 yes Evaluation Count:9103 | yes Evaluation Count:1007 |
evaluated: surplus != deficit yes Evaluation Count:798 | yes Evaluation Count:8305 |
| 798-10110 |
308 | if (n == 0) evaluated: n == 0 yes Evaluation Count:1007 | yes Evaluation Count:8305 |
| 1007-8305 |
309 | extraspace = space_left; executed: extraspace = space_left; Execution Count:1007 | 1007 |
310 | } executed: } Execution Count:9312 | 9312 |
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 yes Evaluation Count:28349 | yes Evaluation Count:9935 |
| 9935-28349 |
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 yes Evaluation Count:20917 | yes Evaluation Count:7432 |
| 7432-20917 |
325 | p += data->effectiveSpacer(spacer) + extra; executed: p += data->effectiveSpacer(spacer) + extra; Execution Count:20917 | 20917 |
326 | } executed: } Execution Count:28349 | 28349 |
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:9935 | 9935 |
340 | | - |
341 | Q_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 yes Evaluation Count:18649 | yes Evaluation Count:158 |
| 158-18649 |
348 | if (sizePolicy.horizontalPolicy() & QSizePolicy::ShrinkFlag) evaluated: sizePolicy.horizontalPolicy() & QSizePolicy::ShrinkFlag yes Evaluation Count:14513 | yes Evaluation Count:4136 |
| 4136-14513 |
349 | s.setWidth(minSizeHint.width()); executed: s.setWidth(minSizeHint.width()); Execution Count:14513 | 14513 |
350 | else | - |
351 | s.setWidth(qMax(sizeHint.width(), minSizeHint.width())); executed: s.setWidth(qMax(sizeHint.width(), minSizeHint.width())); Execution Count:4136 | 4136 |
352 | } | - |
353 | | - |
354 | if (sizePolicy.verticalPolicy() != QSizePolicy::Ignored) { evaluated: sizePolicy.verticalPolicy() != QSizePolicy::Ignored yes Evaluation Count:18796 | yes Evaluation Count:11 |
| 11-18796 |
355 | if (sizePolicy.verticalPolicy() & QSizePolicy::ShrinkFlag) { evaluated: sizePolicy.verticalPolicy() & QSizePolicy::ShrinkFlag yes Evaluation Count:14078 | yes Evaluation Count:4718 |
| 4718-14078 |
356 | s.setHeight(minSizeHint.height()); executed (the execution status of this line is deduced): s.setHeight(minSizeHint.height()); | - |
357 | } else { executed: } Execution Count:14078 | 14078 |
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:4718 | 4718 |
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 yes Evaluation Count:4946 | yes Evaluation Count:13861 |
| 4946-13861 |
364 | s.setWidth(minSize.width()); executed: s.setWidth(minSize.width()); Execution Count:4946 | 4946 |
365 | if (minSize.height() > 0) evaluated: minSize.height() > 0 yes Evaluation Count:998 | yes Evaluation Count:17809 |
| 998-17809 |
366 | s.setHeight(minSize.height()); executed: s.setHeight(minSize.height()); Execution Count:998 | 998 |
367 | | - |
368 | return s.expandedTo(QSize(0,0)); executed: return s.expandedTo(QSize(0,0)); Execution Count:18807 | 18807 |
369 | } | - |
370 | | - |
371 | Q_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:39 | 39 |
375 | w->minimumSize(), w->maximumSize(), executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy()); Execution Count:39 | 39 |
376 | w->sizePolicy()); executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy()); Execution Count:39 | 39 |
377 | } | - |
378 | | - |
379 | Q_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:11307 | 11307 |
382 | w->minimumSize(), w->maximumSize(), executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy()); Execution Count:11307 | 11307 |
383 | w->sizePolicy()); executed: return qSmartMinSize(w->sizeHint(), w->minimumSizeHint(), w->minimumSize(), w->maximumSize(), w->sizePolicy()); Execution Count:11307 | 11307 |
384 | } | - |
385 | | - |
386 | Q_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 yes Evaluation Count:1367 | yes Evaluation Count:8015 |
evaluated: align & Qt::AlignVertical_Mask yes Evaluation Count:17 | yes Evaluation Count:1350 |
| 17-8015 |
391 | return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX); executed: return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX); Execution Count:17 | 17 |
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) yes Evaluation Count:7197 | yes Evaluation Count:2168 |
evaluated: !(align & Qt::AlignHorizontal_Mask) yes Evaluation Count:6855 | yes Evaluation Count:342 |
| 342-7197 |
395 | if (!(sizePolicy.horizontalPolicy() & QSizePolicy::GrowFlag)) evaluated: !(sizePolicy.horizontalPolicy() & QSizePolicy::GrowFlag) yes Evaluation Count:1057 | yes Evaluation Count:5798 |
| 1057-5798 |
396 | s.setWidth(hint.width()); executed: s.setWidth(hint.width()); Execution Count:1057 | 1057 |
397 | | - |
398 | if (s.height() == QWIDGETSIZE_MAX && !(align & Qt::AlignVertical_Mask)) evaluated: s.height() == ((1<<24)-1) yes Evaluation Count:6626 | yes Evaluation Count:2739 |
evaluated: !(align & Qt::AlignVertical_Mask) yes Evaluation Count:6571 | yes Evaluation Count:55 |
| 55-6626 |
399 | if (!(sizePolicy.verticalPolicy() & QSizePolicy::GrowFlag)) evaluated: !(sizePolicy.verticalPolicy() & QSizePolicy::GrowFlag) yes Evaluation Count:3120 | yes Evaluation Count:3451 |
| 3120-3451 |
400 | s.setHeight(hint.height()); executed: s.setHeight(hint.height()); Execution Count:3120 | 3120 |
401 | | - |
402 | if (align & Qt::AlignHorizontal_Mask) evaluated: align & Qt::AlignHorizontal_Mask yes Evaluation Count:1350 | yes Evaluation Count:8015 |
| 1350-8015 |
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 yes Evaluation Count:55 | yes Evaluation Count:9310 |
| 55-9310 |
405 | s.setHeight(QLAYOUTSIZE_MAX); executed: s.setHeight(QLAYOUTSIZE_MAX); Execution Count:55 | 55 |
406 | return s; executed: return s; Execution Count:9365 | 9365 |
407 | } | - |
408 | | - |
409 | Q_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:51 | 51 |
414 | w->sizePolicy(), align); executed: return qSmartMaxSize(w->sizeHint().expandedTo(w->minimumSizeHint()), w->minimumSize(), w->maximumSize(), w->sizePolicy(), align); Execution Count:51 | 51 |
415 | } | - |
416 | | - |
417 | Q_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 | | - |
423 | Q_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 no Evaluation Count:0 | yes Evaluation Count:7391 |
| 0-7391 |
427 | return -1; never executed: return -1; | 0 |
428 | } else if (parent->isWidgetType()) { evaluated: parent->isWidgetType() yes Evaluation Count:6837 | yes Evaluation Count:554 |
| 554-6837 |
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:6837 | 6837 |
431 | } else { | - |
432 | return static_cast<QLayout *>(parent)->spacing(); executed: return static_cast<QLayout *>(parent)->spacing(); Execution Count:554 | 554 |
433 | } | - |
434 | } | - |
435 | | - |
436 | QT_END_NAMESPACE | - |
437 | | - |
| | |