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