Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickstackview.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickstackview_p.h"
7#if QT_CONFIG(quick_viewtransitions)
9#endif
10
11#include <QtCore/qscopedvaluerollback.h>
12#include <QtQml/qjsvalue.h>
13#include <QtQml/qqmlengine.h>
14#include <QtQml/qqmlinfo.h>
15
16#include <private/qv4qobjectwrapper_p.h>
17#include <private/qqmlengine_p.h>
18
20
25
30
35
40
41#ifndef QT_NO_DEBUG_STREAM
43{
45 debug.nospace() << "QQuickStackViewArg("
46 << "mItem=" << arg.mItem
47 << " mComponent=" << arg.mComponent
48 << " mUrl=" << arg.mUrl
49 << ")";
50 return debug;
51}
52#endif
53
58
391
393{
394 Q_D(QQuickStackView);
395#if QT_CONFIG(quick_viewtransitions)
396 if (d->transitioner) {
397 d->transitioner->setChangeListener(nullptr);
398 delete d->transitioner;
399 }
400#endif
401 qDeleteAll(d->removing);
402 qDeleteAll(d->removed);
403 qDeleteAll(d->elements);
404}
405
410
417{
418 Q_D(const QQuickStackView);
419 return d->busy;
420}
421
428{
429 Q_D(const QQuickStackView);
430 return d->elements.size();
431}
432
439{
440 Q_D(const QQuickStackView);
441 return d->currentItem;
442}
443
455{
456 Q_D(QQuickStackView);
457 QQuickStackElement *element = d->elements.value(index);
458 if (element) {
459 if (behavior == ForceLoad)
460 element->load(this);
461 return element->item;
462 }
463 return nullptr;
464}
465
484{
485 Q_D(QQuickStackView);
486 QJSValue func(callback);
487 QQmlEngine *engine = qmlEngine(this);
488 if (!engine || !func.isCallable()) // TODO: warning?
489 return nullptr;
490
491 for (int i = d->elements.size() - 1; i >= 0; --i) {
492 QQuickStackElement *element = d->elements.at(i);
493 if (behavior == ForceLoad)
494 element->load(this);
495 if (element->item) {
496 QJSValue rv = func.call(QJSValueList() << engine->newQObject(element->item) << i);
497 if (rv.toBool())
498 return element->item;
499 }
500 }
501
502 return nullptr;
503}
504
571{
572 Q_D(QQuickStackView);
573 const QString operationName = QStringLiteral("push");
574 if (d->modifyingElements) {
575 d->warnOfInterruption(operationName);
576 return;
577 }
578
579 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
580 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
581 if (args->length() <= 0) {
582 d->warn(QStringLiteral("missing arguments"));
583 args->setReturnValue(QV4::Encode::null());
584 return;
585 }
586
587 QV4::ExecutionEngine *v4 = args->v4engine();
588 QV4::Scope scope(v4);
589
590#if QT_CONFIG(quick_viewtransitions)
591 Operation operation = d->elements.isEmpty() ? Immediate : PushTransition;
592 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
593 if (lastArg->isInt32())
594 operation = static_cast<Operation>(lastArg->toInt32());
595#endif
596
597 QStringList errors;
598 QList<QQuickStackElement *> elements = d->parseElements(0, args, &errors);
599 // Remove any items that are already in the stack, as they can't be in two places at once.
600 // not using erase_if, as we have to delete the elements first
601 auto removeIt = std::remove_if(elements.begin(), elements.end(), [&](QQuickStackElement *element) {
602 return element->item && d->findElement(element->item);
603 });
604 for (auto it = removeIt, end = elements.end(); it != end; ++it)
605 delete *it;
606 elements.erase(removeIt, elements.end());
607
608 if (!errors.isEmpty() || elements.isEmpty()) {
609 if (!errors.isEmpty()) {
610 for (const QString &error : std::as_const(errors))
611 d->warn(error);
612 } else {
613 d->warn(QStringLiteral("nothing to push"));
614 }
615 args->setReturnValue(QV4::Encode::null());
616 return;
617 }
618
619#if QT_CONFIG(quick_viewtransitions)
620 QQuickStackElement *exit = nullptr;
621 if (!d->elements.isEmpty())
622 exit = d->elements.top();
623#endif
624
625 int oldDepth = d->elements.size();
626 if (d->pushElements(elements)) {
627 d->depthChange(d->elements.size(), oldDepth);
628 QQuickStackElement *enter = d->elements.top();
629#if QT_CONFIG(quick_viewtransitions)
630 d->startTransition(QQuickStackTransition::pushEnter(operation, enter, this),
633#endif
634 d->setCurrentItem(enter);
635 }
636
637 if (d->currentItem) {
638 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
639 args->setReturnValue(rv->asReturnedValue());
640 } else {
641 args->setReturnValue(QV4::Encode::null());
642 }
643}
644
685{
686 Q_D(QQuickStackView);
687 const QString operationName = QStringLiteral("pop");
688 if (d->modifyingElements) {
689 d->warnOfInterruption(operationName);
690 args->setReturnValue(QV4::Encode::null());
691 return;
692 }
693
694 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
695 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
696 int argc = args->length();
697 if (d->elements.size() <= 1 || argc > 2) {
698 if (argc > 2)
699 d->warn(QStringLiteral("too many arguments"));
700 args->setReturnValue(QV4::Encode::null());
701 return;
702 }
703
704 int oldDepth = d->elements.size();
705 QQuickStackElement *exit = d->elements.pop();
706 QQuickStackElement *enter = d->elements.top();
707
708 QV4::ExecutionEngine *v4 = args->v4engine();
709 QV4::Scope scope(v4);
710
711 if (argc > 0) {
712 QV4::ScopedValue value(scope, (*args)[0]);
713 if (value->isNull()) {
714 enter = d->elements.value(0);
715 } else if (const QV4::QObjectWrapper *o = value->as<QV4::QObjectWrapper>()) {
717 enter = d->findElement(item);
718 if (!enter) {
719 if (item != d->currentItem)
720 d->warn(QStringLiteral("can't find item to pop: ") + value->toQString());
721 args->setReturnValue(QV4::Encode::null());
722 d->elements.push(exit); // restore
723 return;
724 }
725 }
726 }
727
728#if QT_CONFIG(quick_viewtransitions)
730 if (argc > 0) {
731 QV4::ScopedValue lastArg(scope, (*args)[argc - 1]);
732 if (lastArg->isInt32())
733 operation = static_cast<Operation>(lastArg->toInt32());
734 }
735#endif
736
737 QPointer<QQuickItem> previousItem;
738
739 if (d->popElements(enter)) {
740 if (exit) {
741 exit->removal = true;
742 d->removing.insert(exit);
743 previousItem = exit->item;
744 }
745 d->depthChange(d->elements.size(), oldDepth);
746#if QT_CONFIG(quick_viewtransitions)
747 d->startTransition(QQuickStackTransition::popExit(operation, exit, this),
750#endif
751 d->setCurrentItem(enter);
752 }
753
754 if (previousItem) {
755 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, previousItem));
756 args->setReturnValue(rv->asReturnedValue());
757 } else {
758 args->setReturnValue(QV4::Encode::null());
759 }
760}
761
857{
858 Q_D(QQuickStackView);
859 const QString operationName = QStringLiteral("replace");
860 if (d->modifyingElements) {
861 d->warnOfInterruption(operationName);
862 args->setReturnValue(QV4::Encode::null());
863 return;
864 }
865
866 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
867 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
868 if (args->length() <= 0) {
869 d->warn(QStringLiteral("missing arguments"));
870 args->setReturnValue(QV4::Encode::null());
871 return;
872 }
873
874 QV4::ExecutionEngine *v4 = args->v4engine();
875 QV4::Scope scope(v4);
876
877#if QT_CONFIG(quick_viewtransitions)
878 Operation operation = d->elements.isEmpty() ? Immediate : ReplaceTransition;
879 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
880 if (lastArg->isInt32())
881 operation = static_cast<Operation>(lastArg->toInt32());
882#endif
883
884 QQuickStackElement *target = nullptr;
885 QV4::ScopedValue firstArg(scope, (*args)[0]);
886 if (firstArg->isNull())
887 target = d->elements.value(0);
888 else if (!firstArg->isInt32())
889 target = d->findElement(firstArg);
890
891 QStringList errors;
892 QList<QQuickStackElement *> elements = d->parseElements(target ? 1 : 0, args, &errors);
893 if (!errors.isEmpty() || elements.isEmpty()) {
894 if (!errors.isEmpty()) {
895 for (const QString &error : std::as_const(errors))
896 d->warn(error);
897 } else {
898 d->warn(QStringLiteral("nothing to push"));
899 }
900 args->setReturnValue(QV4::Encode::null());
901 return;
902 }
903
904 int oldDepth = d->elements.size();
905 QQuickStackElement* exit = nullptr;
906 if (!d->elements.isEmpty())
907 exit = d->elements.pop();
908
909 if (exit != target ? d->replaceElements(target, elements) : d->pushElements(elements)) {
910 d->depthChange(d->elements.size(), oldDepth);
911 if (exit) {
912 exit->removal = true;
913 d->removing.insert(exit);
914 }
915 QQuickStackElement *enter = d->elements.top();
916#if QT_CONFIG(quick_viewtransitions)
917 d->startTransition(QQuickStackTransition::replaceExit(operation, exit, this),
920#endif
921 d->setCurrentItem(enter);
922 }
923
924 if (d->currentItem) {
925 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
926 args->setReturnValue(rv->asReturnedValue());
927 } else {
928 args->setReturnValue(QV4::Encode::null());
929 }
930}
931
984QQuickItem *QQuickStackView::pushItems(QList<QQuickStackViewArg> args, Operation operation)
985{
986 Q_D(QQuickStackView);
987 const QString operationName = QStringLiteral("pushItem");
988 if (d->modifyingElements) {
989 d->warnOfInterruption(operationName);
990 return nullptr;
991 }
992
993 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
994 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
995
996 const QList<QQuickStackElement *> stackElements = d->parseElements(args);
997
998#if QT_CONFIG(quick_viewtransitions)
999 QQuickStackElement *exit = nullptr;
1000 if (!d->elements.isEmpty())
1001 exit = d->elements.top();
1002#endif
1003
1004 const int oldDepth = d->elements.size();
1005 if (d->pushElements(stackElements)) {
1006 d->depthChange(d->elements.size(), oldDepth);
1007 QQuickStackElement *enter = d->elements.top();
1008#if QT_CONFIG(quick_viewtransitions)
1009 d->startTransition(QQuickStackTransition::pushEnter(operation, enter, this),
1011 operation == Immediate);
1012#endif
1013 d->setCurrentItem(enter);
1014 }
1015
1016 return d->currentItem;
1017}
1018
1036QQuickItem *QQuickStackView::pushItem(QQuickItem *item, const QVariantMap &properties, Operation operation)
1037{
1038 return pushItems({ item, properties }, operation);
1039}
1040
1059QQuickItem *QQuickStackView::pushItem(QQmlComponent *component, const QVariantMap &properties, Operation operation)
1060{
1061 return pushItems({ component, properties }, operation);
1062}
1063
1082QQuickItem *QQuickStackView::pushItem(const QUrl &url, const QVariantMap &properties, Operation operation)
1083{
1084 return pushItems({ url, properties }, operation);
1085}
1086
1108QQuickItem *QQuickStackView::popToItem(QQuickItem *item, Operation operation)
1109{
1110 Q_D(QQuickStackView);
1112}
1113
1136QQuickItem *QQuickStackView::popToIndex(int index, Operation operation)
1137{
1138 Q_D(QQuickStackView);
1139 if (index < 0 || index >= d->elements.size()) {
1140 d->warn(QString::fromLatin1("popToIndex: index %1 is out of bounds (%2 item(s))")
1141 .arg(index).arg(d->elements.size()));
1142 return nullptr;
1143 }
1144
1145 if (index == d->elements.size() - 1) {
1146 // This would pop down to the current item, which is a no-op.
1147 return nullptr;
1148 }
1149
1150 QQuickStackElement *element = d->elements.at(index);
1151 element->load(this);
1152 return d->popToItem(element->item, operation, QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1153}
1154
1172QQuickItem *QQuickStackView::popCurrentItem(Operation operation)
1173{
1174 Q_D(QQuickStackView);
1175 if (d->elements.size() == 1) {
1176 auto lastItemRemoved = d->elements.last()->item;
1178 return lastItemRemoved;
1179 }
1180 return d->popToItem(d->currentItem, operation, QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1181}
1182
1224QQuickItem *QQuickStackView::replaceCurrentItem(const QList<QQuickStackViewArg> &args,
1225 Operation operation)
1226{
1227 Q_D(QQuickStackView);
1228 const QString operationName = QStringLiteral("replace");
1229 if (d->modifyingElements) {
1230 d->warnOfInterruption(operationName);
1231 return nullptr;
1232 }
1233
1234 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
1235 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1236
1237 QQuickStackElement *currentElement = !d->elements.isEmpty() ? d->elements.top() : nullptr;
1238
1239 const QList<QQuickStackElement *> stackElements = d->parseElements(args);
1240
1241 int oldDepth = d->elements.size();
1242 QQuickStackElement* exit = nullptr;
1243 if (!d->elements.isEmpty())
1244 exit = d->elements.pop();
1245
1246 const bool successfullyReplaced = exit != currentElement
1247 ? d->replaceElements(currentElement, stackElements)
1248 : d->pushElements(stackElements);
1249 if (successfullyReplaced) {
1250 d->depthChange(d->elements.size(), oldDepth);
1251 if (exit) {
1252 exit->removal = true;
1253 d->removing.insert(exit);
1254 }
1255 QQuickStackElement *enter = d->elements.top();
1256#if QT_CONFIG(quick_viewtransitions)
1257 d->startTransition(QQuickStackTransition::replaceExit(operation, exit, this),
1259 operation == Immediate);
1260#endif
1261 d->setCurrentItem(enter);
1262 }
1263
1264 return d->currentItem;
1265}
1266
1287QQuickItem *QQuickStackView::replaceCurrentItem(QQuickItem *item, const QVariantMap &properties,
1288 Operation operation)
1289{
1290 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(item), QQuickStackViewArg(properties) };
1291 return replaceCurrentItem(args, operation);
1292}
1293
1314QQuickItem *QQuickStackView::replaceCurrentItem(QQmlComponent *component, const QVariantMap &properties,
1315 Operation operation)
1316{
1317 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(component), QQuickStackViewArg(properties) };
1318 return replaceCurrentItem(args, operation);
1319}
1320
1341QQuickItem *QQuickStackView::replaceCurrentItem(const QUrl &url, const QVariantMap &properties,
1342 Operation operation)
1343{
1344 const QList<QQuickStackViewArg> args = { QQuickStackViewArg(url), QQuickStackViewArg(properties) };
1345 return replaceCurrentItem(args, operation);
1346}
1347
1358{
1359 Q_D(const QQuickStackView);
1360 return d->elements.isEmpty();
1361}
1362
1378{
1379#if !QT_CONFIG(quick_viewtransitions)
1381#endif
1382 Q_D(QQuickStackView);
1383 if (d->elements.isEmpty())
1384 return;
1385
1386 const QString operationName = QStringLiteral("clear");
1387 if (d->modifyingElements) {
1388 d->warnOfInterruption(operationName);
1389 return;
1390 }
1391
1392 const int oldDepth = d->elements.size();
1393
1394 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
1395 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1396#if QT_CONFIG(quick_viewtransitions)
1397 if (operation != Immediate) {
1398 QQuickStackElement *exit = d->elements.pop();
1399 exit->removal = true;
1400 d->removing.insert(exit);
1401 d->startTransition(QQuickStackTransition::popExit(operation, exit, this),
1402 QQuickStackTransition::popEnter(operation, nullptr, this), false);
1403 }
1404#endif
1405
1406 d->setCurrentItem(nullptr);
1407 qDeleteAll(d->elements);
1408 d->elements.clear();
1409 d->depthChange(0, oldDepth);
1410}
1411
1425{
1426 Q_D(const QQuickStackView);
1427 return d->initialItem;
1428}
1429
1431{
1432 Q_D(QQuickStackView);
1433 d->initialItem = item;
1434}
1435
1436#if QT_CONFIG(quick_viewtransitions)
1445QQuickTransition *QQuickStackView::popEnter() const
1446{
1447 Q_D(const QQuickStackView);
1448 if (d->transitioner)
1449 return d->transitioner->removeDisplacedTransition;
1450 return nullptr;
1451}
1452
1453void QQuickStackView::setPopEnter(QQuickTransition *enter)
1454{
1455 Q_D(QQuickStackView);
1456 d->ensureTransitioner();
1457 if (d->transitioner->removeDisplacedTransition == enter)
1458 return;
1459
1460 d->transitioner->removeDisplacedTransition = enter;
1461 emit popEnterChanged();
1462}
1463
1472QQuickTransition *QQuickStackView::popExit() const
1473{
1474 Q_D(const QQuickStackView);
1475 if (d->transitioner)
1476 return d->transitioner->removeTransition;
1477 return nullptr;
1478}
1479
1480void QQuickStackView::setPopExit(QQuickTransition *exit)
1481{
1482 Q_D(QQuickStackView);
1483 d->ensureTransitioner();
1484 if (d->transitioner->removeTransition == exit)
1485 return;
1486
1487 d->transitioner->removeTransition = exit;
1488 emit popExitChanged();
1489}
1490
1499QQuickTransition *QQuickStackView::pushEnter() const
1500{
1501 Q_D(const QQuickStackView);
1502 if (d->transitioner)
1503 return d->transitioner->addTransition;
1504 return nullptr;
1505}
1506
1507void QQuickStackView::setPushEnter(QQuickTransition *enter)
1508{
1509 Q_D(QQuickStackView);
1510 d->ensureTransitioner();
1511 if (d->transitioner->addTransition == enter)
1512 return;
1513
1514 d->transitioner->addTransition = enter;
1515 emit pushEnterChanged();
1516}
1517
1526QQuickTransition *QQuickStackView::pushExit() const
1527{
1528 Q_D(const QQuickStackView);
1529 if (d->transitioner)
1530 return d->transitioner->addDisplacedTransition;
1531 return nullptr;
1532}
1533
1534void QQuickStackView::setPushExit(QQuickTransition *exit)
1535{
1536 Q_D(QQuickStackView);
1537 d->ensureTransitioner();
1538 if (d->transitioner->addDisplacedTransition == exit)
1539 return;
1540
1541 d->transitioner->addDisplacedTransition = exit;
1542 emit pushExitChanged();
1543}
1544
1553QQuickTransition *QQuickStackView::replaceEnter() const
1554{
1555 Q_D(const QQuickStackView);
1556 if (d->transitioner)
1557 return d->transitioner->moveTransition;
1558 return nullptr;
1559}
1560
1561void QQuickStackView::setReplaceEnter(QQuickTransition *enter)
1562{
1563 Q_D(QQuickStackView);
1564 d->ensureTransitioner();
1565 if (d->transitioner->moveTransition == enter)
1566 return;
1567
1568 d->transitioner->moveTransition = enter;
1569 emit replaceEnterChanged();
1570}
1571
1580QQuickTransition *QQuickStackView::replaceExit() const
1581{
1582 Q_D(const QQuickStackView);
1583 if (d->transitioner)
1584 return d->transitioner->moveDisplacedTransition;
1585 return nullptr;
1586}
1587
1588void QQuickStackView::setReplaceExit(QQuickTransition *exit)
1589{
1590 Q_D(QQuickStackView);
1591 d->ensureTransitioner();
1592 if (d->transitioner->moveDisplacedTransition == exit)
1593 return;
1594
1595 d->transitioner->moveDisplacedTransition = exit;
1596 emit replaceExitChanged();
1597}
1598#endif
1599
1601{
1603
1604 Q_D(QQuickStackView);
1605 QScopedValueRollback<QString> operationNameRollback(d->operation, QStringLiteral("initialItem"));
1606 QQuickStackElement *element = nullptr;
1607 QString error;
1608 int oldDepth = d->elements.size();
1609 if (QObject *o = d->initialItem.toQObject())
1610 element = QQuickStackElement::fromObject(o, this, &error);
1611 else if (d->initialItem.isString())
1612 element = QQuickStackElement::fromString(d->initialItem.toString(), this, &error);
1613 if (!error.isEmpty()) {
1614 d->warn(error);
1615 delete element;
1616 } else if (d->pushElement(element)) {
1617 d->depthChange(d->elements.size(), oldDepth);
1618 d->setCurrentItem(element);
1620 }
1621}
1622
1623void QQuickStackView::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
1624{
1625 QQuickControl::geometryChange(newGeometry, oldGeometry);
1626
1627 Q_D(QQuickStackView);
1628 for (QQuickStackElement *element : std::as_const(d->elements)) {
1629 if (element->item) {
1630 if (!element->widthValid)
1631 element->item->setWidth(newGeometry.width());
1632 if (!element->heightValid)
1633 element->item->setHeight(newGeometry.height());
1634 }
1635 }
1636}
1637
1639{
1640 // in order to block accidental user interaction while busy/transitioning,
1641 // StackView filters out childrens' mouse events. therefore we block all
1642 // press events. however, since push() may be called from signal handlers
1643 // such as onPressed or onDoubleClicked, we must let the current mouse
1644 // grabber item receive the respective mouse release event to avoid
1645 // breaking its state (QTBUG-50305).
1646 if (event->type() == QEvent::MouseButtonPress)
1647 return true;
1648 if (event->type() == QEvent::UngrabMouse)
1649 return false;
1651 return window && !window->mouseGrabberItem();
1652}
1653
1654#if QT_CONFIG(quicktemplates2_multitouch)
1656{
1657 event->ignore(); // QTBUG-65084
1658}
1659#endif
1660
1661#if QT_CONFIG(accessibility)
1662QAccessible::Role QQuickStackView::accessibleRole() const
1663{
1664 return QAccessible::LayeredPane;
1665}
1666#endif
1667
1669{
1671 int oldIndex = element ? element->index : -1;
1672 QQuickStackView *oldView = element ? element->view : nullptr;
1674
1675 QQuickStackView *newView = qobject_cast<QQuickStackView *>(parent);
1676 element = newView ? QQuickStackViewPrivate::get(newView)->findElement(item) : nullptr;
1677
1678 int newIndex = element ? element->index : -1;
1680
1681 if (oldIndex != newIndex)
1682 emit q->indexChanged();
1683 if (oldView != newView)
1684 emit q->viewChanged();
1685 if (oldStatus != newStatus)
1686 emit q->statusChanged();
1687}
1688
1690 : QObject(*(new QQuickStackViewAttachedPrivate), parent)
1691{
1694 if (item) {
1696 QQuickItemPrivate::get(item)->addItemChangeListener(d, QQuickItemPrivate::Parent);
1697 d->itemParentChanged(item, item->parentItem());
1698 } else if (parent) {
1699 qmlWarning(parent) << "StackView must be attached to an Item";
1700 }
1701}
1702
1704{
1707 if (parentItem)
1708 QQuickItemPrivate::get(parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Parent);
1709}
1710
1719{
1720 Q_D(const QQuickStackViewAttached);
1721 return d->element ? d->element->index : -1;
1722}
1723
1732{
1733 Q_D(const QQuickStackViewAttached);
1734 return d->element ? d->element->view : nullptr;
1735}
1736
1751{
1752 Q_D(const QQuickStackViewAttached);
1753 return d->element ? d->element->status : QQuickStackView::Inactive;
1754}
1755
1778{
1779 const QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1780 return parentItem && parentItem->isVisible();
1781}
1782
1784{
1786 d->explicitVisible = true;
1788 if (parentItem)
1789 parentItem->setVisible(visible);
1790}
1791
1793{
1795 d->explicitVisible = false;
1796 if (!d->element || !d->element->view)
1797 return;
1798
1800 if (parentItem)
1801 parentItem->setVisible(parentItem == d->element->view->currentItem());
1802}
1803
1860
1861#include "moc_qquickstackview_p.cpp"
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:45
@ UngrabMouse
Definition qcoreevent.h:234
@ MouseButtonPress
Definition qcoreevent.h:60
QGraphicsWidget * window() const
QGraphicsItem * parentItem() const
Returns a pointer to this item's parent item.
QJSValue newQObject(QObject *object)
Creates a JavaScript object that wraps the given QObject object, using JavaScriptOwnership.
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
QJSValue call(const QJSValueList &args=QJSValueList()) const
Calls this QJSValue as a function, passing args as arguments to the function, and using the globalObj...
Definition qjsvalue.cpp:705
static constexpr Policy Preferred
qsizetype length() const noexcept
Definition qlist.h:399
QObject * parent
Definition qobject.h:73
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QQmlComponent class encapsulates a QML component definition.
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
bool isVisible() const
void visibleChanged()
void setHeight(qreal)
QQuickWindow * window() const
Returns the window in which this item is rendered.
void setVisible(bool)
virtual void touchEvent(QTouchEvent *event)
This event handler can be reimplemented in a subclass to receive touch events for an item.
void setWidth(qreal)
static QQuickStackElement * fromObject(QObject *object, QQuickStackView *view, QString *error)
void setStatus(QQuickStackView::Status status)
static QQuickStackElement * fromString(const QString &str, QQuickStackView *view, QString *error)
QQuickStackView::Status status
bool load(QQuickStackView *parent)
QQuickStackViewArg()=default
void itemParentChanged(QQuickItem *item, QQuickItem *parent) override
void setVisible(bool visible)
QQuickStackViewAttached(QObject *parent=nullptr)
QQuickStackView::Status status
static QQuickStackViewPrivate * get(QQuickStackView *view)
QQuickStackView(QQuickItem *parent=nullptr)
Provides a stack-based navigation model.
static QQuickStackViewAttached * qmlAttachedProperties(QObject *object)
bool isBusy() const
\qmlproperty bool QtQuick.Controls::StackView::busy \readonly This property holds whether a transitio...
void clear(Operation operation=Immediate)
\qmlmethod void QtQuick.Controls::StackView::clear(transition)
QQuickItem * currentItem
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
Q_INVOKABLE void pop(QQmlV4FunctionPtr args)
\qmlmethod Item QtQuick.Controls::StackView::pop(item, operation)
void setInitialItem(const QJSValue &item)
Q_INVOKABLE void push(QQmlV4FunctionPtr args)
\qmlmethod Item QtQuick.Controls::StackView::push(item, properties, operation)
Q_INVOKABLE QQuickItem * get(int index, QQuickStackView::LoadBehavior behavior=DontLoad)
\qmlmethod Item QtQuick.Controls::StackView::get(index, behavior)
Q_INVOKABLE void replace(QQmlV4FunctionPtr args)
\qmlmethod Item QtQuick.Controls::StackView::replace(target, item, properties, operation)
Q_INVOKABLE QQuickItem * find(const QJSValue &callback, QQuickStackView::LoadBehavior behavior=DontLoad)
\qmlmethod Item QtQuick.Controls::StackView::find(callback, behavior)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
bool childMouseEventFilter(QQuickItem *, QEvent *) override
Reimplement this method to filter the pointer events that are received by this item's children.
const QVariantMap & properties
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
\inmodule QtCore
Definition qurl.h:94
b clear()
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
QList< QJSValue > QJSValueList
Definition qjsvalue.h:22
GLuint index
[2]
GLuint GLuint end
GLenum target
struct _cl_event * event
GLenum func
Definition qopenglext.h:663
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
static qreal component(const QPointF &point, unsigned int i)
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:80
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:492
QDebug operator<<(QDebug debug, const QQuickStackViewArg &arg)
static QLatin1StringView operationName(QNetworkAccessManager::Operation operation)
SSL_CTX int void * arg
#define QStringLiteral(str)
static const QTextHtmlElement elements[Html_NumElements]
#define emit
#define Q_UNUSED(x)
QUrl url("example.com")
[constructor-url-reference]
QGraphicsItem * item
QJSValueList args
QJSEngine engine
[0]
static QQuickStackTransition pushExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
static QQuickStackTransition replaceExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
static QQuickStackTransition replaceEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
static QQuickStackTransition popExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
static QQuickStackTransition popEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
static QQuickStackTransition pushEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
static constexpr ReturnedValue null()
static ReturnedValue wrap(ExecutionEngine *engine, QObject *object)