qstackedlayout.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9