From bd383e8746f1035a2a6990ffa5fb3b006470d733 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 --- sandbox/Popups.qml | 29 +++++++++++++++++++++++++++++ src/StatusQ/Popups/StatusModal.qml | 2 ++ 2 files changed, 31 insertions(+) diff --git a/sandbox/Popups.qml b/sandbox/Popups.qml index 30cfb71f..57d7a430 100644 --- a/sandbox/Popups.qml +++ b/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/src/StatusQ/Popups/StatusModal.qml b/src/StatusQ/Popups/StatusModal.qml index 02b9a3d6..6e0e7702 100644 --- a/src/StatusQ/Popups/StatusModal.qml +++ b/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