| Line | Source Code | Coverage |
|---|
| 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 "qstackedlayout.h" | - |
| 43 | #include "qlayout_p.h" | - |
| 44 | | - |
| 45 | #include <qlist.h> | - |
| 46 | #include <qwidget.h> | - |
| 47 | #include "private/qlayoutengine_p.h" | - |
| 48 | | - |
| 49 | QT_BEGIN_NAMESPACE | - |
| 50 | | - |
| 51 | class QStackedLayoutPrivate : public QLayoutPrivate | - |
| 52 | { | - |
| 53 | Q_DECLARE_PUBLIC(QStackedLayout) | - |
| 54 | public: | - |
| 55 | QStackedLayoutPrivate() : index(-1), stackingMode(QStackedLayout::StackOne) {} executed: }Execution Count:238 | 238 |
| 56 | QList<QLayoutItem *> list; | - |
| 57 | int index; | - |
| 58 | QStackedLayout::StackingMode stackingMode; | - |
| 59 | }; | - |
| 60 | | - |
| 61 | /*! | - |
| 62 | \class QStackedLayout | - |
| 63 | | - |
| 64 | \brief The QStackedLayout class provides a stack of widgets where | - |
| 65 | only one widget is visible at a time. | - |
| 66 | | - |
| 67 | \ingroup geomanagement | - |
| 68 | \inmodule QtWidgets | - |
| 69 | | - |
| 70 | QStackedLayout can be used to create a user interface similar to | - |
| 71 | the one provided by QTabWidget. There is also a convenience | - |
| 72 | QStackedWidget class built on top of QStackedLayout. | - |
| 73 | | - |
| 74 | A QStackedLayout can be populated with a number of child widgets | - |
| 75 | ("pages"). For example: | - |
| 76 | | - |
| 77 | \snippet qstackedlayout/main.cpp 0 | - |
| 78 | \codeline | - |
| 79 | \snippet qstackedlayout/main.cpp 2 | - |
| 80 | \snippet qstackedlayout/main.cpp 3 | - |
| 81 | | - |
| 82 | QStackedLayout provides no intrinsic means for the user to switch | - |
| 83 | page. This is typically done through a QComboBox or a QListWidget | - |
| 84 | that stores the titles of the QStackedLayout's pages. For | - |
| 85 | example: | - |
| 86 | | - |
| 87 | \snippet qstackedlayout/main.cpp 1 | - |
| 88 | | - |
| 89 | When populating a layout, the widgets are added to an internal | - |
| 90 | list. The indexOf() function returns the index of a widget in that | - |
| 91 | list. The widgets can either be added to the end of the list using | - |
| 92 | the addWidget() function, or inserted at a given index using the | - |
| 93 | insertWidget() function. The removeWidget() function removes the | - |
| 94 | widget at the given index from the layout. The number of widgets | - |
| 95 | contained in the layout, can be obtained using the count() | - |
| 96 | function. | - |
| 97 | | - |
| 98 | The widget() function returns the widget at a given index | - |
| 99 | position. The index of the widget that is shown on screen is given | - |
| 100 | by currentIndex() and can be changed using setCurrentIndex(). In a | - |
| 101 | similar manner, the currently shown widget can be retrieved using | - |
| 102 | the currentWidget() function, and altered using the | - |
| 103 | setCurrentWidget() function. | - |
| 104 | | - |
| 105 | Whenever the current widget in the layout changes or a widget is | - |
| 106 | removed from the layout, the currentChanged() and widgetRemoved() | - |
| 107 | signals are emitted respectively. | - |
| 108 | | - |
| 109 | \sa QStackedWidget, QTabWidget | - |
| 110 | */ | - |
| 111 | | - |
| 112 | /*! | - |
| 113 | \fn void QStackedLayout::currentChanged(int index) | - |
| 114 | | - |
| 115 | This signal is emitted whenever the current widget in the layout | - |
| 116 | changes. The \a index specifies the index of the new current | - |
| 117 | widget, or -1 if there isn't a new one (for example, if there | - |
| 118 | are no widgets in the QStackedLayout) | - |
| 119 | | - |
| 120 | \sa currentWidget(), setCurrentWidget() | - |
| 121 | */ | - |
| 122 | | - |
| 123 | /*! | - |
| 124 | \fn void QStackedLayout::widgetRemoved(int index) | - |
| 125 | | - |
| 126 | This signal is emitted whenever a widget is removed from the | - |
| 127 | layout. The widget's \a index is passed as parameter. | - |
| 128 | | - |
| 129 | \sa removeWidget() | - |
| 130 | */ | - |
| 131 | | - |
| 132 | /*! | - |
| 133 | \fn QWidget *QStackedLayout::widget() | - |
| 134 | \internal | - |
| 135 | */ | - |
| 136 | | - |
| 137 | /*! | - |
| 138 | Constructs a QStackedLayout with no parent. | - |
| 139 | | - |
| 140 | This QStackedLayout must be installed on a widget later on to | - |
| 141 | become effective. | - |
| 142 | | - |
| 143 | \sa addWidget(), insertWidget() | - |
| 144 | */ | - |
| 145 | QStackedLayout::QStackedLayout() | - |
| 146 | : QLayout(*new QStackedLayoutPrivate, 0, 0) | - |
| 147 | { | - |
| 148 | } executed: }Execution Count:2 | 2 |
| 149 | | - |
| 150 | /*! | - |
| 151 | Constructs a new QStackedLayout with the given \a parent. | - |
| 152 | | - |
| 153 | This layout will install itself on the \a parent widget and | - |
| 154 | manage the geometry of its children. | - |
| 155 | */ | - |
| 156 | QStackedLayout::QStackedLayout(QWidget *parent) | - |
| 157 | : QLayout(*new QStackedLayoutPrivate, 0, parent) | - |
| 158 | { | - |
| 159 | } executed: }Execution Count:236 | 236 |
| 160 | | - |
| 161 | /*! | - |
| 162 | Constructs a new QStackedLayout and inserts it into | - |
| 163 | the given \a parentLayout. | - |
| 164 | */ | - |
| 165 | QStackedLayout::QStackedLayout(QLayout *parentLayout) | - |
| 166 | : QLayout(*new QStackedLayoutPrivate, parentLayout, 0) | - |
| 167 | { | - |
| 168 | } | 0 |
| 169 | | - |
| 170 | /*! | - |
| 171 | Destroys this QStackedLayout. Note that the layout's widgets are | - |
| 172 | \e not destroyed. | - |
| 173 | */ | - |
| 174 | QStackedLayout::~QStackedLayout() | - |
| 175 | { | - |
| 176 | Q_D(QStackedLayout); executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func(); | - |
| 177 | qDeleteAll(d->list); executed (the execution status of this line is deduced): qDeleteAll(d->list); | - |
| 178 | } executed: }Execution Count:234 | 234 |
| 179 | | - |
| 180 | /*! | - |
| 181 | Adds the given \a widget to the end of this layout and returns the | - |
| 182 | index position of the \a widget. | - |
| 183 | | - |
| 184 | If the QStackedLayout is empty before this function is called, | - |
| 185 | the given \a widget becomes the current widget. | - |
| 186 | | - |
| 187 | \sa insertWidget(), removeWidget(), setCurrentWidget() | - |
| 188 | */ | - |
| 189 | int QStackedLayout::addWidget(QWidget *widget) | - |
| 190 | { | - |
| 191 | Q_D(QStackedLayout); executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func(); | - |
| 192 | return insertWidget(d->list.count(), widget); executed: return insertWidget(d->list.count(), widget);Execution Count:397 | 397 |
| 193 | } | - |
| 194 | | - |
| 195 | /*! | - |
| 196 | Inserts the given \a widget at the given \a index in this | - |
| 197 | QStackedLayout. If \a index is out of range, the widget is | - |
| 198 | appended (in which case it is the actual index of the \a widget | - |
| 199 | that is returned). | - |
| 200 | | - |
| 201 | If the QStackedLayout is empty before this function is called, the | - |
| 202 | given \a widget becomes the current widget. | - |
| 203 | | - |
| 204 | Inserting a new widget at an index less than or equal to the current index | - |
| 205 | will increment the current index, but keep the current widget. | - |
| 206 | | - |
| 207 | \sa addWidget(), removeWidget(), setCurrentWidget() | - |
| 208 | */ | - |
| 209 | int QStackedLayout::insertWidget(int index, QWidget *widget) | - |
| 210 | { | - |
| 211 | Q_D(QStackedLayout); executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func(); | - |
| 212 | addChildWidget(widget); executed (the execution status of this line is deduced): addChildWidget(widget); | - |
| 213 | index = qMin(index, d->list.count()); executed (the execution status of this line is deduced): index = qMin(index, d->list.count()); | - |
| 214 | if (index < 0) evaluated: index < 0| yes Evaluation Count:53 | yes Evaluation Count:398 |
| 53-398 |
| 215 | index = d->list.count(); executed: index = d->list.count();Execution Count:53 | 53 |
| 216 | QWidgetItem *wi = QLayoutPrivate::createWidgetItem(this, widget); executed (the execution status of this line is deduced): QWidgetItem *wi = QLayoutPrivate::createWidgetItem(this, widget); | - |
| 217 | d->list.insert(index, wi); executed (the execution status of this line is deduced): d->list.insert(index, wi); | - |
| 218 | invalidate(); executed (the execution status of this line is deduced): invalidate(); | - |
| 219 | if (d->index < 0) { evaluated: d->index < 0| yes Evaluation Count:228 | yes Evaluation Count:223 |
| 223-228 |
| 220 | setCurrentIndex(index); executed (the execution status of this line is deduced): setCurrentIndex(index); | - |
| 221 | } else { executed: }Execution Count:228 | 228 |
| 222 | if (index <= d->index) evaluated: index <= d->index| yes Evaluation Count:1 | yes Evaluation Count:222 |
| 1-222 |
| 223 | ++d->index; executed: ++d->index;Execution Count:1 | 1 |
| 224 | if (d->stackingMode == StackOne) partially evaluated: d->stackingMode == StackOne| yes Evaluation Count:223 | no Evaluation Count:0 |
| 0-223 |
| 225 | widget->hide(); executed: widget->hide();Execution Count:223 | 223 |
| 226 | widget->lower(); executed (the execution status of this line is deduced): widget->lower(); | - |
| 227 | } executed: }Execution Count:223 | 223 |
| 228 | return index; executed: return index;Execution Count:451 | 451 |
| 229 | } | - |
| 230 | | - |
| 231 | /*! | - |
| 232 | \reimp | - |
| 233 | */ | - |
| 234 | QLayoutItem *QStackedLayout::itemAt(int index) const | - |
| 235 | { | - |
| 236 | Q_D(const QStackedLayout); executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func(); | - |
| 237 | return d->list.value(index); executed: return d->list.value(index);Execution Count:2103 | 2103 |
| 238 | } | - |
| 239 | | - |
| 240 | // Code that enables proper handling of the case that takeAt() is | - |
| 241 | // called somewhere inside QObject destructor (can't call hide() | - |
| 242 | // on the object then) | - |
| 243 | | - |
| 244 | class QtFriendlyLayoutWidget : public QWidget | - |
| 245 | { | - |
| 246 | public: | - |
| 247 | inline bool wasDeleted() const { return d_ptr->wasDeleted; } executed: return d_ptr->wasDeleted;Execution Count:33 | 33 |
| 248 | }; | - |
| 249 | | - |
| 250 | static 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 |
| 251 | | - |
| 252 | | - |
| 253 | /*! | - |
| 254 | \reimp | - |
| 255 | */ | - |
| 256 | QLayoutItem *QStackedLayout::takeAt(int index) | - |
| 257 | { | - |
| 258 | Q_D(QStackedLayout); executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func(); | - |
| 259 | if (index <0 || index >= d->list.size()) partially evaluated: index <0| no Evaluation Count:0 | yes Evaluation Count:33 |
partially evaluated: index >= d->list.size()| no Evaluation Count:0 | yes Evaluation Count:33 |
| 0-33 |
| 260 | return 0; never executed: return 0; | 0 |
| 261 | QLayoutItem *item = d->list.takeAt(index); executed (the execution status of this line is deduced): QLayoutItem *item = d->list.takeAt(index); | - |
| 262 | if (index == d->index) { evaluated: index == d->index| yes Evaluation Count:25 | yes Evaluation Count:8 |
| 8-25 |
| 263 | d->index = -1; executed (the execution status of this line is deduced): d->index = -1; | - |
| 264 | if ( d->list.count() > 0 ) { evaluated: d->list.count() > 0| yes Evaluation Count:9 | yes Evaluation Count:16 |
| 9-16 |
| 265 | int newIndex = (index == d->list.count()) ? index-1 : index; evaluated: (index == d->list.count())| yes Evaluation Count:4 | yes Evaluation Count:5 |
| 4-5 |
| 266 | setCurrentIndex(newIndex); executed (the execution status of this line is deduced): setCurrentIndex(newIndex); | - |
| 267 | } else { executed: }Execution Count:9 | 9 |
| 268 | emit currentChanged(-1); executed (the execution status of this line is deduced): currentChanged(-1); | - |
| 269 | } executed: }Execution Count:16 | 16 |
| 270 | } else if (index < d->index) { evaluated: index < d->index| yes Evaluation Count:7 | yes Evaluation Count:1 |
| 1-7 |
| 271 | --d->index; executed (the execution status of this line is deduced): --d->index; | - |
| 272 | } executed: }Execution Count:7 | 7 |
| 273 | emit widgetRemoved(index); executed (the execution status of this line is deduced): widgetRemoved(index); | - |
| 274 | if (item->widget() && !qt_wasDeleted(item->widget())) partially evaluated: item->widget()| yes Evaluation Count:33 | no Evaluation Count:0 |
evaluated: !qt_wasDeleted(item->widget())| yes Evaluation Count:28 | yes Evaluation Count:5 |
| 0-33 |
| 275 | item->widget()->hide(); executed: item->widget()->hide();Execution Count:28 | 28 |
| 276 | return item; executed: return item;Execution Count:33 | 33 |
| 277 | } | - |
| 278 | | - |
| 279 | /*! | - |
| 280 | \property QStackedLayout::currentIndex | - |
| 281 | \brief the index position of the widget that is visible | - |
| 282 | | - |
| 283 | The current index is -1 if there is no current widget. | - |
| 284 | | - |
| 285 | \sa currentWidget(), indexOf() | - |
| 286 | */ | - |
| 287 | void QStackedLayout::setCurrentIndex(int index) | - |
| 288 | { | - |
| 289 | Q_D(QStackedLayout); executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func(); | - |
| 290 | QWidget *prev = currentWidget(); executed (the execution status of this line is deduced): QWidget *prev = currentWidget(); | - |
| 291 | QWidget *next = widget(index); executed (the execution status of this line is deduced): QWidget *next = widget(index); | - |
| 292 | if (!next || next == prev) evaluated: !next| yes Evaluation Count:6 | yes Evaluation Count:635 |
evaluated: next == prev| yes Evaluation Count:355 | yes Evaluation Count:280 |
| 6-635 |
| 293 | return; executed: return;Execution Count:361 | 361 |
| 294 | | - |
| 295 | bool reenableUpdates = false; executed (the execution status of this line is deduced): bool reenableUpdates = false; | - |
| 296 | QWidget *parent = parentWidget(); executed (the execution status of this line is deduced): QWidget *parent = parentWidget(); | - |
| 297 | | - |
| 298 | if (parent && parent->updatesEnabled()) { evaluated: parent| yes Evaluation Count:278 | yes Evaluation Count:2 |
partially evaluated: parent->updatesEnabled()| yes Evaluation Count:278 | no Evaluation Count:0 |
| 0-278 |
| 299 | reenableUpdates = true; executed (the execution status of this line is deduced): reenableUpdates = true; | - |
| 300 | parent->setUpdatesEnabled(false); executed (the execution status of this line is deduced): parent->setUpdatesEnabled(false); | - |
| 301 | } executed: }Execution Count:278 | 278 |
| 302 | | - |
| 303 | QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0; evaluated: parent| yes Evaluation Count:278 | yes Evaluation Count:2 |
| 2-278 |
| 304 | const bool focusWasOnOldPage = fw && (prev && prev->isAncestorOf(fw)); evaluated: fw| yes Evaluation Count:24 | yes Evaluation Count:256 |
evaluated: prev| yes Evaluation Count:23 | yes Evaluation Count:1 |
evaluated: prev->isAncestorOf(fw)| yes Evaluation Count:7 | yes Evaluation Count:16 |
| 1-256 |
| 305 | | - |
| 306 | if (prev) { evaluated: prev| yes Evaluation Count:43 | yes Evaluation Count:237 |
| 43-237 |
| 307 | prev->clearFocus(); executed (the execution status of this line is deduced): prev->clearFocus(); | - |
| 308 | if (d->stackingMode == StackOne) partially evaluated: d->stackingMode == StackOne| yes Evaluation Count:43 | no Evaluation Count:0 |
| 0-43 |
| 309 | prev->hide(); executed: prev->hide();Execution Count:43 | 43 |
| 310 | } executed: }Execution Count:43 | 43 |
| 311 | | - |
| 312 | d->index = index; executed (the execution status of this line is deduced): d->index = index; | - |
| 313 | next->raise(); executed (the execution status of this line is deduced): next->raise(); | - |
| 314 | next->show(); executed (the execution status of this line is deduced): next->show(); | - |
| 315 | | - |
| 316 | // try to move focus onto the incoming widget if focus | - |
| 317 | // was somewhere on the outgoing widget. | - |
| 318 | | - |
| 319 | if (parent) { evaluated: parent| yes Evaluation Count:278 | yes Evaluation Count:2 |
| 2-278 |
| 320 | if (focusWasOnOldPage) { evaluated: focusWasOnOldPage| yes Evaluation Count:7 | yes Evaluation Count:271 |
| 7-271 |
| 321 | // look for the best focus widget we can find | - |
| 322 | if (QWidget *nfw = next->focusWidget()) evaluated: QWidget *nfw = next->focusWidget()| yes Evaluation Count:3 | yes Evaluation Count:4 |
| 3-4 |
| 323 | nfw->setFocus(); executed: nfw->setFocus();Execution Count:3 | 3 |
| 324 | else { | - |
| 325 | // second best: first child widget in the focus chain | - |
| 326 | if (QWidget *i = fw) { partially evaluated: QWidget *i = fw| yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
| 327 | while ((i = i->nextInFocusChain()) != fw) { evaluated: (i = i->nextInFocusChain()) != fw| yes Evaluation Count:51 | yes Evaluation Count:1 |
| 1-51 |
| 328 | if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus) evaluated: ((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus)| yes Evaluation Count:16 | yes Evaluation Count:35 |
| 16-35 |
| 329 | && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled() evaluated: !i->focusProxy()| yes Evaluation Count:14 | yes Evaluation Count:2 |
evaluated: i->isVisibleTo(next)| yes Evaluation Count:5 | yes Evaluation Count:9 |
partially evaluated: i->isEnabled()| yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-14 |
| 330 | && next->isAncestorOf(i)) { evaluated: next->isAncestorOf(i)| yes Evaluation Count:3 | yes Evaluation Count:2 |
| 2-3 |
| 331 | i->setFocus(); executed (the execution status of this line is deduced): i->setFocus(); | - |
| 332 | break; executed: break;Execution Count:3 | 3 |
| 333 | } | - |
| 334 | } executed: }Execution Count:48 | 48 |
| 335 | // third best: incoming widget | - |
| 336 | if (i == fw ) evaluated: i == fw| yes Evaluation Count:1 | yes Evaluation Count:3 |
| 1-3 |
| 337 | next->setFocus(); executed: next->setFocus();Execution Count:1 | 1 |
| 338 | } executed: }Execution Count:4 | 4 |
| 339 | } executed: }Execution Count:4 | 4 |
| 340 | } | - |
| 341 | } executed: }Execution Count:278 | 278 |
| 342 | if (reenableUpdates) evaluated: reenableUpdates| yes Evaluation Count:278 | yes Evaluation Count:2 |
| 2-278 |
| 343 | parent->setUpdatesEnabled(true); executed: parent->setUpdatesEnabled(true);Execution Count:278 | 278 |
| 344 | emit currentChanged(index); executed (the execution status of this line is deduced): currentChanged(index); | - |
| 345 | } executed: }Execution Count:280 | 280 |
| 346 | | - |
| 347 | int QStackedLayout::currentIndex() const | - |
| 348 | { | - |
| 349 | Q_D(const QStackedLayout); executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func(); | - |
| 350 | return d->index; executed: return d->index;Execution Count:19 | 19 |
| 351 | } | - |
| 352 | | - |
| 353 | | - |
| 354 | /*! | - |
| 355 | \fn void QStackedLayout::setCurrentWidget(QWidget *widget) | - |
| 356 | | - |
| 357 | Sets the current widget to be the specified \a widget. The new | - |
| 358 | current widget must already be contained in this stacked layout. | - |
| 359 | | - |
| 360 | \sa setCurrentIndex(), currentWidget() | - |
| 361 | */ | - |
| 362 | void QStackedLayout::setCurrentWidget(QWidget *widget) | - |
| 363 | { | - |
| 364 | int index = indexOf(widget); executed (the execution status of this line is deduced): int index = indexOf(widget); | - |
| 365 | if (index == -1) { evaluated: index == -1| yes Evaluation Count:1 | yes Evaluation Count:132 |
| 1-132 |
| 366 | qWarning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget); executed (the execution status of this line is deduced): QMessageLogger("kernel/qstackedlayout.cpp", 366, __PRETTY_FUNCTION__).warning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget); | - |
| 367 | return; executed: return;Execution Count:1 | 1 |
| 368 | } | - |
| 369 | setCurrentIndex(index); executed (the execution status of this line is deduced): setCurrentIndex(index); | - |
| 370 | } executed: }Execution Count:132 | 132 |
| 371 | | - |
| 372 | | - |
| 373 | /*! | - |
| 374 | Returns the current widget, or 0 if there are no widgets in this | - |
| 375 | layout. | - |
| 376 | | - |
| 377 | \sa currentIndex(), setCurrentWidget() | - |
| 378 | */ | - |
| 379 | QWidget *QStackedLayout::currentWidget() const | - |
| 380 | { | - |
| 381 | Q_D(const QStackedLayout); executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func(); | - |
| 382 | 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 |
| 383 | } | - |
| 384 | | - |
| 385 | /*! | - |
| 386 | Returns the widget at the given \a index, or 0 if there is no | - |
| 387 | widget at the given position. | - |
| 388 | | - |
| 389 | \sa currentWidget(), indexOf() | - |
| 390 | */ | - |
| 391 | QWidget *QStackedLayout::widget(int index) const | - |
| 392 | { | - |
| 393 | Q_D(const QStackedLayout); executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func(); | - |
| 394 | if (index < 0 || index >= d->list.size()) evaluated: index < 0| yes Evaluation Count:5 | yes Evaluation Count:689 |
evaluated: index >= d->list.size()| yes Evaluation Count:4 | yes Evaluation Count:685 |
| 4-689 |
| 395 | return 0; executed: return 0;Execution Count:9 | 9 |
| 396 | return d->list.at(index)->widget(); executed: return d->list.at(index)->widget();Execution Count:685 | 685 |
| 397 | } | - |
| 398 | | - |
| 399 | /*! | - |
| 400 | \property QStackedLayout::count | - |
| 401 | \brief the number of widgets contained in the layout | - |
| 402 | | - |
| 403 | \sa currentIndex(), widget() | - |
| 404 | */ | - |
| 405 | int QStackedLayout::count() const | - |
| 406 | { | - |
| 407 | Q_D(const QStackedLayout); executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func(); | - |
| 408 | return d->list.size(); executed: return d->list.size();Execution Count:866 | 866 |
| 409 | } | - |
| 410 | | - |
| 411 | | - |
| 412 | /*! | - |
| 413 | \reimp | - |
| 414 | */ | - |
| 415 | void QStackedLayout::addItem(QLayoutItem *item) | - |
| 416 | { | - |
| 417 | QWidget *widget = item->widget(); never executed (the execution status of this line is deduced): QWidget *widget = item->widget(); | - |
| 418 | if (widget) { | 0 |
| 419 | addWidget(widget); never executed (the execution status of this line is deduced): addWidget(widget); | - |
| 420 | delete item; never executed (the execution status of this line is deduced): delete item; | - |
| 421 | } else { | 0 |
| 422 | qWarning("QStackedLayout::addItem: Only widgets can be added"); never executed (the execution status of this line is deduced): QMessageLogger("kernel/qstackedlayout.cpp", 422, __PRETTY_FUNCTION__).warning("QStackedLayout::addItem: Only widgets can be added"); | - |
| 423 | } | 0 |
| 424 | } | - |
| 425 | | - |
| 426 | /*! | - |
| 427 | \reimp | - |
| 428 | */ | - |
| 429 | QSize QStackedLayout::sizeHint() const | - |
| 430 | { | - |
| 431 | Q_D(const QStackedLayout); executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func(); | - |
| 432 | QSize s(0, 0); executed (the execution status of this line is deduced): QSize s(0, 0); | - |
| 433 | int n = d->list.count(); executed (the execution status of this line is deduced): int n = d->list.count(); | - |
| 434 | | - |
| 435 | for (int i = 0; i < n; ++i) evaluated: i < n| yes Evaluation Count:542 | yes Evaluation Count:295 |
| 295-542 |
| 436 | if (QWidget *widget = d->list.at(i)->widget()) { partially evaluated: QWidget *widget = d->list.at(i)->widget()| yes Evaluation Count:542 | no Evaluation Count:0 |
| 0-542 |
| 437 | QSize ws(widget->sizeHint()); executed (the execution status of this line is deduced): QSize ws(widget->sizeHint()); | - |
| 438 | if (widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored) partially evaluated: widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored| no Evaluation Count:0 | yes Evaluation Count:542 |
| 0-542 |
| 439 | ws.setWidth(0); never executed: ws.setWidth(0); | 0 |
| 440 | if (widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored) partially evaluated: widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored| no Evaluation Count:0 | yes Evaluation Count:542 |
| 0-542 |
| 441 | ws.setHeight(0); never executed: ws.setHeight(0); | 0 |
| 442 | s = s.expandedTo(ws); executed (the execution status of this line is deduced): s = s.expandedTo(ws); | - |
| 443 | } executed: }Execution Count:542 | 542 |
| 444 | return s; executed: return s;Execution Count:295 | 295 |
| 445 | } | - |
| 446 | | - |
| 447 | /*! | - |
| 448 | \reimp | - |
| 449 | */ | - |
| 450 | QSize QStackedLayout::minimumSize() const | - |
| 451 | { | - |
| 452 | Q_D(const QStackedLayout); executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func(); | - |
| 453 | QSize s(0, 0); executed (the execution status of this line is deduced): QSize s(0, 0); | - |
| 454 | int n = d->list.count(); executed (the execution status of this line is deduced): int n = d->list.count(); | - |
| 455 | | - |
| 456 | for (int i = 0; i < n; ++i) evaluated: i < n| yes Evaluation Count:607 | yes Evaluation Count:342 |
| 342-607 |
| 457 | if (QWidget *widget = d->list.at(i)->widget()) partially evaluated: QWidget *widget = d->list.at(i)->widget()| yes Evaluation Count:607 | no Evaluation Count:0 |
| 0-607 |
| 458 | s = s.expandedTo(qSmartMinSize(widget)); executed: s = s.expandedTo(qSmartMinSize(widget));Execution Count:607 | 607 |
| 459 | return s; executed: return s;Execution Count:342 | 342 |
| 460 | } | - |
| 461 | | - |
| 462 | /*! | - |
| 463 | \reimp | - |
| 464 | */ | - |
| 465 | void QStackedLayout::setGeometry(const QRect &rect) | - |
| 466 | { | - |
| 467 | Q_D(QStackedLayout); executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func(); | - |
| 468 | switch (d->stackingMode) { | - |
| 469 | case StackOne: | - |
| 470 | if (QWidget *widget = currentWidget()) evaluated: QWidget *widget = currentWidget()| yes Evaluation Count:180 | yes Evaluation Count:12 |
| 12-180 |
| 471 | widget->setGeometry(rect); executed: widget->setGeometry(rect);Execution Count:180 | 180 |
| 472 | break; executed: break;Execution Count:192 | 192 |
| 473 | case StackAll: | - |
| 474 | if (const int n = d->list.count()) never evaluated: const int n = d->list.count() | 0 |
| 475 | for (int i = 0; i < n; ++i) | 0 |
| 476 | if (QWidget *widget = d->list.at(i)->widget()) never evaluated: QWidget *widget = d->list.at(i)->widget() | 0 |
| 477 | widget->setGeometry(rect); never executed: widget->setGeometry(rect); | 0 |
| 478 | break; | 0 |
| 479 | } | - |
| 480 | } executed: }Execution Count:192 | 192 |
| 481 | | - |
| 482 | /*! | - |
| 483 | \reimp | - |
| 484 | */ | - |
| 485 | bool QStackedLayout::hasHeightForWidth() const | - |
| 486 | { | - |
| 487 | const int n = count(); executed (the execution status of this line is deduced): const int n = count(); | - |
| 488 | | - |
| 489 | for (int i = 0; i < n; ++i) { evaluated: i < n| yes Evaluation Count:1309 | yes Evaluation Count:629 |
| 629-1309 |
| 490 | if (QLayoutItem *item = itemAt(i)) { partially evaluated: QLayoutItem *item = itemAt(i)| yes Evaluation Count:1309 | no Evaluation Count:0 |
| 0-1309 |
| 491 | if (item->hasHeightForWidth()) evaluated: item->hasHeightForWidth()| yes Evaluation Count:102 | yes Evaluation Count:1207 |
| 102-1207 |
| 492 | return true; executed: return true;Execution Count:102 | 102 |
| 493 | } executed: }Execution Count:1207 | 1207 |
| 494 | } executed: }Execution Count:1207 | 1207 |
| 495 | return false; executed: return false;Execution Count:629 | 629 |
| 496 | } | - |
| 497 | | - |
| 498 | /*! | - |
| 499 | \reimp | - |
| 500 | */ | - |
| 501 | int QStackedLayout::heightForWidth(int width) const | - |
| 502 | { | - |
| 503 | const int n = count(); executed (the execution status of this line is deduced): const int n = count(); | - |
| 504 | | - |
| 505 | int hfw = 0; executed (the execution status of this line is deduced): int hfw = 0; | - |
| 506 | for (int i = 0; i < n; ++i) { evaluated: i < n| yes Evaluation Count:47 | yes Evaluation Count:44 |
| 44-47 |
| 507 | if (QLayoutItem *item = itemAt(i)) { partially evaluated: QLayoutItem *item = itemAt(i)| yes Evaluation Count:47 | no Evaluation Count:0 |
| 0-47 |
| 508 | if (QWidget *w = item->widget()) partially evaluated: QWidget *w = item->widget()| yes Evaluation Count:47 | no Evaluation Count:0 |
| 0-47 |
| 509 | /* | - |
| 510 | Note: Does not query the layout item, but bypasses it and asks the widget | - |
| 511 | directly. This is consistent with how QStackedLayout::sizeHint() is | - |
| 512 | implemented. This also avoids an issue where QWidgetItem::heightForWidth() | - |
| 513 | returns -1 if the widget is hidden. | - |
| 514 | */ | - |
| 515 | hfw = qMax(hfw, w->heightForWidth(width)); executed: hfw = qMax(hfw, w->heightForWidth(width));Execution Count:47 | 47 |
| 516 | } executed: }Execution Count:47 | 47 |
| 517 | } executed: }Execution Count:47 | 47 |
| 518 | hfw = qMax(hfw, minimumSize().height()); executed (the execution status of this line is deduced): hfw = qMax(hfw, minimumSize().height()); | - |
| 519 | return hfw; executed: return hfw;Execution Count:44 | 44 |
| 520 | } | - |
| 521 | | - |
| 522 | /*! | - |
| 523 | \enum QStackedLayout::StackingMode | - |
| 524 | \since 4.4 | - |
| 525 | | - |
| 526 | This enum specifies how the layout handles its child widgets | - |
| 527 | regarding their visibility. | - |
| 528 | | - |
| 529 | \value StackOne | - |
| 530 | Only the current widget is visible. This is the default. | - |
| 531 | | - |
| 532 | \value StackAll | - |
| 533 | All widgets are visible. The current widget is merely raised. | - |
| 534 | */ | - |
| 535 | | - |
| 536 | | - |
| 537 | /*! | - |
| 538 | \property QStackedLayout::stackingMode | - |
| 539 | \brief determines the way visibility of child widgets are handled. | - |
| 540 | \since 4.4 | - |
| 541 | | - |
| 542 | The default value is StackOne. Setting the property to StackAll | - |
| 543 | allows you to make use of the layout for overlay widgets | - |
| 544 | that do additional drawing on top of other widgets, for example, | - |
| 545 | graphical editors. | - |
| 546 | */ | - |
| 547 | | - |
| 548 | QStackedLayout::StackingMode QStackedLayout::stackingMode() const | - |
| 549 | { | - |
| 550 | Q_D(const QStackedLayout); never executed (the execution status of this line is deduced): const QStackedLayoutPrivate * const d = d_func(); | - |
| 551 | return d->stackingMode; never executed: return d->stackingMode; | 0 |
| 552 | } | - |
| 553 | | - |
| 554 | void QStackedLayout::setStackingMode(StackingMode stackingMode) | - |
| 555 | { | - |
| 556 | Q_D(QStackedLayout); never executed (the execution status of this line is deduced): QStackedLayoutPrivate * const d = d_func(); | - |
| 557 | if (d->stackingMode == stackingMode) never evaluated: d->stackingMode == stackingMode | 0 |
| 558 | return; | 0 |
| 559 | d->stackingMode = stackingMode; never executed (the execution status of this line is deduced): d->stackingMode = stackingMode; | - |
| 560 | | - |
| 561 | const int n = d->list.count(); never executed (the execution status of this line is deduced): const int n = d->list.count(); | - |
| 562 | if (n == 0) | 0 |
| 563 | return; | 0 |
| 564 | | - |
| 565 | switch (d->stackingMode) { | - |
| 566 | case StackOne: | - |
| 567 | if (const int idx = currentIndex()) never evaluated: const int idx = currentIndex() | 0 |
| 568 | for (int i = 0; i < n; ++i) | 0 |
| 569 | if (QWidget *widget = d->list.at(i)->widget()) never evaluated: QWidget *widget = d->list.at(i)->widget() | 0 |
| 570 | widget->setVisible(i == idx); never executed: widget->setVisible(i == idx); | 0 |
| 571 | break; | 0 |
| 572 | case StackAll: { // Turn overlay on: Make sure all widgets are the same size | - |
| 573 | QRect geometry; never executed (the execution status of this line is deduced): QRect geometry; | - |
| 574 | if (const QWidget *widget = currentWidget()) never evaluated: const QWidget *widget = currentWidget() | 0 |
| 575 | geometry = widget->geometry(); never executed: geometry = widget->geometry(); | 0 |
| 576 | for (int i = 0; i < n; ++i) | 0 |
| 577 | if (QWidget *widget = d->list.at(i)->widget()) { never evaluated: QWidget *widget = d->list.at(i)->widget() | 0 |
| 578 | if (!geometry.isNull()) never evaluated: !geometry.isNull() | 0 |
| 579 | widget->setGeometry(geometry); never executed: widget->setGeometry(geometry); | 0 |
| 580 | widget->setVisible(true); never executed (the execution status of this line is deduced): widget->setVisible(true); | - |
| 581 | } | 0 |
| 582 | } | - |
| 583 | break; | 0 |
| 584 | } | - |
| 585 | } | 0 |
| 586 | | - |
| 587 | QT_END_NAMESPACE | - |
| 588 | | - |
| | |