diff options
Diffstat (limited to 'src/quicktemplates/qquickstackelement.cpp')
-rw-r--r-- | src/quicktemplates/qquickstackelement.cpp | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/quicktemplates/qquickstackelement.cpp b/src/quicktemplates/qquickstackelement.cpp index f8001a2980..f6a5ffdd74 100644 --- a/src/quicktemplates/qquickstackelement.cpp +++ b/src/quicktemplates/qquickstackelement.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qquickstackelement_p_p.h" +#include "qquickstackview_p.h" #include "qquickstackview_p_p.h" #include <QtQml/qqmlinfo.h> @@ -15,6 +16,7 @@ QT_BEGIN_NAMESPACE +#if QT_CONFIG(quick_viewtransitions) static QQuickStackViewAttached *attachedStackObject(QQuickStackElement *element) { QQuickStackViewAttached *attached = qobject_cast<QQuickStackViewAttached *>(qmlAttachedPropertiesObject<QQuickStackView>(element->item, false)); @@ -22,6 +24,7 @@ static QQuickStackViewAttached *attachedStackObject(QQuickStackElement *element) QQuickStackViewAttachedPrivate::get(attached)->element = element; return attached; } +#endif class QQuickStackIncubator : public QQmlIncubator { @@ -44,18 +47,23 @@ private: }; QQuickStackElement::QQuickStackElement() +#if QT_CONFIG(quick_viewtransitions) : QQuickItemViewTransitionableItem(nullptr) +#endif { } QQuickStackElement::~QQuickStackElement() { +#if QT_CONFIG(quick_viewtransitions) if (item) QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed); +#endif if (ownComponent) delete component; +#if QT_CONFIG(quick_viewtransitions) QQuickStackViewAttached *attached = attachedStackObject(this); if (item) { if (ownItem) { @@ -79,6 +87,7 @@ QQuickStackElement::~QQuickStackElement() if (attached) emit attached->removed(); +#endif } QQuickStackElement *QQuickStackElement::fromString(const QString &str, QQuickStackView *view, QString *error) @@ -110,9 +119,36 @@ QQuickStackElement *QQuickStackElement::fromObject(QObject *object, QQuickStackV QQuickStackElement *element = new QQuickStackElement; element->component = qobject_cast<QQmlComponent *>(object); +#if QT_CONFIG(quick_viewtransitions) element->item = qobject_cast<QQuickItem *>(object); if (element->item) element->originalParent = element->item->parentItem(); +#endif + return element; +} + +QQuickStackElement *QQuickStackElement::fromStackViewArg(QQuickStackView *view, QQuickStackViewArg arg) +{ + QQuickStackElement *element = new QQuickStackElement; +#if QT_CONFIG(quick_viewtransitions) + element->item = arg.mItem; + if (element->item) { + element->originalParent = element->item->parentItem(); + + Q_ASSERT(!arg.mComponent); + Q_ASSERT(!arg.mUrl.isValid()); + } else +#endif + if (arg.mComponent) { + element->component = arg.mComponent; + + Q_ASSERT(!arg.mUrl.isValid()); + } else if (arg.mUrl.isValid()) { + element->component = new QQmlComponent(qmlEngine(view), arg.mUrl, view); + element->ownComponent = true; + } else { + qFatal("No Item, Component or URL set on arg passed to fromStrictArg"); + } return element; } @@ -177,7 +213,9 @@ void QQuickStackElement::initialize(RequiredProperties *requiredProperties) QV4::ScopedValue ipv(scope, properties.value()); QV4::Scoped<QV4::QmlContext> qmlContext(scope, qmlCallingContext.value()); QV4::ScopedValue qmlObject(scope, QV4::QObjectWrapper::wrap(v4, item)); - QQmlComponentPrivate::setInitialProperties(v4, qmlContext, qmlObject, ipv, requiredProperties, item); + QQmlComponentPrivate::setInitialProperties( + v4, qmlContext, qmlObject, ipv, requiredProperties, item, + component ? QQmlComponentPrivate::get(component)->state.creator() : nullptr); properties.clear(); } @@ -202,9 +240,11 @@ void QQuickStackElement::setIndex(int value) return; index = value; +#if QT_CONFIG(quick_viewtransitions) QQuickStackViewAttached *attached = attachedStackObject(this); if (attached) emit attached->indexChanged(); +#endif } void QQuickStackElement::setView(QQuickStackView *value) @@ -213,9 +253,11 @@ void QQuickStackElement::setView(QQuickStackView *value) return; view = value; +#if QT_CONFIG(quick_viewtransitions) QQuickStackViewAttached *attached = attachedStackObject(this); if (attached) emit attached->viewChanged(); +#endif } void QQuickStackElement::setStatus(QQuickStackView::Status value) @@ -224,6 +266,7 @@ void QQuickStackElement::setStatus(QQuickStackView::Status value) return; status = value; +#if QT_CONFIG(quick_viewtransitions) QQuickStackViewAttached *attached = attachedStackObject(this); if (!attached) return; @@ -247,17 +290,25 @@ void QQuickStackElement::setStatus(QQuickStackView::Status value) } emit attached->statusChanged(); +#endif } void QQuickStackElement::setVisible(bool visible) { +#if QT_CONFIG(quick_viewtransitions) QQuickStackViewAttached *attached = attachedStackObject(this); - if (!item || (attached && QQuickStackViewAttachedPrivate::get(attached)->explicitVisible)) +#endif + if (!item +#if QT_CONFIG(quick_viewtransitions) + || (attached && QQuickStackViewAttachedPrivate::get(attached)->explicitVisible) +#endif + ) return; item->setVisible(visible); } +#if QT_CONFIG(quick_viewtransitions) void QQuickStackElement::transitionNextReposition(QQuickItemViewTransitioner *transitioner, QQuickItemViewTransitioner::TransitionType type, bool asTarget) { if (transitioner) @@ -294,10 +345,13 @@ void QQuickStackElement::completeTransition(QQuickTransition *quickTransition) { QQuickItemViewTransitionableItem::completeTransition(quickTransition); } +#endif void QQuickStackElement::itemDestroyed(QQuickItem *) { +#if QT_CONFIG(quick_viewtransitions) item = nullptr; +#endif } QT_END_NAMESPACE |