Qt 6.x
The Qt SDK
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
22 : mItem(item)
23{
24}
25
27 : mUrl(url)
28{
29}
30
32 : mComponent(component)
33{
34}
35
37 : mProperties(properties)
38{
39}
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
385{
387}
388
390{
391 Q_D(QQuickStackView);
392#if QT_CONFIG(quick_viewtransitions)
393 if (d->transitioner) {
394 d->transitioner->setChangeListener(nullptr);
395 delete d->transitioner;
396 }
397#endif
398 qDeleteAll(d->removing);
399 qDeleteAll(d->removed);
400 qDeleteAll(d->elements);
401}
402
404{
405 return new QQuickStackViewAttached(object);
406}
407
414{
415 Q_D(const QQuickStackView);
416 return d->busy;
417}
418
425{
426 Q_D(const QQuickStackView);
427 return d->elements.size();
428}
429
436{
437 Q_D(const QQuickStackView);
438 return d->currentItem;
439}
440
452{
453 Q_D(QQuickStackView);
454 QQuickStackElement *element = d->elements.value(index);
455 if (element) {
456 if (behavior == ForceLoad)
457 element->load(this);
458 return element->item;
459 }
460 return nullptr;
461}
462
481{
482 Q_D(QQuickStackView);
483 QJSValue func(callback);
484 QQmlEngine *engine = qmlEngine(this);
485 if (!engine || !func.isCallable()) // TODO: warning?
486 return nullptr;
487
488 for (int i = d->elements.size() - 1; i >= 0; --i) {
489 QQuickStackElement *element = d->elements.at(i);
490 if (behavior == ForceLoad)
491 element->load(this);
492 if (element->item) {
493 QJSValue rv = func.call(QJSValueList() << engine->newQObject(element->item) << i);
494 if (rv.toBool())
495 return element->item;
496 }
497 }
498
499 return nullptr;
500}
501
567{
568 Q_D(QQuickStackView);
569 const QString operationName = QStringLiteral("push");
570 if (d->modifyingElements) {
571 d->warnOfInterruption(operationName);
572 return;
573 }
574
575 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
576 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
577 if (args->length() <= 0) {
578 d->warn(QStringLiteral("missing arguments"));
579 args->setReturnValue(QV4::Encode::null());
580 return;
581 }
582
583 QV4::ExecutionEngine *v4 = args->v4engine();
584 QV4::Scope scope(v4);
585
586#if QT_CONFIG(quick_viewtransitions)
587 Operation operation = d->elements.isEmpty() ? Immediate : PushTransition;
588 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
589 if (lastArg->isInt32())
590 operation = static_cast<Operation>(lastArg->toInt32());
591#endif
592
593 QStringList errors;
594 QList<QQuickStackElement *> elements = d->parseElements(0, args, &errors);
595 // Remove any items that are already in the stack, as they can't be in two places at once.
596 // not using erase_if, as we have to delete the elements first
597 auto removeIt = std::remove_if(elements.begin(), elements.end(), [&](QQuickStackElement *element) {
598 return element->item && d->findElement(element->item);
599 });
600 for (auto it = removeIt, end = elements.end(); it != end; ++it)
601 delete *it;
602 elements.erase(removeIt, elements.end());
603
604 if (!errors.isEmpty() || elements.isEmpty()) {
605 if (!errors.isEmpty()) {
606 for (const QString &error : std::as_const(errors))
607 d->warn(error);
608 } else {
609 d->warn(QStringLiteral("nothing to push"));
610 }
611 args->setReturnValue(QV4::Encode::null());
612 return;
613 }
614
615#if QT_CONFIG(quick_viewtransitions)
616 QQuickStackElement *exit = nullptr;
617 if (!d->elements.isEmpty())
618 exit = d->elements.top();
619#endif
620
621 int oldDepth = d->elements.size();
622 if (d->pushElements(elements)) {
623 d->depthChange(d->elements.size(), oldDepth);
624 QQuickStackElement *enter = d->elements.top();
625#if QT_CONFIG(quick_viewtransitions)
626 d->startTransition(QQuickStackTransition::pushEnter(operation, enter, this),
629#endif
630 d->setCurrentItem(enter);
631 }
632
633 if (d->currentItem) {
634 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
635 args->setReturnValue(rv->asReturnedValue());
636 } else {
637 args->setReturnValue(QV4::Encode::null());
638 }
639}
640
681{
682 Q_D(QQuickStackView);
683 const QString operationName = QStringLiteral("pop");
684 if (d->modifyingElements) {
685 d->warnOfInterruption(operationName);
686 args->setReturnValue(QV4::Encode::null());
687 return;
688 }
689
690 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
691 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
692 int argc = args->length();
693 if (d->elements.size() <= 1 || argc > 2) {
694 if (argc > 2)
695 d->warn(QStringLiteral("too many arguments"));
696 args->setReturnValue(QV4::Encode::null());
697 return;
698 }
699
700 int oldDepth = d->elements.size();
701 QQuickStackElement *exit = d->elements.pop();
702 QQuickStackElement *enter = d->elements.top();
703
704 QV4::ExecutionEngine *v4 = args->v4engine();
705 QV4::Scope scope(v4);
706
707 if (argc > 0) {
708 QV4::ScopedValue value(scope, (*args)[0]);
709 if (value->isNull()) {
710 enter = d->elements.value(0);
711 } else if (const QV4::QObjectWrapper *o = value->as<QV4::QObjectWrapper>()) {
713 enter = d->findElement(item);
714 if (!enter) {
715 if (item != d->currentItem)
716 d->warn(QStringLiteral("can't find item to pop: ") + value->toQString());
717 args->setReturnValue(QV4::Encode::null());
718 d->elements.push(exit); // restore
719 return;
720 }
721 }
722 }
723
724#if QT_CONFIG(quick_viewtransitions)
726 if (argc > 0) {
727 QV4::ScopedValue lastArg(scope, (*args)[argc - 1]);
728 if (lastArg->isInt32())
729 operation = static_cast<Operation>(lastArg->toInt32());
730 }
731#endif
732
733 QQuickItem *previousItem = nullptr;
734
735 if (d->popElements(enter)) {
736 if (exit) {
737 exit->removal = true;
738 d->removing.insert(exit);
739 previousItem = exit->item;
740 }
741 d->depthChange(d->elements.size(), oldDepth);
742#if QT_CONFIG(quick_viewtransitions)
743 d->startTransition(QQuickStackTransition::popExit(operation, exit, this),
746#endif
747 d->setCurrentItem(enter);
748 }
749
750 if (previousItem) {
751 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, previousItem));
752 args->setReturnValue(rv->asReturnedValue());
753 } else {
754 args->setReturnValue(QV4::Encode::null());
755 }
756}
757
852{
853 Q_D(QQuickStackView);
854 const QString operationName = QStringLiteral("replace");
855 if (d->modifyingElements) {
856 d->warnOfInterruption(operationName);
857 args->setReturnValue(QV4::Encode::null());
858 return;
859 }
860
861 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
862 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
863 if (args->length() <= 0) {
864 d->warn(QStringLiteral("missing arguments"));
865 args->setReturnValue(QV4::Encode::null());
866 return;
867 }
868
869 QV4::ExecutionEngine *v4 = args->v4engine();
870 QV4::Scope scope(v4);
871
872#if QT_CONFIG(quick_viewtransitions)
873 Operation operation = d->elements.isEmpty() ? Immediate : ReplaceTransition;
874 QV4::ScopedValue lastArg(scope, (*args)[args->length() - 1]);
875 if (lastArg->isInt32())
876 operation = static_cast<Operation>(lastArg->toInt32());
877#endif
878
879 QQuickStackElement *target = nullptr;
880 QV4::ScopedValue firstArg(scope, (*args)[0]);
881 if (firstArg->isNull())
882 target = d->elements.value(0);
883 else if (!firstArg->isInt32())
884 target = d->findElement(firstArg);
885
886 QStringList errors;
887 QList<QQuickStackElement *> elements = d->parseElements(target ? 1 : 0, args, &errors);
888 if (!errors.isEmpty() || elements.isEmpty()) {
889 if (!errors.isEmpty()) {
890 for (const QString &error : std::as_const(errors))
891 d->warn(error);
892 } else {
893 d->warn(QStringLiteral("nothing to push"));
894 }
895 args->setReturnValue(QV4::Encode::null());
896 return;
897 }
898
899 int oldDepth = d->elements.size();
900 QQuickStackElement* exit = nullptr;
901 if (!d->elements.isEmpty())
902 exit = d->elements.pop();
903
904 if (exit != target ? d->replaceElements(target, elements) : d->pushElements(elements)) {
905 d->depthChange(d->elements.size(), oldDepth);
906 if (exit) {
907 exit->removal = true;
908 d->removing.insert(exit);
909 }
910 QQuickStackElement *enter = d->elements.top();
911#if QT_CONFIG(quick_viewtransitions)
912 d->startTransition(QQuickStackTransition::replaceExit(operation, exit, this),
915#endif
916 d->setCurrentItem(enter);
917 }
918
919 if (d->currentItem) {
920 QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(v4, d->currentItem));
921 args->setReturnValue(rv->asReturnedValue());
922 } else {
923 args->setReturnValue(QV4::Encode::null());
924 }
925}
926
977QQuickItem *QQuickStackView::pushItems(QList<QQuickStackViewArg> args, Operation operation)
978{
979 Q_D(QQuickStackView);
980 const QString operationName = QStringLiteral("pushItem");
981 if (d->modifyingElements) {
982 d->warnOfInterruption(operationName);
983 return nullptr;
984 }
985
986 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
987 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
988
989 const QList<QQuickStackElement *> stackElements = d->parseElements(args);
990
991#if QT_CONFIG(quick_viewtransitions)
992 QQuickStackElement *exit = nullptr;
993 if (!d->elements.isEmpty())
994 exit = d->elements.top();
995#endif
996
997 const int oldDepth = d->elements.size();
998 if (d->pushElements(stackElements)) {
999 d->depthChange(d->elements.size(), oldDepth);
1000 QQuickStackElement *enter = d->elements.top();
1001#if QT_CONFIG(quick_viewtransitions)
1002 d->startTransition(QQuickStackTransition::pushEnter(operation, enter, this),
1004 operation == Immediate);
1005#endif
1006 d->setCurrentItem(enter);
1007 }
1008
1009 return d->currentItem;
1010}
1011
1029QQuickItem *QQuickStackView::pushItem(QQuickItem *item, const QVariantMap &properties, Operation operation)
1030{
1031 return pushItems({ item, properties }, operation);
1032}
1033
1052QQuickItem *QQuickStackView::pushItem(QQmlComponent *component, const QVariantMap &properties, Operation operation)
1053{
1054 return pushItems({ component, properties }, operation);
1055}
1056
1075QQuickItem *QQuickStackView::pushItem(const QUrl &url, const QVariantMap &properties, Operation operation)
1076{
1077 return pushItems({ url, properties }, operation);
1078}
1079
1101QQuickItem *QQuickStackView::popToItem(QQuickItem *item, Operation operation)
1102{
1103 Q_D(QQuickStackView);
1105}
1106
1129QQuickItem *QQuickStackView::popToIndex(int index, Operation operation)
1130{
1131 Q_D(QQuickStackView);
1132 if (index < 0 || index >= d->elements.size()) {
1133 d->warn(QString::fromLatin1("popToIndex: index %1 is out of bounds (%2 item(s))")
1134 .arg(index).arg(d->elements.size()));
1135 return nullptr;
1136 }
1137
1138 if (index == d->elements.size() - 1) {
1139 // This would pop down to the current item, which is a no-op.
1140 return nullptr;
1141 }
1142
1143 QQuickStackElement *element = d->elements.at(index);
1144 element->load(this);
1145 return d->popToItem(element->item, operation, QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1146}
1147
1165QQuickItem *QQuickStackView::popCurrentItem(Operation operation)
1166{
1167 Q_D(QQuickStackView);
1168 if (d->elements.size() == 1) {
1169 auto lastItemRemoved = d->elements.last()->item;
1171 return lastItemRemoved;
1172 }
1173 return d->popToItem(d->currentItem, operation, QQuickStackViewPrivate::CurrentItemPolicy::Pop);
1174}
1175
1217QQuickItem *QQuickStackView::replaceCurrentItem(const QList<QQuickStackViewArg> &args,
1218 Operation operation)
1219{
1220 Q_D(QQuickStackView);
1221 const QString operationName = QStringLiteral("replace");
1222 if (d->modifyingElements) {
1223 d->warnOfInterruption(operationName);
1224 return nullptr;
1225 }
1226
1227 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
1228 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1229
1230 QQuickStackElement *currentElement = !d->elements.isEmpty() ? d->elements.top() : nullptr;
1231
1232 const QList<QQuickStackElement *> stackElements = d->parseElements(args);
1233
1234 int oldDepth = d->elements.size();
1235 QQuickStackElement* exit = nullptr;
1236 if (!d->elements.isEmpty())
1237 exit = d->elements.pop();
1238
1239 const bool successfullyReplaced = exit != currentElement
1240 ? d->replaceElements(currentElement, stackElements)
1241 : d->pushElements(stackElements);
1242 if (successfullyReplaced) {
1243 d->depthChange(d->elements.size(), oldDepth);
1244 if (exit) {
1245 exit->removal = true;
1246 d->removing.insert(exit);
1247 }
1248 QQuickStackElement *enter = d->elements.top();
1249#if QT_CONFIG(quick_viewtransitions)
1250 d->startTransition(QQuickStackTransition::replaceExit(operation, exit, this),
1252 operation == Immediate);
1253#endif
1254 d->setCurrentItem(enter);
1255 }
1256
1257 return d->currentItem;
1258}
1259
1280QQuickItem *QQuickStackView::replaceCurrentItem(QQuickItem *item, const QVariantMap &properties,
1281 Operation operation)
1282{
1284 return replaceCurrentItem(args, operation);
1285}
1286
1307QQuickItem *QQuickStackView::replaceCurrentItem(QQmlComponent *component, const QVariantMap &properties,
1308 Operation operation)
1309{
1311 return replaceCurrentItem(args, operation);
1312}
1313
1334QQuickItem *QQuickStackView::replaceCurrentItem(const QUrl &url, const QVariantMap &properties,
1335 Operation operation)
1336{
1338 return replaceCurrentItem(args, operation);
1339}
1340
1351{
1352 Q_D(const QQuickStackView);
1353 return d->elements.isEmpty();
1354}
1355
1371{
1372#if !QT_CONFIG(quick_viewtransitions)
1374#endif
1375 Q_D(QQuickStackView);
1376 if (d->elements.isEmpty())
1377 return;
1378
1379 const QString operationName = QStringLiteral("clear");
1380 if (d->modifyingElements) {
1381 d->warnOfInterruption(operationName);
1382 return;
1383 }
1384
1385 const int oldDepth = d->elements.size();
1386
1387 QScopedValueRollback<bool> modifyingElements(d->modifyingElements, true);
1388 QScopedValueRollback<QString> operationNameRollback(d->operation, operationName);
1389#if QT_CONFIG(quick_viewtransitions)
1390 if (operation != Immediate) {
1391 QQuickStackElement *exit = d->elements.pop();
1392 exit->removal = true;
1393 d->removing.insert(exit);
1394 d->startTransition(QQuickStackTransition::popExit(operation, exit, this),
1395 QQuickStackTransition::popEnter(operation, nullptr, this), false);
1396 }
1397#endif
1398
1399 d->setCurrentItem(nullptr);
1400 qDeleteAll(d->elements);
1401 d->elements.clear();
1402 d->depthChange(0, oldDepth);
1403}
1404
1418{
1419 Q_D(const QQuickStackView);
1420 return d->initialItem;
1421}
1422
1424{
1425 Q_D(QQuickStackView);
1426 d->initialItem = item;
1427}
1428
1429#if QT_CONFIG(quick_viewtransitions)
1438QQuickTransition *QQuickStackView::popEnter() const
1439{
1440 Q_D(const QQuickStackView);
1441 if (d->transitioner)
1442 return d->transitioner->removeDisplacedTransition;
1443 return nullptr;
1444}
1445
1446void QQuickStackView::setPopEnter(QQuickTransition *enter)
1447{
1448 Q_D(QQuickStackView);
1449 d->ensureTransitioner();
1450 if (d->transitioner->removeDisplacedTransition == enter)
1451 return;
1452
1453 d->transitioner->removeDisplacedTransition = enter;
1454 emit popEnterChanged();
1455}
1456
1465QQuickTransition *QQuickStackView::popExit() const
1466{
1467 Q_D(const QQuickStackView);
1468 if (d->transitioner)
1469 return d->transitioner->removeTransition;
1470 return nullptr;
1471}
1472
1473void QQuickStackView::setPopExit(QQuickTransition *exit)
1474{
1475 Q_D(QQuickStackView);
1476 d->ensureTransitioner();
1477 if (d->transitioner->removeTransition == exit)
1478 return;
1479
1480 d->transitioner->removeTransition = exit;
1481 emit popExitChanged();
1482}
1483
1492QQuickTransition *QQuickStackView::pushEnter() const
1493{
1494 Q_D(const QQuickStackView);
1495 if (d->transitioner)
1496 return d->transitioner->addTransition;
1497 return nullptr;
1498}
1499
1500void QQuickStackView::setPushEnter(QQuickTransition *enter)
1501{
1502 Q_D(QQuickStackView);
1503 d->ensureTransitioner();
1504 if (d->transitioner->addTransition == enter)
1505 return;
1506
1507 d->transitioner->addTransition = enter;
1508 emit pushEnterChanged();
1509}
1510
1519QQuickTransition *QQuickStackView::pushExit() const
1520{
1521 Q_D(const QQuickStackView);
1522 if (d->transitioner)
1523 return d->transitioner->addDisplacedTransition;
1524 return nullptr;
1525}
1526
1527void QQuickStackView::setPushExit(QQuickTransition *exit)
1528{
1529 Q_D(QQuickStackView);
1530 d->ensureTransitioner();
1531 if (d->transitioner->addDisplacedTransition == exit)
1532 return;
1533
1534 d->transitioner->addDisplacedTransition = exit;
1535 emit pushExitChanged();
1536}
1537
1546QQuickTransition *QQuickStackView::replaceEnter() const
1547{
1548 Q_D(const QQuickStackView);
1549 if (d->transitioner)
1550 return d->transitioner->moveTransition;
1551 return nullptr;
1552}
1553
1554void QQuickStackView::setReplaceEnter(QQuickTransition *enter)
1555{
1556 Q_D(QQuickStackView);
1557 d->ensureTransitioner();
1558 if (d->transitioner->moveTransition == enter)
1559 return;
1560
1561 d->transitioner->moveTransition = enter;
1562 emit replaceEnterChanged();
1563}
1564
1573QQuickTransition *QQuickStackView::replaceExit() const
1574{
1575 Q_D(const QQuickStackView);
1576 if (d->transitioner)
1577 return d->transitioner->moveDisplacedTransition;
1578 return nullptr;
1579}
1580
1581void QQuickStackView::setReplaceExit(QQuickTransition *exit)
1582{
1583 Q_D(QQuickStackView);
1584 d->ensureTransitioner();
1585 if (d->transitioner->moveDisplacedTransition == exit)
1586 return;
1587
1588 d->transitioner->moveDisplacedTransition = exit;
1589 emit replaceExitChanged();
1590}
1591#endif
1592
1594{
1596
1597 Q_D(QQuickStackView);
1598 QScopedValueRollback<QString> operationNameRollback(d->operation, QStringLiteral("initialItem"));
1599 QQuickStackElement *element = nullptr;
1600 QString error;
1601 int oldDepth = d->elements.size();
1602 if (QObject *o = d->initialItem.toQObject())
1603 element = QQuickStackElement::fromObject(o, this, &error);
1604 else if (d->initialItem.isString())
1605 element = QQuickStackElement::fromString(d->initialItem.toString(), this, &error);
1606 if (!error.isEmpty()) {
1607 d->warn(error);
1608 delete element;
1609 } else if (d->pushElement(element)) {
1610 d->depthChange(d->elements.size(), oldDepth);
1611 d->setCurrentItem(element);
1613 }
1614}
1615
1616void QQuickStackView::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
1617{
1618 QQuickControl::geometryChange(newGeometry, oldGeometry);
1619
1620 Q_D(QQuickStackView);
1621 for (QQuickStackElement *element : std::as_const(d->elements)) {
1622 if (element->item) {
1623 if (!element->widthValid)
1624 element->item->setWidth(newGeometry.width());
1625 if (!element->heightValid)
1626 element->item->setHeight(newGeometry.height());
1627 }
1628 }
1629}
1630
1632{
1633 // in order to block accidental user interaction while busy/transitioning,
1634 // StackView filters out childrens' mouse events. therefore we block all
1635 // press events. however, since push() may be called from signal handlers
1636 // such as onPressed or onDoubleClicked, we must let the current mouse
1637 // grabber item receive the respective mouse release event to avoid
1638 // breaking its state (QTBUG-50305).
1639 if (event->type() == QEvent::MouseButtonPress)
1640 return true;
1641 if (event->type() == QEvent::UngrabMouse)
1642 return false;
1644 return window && !window->mouseGrabberItem();
1645}
1646
1647#if QT_CONFIG(quicktemplates2_multitouch)
1649{
1650 event->ignore(); // QTBUG-65084
1651}
1652#endif
1653
1654#if QT_CONFIG(accessibility)
1655QAccessible::Role QQuickStackView::accessibleRole() const
1656{
1657 return QAccessible::LayeredPane;
1658}
1659#endif
1660
1662{
1664 int oldIndex = element ? element->index : -1;
1665 QQuickStackView *oldView = element ? element->view : nullptr;
1667
1668 QQuickStackView *newView = qobject_cast<QQuickStackView *>(parent);
1669 element = newView ? QQuickStackViewPrivate::get(newView)->findElement(item) : nullptr;
1670
1671 int newIndex = element ? element->index : -1;
1673
1674 if (oldIndex != newIndex)
1675 emit q->indexChanged();
1676 if (oldView != newView)
1677 emit q->viewChanged();
1678 if (oldStatus != newStatus)
1679 emit q->statusChanged();
1680}
1681
1684{
1687 if (item) {
1690 d->itemParentChanged(item, item->parentItem());
1691 } else if (parent) {
1692 qmlWarning(parent) << "StackView must be attached to an Item";
1693 }
1694}
1695
1697{
1700 if (parentItem)
1702}
1703
1712{
1713 Q_D(const QQuickStackViewAttached);
1714 return d->element ? d->element->index : -1;
1715}
1716
1725{
1726 Q_D(const QQuickStackViewAttached);
1727 return d->element ? d->element->view : nullptr;
1728}
1729
1744{
1745 Q_D(const QQuickStackViewAttached);
1746 return d->element ? d->element->status : QQuickStackView::Inactive;
1747}
1748
1771{
1772 const QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent());
1773 return parentItem && parentItem->isVisible();
1774}
1775
1777{
1779 d->explicitVisible = true;
1781 if (parentItem)
1782 parentItem->setVisible(visible);
1783}
1784
1786{
1788 d->explicitVisible = false;
1789 if (!d->element || !d->element->view)
1790 return;
1791
1793 if (parentItem)
1794 parentItem->setVisible(parentItem == d->element->view->currentItem());
1795}
1796
1853
1854#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
bool toBool() const
Returns the boolean value of this QJSValue, using the conversion rules described in \l{ECMA-262} sect...
Definition qjsvalue.cpp:525
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:681
Definition qlist.h:74
qsizetype length() const noexcept
Definition qlist.h:388
QObject * parent
Definition qobject.h:61
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
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
void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types)
void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
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)
QQuickStackElement * findElement(QQuickItem *item) const
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
Q_INVOKABLE void push(QQmlV4Function *args)
\qmlmethod Item QtQuick.Controls::StackView::push(item, properties, operation)
Q_INVOKABLE void pop(QQmlV4Function *args)
\qmlmethod Item QtQuick.Controls::StackView::pop(item, operation)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setInitialItem(const QJSValue &item)
Q_INVOKABLE void replace(QQmlV4Function *args)
\qmlmethod Item QtQuick.Controls::StackView::replace(target, item, properties, operation)
Q_INVOKABLE QQuickItem * get(int index, QQuickStackView::LoadBehavior behavior=DontLoad)
\qmlmethod Item QtQuick.Controls::StackView::get(index, behavior)
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:483
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:718
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:715
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5710
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:916
\inmodule QtCore
Definition qurl.h:94
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:76
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:483
QDebug operator<<(QDebug debug, const QQuickStackViewArg &arg)
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)
constexpr ReturnedValue asReturnedValue() const
int toInt32() const
Definition qv4value_p.h:350
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent