From 12b35ba88c2d874647547c888dbb2f06ef09f925 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Wed, 7 Jul 2021 13:54:26 +0200 Subject: [PATCH] feat(StatusModal): expose loaded content As discussed in #237, this is needed for consumers to access content children from outside `content`. Usage: ```qml StatusModal { id: modal content: StatusBaseText { text: "Foo" } rightButtons: [ StatusButton { text: "Change text" onClicked: { modal.contentComponent.text = "Bar" } } ] } ``` Fixes #237 --- ui/StatusQ/sandbox/Popups.qml | 29 +++++++++++++++++++ ui/StatusQ/src/StatusQ/Popups/StatusModal.qml | 2 ++ 2 files changed, 31 insertions(+) diff --git a/ui/StatusQ/sandbox/Popups.qml b/ui/StatusQ/sandbox/Popups.qml index 30cfb71ffb..57d7a4301c 100644 --- a/ui/StatusQ/sandbox/Popups.qml +++ b/ui/StatusQ/sandbox/Popups.qml @@ -33,6 +33,11 @@ Column { onClicked: modalExample.open() } + StatusButton { + text: "Modal with changable content" + onClicked: modalWithContentAccess.open() + } + StatusModal { id: simpleModal anchors.centerIn: parent @@ -142,4 +147,28 @@ Column { icon.name: "info" } } + + StatusModal { + id: modalWithContentAccess + anchors.centerIn: parent + header.title: "Header" + header.subTitle: "SubTitle" + + content: StatusBaseText { + id: text + anchors.centerIn: parent + text: "Some text content" + font.pixelSize: 15 + color: Theme.palette.directColor1 + } + + rightButtons: [ + StatusButton { + text: "Change text" + onClicked: { + modalWithContentAccess.contentComponent.text = "Changed!" + } + } + ] + } } diff --git a/ui/StatusQ/src/StatusQ/Popups/StatusModal.qml b/ui/StatusQ/src/StatusQ/Popups/StatusModal.qml index 02b9a3d64b..6e0e7702a6 100644 --- a/ui/StatusQ/src/StatusQ/Popups/StatusModal.qml +++ b/ui/StatusQ/src/StatusQ/Popups/StatusModal.qml @@ -16,6 +16,7 @@ QC.Popup { property alias headerActionButton: headerImpl.actionButton property StatusModalHeaderSettings header: StatusModalHeaderSettings {} + property alias contentComponent: contentLoader.item property alias rightButtons: footerImpl.rightButtons property alias leftButtons: footerImpl.leftButtons @@ -56,6 +57,7 @@ QC.Popup { } Loader { + id: contentLoader active: true anchors.horizontalCenter: parent.horizontalCenter sourceComponent: statusModal.content