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:238
238
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:236
236
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:234
234
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:397
397
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:53
yes
Evaluation Count:398
53-398
59 index = d->list.count();
executed: index = d->list.count();
Execution Count:53
53
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:228
yes
Evaluation Count:223
223-228
64 setCurrentIndex(index); -
65 } else {
executed: }
Execution Count:228
228
66 if (index <= d->index)
evaluated: index <= d->index
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:222
1-222
67 ++d->index;
executed: ++d->index;
Execution Count:1
1
68 if (d->stackingMode == StackOne)
partially evaluated: d->stackingMode == StackOne
TRUEFALSE
yes
Evaluation Count:223
no
Evaluation Count:0
0-223
69 widget->hide();
executed: widget->hide();
Execution Count:223
223
70 widget->lower(); -
71 }
executed: }
Execution Count:223
223
72 return index;
executed: return index;
Execution Count:451
451
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:2103
2103
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:635
evaluated: next == prev
TRUEFALSE
yes
Evaluation Count:355
yes
Evaluation Count:280
6-635
128 return;
executed: return;
Execution Count:361
361
129 -
130 bool reenableUpdates = false; -
131 QWidget *parent = parentWidget(); -
132 -
133 if (parent && parent->updatesEnabled()) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:278
yes
Evaluation Count:2
partially evaluated: parent->updatesEnabled()
TRUEFALSE
yes
Evaluation Count:278
no
Evaluation Count:0
0-278
134 reenableUpdates = true; -
135 parent->setUpdatesEnabled(false); -
136 }
executed: }
Execution Count:278
278
137 -
138 QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0;
evaluated: parent
TRUEFALSE
yes
Evaluation Count:278
yes
Evaluation Count:2
2-278
139 const bool focusWasOnOldPage = fw && (prev && prev->isAncestorOf(fw));
evaluated: fw
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:256
evaluated: prev
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:1
evaluated: prev->isAncestorOf(fw)
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:16
1-256
140 -
141 if (prev) {
evaluated: prev
TRUEFALSE
yes
Evaluation Count:43
yes
Evaluation Count:237
43-237
142 prev->clearFocus(); -
143 if (d->stackingMode == StackOne)
partially evaluated: d->stackingMode == StackOne
TRUEFALSE
yes
Evaluation Count:43
no
Evaluation Count:0
0-43
144 prev->hide();
executed: prev->hide();
Execution Count:43
43
145 }
executed: }
Execution Count:43
43
146 -
147 d->index = index; -
148 next->raise(); -
149 next->show(); -
150 -
151 -
152 -
153 -
154 if (parent) {
evaluated: parent
TRUEFALSE
yes
Evaluation Count:278
yes
Evaluation Count:2
2-278
155 if (focusWasOnOldPage) {
evaluated: focusWasOnOldPage
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:271
7-271
156 -
157 if (QWidget *nfw = next->focusWidget())
evaluated: QWidget *nfw = next->focusWidget()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:4
3-4
158 nfw->setFocus();
executed: nfw->setFocus();
Execution Count:3
3
159 else { -
160 -
161 if (QWidget *i = fw) {
partially evaluated: QWidget *i = fw
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
162 while ((i = i->nextInFocusChain()) != fw) {
evaluated: (i = i->nextInFocusChain()) != fw
TRUEFALSE
yes
Evaluation Count:51
yes
Evaluation Count:1
1-51
163 if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
evaluated: ((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:35
16-35
164 && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled()
evaluated: !i->focusProxy()
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:2
evaluated: i->isVisibleTo(next)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:9
partially evaluated: i->isEnabled()
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-14
165 && next->isAncestorOf(i)) {
evaluated: next->isAncestorOf(i)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
166 i->setFocus(); -
167 break;
executed: break;
Execution Count:3
3
168 } -
169 }
executed: }
Execution Count:48
48
170 -
171 if (i == fw )
evaluated: i == fw
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
172 next->setFocus();
executed: next->setFocus();
Execution Count:1
1
173 }
executed: }
Execution Count:4
4
174 }
executed: }
Execution Count:4
4
175 } -
176 }
executed: }
Execution Count:278
278
177 if (reenableUpdates)
evaluated: reenableUpdates
TRUEFALSE
yes
Evaluation Count:278
yes
Evaluation Count:2
2-278
178 parent->setUpdatesEnabled(true);
executed: parent->setUpdatesEnabled(true);
Execution Count:278
278
179 currentChanged(index); -
180}
executed: }
Execution Count:280
280
181 -
182int QStackedLayout::currentIndex() const -
183{ -
184 const QStackedLayoutPrivate * const d = d_func(); -
185 return d->index;
executed: return d->index;
Execution Count:19
19
186} -
187void QStackedLayout::setCurrentWidget(QWidget *widget) -
188{ -
189 int index = indexOf(widget); -
190 if (index == -1) {
evaluated: index == -1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:132
1-132
191 QMessageLogger("kernel/qstackedlayout.cpp", 366, __PRETTY_FUNCTION__).warning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget); -
192 return;
executed: return;
Execution Count:1
1
193 } -
194 setCurrentIndex(index); -
195}
executed: }
Execution Count:132
132
196QWidget *QStackedLayout::currentWidget() const -
197{ -
198 const QStackedLayoutPrivate * const d = d_func(); -
199 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:1078
1078
200} -
201 -
202 -
203 -
204 -
205 -
206 -
207 -
208QWidget *QStackedLayout::widget(int index) const -
209{ -
210 const QStackedLayoutPrivate * const d = d_func(); -
211 if (index < 0 || index >= d->list.size())
evaluated: index < 0
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:689
evaluated: index >= d->list.size()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:685
4-689
212 return 0;
executed: return 0;
Execution Count:9
9
213 return d->list.at(index)->widget();
executed: return d->list.at(index)->widget();
Execution Count:685
685
214} -
215 -
216 -
217 -
218 -
219 -
220 -
221 -
222int QStackedLayout::count() const -
223{ -
224 const QStackedLayoutPrivate * const d = d_func(); -
225 return d->list.size();
executed: return d->list.size();
Execution Count:866
866
226} -
227 -
228 -
229 -
230 -
231 -
232void QStackedLayout::addItem(QLayoutItem *item) -
233{ -
234 QWidget *widget = item->widget(); -
235 if (widget) {
never evaluated: widget
0
236 addWidget(widget); -
237 delete item; -
238 } else {
never executed: }
0
239 QMessageLogger("kernel/qstackedlayout.cpp", 422, __PRETTY_FUNCTION__).warning("QStackedLayout::addItem: Only widgets can be added"); -
240 }
never executed: }
0
241} -
242 -
243 -
244 -
245 -
246QSize QStackedLayout::sizeHint() const -
247{ -
248 const QStackedLayoutPrivate * const d = d_func(); -
249 QSize s(0, 0); -
250 int n = d->list.count(); -
251 -
252 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:542
yes
Evaluation Count:295
295-542
253 if (QWidget *widget = d->list.at(i)->widget()) {
partially evaluated: QWidget *widget = d->list.at(i)->widget()
TRUEFALSE
yes
Evaluation Count:542
no
Evaluation Count:0
0-542
254 QSize ws(widget->sizeHint()); -
255 if (widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)
partially evaluated: widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:542
0-542
256 ws.setWidth(0);
never executed: ws.setWidth(0);
0
257 if (widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)
partially evaluated: widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:542
0-542
258 ws.setHeight(0);
never executed: ws.setHeight(0);
0
259 s = s.expandedTo(ws); -
260 }
executed: }
Execution Count:542
542
261 return s;
executed: return s;
Execution Count:295
295
262} -
263 -
264 -
265 -
266 -
267QSize QStackedLayout::minimumSize() const -
268{ -
269 const QStackedLayoutPrivate * const d = d_func(); -
270 QSize s(0, 0); -
271 int n = d->list.count(); -
272 -
273 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:607
yes
Evaluation Count:342
342-607
274 if (QWidget *widget = d->list.at(i)->widget())
partially evaluated: QWidget *widget = d->list.at(i)->widget()
TRUEFALSE
yes
Evaluation Count:607
no
Evaluation Count:0
0-607
275 s = s.expandedTo(qSmartMinSize(widget));
executed: s = s.expandedTo(qSmartMinSize(widget));
Execution Count:607
607
276 return s;
executed: return s;
Execution Count:342
342
277} -
278 -
279 -
280 -
281 -
282void QStackedLayout::setGeometry(const QRect &rect) -
283{ -
284 QStackedLayoutPrivate * const d = d_func(); -
285 switch (d->stackingMode) { -
286 case StackOne: -
287 if (QWidget *widget = currentWidget())
evaluated: QWidget *widget = currentWidget()
TRUEFALSE
yes
Evaluation Count:180
yes
Evaluation Count:12
12-180
288 widget->setGeometry(rect);
executed: widget->setGeometry(rect);
Execution Count:180
180
289 break;
executed: break;
Execution Count:192
192
290 case StackAll: -
291 if (const int n = d->list.count())
never evaluated: const int n = d->list.count()
0
292 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
293 if (QWidget *widget = d->list.at(i)->widget())
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
294 widget->setGeometry(rect);
never executed: widget->setGeometry(rect);
0
295 break;
never executed: break;
0
296 } -
297}
executed: }
Execution Count:192
192
298 -
299 -
300 -
301 -
302bool QStackedLayout::hasHeightForWidth() const -
303{ -
304 const int n = count(); -
305 -
306 for (int i = 0; i < n; ++i) {
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:1309
yes
Evaluation Count:629
629-1309
307 if (QLayoutItem *item = itemAt(i)) {
partially evaluated: QLayoutItem *item = itemAt(i)
TRUEFALSE
yes
Evaluation Count:1309
no
Evaluation Count:0
0-1309
308 if (item->hasHeightForWidth())
evaluated: item->hasHeightForWidth()
TRUEFALSE
yes
Evaluation Count:102
yes
Evaluation Count:1207
102-1207
309 return true;
executed: return true;
Execution Count:102
102
310 }
executed: }
Execution Count:1207
1207
311 }
executed: }
Execution Count:1207
1207
312 return false;
executed: return false;
Execution Count:629
629
313} -
314 -
315 -
316 -
317 -
318int QStackedLayout::heightForWidth(int width) const -
319{ -
320 const int n = count(); -
321 -
322 int hfw = 0; -
323 for (int i = 0; i < n; ++i) {
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:47
yes
Evaluation Count:44
44-47
324 if (QLayoutItem *item = itemAt(i)) {
partially evaluated: QLayoutItem *item = itemAt(i)
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
325 if (QWidget *w = item->widget())
partially evaluated: QWidget *w = item->widget()
TRUEFALSE
yes
Evaluation Count:47
no
Evaluation Count:0
0-47
326 -
327 -
328 -
329 -
330 -
331 -
332 hfw = qMax(hfw, w->heightForWidth(width));
executed: hfw = qMax(hfw, w->heightForWidth(width));
Execution Count:47
47
333 }
executed: }
Execution Count:47
47
334 }
executed: }
Execution Count:47
47
335 hfw = qMax(hfw, minimumSize().height()); -
336 return hfw;
executed: return hfw;
Execution Count:44
44
337} -
338QStackedLayout::StackingMode QStackedLayout::stackingMode() const -
339{ -
340 const QStackedLayoutPrivate * const d = d_func(); -
341 return d->stackingMode;
never executed: return d->stackingMode;
0
342} -
343 -
344void QStackedLayout::setStackingMode(StackingMode stackingMode) -
345{ -
346 QStackedLayoutPrivate * const d = d_func(); -
347 if (d->stackingMode == stackingMode)
never evaluated: d->stackingMode == stackingMode
0
348 return;
never executed: return;
0
349 d->stackingMode = stackingMode; -
350 -
351 const int n = d->list.count(); -
352 if (n == 0)
never evaluated: n == 0
0
353 return;
never executed: return;
0
354 -
355 switch (d->stackingMode) { -
356 case StackOne: -
357 if (const int idx = currentIndex())
never evaluated: const int idx = currentIndex()
0
358 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
359 if (QWidget *widget = d->list.at(i)->widget())
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
360 widget->setVisible(i == idx);
never executed: widget->setVisible(i == idx);
0
361 break;
never executed: break;
0
362 case StackAll: { -
363 QRect geometry; -
364 if (const QWidget *widget = currentWidget())
never evaluated: const QWidget *widget = currentWidget()
0
365 geometry = widget->geometry();
never executed: geometry = widget->geometry();
0
366 for (int i = 0; i < n; ++i)
never evaluated: i < n
0
367 if (QWidget *widget = d->list.at(i)->widget()) {
never evaluated: QWidget *widget = d->list.at(i)->widget()
0
368 if (!geometry.isNull())
never evaluated: !geometry.isNull()
0
369 widget->setGeometry(geometry);
never executed: widget->setGeometry(geometry);
0
370 widget->setVisible(true); -
371 }
never executed: }
0
372 } -
373 break;
never executed: break;
0
374 } -
375}
never executed: }
0
376 -
377 -
378 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial