Kirigami2

pagestackattached.h
1// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <QJSValue>
7#include <QQuickAttachedPropertyPropagator>
8#include <QQuickItem>
9#include <qqmlregistration.h>
10
11/**
12 * This attached property makes possible to access from anywhere the
13 * page stack this page was pushed into.
14 * It can be an instance of org::kde::kirigami::PageRow or
15 * a StackView from QtQuickControls
16 *
17 * Kirigami.Page {
18 * id: root
19 *
20 * Button {
21 * text: "Push Page"
22 * onClicked: Kirigami.PageStack.push(Qt.resolvedurl("AnotherPage"));
23 * }
24 * }
25 *
26 * @since 6.10
27 */
28class PageStackAttached : public QQuickAttachedPropertyPropagator
29{
31 QML_NAMED_ELEMENT(PageStack)
32 QML_ATTACHED(PageStackAttached)
33 QML_UNCREATABLE("")
34
35 Q_PROPERTY(QQuickItem *pageStack READ pageStack WRITE setPageStack NOTIFY pageStackChanged)
36
37public:
38 explicit PageStackAttached(QObject *parent);
39
40 /*!
41 \qmlattachedproperty PageRow PageStack::pageStack
42
43 This property holds the pageStack where this page was pushed.
44 It will point to the proper instance in the parent hyerarchy
45 and normally is not necessary to explicitly write it.
46 Write on this property only if it's desired this attached
47 property and those of all the children to point to a different
48 PageRow or StackView
49 */
50 QQuickItem *pageStack() const;
51 void setPageStack(QQuickItem *pageStack);
52
53 Q_INVOKABLE void push(const QVariant &page, const QVariantMap &properties = QVariantMap());
54 Q_INVOKABLE void replace(const QVariant &page, const QVariantMap &properties = QVariantMap());
55 Q_INVOKABLE void pop(const QVariant &page = QVariant());
56 Q_INVOKABLE void clear();
57
58 static PageStackAttached *qmlAttachedProperties(QObject *object);
59
60protected:
61 bool hasStackCapabilities(QQuickItem *candidate);
62 void propagatePageStack(QQuickItem *pageStack);
63 void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent) override;
64
66 void pageStackChanged();
67
68private:
69 QPointer<QQuickItem> m_pageStack;
70 QPointer<QQuickItem> m_parentItem;
71 bool m_customStack = false;
72};
QObject(QObject *parent)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
QQuickAttachedPropertyPropagator(QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:53:57 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.