kernel/qstackedlayout.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5class QStackedLayoutPrivate : public QLayoutPrivate -
6{ -
7 inline QStackedLayout* q_func() { return static_cast<QStackedLayout *>(q_ptr); } inline const QStackedLayout* q_func() const { return static_cast<const QStackedLayout *>(q_ptr); } friend class QStackedLayout; -
8public: -
9 QStackedLayoutPrivate() : index(-1), stackingMode(QStackedLayout::StackOne) {}
executed: }
Execution Count:164
164
10 QList<QLayoutItem *> list; -
11 int index; -
12 QStackedLayout::StackingMode stackingMode; -
13}; -
14QStackedLayout::QStackedLayout() -
15 : QLayout(*new QStackedLayoutPrivate, 0, 0) -
16{ -
17}
executed: }
Execution Count:2
2
18 -
19 -
20 -
21 -
22 -
23 -
24 -
25QStackedLayout::QStackedLayout(QWidget *parent) -
26 : QLayout(*new QStackedLayoutPrivate, 0, parent) -
27{ -
28}
executed: }
Execution Count:162
162
29 -
30 -
31 -
32 -
33 -
34QStackedLayout::QStackedLayout(QLayout *parentLayout) -
35 : QLayout(*new QStackedLayoutPrivate, parentLayout, 0) -
36{ -
37}
never executed: }
0
38 -
39 -
40 -
41 -
42 -
43QStackedLayout::~QStackedLayout() -
44{ -
45 QStackedLayoutPrivate * const d = d_func(); -
46 qDeleteAll(d->list); -
47}
executed: }
Execution Count:161
161
48int QStackedLayout::addWidget(QWidget *widget) -
49{ -
50 QStackedLayoutPrivate * const d = d_func(); -
51 return insertWidget(d->list.count(), widget);
executed: return insertWidget(d->list.count(), widget);
Execution Count:255
255
52} -
53int QStackedLayout::insertWidget(int index, QWidget *widget) -
54{ -
55 QStackedLayoutPrivate * const d = d_func(); -
56 addChildWidget(widget); -
57 index = qMin(index, d->list.count()); -
58 if (index < 0)
evaluated: index < 0
TRUEFALSE
yes
Evaluation Count:52
yes
Evaluation Count:256
52-256
59 index = d->list.count();
executed: index = d->list.count();
Execution Count:52
52
60 QWidgetItem *wi = QLayoutPrivate::createWidgetItem(this, widget); -
61 d->list.insert(index, wi); -
62 invalidate(); -
63 if (d->index < 0) {
evaluated: d->index < 0
TRUEFALSE
yes
Evaluation Count:156
yes
Evaluation Count:152
152-156
64 setCurrentIndex(index); -
65 } else {
executed: }
Execution Count:156
156
66 if (index <= d->index)
evaluated: index <= d->index
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:151
1-151
67 ++d->index;
executed: ++d->index;
Execution Count:1
1
68 if (d->stackingMode == StackOne)
partially evaluated: d->stackingMode == StackOne
TRUEFALSE
yes
Evaluation Count:152
no
Evaluation Count:0
0-152
69 widget->hide();
executed: widget->hide();
Execution Count:152
152
70 widget->lower(); -
71 }
executed: }
Execution Count:152
152
72 return index;
executed: return index;
Execution Count:308
308
73} -
74 -
75 -
76 -
77 -
78QLayoutItem *QStackedLayout::itemAt(int index) const -
79{ -
80 const QStackedLayoutPrivate * const d = d_func(); -
81 return d->list.value(index);
executed: return d->list.value(index);
Execution Count:1445
1445
82} -
83 -
84 -
85 -
86 -
87 -
88class QtFriendlyLayoutWidget : public QWidget -
89{ -
90public: -
91 inline bool wasDeleted() const { return d_ptr->wasDeleted; }
executed: return d_ptr->wasDeleted;
Execution Count:33
33
92}; -
93 -
94static bool qt_wasDeleted(const QWidget *w) { return static_cast<const QtFriendlyLayoutWidget*>(w)->wasDeleted(); }
executed: return static_cast<const QtFriendlyLayoutWidget*>(w)->wasDeleted();
Execution Count:33
33
95 -
96 -
97 -
98 -
99 -
100QLayoutItem *QStackedLayout::takeAt(int index) -
101{ -
102 QStackedLayoutPrivate * const d = d_func(); -
103 if (index <0 || index >= d->list.size())
partially evaluated: index <0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
partially evaluated: index >= d->list.size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:33
0-33
104 return 0;
never executed: return 0;
0
105 QLayoutItem *item = d->list.takeAt(index); -
106 if (index == d->index) {
evaluated: index == d->index
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:8
8-25
107 d->index = -1; -
108 if ( d->list.count() > 0 ) {
evaluated: d->list.count() > 0
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:16
9-16
109 int newIndex = (index == d->list.count()) ? index-1 : index;
evaluated: (index == d->list.count())
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:5
4-5
110 setCurrentIndex(newIndex); -
111 } else {
executed: }
Execution Count:9
9
112 currentChanged(-1); -
113 }
executed: }
Execution Count:16
16
114 } else if (index < d->index) {
evaluated: index < d->index
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:1
1-7
115 --d->index; -
116 }
executed: }
Execution Count:7
7
117 widgetRemoved(index); -
118 if (item->widget() && !qt_wasDeleted(item->widget()))
partially evaluated: item->widget()
TRUEFALSE
yes
Evaluation Count:33
no
Evaluation Count:0
evaluated: !qt_wasDeleted(item->widget())
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:5
0-33
119 item->widget()->hide();
executed: item->widget()->hide();
Execution Count:28
28
120 return item;
executed: return item;
Execution Count:33
33
121} -
122void QStackedLayout::setCurrentIndex(int index) -
123{ -
124 QStackedLayoutPrivate * const d = d_func(); -
125 QWidget *prev = currentWidget(); -
126 QWidget *next = widget(index); -
127 if (!next || next == prev)
evaluated: !next
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:435
evaluated: next == prev
TRUEFALSE
yes
Evaluation Count:232
yes
Evaluation Count:203
6-435
128 return;
executed: return;
Execution Count:238
238
129 -
130 bool reenableUpdates = false; -
131 QWidget *parent = parentWidget(); -
132 -
133 if (parent && parent->updatesEnabled()) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:2
partially evaluated: parent->updatesEnabled()
TRUEFALSE
yes
Evaluation Count:201
no
Evaluation Count:0
0-201
134 reenableUpdates = true; -
135 parent->setUpdatesEnabled(false); -
136 }
executed: }
Execution Count:201
201
137 -
138 QWidget *fw = parent ? parent->window()->focusWidget() : 0;
evaluated: parent
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:2
2-201
139 if (prev) {
evaluated: prev
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:165
38-165
140 prev->clearFocus(); -
141 if (d->stackingMode == StackOne)
partially evaluated: d->stackingMode == StackOne
TRUEFALSE
yes
Evaluation Count:38
no
Evaluation Count:0
0-38
142 prev->hide();
executed: prev->hide();
Execution Count:38
38
143 }
executed: }
Execution Count:38
38
144 -
145 d->index = index; -
146 next->raise(); -
147 next->show(); -
148 -
149 -
150 -
151 -
152 if (parent) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:2
2-201
153 if (fw && (prev && prev->isAncestorOf(fw))) {
evaluated: fw
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:179
evaluated: prev
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:1
evaluated: prev->isAncestorOf(fw)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:16
1-179
154 -
155 if (QWidget *nfw = next->focusWidget())
evaluated: QWidget *nfw = next->focusWidget()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:3
2-3
156 nfw->setFocus();
executed: nfw->setFocus();
Execution Count:2
2
157 else { -
158 -
159 QWidget *i = fw; -
160 while ((i = i->nextInFocusChain()) != fw) {
partially evaluated: (i = i->nextInFocusChain()) != fw
TRUEFALSE
yes
Evaluation Count:43
no
Evaluation Count:0
0-43
161 if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
evaluated: ((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:32
11-32
162 && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
evaluated: !i->focusProxy()
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:2
evaluated: i->isVisibleTo(next)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:4
partially evaluated: i->isEnabled()
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-9
163 && next->isAncestorOf(i)) {
evaluated: next->isAncestorOf(i)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
164 i->setFocus(); -
165 break;
executed: break;
Execution Count:3
3
166 } -
167 }
executed: }
Execution Count:40
40
168 -
169 if (i == fw )
partially evaluated: i == fw
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
170 next->setFocus();
never executed: next->setFocus();
0
171 }
executed: }
Execution Count:3
3
172 } -
173 }
executed: }
Execution Count:201
201
174 if (reenableUpdates)
evaluated: reenableUpdates
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:2
2-201
175 parent->setUpdatesEnabled(true);
executed: parent->setUpdatesEnabled(true);
Execution Count:201
201
176 currentChanged(index); -
177}
executed: }
Execution Count:203
203
178 -
179int QStackedLayout::currentIndex() const -
180{ -
181 const QStackedLayoutPrivate * const d = d_func(); -
182 return d->index;
executed: return d->index;
Execution Count:19
19
183} -
184void QStackedLayout::setCurrentWidget(QWidget *widget) -
185{ -
186 int index = indexOf(widget); -
187 if (index == -1) {
evaluated: index == -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:77
1-77
188 QMessageLogger("kernel/qstackedlayout.cpp", 363, __PRETTY_FUNCTION__).warning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget); -
189 return;
executed: return;
Execution Count:1
1
190 } -
191 setCurrentIndex(index); -
192}
executed: }
Execution Count:77
77
193QWidget *QStackedLayout::currentWidget() const -
194{ -
195 const QStackedLayoutPrivate * const d = d_func(); -
196 return d->index >= 0 ? d->list.at(d->index)->widget() : 0;
executed: return d->index >= 0 ? d->list.at(d->index)->widget() : 0;
Execution Count:746
746
197} -
198 -
199 -
200 -
201 -
202 -
203 -
204 -
205QWidget *QStackedLayout::widget(int index) const -
206{ -
207 const QStackedLayoutPrivate * const d = d_func(); -
208 if (index < 0 || index >= d->list.size())
evaluated: index < 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:489
evaluated: index >= d->list.size()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:485
4-489
209 return 0;
executed: return 0;
Execution Count:9
9
210 return d->list.at(index)->widget();
executed: return d->list.at(index)->widget();
Execution Count:485
485
211} -
212 -
213 -
214 -
215 -
216 -
217 -
218 -
219int QStackedLayout::count() const -
220{ -
221 const QStackedLayoutPrivate * const d = d_func(); -
222 return d->list.size();
executed: return d->list.size();
Execution Count:621
621
223} -
224 -
225 -
226 -
227 -
228 -
229void QStackedLayout::addItem(QLayoutItem *item) -
230{ -
231 QWidget *widget = item->widget(); -
232 if (widget) {
never evaluated: widget
0
233 addWidget(widget); -
234 delete item; -
235 } else {
never executed: }
0
236 QMessageLogger("kernel/qstackedlayout.cpp", 419, __PRETTY_FUNCTION__).warning("QStackedLayout::addItem: Only widgets can be added"); -
237 }
never executed: }
0
238} -
239 -
240 -
241 -
242 -
243QSize QStackedLayout::sizeHint() const -
244{ -
245 const QStackedLayoutPrivate * const d = d_func(); -
246 QSize s(0, 0); -
247 int n = d->list.count(); -
248 -
249 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:354
yes
Evaluation Count:193
193-354
250 if (QWidget *widget = d->list.at(i)->widget()) {
partially evaluated: QWidget *widget = d->list.at(i)->widget()
TRUEFALSE
yes
Evaluation Count:354
no
Evaluation Count:0
0-354
251 QSize ws(widget->sizeHint()); -
252 if (widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)
partially evaluated: widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:354
0-354
253 ws.setWidth(0);
never executed: ws.setWidth(0);
0
254 if (widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)
partially evaluated: widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:354
0-354
255 ws.setHeight(0);
never executed: ws.setHeight(0);
0
256 s = s.expandedTo(ws); -
257 }
executed: }
Execution Count:354
354
258 return s;
executed: return s;
Execution Count:193
193
259} -
260 -
261 -
262 -
263 -
264QSize QStackedLayout::minimumSize() const -
265{ -
266 const QStackedLayoutPrivate * const d = d_func(); -
267 QSize s(0, 0); -
268 int n = d->list.count(); -
269 -
270 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:408
yes
Evaluation Count:236
236-408
271 if (QWidget *widget = d->list.at(i)->widget())
partially evaluated: QWidget *widget = d->list.at(i)->widget()
TRUEFALSE
yes
Evaluation Count:408
no
Evaluation Count:0
0-408
272 s = s.expandedTo(qSmartMinSize(widget));
executed: s = s.expandedTo(qSmartMinSize(widget));
Execution Count:408
408
273 return s;
executed: return s;
Execution Count:236
236
274} -
275 -
276 -
277 -
278 -
279void QStackedLayout::setGeometry(const QRect &rect) -
280{ -
281 QStackedLayoutPrivate * const d = d_func(); -
282 switch (d->stackingMode) { -
283 case StackOne: -
284 if (QWidget *widget = currentWidget())
evaluated: QWidget *widget = currentWidget()
TRUEFALSE
yes
Evaluation Count:128
yes
Evaluation Count:7
7-128
285 widget->setGeometry(rect);
executed: widget->setGeometry(rect);
Execution Count:128
128
286 break;
executed: break;
Execution Count:135
135
287 case StackAll: -
288 if (const int n = d->list.count())
never evaluated: const int n = d->list.count()
0
289 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
290 if (QWidget *widget = d->list.at(i)->widget())
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
291 widget->setGeometry(rect);
never executed: widget->setGeometry(rect);
0
292 break;
never executed: break;
0
293 } -
294}
executed: }
Execution Count:135
135
295 -
296 -
297 -
298 -
299bool QStackedLayout::hasHeightForWidth() const -
300{ -
301 const int n = count(); -
302 -
303 for (int i = 0; i < n; ++i) {
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:852
yes
Evaluation Count:385
385-852
304 if (QLayoutItem *item = itemAt(i)) {
partially evaluated: QLayoutItem *item = itemAt(i)
TRUEFALSE
yes
Evaluation Count:852
no
Evaluation Count:0
0-852
305 if (item->hasHeightForWidth())
evaluated: item->hasHeightForWidth()
TRUEFALSE
yes
Evaluation Count:102
yes
Evaluation Count:750
102-750
306 return true;
executed: return true;
Execution Count:102
102
307 }
executed: }
Execution Count:750
750
308 }
executed: }
Execution Count:750
750
309 return false;
executed: return false;
Execution Count:385
385
310} -
311 -
312 -
313 -
314 -
315int QStackedLayout::heightForWidth(int width) const -
316{ -
317 const int n = count(); -
318 -
319 int hfw = 0; -
320 for (int i = 0; i < n; ++i) {
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:47
yes
Evaluation Count:44
44-47
321 if (QLayoutItem *item = itemAt(i)) {
partially evaluated: QLayoutItem *item = itemAt(i)
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
322 if (QWidget *w = item->widget())
partially evaluated: QWidget *w = item->widget()
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
323 -
324 -
325 -
326 -
327 -
328 -
329 hfw = qMax(hfw, w->heightForWidth(width));
executed: hfw = qMax(hfw, w->heightForWidth(width));
Execution Count:47
47
330 }
executed: }
Execution Count:47
47
331 }
executed: }
Execution Count:47
47
332 hfw = qMax(hfw, minimumSize().height()); -
333 return hfw;
executed: return hfw;
Execution Count:44
44
334} -
335QStackedLayout::StackingMode QStackedLayout::stackingMode() const -
336{ -
337 const QStackedLayoutPrivate * const d = d_func(); -
338 return d->stackingMode;
never executed: return d->stackingMode;
0
339} -
340 -
341void QStackedLayout::setStackingMode(StackingMode stackingMode) -
342{ -
343 QStackedLayoutPrivate * const d = d_func(); -
344 if (d->stackingMode == stackingMode)
never evaluated: d->stackingMode == stackingMode
0
345 return;
never executed: return;
0
346 d->stackingMode = stackingMode; -
347 -
348 const int n = d->list.count(); -
349 if (n == 0)
never evaluated: n == 0
0
350 return;
never executed: return;
0
351 -
352 switch (d->stackingMode) { -
353 case StackOne: -
354 if (const int idx = currentIndex())
never evaluated: const int idx = currentIndex()
0
355 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
356 if (QWidget *widget = d->list.at(i)->widget())
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
357 widget->setVisible(i == idx);
never executed: widget->setVisible(i == idx);
0
358 break;
never executed: break;
0
359 case StackAll: { -
360 QRect geometry; -
361 if (const QWidget *widget = currentWidget())
never evaluated: const QWidget *widget = currentWidget()
0
362 geometry = widget->geometry();
never executed: geometry = widget->geometry();
0
363 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
364 if (QWidget *widget = d->list.at(i)->widget()) {
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
365 if (!geometry.isNull())
never evaluated: !geometry.isNull()
0
366 widget->setGeometry(geometry);
never executed: widget->setGeometry(geometry);
0
367 widget->setVisible(true); -
368 }
never executed: }
0
369 } -
370 break;
never executed: break;
0
371 } -
372}
never executed: }
0
373 -
374 -
375 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial